diff --git a/PlayTools/Controls/PlayMice.swift b/PlayTools/Controls/PlayMice.swift index ae4a73f9..02311452 100644 --- a/PlayTools/Controls/PlayMice.swift +++ b/PlayTools/Controls/PlayMice.swift @@ -109,8 +109,11 @@ public class PlayMice { } public func handleMouseMoved(deltaX: Float, deltaY: Float) { - if self.acceptMouseEvents && self.fakedMousePressed { - Toucher.touchcam(point: self.cursorPos, phase: UITouch.Phase.moved, tid: 1) + if self.acceptMouseEvents { + if self.fakedMousePressed { + Toucher.touchcam(point: self.cursorPos, phase: UITouch.Phase.moved, tid: 1) + } + return } if mode.visible { return @@ -236,40 +239,22 @@ class CameraAction: Action { Toucher.touchQueue.asyncAfter(deadline: when, execute: closure) } - // if max speed of this touch is high - var movingFast = false // like sequence but resets when touch begins. Used to calc touch duration var counter = 0 // if should wait before beginning next touch var cooldown = false - // if the touch point had been prevented from lifting off because of moving slow - var idled = false // in how many tests has this been identified as stationary var stationaryCount = 0 let stationaryThreshold = 2 @objc func checkEnded() { // if been stationary for enough time - if self.stationaryCount < self.stationaryThreshold { + if self.stationaryCount < self.stationaryThreshold || (self.stationaryCount < 20 - self.counter) { self.stationaryCount += 1 - self.delay(0.1, closure: checkEnded) + self.delay(0.04, closure: checkEnded) return } - // and slow touch lasts for sufficient time - if self.movingFast || self.counter > 64 { - self.doLiftOff() - } else { - self.idled = true - // idle for at most 4 seconds - self.delay(4) { - if self.stationaryCount < self.stationaryThreshold { - self.stationaryCount += 1 - self.delay(0.1, closure: self.checkEnded) - return - } - self.doLiftOff() - } - } + self.doLiftOff() } @objc func updated(_ deltaX: CGFloat, _ deltaY: CGFloat) { @@ -280,26 +265,16 @@ class CameraAction: Action { counter += 1 if !isMoving { isMoving = true - movingFast = false - idled = false location = center counter = 0 stationaryCount = 0 Toucher.touchcam(point: self.center, phase: UITouch.Phase.began, tid: id) - delay(0.1, closure: checkEnded) + delay(0.01, closure: checkEnded) } - // if not moving fast, regard the user fine-tuning the camera(e.g. aiming) - // so hold the touch for longer to avoid cold startup - if deltaX.magnitude + deltaY.magnitude > 12 { - // if we had mistaken this as player aiming - if self.idled { -// Toast.showOver(msg: "idled") - // since not aiming, re-touch to re-gain control - self.doLiftOff() - return - } - movingFast = true + if self.counter == 120 { + self.doLiftOff() + return } self.location.x += deltaX self.location.y -= deltaY diff --git a/PlayTools/Keymap/DragElementsView.swift b/PlayTools/Keymap/DragElementsView.swift index 8d31d160..c1e0a378 100644 --- a/PlayTools/Keymap/DragElementsView.swift +++ b/PlayTools/Keymap/DragElementsView.swift @@ -20,7 +20,7 @@ class KeymapHolder: CircleMenuDelegate { frame: CGRect(x: 0, y: 0, width: 50, height: 50), normalIcon: "xmark.circle.fill", selectedIcon: "xmark.circle.fill", - buttonsCount: 6, + buttonsCount: 4, duration: 0.25, distance: 80) menu?.delegate = self @@ -56,12 +56,8 @@ class KeymapHolder: CircleMenuDelegate { EditorController.shared.addJoystick(globalPoint!) case 2: EditorController.shared.addMouseArea(globalPoint!) - case 3: - EditorController.shared.addRMB(globalPoint!) - case 4: - EditorController.shared.addLMB(globalPoint!) default: - EditorController.shared.addMMB(globalPoint!) + EditorController.shared.addMouseJoystick(globalPoint!) } hideWithAnimation() } @@ -78,8 +74,8 @@ class KeymapHolder: CircleMenuDelegate { "circle.circle", "dpad", "arrow.up.and.down.and.arrow.left.and.right", - "rb.rectangle.roundedbottom.fill", - "lb.rectangle.roundedbottom", +// "rb.rectangle.roundedbottom.fill", +// "lb.rectangle.roundedbottom", "computermouse" ] } diff --git a/PlayTools/Keymap/EditorController.swift b/PlayTools/Keymap/EditorController.swift index a23dfc88..d878c287 100644 --- a/PlayTools/Keymap/EditorController.swift +++ b/PlayTools/Keymap/EditorController.swift @@ -185,16 +185,21 @@ class EditorController { self.addLMB(toPoint) } - public func addRMB(_ toPoint: CGPoint) { - self.addButton(keyCode: -2, point: toPoint) - } - public func addLMB(_ toPoint: CGPoint) { self.addButton(keyCode: -1, point: toPoint) } - public func addMMB(_ toPoint: CGPoint) { - self.addButton(keyCode: -3, point: toPoint) + public func addMouseJoystick(_ center: CGPoint) { + if editorMode { + addControlToView(control: JoystickModel(data: ControlData(keyCodes: [GCKeyCode.keyW.rawValue, + GCKeyCode.keyS.rawValue, + GCKeyCode.keyA.rawValue, + GCKeyCode.keyD.rawValue], + keyName: "Mouse", + size: 20, + xCoord: center.x.relativeX, + yCoord: center.y.relativeY))) + } } public func addMouseArea(_ center: CGPoint) {