From 67dbe9a5998979c43b7fc49fd3cbb142f5555b00 Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Tue, 16 Apr 2024 13:19:16 +0200 Subject: [PATCH] Better selection! --- source/funkin/editors/stage/StageEditor.hx | 9 ++++++--- source/funkin/editors/ui/UIUtil.hx | 23 ++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/source/funkin/editors/stage/StageEditor.hx b/source/funkin/editors/stage/StageEditor.hx index b552d415..201f333a 100644 --- a/source/funkin/editors/stage/StageEditor.hx +++ b/source/funkin/editors/stage/StageEditor.hx @@ -563,10 +563,14 @@ class StageEditor extends UIState { } public function selectSprite(_sprite:FunkinSprite) { - _select_deselect(null, false); + if(!UIUtil.getKeyState(CONTROL, PRESSED)) + _select_deselect(null, false); if(_sprite is FunkinSprite) { - selection = new Selection([cast _sprite]); + if(selection.contains(_sprite)) + selection.remove(_sprite); + else + selection.push(_sprite); } updateSelection(); } @@ -604,7 +608,6 @@ class StageEditor extends UIState { } function _select_deselect(_, checkSelection:Bool = true) { - var sprites = getSprites();// && o.animateAtlas == null); selection = new Selection(); if(checkSelection) updateSelection(); } diff --git a/source/funkin/editors/ui/UIUtil.hx b/source/funkin/editors/ui/UIUtil.hx index 7f9de548..4a5a0ee4 100644 --- a/source/funkin/editors/ui/UIUtil.hx +++ b/source/funkin/editors/ui/UIUtil.hx @@ -1,5 +1,6 @@ package funkin.editors.ui; +import flixel.input.FlxInput.FlxInputState; import flixel.input.keyboard.FlxKey; import funkin.editors.ui.UIContextMenu.UIContextMenuOption; @@ -14,6 +15,19 @@ class UIUtil { return contextMenu != null && UIState.state.curContextMenu == contextMenu; } + @:noUsing public static function fixKey(key:FlxKey):FlxKey { + return switch(key) { + #if mac + case CONTROL: WINDOWS; // Remap control to the meta key + #end + default: key; + } + } + + public static function getKeyState(key:FlxKey, Status:FlxInputState):Bool { + return FlxG.keys.checkStatus(fixKey(key), Status); + } + /** * Process all options with shortcuts present in a `Array`. Also checks childrens. * @param topMenuOptions @@ -41,14 +55,7 @@ class UIUtil { var shouldPress = Std.int(key) > 0; if(!shouldPress) key = -key; - var k = switch(key) { - #if mac - case CONTROL: - WINDOWS; - #end - default: - key; - } + var k = fixKey(key); if (FlxG.keys.checkStatus(k, shouldPress ? JUST_PRESSED : JUST_RELEASED)) { justPressed = true; } else if (!FlxG.keys.checkStatus(k, shouldPress ? PRESSED : RELEASED)) {