Habit game Disable most mouse input when menu is open

This commit is contained in:
2022-08-20 14:43:07 +00:00
parent 1af88ab3d7
commit d77ac2594d
2 changed files with 47 additions and 20 deletions

View File

@@ -41,9 +41,13 @@
(prop &mut :DebugLayer debugLayer null) (prop &mut :DebugLayer debugLayer null)
(prop &mut t 1) (prop &mut t 1)
(prop :FlxRect disableMouse (new FlxRect 0 0 0 0))
(method &override :Void update [:Float elapsed] (method &override :Void update [:Float elapsed]
(super.update elapsed) (super.update elapsed)
(if (windowIsShown)
(set FlxMouseControl.mouseZone disableMouse)
(set FlxMouseControl.mouseZone null))
(#when debug (#when debug
(debugLayer.clear) (debugLayer.clear)
@@ -61,6 +65,7 @@
(debugLayer.drawFlxRect z FlxColor.RED))))))) (debugLayer.drawFlxRect z FlxColor.RED)))))))
(when model.rewardFiles (when model.rewardFiles
(unless (windowIsShown)
(let [zoom pieceCamera.zoom (let [zoom pieceCamera.zoom
scroll (pieceCamera.scroll.copyTo)] scroll (pieceCamera.scroll.copyTo)]
(pieceCamera.updateScrollWheelZoom elapsed 5) (pieceCamera.updateScrollWheelZoom elapsed 5)
@@ -68,9 +73,9 @@
(when (or !(= zoom pieceCamera.zoom) !(scroll.equals pieceCamera.scroll)) (when (or !(= zoom pieceCamera.zoom) !(scroll.equals pieceCamera.scroll))
(set save.data.zoom pieceCamera.zoom) (set save.data.zoom pieceCamera.zoom)
(set save.data.scroll pieceCamera.scroll) (set save.data.scroll pieceCamera.scroll)
(save.flush))) (save.flush))))
(when entryWindow (when (and entryWindow !(tempWindowIsShown))
(when FlxG.keys.justPressed.ESCAPE (when FlxG.keys.justPressed.ESCAPE
(if (entryWindow.isShown) (if (entryWindow.isShown)
(entryWindow.hide) (entryWindow.hide)
@@ -97,15 +102,15 @@
// TODO provide a saner/configurable set of bindings to trigger these ui action functions // TODO provide a saner/configurable set of bindings to trigger these ui action functions
{ {
(unless (windowIsShown)
(when FlxG.mouse.justPressedRight (when FlxG.mouse.justPressedRight
(when draggingSprite (when draggingSprite
(draggingSprite.rotate 90) (draggingSprite.rotate 90)
(doFor s (recursivelyConnectedPieces draggingSprite) (doFor s (recursivelyConnectedPieces draggingSprite)
(dictSet (the Map<Int,Float> save.data.storedAngles) (dictGet indexMap s) s.angle) (dictSet (the Map<Int,Float> save.data.storedAngles) (dictGet indexMap s) s.angle)
(dictSet (the Map<Int,FlxPoint> save.data.storedOrigins) (dictGet indexMap s) s.origin)) (dictSet (the Map<Int,FlxPoint> save.data.storedOrigins) (dictGet indexMap s) s.origin))
(save.flush))) (save.flush))))
(method startAdding [:EntryType type] (method startAdding [:EntryType type]
(set typeAdding type) (set typeAdding type)
@@ -142,6 +147,20 @@
(prop &mut :FlxSave save null) (prop &mut :FlxSave save null)
(prop &mut :SimpleWindow entryWindow null) (prop &mut :SimpleWindow entryWindow null)
// TODO add other windows and add them to the windowIsShown and tempWindowIsShown lists
(method windowIsShown []
(doFor window [entryWindow]
(when (and window (window.isShown))
(return true)))
false)
(method tempWindowIsShown []
(doFor window []
(when (and window (window.isShown))
(return true)))
false)
(prop &mut :FlxTypedGroup<FlxText> logTexts (new FlxTypedGroup)) (prop &mut :FlxTypedGroup<FlxText> logTexts (new FlxTypedGroup))
(prop &mut :FlxKeyShortcutHandler<Entry> shortcutHandler null) (prop &mut :FlxKeyShortcutHandler<Entry> shortcutHandler null)

View File

@@ -80,14 +80,22 @@ class DragToSelectPlugin extends FlxBasic {
var camera = dragState.camera; var camera = dragState.camera;
if (camera == null) camera = FlxG.camera; if (camera == null) camera = FlxG.camera;
// If FlxMouseControl has a mouseZone enabled, respect it
var mousePos = FlxG.mouse.getWorldPosition(camera);
if (FlxMouseControl.mouseZone != null && !FlxMouseControl.mouseZone.containsPoint(mousePos)) {
dragState.firstCorner = null;
dragState.secondCorner = null;
return;
}
// have to skip a frame after justPressed, so KissExtendedSprites // have to skip a frame after justPressed, so KissExtendedSprites
// can get first access to the mouse input // can get first access to the mouse input
if (FlxMouseControl.dragTarget == null) { if (FlxMouseControl.dragTarget == null) {
if (wasJustPressed && FlxMouseControl.clickTarget == null) { if (wasJustPressed && FlxMouseControl.clickTarget == null) {
deselectSprites(); deselectSprites();
dragState.firstCorner = FlxG.mouse.getWorldPosition(camera); dragState.firstCorner = mousePos;
} }
dragState.secondCorner = FlxG.mouse.getWorldPosition(camera); dragState.secondCorner = mousePos;
if (dragState.firstCorner != null && dragState.selectedSprites.length == 0) { if (dragState.firstCorner != null && dragState.selectedSprites.length == 0) {
var rounded1 = dragState.firstCorner.copyTo(); var rounded1 = dragState.firstCorner.copyTo();
var rounded2 = dragState.secondCorner.copyTo(); var rounded2 = dragState.secondCorner.copyTo();