diff --git a/src/client/haxe/ru/m/tankz/Client.yaml b/src/client/haxe/ru/m/tankz/Client.yaml index 6c105e5..a6a5849 100755 --- a/src/client/haxe/ru/m/tankz/Client.yaml +++ b/src/client/haxe/ru/m/tankz/Client.yaml @@ -18,7 +18,7 @@ views: - id: start $type: ru.m.tankz.frame.StartFrame - id: level - $type: ru.m.tankz.frame.LevelFrame + $type: ru.m.tankz.frame.StartGameFrame - id: game $type: ru.m.tankz.frame.GameFrame - id: network diff --git a/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx b/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx index 8dcf381..34d84fc 100644 --- a/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx +++ b/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx @@ -10,8 +10,13 @@ import yaml.Yaml; class ConfigBundle implements IConfigBundle { + private var _cache:Map = new Map(); + public function get(type:GameType):Config { - var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()); - return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses); + if (!_cache.exists(type)) { + var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()); + _cache.set(type, new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses)); + } + return _cache.get(type); } } diff --git a/src/client/haxe/ru/m/tankz/frame/LevelFrame.hx b/src/client/haxe/ru/m/tankz/frame/LevelFrame.hx deleted file mode 100644 index 5fea55a..0000000 --- a/src/client/haxe/ru/m/tankz/frame/LevelFrame.hx +++ /dev/null @@ -1,32 +0,0 @@ -package ru.m.tankz.frame; - -import haxework.gui.frame.IFrameSwitcher; -import haxework.gui.list.ListView; -import haxework.gui.VGroupView; -import haxework.provider.Provider; -import ru.m.tankz.bundle.IConfigBundle; -import ru.m.tankz.game.GameSave; -import ru.m.tankz.game.GameState; - - -@:template("ru/m/tankz/frame/LevelFrame.yaml", "ru/m/tankz/Style.yaml") -class LevelFrame extends VGroupView { - public static inline var ID = "level"; - - @:view var levels(default, null):ListView; - - public function init():Void { - levels.dispatcher.addListener(this); - } - - public function onShow():Void { - var state:GameState = Provider.get(GameSave).state; - var c = Provider.get(IConfigBundle).get(state.type).game.levels; - levels.data = [for (i in 0...c) i]; - } - - public function onListItemClick(item:IListItemView):Void { - Provider.get(GameSave).state.level = item.data; - Provider.get(IFrameSwitcher).change(GameFrame.ID); - } -} diff --git a/src/client/haxe/ru/m/tankz/frame/LevelFrame.yaml b/src/client/haxe/ru/m/tankz/frame/LevelFrame.yaml deleted file mode 100644 index 8909aea..0000000 --- a/src/client/haxe/ru/m/tankz/frame/LevelFrame.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -pWidth: 100 -pHeight: 100 -views: -- id: levels - $type: haxework.gui.list.VListView - factory: "@class:ru.m.tankz.frame.level.LevelView" - pWidth: 100 - pHeight: 100 - paddings: 10 - scroll: - $type: haxework.gui.list.VScrollView - width: 10 - pHeight: 100 - skin: - $type: haxework.gui.list.VScrollSkin - skin: - $type: haxework.gui.skin.ColorSkin - color: "#000000" - alpha: 0 diff --git a/src/client/haxe/ru/m/tankz/frame/StartFrame.hx b/src/client/haxe/ru/m/tankz/frame/StartFrame.hx index b95a06c..caf95cc 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/StartFrame.hx @@ -72,7 +72,7 @@ class StartFrame extends VGroupView { private function startGame(type:GameType, presetId:PresetId):Void { Provider.set(GameSave, new GameSave({type: type, presetId: presetId})); - frameSwitcher.change(LevelFrame.ID); + frameSwitcher.change(StartGameFrame.ID); } private function loadGame(type:GameType):Void { diff --git a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx new file mode 100644 index 0000000..37f656c --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.hx @@ -0,0 +1,41 @@ +package ru.m.tankz.frame; + +import ru.m.tankz.config.Config; +import ru.m.tankz.config.Config.PlayerConfig; +import haxework.gui.frame.IFrameSwitcher; +import haxework.gui.list.ListView; +import haxework.gui.HGroupView; +import haxework.provider.Provider; +import ru.m.tankz.bundle.IConfigBundle; +import ru.m.tankz.game.GameSave; + + +@:template("ru/m/tankz/frame/StartGameFrame.yaml", "ru/m/tankz/Style.yaml") +class StartGameFrame extends HGroupView { + public static inline var ID = "level"; + + @:view var players(default, null):ListView; + @:view var levels(default, null):ListView; + + public function init():Void { + levels.dispatcher.addListener(this); + } + + 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); + } + this.players.data = players; + } + + public function onListItemClick(item:IListItemView):Void { + Provider.get(GameSave).state.level = item.data; + Provider.get(IFrameSwitcher).change(GameFrame.ID); + } +} diff --git a/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml new file mode 100644 index 0000000..a19b2fe --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/StartGameFrame.yaml @@ -0,0 +1,36 @@ +--- +pWidth: 100 +pHeight: 100 +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.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.skin.ColorSkin + color: "#000000" + alpha: 0 diff --git a/src/client/haxe/ru/m/tankz/frame/level/LevelView.yaml b/src/client/haxe/ru/m/tankz/frame/level/LevelView.yaml index 1cf0139..5e7e02a 100644 --- a/src/client/haxe/ru/m/tankz/frame/level/LevelView.yaml +++ b/src/client/haxe/ru/m/tankz/frame/level/LevelView.yaml @@ -1,5 +1,5 @@ --- -width: 440 +pWidth: 100 height: 44 margins: 5 views: diff --git a/src/client/haxe/ru/m/tankz/frame/level/PlayerView.hx b/src/client/haxe/ru/m/tankz/frame/level/PlayerView.hx new file mode 100644 index 0000000..d5ac87b --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/level/PlayerView.hx @@ -0,0 +1,42 @@ +package ru.m.tankz.frame.level; + +import haxework.gui.ButtonView; +import haxework.gui.HGroupView; +import haxework.gui.LabelView; +import haxework.gui.list.ListView.IListItemView; +import ru.m.tankz.config.Config; +import ru.m.tankz.control.Control; + + +@:template("ru/m/tankz/frame/level/PlayerView.yaml", "ru/m/tankz/Style.yaml") +class PlayerView extends HGroupView implements IListItemView { + + public var item_index(default, default):Int; + public var data(default, set):PlayerConfig; + + @:view("index") var indexLabel(default, null):LabelView; + @:view var control(default, null):ButtonView; + + private function init():Void { + control.onPress = this; + } + + private function set_data(value:PlayerConfig):PlayerConfig { + data = value; + indexLabel.text = data.index == -1 ? "" : Std.string(data.index); + control.text = data.control; + control.fontColor = data.index == -1 ? 0x00ff00 : 0xffffff; + return data; + } + + public function onPress(view:ButtonView):Void { + if (data != null && data.index > -1) { + data.control = switch (data.control) { + case Control.BOT: Control.HUMAN; + case Control.HUMAN: Control.BOT; + case _: Control.BOT; + } + control.text = data.control; + } + } +} \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/frame/level/PlayerView.yaml b/src/client/haxe/ru/m/tankz/frame/level/PlayerView.yaml new file mode 100644 index 0000000..655127d --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/level/PlayerView.yaml @@ -0,0 +1,19 @@ +--- +pWidth: 100 +height: 44 +margins: 5 +views: +- id: index + $type: haxework.gui.LabelView + $style: label + pHeight: 100 + width: 50 +- id: control + $type: haxework.gui.ButtonView + $style: label + pHeight: 100 + pWidth: 100 +skin: + $type: haxework.gui.skin.ColorSkin + color: "#000000" + alpha: 0.2 diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.hx b/src/editor/haxe/ru/m/tankz/editor/Editor.hx index 0f5dcf1..ab42306 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -13,7 +13,7 @@ import haxework.log.TraceLogger; import haxework.provider.Provider; import haxework.resources.IResources; import haxework.resources.Resources; -import ru.m.tankz.frame.LevelFrame; +import ru.m.tankz.frame.StartGameFrame; #if flash import haxework.log.JSLogger; #end #if debug import haxework.log.SocketLogger; #end @@ -62,7 +62,7 @@ class Editor { view.btn_level.onPress = this; view.btn_tank.onPress = this; - view.switcher.change(LevelFrame.ID); + view.switcher.change(StartGameFrame.ID); } public function onPress(v:ButtonView):Void {