[client] rename frame => view
This commit is contained in:
83
src/client/haxe/ru/m/tankz/view/settings/ActionView.hx
Executable file
83
src/client/haxe/ru/m/tankz/view/settings/ActionView.hx
Executable file
@@ -0,0 +1,83 @@
|
||||
package ru.m.tankz.view.settings;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
import openfl.Assets;
|
||||
import openfl.events.KeyboardEvent;
|
||||
import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class KeyboardMap {
|
||||
|
||||
private var data:Map<Int, String>;
|
||||
|
||||
public function new() {
|
||||
this.data = new Map();
|
||||
var data = Assets.getText("resources/keyboard.txt");
|
||||
for (line in data.split("\n")) {
|
||||
var arr = line.split("\t");
|
||||
if (arr.length == 2) {
|
||||
this.data.set(Std.parseInt(arr[1]), arr[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static var instance: KeyboardMap;
|
||||
|
||||
public static function getName(key: Int): String {
|
||||
if (instance == null) instance = new KeyboardMap();
|
||||
return key == -1 ? "<NONE>" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||
}
|
||||
}
|
||||
|
||||
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):ActionItem;
|
||||
|
||||
@:view var action(default, null):LabelView;
|
||||
@:view var key(default, null):LabelView;
|
||||
|
||||
private var editDeferred: Deferred<Int>;
|
||||
|
||||
private static function actionLabel(action: TankAction): String {
|
||||
return switch (action) {
|
||||
case TankAction.SHOT: "SHOT";
|
||||
case TankAction.MOVE(d): 'MOVE_$d';
|
||||
case x: '$x';
|
||||
}
|
||||
}
|
||||
|
||||
private static function keyLabel(key: Int): String {
|
||||
return KeyboardMap.getName(key);
|
||||
}
|
||||
|
||||
private function set_data(value:ActionItem):ActionItem {
|
||||
data = value;
|
||||
action.text = actionLabel(data.action);
|
||||
key.text = keyLabel(data.key);
|
||||
return data;
|
||||
}
|
||||
|
||||
public function edit():Promise<Int> {
|
||||
action.skinId = key.skinId = "text.box.active";
|
||||
toRedraw();
|
||||
editDeferred = new Deferred();
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
return editDeferred.promise();
|
||||
}
|
||||
|
||||
private function onKeyDown(event: KeyboardEvent):Void {
|
||||
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
action.skinId = key.skinId = "text.box";
|
||||
toRedraw();
|
||||
data.key = event.keyCode;
|
||||
key.text = keyLabel(data.key);
|
||||
editDeferred.resolve(data.key);
|
||||
editDeferred = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user