[client] add StartGameFrame

This commit is contained in:
2018-07-26 18:01:15 +03:00
parent 17e4f1f172
commit 80f2ac25ad
11 changed files with 150 additions and 59 deletions

View File

@@ -18,7 +18,7 @@ views:
- id: start - id: start
$type: ru.m.tankz.frame.StartFrame $type: ru.m.tankz.frame.StartFrame
- id: level - id: level
$type: ru.m.tankz.frame.LevelFrame $type: ru.m.tankz.frame.StartGameFrame
- id: game - id: game
$type: ru.m.tankz.frame.GameFrame $type: ru.m.tankz.frame.GameFrame
- id: network - id: network

View File

@@ -10,8 +10,13 @@ import yaml.Yaml;
class ConfigBundle implements IConfigBundle { class ConfigBundle implements IConfigBundle {
private var _cache:Map<GameType, Config> = new Map();
public function get(type:GameType):Config { public function get(type:GameType):Config {
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()); if (!_cache.exists(type)) {
return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses); 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);
} }
} }

View File

@@ -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<Int>;
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<Int>):Void {
Provider.get(GameSave).state.level = item.data;
Provider.get(IFrameSwitcher).change(GameFrame.ID);
}
}

View File

@@ -1,20 +0,0 @@
---
pWidth: 100
pHeight: 100
views:
- id: levels
$type: haxework.gui.list.VListView<Int>
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

View File

@@ -72,7 +72,7 @@ class StartFrame extends VGroupView {
private function startGame(type:GameType, presetId:PresetId):Void { private function startGame(type:GameType, presetId:PresetId):Void {
Provider.set(GameSave, new GameSave({type: type, presetId: presetId})); Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
frameSwitcher.change(LevelFrame.ID); frameSwitcher.change(StartGameFrame.ID);
} }
private function loadGame(type:GameType):Void { private function loadGame(type:GameType):Void {

View File

@@ -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<PlayerConfig>;
@:view var levels(default, null):ListView<Int>;
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<PlayerConfig> = [];
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<Int>):Void {
Provider.get(GameSave).state.level = item.data;
Provider.get(IFrameSwitcher).change(GameFrame.ID);
}
}

View File

@@ -0,0 +1,36 @@
---
pWidth: 100
pHeight: 100
views:
- id: players
$type: haxework.gui.list.VListView<ru.m.tankz.config.Config.PlayerConfig>
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<Int>
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

View File

@@ -1,5 +1,5 @@
--- ---
width: 440 pWidth: 100
height: 44 height: 44
margins: 5 margins: 5
views: views:

View File

@@ -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<PlayerConfig> {
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;
}
}
}

View File

@@ -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

View File

@@ -13,7 +13,7 @@ import haxework.log.TraceLogger;
import haxework.provider.Provider; import haxework.provider.Provider;
import haxework.resources.IResources; import haxework.resources.IResources;
import haxework.resources.Resources; import haxework.resources.Resources;
import ru.m.tankz.frame.LevelFrame; import ru.m.tankz.frame.StartGameFrame;
#if flash import haxework.log.JSLogger; #end #if flash import haxework.log.JSLogger; #end
#if debug import haxework.log.SocketLogger; #end #if debug import haxework.log.SocketLogger; #end
@@ -62,7 +62,7 @@ class Editor {
view.btn_level.onPress = this; view.btn_level.onPress = this;
view.btn_tank.onPress = this; view.btn_tank.onPress = this;
view.switcher.change(LevelFrame.ID); view.switcher.change(StartGameFrame.ID);
} }
public function onPress(v:ButtonView):Void { public function onPress(v:ButtonView):Void {