From a547b68dc06c972fb650d970f73f7c83e43a40a8 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 24 Jul 2019 17:32:48 +0300 Subject: [PATCH] [client] SettingsEditor fixes --- ansible/group_vars/all.yml | 2 +- src/client/haxe/ru/m/control/DeviceType.hx | 1 + .../haxe/ru/m/tankz/control/HumanControl.hx | 11 +++++ .../ru/m/tankz/storage/SettingsStorage.hx | 3 +- src/client/haxe/ru/m/tankz/view/GameFrame.hx | 21 ++++---- .../haxe/ru/m/tankz/view/ResultFrame.hx | 2 +- src/client/haxe/ru/m/tankz/view/StartFrame.hx | 2 +- src/client/haxe/ru/m/tankz/view/ViewUtil.hx | 44 ++++++++++++++++- .../ru/m/tankz/view/gamepad/GamepadView.hx | 3 +- .../m/tankz/view/gamepad/RhombusActionArea.hx | 1 + .../view/gamepad/SmartActionAreaBuilder.hx | 4 +- .../ru/m/tankz/view/settings/ActionView.hx | 49 ++----------------- .../m/tankz/view/settings/SettingsEditor.hx | 3 +- .../m/tankz/view/settings/SettingsEditor.yaml | 4 -- 14 files changed, 79 insertions(+), 71 deletions(-) diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 22c7feb..14cc1f7 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -5,7 +5,7 @@ project_user: holop deploy_user: "{{ project_user }}" deploy_project: "{{ project_name }}" deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git" -deploy_repo_version: master +deploy_repo_version: develop deploy_npm: yes service_name: "{{ project_name }}" diff --git a/src/client/haxe/ru/m/control/DeviceType.hx b/src/client/haxe/ru/m/control/DeviceType.hx index 7d47901..0455309 100644 --- a/src/client/haxe/ru/m/control/DeviceType.hx +++ b/src/client/haxe/ru/m/control/DeviceType.hx @@ -3,5 +3,6 @@ package ru.m.control; enum DeviceType { NONE; KEYBOARD; + SCREEN; GAMEPAD(id:Int); } diff --git a/src/client/haxe/ru/m/tankz/control/HumanControl.hx b/src/client/haxe/ru/m/tankz/control/HumanControl.hx index 57a19c0..617eb64 100644 --- a/src/client/haxe/ru/m/tankz/control/HumanControl.hx +++ b/src/client/haxe/ru/m/tankz/control/HumanControl.hx @@ -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); diff --git a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx index 03b698c..785c37d 100644 --- a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx +++ b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx @@ -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)}, diff --git a/src/client/haxe/ru/m/tankz/view/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/GameFrame.hx index ebbe7b6..28bbb93 100644 --- a/src/client/haxe/ru/m/tankz/view/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/GameFrame.hx @@ -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 { diff --git a/src/client/haxe/ru/m/tankz/view/ResultFrame.hx b/src/client/haxe/ru/m/tankz/view/ResultFrame.hx index 026c143..bf8aa30 100644 --- a/src/client/haxe/ru/m/tankz/view/ResultFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/ResultFrame.hx @@ -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}'; } diff --git a/src/client/haxe/ru/m/tankz/view/StartFrame.hx b/src/client/haxe/ru/m/tankz/view/StartFrame.hx index 676d49c..bb5b75a 100644 --- a/src/client/haxe/ru/m/tankz/view/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/StartFrame.hx @@ -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); } diff --git a/src/client/haxe/ru/m/tankz/view/ViewUtil.hx b/src/client/haxe/ru/m/tankz/view/ViewUtil.hx index 800cec2..1bc63b1 100644 --- a/src/client/haxe/ru/m/tankz/view/ViewUtil.hx +++ b/src/client/haxe/ru/m/tankz/view/ViewUtil.hx @@ -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; + + 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 = ['${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); + }; + } } diff --git a/src/client/haxe/ru/m/tankz/view/gamepad/GamepadView.hx b/src/client/haxe/ru/m/tankz/view/gamepad/GamepadView.hx index 6c32e4d..9fe5122 100644 --- a/src/client/haxe/ru/m/tankz/view/gamepad/GamepadView.hx +++ b/src/client/haxe/ru/m/tankz/view/gamepad/GamepadView.hx @@ -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; @@ -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 = []; diff --git a/src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx b/src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx index d327296..7057e66 100644 --- a/src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx +++ b/src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx @@ -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); } } diff --git a/src/client/haxe/ru/m/tankz/view/gamepad/SmartActionAreaBuilder.hx b/src/client/haxe/ru/m/tankz/view/gamepad/SmartActionAreaBuilder.hx index fa60a38..2c2f7f1 100644 --- a/src/client/haxe/ru/m/tankz/view/gamepad/SmartActionAreaBuilder.hx +++ b/src/client/haxe/ru/m/tankz/view/gamepad/SmartActionAreaBuilder.hx @@ -11,8 +11,8 @@ class SmartActionAreaBuilder implements IActionAreaBuilder { public function build(width:Float, height:Float):Array { var areas:Array = []; - 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), diff --git a/src/client/haxe/ru/m/tankz/view/settings/ActionView.hx b/src/client/haxe/ru/m/tankz/view/settings/ActionView.hx index 0d642d1..f4c4fc1 100755 --- a/src/client/haxe/ru/m/tankz/view/settings/ActionView.hx +++ b/src/client/haxe/ru/m/tankz/view/settings/ActionView.hx @@ -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; - - 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 { 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; } diff --git a/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.hx b/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.hx index 8aa99bc..b600f6d 100644 --- a/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.hx +++ b/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.hx @@ -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(); } diff --git a/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.yaml b/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.yaml index b704de3..b1e6392 100644 --- a/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.yaml +++ b/src/client/haxe/ru/m/tankz/view/settings/SettingsEditor.yaml @@ -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