[client] update StartFrame
This commit is contained in:
25
src/client/haxe/ru/m/skin/SimpleButtonSkin.hx
Normal file
25
src/client/haxe/ru/m/skin/SimpleButtonSkin.hx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package ru.m.skin;
|
||||||
|
|
||||||
|
import flash.display.Graphics;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.skin.ButtonColorSkin;
|
||||||
|
|
||||||
|
class SimpleButtonSkin extends ButtonColorSkin {
|
||||||
|
|
||||||
|
public var borderColor(default, default):Int;
|
||||||
|
|
||||||
|
public function new(color:Int = 0xffffff, borderColor:Int = 0x95937D) {
|
||||||
|
super(color, 0.6);
|
||||||
|
this.borderColor = borderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function draw(view:ButtonView):Void {
|
||||||
|
var color:Int = selectColor(view);
|
||||||
|
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||||
|
graphics.clear();
|
||||||
|
graphics.beginFill(color, alpha);
|
||||||
|
graphics.lineStyle(2, borderColor);
|
||||||
|
graphics.drawRoundRect(0, 0, view.width, view.height, 10, 10);
|
||||||
|
graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,16 @@ button:
|
|||||||
fontColor: "#E7E0BB"
|
fontColor: "#E7E0BB"
|
||||||
fontSize: 20
|
fontSize: 20
|
||||||
|
|
||||||
|
button_simple:
|
||||||
|
width: 100
|
||||||
|
height: 36
|
||||||
|
skin:
|
||||||
|
$type: ru.m.skin.SimpleButtonSkin
|
||||||
|
fontFamily: "@res:text:font"
|
||||||
|
fontEmbed: true
|
||||||
|
fontColor: "#95937D"
|
||||||
|
fontSize: 20
|
||||||
|
|
||||||
label:
|
label:
|
||||||
fontColor: "#ffffff"
|
fontColor: "#ffffff"
|
||||||
fontEmbed: false
|
fontEmbed: false
|
||||||
|
|||||||
@@ -16,12 +16,8 @@ class StartFrame extends VGroupView {
|
|||||||
|
|
||||||
public static var ID(default, never):String = "start";
|
public static var ID(default, never):String = "start";
|
||||||
|
|
||||||
@:view var classic_1p(default, null):ButtonView;
|
@:view var classic(default, null):ButtonView;
|
||||||
@:view var classic_2p(default, null):ButtonView;
|
@:view var dota(default, null):ButtonView;
|
||||||
@:view var classic_load(default, null):ButtonView;
|
|
||||||
@:view var dota_1p(default, null):ButtonView;
|
|
||||||
@:view var dota_2p_coop(default, null):ButtonView;
|
|
||||||
@:view var dota_2p_vs(default, null):ButtonView;
|
|
||||||
@:view var network(default, null):ButtonView;
|
@:view var network(default, null):ButtonView;
|
||||||
@:view var settings(default, null):ButtonView;
|
@:view var settings(default, null):ButtonView;
|
||||||
|
|
||||||
@@ -29,40 +25,18 @@ class StartFrame extends VGroupView {
|
|||||||
@:provide var storage:SaveStorage;
|
@:provide var storage:SaveStorage;
|
||||||
|
|
||||||
public function init():Void {
|
public function init():Void {
|
||||||
classic_1p.onPress = this;
|
classic.onPress = this;
|
||||||
classic_2p.onPress = this;
|
dota.onPress = this;
|
||||||
classic_load.onPress = this;
|
|
||||||
dota_1p.onPress = this;
|
|
||||||
dota_2p_coop.onPress = this;
|
|
||||||
dota_2p_vs.onPress = this;
|
|
||||||
network.onPress = this;
|
network.onPress = this;
|
||||||
settings.onPress = this;
|
settings.onPress = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
var save:GameSave = storage.read(ClassicGame.TYPE);
|
|
||||||
if (save != null) {
|
|
||||||
classic_load.visible = true;
|
|
||||||
classic_load.text = 'Load (Level ${save.state.level})';
|
|
||||||
} else {
|
|
||||||
classic_load.visible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
public function onPress(view:ButtonView):Void {
|
||||||
switch (view.id) {
|
switch (view.id) {
|
||||||
case 'classic_1p':
|
case 'classic':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
||||||
case 'classic_2p':
|
case 'dota':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
|
|
||||||
case 'classic_load':
|
|
||||||
loadGame(ClassicGame.TYPE);
|
|
||||||
case 'dota_1p':
|
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
||||||
case 'dota_2p_coop':
|
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_COOP);
|
|
||||||
case 'dota_2p_vs':
|
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_VS);
|
|
||||||
case 'network':
|
case 'network':
|
||||||
frameSwitcher.change(NetworkFrame.ID);
|
frameSwitcher.change(NetworkFrame.ID);
|
||||||
case 'settings':
|
case 'settings':
|
||||||
@@ -74,10 +48,4 @@ class StartFrame extends VGroupView {
|
|||||||
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
|
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
|
||||||
frameSwitcher.change(StartGameFrame.ID);
|
frameSwitcher.change(StartGameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadGame(type:GameType):Void {
|
|
||||||
var save:GameSave = storage.read(type);
|
|
||||||
Provider.set(GameSave, save);
|
|
||||||
frameSwitcher.change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,69 +7,22 @@ views:
|
|||||||
image: "@asset:image:resources/image/ui/logo.png"
|
image: "@asset:image:resources/image/ui/logo.png"
|
||||||
contentSize: true
|
contentSize: true
|
||||||
bottomMargin: 15
|
bottomMargin: 15
|
||||||
- $type: haxework.gui.HGroupView
|
|
||||||
contentSize: true
|
|
||||||
views:
|
|
||||||
- $type: haxework.gui.VGroupView
|
- $type: haxework.gui.VGroupView
|
||||||
contentSize: true
|
contentSize: true
|
||||||
views:
|
views:
|
||||||
# classic
|
- id: classic
|
||||||
- $type: haxework.gui.LabelView
|
$type: haxework.gui.ButtonView
|
||||||
$style: label
|
|
||||||
fontSize: 20
|
|
||||||
topMargin: 15
|
|
||||||
contentSize: true
|
|
||||||
text: Classic
|
text: Classic
|
||||||
- id: classic_1p
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: 1 Player
|
|
||||||
$style: button
|
$style: button
|
||||||
- id: classic_2p
|
- id: dota
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
text: 2 Player
|
|
||||||
$style: button
|
|
||||||
- id: classic_load
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: Load
|
|
||||||
$style: button
|
|
||||||
- $type: haxework.gui.VGroupView
|
|
||||||
contentSize: true
|
|
||||||
views:
|
|
||||||
# dota
|
|
||||||
- $type: haxework.gui.LabelView
|
|
||||||
$style: label
|
|
||||||
fontSize: 20
|
|
||||||
topMargin: 15
|
|
||||||
contentSize: true
|
|
||||||
text: DotA
|
text: DotA
|
||||||
- id: dota_1p
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: 1 Player
|
|
||||||
$style: button
|
$style: button
|
||||||
- id: dota_2p_coop
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: 2 COOP
|
|
||||||
$style: button
|
|
||||||
- id: dota_2p_vs
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: 2 VS
|
|
||||||
$style: button
|
|
||||||
# network
|
|
||||||
- $type: haxework.gui.VGroupView
|
|
||||||
contentSize: true
|
|
||||||
visible: true
|
|
||||||
views:
|
|
||||||
- $type: haxework.gui.LabelView
|
|
||||||
$style: label
|
|
||||||
fontSize: 20
|
|
||||||
topMargin: 15
|
|
||||||
contentSize: true
|
|
||||||
text: Network (in developing)
|
|
||||||
fontColor: 0xff0000
|
|
||||||
- id: network
|
- id: network
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
text: Network
|
text: Network (in developing)
|
||||||
$style: button
|
$style: button
|
||||||
|
fontColor: 0xff0000
|
||||||
- $type: haxework.gui.LabelView
|
- $type: haxework.gui.LabelView
|
||||||
$style: label
|
$style: label
|
||||||
inLayout: false
|
inLayout: false
|
||||||
|
|||||||
@@ -1,37 +1,79 @@
|
|||||||
package ru.m.tankz.frame;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
import ru.m.tankz.config.Config.PlayerConfig;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.frame.level.PresetsView;
|
||||||
import ru.m.tankz.game.GameSave;
|
import ru.m.tankz.game.GameSave;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/StartGameFrame.yaml", "ru/m/tankz/Style.yaml")
|
@:template("ru/m/tankz/frame/StartGameFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||||
class StartGameFrame extends HGroupView {
|
class StartGameFrame extends VGroupView {
|
||||||
public static inline var ID = "level";
|
public static inline var ID = "level";
|
||||||
|
|
||||||
|
@:view var presets(default, null):PresetsView;
|
||||||
@:view var players(default, null):ListView<PlayerConfig>;
|
@:view var players(default, null):ListView<PlayerConfig>;
|
||||||
@:view var levels(default, null):ListView<Int>;
|
@:view var levels(default, null):ListView<Int>;
|
||||||
|
|
||||||
|
@:provide var save:GameSave;
|
||||||
|
@:provide var storage:SaveStorage;
|
||||||
|
|
||||||
|
public var gameType(default, set):GameType;
|
||||||
|
public var presetId(default, set):PresetId;
|
||||||
|
|
||||||
|
private var config:Config;
|
||||||
|
private var preset:GamePreset;
|
||||||
|
|
||||||
public function init():Void {
|
public function init():Void {
|
||||||
levels.dispatcher.addListener(this);
|
levels.dispatcher.addListener(this);
|
||||||
|
presets.change.connect(function(presetId) this.presetId = presetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
private function set_gameType(value:GameType):GameType {
|
||||||
var save:GameSave = Provider.get(GameSave);
|
if (gameType != value) {
|
||||||
var config:Config = Provider.get(IConfigBundle).get(save.state.type);
|
gameType = value;
|
||||||
var preset:GamePreset = config.getPreset(save.state.presetId);
|
config = Provider.get(IConfigBundle).get(gameType);
|
||||||
|
presets.data = config.presets;
|
||||||
levels.data = [for (i in 0...config.game.levels) i];
|
levels.data = [for (i in 0...config.game.levels) i];
|
||||||
|
presetId = null;
|
||||||
|
presetId = config.presets[0].id;
|
||||||
|
|
||||||
|
var save:GameSave = storage.read(gameType);
|
||||||
|
// ToDo: start save button
|
||||||
|
}
|
||||||
|
return gameType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_presetId(value:PresetId):PresetId {
|
||||||
|
if (presetId != value) {
|
||||||
|
presetId = value;
|
||||||
|
presets.selected = presetId;
|
||||||
|
save.state.presetId = presetId;
|
||||||
|
if (presetId != null) {
|
||||||
|
preset = config.getPreset(presetId);
|
||||||
var players:Array<PlayerConfig> = [];
|
var players:Array<PlayerConfig> = [];
|
||||||
for (team in preset.teams) {
|
for (team in preset.teams) {
|
||||||
players.push({index: -1, control: 'Team "${team.id}"', tanks: []});
|
players.push({index: -1, control: 'Team "${team.id}"', tanks: []});
|
||||||
players = players.concat(team.players);
|
players = players.concat(team.players);
|
||||||
}
|
}
|
||||||
this.players.data = players;
|
this.players.data = players;
|
||||||
|
} else {
|
||||||
|
this.players.data = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return presetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
gameType = save.state.type;
|
||||||
|
if (save.state.presetId != null) {
|
||||||
|
presetId = save.state.presetId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onListItemClick(item:IListItemView<Int>):Void {
|
public function onListItemClick(item:IListItemView<Int>):Void {
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
---
|
---
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: presets
|
||||||
|
$type: ru.m.tankz.frame.level.PresetsView
|
||||||
|
contentSize: true
|
||||||
|
topMargin: 10
|
||||||
|
- $type: haxework.gui.HGroupView
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
views:
|
views:
|
||||||
|
|||||||
61
src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx
Normal file
61
src/client/haxe/ru/m/tankz/frame/level/PresetsView.hx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package ru.m.tankz.frame.level;
|
||||||
|
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import ru.m.skin.SimpleButtonSkin;
|
||||||
|
import ru.m.signal.Signal.Signal1;
|
||||||
|
import haxework.gui.ToggleButtonView;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import ru.m.tankz.config.Config.GamePreset;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
|
|
||||||
|
class PresetsView extends HGroupView {
|
||||||
|
|
||||||
|
public var data(default, set):Array<GamePreset>;
|
||||||
|
public var selected(default, set):PresetId;
|
||||||
|
|
||||||
|
public var change(default, null):Signal1<PresetId>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
layoutMargin = 10;
|
||||||
|
change = new Signal1();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_data(value:Array<GamePreset>):Array<GamePreset> {
|
||||||
|
data = value;
|
||||||
|
removeAllViews();
|
||||||
|
for (item in data) {
|
||||||
|
var view = new ToggleButtonView();
|
||||||
|
view.skin = new SimpleButtonSkin();
|
||||||
|
view.onSkin = new SimpleButtonSkin(0x00ff00);
|
||||||
|
view.text = item.id;
|
||||||
|
view.width = 250;
|
||||||
|
view.height = 36;
|
||||||
|
view.fontFamily = Provider.get(IResources).text.get("font");
|
||||||
|
view.fontEmbed = true;
|
||||||
|
view.fontColor = 0x95937D;
|
||||||
|
view.fontSize = 20;
|
||||||
|
view.onPress = this;
|
||||||
|
view.update();
|
||||||
|
addView(view);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_selected(value:PresetId):PresetId {
|
||||||
|
selected = value;
|
||||||
|
for (view in views) {
|
||||||
|
var button = cast(view, ToggleButtonView);
|
||||||
|
button.on = button.text == selected;
|
||||||
|
}
|
||||||
|
change.emit(selected);
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
selected = view.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,23 @@
|
|||||||
$type: haxework.gui.VGroupView
|
|
||||||
layoutMargin: 10
|
layoutMargin: 10
|
||||||
views:
|
views:
|
||||||
- id: label
|
- id: label
|
||||||
$type: haxework.gui.LabelView
|
$type: haxework.gui.LabelView
|
||||||
$style: label
|
$style: label
|
||||||
|
- $type: haxework.gui.HGroupView
|
||||||
|
contentSize: true
|
||||||
|
layoutMargin: 10
|
||||||
|
views:
|
||||||
- id: change
|
- id: change
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
$style: button
|
$style: button_simple
|
||||||
text: Change
|
text: Change
|
||||||
- id: clear
|
- id: clear
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
$style: button
|
$style: button_simple
|
||||||
text: Clear
|
text: Clear
|
||||||
- id: reset
|
- id: reset
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
$style: button
|
$style: button_simple
|
||||||
text: Reset
|
text: Reset
|
||||||
- id: list
|
- id: list
|
||||||
$type: haxework.gui.list.VListView<ru.m.tankz.control.ActionItem>
|
$type: haxework.gui.list.VListView<ru.m.tankz.control.ActionItem>
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ class SettingsStorage {
|
|||||||
1 => new ActionConfig([
|
1 => new ActionConfig([
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.RIGHT},
|
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.DOWN},
|
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
||||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user