diff --git a/src/client/haxe/ru/m/tankz/ClientView.yaml b/src/client/haxe/ru/m/tankz/ClientView.yaml index 4d18d82..ee7d9d3 100755 --- a/src/client/haxe/ru/m/tankz/ClientView.yaml +++ b/src/client/haxe/ru/m/tankz/ClientView.yaml @@ -24,7 +24,11 @@ views: $type: ru.m.tankz.frame.dota.DotaLevelFrame - id: dota.game $type: ru.m.tankz.frame.dota.DotaGameFrame + # result + - id: result + $type: ru.m.tankz.frame.ResultFrame # - id: network # $type: ru.m.tankz.frame.NetworkFrame + # settings - id: settings $type: ru.m.tankz.frame.SettingsFrame diff --git a/src/client/haxe/ru/m/tankz/Style.hx b/src/client/haxe/ru/m/tankz/Style.hx index 784d6a6..1ff3b5a 100644 --- a/src/client/haxe/ru/m/tankz/Style.hx +++ b/src/client/haxe/ru/m/tankz/Style.hx @@ -70,5 +70,9 @@ class Style { Skin.size(64, 64), new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor) ]); + resources.skin.put("button.next", [ + Skin.size(64, 64), + new ButtonSVGSkin(Assets.getText("resources/image/icon/arrow-alt-circle-right-solid.svg"), lightColor) + ]); } } diff --git a/src/client/haxe/ru/m/tankz/frame/ResultFrame.hx b/src/client/haxe/ru/m/tankz/frame/ResultFrame.hx new file mode 100644 index 0000000..52bb5a6 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/ResultFrame.hx @@ -0,0 +1,50 @@ +package ru.m.tankz.frame; + +import haxework.gui.DataView; +import haxework.gui.frame.FrameSwitcher; +import haxework.gui.VGroupView; +import ru.m.tankz.control.Control; +import ru.m.tankz.frame.classic.ClassicGameFrame; +import ru.m.tankz.frame.common.LifeView; +import ru.m.tankz.frame.dota.DotaGameFrame; +import ru.m.tankz.game.GameState; +import ru.m.tankz.preset.ClassicGame; +import ru.m.tankz.preset.DotaGame; + +@:template class ResultFrame extends VGroupView { + public static var ID(default, never):String = "result"; + + @:view("result") var resultView:DataView; + + @:provide var frames:FrameSwitcher; + @:provide var state:GameState; + @:provide("result") var resultState:GameState; + + private function playerViewFactory(index:Int, player:PlayerState) { + var view = new LifeView(); + var playerConfig = resultState.config.getPlayer(player.id); + var tankType = playerConfig.tanks[0].type; + var tankConfig = resultState.config.getTank(tankType); + view.tank = tankConfig == null ? 'ba' : tankConfig.skin; + view.color = resultState.config.getColor(player.id); + view.live = player.frags; + view.score = player.score; + return view; + } + + public function onShow() { + resultView.data = resultState.players.filter(function(player) return player.control == Control.HUMAN); + } + + private function next() { + frames.change(switch state == null ? null : state.type { + case ClassicGame.TYPE: ClassicGameFrame.ID; + case DotaGame.TYPE: DotaGameFrame.ID; + case _: StartFrame.ID; + }); + } + + private function close() { + frames.change(StartFrame.ID); + } +} diff --git a/src/client/haxe/ru/m/tankz/frame/ResultFrame.yaml b/src/client/haxe/ru/m/tankz/frame/ResultFrame.yaml new file mode 100644 index 0000000..627db74 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/ResultFrame.yaml @@ -0,0 +1,35 @@ +--- +geometry.size.stretch: true +layout.hAlign: center +layout.vAlign: middle +views: + - $type: haxework.gui.LabelView + skinId: text.header + text: Result + + - id: result + $type: haxework.gui.DataView + factory: $this:playerViewFactory + geometry.margin.top: 20 + layout: + $type: haxework.gui.layout.VerticalLayout + hAlign: right + margin: 10 + + - id: close + $type: haxework.gui.ButtonView + skinId: button.close + +onPress: $code:close() + geometry.position: absolute + geometry.margin: 10 + geometry.vAlign: bottom + geometry.hAlign: left + + - id: next + $type: haxework.gui.ButtonView + skinId: button.next + +onPress: $code:next() + geometry.position: absolute + geometry.margin: 10 + geometry.vAlign: bottom + geometry.hAlign: right diff --git a/src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx b/src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx index b4f851e..84201e2 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx @@ -22,6 +22,7 @@ class GameFrame extends GroupView { @:provide var network:NetworkManager; @:provide var sound:SoundManager; @:provide var state:GameState; + @:provide("result") var result:GameState; @:provide var switcher:FrameSwitcher; private var game:Game; @@ -70,13 +71,13 @@ class GameFrame extends GroupView { } private function onGameComplete(_):Void { - switch (game.next()) { - case Option.Some(s): - stop(); - start(s); - case Option.None: - switcher.change(StartFrame.ID); + result = state; + state = switch game.next() { + case Option.Some(s): s; + case Option.None: null; } + stop(); + switcher.change(ResultFrame.ID); } public function onHide():Void { diff --git a/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx b/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx index 7b52486..2c6b815 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx +++ b/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx @@ -16,7 +16,9 @@ import haxework.gui.HGroupView; public var score(null, set):Int; private inline function set_tank(value:String):String { - tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png'); + if (value != null) { + tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png'); + } return value; } diff --git a/src/client/resources/image/icon/arrow-alt-circle-right-solid.svg b/src/client/resources/image/icon/arrow-alt-circle-right-solid.svg new file mode 100644 index 0000000..523c283 --- /dev/null +++ b/src/client/resources/image/icon/arrow-alt-circle-right-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/common/haxe/ru/m/tankz/bot/BotControl.hx b/src/common/haxe/ru/m/tankz/bot/BotControl.hx index b9d8a71..7f9d864 100644 --- a/src/common/haxe/ru/m/tankz/bot/BotControl.hx +++ b/src/common/haxe/ru/m/tankz/bot/BotControl.hx @@ -106,7 +106,7 @@ class BotControl extends Control { // ToDo: if (handler == null || tank == null) return; var eagle:Eagle = BotHelper.findEagle(playerId.team, handler); - if (eagle != null && Math.random() > 0.25) { + if (eagle != null && Math.random() > 0.5) { action(TankAction.MOVE(BotHelper.getDirectionTo(tank, eagle))); } else { action(TankAction.MOVE(BotHelper.randomDirection())); diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 6ca73f8..098e431 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -117,6 +117,8 @@ class Config { private var tankMap:Map; private var presetsMap:Map; private var bonusMap:Map; + private var teamsMap:Map; + private var playersMap:Map; public function new( type:String, @@ -158,6 +160,16 @@ class Config { for (item in bonuses) { bonusMap.set(item.type, item); } + teamsMap = new Map(); + playersMap = new Map(); + for (preset in presets) { + for (team in preset.teams) { + teamsMap.set(team.id, team); + for (player in team.players) { + playersMap.set(new PlayerId(team.id, player.index), player); + } + } + } } public function getBrick(type:BrickType):BrickConfig { @@ -179,4 +191,24 @@ class Config { public function getBonus(type:BonusType):BonusConfig { return bonusMap.get(type); } + + public function getTeam(team:TeamId):TeamConfig { + return teamsMap.get(team); + } + + public function getPlayer(playerId:PlayerId):PlayerConfig { + return playersMap.get(playerId); + } + + public function getColor(playerId:PlayerId):Color { + var player = getPlayer(playerId); + if (player != null && !player.color.zero) { + return player.color; + } + var team = getTeam(playerId.team); + if (team != null) { + return team.color; + } + return -1; + } } diff --git a/src/common/haxe/ru/m/tankz/game/GameState.hx b/src/common/haxe/ru/m/tankz/game/GameState.hx index 0e660ef..4c58bb8 100644 --- a/src/common/haxe/ru/m/tankz/game/GameState.hx +++ b/src/common/haxe/ru/m/tankz/game/GameState.hx @@ -34,6 +34,7 @@ class GameState { public var level:Int; public var players:Array; public var preset(get, null):GamePreset; + public var config(get, null):Config; @:provide private var configBundle:IConfigBundle; @@ -49,4 +50,8 @@ class GameState { var preset = config.getPreset(presetId); return preset; } + + private function get_config():Config { + return configBundle.get(type); + } }