Skip to content

Commit 8a79873

Browse files
committed
Right click select
Can deselect selected sprite with control Can right click on selection mode and current selection labels Ctrl Deez None! Current selection text no longer appears while hovering over UI or testing Prevent inputs when welcome dialog open
1 parent 8cd3785 commit 8a79873

File tree

1 file changed

+105
-83
lines changed

1 file changed

+105
-83
lines changed

source/funkin/ui/debug/stageeditor/StageEditorState.hx

Lines changed: 105 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class StageEditorState extends UIState
102102
var menubarItemDelete:MenuItem; // delete
103103
var menubarItemNewObj:MenuItem; // new
104104
var menubarItemFindObj:MenuItem; // find
105+
var menubarItemSelectNone:MenuItem; // access none
105106
var menubarItemMoveStep:Menu; // move step submenu
106107

107108
var menubarMenuView:Menu;
@@ -141,6 +142,7 @@ class StageEditorState extends UIState
141142
{
142143
selectedSprite?.selectedShader.setAmount(0);
143144
this.selectedSprite = value;
145+
infoSelection = value?.name ?? "None";
144146
updateDialog(StageEditorDialogType.OBJECT_GRAPHIC);
145147
updateDialog(StageEditorDialogType.OBJECT_ANIMS);
146148
updateDialog(StageEditorDialogType.OBJECT_PROPERTIES);
@@ -161,6 +163,7 @@ class StageEditorState extends UIState
161163
function set_selectedChar(value:BaseCharacter)
162164
{
163165
this.selectedChar = value;
166+
infoSelection = Std.string(value?.characterType) ?? "None";
164167
updateDialog(StageEditorDialogType.CHARACTER);
165168
return selectedChar;
166169
}
@@ -579,7 +582,6 @@ class StageEditorState extends UIState
579582

580583
// testmode
581584
menubarMenuFile.disabled = menubarMenuEdit.disabled = bottomBarModeText.disabled = menubarMenuWindow.disabled = testingMode;
582-
menubarButtonText.selected = testingMode;
583585

584586
if (testingMode)
585587
{
@@ -596,6 +598,7 @@ class StageEditorState extends UIState
596598
if (FlxG.keys.justPressed.TAB && !FlxG.keys.pressed.SHIFT) curTestChar++;
597599

598600
if (curTestChar >= getCharacters().length) curTestChar = 0;
601+
else if (curTestChar < 0) curTestChar = getCharacters().length - 1;
599602

600603
bottomBarSelectText.text = Std.string(getCharacters()[curTestChar].characterType);
601604

@@ -625,10 +628,11 @@ class StageEditorState extends UIState
625628
}
626629

627630
// key shortcuts and inputs
628-
if (allowInput)
631+
if (pressingControl() && FlxG.keys.justPressed.Q) onMenuItemClick("exit");
632+
633+
if (allowInput && welcomeDialog == null)
629634
{
630-
// "WINDOWS" key code is the same keycode as COMMAND on mac
631-
if (FlxG.keys.pressed.CONTROL || FlxG.keys.pressed.WINDOWS)
635+
if (pressingControl())
632636
{
633637
if (FlxG.keys.justPressed.Z) onMenuItemClick("undo");
634638
if (FlxG.keys.justPressed.Y) onMenuItemClick("redo");
@@ -637,9 +641,9 @@ class StageEditorState extends UIState
637641
if (FlxG.keys.justPressed.X) onMenuItemClick("cut object");
638642
if (FlxG.keys.justPressed.S) FlxG.keys.pressed.SHIFT ? onMenuItemClick("save stage as") : onMenuItemClick("save stage");
639643
if (FlxG.keys.justPressed.F) onMenuItemClick("find object");
644+
if (FlxG.keys.justPressed.D) onMenuItemClick("select none");
640645
if (FlxG.keys.justPressed.O) onMenuItemClick("open stage");
641646
if (FlxG.keys.justPressed.N) onMenuItemClick("new stage");
642-
if (FlxG.keys.justPressed.Q) onMenuItemClick("exit");
643647
}
644648

645649
if (FlxG.keys.justPressed.TAB) onMenuItemClick("switch mode");
@@ -653,7 +657,8 @@ class StageEditorState extends UIState
653657
FlxG.camera.zoom = 1;
654658
}
655659

656-
if (FlxG.keys.pressed.W || FlxG.keys.pressed.S || FlxG.keys.pressed.A || FlxG.keys.pressed.D)
660+
if (!pressingControl()
661+
&& (FlxG.keys.pressed.W || FlxG.keys.pressed.S || FlxG.keys.pressed.A || FlxG.keys.pressed.D))
657662
{
658663
if (FlxG.keys.pressed.W) camFollow.velocity.y = -90 * (2 / FlxG.camera.zoom);
659664
else if (FlxG.keys.pressed.S) camFollow.velocity.y = 90 * (2 / FlxG.camera.zoom);
@@ -680,30 +685,33 @@ class StageEditorState extends UIState
680685

681686
if (moveMode == "assets")
682687
{
683-
if (selectedSprite != null && !FlxG.mouse.overlaps(selectedSprite) && FlxG.mouse.justPressed && !isCursorOverHaxeUI)
688+
if (selectedSprite != null
689+
&& (!FlxG.mouse.overlaps(selectedSprite)
690+
|| (FlxG.mouse.overlaps(selectedSprite) && pressingControl()))
691+
&& FlxG.mouse.justPressed
692+
&& !isCursorOverHaxeUI)
684693
{
685694
selectedSprite = null;
686695
}
687696

688-
for (spr in spriteArray)
697+
if (!isCursorOverHaxeUI)
689698
{
690-
if (FlxG.mouse.overlaps(spr))
699+
if (menubarItemViewNameText.selected) nameTxt.visible = true;
700+
for (spr in spriteArray)
691701
{
692-
if (spr.visible && !FlxG.keys.pressed.SHIFT) nameTxt.text = spr.name;
693-
694-
if (FlxG.mouse.justPressed && allowInput && spr.visible && !FlxG.keys.pressed.SHIFT && !isCursorOverHaxeUI)
702+
if (!pressingControl() && FlxG.mouse.overlaps(spr))
695703
{
696-
selectedSprite = spr;
697-
}
698-
}
704+
if (spr.visible && !FlxG.keys.pressed.SHIFT) nameTxt.text = spr.name;
699705

700-
if (spr == selectedSprite)
701-
{
702-
infoSelection = spr.name;
703-
704-
if (FlxG.keys.pressed.SHIFT) nameTxt.text = spr.name + " (LOCKED)";
706+
if (FlxG.mouse.justPressed && allowInput && spr.visible && !FlxG.keys.pressed.SHIFT)
707+
{
708+
selectedSprite = spr;
709+
}
710+
}
705711
}
712+
if (selectedSprite != null && FlxG.keys.pressed.SHIFT) nameTxt.text = selectedSprite.name + " (LOCKED)";
706713
}
714+
else if (nameTxt.visible) nameTxt.visible = false;
707715

708716
if (FlxG.mouse.pressed && allowInput && selectedSprite != null && FlxG.mouse.overlaps(selectedSprite) && FlxG.mouse.justMoved && !isCursorOverHaxeUI)
709717
{
@@ -745,29 +753,26 @@ class StageEditorState extends UIState
745753
else
746754
{
747755
selectedChar.shader = null;
748-
749-
for (char in getCharacters())
756+
if (!isCursorOverHaxeUI)
750757
{
751-
if (char != selectedChar) char.shader = charDeselectShader;
752-
753-
if (char != null && checkCharOverlaps(char)) // flxg.mouse.overlaps crashes the game
758+
if (menubarItemViewNameText.selected) nameTxt.visible = true;
759+
for (char in getCharacters())
754760
{
755-
if (char.visible && !FlxG.keys.pressed.SHIFT) nameTxt.text = Std.string(char.characterType);
761+
if (char != selectedChar) char.shader = charDeselectShader;
756762

757-
if (FlxG.mouse.justPressed && allowInput && char.visible && !FlxG.keys.pressed.SHIFT && !isCursorOverHaxeUI)
763+
if (char != null && checkCharOverlaps(char)) // flxg.mouse.overlaps crashes the game
758764
{
759-
selectedChar = char;
760-
updateDialog(StageEditorDialogType.CHARACTER);
761-
}
762-
}
763-
764-
if (selectedChar == char)
765-
{
766-
infoSelection = Std.string(char.characterType);
765+
if (char.visible && !FlxG.keys.pressed.SHIFT) nameTxt.text = Std.string(char.characterType);
767766

768-
if (FlxG.keys.pressed.SHIFT) nameTxt.text = Std.string(char.characterType) + " (LOCKED)";
767+
if (FlxG.mouse.justPressed && allowInput && char.visible && !FlxG.keys.pressed.SHIFT && !isCursorOverHaxeUI)
768+
{
769+
selectedChar = char;
770+
}
771+
}
769772
}
773+
if (selectedChar != null && FlxG.keys.pressed.SHIFT) nameTxt.text = Std.string(selectedChar.characterType) + " (LOCKED)";
770774
}
775+
else if (nameTxt.visible) nameTxt.visible = false;
771776

772777
if (FlxG.mouse.pressed && allowInput && checkCharOverlaps(selectedChar) && FlxG.mouse.justMoved && !isCursorOverHaxeUI)
773778
{
@@ -793,8 +798,6 @@ class StageEditorState extends UIState
793798
arrowMovement(selectedChar);
794799
updateMarkerPos();
795800
}
796-
797-
if ((selectedSprite == null && moveMode == "assets") || (selectedChar == null && moveMode == "chars")) infoSelection = "None";
798801
bottomBarSelectText.text = infoSelection;
799802

800803
// ui stuff
@@ -815,6 +818,20 @@ class StageEditorState extends UIState
815818
menubarItemRedo.disabled = redoArray.length == 0;
816819
}
817820

821+
/**
822+
* Small helper for MacOS, "WINDOWS" is keycode 15, which maps to "COMMAND" on Mac, which is more often used than "CONTROL"
823+
* Everywhere else, it just returns `FlxG.keys.pressed.CONTROL`
824+
* @return Bool
825+
*/
826+
function pressingControl():Bool
827+
{
828+
#if mac
829+
return FlxG.keys.pressed.WINDOWS;
830+
#else
831+
return FlxG.keys.pressed.CONTROL;
832+
#end
833+
}
834+
818835
public function getCharacters()
819836
{
820837
return [gf, dad, bf];
@@ -905,7 +922,7 @@ class StageEditorState extends UIState
905922
if (obj == null) return;
906923
if (FlxG.keys.pressed.R) return; // rotations
907924

908-
if (allowInput)
925+
if (allowInput && welcomeDialog == null)
909926
{
910927
if ((FlxG.keys.justPressed.UP || FlxG.keys.justPressed.DOWN || FlxG.keys.justPressed.LEFT || FlxG.keys.justPressed.RIGHT)
911928
&& !moveUndoed)
@@ -1009,17 +1026,6 @@ class StageEditorState extends UIState
10091026
bg.screenCenter();
10101027
}
10111028

1012-
function checkOverlaps(spr:FlxSprite):Bool
1013-
{
1014-
if (FlxG.mouse.overlaps(spr) /*spr.overlapsPoint(FlxG.mouse.getWorldPosition(spr.camera), true, spr.camera) */
1015-
&& Screen.instance != null
1016-
&& !Screen.instance.hasSolidComponentUnderPoint(FlxG.mouse.viewX, FlxG.mouse.viewY)
1017-
&& WindowManager.instance.windows.length == 0) // ik its stupid but maybe I have other cases soon (i did)
1018-
return true;
1019-
1020-
return false;
1021-
}
1022-
10231029
var sprDependant:Array<MenuItem> = [];
10241030

10251031
function addUI():Void
@@ -1038,13 +1044,49 @@ class StageEditorState extends UIState
10381044
menubarItemDelete.onClick = function(_) onMenuItemClick("delete object");
10391045
menubarItemNewObj.onClick = function(_) onMenuItemClick("new object");
10401046
menubarItemFindObj.onClick = function(_) onMenuItemClick("find object");
1047+
menubarItemSelectNone.onClick = function(_) onMenuItemClick("select none");
10411048
menubarButtonText.onClick = function(_) onMenuItemClick("test stage");
10421049
menubarItemUserGuide.onClick = function(_) onMenuItemClick("user guide");
10431050
menubarItemGoToBackupsFolder.onClick = function(_) onMenuItemClick("open folder");
10441051
menubarItemAbout.onClick = function(_) onMenuItemClick("about");
10451052

10461053
bottomBarModeText.onClick = function(_) onMenuItemClick("switch mode");
1047-
bottomBarSelectText.onClick = function(_) onMenuItemClick("switch focus");
1054+
bottomBarModeText.onRightClick = function(_) onMenuItemClick("switch mode");
1055+
1056+
function switchFocus(rightClick:Bool = false)
1057+
if (testingMode)
1058+
{
1059+
(rightClick) ? curTestChar-- : curTestChar++;
1060+
}
1061+
else
1062+
{
1063+
if (moveMode == "chars")
1064+
{
1065+
var chars = getCharacters();
1066+
var index = chars.indexOf(selectedChar);
1067+
(rightClick) ? index-- : index++;
1068+
1069+
if (index >= chars.length) index = 0;
1070+
else if (index < 0) index = chars.length - 1;
1071+
1072+
selectedChar = chars[index];
1073+
}
1074+
else
1075+
{
1076+
if (selectedSprite == null || FlxG.keys.pressed.SHIFT) return;
1077+
1078+
var index = spriteArray.indexOf(selectedSprite);
1079+
(rightClick) ? index-- : index++;
1080+
1081+
if (index >= spriteArray.length) index = 0;
1082+
else if (index < 0) index = spriteArray.length - 1;
1083+
1084+
selectedSprite = spriteArray[index];
1085+
}
1086+
}
1087+
1088+
bottomBarSelectText.onClick = function(_) switchFocus();
1089+
bottomBarSelectText.onRightClick = function(_) switchFocus(true);
10481090

10491091
var stepOptions = ["1px", "2px", "3px", "5px", "10px", "25px", "50px", "100px"];
10501092
bottomBarMoveStepText.text = stepOptions.contains(Save.instance.stageEditorMoveStep) ? Save.instance.stageEditorMoveStep : "1px";
@@ -1118,6 +1160,7 @@ class StageEditorState extends UIState
11181160

11191161
menubarItemViewChars.onChange = function(_) showChars = menubarItemViewChars.selected;
11201162
menubarItemViewNameText.onChange = function(_) nameTxt.visible = menubarItemViewNameText.selected;
1163+
menubarItemViewNameText.selected = true; // TODO: Remove this when this haxeUI bug is fixed (it starts as false in the code)?
11211164
menubarItemViewCamBounds.onChange = function(_) camFields.visible = menubarItemViewCamBounds.selected;
11221165

11231166
menubarItemViewFloorLines.onChange = function(_) {
@@ -1130,7 +1173,7 @@ class StageEditorState extends UIState
11301173
coolbeans.visible = menubarItemViewPosMarkers.selected;
11311174
}
11321175

1133-
sprDependant = [menubarItemCopy, menubarItemCut, menubarItemDelete];
1176+
sprDependant = [menubarItemCopy, menubarItemCut, menubarItemDelete, menubarItemSelectNone];
11341177
reloadRecentFiles();
11351178
}
11361179

@@ -1287,37 +1330,9 @@ class StageEditorState extends UIState
12871330
if (testingMode) return;
12881331
moveMode = (moveMode == "assets" ? "chars" : "assets");
12891332

1290-
selectedSprite?.selectedShader.setAmount((moveMode == "assets" ? 1 : 0));
1333+
infoSelection = (moveMode == "chars") ? (Std.string(selectedChar?.characterType) ?? "None") : (moveMode == "assets") ? (selectedSprite?.name ?? "None") : "Wut";
12911334

1292-
case "switch focus":
1293-
if (testingMode)
1294-
{
1295-
curTestChar++;
1296-
}
1297-
else
1298-
{
1299-
if (moveMode == "chars")
1300-
{
1301-
var chars = getCharacters();
1302-
var index = chars.indexOf(selectedChar);
1303-
index++;
1304-
1305-
if (index >= chars.length) index = 0;
1306-
1307-
selectedChar = chars[index];
1308-
}
1309-
else
1310-
{
1311-
if (selectedSprite == null) return;
1312-
1313-
var index = spriteArray.indexOf(selectedSprite);
1314-
index++;
1315-
1316-
if (index >= spriteArray.length) index = 0;
1317-
1318-
selectedSprite = spriteArray[index];
1319-
}
1320-
}
1335+
selectedSprite?.selectedShader.setAmount((moveMode == "assets" ? 1 : 0));
13211336

13221337
case "new object":
13231338
findObjDialog.hideDialog(DialogButton.CANCEL);
@@ -1336,6 +1351,12 @@ class StageEditorState extends UIState
13361351
findObjDialog = new FindObjDialog(this, selectedSprite == null ? "" : selectedSprite.name);
13371352
findObjDialog.showDialog(false);
13381353

1354+
case "select none":
1355+
if (menubarItemSelectNone.disabled == false)
1356+
{
1357+
selectedSprite = null;
1358+
}
1359+
13391360
case "about":
13401361
aboutDialog = new AboutDialog();
13411362
aboutDialog.showDialog();
@@ -1369,6 +1390,8 @@ class StageEditorState extends UIState
13691390
{
13701391
menubarItemWindowObjectGraphic.selected = menubarItemWindowObjectAnims.selected = menubarItemWindowObjectProps.selected = menubarItemWindowCharacter.selected = menubarItemWindowStage.selected = false;
13711392
}
1393+
nameTxt.exists = testingMode;
1394+
menubarButtonText.selected = !testingMode;
13721395

13731396
selectedSprite?.selectedShader.setAmount((testingMode ? (moveMode == "assets" ? 1 : 0) : 0));
13741397
testingMode = !testingMode;
@@ -1413,7 +1436,6 @@ class StageEditorState extends UIState
14131436
remove(selectedSprite, true);
14141437
selectedSprite.destroy();
14151438
selectedSprite = null;
1416-
14171439
updateArray();
14181440

14191441
case "copy object":

0 commit comments

Comments
 (0)