Skip to content

Commit 98530af

Browse files
committed
feat: Hotkey Manager
1 parent 4559357 commit 98530af

File tree

17 files changed

+1595
-111
lines changed

17 files changed

+1595
-111
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ workerswfs/
1313

1414
*.p12
1515

16+
/.history
17+
1618
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
1719
# should NOT be excluded as they contain compiler settings and other important
1820
# information for Eclipse / Flash Builder.

locale/en_US/strings.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ debug=Debug
5252
delete=Delete
5353
deleteFrame=Delete frame
5454
duplicate=Duplicate
55+
reset=Reset
5556
duplicateFrame=Duplicate frame
5657
edit=Edit
5758
edition=Edition
@@ -75,6 +76,7 @@ format=Format
7576
found=Found
7677
frameStrategy=Frame strategy
7778
general=General
79+
hotkeys=Hotkeys
7880
gettingFreeIds=Getting free ids
7981
hasingSprites=Hashing Sprites
8082
changingDurationsInItems=Changing frame durations in items
@@ -122,6 +124,7 @@ organizingSprites=Organizing sprites
122124
outfit=Outfit
123125
outfits=Outfits
124126
paste=Paste
127+
pressShortcut=Press shortcut...
125128
patterns=Patterns
126129
pause=Pause
127130
pingPong=Ping Pong

locale/es_ES/strings.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ debug=Debug
5252
delete=Borrar
5353
deleteFrame=Borrar cuadro
5454
duplicate=Duplicar
55+
reset=Restablecer
5556
duplicateFrame=Duplicar cuadro
5657
edit=Editar
5758
edition=Edición
@@ -75,6 +76,7 @@ format=Formato
7576
found=Encontrado
7677
frameStrategy=Estrategia
7778
general=General
79+
hotkeys=Atajos
7880
gettingFreeIds=Buscando IDs libres
7981
hasingSprites=Hashing Sprites
8082
changingDurationsInItems=Cambiar la duración de los fotogramas en los elementos
@@ -122,6 +124,7 @@ organizingSprites=Organizando sprites
122124
outfit=Outfit
123125
outfits=Outfits
124126
paste=Pegar
127+
pressShortcut=Presione un atajo...
125128
patterns=Patrones
126129
pause=Pausar
127130
pingPong=Ping Pong

locale/pt_BR/strings.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ debug=Debug
5252
delete=Deletar
5353
deleteFrame=Deletar quadro
5454
duplicate=Duplicar
55+
reset=Restaurar
5556
duplicateFrame=Duplicar quadro
5657
edit=Editar
5758
edition=Edição
@@ -75,6 +76,7 @@ format=Formato
7576
found=Encontrado
7677
frameStrategy=Frame strategy
7778
general=Geral
79+
hotkeys=Atalhos
7880
gettingFreeIds=Obtendo ids livres
7981
hasingSprites=Hashing Sprites
8082
changingDurationsInItems=Alterando as durações dos quadros nos itens
@@ -121,6 +123,7 @@ organizingSprites=Organizando sprites
121123
outfit=Roupa
122124
outfits=Roupas
123125
paste=Colar
126+
pressShortcut=Pressione um atalho...
124127
patterns=Padrões
125128
pause=Pausa
126129
pingPong=Ping Pong

src/ObjectBuilder.mxml

Lines changed: 356 additions & 12 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
3+
xmlns:s="library://ns.adobe.com/flex/spark"
4+
xmlns:controls="ob.components.controls.*"
5+
width="100%"
6+
verticalAlign="middle"
7+
gap="10"
8+
creationComplete="creationCompleteHandler(event)">
9+
<fx:Metadata>
10+
[ResourceBundle("strings")]
11+
</fx:Metadata>
12+
13+
<fx:Script>
14+
<![CDATA[
15+
import flash.events.Event;
16+
import flash.events.MouseEvent;
17+
18+
import mx.events.FlexEvent;
19+
import ob.events.HotkeyManagerEvent;
20+
import ob.hotkeys.HotkeyDefinition;
21+
import ob.hotkeys.HotkeyManager;
22+
23+
[Bindable]
24+
public var definition:HotkeyDefinition;
25+
26+
public var hotkeyManager:HotkeyManager;
27+
28+
protected function creationCompleteHandler(event:FlexEvent):void
29+
{
30+
if (hotkeyManager)
31+
hotkeyManager.addEventListener(HotkeyManagerEvent.HOTKEY_CHANGED, hotkeyChangedHandler, false, 0, true);
32+
33+
updateDisplay();
34+
}
35+
36+
protected function inputChangeHandler(event:Event):void
37+
{
38+
if (!definition || !hotkeyManager)
39+
return;
40+
41+
hotkeyManager.updateHotkey(definition.id, hotkeyInput.hotkey);
42+
}
43+
44+
protected function clearButtonClickHandler(event:MouseEvent):void
45+
{
46+
if (!definition || !hotkeyManager)
47+
return;
48+
49+
hotkeyManager.updateHotkey(definition.id, null);
50+
}
51+
52+
protected function resetButtonClickHandler(event:MouseEvent):void
53+
{
54+
if (!definition || !hotkeyManager)
55+
return;
56+
57+
hotkeyManager.resetHotkey(definition.id);
58+
}
59+
60+
protected function hotkeyChangedHandler(event:HotkeyManagerEvent):void
61+
{
62+
if (!definition || event.actionId != definition.id)
63+
return;
64+
65+
updateDisplay();
66+
}
67+
68+
private function updateDisplay():void
69+
{
70+
if (!definition)
71+
return;
72+
73+
actionLabel.text = definition.label;
74+
hotkeyInput.hotkey = definition.hotkey;
75+
clearButton.enabled = definition.hotkey != null;
76+
resetButton.enabled = definition.defaultHotkey != null && !definition.usesDefault();
77+
}
78+
]]>
79+
</fx:Script>
80+
81+
<s:Label id="actionLabel" width="100%" maxDisplayedLines="1"/>
82+
<controls:HotkeyInput id="hotkeyInput"
83+
width="160"
84+
change="inputChangeHandler(event)"/>
85+
<s:Button id="clearButton"
86+
minWidth="60"
87+
label="@Resource(key='clear', bundle='strings')"
88+
click="clearButtonClickHandler(event)"/>
89+
<s:Button id="resetButton"
90+
minWidth="60"
91+
label="@Resource(key='reset', bundle='strings')"
92+
click="resetButtonClickHandler(event)"/>
93+
</s:HGroup>

src/ob/components/PreferencesWindow.mxml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ THE SOFTWARE.
5353
import ob.settings.ObjectBuilderSettings;
5454
5555
import otlib.assets.Assets;
56+
import ob.components.HotkeyEditorRow;
57+
import ob.hotkeys.HotkeyDefinition;
58+
import ob.hotkeys.HotkeyManager;
59+
import spark.components.Label;
5660
5761
//--------------------------------------------------------------------------
5862
// PROPERTIES
@@ -62,6 +66,7 @@ THE SOFTWARE.
6266
private var _settingsChanged:Boolean;
6367
private var _detail:uint = DialogDetail.CANCEL;
6468
private var _languages:ArrayCollection;
69+
private var _hotkeyManager:HotkeyManager;
6570
6671
//--------------------------------------
6772
// Getters / Setters
@@ -82,6 +87,18 @@ THE SOFTWARE.
8287
8388
public function get detail():uint { return _detail; }
8489
90+
public function get hotkeyManager():HotkeyManager { return _hotkeyManager; }
91+
public function set hotkeyManager(value:HotkeyManager):void
92+
{
93+
if (_hotkeyManager == value)
94+
return;
95+
96+
_hotkeyManager = value;
97+
98+
if (initialized)
99+
rebuildHotkeyRows();
100+
}
101+
85102
//--------------------------------------------------------------------------
86103
// METHODS
87104
//--------------------------------------------------------------------------
@@ -103,6 +120,42 @@ THE SOFTWARE.
103120
}
104121
}
105122
123+
private function rebuildHotkeyRows():void
124+
{
125+
if (!hotkeyContainer)
126+
return;
127+
128+
hotkeyContainer.removeAllElements();
129+
130+
if (!_hotkeyManager)
131+
return;
132+
133+
var definitions:Array = _hotkeyManager.definitions;
134+
var currentCategory:String = null;
135+
136+
for each (var definition:HotkeyDefinition in definitions)
137+
{
138+
if (!definition)
139+
continue;
140+
141+
if (currentCategory != definition.category)
142+
{
143+
currentCategory = definition.category;
144+
145+
var header:Label = new Label();
146+
header.text = currentCategory;
147+
header.setStyle("fontWeight", "bold");
148+
hotkeyContainer.addElement(header);
149+
}
150+
151+
var row:HotkeyEditorRow = new HotkeyEditorRow();
152+
row.percentWidth = 100;
153+
row.definition = definition;
154+
row.hotkeyManager = _hotkeyManager;
155+
hotkeyContainer.addElement(row);
156+
}
157+
}
158+
106159
//--------------------------------------
107160
// Private
108161
//--------------------------------------
@@ -182,6 +235,7 @@ THE SOFTWARE.
182235
focusManager.showFocus();
183236
184237
setSettings(_settings);
238+
rebuildHotkeyRows();
185239
}
186240
187241
protected function confirmButtonClickHandler(event:MouseEvent):void
@@ -330,6 +384,18 @@ THE SOFTWARE.
330384
</mg:GroupBox>
331385

332386
</s:NavigatorContent>
387+
388+
<s:NavigatorContent label="@Resource(key='hotkeys', bundle='strings')"
389+
width="100%" height="100%">
390+
<s:layout>
391+
<s:VerticalLayout padding="10" paddingTop="20" />
392+
</s:layout>
393+
<s:Scroller width="100%" height="100%">
394+
<s:VGroup id="hotkeyContainer"
395+
width="100%"
396+
gap="10"/>
397+
</s:Scroller>
398+
</s:NavigatorContent>
333399
</mx:ViewStack>
334400

335401
<s:BorderContainer width="100%" skinClass="com.mignari.skins.PixeledBorderContainerSkin">

0 commit comments

Comments
 (0)