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 t 1)
(prop :FlxRect disableMouse (new FlxRect 0 0 0 0))
(method &override :Void update [:Float elapsed]
(super.update elapsed)
(if (windowIsShown)
(set FlxMouseControl.mouseZone disableMouse)
(set FlxMouseControl.mouseZone null))
(#when debug
(debugLayer.clear)
@@ -60,17 +64,18 @@
(unless z.isEmpty
(debugLayer.drawFlxRect z FlxColor.RED)))))))
(when model.rewardFiles
(let [zoom pieceCamera.zoom
scroll (pieceCamera.scroll.copyTo)]
(pieceCamera.updateScrollWheelZoom elapsed 5)
(pieceCamera.updateMouseBorderControl elapsed KEYBOARD_SCROLL_SPEED 0.002 uiCamera)
(when (or !(= zoom pieceCamera.zoom) !(scroll.equals pieceCamera.scroll))
(set save.data.zoom pieceCamera.zoom)
(set save.data.scroll pieceCamera.scroll)
(save.flush)))
(when model.rewardFiles
(unless (windowIsShown)
(let [zoom pieceCamera.zoom
scroll (pieceCamera.scroll.copyTo)]
(pieceCamera.updateScrollWheelZoom elapsed 5)
(pieceCamera.updateMouseBorderControl elapsed KEYBOARD_SCROLL_SPEED 0.002 uiCamera)
(when (or !(= zoom pieceCamera.zoom) !(scroll.equals pieceCamera.scroll))
(set save.data.zoom pieceCamera.zoom)
(set save.data.scroll pieceCamera.scroll)
(save.flush))))
(when entryWindow
(when (and entryWindow !(tempWindowIsShown))
(when FlxG.keys.justPressed.ESCAPE
(if (entryWindow.isShown)
(entryWindow.hide)
@@ -97,15 +102,15 @@
// TODO provide a saner/configurable set of bindings to trigger these ui action functions
{
(when FlxG.mouse.justPressedRight
(when draggingSprite
(draggingSprite.rotate 90)
(doFor s (recursivelyConnectedPieces draggingSprite)
(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))
(save.flush)))
(unless (windowIsShown)
(when FlxG.mouse.justPressedRight
(when draggingSprite
(draggingSprite.rotate 90)
(doFor s (recursivelyConnectedPieces draggingSprite)
(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))
(save.flush))))
(method startAdding [:EntryType type]
(set typeAdding type)
@@ -142,6 +147,20 @@
(prop &mut :FlxSave save 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 :FlxKeyShortcutHandler<Entry> shortcutHandler null)

View File

@@ -80,14 +80,22 @@ class DragToSelectPlugin extends FlxBasic {
var camera = dragState.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
// can get first access to the mouse input
if (FlxMouseControl.dragTarget == null) {
if (wasJustPressed && FlxMouseControl.clickTarget == null) {
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) {
var rounded1 = dragState.firstCorner.copyTo();
var rounded2 = dragState.secondCorner.copyTo();