[editor] update Frames

This commit is contained in:
2019-06-25 17:36:31 +03:00
parent bc95ca03e2
commit 9640414ba4
13 changed files with 69 additions and 198 deletions

View File

@@ -5,14 +5,15 @@ import haxework.view.ImageView;
import haxework.view.LabelView;
import openfl.Assets;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
@:template class LifeView extends HGroupView {
@:provide static var currentState:GameState;
@:view("tank") public var tankImage:ImageView;
@:view("life") public var lifeLabel:LabelView;
@:view("score") public var scoreLabel:LabelView;
public var playerId(default, default):PlayerId;
public var state(null, set):PlayerState;
public var tank(null, set):String;
public var color(null, set):Int;
@@ -20,8 +21,11 @@ import ru.m.tankz.game.GameState;
public var score(null, set):Int;
private inline function set_state(value:PlayerState):PlayerState {
state = value;
toUpdate();
playerId = value.id;
tank = value.tank;
color = value.color;
life = value.life;
score = value.score;
return state;
}
@@ -48,17 +52,6 @@ import ru.m.tankz.game.GameState;
return value;
}
override public function update():Void {
super.update();
if (state != null && currentState != null) {
var tankConfig = currentState.config.getTank(state.tank);
tank = tankConfig == null ? 'ba' : tankConfig.skin;
color = currentState.config.getColor(state.id);
life = state.life;
score = state.score;
}
}
public static inline function factory(index:Int, data:PlayerState):LifeView {
var result = new LifeView();
result.state = data;

View File

@@ -1,119 +0,0 @@
package ru.m.tankz.view.common;
import haxework.resources.IResources;
import haxework.color.ColorUtil;
import haxework.view.DataView;
import haxework.view.HGroupView;
import haxework.view.LabelView;
import haxework.view.skin.ISkin;
import haxework.view.ToggleButtonView;
import ru.m.tankz.control.Control;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type.TeamId;
class TeamButton extends ToggleButtonView {
public var team(default, set):TeamId;
private function set_team(value:TeamId):TeamId {
if (team != value) {
team = value;
text = team.substr(0, 1).toUpperCase() + team.substr(1);
}
return team;
}
}
class TeamSkin implements ISkin<TeamButton> {
@:provide private static var resources:IResources;
public var color(default, default):Int;
public function new(color:Int) {
this.color = color;
}
public function draw(view:TeamButton):Void {
view.fontColor = view.on ? 0xffffff : resources.color.get("dark");
var graphics = view.content.graphics;
graphics.beginFill(view.on ? color : resources.color.get("light"));
graphics.lineStyle(2, color, 0.5);
graphics.drawRoundRect(0, 0, view.width, view.height, 5, 5);
graphics.endFill();
graphics.lineStyle();
}
}
@:template class PlayerView extends HGroupView {
private static inline var TEAM_NONE:TeamId = "none";
public var item_index(default, set):Int;
public var data(default, set):Array<PlayerState>;
public var colorize:Bool;
@:view var label(default, null):LabelView;
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
@:provide var state:GameState;
private var player:PlayerState;
private function teamViewFactory(index:Int, team:TeamId) {
var view = new TeamButton();
var color = getTeamColor(team);
view.skin = [Style.text(color), new TeamSkin(color)];
view.geometry.padding = [10, 5];
view.team = team;
view.on = team == TEAM_NONE;
return view;
}
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
data = value;
teams.data = [TEAM_NONE].concat([for (team in state.preset.teams) team.id]);
return data;
}
private function getTeamColor(teamId:TeamId):Int {
var color = 0xaaaaaa;
for (team in state.preset.teams) {
if (team.id == teamId) {
if (!team.color.zero) color = team.color;
break;
}
}
return color;
}
private function set_item_index(value:Int):Int {
item_index = value;
label.text = 'Player ${item_index+1}';
return item_index;
}
private function onTeamSelect(team:TeamId) {
if (player != null) {
player.controller = NONE;
player.color = 0;
player = null;
}
for (p in data) {
if (p.id.team == team) {
switch (p.controller) {
case NONE:
player = p;
player.controller = HUMAN(item_index);
if (colorize) {
player.color = ColorUtil.multiply(state.config.getTeam(team).color, 1.7);
}
break;
case _:
}
}
}
for (view in teams.views) {
var button = cast(view, TeamButton);
button.on = team == button.team;
}
}
}

View File

@@ -4,8 +4,10 @@ import haxework.view.DataView;
import haxework.view.LabelView;
import haxework.view.VGroupView;
import ru.m.geom.Direction;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.preset.DeathGame;
import ru.m.tankz.view.common.LifeView;
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
@@ -14,15 +16,31 @@ import ru.m.tankz.view.common.LifeView;
@:view var level:LabelView;
@:view var players:DataView<PlayerState, LifeView>;
@:provide var configBundle:IConfigBundle;
private function getView(playerId):LifeView {
for (view in players.dataViews) {
if (view.playerId == playerId) {
return view;
}
}
return null;
}
public function onGameEvent(event:GameEvent):Void {
switch event {
case START(start):
this.level.text = 'Level ${start.level.id}';
players.data = Lambda.array(start.state.players);
case SPAWN(TANK(_, _, playerId, info)):
var skin = configBundle.get(DeathGame.TYPE).getTank(info.type).skin;
getView(playerId).tank = skin;
getView(playerId).color = info.color;
case CHANGE(PLAYER_LIFE(playerId, life)):
getView(playerId).life = life;
case CHANGE(PLAYER_SCORE(playerId, score)):
getView(playerId).score = score;
case _:
for (view in players.views) {
view.toUpdate();
}
}
}
}