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