[client] SettingsEditor fixes
This commit is contained in:
@@ -3,5 +3,6 @@ package ru.m.control;
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@@ -34,6 +36,15 @@ class HumanControl extends Control {
|
||||
moveQueue = [];
|
||||
}
|
||||
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
if (binding.exists(device) && binding[device].exists(action)) {
|
||||
toggleAction(binding[device][action], on);
|
||||
|
||||
@@ -29,8 +29,7 @@ class SettingsStorage extends SharedObjectStorage {
|
||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
||||
}
|
||||
|
||||
public static function buildGamepadBinding(id:Int):Binding {
|
||||
var device = GAMEPAD(id);
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
|
||||
@@ -5,6 +5,7 @@ import haxework.view.frame.FrameView;
|
||||
import haxework.view.layout.DefaultLayout;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.IGame;
|
||||
@@ -45,17 +46,6 @@ import ru.m.tankz.view.gamepad.GamepadView;
|
||||
|
||||
override public function onShow(data:GameInit):Void {
|
||||
gamepad.visible = false;
|
||||
// ToDo:
|
||||
for (i in 0...1) {
|
||||
for (bind in settings.getBinding(i)) {
|
||||
switch bind.device {
|
||||
case GAMEPAD(GamepadView.ID):
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
game = switch data {
|
||||
case LOCAL(start): new LocalGame(start);
|
||||
case NETWORK(network): new NetworkGame(network);
|
||||
@@ -71,6 +61,15 @@ import ru.m.tankz.view.gamepad.GamepadView;
|
||||
}
|
||||
game.connect(this);
|
||||
game.start();
|
||||
// ToDo:
|
||||
for (control in game.controls) {
|
||||
if (Std.is(control, HumanControl)) {
|
||||
if (cast(control, HumanControl).hasDevice(SCREEN)) {
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
|
||||
@@ -48,7 +48,7 @@ using ru.m.tankz.view.ViewUtil;
|
||||
var players = Lambda.array(result.state.players);
|
||||
players.sort(function(a, b) return a.id.compare(b.id));
|
||||
resultView.data = players;
|
||||
levelLabel.text = data.level.levelLabel();
|
||||
levelLabel.text = data.level.toLevelLabel();
|
||||
nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId);
|
||||
nextButton.text = 'Next #${result.level.id + 1}';
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ using ru.m.tankz.view.ViewUtil;
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
this.progress = storage.get(start.level.packId);
|
||||
header.text = start.level.levelLabel();
|
||||
header.text = start.level.toLevelLabel();
|
||||
presetsView.data = start.state.config.presets;
|
||||
teamsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,56 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import openfl.Assets;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Binding;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
class ViewUtil {
|
||||
|
||||
public static function levelLabel(level:LevelConfig):String {
|
||||
public static function toLevelLabel(level:LevelConfig):String {
|
||||
var result:Array<String> = ['${level.packId.type} #${level.id}'];
|
||||
if (level.name != null) {
|
||||
result.push(level.name);
|
||||
}
|
||||
return result.join("\n");
|
||||
}
|
||||
|
||||
public static function toActionLabel(action:TankAction):String {
|
||||
return switch (action) {
|
||||
case MOVE(d): 'MOVE_$d';
|
||||
case x: '$x';
|
||||
}
|
||||
}
|
||||
|
||||
public static function toBindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import ru.m.control.IControlDevice;
|
||||
import ru.m.geom.Point;
|
||||
|
||||
class GamepadView extends SpriteView implements IControlDevice {
|
||||
public static var ID(default, never):Int = -128;
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
@@ -25,7 +24,7 @@ class GamepadView extends SpriteView implements IControlDevice {
|
||||
public function new() {
|
||||
super();
|
||||
style = "gamepad";
|
||||
type = GAMEPAD(ID);
|
||||
type = SCREEN;
|
||||
builder = new SmartActionAreaBuilder();
|
||||
signal = new Signal2();
|
||||
areas = [];
|
||||
|
||||
@@ -28,5 +28,6 @@ class RhombusActionArea implements IActionArea {
|
||||
graphics.lineTo(rectangle.right, rectangle.y + rectangle.height / 2);
|
||||
graphics.lineTo(rectangle.x + rectangle.width / 2, rectangle.bottom);
|
||||
graphics.lineTo(rectangle.left, rectangle.y + rectangle.height / 2);
|
||||
graphics.lineTo(rectangle.x + rectangle.width / 2, rectangle.top);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ class SmartActionAreaBuilder implements IActionAreaBuilder {
|
||||
|
||||
public function build(width:Float, height:Float):Array<IActionArea> {
|
||||
var areas:Array<IActionArea> = [];
|
||||
var size = Math.min(width, height) / 6;
|
||||
var padding = size / 2;
|
||||
var size = Math.min(width, height) / 5;
|
||||
var padding = size / 3;
|
||||
// top
|
||||
areas.push(new RhombusActionArea(
|
||||
DIRECTION(Direction.TOP),
|
||||
|
||||
@@ -1,42 +1,18 @@
|
||||
package ru.m.tankz.view.settings;
|
||||
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.list.ListView;
|
||||
import openfl.Assets;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
typedef ActionItem = {
|
||||
var action:TankAction;
|
||||
var bind:BindAction;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -47,25 +23,10 @@ class KeyboardMap {
|
||||
@:view var action(default, null):LabelView;
|
||||
@:view var key(default, null):LabelView;
|
||||
|
||||
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 bindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
|
||||
private function set_data(value:ActionItem):ActionItem {
|
||||
data = value;
|
||||
action.text = actionLabel(data.action);
|
||||
key.text = bindLabel(data.bind);
|
||||
action.text = data.action.toActionLabel();
|
||||
key.text = data.bind.toBindLabel();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.view.gamepad.GamepadView;
|
||||
import ru.m.tankz.view.settings.ActionView;
|
||||
|
||||
class BindEditor {
|
||||
@@ -98,7 +97,7 @@ class BindEditor {
|
||||
}
|
||||
|
||||
private function screen():Void {
|
||||
list.data = bindingToArray(SettingsStorage.buildGamepadBinding(GamepadView.ID));
|
||||
list.data = bindingToArray(SettingsStorage.buildDeviceBinding(SCREEN));
|
||||
list.toUpdate();
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ views:
|
||||
$type: haxework.view.group.GroupView
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 2
|
||||
margin: 10
|
||||
geometry.width: 100%
|
||||
views:
|
||||
@@ -19,9 +18,6 @@ views:
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~change()
|
||||
text: Change
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~clear()
|
||||
text: Clear
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~default_()
|
||||
text: Default
|
||||
|
||||
Reference in New Issue
Block a user