[client] LevelFrame
This commit is contained in:
21
src/client/haxe/layout/frames/level.json
Normal file
21
src/client/haxe/layout/frames/level.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id":"levels", "@type":"haxework.gui.list.VListView<Int>",
|
||||||
|
"factory": "@class:ru.m.tankz.view.frames.list.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": "0x000000", "alpha": 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -15,6 +15,10 @@
|
|||||||
"id": "start",
|
"id": "start",
|
||||||
"@type": "ru.m.tankz.view.frames.StartFrame"
|
"@type": "ru.m.tankz.view.frames.StartFrame"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "level",
|
||||||
|
"@type": "ru.m.tankz.view.frames.LevelFrame"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "game",
|
"id": "game",
|
||||||
"@type": "ru.m.tankz.view.frames.GameFrame"
|
"@type": "ru.m.tankz.view.frames.GameFrame"
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
{
|
{
|
||||||
"person": {
|
"level": {
|
||||||
"width": 440, "height": 44,
|
"width": 440, "height": 44,
|
||||||
|
"margins": 5,
|
||||||
"views": [
|
"views": [
|
||||||
{
|
{
|
||||||
"id": "nameLabel",
|
"id": "label",
|
||||||
"@type": "haxework.gui.LabelView",
|
"@type": "haxework.gui.LabelView",
|
||||||
"pWidth": 100, "height": 44, "text": "Выбор персонажа",
|
"pWidth": 100, "pHeight": 100, "text": "",
|
||||||
"@style": "label"
|
"@style": "label"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"skin": {
|
||||||
|
"@type": "haxework.gui.skin.ColorSkin",
|
||||||
|
"color": "0x000000", "alpha": 0.2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import flash.display.DisplayObjectContainer;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import Type.ValueType;
|
import Type.ValueType;
|
||||||
@@ -68,15 +69,21 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
|
while (layer.numChildren > 0) layer.removeChildAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
public function reset():Void {
|
public function reset():Void {
|
||||||
items = new Map<String, RenderItem<Dynamic>>();
|
items = new Map<String, RenderItem<Dynamic>>();
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
backgroundLayer.removeChild(background);
|
backgroundLayer.removeChild(background);
|
||||||
background = null;
|
background = null;
|
||||||
}
|
}
|
||||||
|
clearLayer(entryLayer);
|
||||||
|
clearLayer(groundLayer);
|
||||||
|
clearLayer(upLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function onSpawn(entity:EntityType):Void {
|
||||||
switch(entity) {
|
switch(entity) {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
|
|||||||
35
src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx
Normal file
35
src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.ConfigBundle;
|
||||||
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
|
||||||
|
|
||||||
|
interface LevelFrameLayout {
|
||||||
|
var levels(default, null):ListView<Int>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@:template("layout/frames/level.json", "layout/styles.json")
|
||||||
|
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout implements ListViewListener<Int> {
|
||||||
|
public static inline var ID = "level";
|
||||||
|
|
||||||
|
public function init():Void {
|
||||||
|
levels.dispatcher.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
var state = Provider.get(GameState);
|
||||||
|
var c = ConfigBundle.get(state.type).levels;
|
||||||
|
levels.data = [for (i in 0...c) i];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onListItemClick(item:IListItemView<Int>):Void {
|
||||||
|
Provider.get(GameState).level = item.data;
|
||||||
|
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,6 @@ class StartFrame extends VGroupView implements ViewBuilder {
|
|||||||
|
|
||||||
private function startGame(humans:Int):Void {
|
private function startGame(humans:Int):Void {
|
||||||
Provider.set(GameState, ClassicGame.buildState(0, humans));
|
Provider.set(GameState, ClassicGame.buildState(0, humans));
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package ru.m.tankz.view.frames.list;
|
|
||||||
|
|
||||||
import ru.m.tankz.proto.Person;
|
|
||||||
import ru.m.tankz.proto.Game;
|
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
|
||||||
import haxework.gui.LabelView;
|
|
||||||
import haxework.gui.skin.ColorSkin;
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
|
|
||||||
class GameView extends HGroupView implements IListItemView<Game> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):Game;
|
|
||||||
|
|
||||||
private var nameLabel:LabelView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
pWidth = 100;
|
|
||||||
height = 50;
|
|
||||||
skin = new ColorSkin(0xffffff);
|
|
||||||
|
|
||||||
nameLabel = new LabelView();
|
|
||||||
addView(nameLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_data(value:Game):Game {
|
|
||||||
this.data = value;
|
|
||||||
var persons:String = Lambda.map(this.data.persons, function(p:Person) return p.name).join(",");
|
|
||||||
nameLabel.text = "Game_" + this.data.id + "(" + persons + ")";
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
src/client/haxe/ru/m/tankz/view/frames/list/LevelView.hx
Executable file
24
src/client/haxe/ru/m/tankz/view/frames/list/LevelView.hx
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
package ru.m.tankz.view.frames.list;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView.IListItemView;
|
||||||
|
|
||||||
|
|
||||||
|
interface LevelViewLayout {
|
||||||
|
var label(default, null):LabelView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template("layout/other.json@level", "layout/styles.json")
|
||||||
|
class LevelView extends HGroupView implements ViewBuilder implements IListItemView<Int> implements LevelViewLayout {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):Int;
|
||||||
|
|
||||||
|
private function set_data(value:Int):Int {
|
||||||
|
data = value;
|
||||||
|
label.text = 'Level ${data}';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package ru.m.tankz.view.frames.list;
|
|
||||||
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
|
||||||
import ru.m.tankz.proto.Person;
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
|
|
||||||
@:template("layout/other.json@person", "layout/styles.json")
|
|
||||||
class PersonView extends HGroupView implements ViewBuilder implements IListItemView<Person> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):Person;
|
|
||||||
|
|
||||||
private function set_data(value:Person):Person {
|
|
||||||
this.data = value;
|
|
||||||
nameLabel.text = this.data.name;
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
levels: 36
|
||||||
|
|
||||||
map:
|
map:
|
||||||
cellWidth: 22
|
cellWidth: 22
|
||||||
cellHeight: 22
|
cellHeight: 22
|
||||||
@@ -54,6 +54,7 @@ typedef TeamConfig = {
|
|||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
public var type(default, null):String;
|
public var type(default, null):String;
|
||||||
|
public var levels(default, null):Int;
|
||||||
public var map(default, null):MapConfig;
|
public var map(default, null):MapConfig;
|
||||||
public var bricks(default, null):Array<BrickConfig>;
|
public var bricks(default, null):Array<BrickConfig>;
|
||||||
public var tanks(default, null):Array<TankConfig>;
|
public var tanks(default, null):Array<TankConfig>;
|
||||||
@@ -63,8 +64,9 @@ class Config {
|
|||||||
private var tankMap:Map<String, Map<String, TankConfig>>;
|
private var tankMap:Map<String, Map<String, TankConfig>>;
|
||||||
private var teamMap:Map<String, TeamConfig>;
|
private var teamMap:Map<String, TeamConfig>;
|
||||||
|
|
||||||
public function new(type:String, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
public function new(type:String, levels:Int, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.levels = levels;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.bricks = bricks;
|
this.bricks = bricks;
|
||||||
this.teams = teams;
|
this.teams = teams;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import ru.m.tankz.config.Config;
|
|||||||
|
|
||||||
|
|
||||||
typedef ConfigSource = {
|
typedef ConfigSource = {
|
||||||
|
var levels:Int;
|
||||||
var map: MapConfig;
|
var map: MapConfig;
|
||||||
var bricks: Array<BrickConfig>;
|
var bricks: Array<BrickConfig>;
|
||||||
var teams: Array<TeamConfig>;
|
var teams: Array<TeamConfig>;
|
||||||
@@ -23,7 +24,7 @@ class ConfigBundle {
|
|||||||
public static function get(type:String):Config {
|
public static function get(type:String):Config {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ClassicGame.TYPE:
|
case ClassicGame.TYPE:
|
||||||
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects()));
|
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
|
||||||
var tanks:Array<TankConfig> = [];
|
var tanks:Array<TankConfig> = [];
|
||||||
for (group in Reflect.fields(source.tanks)) {
|
for (group in Reflect.fields(source.tanks)) {
|
||||||
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
|
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
|
||||||
@@ -32,7 +33,7 @@ class ConfigBundle {
|
|||||||
tanks.push(item);
|
tanks.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Config(type, source.map, source.bricks, source.teams, tanks);
|
return new Config(type, source.levels, source.map, source.bricks, source.teams, tanks);
|
||||||
case _:
|
case _:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ import ru.m.tankz.game.Game;
|
|||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
|
||||||
|
|
||||||
class MapBundle {
|
class LevelBundle {
|
||||||
|
|
||||||
|
private static function formatLevel(level:Int):String {
|
||||||
|
var result = Std.string(level);
|
||||||
|
while (result.length < 3) result = '0${result}';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static function get(type:GameType, config:Config, level:Int):Array<BrickConfig> {
|
public static function get(type:GameType, config:Config, level:Int):Array<BrickConfig> {
|
||||||
var bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
|
var bricksData:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt');
|
||||||
var bricks:Array<BrickConfig> = [];
|
var bricks:Array<BrickConfig> = [];
|
||||||
for (line in ~/\s+/g.split(bricksData)) {
|
for (line in ~/\s+/g.split(bricksData)) {
|
||||||
for (c in line.split('')) {
|
for (c in line.split('')) {
|
||||||
@@ -3,7 +3,7 @@ package ru.m.tankz.game;
|
|||||||
import ru.m.tankz.bot.BotControl;
|
import ru.m.tankz.bot.BotControl;
|
||||||
import ru.m.tankz.control.HumanControl;
|
import ru.m.tankz.control.HumanControl;
|
||||||
import ru.m.tankz.config.ConfigBundle;
|
import ru.m.tankz.config.ConfigBundle;
|
||||||
import ru.m.tankz.config.MapBundle;
|
import ru.m.tankz.config.LevelBundle;
|
||||||
import ru.m.tankz.game.Spawner;
|
import ru.m.tankz.game.Spawner;
|
||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
@@ -60,7 +60,7 @@ class Game implements EngineListener {
|
|||||||
|
|
||||||
public function start(state:GameState):Void {
|
public function start(state:GameState):Void {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
var bricks = MapBundle.get(type, config, state.level);
|
var bricks = LevelBundle.get(type, config, state.level);
|
||||||
engine.map.setData(bricks);
|
engine.map.setData(bricks);
|
||||||
teams = new Map<TeamId, Team>();
|
teams = new Map<TeamId, Team>();
|
||||||
spawners = new Map<TeamId, Spawner>();
|
spawners = new Map<TeamId, Spawner>();
|
||||||
|
|||||||
Reference in New Issue
Block a user