[client] add ResultFrame

This commit is contained in:
2019-03-15 16:15:47 +03:00
parent f09e70c5f8
commit c67385576e
10 changed files with 142 additions and 8 deletions

View File

@@ -24,7 +24,11 @@ views:
$type: ru.m.tankz.frame.dota.DotaLevelFrame $type: ru.m.tankz.frame.dota.DotaLevelFrame
- id: dota.game - id: dota.game
$type: ru.m.tankz.frame.dota.DotaGameFrame $type: ru.m.tankz.frame.dota.DotaGameFrame
# result
- id: result
$type: ru.m.tankz.frame.ResultFrame
# - id: network # - id: network
# $type: ru.m.tankz.frame.NetworkFrame # $type: ru.m.tankz.frame.NetworkFrame
# settings
- id: settings - id: settings
$type: ru.m.tankz.frame.SettingsFrame $type: ru.m.tankz.frame.SettingsFrame

View File

@@ -70,5 +70,9 @@ class Style {
Skin.size(64, 64), Skin.size(64, 64),
new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor) 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)
]);
} }
} }

View File

@@ -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<PlayerState, LifeView>;
@: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);
}
}

View File

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

View File

@@ -22,6 +22,7 @@ class GameFrame extends GroupView {
@:provide var network:NetworkManager; @:provide var network:NetworkManager;
@:provide var sound:SoundManager; @:provide var sound:SoundManager;
@:provide var state:GameState; @:provide var state:GameState;
@:provide("result") var result:GameState;
@:provide var switcher:FrameSwitcher; @:provide var switcher:FrameSwitcher;
private var game:Game; private var game:Game;
@@ -70,13 +71,13 @@ class GameFrame extends GroupView {
} }
private function onGameComplete(_):Void { private function onGameComplete(_):Void {
switch (game.next()) { result = state;
case Option.Some(s): state = switch game.next() {
stop(); case Option.Some(s): s;
start(s); case Option.None: null;
case Option.None:
switcher.change(StartFrame.ID);
} }
stop();
switcher.change(ResultFrame.ID);
} }
public function onHide():Void { public function onHide():Void {

View File

@@ -16,7 +16,9 @@ import haxework.gui.HGroupView;
public var score(null, set):Int; public var score(null, set):Int;
private inline function set_tank(value:String):String { private inline function set_tank(value:String):String {
if (value != null) {
tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png'); tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png');
}
return value; return value;
} }

View File

@@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="arrow-alt-circle-right" class="svg-inline--fa fa-arrow-alt-circle-right fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8c137 0 248 111 248 248S393 504 256 504 8 393 8 256 119 8 256 8zM140 300h116v70.9c0 10.7 13 16.1 20.5 8.5l114.3-114.9c4.7-4.7 4.7-12.2 0-16.9l-114.3-115c-7.6-7.6-20.5-2.2-20.5 8.5V212H140c-6.6 0-12 5.4-12 12v64c0 6.6 5.4 12 12 12z"></path></svg>

After

Width:  |  Height:  |  Size: 499 B

View File

@@ -106,7 +106,7 @@ class BotControl extends Control {
// ToDo: // ToDo:
if (handler == null || tank == null) return; if (handler == null || tank == null) return;
var eagle:Eagle = BotHelper.findEagle(playerId.team, handler); 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))); action(TankAction.MOVE(BotHelper.getDirectionTo(tank, eagle)));
} else { } else {
action(TankAction.MOVE(BotHelper.randomDirection())); action(TankAction.MOVE(BotHelper.randomDirection()));

View File

@@ -117,6 +117,8 @@ class Config {
private var tankMap:Map<TankType, TankConfig>; private var tankMap:Map<TankType, TankConfig>;
private var presetsMap:Map<PresetId, GamePreset>; private var presetsMap:Map<PresetId, GamePreset>;
private var bonusMap:Map<BonusType, BonusConfig>; private var bonusMap:Map<BonusType, BonusConfig>;
private var teamsMap:Map<TeamId, TeamConfig>;
private var playersMap:Map<String, PlayerConfig>;
public function new( public function new(
type:String, type:String,
@@ -158,6 +160,16 @@ class Config {
for (item in bonuses) { for (item in bonuses) {
bonusMap.set(item.type, item); 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 { public function getBrick(type:BrickType):BrickConfig {
@@ -179,4 +191,24 @@ class Config {
public function getBonus(type:BonusType):BonusConfig { public function getBonus(type:BonusType):BonusConfig {
return bonusMap.get(type); 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;
}
} }

View File

@@ -34,6 +34,7 @@ class GameState {
public var level:Int; public var level:Int;
public var players:Array<PlayerState>; public var players:Array<PlayerState>;
public var preset(get, null):GamePreset; public var preset(get, null):GamePreset;
public var config(get, null):Config;
@:provide private var configBundle:IConfigBundle; @:provide private var configBundle:IConfigBundle;
@@ -49,4 +50,8 @@ class GameState {
var preset = config.getPreset(presetId); var preset = config.getPreset(presetId);
return preset; return preset;
} }
private function get_config():Config {
return configBundle.get(type);
}
} }