1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-08-20 07:25:59 +00:00

New shortcut handler

This commit is contained in:
EliteMasterEric 2023-10-28 19:56:34 -04:00
parent 0a4e0861cc
commit d5cf9bfc22
5 changed files with 105 additions and 6 deletions

View file

@ -49,22 +49,20 @@
"name": "haxeui-core",
"type": "git",
"dir": null,
"ref": "e92d5cfac847943fac84696b103670d55c2c774f",
"ref": "815e94dd5aa6cf09c5ddcef1666a54449ffde8dc",
"url": "https://github.com/haxeui/haxeui-core"
},
{
"name": "haxeui-flixel",
"type": "git",
"dir": null,
"ref": "be0b18553189a55fd42821026618a18615b070e3",
"ref": "9bd0b9e0fea40b8e06a89aac4949512d95064609",
"url": "https://github.com/haxeui/haxeui-flixel"
},
{
"name": "hmm",
"type": "git",
"dir": null,
"ref": "d514d7786cabf18b90e60fcee38399fd44c2ddfb",
"url": "https://github.com/andywhite37/hmm"
"type": "haxelib",
"version": "3.1.0"
},
{
"name": "hscript",

View file

@ -49,6 +49,7 @@ import funkin.data.song.SongDataUtils;
import funkin.ui.debug.charting.ChartEditorCommand;
import funkin.ui.debug.charting.ChartEditorCommand;
import funkin.ui.debug.charting.ChartEditorThemeHandler.ChartEditorTheme;
import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler;
import funkin.ui.debug.charting.ChartEditorToolboxHandler.ChartEditorToolMode;
import funkin.ui.haxeui.components.CharacterPlayer;
import funkin.ui.haxeui.HaxeUIState;
@ -1268,6 +1269,7 @@ class ChartEditorState extends HaxeUIState
buildSelectionBox();
buildAdditionalUI();
ChartEditorShortcutHandler.applyPlatformShortcutText(this);
// Setup the onClick listeners for the UI after it's been created.
setupUIListeners();

View file

@ -0,0 +1,61 @@
package funkin.ui.debug.charting.handlers;
import funkin.util.PlatformUtil;
@:access(funkin.ui.debug.charting.ChartEditorState)
class ChartEditorShortcutHandler
{
public static function applyPlatformShortcutText(state:ChartEditorState):Void
{
state.setComponentShortcutText('menubarItemNewChart', ctrlOrCmd('N'));
state.setComponentShortcutText('menubarItemOpenChart', ctrlOrCmd('O'));
state.setComponentShortcutText('menubarItemSaveChartAs', ctrlOrCmd(shift('S')));
state.setComponentShortcutText('menubarItemExit', ctrlOrCmd('Q'));
state.setComponentShortcutText('menubarItemUndo', ctrlOrCmd('Z'));
state.setComponentShortcutText('menubarItemRedo', ctrlOrCmd('Y'));
state.setComponentShortcutText('menubarItemCut', ctrlOrCmd('X'));
state.setComponentShortcutText('menubarItemCopy', ctrlOrCmd('C'));
state.setComponentShortcutText('menubarItemPaste', ctrlOrCmd('V'));
state.setComponentShortcutText('menubarItemSelectAll', ctrlOrCmd('A'));
state.setComponentShortcutText('menubarItemSelectInverse', ctrlOrCmd('I'));
state.setComponentShortcutText('menubarItemSelectNone', ctrlOrCmd('D'));
state.setComponentShortcutText('menubarItemSelectBeforeCursor', shift('Home'));
state.setComponentShortcutText('menubarItemSelectAfterCursor', shift('End'));
state.setComponentShortcutText('menubarItemDifficultyDown', ctrlOrCmd(''));
state.setComponentShortcutText('menubarItemDifficultyUp', ctrlOrCmd(''));
state.setComponentShortcutText('menubarItemPlaytestFull', 'Enter');
state.setComponentShortcutText('menubarItemPlaytestMinimal', shift('Enter'));
}
/**
* Display `Ctrl` on Windows and `` (Command) on macOS.
* @param input
*/
static inline function ctrlOrCmd(input:String)
{
return (PlatformUtil.isMacOS()) ? '+${input}' : 'Ctrl+${input}';
}
/**
* Display `Ctrl` on Windows and `^` (Control) on macOS.
* @param input
*/
static inline function ctrl(input:String)
{
return (PlatformUtil.isMacOS()) ? '^+${input}' : 'Ctrl+${input}';
}
static inline function alt(input:String)
{
return (PlatformUtil.isMacOS()) ? '+${input}' : 'Alt+${input}';
}
static inline function shift(input:String)
{
return (PlatformUtil.isMacOS()) ? '+${input}' : 'Shift+${input}';
}
}

View file

@ -2,6 +2,7 @@ package funkin.ui.haxeui;
import haxe.ui.components.CheckBox;
import haxe.ui.containers.menus.MenuCheckBox;
import haxe.ui.containers.menus.MenuItem;
import haxe.ui.core.Component;
import haxe.ui.core.Screen;
import haxe.ui.events.MouseEvent;
@ -122,6 +123,20 @@ class HaxeUIState extends MusicBeatState
}
}
function setComponentShortcutText(key:String, text:String):Void
{
var target:MenuItem = findComponent(key, MenuItem);
if (target == null)
{
// Gracefully handle the case where the item can't be located.
trace('WARN: Could not locate menu item: $key');
}
else
{
target.shortcutText = text;
}
}
/**
* Add an onChange listener to a HaxeUI input component such as a slider or text field.
*/

View file

@ -0,0 +1,23 @@
package funkin.util;
class PlatformUtil
{
/**
* Returns true if the current platform is MacOS.
*
* NOTE: Only use this for choosing modifier keys for shortcut hints.
* @return Whether the current platform is MacOS, or HTML5 running on MacOS.
*/
public static function isMacOS():Bool
{
#if mac
return true;
#elseif html5
return js.html.Navigator.platform.startsWith("Mac")
|| js.html.Navigator.platform.startsWith("iPad")
|| js.html.Navigator.platform.startsWith("iPhone");
#else
return false;
#end
}
}