[client] DeviceType in SettingsEditor
This commit is contained in:
@@ -11,21 +11,10 @@ import ru.m.tankz.control.Control.TankAction;
|
|||||||
|
|
||||||
class SettingsStorage extends SharedObjectStorage {
|
class SettingsStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
public var screenGamepad(get, set):Bool;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super("settings-2");
|
super("settings-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_screenGamepad():Bool {
|
|
||||||
return read("screenGamepad");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_screenGamepad(value:Bool):Bool {
|
|
||||||
write("screenGamepad", value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getActionConfig(index:Int):ActionConfig {
|
public function getActionConfig(index:Int):ActionConfig {
|
||||||
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.control.IControlBus;
|
import ru.m.control.IControlBus;
|
||||||
@@ -28,13 +29,21 @@ import ru.m.tankz.view.GamepadView;
|
|||||||
@:provide var record:GameRecord;
|
@:provide var record:GameRecord;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var gameStorage:GameStorage;
|
@:provide var gameStorage:GameStorage;
|
||||||
@:provide var settings:SettingsStorage;
|
@:provide static var settings:SettingsStorage;
|
||||||
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
@:provide static var bus:IControlBus;
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
gamepad.visible = settings.screenGamepad;
|
gamepad.visible = false;
|
||||||
|
for (i in 0...1) {
|
||||||
|
switch settings.getActionConfig(i).device {
|
||||||
|
case GAMEPAD(GamepadView.ID):
|
||||||
|
gamepad.visible = true;
|
||||||
|
break;
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
bus.connect(gamepad);
|
bus.connect(gamepad);
|
||||||
gameView.type = game.type;
|
gameView.type = game.type;
|
||||||
soundManager.config = game.config;
|
soundManager.config = game.config;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import flash.events.MouseEvent;
|
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
|
import flash.display.Stage;
|
||||||
|
import flash.events.MouseEvent;
|
||||||
import flash.events.TouchEvent;
|
import flash.events.TouchEvent;
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import haxework.view.skin.ISkin;
|
import haxework.view.skin.ISkin;
|
||||||
@@ -42,7 +43,7 @@ class GamepadSkin implements ISkin<GamepadView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GamepadView extends SpriteView implements IControlDevice {
|
class GamepadView extends SpriteView implements IControlDevice {
|
||||||
public static var ID:Int = -128;
|
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>;
|
||||||
@@ -50,9 +51,7 @@ class GamepadView extends SpriteView implements IControlDevice {
|
|||||||
public var areas(default, null):Array<ActionArea>;
|
public var areas(default, null):Array<ActionArea>;
|
||||||
public var currentAreas(default, null):Map<Int, ActionArea>;
|
public var currentAreas(default, null):Map<Int, ActionArea>;
|
||||||
|
|
||||||
private static function touchSupport():Bool {
|
private var stage:Stage;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
@@ -67,8 +66,9 @@ class GamepadView extends SpriteView implements IControlDevice {
|
|||||||
|
|
||||||
private function onMouseDown(event:MouseEvent):Void {
|
private function onMouseDown(event:MouseEvent):Void {
|
||||||
onMouseMove(event);
|
onMouseMove(event);
|
||||||
content.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
stage = event.relatedObject.stage;
|
||||||
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseMove(event:MouseEvent):Void {
|
private function onMouseMove(event:MouseEvent):Void {
|
||||||
@@ -78,14 +78,15 @@ class GamepadView extends SpriteView implements IControlDevice {
|
|||||||
|
|
||||||
private function onMouseUp(event:MouseEvent):Void {
|
private function onMouseUp(event:MouseEvent):Void {
|
||||||
endTouch(-1);
|
endTouch(-1);
|
||||||
content.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTouchBegin(event:TouchEvent):Void {
|
private function onTouchBegin(event:TouchEvent):Void {
|
||||||
onTouchMove(event);
|
onTouchMove(event);
|
||||||
content.stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
stage = event.relatedObject.stage;
|
||||||
content.stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
|
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTouchMove(event:TouchEvent):Void {
|
private function onTouchMove(event:TouchEvent):Void {
|
||||||
@@ -96,8 +97,8 @@ class GamepadView extends SpriteView implements IControlDevice {
|
|||||||
private function onTouchEnd(event:TouchEvent):Void {
|
private function onTouchEnd(event:TouchEvent):Void {
|
||||||
endTouch(event.touchPointID);
|
endTouch(event.touchPointID);
|
||||||
if (Lambda.count(currentAreas) == 0) {
|
if (Lambda.count(currentAreas) == 0) {
|
||||||
content.stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
content.stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,5 +153,7 @@ class GamepadView extends SpriteView implements IControlDevice {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {}
|
public function dispose():Void {
|
||||||
|
stage = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,7 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.ToggleButtonView;
|
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
|
||||||
|
|
||||||
@:template class SettingsFrame extends VGroupView {
|
@:template class SettingsFrame extends VGroupView {
|
||||||
public static var ID(default, never):String = "settings";
|
public static var ID(default, never):String = "settings";
|
||||||
|
|
||||||
@:view("gamepad") private var gamepadButton:ToggleButtonView;
|
|
||||||
|
|
||||||
@:provide private static var settings:SettingsStorage;
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
gamepadButton.on = settings.screenGamepad;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function toggleGamepad():Void {
|
|
||||||
gamepadButton.on = settings.screenGamepad = !settings.screenGamepad;
|
|
||||||
if (settings.screenGamepad) {
|
|
||||||
settings.setActionConffig(0, SettingsStorage.gamepadConfig(GamepadView.ID));
|
|
||||||
} else {
|
|
||||||
settings.setActionConffig(0, SettingsStorage.getDefaultActionConfig(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,28 @@
|
|||||||
views:
|
views:
|
||||||
- $type: haxework.view.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
skinId: container
|
skinId: container
|
||||||
|
geometry.padding: 20
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.LabelView
|
- $type: haxework.view.LabelView
|
||||||
skinId: text.header
|
skinId: text.header
|
||||||
text: Settings
|
text: Settings
|
||||||
- id: gamepad
|
- $type: haxework.view.ScrollView
|
||||||
$type: haxework.view.ToggleButtonView
|
geometry.size.stretch: true
|
||||||
skinId: button.simple
|
scroll:
|
||||||
text: Screen Gamepad Disabled
|
$type: haxework.view.list.VScrollBarView
|
||||||
onText: Screen Gamepad Enabled
|
skinId: scroll.vertical
|
||||||
+onPress: $code:toggleGamepad()
|
view:
|
||||||
- $type: haxework.view.HGroupView
|
$type: haxework.view.GroupView
|
||||||
layout.margin: 20
|
geometry.size.stretch: true
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
vAlign: top
|
||||||
|
margin: 20
|
||||||
|
overflow: true
|
||||||
views:
|
views:
|
||||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
- id: settings0
|
||||||
|
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
controlIndex: 0
|
controlIndex: 0
|
||||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
- id: settings1
|
||||||
|
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
controlIndex: 1
|
controlIndex: 1
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package ru.m.tankz.view.settings;
|
package ru.m.tankz.view.settings;
|
||||||
|
|
||||||
|
import haxe.EnumTools.EnumValueTools;
|
||||||
|
import haxework.view.GroupView;
|
||||||
|
import haxework.view.ButtonGroup;
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
@@ -16,16 +19,32 @@ import ru.m.tankz.view.settings.ActionView;
|
|||||||
|
|
||||||
@:view var label:LabelView;
|
@:view var label:LabelView;
|
||||||
@:view var list:DataView<ActionItem, ActionView>;
|
@:view var list:DataView<ActionItem, ActionView>;
|
||||||
|
@:view var panel:GroupView;
|
||||||
|
@:view var device:ButtonGroup<DeviceType>;
|
||||||
|
|
||||||
@:provide static var storage:SettingsStorage;
|
@:provide static var storage:SettingsStorage;
|
||||||
|
|
||||||
private function set_controlIndex(value: Int): Int {
|
private function set_controlIndex(value: Int): Int {
|
||||||
this.controlIndex = value;
|
this.controlIndex = value;
|
||||||
label.text = 'Player ${controlIndex+1}';
|
label.text = 'Player ${controlIndex+1}';
|
||||||
list.data = bindingToArray(storage.getActionConfig(controlIndex).binding);
|
var config = storage.getActionConfig(controlIndex);
|
||||||
|
list.data = bindingToArray(config.binding);
|
||||||
|
device.data = [KEYBOARD, GAMEPAD(GamepadView.ID)];
|
||||||
|
device.selected = config.device;
|
||||||
|
panel.visible = list.visible = EnumValueTools.equals(config.device, KEYBOARD);
|
||||||
return this.controlIndex;
|
return this.controlIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onDeviceSelect(value:DeviceType):Void {
|
||||||
|
var config = switch value {
|
||||||
|
case GAMEPAD(id): SettingsStorage.gamepadConfig(id);
|
||||||
|
case KEYBOARD | NONE: SettingsStorage.getDefaultActionConfig(controlIndex);
|
||||||
|
}
|
||||||
|
panel.visible = list.visible = EnumValueTools.equals(config.device, KEYBOARD);
|
||||||
|
storage.setActionConffig(controlIndex, config);
|
||||||
|
controlIndex = controlIndex;
|
||||||
|
}
|
||||||
|
|
||||||
private function viewFactory(index:Int, value:ActionItem) {
|
private function viewFactory(index:Int, value:ActionItem) {
|
||||||
var view = new ActionView();
|
var view = new ActionView();
|
||||||
view.item_index = index;
|
view.item_index = index;
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
|
geometry.size.width: 400
|
||||||
views:
|
views:
|
||||||
- id: label
|
- id: label
|
||||||
$type: haxework.view.LabelView
|
$type: haxework.view.LabelView
|
||||||
skinId: text
|
skinId: text
|
||||||
- $type: haxework.view.HGroupView
|
- id: device
|
||||||
|
$type: haxework.view.ButtonGroup
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
margin: 3
|
||||||
|
buttonSkinId: button.simple
|
||||||
|
+onDataSelect: $this:onDeviceSelect
|
||||||
|
- id: panel
|
||||||
|
$type: haxework.view.HGroupView
|
||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- id: change
|
- id: change
|
||||||
|
|||||||
Reference in New Issue
Block a user