From a24d610b052c805bff6ad34f6132ce80643d79df Mon Sep 17 00:00:00 2001 From: shmyga Date: Fri, 27 Jul 2018 17:35:12 +0300 Subject: [PATCH] [client] update StartFrame --- src/client/haxe/ru/m/skin/SimpleButtonSkin.hx | 25 +++++++ src/client/haxe/ru/m/tankz/Style.yaml | 10 +++ .../haxe/ru/m/tankz/frame/StartFrame.hx | 44 ++---------- .../haxe/ru/m/tankz/frame/StartFrame.yaml | 67 +++--------------- .../haxe/ru/m/tankz/frame/StartGameFrame.hx | 68 +++++++++++++++---- .../haxe/ru/m/tankz/frame/StartGameFrame.yaml | 62 +++++++++-------- .../ru/m/tankz/frame/level/PresetsView.hx | 61 +++++++++++++++++ .../tankz/frame/settings/SettingsEditor.yaml | 29 ++++---- .../ru/m/tankz/storage/SettingsStorage.hx | 4 +- 9 files changed, 220 insertions(+), 150 deletions(-) create mode 100644 src/client/haxe/ru/m/skin/SimpleButtonSkin.hx create mode 100644 src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx diff --git a/src/client/haxe/ru/m/skin/SimpleButtonSkin.hx b/src/client/haxe/ru/m/skin/SimpleButtonSkin.hx new file mode 100644 index 0000000..1cf8307 --- /dev/null +++ b/src/client/haxe/ru/m/skin/SimpleButtonSkin.hx @@ -0,0 +1,25 @@ +package ru.m.skin; + +import flash.display.Graphics; +import haxework.gui.ButtonView; +import haxework.gui.skin.ButtonColorSkin; + +class SimpleButtonSkin extends ButtonColorSkin { + + public var borderColor(default, default):Int; + + public function new(color:Int = 0xffffff, borderColor:Int = 0x95937D) { + super(color, 0.6); + this.borderColor = borderColor; + } + + override public function draw(view:ButtonView):Void { + var color:Int = selectColor(view); + var graphics:Graphics = view.contentAsSprite.graphics; + graphics.clear(); + graphics.beginFill(color, alpha); + graphics.lineStyle(2, borderColor); + graphics.drawRoundRect(0, 0, view.width, view.height, 10, 10); + graphics.endFill(); + } +} diff --git a/src/client/haxe/ru/m/tankz/Style.yaml b/src/client/haxe/ru/m/tankz/Style.yaml index cdd2598..43760db 100644 --- a/src/client/haxe/ru/m/tankz/Style.yaml +++ b/src/client/haxe/ru/m/tankz/Style.yaml @@ -13,6 +13,16 @@ button: fontColor: "#E7E0BB" fontSize: 20 +button_simple: + width: 100 + height: 36 + skin: + $type: ru.m.skin.SimpleButtonSkin + fontFamily: "@res:text:font" + fontEmbed: true + fontColor: "#95937D" + fontSize: 20 + label: fontColor: "#ffffff" fontEmbed: false diff --git a/src/client/haxe/ru/m/tankz/frame/StartFrame.hx b/src/client/haxe/ru/m/tankz/frame/StartFrame.hx index caf95cc..f897fb2 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/StartFrame.hx @@ -16,12 +16,8 @@ class StartFrame extends VGroupView { public static var ID(default, never):String = "start"; - @:view var classic_1p(default, null):ButtonView; - @:view var classic_2p(default, null):ButtonView; - @:view var classic_load(default, null):ButtonView; - @:view var dota_1p(default, null):ButtonView; - @:view var dota_2p_coop(default, null):ButtonView; - @:view var dota_2p_vs(default, null):ButtonView; + @:view var classic(default, null):ButtonView; + @:view var dota(default, null):ButtonView; @:view var network(default, null):ButtonView; @:view var settings(default, null):ButtonView; @@ -29,40 +25,18 @@ class StartFrame extends VGroupView { @:provide var storage:SaveStorage; public function init():Void { - classic_1p.onPress = this; - classic_2p.onPress = this; - classic_load.onPress = this; - dota_1p.onPress = this; - dota_2p_coop.onPress = this; - dota_2p_vs.onPress = this; + classic.onPress = this; + dota.onPress = this; network.onPress = this; settings.onPress = this; } - public function onShow():Void { - var save:GameSave = storage.read(ClassicGame.TYPE); - if (save != null) { - classic_load.visible = true; - classic_load.text = 'Load (Level ${save.state.level})'; - } else { - classic_load.visible = false; - } - } - public function onPress(view:ButtonView):Void { switch (view.id) { - case 'classic_1p': + case 'classic': startGame(ClassicGame.TYPE, ClassicGame.PLAYER1); - case 'classic_2p': - startGame(ClassicGame.TYPE, ClassicGame.PLAYER2); - case 'classic_load': - loadGame(ClassicGame.TYPE); - case 'dota_1p': + case 'dota': startGame(DotaGame.TYPE, DotaGame.PLAYER1); - case 'dota_2p_coop': - startGame(DotaGame.TYPE, DotaGame.PLAYER2_COOP); - case 'dota_2p_vs': - startGame(DotaGame.TYPE, DotaGame.PLAYER2_VS); case 'network': frameSwitcher.change(NetworkFrame.ID); case 'settings': @@ -74,10 +48,4 @@ class StartFrame extends VGroupView { Provider.set(GameSave, new GameSave({type: type, presetId: presetId})); frameSwitcher.change(StartGameFrame.ID); } - - private function loadGame(type:GameType):Void { - var save:GameSave = storage.read(type); - Provider.set(GameSave, save); - frameSwitcher.change(GameFrame.ID); - } } diff --git a/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml b/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml index 8fdd5b2..917c49e 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml +++ b/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml @@ -7,69 +7,22 @@ views: image: "@asset:image:resources/image/ui/logo.png" contentSize: true bottomMargin: 15 -- $type: haxework.gui.HGroupView - contentSize: true - views: - - $type: haxework.gui.VGroupView - contentSize: true - views: - # classic - - $type: haxework.gui.LabelView - $style: label - fontSize: 20 - topMargin: 15 - contentSize: true - text: Classic - - id: classic_1p - $type: haxework.gui.ButtonView - text: 1 Player - $style: button - - id: classic_2p - $type: haxework.gui.ButtonView - text: 2 Player - $style: button - - id: classic_load - $type: haxework.gui.ButtonView - text: Load - $style: button - - $type: haxework.gui.VGroupView - contentSize: true - views: - # dota - - $type: haxework.gui.LabelView - $style: label - fontSize: 20 - topMargin: 15 - contentSize: true - text: DotA - - id: dota_1p - $type: haxework.gui.ButtonView - text: 1 Player - $style: button - - id: dota_2p_coop - $type: haxework.gui.ButtonView - text: 2 COOP - $style: button - - id: dota_2p_vs - $type: haxework.gui.ButtonView - text: 2 VS - $style: button -# network - $type: haxework.gui.VGroupView contentSize: true - visible: true views: - - $type: haxework.gui.LabelView - $style: label - fontSize: 20 - topMargin: 15 - contentSize: true - text: Network (in developing) - fontColor: 0xff0000 + - id: classic + $type: haxework.gui.ButtonView + text: Classic + $style: button + - id: dota + $type: haxework.gui.ButtonView + text: DotA + $style: button - id: network $type: haxework.gui.ButtonView - text: Network + text: Network (in developing) $style: button + fontColor: 0xff0000 - $type: haxework.gui.LabelView $style: label inLayout: false diff --git a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx index 37f656c..63bc3b7 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx @@ -1,37 +1,79 @@ package ru.m.tankz.frame; -import ru.m.tankz.config.Config; -import ru.m.tankz.config.Config.PlayerConfig; +import ru.m.tankz.storage.SaveStorage; import haxework.gui.frame.IFrameSwitcher; import haxework.gui.list.ListView; -import haxework.gui.HGroupView; +import haxework.gui.VGroupView; import haxework.provider.Provider; import ru.m.tankz.bundle.IConfigBundle; +import ru.m.tankz.config.Config; +import ru.m.tankz.frame.level.PresetsView; import ru.m.tankz.game.GameSave; +import ru.m.tankz.Type; @:template("ru/m/tankz/frame/StartGameFrame.yaml", "ru/m/tankz/Style.yaml") -class StartGameFrame extends HGroupView { +class StartGameFrame extends VGroupView { public static inline var ID = "level"; + @:view var presets(default, null):PresetsView; @:view var players(default, null):ListView; @:view var levels(default, null):ListView; + @:provide var save:GameSave; + @:provide var storage:SaveStorage; + + public var gameType(default, set):GameType; + public var presetId(default, set):PresetId; + + private var config:Config; + private var preset:GamePreset; + public function init():Void { levels.dispatcher.addListener(this); + presets.change.connect(function(presetId) this.presetId = presetId); + } + + private function set_gameType(value:GameType):GameType { + if (gameType != value) { + gameType = value; + config = Provider.get(IConfigBundle).get(gameType); + presets.data = config.presets; + levels.data = [for (i in 0...config.game.levels) i]; + presetId = null; + presetId = config.presets[0].id; + + var save:GameSave = storage.read(gameType); + // ToDo: start save button + } + return gameType; + } + + private function set_presetId(value:PresetId):PresetId { + if (presetId != value) { + presetId = value; + presets.selected = presetId; + save.state.presetId = presetId; + if (presetId != null) { + preset = config.getPreset(presetId); + var players:Array = []; + for (team in preset.teams) { + players.push({index: -1, control: 'Team "${team.id}"', tanks: []}); + players = players.concat(team.players); + } + this.players.data = players; + } else { + this.players.data = []; + } + } + return presetId; } public function onShow():Void { - var save:GameSave = Provider.get(GameSave); - var config:Config = Provider.get(IConfigBundle).get(save.state.type); - var preset:GamePreset = config.getPreset(save.state.presetId); - levels.data = [for (i in 0...config.game.levels) i]; - var players:Array = []; - for (team in preset.teams) { - players.push({index: -1, control: 'Team "${team.id}"', tanks: []}); - players = players.concat(team.players); + gameType = save.state.type; + if (save.state.presetId != null) { + presetId = save.state.presetId; } - this.players.data = players; } public function onListItemClick(item:IListItemView):Void { diff --git a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml index a19b2fe..cf4449c 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml +++ b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml @@ -2,35 +2,43 @@ pWidth: 100 pHeight: 100 views: -- id: players - $type: haxework.gui.list.VListView - factory: "@class:ru.m.tankz.frame.level.PlayerView" - pWidth: 50 +- id: presets + $type: ru.m.tankz.frame.level.PresetsView + contentSize: true + topMargin: 10 +- $type: haxework.gui.HGroupView + pWidth: 100 pHeight: 100 - paddings: 10 - scroll: - $type: haxework.gui.list.VScrollView - width: 10 + views: + - id: players + $type: haxework.gui.list.VListView + factory: "@class:ru.m.tankz.frame.level.PlayerView" + pWidth: 50 pHeight: 100 + paddings: 10 + scroll: + $type: haxework.gui.list.VScrollView + width: 10 + pHeight: 100 + skin: + $type: haxework.gui.list.VScrollSkin skin: - $type: haxework.gui.list.VScrollSkin - skin: - $type: haxework.gui.skin.ColorSkin - color: "#000000" - alpha: 0 -- id: levels - $type: haxework.gui.list.VListView - factory: "@class:ru.m.tankz.frame.level.LevelView" - pWidth: 50 - pHeight: 100 - paddings: 10 - scroll: - $type: haxework.gui.list.VScrollView - width: 10 + $type: haxework.gui.skin.ColorSkin + color: "#000000" + alpha: 0 + - id: levels + $type: haxework.gui.list.VListView + factory: "@class:ru.m.tankz.frame.level.LevelView" + pWidth: 50 pHeight: 100 + paddings: 10 + scroll: + $type: haxework.gui.list.VScrollView + width: 10 + pHeight: 100 + skin: + $type: haxework.gui.list.VScrollSkin skin: - $type: haxework.gui.list.VScrollSkin - skin: - $type: haxework.gui.skin.ColorSkin - color: "#000000" - alpha: 0 + $type: haxework.gui.skin.ColorSkin + color: "#000000" + alpha: 0 diff --git a/src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx b/src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx new file mode 100644 index 0000000..1b604f3 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx @@ -0,0 +1,61 @@ +package ru.m.tankz.frame.level; + +import haxework.resources.IResources; +import haxework.provider.Provider; +import ru.m.skin.SimpleButtonSkin; +import ru.m.signal.Signal.Signal1; +import haxework.gui.ToggleButtonView; +import ru.m.tankz.Type; +import haxework.gui.ButtonView; +import ru.m.tankz.config.Config.GamePreset; +import haxework.gui.HGroupView; + + +class PresetsView extends HGroupView { + + public var data(default, set):Array; + public var selected(default, set):PresetId; + + public var change(default, null):Signal1; + + public function new() { + super(); + layoutMargin = 10; + change = new Signal1(); + } + + private function set_data(value:Array):Array { + data = value; + removeAllViews(); + for (item in data) { + var view = new ToggleButtonView(); + view.skin = new SimpleButtonSkin(); + view.onSkin = new SimpleButtonSkin(0x00ff00); + view.text = item.id; + view.width = 250; + view.height = 36; + view.fontFamily = Provider.get(IResources).text.get("font"); + view.fontEmbed = true; + view.fontColor = 0x95937D; + view.fontSize = 20; + view.onPress = this; + view.update(); + addView(view); + } + return data; + } + + private function set_selected(value:PresetId):PresetId { + selected = value; + for (view in views) { + var button = cast(view, ToggleButtonView); + button.on = button.text == selected; + } + change.emit(selected); + return selected; + } + + public function onPress(view:ButtonView):Void { + selected = view.text; + } +} diff --git a/src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.yaml b/src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.yaml index 7003587..979704e 100644 --- a/src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.yaml +++ b/src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.yaml @@ -1,21 +1,24 @@ -$type: haxework.gui.VGroupView layoutMargin: 10 views: - id: label $type: haxework.gui.LabelView $style: label -- id: change - $type: haxework.gui.ButtonView - $style: button - text: Change -- id: clear - $type: haxework.gui.ButtonView - $style: button - text: Clear -- id: reset - $type: haxework.gui.ButtonView - $style: button - text: Reset +- $type: haxework.gui.HGroupView + contentSize: true + layoutMargin: 10 + views: + - id: change + $type: haxework.gui.ButtonView + $style: button_simple + text: Change + - id: clear + $type: haxework.gui.ButtonView + $style: button_simple + text: Clear + - id: reset + $type: haxework.gui.ButtonView + $style: button_simple + text: Reset - id: list $type: haxework.gui.list.VListView factory: "@class:ru.m.tankz.frame.settings.ActionView" diff --git a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx index 9c4e926..e18055e 100644 --- a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx +++ b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx @@ -47,8 +47,8 @@ class SettingsStorage { 1 => new ActionConfig([ {action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP}, {action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT}, - {action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.RIGHT}, - {action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.DOWN}, + {action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN}, + {action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT}, {action:TankAction.SHOT, key:Keyboard.NUMPAD_0}, ]), ];