Compare commits
1 Commits
0.16.0
...
event_prot
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e9ced333 |
29
CHANGELOG.md
29
CHANGELOG.md
@@ -1,29 +0,0 @@
|
|||||||
0.15.0
|
|
||||||
------
|
|
||||||
* Added display tank player name in `Render`
|
|
||||||
* Fixed join game after relogin
|
|
||||||
* Updated `CreateGamePopup` for any screen sizes
|
|
||||||
* Fixed tank destroy zero score label
|
|
||||||
* Added custom size map support
|
|
||||||
* Fixed clock bonus for spawned tanks
|
|
||||||
|
|
||||||
0.14.0
|
|
||||||
------
|
|
||||||
* Added `CreateGamePopup`
|
|
||||||
* Fixed null tank color
|
|
||||||
* Updated `Ticker`
|
|
||||||
|
|
||||||
0.13.0
|
|
||||||
------
|
|
||||||
* Added `Ticker`
|
|
||||||
* Fixed `PacketQueue` stream reading
|
|
||||||
* Added `PlayerControl` and `ControlPreset`
|
|
||||||
* Added `BaseControlFactory`
|
|
||||||
|
|
||||||
0.12.0
|
|
||||||
------
|
|
||||||
* Added `GameRoomFrame`
|
|
||||||
* Improved websocket connection with using binary protocol instead of text
|
|
||||||
* Added `GameListFrame`
|
|
||||||
* Added `DesktopConnection` for linux client build
|
|
||||||
* Updated `SoundManager`
|
|
||||||
84
WORK.md
84
WORK.md
@@ -1,11 +1,73 @@
|
|||||||
* **shovel** bonus with armor bricks
|
* build
|
||||||
* bonuses in dota/death mod
|
* gulp 100%
|
||||||
* tanks and bullets speed balancing
|
* linux 100%
|
||||||
* result frame update (next game select, only human player info)
|
* deb-package 100%
|
||||||
* network game series
|
* windows 0%
|
||||||
* map packs (create in editor, import in game, save imported in local storage)
|
* exe-package 0% (inno setup)
|
||||||
* update bots
|
|
||||||
* improve bonuses system
|
* deploy
|
||||||
* screen gamepad on mobiles
|
* capistrano 100%
|
||||||
* resize render on mobiles
|
|
||||||
* save state in classic game
|
* ui
|
||||||
|
* auth frame 0%
|
||||||
|
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
||||||
|
* select level frame 10%
|
||||||
|
* game frame 50%
|
||||||
|
|
||||||
|
* engine
|
||||||
|
* config 100%
|
||||||
|
* map 100%
|
||||||
|
* tanks 100%
|
||||||
|
* bullets 100%
|
||||||
|
* boxes 100%
|
||||||
|
* map changes 100%
|
||||||
|
* bonuses 100%
|
||||||
|
* eagle 100%
|
||||||
|
|
||||||
|
* game
|
||||||
|
* classic
|
||||||
|
* state 50%
|
||||||
|
* bot 50%
|
||||||
|
* human 100%
|
||||||
|
* dota
|
||||||
|
* state 50%
|
||||||
|
* bot 10%
|
||||||
|
* human 100%
|
||||||
|
|
||||||
|
* bonus
|
||||||
|
* star 50%
|
||||||
|
* grenade 0%
|
||||||
|
* helm 0%
|
||||||
|
* clock 0%
|
||||||
|
* shovel 0%
|
||||||
|
|
||||||
|
* state
|
||||||
|
* score 0%
|
||||||
|
* human tank 0%
|
||||||
|
* save/load 0%
|
||||||
|
* export/import 0%
|
||||||
|
|
||||||
|
* render
|
||||||
|
* map 100%
|
||||||
|
* tanks 100%
|
||||||
|
* bullet 100%
|
||||||
|
* calc redraw 50%
|
||||||
|
* animations
|
||||||
|
* tank spawn 0%
|
||||||
|
* tank move 100%
|
||||||
|
* map water 100%
|
||||||
|
* bullet boom 90%
|
||||||
|
* tank boom 90%
|
||||||
|
* bonuses 100%
|
||||||
|
* html5 50%
|
||||||
|
|
||||||
|
* proto
|
||||||
|
...
|
||||||
|
|
||||||
|
* editor
|
||||||
|
* level
|
||||||
|
* open 100%
|
||||||
|
* edit 50%
|
||||||
|
* save 100%
|
||||||
|
* tank
|
||||||
|
* color 10%
|
||||||
19
gulpfile.js
19
gulpfile.js
@@ -1,6 +1,4 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const zip = require('gulp-zip');
|
|
||||||
const foreach = require('gulp-foreach');
|
|
||||||
const gulpClean = require('gulp-clean');
|
const gulpClean = require('gulp-clean');
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const packageInfo = require('./package.json');
|
const packageInfo = require('./package.json');
|
||||||
@@ -27,19 +25,6 @@ exports.generate = function generate() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.levels = function () {
|
|
||||||
return gulp.src("./src/common/level/*").pipe(foreach(function (stream, file) {
|
|
||||||
const type = file.path.substr(file.path.lastIndexOf("/") + 1);
|
|
||||||
gulp.src("./src/common/level/" + type + "/*").pipe(foreach(function (stream, file) {
|
|
||||||
const name = file.path.substr(file.path.lastIndexOf("/") + 1);
|
|
||||||
gulp.src("./src/common/level/" + type + "/" + name + "/*")
|
|
||||||
.pipe(zip(`${type}_${name}.zip`))
|
|
||||||
.pipe(gulp.dest("./target/levels"));
|
|
||||||
}));
|
|
||||||
return stream;
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToDo:
|
* ToDo:
|
||||||
* windows target
|
* windows target
|
||||||
@@ -61,8 +46,7 @@ const config = new Project.Config({
|
|||||||
'src-gen/haxe',
|
'src-gen/haxe',
|
||||||
],
|
],
|
||||||
assets: [
|
assets: [
|
||||||
'src/common/resources',
|
'src/common/resources'
|
||||||
'target/levels'
|
|
||||||
],
|
],
|
||||||
flags: [
|
flags: [
|
||||||
//'proto_debug',
|
//'proto_debug',
|
||||||
@@ -160,7 +144,6 @@ const server = new Project(
|
|||||||
*/
|
*/
|
||||||
module.exports.default = gulp.series(
|
module.exports.default = gulp.series(
|
||||||
exports.clean,
|
exports.clean,
|
||||||
exports.levels,
|
|
||||||
module.exports['client:flash:build'],
|
module.exports['client:flash:build'],
|
||||||
module.exports['client:flash:html'],
|
module.exports['client:flash:html'],
|
||||||
module.exports['client:html5:build'],
|
module.exports['client:html5:build'],
|
||||||
|
|||||||
2486
package-lock.json
generated
2486
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.16.0",
|
"version": "0.14.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-add": "0.0.2",
|
"gulp-add": "0.0.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-foreach": "^0.1.0",
|
"gulp-haxetool": "^0.0.19",
|
||||||
"gulp-haxetool": "0.0.20",
|
|
||||||
"gulp-zip": "^5.0.0",
|
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
import ru.m.control.IControlBus;
|
|
||||||
|
|
||||||
class ControlBus implements IControlBus {
|
|
||||||
|
|
||||||
private static inline var TAG = "control";
|
|
||||||
|
|
||||||
public var devices(default, null):Array<IControlDevice>;
|
|
||||||
|
|
||||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
|
||||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
|
||||||
|
|
||||||
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
devices = [];
|
|
||||||
signal = new Signal3();
|
|
||||||
devicesSignal = new Signal();
|
|
||||||
connections = new Map();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connect(device:IControlDevice):Void {
|
|
||||||
var connector = function(action:DeviceAction, on:Bool):Void {
|
|
||||||
//L.d("TAG", '${device.type}, ${action}, ${on}');
|
|
||||||
signal.emit(device.type, action, on);
|
|
||||||
}
|
|
||||||
connections.set(device.type, connector);
|
|
||||||
device.signal.connect(connector);
|
|
||||||
devices.push(device);
|
|
||||||
devicesSignal.emit(devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disconnect(device:IControlDevice):Void {
|
|
||||||
if (connections.exists(device.type)) {
|
|
||||||
device.signal.disconnect(connections.get(device.type));
|
|
||||||
connections.remove(device.type);
|
|
||||||
devices.remove(device);
|
|
||||||
devicesSignal.emit(devices);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
|
|
||||||
enum DeviceAction {
|
|
||||||
DIRECTION(direction:Direction);
|
|
||||||
KEY(code:Int);
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
enum DeviceType {
|
|
||||||
NONE;
|
|
||||||
KEYBOARD;
|
|
||||||
GAMEPAD(id:Int);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
|
|
||||||
interface IControlBus {
|
|
||||||
public var devices(default, null):Array<IControlDevice>;
|
|
||||||
|
|
||||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
|
||||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
|
||||||
|
|
||||||
public function connect(device:IControlDevice):Void;
|
|
||||||
public function disconnect(device:IControlDevice):Void;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
|
|
||||||
interface IControlDevice {
|
|
||||||
public var type(default, null):DeviceType;
|
|
||||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
|
||||||
|
|
||||||
public function dispose():Void;
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
import lime.ui.Joystick;
|
|
||||||
import ru.m.control.DeviceAction;
|
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
|
|
||||||
class JoystickDevice implements IControlDevice {
|
|
||||||
|
|
||||||
public var type(default, null):DeviceType;
|
|
||||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
|
||||||
|
|
||||||
private var joystick:Joystick;
|
|
||||||
private var axisState:Map<Int, Direction>;
|
|
||||||
|
|
||||||
public function new(joystick:Joystick) {
|
|
||||||
this.joystick = joystick;
|
|
||||||
type = GAMEPAD(joystick.id);
|
|
||||||
signal = new Signal2();
|
|
||||||
axisState = new Map();
|
|
||||||
joystick.onButtonDown.add(onButtonDown);
|
|
||||||
joystick.onButtonUp.add(onButtonUp);
|
|
||||||
joystick.onAxisMove.add(onAxisMove);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onButtonDown(code:Int):Void {
|
|
||||||
signal.emit(KEY(code), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onButtonUp(code:Int):Void {
|
|
||||||
signal.emit(KEY(code), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onAxisMove(axis:Int, position:Float):Void {
|
|
||||||
var direction:Direction = switch [axis, position] {
|
|
||||||
case [0, 1]: Direction.RIGHT;
|
|
||||||
case [0, -1]: Direction.LEFT;
|
|
||||||
case [1, 1]: Direction.BOTTOM;
|
|
||||||
case [1, -1]: Direction.TOP;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
if (direction != null) {
|
|
||||||
axisState.set(axis, direction);
|
|
||||||
signal.emit(DIRECTION(direction), true);
|
|
||||||
} else if (position == 0) {
|
|
||||||
if (axisState.exists(axis)) {
|
|
||||||
signal.emit(DIRECTION(axisState.get(axis)), false);
|
|
||||||
axisState.remove(axis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {
|
|
||||||
if (joystick != null) {
|
|
||||||
joystick.onButtonDown.remove(onButtonDown);
|
|
||||||
joystick.onButtonUp.remove(onButtonUp);
|
|
||||||
joystick.onAxisMove.remove(onAxisMove);
|
|
||||||
joystick = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package ru.m.control;
|
|
||||||
|
|
||||||
import flash.display.Stage;
|
|
||||||
import flash.events.KeyboardEvent;
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
import ru.m.control.DeviceAction;
|
|
||||||
|
|
||||||
class KeyboardDevice implements IControlDevice {
|
|
||||||
|
|
||||||
public var type(default, null):DeviceType;
|
|
||||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
|
||||||
|
|
||||||
private var stage:Stage;
|
|
||||||
|
|
||||||
public function new(stage:Stage) {
|
|
||||||
this.stage = stage;
|
|
||||||
type = DeviceType.KEYBOARD;
|
|
||||||
signal = new Signal2();
|
|
||||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
|
||||||
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onKeyDown(event:KeyboardEvent):Void {
|
|
||||||
signal.emit(KEY(event.keyCode), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onKeyUp(event:KeyboardEvent):Void {
|
|
||||||
signal.emit(KEY(event.keyCode), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {
|
|
||||||
if (stage != null) {
|
|
||||||
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
|
||||||
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
|
||||||
stage = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,18 +5,10 @@ import flash.display.DisplayObjectContainer;
|
|||||||
|
|
||||||
class DisplayObjectContainerExtender {
|
class DisplayObjectContainerExtender {
|
||||||
|
|
||||||
public static function childrenIterator():Iterator<DisplayObject> {
|
|
||||||
throw "Not implemented";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||||
if (self.contains(child)) {
|
if (self.contains(child)) {
|
||||||
return self.removeChild(child);
|
return self.removeChild(child);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
|
||||||
throw "Not implemented";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,33 @@ package ru.m.skin;
|
|||||||
|
|
||||||
import format.SVG;
|
import format.SVG;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.skin.ISkin;
|
import haxework.view.skin.ISkin;
|
||||||
|
|
||||||
using StringTools;
|
class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||||
using haxework.color.ColorUtil;
|
|
||||||
|
|
||||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
private var svg:String;
|
||||||
|
private var color:Color;
|
||||||
@:style(null) private var svg:String;
|
|
||||||
@:style(0) private var color:Null<Color>;
|
|
||||||
|
|
||||||
private var svgs:Map<ButtonState, SVG>;
|
private var svgs:Map<ButtonState, SVG>;
|
||||||
|
|
||||||
public function new(?svg:String, ?color:Color) {
|
public function new(svg:String, color:Color) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function buildSVG(color:Color):SVG {
|
private inline function buildSVG(color:Color):SVG {
|
||||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init():Void {
|
private function init():Void {
|
||||||
svgs = new Map();
|
svgs = new Map<ButtonState, SVG>();
|
||||||
svgs.set(UP, buildSVG(color));
|
svgs.set(ButtonState.UP, buildSVG(color));
|
||||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
svgs.set(ButtonState.DISABLED, buildSVG(ColorUtil.grey(color)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(view:ButtonView):Void {
|
public function draw(view:ButtonView):Void {
|
||||||
@@ -39,8 +37,7 @@ using haxework.color.ColorUtil;
|
|||||||
graphics.beginFill(0, 0);
|
graphics.beginFill(0, 0);
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
graphics.beginFill(color);
|
graphics.beginFill(color);
|
||||||
graphics.lineStyle(2, color.multiply(1.5));
|
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5));
|
||||||
// ToDo: padding
|
|
||||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||||
graphics.lineStyle();
|
graphics.lineStyle();
|
||||||
graphics.endFill();
|
graphics.endFill();
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
package ru.m.tankz;
|
|
||||||
|
|
||||||
import haxework.color.Color;
|
|
||||||
import haxework.view.geometry.Box;
|
|
||||||
import haxework.view.geometry.HAlign;
|
|
||||||
import haxework.view.geometry.SizeValue;
|
|
||||||
import haxework.view.geometry.VAlign;
|
|
||||||
import haxework.view.theme.ITheme;
|
|
||||||
import haxework.view.theme.Theme;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.skin.ButtonSVGSkin;
|
|
||||||
|
|
||||||
using haxework.color.ColorUtil;
|
|
||||||
|
|
||||||
class AppTheme extends Theme {
|
|
||||||
|
|
||||||
public static var COLORS(default, never):ThemeColors = {
|
|
||||||
light: 0x95937D,
|
|
||||||
dark: 0x777564,
|
|
||||||
text: 0xE7E0BB,
|
|
||||||
active: 0xFFFF00,
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super({embed: true}, COLORS);
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function reload():Void {
|
|
||||||
super.reload();
|
|
||||||
register(new Style("light", [
|
|
||||||
"skin.background.color" => colors.light,
|
|
||||||
]));
|
|
||||||
|
|
||||||
register(new Style("dark", [
|
|
||||||
"skin.background.color" => colors.dark,
|
|
||||||
]));
|
|
||||||
|
|
||||||
register(new Style("font", [
|
|
||||||
"_" => null,
|
|
||||||
], ["text"]));
|
|
||||||
|
|
||||||
register(new Style("text.header", [
|
|
||||||
"font.size" => fontSize.big,
|
|
||||||
"skin.background.color" => Color.fromInt(0x000000),
|
|
||||||
"skin.background.alpha" => 0.1,
|
|
||||||
"skin.border.color" => colors.light,
|
|
||||||
"geometry.padding" => Box.fromArray([50, 8]),
|
|
||||||
"geometry.margin" => Box.fromArray([0, 0, 30, 30]),
|
|
||||||
], ["text"]));
|
|
||||||
|
|
||||||
register(new Style("button.menu", [
|
|
||||||
"font.size" => fontSize.big,
|
|
||||||
"geometry.padding" => Box.fromFloat(0),
|
|
||||||
"geometry.width" => SizeValue.fromInt(250),
|
|
||||||
"geometry.height" => SizeValue.fromInt(50),
|
|
||||||
], ["button"]));
|
|
||||||
|
|
||||||
register(new Style("text.box", [
|
|
||||||
"skin.background.color" => Color.fromInt(0x000000),
|
|
||||||
"skin.background.alpha" => 0.1,
|
|
||||||
"skin.border.color" => colors.light,
|
|
||||||
], ["text"]));
|
|
||||||
|
|
||||||
register(new Style("text.box.active", [
|
|
||||||
"skin.background.color" => Color.fromInt(0x55aa55),
|
|
||||||
"skin.background.alpha" => 1,
|
|
||||||
"skin.border.color" => Color.fromInt(0x88dd88),
|
|
||||||
], ["text"]));
|
|
||||||
|
|
||||||
register(new Style("button.level", [
|
|
||||||
"font.size" => fontSize.veryBig,
|
|
||||||
"geometry.width" => SizeValue.fromInt(64),
|
|
||||||
"geometry.height" => SizeValue.fromInt(64),
|
|
||||||
"geometry.padding" => Box.fromFloat(0),
|
|
||||||
], ["button"]));
|
|
||||||
|
|
||||||
register(new Style("container", [
|
|
||||||
"geometry.width" => SizeValue.fromString("100%"),
|
|
||||||
"geometry.height" => SizeValue.fromString("100%"),
|
|
||||||
"layout.hAlign" => HAlign.CENTER,
|
|
||||||
"layout.vAlign" => VAlign.MIDDLE,
|
|
||||||
], ["dark"]));
|
|
||||||
|
|
||||||
register(new Style("panel", [
|
|
||||||
"geometry.width" => SizeValue.fromString("100%"),
|
|
||||||
"geometry.padding" => Box.fromArray([10, 5]),
|
|
||||||
"layout.vAlign" => VAlign.MIDDLE,
|
|
||||||
], ["light"]));
|
|
||||||
|
|
||||||
register(new Style("window", [
|
|
||||||
"geometry.padding" => Box.fromFloat(2),
|
|
||||||
], ["dark", "border"]));
|
|
||||||
|
|
||||||
register(new Style("line", [
|
|
||||||
"_" => null,
|
|
||||||
], ["border"]));
|
|
||||||
|
|
||||||
register(new Style("window.close", [
|
|
||||||
"skin" => function() return new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), colors.light),
|
|
||||||
"geometry.width" => SizeValue.fromInt(36),
|
|
||||||
"geometry.height" => SizeValue.fromInt(36),
|
|
||||||
]));
|
|
||||||
|
|
||||||
registerButton("settings", "cog-solid.svg");
|
|
||||||
registerButton("close", "times-circle-solid.svg");
|
|
||||||
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
|
||||||
registerButton("prev", "arrow-alt-circle-left-solid.svg");
|
|
||||||
registerButton("start", "play-circle-solid.svg");
|
|
||||||
registerButton("login", "sign-in-solid.svg");
|
|
||||||
registerButton("logout", "sign-out-solid.svg");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function registerButton(name:String, resource:String):Void {
|
|
||||||
register(new Style('button.$name', [
|
|
||||||
"geometry.width" => SizeValue.fromInt(42),
|
|
||||||
"geometry.height" => SizeValue.fromInt(42),
|
|
||||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light),
|
|
||||||
]));
|
|
||||||
register(new Style('button.$name.small', [
|
|
||||||
"geometry.width" => SizeValue.fromInt(32),
|
|
||||||
"geometry.height" => SizeValue.fromInt(32),
|
|
||||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light),
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -26,6 +26,7 @@ class Client {
|
|||||||
#if linux
|
#if linux
|
||||||
LinuxIcon.apply();
|
LinuxIcon.apply();
|
||||||
#end
|
#end
|
||||||
|
Style.register();
|
||||||
var view:ClientView = new ClientView();
|
var view:ClientView = new ClientView();
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.launch();
|
view.launch();
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import haxework.view.theme.ITheme;
|
|
||||||
import flash.Lib;
|
|
||||||
import haxework.animate.FadeAnimate;
|
import haxework.animate.FadeAnimate;
|
||||||
import haxework.animate.UnFadeAnimate;
|
import haxework.animate.UnFadeAnimate;
|
||||||
import haxework.resources.IResources;
|
import haxework.resources.IResources;
|
||||||
import haxework.resources.Resources;
|
import haxework.resources.Resources;
|
||||||
import haxework.view.popup.PopupManager;
|
import haxework.view.popup.PopupManager;
|
||||||
import lime.ui.Gamepad;
|
|
||||||
import lime.ui.Joystick;
|
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.control.ControlBus;
|
|
||||||
import ru.m.control.IControlBus;
|
|
||||||
import ru.m.control.JoystickDevice;
|
|
||||||
import ru.m.control.KeyboardDevice;
|
|
||||||
import ru.m.tankz.bundle.ConfigBundle;
|
import ru.m.tankz.bundle.ConfigBundle;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
@@ -29,7 +21,6 @@ import ru.m.tankz.storage.SettingsStorage;
|
|||||||
|
|
||||||
class Init {
|
class Init {
|
||||||
|
|
||||||
@:provide static var theme:ITheme;
|
|
||||||
@:provide static var resources:IResources;
|
@:provide static var resources:IResources;
|
||||||
@:provide static var levelBundle:ILevelBundle;
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
@:provide static var configBundle:IConfigBundle;
|
@:provide static var configBundle:IConfigBundle;
|
||||||
@@ -41,7 +32,6 @@ class Init {
|
|||||||
@:provide static var networkManager:NetworkManager;
|
@:provide static var networkManager:NetworkManager;
|
||||||
@:provide static var popupManager:PopupManager;
|
@:provide static var popupManager:PopupManager;
|
||||||
@:provide static var connection:IConnection<Request, Response>;
|
@:provide static var connection:IConnection<Request, Response>;
|
||||||
@:provide static var bus:IControlBus;
|
|
||||||
|
|
||||||
private static function buildConnection():IConnection<Request, Response> {
|
private static function buildConnection():IConnection<Request, Response> {
|
||||||
var host:String = CompilationOption.get("host");
|
var host:String = CompilationOption.get("host");
|
||||||
@@ -57,7 +47,6 @@ class Init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
theme = new AppTheme();
|
|
||||||
resources = new Resources();
|
resources = new Resources();
|
||||||
levelBundle = new LevelBundle();
|
levelBundle = new LevelBundle();
|
||||||
configBundle = new ConfigBundle();
|
configBundle = new ConfigBundle();
|
||||||
@@ -73,22 +62,5 @@ class Init {
|
|||||||
|
|
||||||
connection = buildConnection();
|
connection = buildConnection();
|
||||||
networkManager = new NetworkManager();
|
networkManager = new NetworkManager();
|
||||||
|
|
||||||
bus = new ControlBus();
|
|
||||||
bus.connect(new KeyboardDevice(Lib.current.stage));
|
|
||||||
|
|
||||||
for (device in Gamepad.devices) {
|
|
||||||
trace('gamepad', device);
|
|
||||||
}
|
|
||||||
Gamepad.onConnect.add(function(device) {
|
|
||||||
trace('connect gamepad', device);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (device in Joystick.devices) {
|
|
||||||
bus.connect(new JoystickDevice(device));
|
|
||||||
}
|
|
||||||
Joystick.onConnect.add(function(device) {
|
|
||||||
bus.connect(new JoystickDevice(device));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import flash.display.Sprite;
|
|||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.events.ProgressEvent;
|
import flash.events.ProgressEvent;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import haxework.view.geometry.Size;
|
import haxework.view.core.Size;
|
||||||
import ru.m.tankz.AppTheme;
|
|
||||||
|
|
||||||
class Progress extends Sprite {
|
class Progress extends Sprite {
|
||||||
|
|
||||||
@@ -106,10 +105,10 @@ class Preloader extends Sprite {
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
Lib.current.stage.color = AppTheme.COLORS.light;
|
Lib.current.stage.color = Style.lightColor;
|
||||||
progress = new Progress();
|
progress = new Progress();
|
||||||
progress.color = AppTheme.COLORS.dark;
|
progress.color = Style.darkColor;
|
||||||
progress.backColor = AppTheme.COLORS.light;
|
progress.backColor = Style.lightColor;
|
||||||
progress.size = [200, 200];
|
progress.size = [200, 200];
|
||||||
addChild(progress);
|
addChild(progress);
|
||||||
onResize(null);
|
onResize(null);
|
||||||
|
|||||||
164
src/client/haxe/ru/m/tankz/Style.hx
Normal file
164
src/client/haxe/ru/m/tankz/Style.hx
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.text.Font;
|
||||||
|
import flash.text.FontType;
|
||||||
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.view.core.Geometry;
|
||||||
|
import haxework.view.core.HAlign;
|
||||||
|
import haxework.view.core.VAlign;
|
||||||
|
import haxework.view.ITextView;
|
||||||
|
import haxework.view.layout.Layout;
|
||||||
|
import haxework.view.skin.ISkin;
|
||||||
|
import haxework.view.skin.Skin;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.skin.ButtonSVGSkin;
|
||||||
|
|
||||||
|
class Style {
|
||||||
|
|
||||||
|
@:provide private static var resources:IResources;
|
||||||
|
|
||||||
|
public static var lightColor = 0x95937D;
|
||||||
|
public static var darkColor = 0x777564;
|
||||||
|
public static var textColor = 0xE7E0BB;
|
||||||
|
public static var activeColor = 0xFFFF00;
|
||||||
|
public static var borderColor = ColorUtil.multiply(lightColor, 1.5);
|
||||||
|
|
||||||
|
public static var baseFontSize = 18;
|
||||||
|
public static var bigFontSize = 22;
|
||||||
|
public static var veryBigFontSize = 24;
|
||||||
|
|
||||||
|
public static var fontFamily = "Courirer New";
|
||||||
|
public static var fontEmbed = false;
|
||||||
|
|
||||||
|
public static function text(color):ISkin<ITextView> {
|
||||||
|
return Skin.text(color, baseFontSize, fontFamily, fontEmbed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function registerButton(name:String, resource:String):Void {
|
||||||
|
resources.skin.put('button.$name', [
|
||||||
|
Skin.size(64, 64),
|
||||||
|
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put('button.$name.small', [
|
||||||
|
Skin.size(32, 32),
|
||||||
|
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function textBox(color:Int):SkinSet {
|
||||||
|
return [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(color, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function register(font:Font = null):Void {
|
||||||
|
resources.color.put("light", lightColor);
|
||||||
|
resources.color.put("dark", darkColor);
|
||||||
|
if (font == null) {
|
||||||
|
font = Font.enumerateFonts()[0];
|
||||||
|
}
|
||||||
|
if (font == null) {
|
||||||
|
font = Font.enumerateFonts(true)[0];
|
||||||
|
}
|
||||||
|
fontFamily = font == null ? "Courirer New" : font.fontName;
|
||||||
|
fontEmbed = font == null ? false : switch font.fontType {
|
||||||
|
case DEVICE: false;
|
||||||
|
case _: true;
|
||||||
|
};
|
||||||
|
resources.skin.put("light", [
|
||||||
|
Skin.color(lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("dark", [
|
||||||
|
Skin.color(darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("font", [
|
||||||
|
Skin.text(textColor, 0, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text", [
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("scroll.vertical", [
|
||||||
|
haxework.view.skin.Skin.scrollVertical(lightColor, darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.header", [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([50, 8]).setMargin([0, 0, 0, 30])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.size(250, 50),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box", [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box.active", [
|
||||||
|
Skin.color(0x55aa55),
|
||||||
|
Skin.border(0x88dd88, 1, 2),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.simple", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.simple.active", [
|
||||||
|
Skin.buttonColor(lightColor, activeColor),
|
||||||
|
Skin.text(activeColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.tab", [
|
||||||
|
Skin.tabColor(lightColor),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("border", [
|
||||||
|
Skin.border(borderColor, 1, 2),
|
||||||
|
]);
|
||||||
|
resources.skin.put("scroll", [
|
||||||
|
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.level", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, veryBigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.size(64, 64),
|
||||||
|
]);
|
||||||
|
|
||||||
|
resources.skin.put("container", [
|
||||||
|
Skin.geometry(new Geometry().setSize("100%", "100%")),
|
||||||
|
Skin.layout(new Layout().setAlign(CENTER, MIDDLE)),
|
||||||
|
Skin.color(darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("panel", [
|
||||||
|
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([20, 10])),
|
||||||
|
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
||||||
|
Skin.color(lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("window", [
|
||||||
|
Skin.color(darkColor),
|
||||||
|
Skin.border(borderColor, 1, 2),
|
||||||
|
Skin.geometry(new Geometry().setPadding(2)),
|
||||||
|
]);
|
||||||
|
resources.skin.put("window.close", [
|
||||||
|
Skin.size(36, 36),
|
||||||
|
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("line", [
|
||||||
|
Skin.color(borderColor),
|
||||||
|
]);
|
||||||
|
|
||||||
|
registerButton("settings", "cog-solid.svg");
|
||||||
|
registerButton("close", "times-circle-solid.svg");
|
||||||
|
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||||
|
registerButton("start", "play-circle-solid.svg");
|
||||||
|
registerButton("login", "sign-in-solid.svg");
|
||||||
|
registerButton("logout", "sign-out-solid.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ class ConfigBundle implements IConfigBundle {
|
|||||||
|
|
||||||
public function get(type:GameType):Config {
|
public function get(type:GameType):Config {
|
||||||
if (!_cache.exists(type)) {
|
if (!_cache.exists(type)) {
|
||||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
||||||
_cache.set(type, Config.fromSource(type, source));
|
_cache.set(type, Config.fromSource(type, source));
|
||||||
}
|
}
|
||||||
return _cache.get(type);
|
return _cache.get(type);
|
||||||
|
|||||||
@@ -7,25 +7,17 @@ import ru.m.tankz.util.LevelUtil;
|
|||||||
|
|
||||||
class LevelBundle implements ILevelBundle {
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
private var _cache:Map<String, LevelPack> = new Map();
|
private var cache:Map<String, LevelConfig> = new Map();
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
private function resolve(id:PackId):LevelPack {
|
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
||||||
var bytes = Assets.getBytes('levels/${id}.zip');
|
var key = '${type}:${levelId}';
|
||||||
return {
|
if (!cache.exists(key)) {
|
||||||
id: id,
|
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
||||||
data: LevelUtil.unpack(bytes).map(function(level) {
|
cache[key] = LevelUtil.loads(config, data);
|
||||||
level.packId = id;
|
cache[key].id = levelId;
|
||||||
return level;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get(id:PackId):LevelPack {
|
|
||||||
if (!_cache.exists(id)) {
|
|
||||||
_cache.set(id, resolve(id));
|
|
||||||
}
|
}
|
||||||
return _cache.get(id);
|
return cache[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
27
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.Control.TankAction;
|
||||||
|
|
||||||
|
typedef ActionItem = {
|
||||||
|
public var action:TankAction;
|
||||||
|
public var key:Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef KeyBinding = Map<Int, TankAction>;
|
||||||
|
|
||||||
|
class ActionConfig {
|
||||||
|
|
||||||
|
public var data(default, null):Array<ActionItem>;
|
||||||
|
|
||||||
|
public function new(data:Array<ActionItem>) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asKeyBinding():KeyBinding {
|
||||||
|
var result = new KeyBinding();
|
||||||
|
for (item in data) {
|
||||||
|
result[item.key] = item.action;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import ru.m.control.DeviceAction;
|
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
|
|
||||||
typedef BindAction = {
|
|
||||||
var device:DeviceType;
|
|
||||||
var action:DeviceAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef Binding = Map<TankAction, BindAction>;
|
|
||||||
@@ -1,85 +1,69 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
|
import flash.Lib;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.control.DeviceAction;
|
import ru.m.tankz.control.ActionConfig;
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.control.IControlBus;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
|
|
||||||
@:provide static var storage:SettingsStorage;
|
@:provide var storage:SettingsStorage;
|
||||||
@:provide static var bus:IControlBus;
|
|
||||||
|
|
||||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
private var keyBinding:KeyBinding;
|
||||||
|
private var moveQueue:Array<Int>;
|
||||||
private var moveQueue:Array<Direction>;
|
|
||||||
private var shotTimer:Timer;
|
private var shotTimer:Timer;
|
||||||
|
|
||||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super(playerId);
|
super(playerId);
|
||||||
var config = storage.getBinding(controlIndex);
|
this.keyBinding = storage.getActionConfig(controlIndex).asKeyBinding();
|
||||||
binding = new Map();
|
|
||||||
for (action in config.keys()) {
|
|
||||||
var bind = config.get(action);
|
|
||||||
if (!binding.exists(bind.device)) {
|
|
||||||
binding.set(bind.device, new Map());
|
|
||||||
}
|
|
||||||
binding.get(bind.device).set(bind.action, action);
|
|
||||||
}
|
|
||||||
moveQueue = [];
|
moveQueue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
|
||||||
if (binding.exists(device) && binding[device].exists(action)) {
|
|
||||||
toggleAction(binding[device][action], on);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
super.start();
|
super.start();
|
||||||
bus.signal.connect(onDeviceAction);
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function stop():Void {
|
override public function stop():Void {
|
||||||
super.stop();
|
super.stop();
|
||||||
bus.signal.disconnect(onDeviceAction);
|
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
moveQueue = [];
|
moveQueue = [];
|
||||||
if (shotTimer != null) {
|
}
|
||||||
shotTimer.stop();
|
|
||||||
shotTimer = null;
|
private function onKeyDown(event:KeyboardEvent):Void {
|
||||||
|
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||||
|
case TankAction.MOVE(direction):
|
||||||
|
if (moveQueue.indexOf(event.keyCode) == -1) {
|
||||||
|
moveQueue.unshift(event.keyCode);
|
||||||
|
updateMove();
|
||||||
|
}
|
||||||
|
case TankAction.SHOT:
|
||||||
|
if (shotTimer == null) {
|
||||||
|
shotTimer = new Timer(300);
|
||||||
|
shotTimer.run = shot;
|
||||||
|
shot();
|
||||||
|
}
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
private function onKeyUp(event:KeyboardEvent):Void {
|
||||||
switch action {
|
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||||
case TankAction.MOVE(direction):
|
case TankAction.MOVE(direction):
|
||||||
if (on) {
|
moveQueue.remove(event.keyCode);
|
||||||
if (moveQueue.indexOf(direction) == -1) {
|
|
||||||
moveQueue.unshift(direction);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
moveQueue.remove(direction);
|
|
||||||
}
|
|
||||||
updateMove();
|
updateMove();
|
||||||
case TankAction.SHOT:
|
case TankAction.SHOT:
|
||||||
if (on) {
|
if (shotTimer != null) {
|
||||||
if (shotTimer == null) {
|
shotTimer.stop();
|
||||||
shotTimer = new Timer(300);
|
shotTimer = null;
|
||||||
shotTimer.run = shot;
|
|
||||||
shot();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (shotTimer != null) {
|
|
||||||
shotTimer.stop();
|
|
||||||
shotTimer = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case TankAction.STOP:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +74,17 @@ class HumanControl extends Control {
|
|||||||
|
|
||||||
private function updateMove():Void {
|
private function updateMove():Void {
|
||||||
if (moveQueue.length == 0) {
|
if (moveQueue.length == 0) {
|
||||||
action(STOP);
|
action(TankAction.STOP);
|
||||||
} else {
|
} else {
|
||||||
action(MOVE(moveQueue[0]));
|
switch (keyBinding.get(moveQueue[0])) {
|
||||||
|
case TankAction.MOVE(direction):
|
||||||
|
action(TankAction.MOVE(direction));
|
||||||
|
case _:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function shot():Void {
|
private function shot():Void {
|
||||||
action(SHOT);
|
action(TankAction.SHOT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package ru.m.tankz.game;
|
|
||||||
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
|
|
||||||
enum GameInit {
|
|
||||||
LOCAL(start:Start);
|
|
||||||
NETWORK(network:NetworkManager);
|
|
||||||
RECORD(record:GameRecord);
|
|
||||||
}
|
|
||||||
@@ -1,41 +1,31 @@
|
|||||||
package ru.m.tankz.local;
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
import ru.m.tankz.control.HumanControl;
|
import ru.m.tankz.local.LocalControlFactory;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameRunner;
|
import ru.m.tankz.game.GameRunner;
|
||||||
import ru.m.tankz.local.LocalControlFactory;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.game.record.GameRecorder;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
class LocalGame extends GameRunner {
|
class LocalGame extends GameRunner {
|
||||||
|
@:provide var recordStorage:RecordStorage;
|
||||||
|
private var recorder:GameRecorder;
|
||||||
|
|
||||||
@:provide static var gameStorage:GameStorage;
|
public function new(state:GameState) {
|
||||||
|
super(state);
|
||||||
public function new(start:Start) {
|
|
||||||
super(start);
|
|
||||||
controlFactory = new LocalControlFactory();
|
controlFactory = new LocalControlFactory();
|
||||||
|
recorder = new GameRecorder();
|
||||||
|
connect(recorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onGameEvent(event:GameEvent):Void {
|
override public function onGameEvent(event:GameEvent):Void {
|
||||||
super.onGameEvent(event);
|
super.onGameEvent(event);
|
||||||
switch event {
|
switch event {
|
||||||
case COMPLETE(result): updateProgress(result);
|
case GameEvent.COMPLETE(_, _):
|
||||||
|
disconnect(recorder);
|
||||||
|
recorder.onGameEvent(event); //ToDo:
|
||||||
|
recordStorage.save(recorder.record);
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateProgress(result:Result):Void {
|
|
||||||
var complete = false;
|
|
||||||
var humansTeams:Array<TeamId> = [];
|
|
||||||
for (control in controls) {
|
|
||||||
if (Std.is(control, HumanControl) && humansTeams.indexOf(control.playerId.team) == -1) {
|
|
||||||
humansTeams.push(control.playerId.team);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (humansTeams.length == 1 && result.winner == humansTeams[0]) {
|
|
||||||
var progress = gameStorage.get(new PackId(result.state.type));
|
|
||||||
progress.completeLevel(result.level.id, result.state.presetId);
|
|
||||||
gameStorage.set(progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
import haxe.Unserializer;
|
import haxe.Unserializer;
|
||||||
import ru.m.tankz.control.Controller;
|
|
||||||
import ru.m.tankz.game.Game;
|
import ru.m.tankz.game.Game;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.network.NetworkControlFactory;
|
import ru.m.tankz.network.NetworkControlFactory;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
@@ -14,7 +14,7 @@ class NetworkGame extends Game {
|
|||||||
private var network:NetworkManager;
|
private var network:NetworkManager;
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
public function new(network:NetworkManager) {
|
||||||
super(network.room.game.type);
|
super(new GameState(network.room.game.type, 0, network.room.game.level));
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.controlFactory = new NetworkControlFactory();
|
this.controlFactory = new NetworkControlFactory();
|
||||||
network.gameEventSignal.connect(onGameEventProto);
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
@@ -38,12 +38,12 @@ class NetworkGame extends Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override private function onStart(start:Start):Void {
|
override public function start():Void {
|
||||||
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||||
if (slot != null) {
|
if (slot != null) {
|
||||||
start.state.controls.push({playerId: [slot.slot.team, slot.slot.index], controller: HUMAN(0)});
|
state.controls.push({playerId: [slot.slot.team, slot.slot.index], control: "human-0"});
|
||||||
}
|
}
|
||||||
super.onStart(start);
|
super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function dispose():Void {
|
override public function dispose():Void {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import ru.m.tankz.game.IGame;
|
|||||||
|
|
||||||
interface IRender extends IView<Dynamic> extends GameListener {
|
interface IRender extends IView<Dynamic> extends GameListener {
|
||||||
public var config(default, set):Config;
|
public var config(default, set):Config;
|
||||||
public var gridSize(default, set):GridSize;
|
|
||||||
public function draw():Void;
|
public function draw():Void;
|
||||||
public function reset():Void;
|
public function reset():Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import flash.display.Graphics;
|
|||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.SpriteView;
|
import haxework.view.SpriteView;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
@@ -26,10 +26,6 @@ using ru.m.display.DisplayObjectContainerExtender;
|
|||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
public var config(default, set):Config;
|
public var config(default, set):Config;
|
||||||
public var gridSize(default, set):GridSize;
|
|
||||||
|
|
||||||
private var mapWidth(get, null):Float;
|
|
||||||
private var mapHeight(get, null):Float;
|
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
@@ -55,33 +51,18 @@ class Render extends SpriteView implements IRender {
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_mapWidth():Float {
|
|
||||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_mapHeight():Float {
|
|
||||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_config(value:Config):Config {
|
private function set_config(value:Config):Config {
|
||||||
config = value;
|
config = value;
|
||||||
setSize(mapWidth, mapHeight, "render");
|
setContentSize(config.mapWidth, config.mapHeight);
|
||||||
drawBackground();
|
drawBackground();
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_gridSize(value:GridSize):GridSize {
|
|
||||||
gridSize = value;
|
|
||||||
setSize(mapWidth, mapHeight, "render");
|
|
||||||
drawBackground();
|
|
||||||
return gridSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function drawBackground():Void {
|
private function drawBackground():Void {
|
||||||
var g:Graphics = backgroundLayer.graphics;
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
g.drawRect(0, 0, config.mapWidth, config.mapHeight);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,9 +77,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function clearLayer(layer:DisplayObjectContainer) {
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
while (layer.numChildren > 0) {
|
while (layer.numChildren > 0) layer.removeChildAt(0);
|
||||||
layer.removeChildAt(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset():Void {
|
public function reset():Void {
|
||||||
@@ -115,10 +94,9 @@ class Render extends SpriteView implements IRender {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(start):
|
case START(_):
|
||||||
gridSize = start.level.size;
|
|
||||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
case COMPLETE(_):
|
case COMPLETE(_, _):
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
case SPAWN(BRICK(bricks)):
|
case SPAWN(BRICK(bricks)):
|
||||||
drawBackground();
|
drawBackground();
|
||||||
@@ -207,7 +185,9 @@ class Render extends SpriteView implements IRender {
|
|||||||
var item = items[id];
|
var item = items[id];
|
||||||
entryLayer.removeChild(item.view);
|
entryLayer.removeChild(item.view);
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
showScore(item.rect.center, shot.score);
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
items.remove(id);
|
items.remove(id);
|
||||||
}
|
}
|
||||||
case DESTROY(BULLET(id)):
|
case DESTROY(BULLET(id)):
|
||||||
@@ -224,14 +204,18 @@ class Render extends SpriteView implements IRender {
|
|||||||
if (items.exists(id)) {
|
if (items.exists(id)) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
showScore(item.rect.center, shot.score);
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
cast(item, EagleRenderItem).death = true;
|
cast(item, EagleRenderItem).death = true;
|
||||||
}
|
}
|
||||||
case DESTROY(BONUS(id, shot)):
|
case DESTROY(BONUS(id, shot)):
|
||||||
if (items.exists(id)) {
|
if (items.exists(id)) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
upperLayer.removeChild(item.view);
|
upperLayer.removeChild(item.view);
|
||||||
showScore(item.rect.center, shot.score);
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
items.remove(id);
|
items.remove(id);
|
||||||
}
|
}
|
||||||
case DESTROY(CELL(id, x, y, shot)):
|
case DESTROY(CELL(id, x, y, shot)):
|
||||||
@@ -260,17 +244,15 @@ class Render extends SpriteView implements IRender {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function showScore(point:Point, score:Null<Int>):Void {
|
private function showScore(point:Point, score:Int):Void {
|
||||||
if (score != null && score != 0) {
|
var view:LabelView = new LabelView();
|
||||||
var view:LabelView = new LabelView();
|
view.skinId = "text";
|
||||||
view.style = "text";
|
view.text = Std.string(score);
|
||||||
view.text = Std.string(score);
|
view.update();
|
||||||
view.update();
|
view.redraw();
|
||||||
view.redraw();
|
view.x = point.x - view.width / 2;
|
||||||
view.x = point.x - view.width / 2;
|
view.y = point.y - view.height / 2;
|
||||||
view.y = point.y - view.height / 2;
|
upperLayer.addChild(view.content);
|
||||||
upperLayer.addChild(view.content);
|
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.tankz.render.item;
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
import haxework.view.theme.ITheme;
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
@@ -29,8 +28,6 @@ class TankRenderItem extends BitmapRenderItem {
|
|||||||
private var protectView:Animate;
|
private var protectView:Animate;
|
||||||
private var nameView:TextField;
|
private var nameView:TextField;
|
||||||
|
|
||||||
@:provide static var theme:ITheme;
|
|
||||||
|
|
||||||
public function new(rect:Rectangle) {
|
public function new(rect:Rectangle) {
|
||||||
super(rect);
|
super(rect);
|
||||||
container = new Sprite();
|
container = new Sprite();
|
||||||
@@ -45,8 +42,8 @@ class TankRenderItem extends BitmapRenderItem {
|
|||||||
|
|
||||||
private function buildNameView():TextField {
|
private function buildNameView():TextField {
|
||||||
var result = new BitmapTextField();
|
var result = new BitmapTextField();
|
||||||
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
result.defaultTextFormat = new TextFormat(Style.fontFamily, 10, 0xffffff);
|
||||||
result.embedFonts = theme.font.embed;
|
result.embedFonts = Style.fontEmbed;
|
||||||
result.autoSize = TextFieldAutoSize.LEFT;
|
result.autoSize = TextFieldAutoSize.LEFT;
|
||||||
result.shadowColor = 0x000000;
|
result.shadowColor = 0x000000;
|
||||||
result.stroke = true;
|
result.stroke = true;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import haxework.storage.SharedObjectStorage;
|
import haxework.storage.SharedObjectStorage;
|
||||||
import ru.m.tankz.game.PackProgress;
|
import ru.m.tankz.game.GameProgress;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type.GameType;
|
||||||
|
|
||||||
class GameStorage extends SharedObjectStorage {
|
class GameStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ class GameStorage extends SharedObjectStorage {
|
|||||||
super('game_${VERSION}');
|
super('game_${VERSION}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(id:PackId):PackProgress {
|
public function get(type:GameType):GameProgress {
|
||||||
return exists(id) ? read(id) : new PackProgress(id);
|
return exists(type) ? read(type) : new GameProgress(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(progress:PackProgress):Void {
|
public function set(progress:GameProgress):Void {
|
||||||
write(progress.id, progress);
|
write(progress.type, progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,64 +3,50 @@ package ru.m.tankz.storage;
|
|||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxework.storage.SharedObjectStorage;
|
import haxework.storage.SharedObjectStorage;
|
||||||
import haxework.utils.ObjectUtil;
|
import haxework.utils.ObjectUtil;
|
||||||
import ru.m.control.DeviceAction;
|
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.control.Binding;
|
import ru.m.tankz.control.ActionConfig;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control.TankAction;
|
||||||
|
|
||||||
class SettingsStorage extends SharedObjectStorage {
|
class SettingsStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
private static inline var VERSION = 3;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super('settings_${VERSION}');
|
super("settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBinding(index:Int):Binding {
|
public function getActionConfig(index:Int):ActionConfig {
|
||||||
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveBinding(index:Int, value:Binding) {
|
public function setActionConffig(index:Int, value:ActionConfig) {
|
||||||
write('action:$index', value);
|
write('action:$index', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDefaultBinding(index:Int):Binding {
|
public static function getDefaultActionConfig(index:Int):ActionConfig {
|
||||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function buildGamepadBinding(id:Int):Binding {
|
private static var defaults:Map<Int, ActionConfig> = [
|
||||||
var device = GAMEPAD(id);
|
0 => new ActionConfig([
|
||||||
return [
|
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
||||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
||||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
||||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
||||||
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
||||||
SHOT => {device: device, action: KEY(0)},
|
]),
|
||||||
];
|
1 => new ActionConfig([
|
||||||
}
|
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
||||||
|
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
||||||
private static var defaults:Map<Int, Binding> = [
|
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
||||||
-1 => [
|
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
||||||
MOVE(Direction.TOP) => null,
|
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||||
MOVE(Direction.LEFT) => null,
|
]),
|
||||||
MOVE(Direction.BOTTOM) => null,
|
|
||||||
MOVE(Direction.RIGHT) => null,
|
|
||||||
SHOT => null,
|
|
||||||
],
|
|
||||||
0 => [
|
|
||||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
|
||||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
|
||||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
|
||||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
|
||||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
|
||||||
],
|
|
||||||
1 => [
|
|
||||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
|
||||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
|
||||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
|
||||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
|
||||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static var empty:ActionConfig = new ActionConfig([
|
||||||
|
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
||||||
|
{action:TankAction.SHOT, key:-1},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxework.resources.IResources;
|
import haxework.resources.IResources;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.group.VGroupView;
|
import haxework.view.LabelView;
|
||||||
import ru.m.tankz.game.IGame;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
|
|
||||||
@:template class ClientView extends VGroupView {
|
@:template class ClientView extends VGroupView {
|
||||||
@:view("switcher") var switcherView:FrameSwitcher;
|
@:view("switcher") var switcherView:FrameSwitcher;
|
||||||
|
@:view var username:LabelView;
|
||||||
|
@:view("login") var loginButton:ButtonView;
|
||||||
|
@:view("logout") var logoutButton:ButtonView;
|
||||||
|
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
@:provide var resources:IResources;
|
@:provide var resources:IResources;
|
||||||
@@ -21,6 +27,8 @@ import ru.m.tankz.sound.SoundManager;
|
|||||||
public function init():Void {
|
public function init():Void {
|
||||||
resources.text.put('version', '${Const.VERSION}');
|
resources.text.put('version', '${Const.VERSION}');
|
||||||
switcher = switcherView;
|
switcher = switcherView;
|
||||||
|
network.stateSignal.connect(onConnectionState);
|
||||||
|
onConnectionState(network.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function launch():Void {
|
public function launch():Void {
|
||||||
@@ -28,7 +36,7 @@ import ru.m.tankz.sound.SoundManager;
|
|||||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
switch event.keyCode {
|
switch event.keyCode {
|
||||||
case Keyboard.ESCAPE:
|
case Keyboard.ESCAPE:
|
||||||
switcher.change(MenuFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
case Keyboard.M:
|
case Keyboard.M:
|
||||||
soundManager.mute = !soundManager.mute;
|
soundManager.mute = !soundManager.mute;
|
||||||
case Keyboard.P:
|
case Keyboard.P:
|
||||||
@@ -37,6 +45,41 @@ import ru.m.tankz.sound.SoundManager;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
switcher.change(MenuFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionState(state:ConnectionState):Void {
|
||||||
|
L.d("ClientView", 'onConnectionState: ${state}');
|
||||||
|
switch state {
|
||||||
|
case ONLINE(user):
|
||||||
|
username.text = user.name;
|
||||||
|
logoutButton.visible = true;
|
||||||
|
loginButton.visible = false;
|
||||||
|
case CONNECTED:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = true;
|
||||||
|
case ERROR(error):
|
||||||
|
//L.e("ClientView", 'onConnectionState: ERROR', error);
|
||||||
|
L.w("ClientView", 'onConnectionState: ERROR');
|
||||||
|
case _:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function login():Void {
|
||||||
|
LoginPopup.instance.show().then(function(user:User):Void {
|
||||||
|
L.d("Login", 'user: $user');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logout():Void {
|
||||||
|
network.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function close():Void {
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,50 @@
|
|||||||
views:
|
views:
|
||||||
- $type: haxework.view.frame.FrameSwitcher
|
- $type: haxework.view.frame.FrameSwitcher
|
||||||
id: switcher
|
id: switcher
|
||||||
geometry.stretch: true
|
geometry.size.stretch: true
|
||||||
style: dark
|
skinId: dark
|
||||||
factory:
|
views:
|
||||||
_menu_: {$class: ru.m.tankz.view.MenuFrame}
|
- id: start
|
||||||
_level_: {$class: ru.m.tankz.view.LevelFrame}
|
$type: ru.m.tankz.view.StartFrame
|
||||||
_start_: {$class: ru.m.tankz.view.StartFrame}
|
- id: level
|
||||||
_game_: {$class: ru.m.tankz.view.GameFrame}
|
$type: ru.m.tankz.view.LevelFrame
|
||||||
_result_: {$class: ru.m.tankz.view.ResultFrame}
|
- id: game
|
||||||
_settings_: {$class: ru.m.tankz.view.SettingsFrame}
|
$type: ru.m.tankz.view.GameFrame
|
||||||
_record_: {$class: ru.m.tankz.view.RecordFrame}
|
- id: result
|
||||||
_room_list_: {$class: ru.m.tankz.view.network.RoomListFrame}
|
$type: ru.m.tankz.view.ResultFrame
|
||||||
_room_: {$class: ru.m.tankz.view.network.RoomFrame}
|
- id: settings
|
||||||
|
$type: ru.m.tankz.view.SettingsFrame
|
||||||
|
- id: record
|
||||||
|
$type: ru.m.tankz.view.RecordFrame
|
||||||
|
- id: room_list
|
||||||
|
$type: ru.m.tankz.view.network.RoomListFrame
|
||||||
|
- id: room
|
||||||
|
$type: ru.m.tankz.view.network.RoomFrame
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
skinId: panel
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: settings
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.settings
|
||||||
|
+onPress: $code:switcher.change('settings')
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: username
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text
|
||||||
|
- id: login
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.login
|
||||||
|
+onPress: $code:login()
|
||||||
|
- id: logout
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.logout
|
||||||
|
+onPress: $code:logout()
|
||||||
|
visible: false
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: close
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.close
|
||||||
|
+onPress: $code:close()
|
||||||
|
|||||||
@@ -1,68 +1,36 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.layout.DefaultLayout;
|
import haxe.ds.Option;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.control.IControlBus;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameInit;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.game.record.GamePlayer;
|
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
import ru.m.tankz.local.LocalGame;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.network.NetworkGame;
|
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.game.GameView;
|
import ru.m.tankz.view.game.GameView;
|
||||||
import ru.m.tankz.view.GamepadView;
|
|
||||||
|
|
||||||
@:template class GameFrame extends FrameView<GameInit> implements GameListener {
|
@:template class GameFrame extends VGroupView implements GameListener {
|
||||||
public static inline var ID = "game";
|
public static inline var ID = "game";
|
||||||
|
|
||||||
private static inline var TAG = "GameFrame";
|
private static inline var TAG = "GameFrame";
|
||||||
|
|
||||||
@:view("game") private var gameView(default, null):GameView;
|
@:view("game") private var gameView(default, null):GameView;
|
||||||
@:view private var gamepad(default, null):GamepadView;
|
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
@:provide var soundManager:SoundManager;
|
@:provide var soundManager:SoundManager;
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var record:GameRecord;
|
||||||
|
@:provide("next") var nextState:GameState;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide static var gameStorage:GameStorage;
|
@:provide var gameStorage:GameStorage;
|
||||||
@:provide static var settings:SettingsStorage;
|
|
||||||
|
|
||||||
@:provide static var bus:IControlBus;
|
@:provide var game:IGame;
|
||||||
|
|
||||||
private var game:IGame;
|
public function onShow():Void {
|
||||||
private var recorder:GameRecord;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(id, new DefaultLayout());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init():Void {
|
|
||||||
bus.connect(gamepad);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onShow(data:GameInit):Void {
|
|
||||||
gamepad.visible = false;
|
|
||||||
// ToDo:
|
|
||||||
for (i in 0...1) {
|
|
||||||
for (bind in settings.getBinding(i)) {
|
|
||||||
switch bind.device {
|
|
||||||
case GAMEPAD(GamepadView.ID):
|
|
||||||
gamepad.visible = true;
|
|
||||||
break;
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game = switch data {
|
|
||||||
case LOCAL(start): new LocalGame(start);
|
|
||||||
case NETWORK(network): new NetworkGame(network);
|
|
||||||
case RECORD(record): new GamePlayer(record);
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
gameView.type = game.type;
|
gameView.type = game.type;
|
||||||
soundManager.config = game.config;
|
soundManager.config = game.config;
|
||||||
gameView.render.config = game.config;
|
gameView.render.config = game.config;
|
||||||
@@ -85,19 +53,42 @@ import ru.m.tankz.view.GamepadView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case COMPLETE(result):
|
case GameEvent.COMPLETE(state, winner):
|
||||||
|
this.state = state;
|
||||||
|
nextState = switch next(winner) {
|
||||||
|
case Some(s):
|
||||||
|
// ToDo:
|
||||||
|
var progress = gameStorage.get(game.type);
|
||||||
|
progress.completeLevel(state.levelId, state.presetId);
|
||||||
|
gameStorage.set(progress);
|
||||||
|
s;
|
||||||
|
case None:
|
||||||
|
null;
|
||||||
|
}
|
||||||
stop();
|
stop();
|
||||||
switcher.change(ResultFrame.ID, result);
|
switcher.change(ResultFrame.ID);
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onHide():Void {
|
// ToDo:
|
||||||
|
private function next(winner:TeamId):Option<GameState> {
|
||||||
|
for (rule in game.config.game.complete) {
|
||||||
|
if (rule.team != null && rule.team != winner) {
|
||||||
|
return Option.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var level = state.levelId + 1;
|
||||||
|
if (level >= game.config.game.levels) level = 0;
|
||||||
|
return Option.Some(new GameState(game.type, state.presetId, level, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
stop();
|
stop();
|
||||||
soundManager.stopAll();
|
soundManager.stopAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close():Void {
|
public function close():Void {
|
||||||
switcher.change(MenuFrame.ID);
|
switcher.change(LevelFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
---
|
---
|
||||||
style: container
|
|
||||||
overflow.x: crop
|
|
||||||
overflow.y: crop
|
|
||||||
views:
|
views:
|
||||||
- id: game
|
- $type: haxework.view.VGroupView
|
||||||
$type: ru.m.tankz.view.game.GameView
|
skinId: container
|
||||||
- id: gamepad
|
views:
|
||||||
$type: ru.m.tankz.view.GamepadView
|
- id: game
|
||||||
geometry.position: absolute
|
$type: ru.m.tankz.view.game.GameView
|
||||||
geometry.stretch: true
|
|
||||||
visible: false
|
|
||||||
|
|||||||
@@ -1,160 +0,0 @@
|
|||||||
package ru.m.tankz.view;
|
|
||||||
|
|
||||||
import flash.display.Graphics;
|
|
||||||
import flash.display.Stage;
|
|
||||||
import flash.events.MouseEvent;
|
|
||||||
import flash.events.TouchEvent;
|
|
||||||
import haxework.color.Color;
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
import haxework.view.skin.ISkin;
|
|
||||||
import haxework.view.SpriteView;
|
|
||||||
import ru.m.control.DeviceAction;
|
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.control.IControlDevice;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import ru.m.geom.Point;
|
|
||||||
import ru.m.geom.Rectangle;
|
|
||||||
|
|
||||||
typedef ActionArea = {
|
|
||||||
var action:DeviceAction;
|
|
||||||
var rect:Rectangle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:style class GamepadSkin implements ISkin<GamepadView> {
|
|
||||||
|
|
||||||
@:style(0) public var color(default, default):Null<Color>;
|
|
||||||
|
|
||||||
public function new(?color:Color) {
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function draw(view:GamepadView):Void {
|
|
||||||
var graphics:Graphics = view.content.graphics;
|
|
||||||
graphics.clear();
|
|
||||||
graphics.beginFill(0, 0.0);
|
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
|
||||||
graphics.endFill();
|
|
||||||
graphics.lineStyle(2, color);
|
|
||||||
graphics.beginFill(color, 0.2);
|
|
||||||
for (area in view.areas) {
|
|
||||||
graphics.drawRect(area.rect.x, area.rect.y, area.rect.width, area.rect.height);
|
|
||||||
}
|
|
||||||
graphics.lineStyle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GamepadView extends SpriteView implements IControlDevice {
|
|
||||||
public static var ID(default, never):Int = -128;
|
|
||||||
|
|
||||||
public var type(default, null):DeviceType;
|
|
||||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
|
||||||
|
|
||||||
public var areas(default, null):Array<ActionArea>;
|
|
||||||
public var currentAreas(default, null):Map<Int, ActionArea>;
|
|
||||||
|
|
||||||
private var stage:Stage;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
type = GAMEPAD(ID);
|
|
||||||
signal = new Signal2();
|
|
||||||
areas = [];
|
|
||||||
currentAreas = new Map();
|
|
||||||
skin = new GamepadSkin(0x00ff00);
|
|
||||||
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
|
||||||
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onMouseDown(event:MouseEvent):Void {
|
|
||||||
onMouseMove(event);
|
|
||||||
stage = content.stage;
|
|
||||||
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
|
||||||
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onMouseMove(event:MouseEvent):Void {
|
|
||||||
var point = new Point(event.localX, event.localY);
|
|
||||||
updateTouch(-1, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onMouseUp(event:MouseEvent):Void {
|
|
||||||
endTouch(-1);
|
|
||||||
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
|
||||||
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onTouchBegin(event:TouchEvent):Void {
|
|
||||||
onTouchMove(event);
|
|
||||||
stage = content.stage;
|
|
||||||
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
|
||||||
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onTouchMove(event:TouchEvent):Void {
|
|
||||||
var point = new Point(event.localX, event.localY);
|
|
||||||
updateTouch(event.touchPointID, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onTouchEnd(event:TouchEvent):Void {
|
|
||||||
endTouch(event.touchPointID);
|
|
||||||
if (Lambda.count(currentAreas) == 0) {
|
|
||||||
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
|
||||||
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateTouch(pointID:Int, point:Point):Void {
|
|
||||||
if (currentAreas.exists(pointID)) {
|
|
||||||
var area = currentAreas[pointID];
|
|
||||||
if (!area.rect.contain(point)) {
|
|
||||||
currentAreas.remove(pointID);
|
|
||||||
signal.emit(area.action, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (area in areas) {
|
|
||||||
if (area.rect.contain(point)) {
|
|
||||||
currentAreas[pointID] = area;
|
|
||||||
signal.emit(area.action, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function endTouch(pointID:Int):Void {
|
|
||||||
if (currentAreas.exists(pointID)) {
|
|
||||||
signal.emit(currentAreas[pointID].action, false);
|
|
||||||
currentAreas.remove(pointID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
areas = [];
|
|
||||||
var size = Math.min(width, height) / 7;
|
|
||||||
var padding = size / 2;
|
|
||||||
areas.push({
|
|
||||||
action: DIRECTION(Direction.TOP),
|
|
||||||
rect: new Rectangle(padding + size, height - size * 3 - padding, size, size)
|
|
||||||
});
|
|
||||||
areas.push({
|
|
||||||
action: DIRECTION(Direction.LEFT),
|
|
||||||
rect: new Rectangle(padding, height - size * 2 - padding, size, size)
|
|
||||||
});
|
|
||||||
areas.push({
|
|
||||||
action: DIRECTION(Direction.BOTTOM),
|
|
||||||
rect: new Rectangle(padding + size, height - size - padding, size, size)
|
|
||||||
});
|
|
||||||
areas.push({
|
|
||||||
action: DIRECTION(Direction.RIGHT),
|
|
||||||
rect: new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
|
|
||||||
});
|
|
||||||
areas.push({
|
|
||||||
action: KEY(0),
|
|
||||||
rect: new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {
|
|
||||||
stage = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +1,70 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.form.LabelView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.LabelView;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.local.LocalGame;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.Type.PackId;
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.view.popup.LevelPopup;
|
||||||
|
|
||||||
@:template class LevelFrame extends FrameView<PackId> {
|
@:template class LevelFrame extends VGroupView {
|
||||||
public static inline var ID = "level";
|
public static inline var ID = "level";
|
||||||
|
|
||||||
@:provide static var switcher:FrameSwitcher;
|
|
||||||
@:provide static var storage:GameStorage;
|
|
||||||
@:provide static var configBundle:IConfigBundle;
|
|
||||||
@:provide static var levelBundle:ILevelBundle;
|
|
||||||
|
|
||||||
@:view var header:LabelView;
|
@:view var header:LabelView;
|
||||||
@:view var levels:DataView<LevelConfig, ButtonView>;
|
@:view var levels:DataView<LevelId, ButtonView>;
|
||||||
|
|
||||||
private var pack:LevelPack;
|
@:provide var state:GameState;
|
||||||
private var config(get, never):Config;
|
@:provide var game:IGame;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var levelBundle:ILevelBundle;
|
||||||
|
@:provide var storage:GameStorage;
|
||||||
|
|
||||||
public function new() {
|
private var levelPopup:LevelPopup;
|
||||||
super(ID);
|
|
||||||
|
public function onShow():Void {
|
||||||
|
header.text = state.type;
|
||||||
|
levels.data = [for (i in 0...state.config.game.levels) i];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_config():Config {
|
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||||
return configBundle.get(pack.id.type);
|
state.levelId = level.id;
|
||||||
|
state.presetId = preset.id;
|
||||||
|
state.controls = control.values;
|
||||||
|
game = new LocalGame(state);
|
||||||
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:PackId):Void {
|
private function levelViewFactory(index:Int, levelId:LevelId):ButtonView {
|
||||||
header.text = data.type;
|
var progress = storage.get(state.type);
|
||||||
pack = levelBundle.get(data);
|
|
||||||
levels.data = pack.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
|
||||||
var progress = storage.get(pack.id);
|
|
||||||
var result = new ButtonView();
|
var result = new ButtonView();
|
||||||
result.style = "button.level";
|
result.skinId = "button.level";
|
||||||
var presetsLine = [for (p in config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(levelId, p.id) ? '*' : '_'].join('');
|
||||||
result.text = '${level.id}\n${presetsLine}';
|
result.text = '${levelId}\n${presetsLine}';
|
||||||
result.disabled = !progress.isLevelAvailable(level.id);
|
result.disabled = !progress.isLevelAvailable(levelId);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
private function onLevelSelect(index:Int, levelId:LevelId, view:ButtonView):Void {
|
||||||
if (storage.get(pack.id).isLevelAvailable(level.id)) {
|
if (!storage.get(state.type).isLevelAvailable(levelId)) {
|
||||||
switcher.change(StartFrame.ID, {
|
return;
|
||||||
state: new GameState(pack.id.type),
|
|
||||||
level: level,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (levelPopup == null) {
|
||||||
|
levelPopup = new LevelPopup();
|
||||||
|
}
|
||||||
|
var level = levelBundle.get(state.type, state.config, levelId);
|
||||||
|
levelPopup.setData(
|
||||||
|
level,
|
||||||
|
state.config.presets,
|
||||||
|
state.config.controls,
|
||||||
|
storage.get(state.type)
|
||||||
|
);
|
||||||
|
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,18 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
views:
|
views:
|
||||||
- id: header
|
- id: header
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.header
|
skinId: text.header
|
||||||
- id: levels
|
- id: levels
|
||||||
$type: haxework.view.data.DataView
|
$type: haxework.view.DataView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.height: 100%
|
|
||||||
overflow.y: scroll
|
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.TailLayout
|
$type: haxework.view.layout.TailLayout
|
||||||
rowSize: 10
|
rowSize: 10
|
||||||
margin: 5
|
margin: 5
|
||||||
factory: ~levelViewFactory
|
factory: $this:levelViewFactory
|
||||||
+onItemSelect: ~onLevelSelect
|
+onItemSelect: $this:onLevelSelect
|
||||||
geometry.padding: 10
|
geometry.padding: 10
|
||||||
- $type: haxework.view.group.HGroupView
|
|
||||||
style: panel
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 100%
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.prev
|
|
||||||
+onPress: ~switcher.change("menu")
|
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
package ru.m.tankz.view;
|
|
||||||
|
|
||||||
import haxework.view.form.ButtonView;
|
|
||||||
import haxework.view.form.LabelView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
|
||||||
import haxework.view.frame.FrameView;
|
|
||||||
import ru.m.tankz.game.GameInit;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
import ru.m.tankz.view.network.RoomFrame;
|
|
||||||
import ru.m.tankz.view.network.RoomListFrame;
|
|
||||||
import ru.m.tankz.view.popup.LoginPopup;
|
|
||||||
|
|
||||||
@:template class MenuFrame extends FrameView<Dynamic> {
|
|
||||||
|
|
||||||
public static var ID(default, never):String = "menu";
|
|
||||||
|
|
||||||
@:provide var gameInit:GameInit;
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
|
||||||
@:provide var network:NetworkManager;
|
|
||||||
|
|
||||||
@:view var username:LabelView;
|
|
||||||
@:view("login") var loginButton:ButtonView;
|
|
||||||
@:view("logout") var logoutButton:ButtonView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onShow(data:Dynamic):Void {
|
|
||||||
super.onShow(data);
|
|
||||||
network.stateSignal.connect(onConnectionState);
|
|
||||||
onConnectionState(network.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onHide():Void {
|
|
||||||
super.onHide();
|
|
||||||
network.stateSignal.disconnect(onConnectionState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function startGame(type:GameType):Void {
|
|
||||||
gameInit = LOCAL({state: new GameState(type), level: null});
|
|
||||||
switcher.change(LevelFrame.ID, new PackId(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function startNetwork():Void {
|
|
||||||
switch network.state {
|
|
||||||
case ONLINE(user):
|
|
||||||
if (network.room != null) {
|
|
||||||
switcher.change(RoomFrame.ID, network.room);
|
|
||||||
network.joinGame(network.room.game.id, true);
|
|
||||||
} else {
|
|
||||||
switcher.change(RoomListFrame.ID);
|
|
||||||
}
|
|
||||||
case CONNECTED:
|
|
||||||
LoginPopup.instance.show().then(function(user):Void {
|
|
||||||
if (user != null) {
|
|
||||||
switcher.change(RoomListFrame.ID);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onConnectionState(state:ConnectionState):Void {
|
|
||||||
L.d("ClientView", 'onConnectionState: ${state}');
|
|
||||||
switch state {
|
|
||||||
case ONLINE(user):
|
|
||||||
username.text = user.name;
|
|
||||||
logoutButton.visible = true;
|
|
||||||
loginButton.visible = false;
|
|
||||||
case CONNECTED:
|
|
||||||
username.text = "";
|
|
||||||
logoutButton.visible = false;
|
|
||||||
loginButton.visible = true;
|
|
||||||
case ERROR(error):
|
|
||||||
//L.e("ClientView", 'onConnectionState: ERROR', error);
|
|
||||||
L.w("ClientView", 'onConnectionState: ERROR');
|
|
||||||
case _:
|
|
||||||
username.text = "";
|
|
||||||
logoutButton.visible = false;
|
|
||||||
loginButton.visible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function login():Void {
|
|
||||||
LoginPopup.instance.show().then(function(user:User):Void {
|
|
||||||
L.d("Login", 'user: $user');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function logout():Void {
|
|
||||||
network.logout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
---
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.group.VGroupView
|
|
||||||
style: container
|
|
||||||
layout.margin: 10
|
|
||||||
overflow.y: scroll
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.form.LabelView
|
|
||||||
text: Tank'z
|
|
||||||
style: font
|
|
||||||
font.size: 100
|
|
||||||
geometry.margin.bottom: 30
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.menu
|
|
||||||
+onPress: ~startGame('classic')
|
|
||||||
text: Classic
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.menu
|
|
||||||
+onPress: ~startGame('dota')
|
|
||||||
text: DotA
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.menu
|
|
||||||
+onPress: ~startGame('death')
|
|
||||||
text: DeathMatch
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.menu
|
|
||||||
+onPress: ~switcher.change('record')
|
|
||||||
text: Records
|
|
||||||
- id: network
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
style: button.menu
|
|
||||||
+onPress: ~startNetwork()
|
|
||||||
text: Network
|
|
||||||
- $type: haxework.view.form.LabelView
|
|
||||||
geometry.hAlign: right
|
|
||||||
geometry.vAlign: top
|
|
||||||
geometry.padding: [20, 5]
|
|
||||||
geometry.position: absolute
|
|
||||||
geometry.margin: [0, 20, 20, 0]
|
|
||||||
style: text.box
|
|
||||||
text: $r:text:version
|
|
||||||
- $type: haxework.view.group.HGroupView
|
|
||||||
style: panel
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- id: settings
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
style: button.settings
|
|
||||||
+onPress: ~switcher.change('settings')
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 50%
|
|
||||||
- id: username
|
|
||||||
$type: haxework.view.form.LabelView
|
|
||||||
style: text
|
|
||||||
- id: login
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
style: button.login
|
|
||||||
+onPress: ~login()
|
|
||||||
- id: logout
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
style: button.logout
|
|
||||||
+onPress: ~logout()
|
|
||||||
visible: false
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 50%
|
|
||||||
@@ -1,27 +1,28 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.list.ListView;
|
||||||
import haxework.view.list.VListView;
|
import haxework.view.list.VListView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
@:template class RecordFrame extends FrameView<Dynamic> {
|
@:template class RecordFrame extends VGroupView {
|
||||||
|
|
||||||
public static var ID(default, never):String = "record";
|
public static var ID(default, never):String = "record";
|
||||||
|
|
||||||
@:provide static var switcher:FrameSwitcher;
|
|
||||||
@:provide static var recordStorage:RecordStorage;
|
|
||||||
|
|
||||||
@:view var data:VListView<GameRecordInfo>;
|
@:view var data:VListView<GameRecordInfo>;
|
||||||
|
|
||||||
public function new() {
|
@:provide var recordStorage:RecordStorage;
|
||||||
super(ID);
|
@:provide var switcher:FrameSwitcher;
|
||||||
}
|
@:provide var record:GameRecord;
|
||||||
|
|
||||||
override public function onShow(_:Dynamic):Void {
|
public function onShow():Void {
|
||||||
var data = Lambda.array(recordStorage);
|
var data = Lambda.array(recordStorage);
|
||||||
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||||
this.data.data = data;
|
this.data.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,18 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
|
geometry.padding: 20
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.LabelView
|
- $type: haxework.view.LabelView
|
||||||
style: text.header
|
skinId: text.header
|
||||||
text: Records
|
text: Records
|
||||||
- id: data
|
- id: data
|
||||||
$type: haxework.view.list.VListView
|
$type: haxework.view.list.VListView
|
||||||
factory: ~function() return new ru.m.tankz.view.common.RecordView()
|
factory: $code:function() return new ru.m.tankz.view.common.RecordView()
|
||||||
|
+onItemSelect: $this:onRecordSelect
|
||||||
geometry.margin.top: 20
|
geometry.margin.top: 20
|
||||||
geometry.stretch: true
|
geometry.size.stretch: true
|
||||||
scroll:
|
scroll:
|
||||||
$type: haxework.view.list.VScrollBarView
|
$type: haxework.view.list.VScrollBarView
|
||||||
- $type: haxework.view.group.HGroupView
|
skinId: scroll
|
||||||
style: panel
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 100%
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.prev
|
|
||||||
+onPress: ~switcher.change("menu")
|
|
||||||
|
|||||||
@@ -1,80 +1,51 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.game.GameRunner;
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import ru.m.tankz.game.GameInit;
|
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.view.common.LifeView;
|
import ru.m.tankz.view.common.LifeView;
|
||||||
|
|
||||||
@:template class ResultFrame extends FrameView<Result> {
|
@:template class ResultFrame extends VGroupView {
|
||||||
public static var ID(default, never):String = "result";
|
public static var ID(default, never):String = "result";
|
||||||
|
|
||||||
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
||||||
@:view("level") var levelLabel:LabelView;
|
@:view("level") var levelLabel:LabelView;
|
||||||
@:view("next") var nextButton:ButtonView;
|
|
||||||
|
|
||||||
@:provide var frames:FrameSwitcher;
|
@:provide var frames:FrameSwitcher;
|
||||||
@:provide static var levelBundle:ILevelBundle;
|
@:provide var state:GameState;
|
||||||
@:provide static var gameStorage:GameStorage;
|
@:provide("next") var nextState:GameState;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
private var result:Result;
|
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playerViewFactory(index:Int, player:PlayerState):LifeView {
|
|
||||||
var view = new LifeView();
|
var view = new LifeView();
|
||||||
var playerConfig = result.state.config.getPlayer(player.id);
|
var playerConfig = state.config.getPlayer(player.id);
|
||||||
var tankType = playerConfig.tanks[0].type;
|
var tankType = playerConfig.tanks[0].type;
|
||||||
var tankConfig = result.state.config.getTank(tankType);
|
var tankConfig = state.config.getTank(tankType);
|
||||||
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||||
view.color = result.state.getPlayerColor(player.id);
|
view.color = state.getPlayerColor(player.id);
|
||||||
view.life = player.frags;
|
view.life = player.frags;
|
||||||
view.score = player.score;
|
view.score = player.score;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:Result):Void {
|
public function onShow() {
|
||||||
result = data;
|
resultView.data = Lambda.array(state.players);
|
||||||
var players = Lambda.array(result.state.players);
|
levelLabel.text = 'Level ${state.levelId}';
|
||||||
players.sort(function(a, b) return a.id.compare(b.id));
|
|
||||||
resultView.data = players;
|
|
||||||
var label = '${result.state.type} Level ${result.level.id}';
|
|
||||||
if (result.level.name != null) {
|
|
||||||
label += '\n${result.level.name}';
|
|
||||||
}
|
|
||||||
levelLabel.text = label;
|
|
||||||
nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId);
|
|
||||||
nextButton.text = 'Next (${result.level.id + 1})';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function levels():Void {
|
private function next() {
|
||||||
frames.change(LevelFrame.ID, result.level.packId);
|
if (nextState != null) {
|
||||||
}
|
game = new GameRunner(nextState);
|
||||||
|
frames.change(GameFrame.ID);
|
||||||
private function restart():Void {
|
|
||||||
frames.change(GameFrame.ID, LOCAL({state: result.state.clean(), level: result.level}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function next():Void {
|
|
||||||
var pack = levelBundle.get(result.level.packId);
|
|
||||||
if (pack.data.length > result.level.id + 1) {
|
|
||||||
var level = pack.data[result.level.id + 1];
|
|
||||||
var progress = gameStorage.get(pack.id);
|
|
||||||
if (progress.isPresetAvailable(level.id, result.state.presetId)) {
|
|
||||||
frames.change(GameFrame.ID, LOCAL({state: result.state.clean(), level: level}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function close():Void {
|
private function close() {
|
||||||
frames.change(MenuFrame.ID);
|
frames.change(LevelFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,16 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
views:
|
views:
|
||||||
- id: level
|
- id: level
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.header
|
skinId: text.header
|
||||||
font.align: center
|
|
||||||
- id: result
|
- id: result
|
||||||
$type: haxework.view.data.DataView
|
$type: haxework.view.DataView
|
||||||
factory: ~playerViewFactory
|
factory: $this:playerViewFactory
|
||||||
geometry.height: 100%
|
|
||||||
overflow.y: scroll
|
|
||||||
geometry.margin.top: 20
|
geometry.margin.top: 20
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.VerticalLayout
|
$type: haxework.view.layout.VerticalLayout
|
||||||
hAlign: right
|
hAlign: right
|
||||||
margin: 10
|
margin: 10
|
||||||
- $type: haxework.view.group.HGroupView
|
|
||||||
style: panel
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 50%
|
|
||||||
- id: levels
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
text: Levels
|
|
||||||
+onPress: ~levels()
|
|
||||||
- id: restart
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
text: Restart
|
|
||||||
+onPress: ~restart()
|
|
||||||
- id: next
|
|
||||||
$type: haxework.view.form.ButtonView
|
|
||||||
text: Next
|
|
||||||
+onPress: ~next()
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 50%
|
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.VGroupView;
|
||||||
import haxework.view.frame.FrameView;
|
|
||||||
|
|
||||||
@:template class SettingsFrame extends FrameView<Dynamic> {
|
@:template class SettingsFrame extends VGroupView {
|
||||||
public static var ID(default, never):String = "settings";
|
public static var ID(default, never):String = "settings";
|
||||||
|
|
||||||
@:provide static var switcher:FrameSwitcher;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,15 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.LabelView
|
- $type: haxework.view.LabelView
|
||||||
style: text.header
|
skinId: text.header
|
||||||
text: Settings
|
text: Settings
|
||||||
- $type: haxework.view.group.GroupView
|
- $type: haxework.view.HGroupView
|
||||||
geometry.width: 100%
|
layout.margin: 20
|
||||||
geometry.height: 100%
|
|
||||||
overflow.y: scroll
|
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
vAlign: top
|
|
||||||
margin: 20
|
|
||||||
views:
|
views:
|
||||||
- id: settings0
|
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
|
||||||
controlIndex: 0
|
controlIndex: 0
|
||||||
- id: settings1
|
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
|
||||||
controlIndex: 1
|
controlIndex: 1
|
||||||
- $type: haxework.view.group.HGroupView
|
|
||||||
style: panel
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.width: 100%
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.prev
|
|
||||||
+onPress: ~switcher.change("menu")
|
|
||||||
|
|||||||
@@ -1,113 +1,56 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
|
||||||
import haxework.view.form.ButtonView;
|
|
||||||
import haxework.view.form.LabelView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.control.Controller;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.control.PlayerControl;
|
import ru.m.tankz.Type.GameType;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.view.network.RoomListFrame;
|
||||||
import ru.m.tankz.game.GameInit;
|
import ru.m.tankz.view.network.RoomFrame;
|
||||||
import ru.m.tankz.game.PackProgress;
|
import ru.m.tankz.view.popup.FontPopup;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
import ru.m.tankz.Type;
|
|
||||||
import ru.m.tankz.view.common.SlotView;
|
|
||||||
|
|
||||||
using haxe.EnumTools.EnumValueTools;
|
@:template class StartFrame extends VGroupView {
|
||||||
|
|
||||||
@:template class StartFrame extends FrameView<Start> {
|
|
||||||
|
|
||||||
public static var ID(default, never):String = "start";
|
public static var ID(default, never):String = "start";
|
||||||
|
|
||||||
@:provide static var switcher:FrameSwitcher;
|
@:provide var state:GameState;
|
||||||
@:provide static var storage:GameStorage;
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
|
||||||
private var progress:PackProgress;
|
private var fontPopup:FontPopup;
|
||||||
|
|
||||||
@:view var header:LabelView;
|
private function startGame(type:GameType):Void {
|
||||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
state = new GameState(type);
|
||||||
@:view("slots") var slotsView:DataView<PlayerControl, SlotView>;
|
switcher.change(LevelFrame.ID);
|
||||||
|
|
||||||
private var humanIndex:Int = 0;
|
|
||||||
private var humanTotal:Int = 2;
|
|
||||||
|
|
||||||
|
|
||||||
private var start:Start;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:Start):Void {
|
private function startNetwork():Void {
|
||||||
super.onShow(data);
|
switch network.state {
|
||||||
start = data;
|
case ONLINE(user):
|
||||||
this.progress = storage.get(start.level.packId);
|
if (network.room != null) {
|
||||||
header.text = '${start.state.type} - ${start.level.id}. ${start.level.name != null ? start.level.name : "#"}';
|
switcher.change(RoomFrame.ID);
|
||||||
presetsView.data = start.state.config.presets;
|
network.joinGame(network.room.game.id, true);
|
||||||
slotsView.data = defaultControls(start.state.config);
|
} else {
|
||||||
}
|
switcher.change(RoomListFrame.ID);
|
||||||
|
|
||||||
private static function defaultControls(config:Config):Array<PlayerControl> {
|
|
||||||
var controls:Array<PlayerControl> = [];
|
|
||||||
var preset = config.getPreset(0);
|
|
||||||
for (team in preset.teams) {
|
|
||||||
if (team.id != "bot") { // ToDo:
|
|
||||||
for (player in team.players) {
|
|
||||||
var playerId = new PlayerId(team.id, player.index);
|
|
||||||
controls.push({
|
|
||||||
playerId: playerId,
|
|
||||||
color: config.getColor(playerId),
|
|
||||||
controller: NONE,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
case CONNECTED:
|
||||||
}
|
LoginPopup.instance.show().then(function(user):Void {
|
||||||
controls.sort(function(a, b) return a.playerId.compare(b.playerId));
|
if (user != null) {
|
||||||
if (controls.length > 0) {
|
switcher.change(RoomListFrame.ID);
|
||||||
controls[0].controller = HUMAN(0);
|
|
||||||
controls[0].name = ControllerParser.defaultName(controls[0].controller);
|
|
||||||
}
|
|
||||||
return controls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
|
|
||||||
var result = new SlotView();
|
|
||||||
result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
|
|
||||||
result.control = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setController(value:PlayerControl, controller:Controller):Void {
|
|
||||||
switch controller {
|
|
||||||
case NONE:
|
|
||||||
case _:
|
|
||||||
for (view in slotsView.dataViews) {
|
|
||||||
if (view.control.controller.equals(controller)) {
|
|
||||||
view.control.controller = NONE;
|
|
||||||
view.select.selected = NONE;
|
|
||||||
view.control.name = null;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
value.controller = controller;
|
|
||||||
value.name = ControllerParser.defaultName(controller);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
private function choiceFont():Void {
|
||||||
var result = new ButtonView();
|
if (fontPopup == null) {
|
||||||
result.style = 'button${!progress.isPresetCompleted(start.level.id, value.id) ? ".active" : ""}';
|
fontPopup = new FontPopup();
|
||||||
result.text = value.name;
|
|
||||||
result.disabled = !progress.isPresetAvailable(start.level.id, value.id);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onPresetSelect(value:GamePreset):Void {
|
|
||||||
if (progress.isPresetAvailable(start.level.id, value.id)) {
|
|
||||||
start.state.presetId = value.id;
|
|
||||||
start.state.controls = slotsView.data;
|
|
||||||
switcher.change(GameFrame.ID, LOCAL(start));
|
|
||||||
}
|
}
|
||||||
|
fontPopup
|
||||||
|
.show()
|
||||||
|
.then(function(font) Style.register(font))
|
||||||
|
.catchError(function(e) {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,41 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
views:
|
layout.margin: 10
|
||||||
- id: header
|
views:
|
||||||
$type: haxework.view.form.LabelView
|
- $type: haxework.view.LabelView
|
||||||
style: text.header
|
text: Tank'z
|
||||||
- id: slots
|
skinId: font
|
||||||
$type: haxework.view.data.DataView
|
fontSize: 100
|
||||||
geometry.padding: 10
|
geometry.margin.bottom: 30
|
||||||
geometry.width: 100%
|
- $type: haxework.view.ButtonView
|
||||||
geometry.height: 100%
|
skinId: button
|
||||||
layout.hAlign: center
|
+onPress: $code:startGame('classic')
|
||||||
overflow.y: scroll
|
text: Classic
|
||||||
factory: ~slotViewFactory
|
- $type: haxework.view.ButtonView
|
||||||
layout:
|
skinId: button
|
||||||
$type: haxework.view.layout.VerticalLayout
|
+onPress: $code:startGame('dota')
|
||||||
# $type: haxework.view.layout.TailLayout
|
text: DotA
|
||||||
margin: 5
|
- $type: haxework.view.ButtonView
|
||||||
- $type: haxework.view.group.HGroupView
|
skinId: button
|
||||||
style: panel
|
+onPress: $code:startGame('death')
|
||||||
layout.margin: 10
|
text: DeathMatch
|
||||||
views:
|
- $type: haxework.view.ButtonView
|
||||||
- $type: haxework.view.SpriteView
|
skinId: button
|
||||||
geometry.width: 50%
|
+onPress: $code:switcher.change('record')
|
||||||
- id: presets
|
text: Records
|
||||||
$type: haxework.view.data.DataView
|
- id: network
|
||||||
factory: ~presetViewFactory
|
$type: haxework.view.ButtonView
|
||||||
+onDataSelect: ~onPresetSelect
|
skinId: button
|
||||||
layout:
|
+onPress: $code:startNetwork()
|
||||||
$type: haxework.view.layout.HorizontalLayout
|
text: Network
|
||||||
hAlign: center
|
#disabled: true
|
||||||
margin: 5
|
- $type: haxework.view.LabelView
|
||||||
- $type: haxework.view.SpriteView
|
geometry.hAlign: right
|
||||||
geometry.width: 50%
|
geometry.vAlign: top
|
||||||
- $type: haxework.view.form.ButtonView
|
geometry.padding: [20, 5]
|
||||||
style: button.prev
|
geometry.position: absolute
|
||||||
+onPress: ~switcher.change("level", start.level.packId)
|
geometry.margin: [0, 20, 20, 0]
|
||||||
|
skinId: text.box
|
||||||
|
text: $r:text:version
|
||||||
|
|||||||
@@ -1,32 +1,27 @@
|
|||||||
package ru.m.tankz.view.common;
|
package ru.m.tankz.view.common;
|
||||||
|
|
||||||
import haxework.color.Color;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.group.HGroupView;
|
|
||||||
import haxework.view.ImageView;
|
import haxework.view.ImageView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
@:template class LifeView extends HGroupView {
|
@:template class LifeView extends HGroupView {
|
||||||
|
@:provide static var currentState:GameState;
|
||||||
|
|
||||||
@:view("tank") public var tankImage:ImageView;
|
@:view("tank") public var tankImage:ImageView;
|
||||||
@:view("life") public var lifeLabel:LabelView;
|
@:view("life") public var lifeLabel:LabelView;
|
||||||
@:view("score") public var scoreLabel:LabelView;
|
@:view("score") public var scoreLabel:LabelView;
|
||||||
|
|
||||||
public var playerId(default, default):PlayerId;
|
|
||||||
public var state(null, set):PlayerState;
|
public var state(null, set):PlayerState;
|
||||||
public var tank(null, set):String;
|
public var tank(null, set):String;
|
||||||
public var color(null, set):Color;
|
public var color(null, set):Int;
|
||||||
public var life(null, set):Int;
|
public var life(null, set):Int;
|
||||||
public var score(null, set):Int;
|
public var score(null, set):Int;
|
||||||
|
|
||||||
private inline function set_state(value:PlayerState):PlayerState {
|
private inline function set_state(value:PlayerState):PlayerState {
|
||||||
playerId = value.id;
|
state = value;
|
||||||
tank = value.tank;
|
toUpdate();
|
||||||
color = value.color;
|
|
||||||
life = value.life;
|
|
||||||
score = value.score;
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +33,7 @@ import ru.m.tankz.Type;
|
|||||||
return tank;
|
return tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function set_color(value:Color):Color {
|
private inline function set_color(value:Int):Int {
|
||||||
tankImage.color = value;
|
tankImage.color = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -53,6 +48,17 @@ import ru.m.tankz.Type;
|
|||||||
return value;
|
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 {
|
public static inline function factory(index:Int, data:PlayerState):LifeView {
|
||||||
var result = new LifeView();
|
var result = new LifeView();
|
||||||
result.state = data;
|
result.state = data;
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ views:
|
|||||||
- id: tank
|
- id: tank
|
||||||
$type: haxework.view.ImageView
|
$type: haxework.view.ImageView
|
||||||
- id: life
|
- id: life
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 50
|
geometry.size.fixed: [50, 38]
|
||||||
geometry.height: 38
|
|
||||||
- id: score
|
- id: score
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 100
|
geometry.size.fixed: [100, 38]
|
||||||
geometry.height: 38
|
|
||||||
|
|||||||
119
src/client/haxe/ru/m/tankz/view/common/PlayerView.hx
Normal file
119
src/client/haxe/ru/m/tankz/view/common/PlayerView.hx
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml
Normal file
16
src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
geometry.margin: 5
|
||||||
|
layout.margin: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text
|
||||||
|
- id: teams
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
factory: $this:teamViewFactory
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 5
|
||||||
|
margin: 3
|
||||||
|
+onDataSelect: $this:onTeamSelect
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package ru.m.tankz.view.common;
|
package ru.m.tankz.view.common;
|
||||||
|
|
||||||
|
import ru.m.tankz.game.record.GamePlayer;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.group.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView;
|
import haxework.view.list.ListView;
|
||||||
import ru.m.tankz.game.GameInit;
|
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ import ru.m.tankz.storage.RecordStorage;
|
|||||||
|
|
||||||
@:provide var recordStorage:RecordStorage;
|
@:provide var recordStorage:RecordStorage;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
||||||
if (data != value) {
|
if (data != value) {
|
||||||
@@ -33,7 +35,8 @@ import ru.m.tankz.storage.RecordStorage;
|
|||||||
|
|
||||||
private function play():Void {
|
private function play():Void {
|
||||||
var record = recordStorage.read(data.id);
|
var record = recordStorage.read(data.id);
|
||||||
switcher.change(GameFrame.ID, RECORD(record));
|
game = new GamePlayer(record);
|
||||||
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function delete():Void {
|
private function delete():Void {
|
||||||
|
|||||||
@@ -1,33 +1,29 @@
|
|||||||
---
|
---
|
||||||
geometry.height: 38
|
geometry.size.height: 38
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
views:
|
views:
|
||||||
- id: play
|
- id: play
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
style: button.start.small
|
skinId: button.start.small
|
||||||
+onPress: ~play()
|
+onPress: $code:play()
|
||||||
- id: date
|
- id: date
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 200
|
geometry.size.fixed: [250, 38]
|
||||||
geometry.height: 38
|
|
||||||
- id: type
|
- id: type
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 200
|
geometry.size.fixed: [250, 38]
|
||||||
geometry.height: 38
|
|
||||||
- id: level
|
- id: level
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 100
|
geometry.size.fixed: [50, 38]
|
||||||
geometry.height: 38
|
|
||||||
- id: preset
|
- id: preset
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.width: 100
|
geometry.size.fixed: [50, 38]
|
||||||
geometry.height: 38
|
|
||||||
- id: delete
|
- id: delete
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
style: button.close.small
|
skinId: button.close.small
|
||||||
+onPress: ~delete()
|
+onPress: $code:delete()
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package ru.m.tankz.view.common;
|
|
||||||
|
|
||||||
import haxework.view.group.HGroupView;
|
|
||||||
import haxework.view.form.LabelView;
|
|
||||||
import haxework.view.form.SelectView;
|
|
||||||
import ru.m.tankz.control.Controller;
|
|
||||||
import ru.m.tankz.control.PlayerControl;
|
|
||||||
|
|
||||||
@:template class SlotView extends HGroupView {
|
|
||||||
|
|
||||||
@:view("slot") public var slotLabel:LabelView;
|
|
||||||
@:view("select") public var select:SelectView<Controller>;
|
|
||||||
|
|
||||||
public var control(default, set):PlayerControl;
|
|
||||||
|
|
||||||
private function set_control(value:PlayerControl):PlayerControl {
|
|
||||||
control = value;
|
|
||||||
slotLabel.text = '${control.playerId.team} #${control.playerId.index}';
|
|
||||||
slotLabel.font.color = value.color;
|
|
||||||
select.selected = control.controller;
|
|
||||||
return control;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onControllerSelect(value:Controller):Void {
|
|
||||||
select.currentView.style = switch value {
|
|
||||||
case HUMAN(_): "button.active";
|
|
||||||
case _: "button";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.height: 48
|
|
||||||
geometry.padding: 2
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- id: slot
|
|
||||||
$type: haxework.view.form.LabelView
|
|
||||||
style: text.box
|
|
||||||
geometry.height: 100%
|
|
||||||
geometry.width: 150
|
|
||||||
- id: select
|
|
||||||
$type: haxework.view.form.SelectView<ru.m.tankz.control.Controller>
|
|
||||||
geometry.width: 150
|
|
||||||
labelBuilder: |
|
|
||||||
~function(controller) {
|
|
||||||
var result = ControllerParser.defaultName(controller);
|
|
||||||
return result == null ? "None" : result;
|
|
||||||
}
|
|
||||||
data:
|
|
||||||
- ~ru.m.tankz.control.Controller.NONE
|
|
||||||
- ~ru.m.tankz.control.Controller.HUMAN(0)
|
|
||||||
- ~ru.m.tankz.control.Controller.HUMAN(1)
|
|
||||||
selected: ~ru.m.tankz.control.Controller.NONE
|
|
||||||
+onSelect: ~onControllerSelect
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.view.game;
|
package ru.m.tankz.view.game;
|
||||||
|
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.group.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
@@ -21,6 +21,7 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
|
level.text = 'Level ${state.levelId}';
|
||||||
bot.life = state.getTeamLife(ClassicGame.BOT);
|
bot.life = state.getTeamLife(ClassicGame.BOT);
|
||||||
player1.life = state.getPlayerLife(player1Id);
|
player1.life = state.getPlayerLife(player1Id);
|
||||||
player1.score = state.getPlayerScore(player1Id);
|
player1.score = state.getPlayerScore(player1Id);
|
||||||
@@ -35,9 +36,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(start):
|
case START(state):
|
||||||
this.level.text = 'Level ${start.level.id}';
|
refresh(state);
|
||||||
refresh(start.state);
|
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
if (teamId == ClassicGame.BOT) {
|
if (teamId == ClassicGame.BOT) {
|
||||||
bot.life = life;
|
bot.life = life;
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
---
|
---
|
||||||
geometry.padding: 5
|
geometry.padding: 5
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
layout.hAlign: left
|
layout.hAlign: left
|
||||||
views:
|
views:
|
||||||
- id: level
|
- id: level
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.height: 38
|
geometry.size.height: 38
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.height: 50%
|
geometry.size.height: 50%
|
||||||
- id: bot
|
- id: bot
|
||||||
$type: ru.m.tankz.view.common.LifeView
|
$type: ru.m.tankz.view.common.LifeView
|
||||||
tank: ba
|
tank: ba
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package ru.m.tankz.view.game;
|
package ru.m.tankz.view.game;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.group.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.preset.DeathGame;
|
|
||||||
import ru.m.tankz.view.common.LifeView;
|
import ru.m.tankz.view.common.LifeView;
|
||||||
|
|
||||||
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
|
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
|
||||||
@@ -16,31 +14,15 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
@:view var level:LabelView;
|
@:view var level:LabelView;
|
||||||
@:view var players:DataView<PlayerState, LifeView>;
|
@: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 {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(start):
|
case START(state):
|
||||||
this.level.text = 'Level ${start.level.id}';
|
level.text = 'Level ${state.levelId}';
|
||||||
players.data = Lambda.array(start.state.players);
|
players.data = Lambda.array(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 _:
|
case _:
|
||||||
|
for (view in players.views) {
|
||||||
|
view.toUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
---
|
---
|
||||||
geometry.padding: 5
|
geometry.padding: 5
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
layout.hAlign: right
|
layout.hAlign: right
|
||||||
views:
|
views:
|
||||||
- id: level
|
- id: level
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.height: 38
|
geometry.size.height: 38
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.height: 50%
|
geometry.size.height: 50%
|
||||||
- id: players
|
- id: players
|
||||||
$type: haxework.view.data.DataView
|
$type: haxework.view.DataView
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.VerticalLayout
|
$type: haxework.view.layout.VerticalLayout
|
||||||
factory: ~ru.m.tankz.view.common.LifeView.factory
|
factory: $code:ru.m.tankz.view.common.LifeView.factory
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.view.game;
|
package ru.m.tankz.view.game;
|
||||||
|
|
||||||
import haxework.view.group.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
@@ -17,6 +17,7 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
@:view var level:LabelView;
|
@:view var level:LabelView;
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
|
level.text = 'Level ${state.levelId}';
|
||||||
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
||||||
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
||||||
dire.life = state.getTeamLife(DotaGame.DIRE);
|
dire.life = state.getTeamLife(DotaGame.DIRE);
|
||||||
@@ -33,9 +34,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(start):
|
case START(state):
|
||||||
this.level.text = 'Level ${start.level.id}';
|
refresh(state);
|
||||||
refresh(start.state);
|
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
getLifeView(teamId).life = life;
|
getLifeView(teamId).life = life;
|
||||||
case CHANGE(TEAM_SCORE(teamId, score)):
|
case CHANGE(TEAM_SCORE(teamId, score)):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
layout.margin: 20
|
layout.margin: 20
|
||||||
views:
|
views:
|
||||||
- id: radiant
|
- id: radiant
|
||||||
@@ -7,14 +7,14 @@ views:
|
|||||||
tank: bc
|
tank: bc
|
||||||
color: 0xff4422
|
color: 0xff4422
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.width: 25%
|
geometry.size.width: 25%
|
||||||
- id: level
|
- id: level
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.height: 38
|
geometry.size.height: 38
|
||||||
geometry.width: 50%
|
geometry.size.width: 50%
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.width: 25%
|
geometry.size.width: 25%
|
||||||
- id: dire
|
- id: dire
|
||||||
$type: ru.m.tankz.view.common.LifeView
|
$type: ru.m.tankz.view.common.LifeView
|
||||||
tank: bc
|
tank: bc
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.view.game;
|
package ru.m.tankz.view.game;
|
||||||
|
|
||||||
import haxework.view.group.IGroupView;
|
import haxework.view.IGroupView;
|
||||||
import haxework.view.group.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.preset.ClassicGame;
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
import ru.m.tankz.preset.DeathGame;
|
import ru.m.tankz.preset.DeathGame;
|
||||||
@@ -50,18 +50,4 @@ import ru.m.tankz.Type;
|
|||||||
case _: throw 'Unsupported position: ${position}';
|
case _: throw 'Unsupported position: ${position}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
if (parent != null) {
|
|
||||||
var s = Math.min(parent.width / width, parent.height / height);
|
|
||||||
if (s < 1) {
|
|
||||||
content.scaleX = content.scaleY = s;
|
|
||||||
content.x = (parent.width - width * s) / 2;
|
|
||||||
content.y = (parent.height - height * s) / 2;
|
|
||||||
} else {
|
|
||||||
content.scaleX = content.scaleY = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
---
|
---
|
||||||
views:
|
views:
|
||||||
- id: top
|
- id: top
|
||||||
$type: haxework.view.group.GroupView
|
$type: haxework.view.GroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
- $type: haxework.view.group.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
views:
|
views:
|
||||||
- id: left
|
- id: left
|
||||||
$type: haxework.view.group.GroupView
|
$type: haxework.view.GroupView
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
- id: render
|
- id: render
|
||||||
$type: ru.m.tankz.render.Render
|
$type: ru.m.tankz.render.Render
|
||||||
- id: right
|
- id: right
|
||||||
$type: haxework.view.group.GroupView
|
$type: haxework.view.GroupView
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
- id: bottom
|
- id: bottom
|
||||||
$type: haxework.view.group.GroupView
|
$type: haxework.view.GroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
package ru.m.tankz.view.network;
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
|
||||||
import haxework.view.list.VListView;
|
import haxework.view.list.VListView;
|
||||||
import haxework.view.text.TextView;
|
import haxework.view.TextView;
|
||||||
import ru.m.tankz.game.GameInit;
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.network.NetworkGame;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.room.RoomProto;
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
@:template class RoomFrame extends FrameView<RoomProto> {
|
@:template class RoomFrame extends VGroupView {
|
||||||
|
|
||||||
public static inline var ID = "room";
|
public static inline var ID = "room";
|
||||||
|
|
||||||
@@ -20,10 +21,7 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
|||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var game:IGame;
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function refresh(room:RoomProto):Void {
|
private function refresh(room:RoomProto):Void {
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
@@ -31,19 +29,22 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
|||||||
info.text = '${room.game.type} #${room.game.level}';
|
info.text = '${room.game.type} #${room.game.level}';
|
||||||
slots.data = room.slots;
|
slots.data = room.slots;
|
||||||
if (room.game.started) {
|
if (room.game.started) {
|
||||||
switcher.change(GameFrame.ID, NETWORK(network));
|
if (this.game == null) {
|
||||||
|
this.game = new NetworkGame(network);
|
||||||
|
}
|
||||||
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Timer.delay(function() switcher.change(RoomListFrame.ID), 1);
|
Timer.delay(function() switcher.change(RoomListFrame.ID), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:RoomProto):Void {
|
public function onShow():Void {
|
||||||
refresh(data);
|
refresh(network.room);
|
||||||
network.roomSignal.connect(refresh);
|
network.roomSignal.connect(refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onHide():Void {
|
public function onHide():Void {
|
||||||
network.roomSignal.disconnect(refresh);
|
network.roomSignal.disconnect(refresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,38 @@
|
|||||||
---
|
---
|
||||||
geometry.stretch: true
|
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.VerticalLayout
|
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
geometry.padding: 20
|
geometry.padding: 20
|
||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- id: header
|
- id: header
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.margin.bottom: 20
|
geometry.margin.bottom: 20
|
||||||
style: text.header
|
skinId: text.header
|
||||||
text: Game Room
|
text: Game Room
|
||||||
- $type: haxework.view.group.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- id: info
|
- id: info
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.padding: [30, 10]
|
geometry.padding: [30, 10]
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- id: start
|
- id: start
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
text: Start
|
text: Start
|
||||||
+onPress: ~network.startGame()
|
+onPress: $code:network.startGame()
|
||||||
visible: false
|
visible: false
|
||||||
- id: leave
|
- id: leave
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
text: Leave
|
text: Leave
|
||||||
+onPress: ~network.leaveGame()
|
+onPress: $code:network.leaveGame()
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.height: 3
|
geometry.size.height: 3
|
||||||
style: line
|
skinId: line
|
||||||
- id: slots
|
- id: slots
|
||||||
$type: haxework.view.list.VListView
|
$type: haxework.view.list.VListView
|
||||||
geometry.stretch: true
|
geometry.size.stretch: true
|
||||||
factory: ~ru.m.tankz.view.network.SlotItemView.factory
|
factory: $code:ru.m.tankz.view.network.SlotItemView.factory
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package ru.m.tankz.view.network;
|
|||||||
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.group.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView;
|
import haxework.view.list.ListView;
|
||||||
import ru.m.tankz.proto.room.RoomProto;
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ import ru.m.tankz.proto.room.RoomProto;
|
|||||||
|
|
||||||
private function set_data(value:RoomProto):RoomProto {
|
private function set_data(value:RoomProto):RoomProto {
|
||||||
data = value;
|
data = value;
|
||||||
creatorView.style = value.creator.uuid == network.user.uuid ? "text.box.active" : "text.box";
|
creatorView.skinId = value.creator.uuid == network.user.uuid ? "text.box.active" : "text.box";
|
||||||
creatorView.text = value.creator.name;
|
creatorView.text = value.creator.name;
|
||||||
typeView.text = '${value.game.type} #${value.game.level}';
|
typeView.text = '${value.game.type} #${value.game.level}';
|
||||||
var used = value.slots.filter(function(slot:RoomSlotProto) return slot.hasUser()).length;
|
var used = value.slots.filter(function(slot:RoomSlotProto) return slot.hasUser()).length;
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
---
|
---
|
||||||
# geometry.width: 100%
|
# geometry.size.width: 100%
|
||||||
geometry.height: 48
|
geometry.size.height: 48
|
||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
views:
|
views:
|
||||||
- id: creator
|
- id: creator
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
geometry.width: 200
|
geometry.size.width: 200
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- id: type
|
- id: type
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
geometry.width: 200
|
geometry.size.width: 200
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- id: users
|
- id: users
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
geometry.width: 150
|
geometry.size.width: 150
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- id: join
|
- id: join
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
|
skinId: button.simple
|
||||||
text: Join
|
text: Join
|
||||||
+onPress: ~join()
|
+onPress: $code:join()
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package ru.m.tankz.view.network;
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
|
||||||
import haxework.view.list.VListView;
|
import haxework.view.list.VListView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.room.RoomProto;
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
import ru.m.tankz.view.popup.CreateGamePopup;
|
import ru.m.tankz.view.popup.CreateGamePopup;
|
||||||
|
|
||||||
@:template class RoomListFrame extends FrameView<Dynamic> {
|
@:template class RoomListFrame extends VGroupView {
|
||||||
public static inline var ID = "room_list";
|
public static inline var ID = "room_list";
|
||||||
|
|
||||||
@:view var games:VListView<RoomProto>;
|
@:view var games:VListView<RoomProto>;
|
||||||
@@ -15,17 +15,13 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
|||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
|
|
||||||
public function new() {
|
public function onShow():Void {
|
||||||
super(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onShow(_:Dynamic):Void {
|
|
||||||
network.listRoomSignal.connect(onRoomList);
|
network.listRoomSignal.connect(onRoomList);
|
||||||
network.roomSignal.connect(onRoom);
|
network.roomSignal.connect(onRoom);
|
||||||
network.listGame(true);
|
network.listGame(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onHide():Void {
|
public function onHide():Void {
|
||||||
network.listRoomSignal.disconnect(onRoomList);
|
network.listRoomSignal.disconnect(onRoomList);
|
||||||
network.roomSignal.disconnect(onRoom);
|
network.roomSignal.disconnect(onRoom);
|
||||||
network.listGame(false);
|
network.listGame(false);
|
||||||
@@ -34,7 +30,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
|||||||
private function create():Void {
|
private function create():Void {
|
||||||
CreateGamePopup.instance.show().then(function(result) {
|
CreateGamePopup.instance.show().then(function(result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
network.createGame(result.type, result.level.id);
|
network.createGame(result.type, result.level);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -45,7 +41,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
|||||||
|
|
||||||
private function onRoom(room:RoomProto):Void {
|
private function onRoom(room:RoomProto):Void {
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
switcher.change(RoomFrame.ID, room);
|
switcher.change(RoomFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
---
|
---
|
||||||
geometry.stretch: true
|
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.VerticalLayout
|
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
style: container
|
skinId: container
|
||||||
geometry.padding: 20
|
geometry.padding: 20
|
||||||
views:
|
views:
|
||||||
- id: header
|
- id: header
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.margin.bottom: 20
|
geometry.margin.bottom: 20
|
||||||
style: text.header
|
skinId: text.header
|
||||||
text: Games List
|
text: Games List
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
text: Create
|
text: Create
|
||||||
+onPress: ~create()
|
+onPress: $code:create()
|
||||||
- id: games
|
- id: games
|
||||||
$type: haxework.view.list.VListView
|
$type: haxework.view.list.VListView
|
||||||
geometry.stretch: true
|
geometry.size.stretch: true
|
||||||
factory: ~ru.m.tankz.view.network.RoomItemView.factory
|
factory: $code:ru.m.tankz.view.network.RoomItemView.factory
|
||||||
geometry.margin: 10
|
geometry.margin: 10
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.view.network;
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.group.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView;
|
import haxework.view.list.ListView;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
@@ -26,10 +26,12 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
|||||||
userView.text = value.hasUser() ? value.user.name : "(NONE)";
|
userView.text = value.hasUser() ? value.user.name : "(NONE)";
|
||||||
userView.visible = value.hasUser();
|
userView.visible = value.hasUser();
|
||||||
selectButton.visible = !value.hasUser();
|
selectButton.visible = !value.hasUser();
|
||||||
userView.style = (value.hasUser() && value.user.uuid == network.user.uuid) ? "text.box.active" : "text.box";
|
userView.skinId = (value.hasUser() && value.user.uuid == network.user.uuid) ? "text.box.active" : "text.box";
|
||||||
var config = configBundle.get(network.room.game.type);
|
var config = configBundle.get(network.room.game.type);
|
||||||
var color = config.getColor([value.slot.team, value.slot.index]);
|
var color = config.getColor([value.slot.team, value.slot.index]);
|
||||||
typeView.font.color = color;
|
if (color != null) {
|
||||||
|
typeView.skin = Style.textBox(color);
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
---
|
---
|
||||||
geometry.height: 48
|
geometry.size.height: 48
|
||||||
geometry.padding: 2
|
geometry.padding: 2
|
||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- id: type
|
- id: type
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text.box
|
skinId: text.box
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
geometry.width: 150
|
geometry.size.width: 150
|
||||||
- $type: haxework.view.group.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
geometry.height: 100%
|
geometry.size.height: 100%
|
||||||
geometry.width: 300
|
geometry.size.width: 300
|
||||||
views:
|
views:
|
||||||
- id: user
|
- id: user
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.stretch: true
|
geometry.size.stretch: true
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- id: select
|
- id: select
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
text: Select
|
text: Select
|
||||||
+onPress: ~select()
|
+onPress: $this:select()
|
||||||
|
|||||||
@@ -1,28 +1,25 @@
|
|||||||
package ru.m.tankz.view.popup;
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
import haxework.view.form.ToggleButtonView;
|
import haxework.view.ToggleButtonView;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
|
||||||
import ru.m.tankz.config.Config;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
private typedef Result = {
|
private typedef Result = {
|
||||||
var type:GameType;
|
var type:GameType;
|
||||||
var level:LevelConfig;
|
var level:LevelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:template class CreateGamePopup extends PopupView<Result> {
|
@:template class CreateGamePopup extends PopupView<Result> {
|
||||||
|
|
||||||
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||||
@:view("level") var levelView:DataView<LevelConfig, ToggleButtonView>;
|
@:view("level") var levelView:DataView<LevelId, ToggleButtonView>;
|
||||||
|
|
||||||
@:provide static var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
@:provide static var levelBundle:ILevelBundle;
|
|
||||||
|
|
||||||
private var type:GameType;
|
private var type:GameType;
|
||||||
private var level:LevelConfig;
|
private var level:LevelId;
|
||||||
|
|
||||||
override private function onShow():Void {
|
override private function onShow():Void {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
@@ -35,6 +32,7 @@ private typedef Result = {
|
|||||||
|
|
||||||
private function gameTypeViewFactory(index:Int, type:GameType):ToggleButtonView {
|
private function gameTypeViewFactory(index:Int, type:GameType):ToggleButtonView {
|
||||||
var result = new ToggleButtonView();
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = "button.simple";
|
||||||
result.text = type;
|
result.text = type;
|
||||||
result.on = type == this.type;
|
result.on = type == this.type;
|
||||||
return result;
|
return result;
|
||||||
@@ -45,18 +43,18 @@ private typedef Result = {
|
|||||||
for (v in typeView.dataViews) {
|
for (v in typeView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
}
|
}
|
||||||
levelView.data = levelBundle.get(new PackId(value)).data;
|
levelView.data = [for (i in 0...configBundle.get(type).game.levels) i];
|
||||||
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
onLevelSelect(0, 0, levelView.dataViews[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, value:LevelConfig):ToggleButtonView {
|
private function levelViewFactory(index:Int, value:LevelId):ToggleButtonView {
|
||||||
var result = new ToggleButtonView();
|
var result = new ToggleButtonView();
|
||||||
result.style = "button.level";
|
result.skinId = "button.level";
|
||||||
result.text = Std.string(value.id);
|
result.text = Std.string(value);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ToggleButtonView):Void {
|
private function onLevelSelect(index:Int, level:LevelId, view:ToggleButtonView):Void {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
for (v in levelView.dataViews) {
|
for (v in levelView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
|
|||||||
@@ -2,70 +2,67 @@
|
|||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
view:
|
view:
|
||||||
$type: haxework.view.group.VGroupView
|
$type: haxework.view.VGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.stretch: true
|
geometry.size.width: 600
|
||||||
geometry.margin: 10
|
skinId: window
|
||||||
style: window
|
views:
|
||||||
views:
|
- $type: haxework.view.HGroupView
|
||||||
- $type: haxework.view.group.HGroupView
|
geometry.size.width: 100%
|
||||||
geometry.width: 100%
|
geometry.padding: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: name
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.margin.left: 10
|
||||||
|
layout.hAlign: left
|
||||||
|
skinId: text
|
||||||
|
text: New game
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: window.close
|
||||||
|
+onPress: $code:reject('close')
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 20
|
||||||
|
layout.margin: 5
|
||||||
|
layout.hAlign: center
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Type
|
||||||
|
- id: type
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.HorizontalLayout
|
||||||
|
margin: 10
|
||||||
|
factory: $this:gameTypeViewFactory
|
||||||
|
+onItemSelect: $this:onGameTypeSelect
|
||||||
|
data:
|
||||||
|
- "classic"
|
||||||
|
- "dota"
|
||||||
|
- "death"
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Level
|
||||||
|
- id: level
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onItemSelect: $this:onLevelSelect
|
||||||
geometry.padding: 10
|
geometry.padding: 10
|
||||||
layout.vAlign: middle
|
- $type: haxework.view.HGroupView
|
||||||
views:
|
layout.hAlign: center
|
||||||
- id: name
|
layout.margin: 5
|
||||||
$type: haxework.view.form.LabelView
|
skinId: panel
|
||||||
geometry.width: 100%
|
views:
|
||||||
geometry.margin.left: 10
|
- $type: haxework.view.ButtonView
|
||||||
layout.hAlign: left
|
skinId: button.simple
|
||||||
style: text
|
text: Create
|
||||||
text: New game
|
+onPress: $code:submit()
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: window.close
|
|
||||||
+onPress: ~reject('close')
|
|
||||||
- $type: haxework.view.group.VGroupView
|
|
||||||
geometry.stretch: true
|
|
||||||
geometry.padding: [5, 20]
|
|
||||||
layout.margin: 5
|
|
||||||
layout.hAlign: center
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.form.LabelView
|
|
||||||
geometry.width: 100%
|
|
||||||
style: text
|
|
||||||
text: Type
|
|
||||||
- id: type
|
|
||||||
$type: haxework.view.data.DataView
|
|
||||||
geometry.width: 100%
|
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
margin: 10
|
|
||||||
factory: ~gameTypeViewFactory
|
|
||||||
+onItemSelect: ~onGameTypeSelect
|
|
||||||
data:
|
|
||||||
- "classic"
|
|
||||||
- "dota"
|
|
||||||
- "death"
|
|
||||||
- $type: haxework.view.form.LabelView
|
|
||||||
geometry.width: 100%
|
|
||||||
style: text
|
|
||||||
text: Level
|
|
||||||
- id: level
|
|
||||||
$type: haxework.view.data.DataView
|
|
||||||
geometry.width: 100%
|
|
||||||
geometry.height: 100%
|
|
||||||
overflow.y: scroll
|
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
rowSize: 10
|
|
||||||
margin: 5
|
|
||||||
factory: ~levelViewFactory
|
|
||||||
+onItemSelect: ~onLevelSelect
|
|
||||||
geometry.padding: 10
|
|
||||||
- $type: haxework.view.group.HGroupView
|
|
||||||
layout.hAlign: center
|
|
||||||
layout.margin: 5
|
|
||||||
style: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
text: Create
|
|
||||||
+onPress: ~submit()
|
|
||||||
|
|||||||
41
src/client/haxe/ru/m/tankz/view/popup/FontPopup.hx
Normal file
41
src/client/haxe/ru/m/tankz/view/popup/FontPopup.hx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
|
import flash.text.Font;
|
||||||
|
import flash.text.FontType;
|
||||||
|
import haxework.view.list.LabelListItem;
|
||||||
|
import haxework.view.list.ListView;
|
||||||
|
import haxework.view.popup.PopupView;
|
||||||
|
|
||||||
|
class FontLabelView extends LabelListItem<Font> {
|
||||||
|
|
||||||
|
override private function set_data(value:Font):Font {
|
||||||
|
skinId = item_index % 2 == 0 ? "light" : "dark";
|
||||||
|
data = value;
|
||||||
|
text = value.fontName;
|
||||||
|
fontFamily = value.fontName;
|
||||||
|
fontEmbed = switch value.fontType {
|
||||||
|
case DEVICE: false;
|
||||||
|
case _: true;
|
||||||
|
};
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template class FontPopup extends PopupView<Font> {
|
||||||
|
|
||||||
|
@:view var fonts:ListView<Font>;
|
||||||
|
|
||||||
|
private function init():Void {
|
||||||
|
var values = Font.enumerateFonts(true);
|
||||||
|
values.sort(function(a:Font, b:Font) {
|
||||||
|
return switch [a.fontType, b.fontType] {
|
||||||
|
case [DEVICE, _]: 1;
|
||||||
|
case [_, DEVICE]: -1;
|
||||||
|
case _: 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fonts.data = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fontViewFactory() return new FontLabelView();
|
||||||
|
}
|
||||||
27
src/client/haxe/ru/m/tankz/view/popup/FontPopup.yaml
Normal file
27
src/client/haxe/ru/m/tankz/view/popup/FontPopup.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
view:
|
||||||
|
$type: haxework.view.VGroupView
|
||||||
|
geometry.size.width: 400
|
||||||
|
geometry.size.height: 80%
|
||||||
|
geometry.padding: 10
|
||||||
|
geometry.hAlign: center
|
||||||
|
geometry.vAlign: middle
|
||||||
|
skinId: dark
|
||||||
|
views:
|
||||||
|
- id: fonts
|
||||||
|
$type: haxework.view.list.VListView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
factory: $this:fontViewFactory
|
||||||
|
+onItemSelect: $code:function(item) close(item.data)
|
||||||
|
scroll:
|
||||||
|
$type: haxework.view.list.VScrollBarView
|
||||||
|
skinId: scroll.vertical
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.margin.top: 10
|
||||||
|
layout.hAlign: right
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Cancel
|
||||||
|
+onPress: $code:reject('cancel')
|
||||||
63
src/client/haxe/ru/m/tankz/view/popup/LevelPopup.hx
Normal file
63
src/client/haxe/ru/m/tankz/view/popup/LevelPopup.hx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
|
import haxework.view.ToggleButtonView;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.popup.PopupView;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.game.GameProgress;
|
||||||
|
|
||||||
|
private typedef Result = {
|
||||||
|
var control:ControlPreset;
|
||||||
|
var preset:GamePreset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template class LevelPopup extends PopupView<Result> {
|
||||||
|
|
||||||
|
private var level:LevelConfig;
|
||||||
|
private var progress:GameProgress;
|
||||||
|
|
||||||
|
@:view var name:LabelView;
|
||||||
|
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||||
|
@:view("controls") var controlsView:DataView<ControlPreset, ToggleButtonView>;
|
||||||
|
private var control:ControlPreset;
|
||||||
|
|
||||||
|
public function setData(level:LevelConfig, presets:Array<GamePreset>, controls:Array<ControlPreset>, progress:GameProgress):Void {
|
||||||
|
this.level = level;
|
||||||
|
this.progress = progress;
|
||||||
|
name.text = '${level.id}. ${level.name != null ? level.name : "#"}';
|
||||||
|
presetsView.data = presets;
|
||||||
|
control = controls[0];
|
||||||
|
controlsView.data = controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
||||||
|
var result = new ButtonView();
|
||||||
|
result.skinId = 'button.simple${!progress.isPresetCompleted(level.id, value.id) ? ".active" : ""}';
|
||||||
|
result.text = value.name;
|
||||||
|
result.disabled = !progress.isPresetAvailable(level.id, value.id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onPresetSelect(value:GamePreset):Void {
|
||||||
|
if (progress.isPresetAvailable(level.id, value.id)) {
|
||||||
|
close({control: control, preset: value});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function controlViewFactory(index:Int, value:ControlPreset):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = 'button.simple.active';
|
||||||
|
result.on = control == value;
|
||||||
|
result.text = value.name;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onControlSelect(index:Int, value:ControlPreset, view:ToggleButtonView):Void {
|
||||||
|
control = value;
|
||||||
|
for (v in controlsView.dataViews) {
|
||||||
|
v.on = v == view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/client/haxe/ru/m/tankz/view/popup/LevelPopup.yaml
Normal file
44
src/client/haxe/ru/m/tankz/view/popup/LevelPopup.yaml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
view:
|
||||||
|
$type: haxework.view.VGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
geometry.size.width: 400
|
||||||
|
geometry.size.height: 400
|
||||||
|
skinId: window
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: name
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.margin.left: 10
|
||||||
|
layout.hAlign: left
|
||||||
|
skinId: text
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: window.close
|
||||||
|
+onPress: $code:reject('close')
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.height: 100%
|
||||||
|
- id: controls
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
factory: $this:controlViewFactory
|
||||||
|
+onItemSelect: $this:onControlSelect
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.HorizontalLayout
|
||||||
|
hAlign: center
|
||||||
|
margin: 5
|
||||||
|
skinId: panel
|
||||||
|
- id: presets
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
factory: $this:presetViewFactory
|
||||||
|
+onDataSelect: $this:onPresetSelect
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.HorizontalLayout
|
||||||
|
hAlign: center
|
||||||
|
margin: 5
|
||||||
|
skinId: panel
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package ru.m.tankz.view.popup;
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
import haxework.log.BaseLogger.LoggerUtil;
|
import haxework.log.BaseLogger.LoggerUtil;
|
||||||
import haxework.view.form.InputView;
|
import haxework.view.InputView;
|
||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
import haxework.view.text.TextView;
|
import haxework.view.TextView;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
|
||||||
@:template class LoginPopup extends PopupView<User> {
|
@:template class LoginPopup extends PopupView<User> {
|
||||||
|
|||||||
@@ -2,64 +2,65 @@
|
|||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
view:
|
view:
|
||||||
$type: haxework.view.group.VGroupView
|
$type: haxework.view.VGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.width: 400
|
geometry.size.width: 400
|
||||||
# geometry.height: 400
|
# geometry.size.height: 400
|
||||||
style: window
|
skinId: window
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.group.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.padding: 10
|
geometry.padding: 10
|
||||||
layout.vAlign: middle
|
layout.vAlign: middle
|
||||||
views:
|
views:
|
||||||
- id: name
|
- id: name
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.margin.left: 10
|
geometry.margin.left: 10
|
||||||
layout.hAlign: left
|
layout.hAlign: left
|
||||||
style: text
|
skinId: text
|
||||||
text: Login
|
text: Login
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.ButtonView
|
||||||
style: window.close
|
skinId: window.close
|
||||||
+onPress: ~reject('close')
|
+onPress: $code:reject('close')
|
||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
# geometry.stretch: true
|
# geometry.size.stretch: true
|
||||||
geometry.padding: 20
|
geometry.padding: 20
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.LabelView
|
- $type: haxework.view.LabelView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
style: text
|
skinId: text
|
||||||
text: Username
|
text: Username
|
||||||
- id: username
|
- id: username
|
||||||
$type: haxework.view.form.InputView
|
$type: haxework.view.InputView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.height: 28
|
geometry.size.height: 28
|
||||||
style: text.box
|
skinId: text.box
|
||||||
- $type: haxework.view.form.LabelView
|
- $type: haxework.view.LabelView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
style: text
|
skinId: text
|
||||||
text: Password
|
text: Password
|
||||||
visible: false
|
visible: false
|
||||||
- id: password
|
- id: password
|
||||||
$type: haxework.view.form.InputView
|
$type: haxework.view.InputView
|
||||||
textField.displayAsPassword: true
|
textField.displayAsPassword: true
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.height: 28
|
geometry.size.height: 28
|
||||||
style: text.box
|
skinId: text.box
|
||||||
visible: false
|
visible: false
|
||||||
- id: error
|
- id: error
|
||||||
$type: haxework.view.text.TextView
|
$type: haxework.view.TextView
|
||||||
geometry.width: 100%
|
geometry.size.width: 100%
|
||||||
style: text
|
skinId: text
|
||||||
fill: false
|
fill: false
|
||||||
- $type: haxework.view.group.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
style: panel
|
skinId: panel
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
text: Submit
|
text: Submit
|
||||||
+onPress: ~submit()
|
+onPress: $code:submit()
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
package ru.m.tankz.view.settings;
|
package ru.m.tankz.view.settings;
|
||||||
|
|
||||||
import haxework.view.group.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView;
|
import haxework.view.list.ListView.IListItemView;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.control.DeviceAction;
|
import openfl.events.KeyboardEvent;
|
||||||
import ru.m.tankz.control.Binding;
|
import promhx.Deferred;
|
||||||
|
import promhx.Promise;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
typedef ActionItem = {
|
|
||||||
var action:TankAction;
|
|
||||||
var bind:BindAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
class KeyboardMap {
|
class KeyboardMap {
|
||||||
|
|
||||||
private var data:Map<Int, String>;
|
private var data:Map<Int, String>;
|
||||||
@@ -29,9 +26,9 @@ class KeyboardMap {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var instance:KeyboardMap;
|
private static var instance: KeyboardMap;
|
||||||
|
|
||||||
public static function getName(key:Int):String {
|
public static function getName(key: Int): String {
|
||||||
if (instance == null) instance = new KeyboardMap();
|
if (instance == null) instance = new KeyboardMap();
|
||||||
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||||
}
|
}
|
||||||
@@ -42,12 +39,12 @@ class KeyboardMap {
|
|||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):ActionItem;
|
public var data(default, set):ActionItem;
|
||||||
|
|
||||||
public var edit(default, set):Bool;
|
|
||||||
|
|
||||||
@:view var action(default, null):LabelView;
|
@:view var action(default, null):LabelView;
|
||||||
@:view var key(default, null):LabelView;
|
@:view var key(default, null):LabelView;
|
||||||
|
|
||||||
private static function actionLabel(action:TankAction):String {
|
private var editDeferred: Deferred<Int>;
|
||||||
|
|
||||||
|
private static function actionLabel(action: TankAction): String {
|
||||||
return switch (action) {
|
return switch (action) {
|
||||||
case TankAction.SHOT: "SHOT";
|
case TankAction.SHOT: "SHOT";
|
||||||
case TankAction.MOVE(d): 'MOVE_$d';
|
case TankAction.MOVE(d): 'MOVE_$d';
|
||||||
@@ -55,25 +52,32 @@ class KeyboardMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function bindLabel(bind:BindAction):String {
|
private static function keyLabel(key: Int): String {
|
||||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
return KeyboardMap.getName(key);
|
||||||
case KEY(code): KeyboardMap.getName(code);
|
|
||||||
case DIRECTION(direction): Std.string(direction);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_data(value:ActionItem):ActionItem {
|
private function set_data(value:ActionItem):ActionItem {
|
||||||
data = value;
|
data = value;
|
||||||
action.text = actionLabel(data.action);
|
action.text = actionLabel(data.action);
|
||||||
key.text = bindLabel(data.bind);
|
key.text = keyLabel(data.key);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_edit(value:Bool):Bool {
|
public function edit():Promise<Int> {
|
||||||
if (edit != value) {
|
action.skinId = key.skinId = "text.box.active";
|
||||||
edit = value;
|
toRedraw();
|
||||||
action.style = key.style = edit ? "text.box.active" : "text.box";
|
editDeferred = new Deferred();
|
||||||
}
|
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
return edit;
|
return editDeferred.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onKeyDown(event: KeyboardEvent):Void {
|
||||||
|
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
action.skinId = key.skinId = "text.box";
|
||||||
|
toRedraw();
|
||||||
|
data.key = event.keyCode;
|
||||||
|
key.text = keyLabel(data.key);
|
||||||
|
editDeferred.resolve(data.key);
|
||||||
|
editDeferred = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ geometry.margin: 5
|
|||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
views:
|
views:
|
||||||
- id: action
|
- id: action
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.width: 180
|
geometry.size.fixed: [200, 38]
|
||||||
geometry.height: 38
|
skinId: text.box
|
||||||
style: text.box
|
|
||||||
- id: key
|
- id: key
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.width: 250
|
geometry.size.fixed: [200, 38]
|
||||||
geometry.height: 38
|
skinId: text.box
|
||||||
style: text.box
|
|
||||||
|
|||||||
@@ -1,66 +1,11 @@
|
|||||||
package ru.m.tankz.view.settings;
|
package ru.m.tankz.view.settings;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.group.GroupView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.form.LabelView;
|
import haxework.view.VGroupView;
|
||||||
import haxework.view.group.VGroupView;
|
|
||||||
import promhx.Deferred;
|
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.control.DeviceAction;
|
import ru.m.tankz.control.ActionConfig;
|
||||||
import ru.m.control.DeviceType;
|
|
||||||
import ru.m.control.IControlBus;
|
|
||||||
import ru.m.tankz.control.Binding;
|
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.view.settings.ActionView;
|
|
||||||
|
|
||||||
class BindEditor {
|
|
||||||
|
|
||||||
private var editViews:Array<ActionView>;
|
|
||||||
|
|
||||||
@:provide static var bus:IControlBus;
|
|
||||||
|
|
||||||
private var def:Deferred<Bool>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
editViews = [];
|
|
||||||
bus.signal.connect(onBusAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onBusAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
|
||||||
if (on && editViews.length > 0) {
|
|
||||||
var view = editViews.shift();
|
|
||||||
view.edit = false;
|
|
||||||
view.data.bind = {device: device, action: action};
|
|
||||||
view.data = view.data;
|
|
||||||
if (editViews.length > 0) {
|
|
||||||
editViews[0].edit = true;
|
|
||||||
} else {
|
|
||||||
def.resolve(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function push(views:Array<ActionView>):Promise<Bool> {
|
|
||||||
for (view in editViews) {
|
|
||||||
view.edit = false;
|
|
||||||
}
|
|
||||||
editViews = views.slice(0);
|
|
||||||
if (editViews.length > 0) {
|
|
||||||
editViews[0].edit = true;
|
|
||||||
}
|
|
||||||
def = new Deferred();
|
|
||||||
return def.promise();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static var i(get, null):BindEditor;
|
|
||||||
|
|
||||||
private static function get_i():BindEditor {
|
|
||||||
if (i == null) {
|
|
||||||
i = new BindEditor();
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@:template class SettingsEditor extends VGroupView {
|
@:template class SettingsEditor extends VGroupView {
|
||||||
|
|
||||||
@@ -68,20 +13,13 @@ class BindEditor {
|
|||||||
|
|
||||||
@:view var label:LabelView;
|
@:view var label:LabelView;
|
||||||
@:view var list:DataView<ActionItem, ActionView>;
|
@:view var list:DataView<ActionItem, ActionView>;
|
||||||
@:view var panel:GroupView;
|
|
||||||
|
|
||||||
@:provide static var storage:SettingsStorage;
|
@:provide var storage:SettingsStorage;
|
||||||
@:provide static var bus:IControlBus;
|
|
||||||
|
|
||||||
private function refresh():Void {
|
|
||||||
label.text = 'Player ${controlIndex+1}';
|
|
||||||
var binding = storage.getBinding(controlIndex);
|
|
||||||
list.data = bindingToArray(binding);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_controlIndex(value: Int): Int {
|
private function set_controlIndex(value: Int): Int {
|
||||||
this.controlIndex = value;
|
this.controlIndex = value;
|
||||||
refresh();
|
label.text = 'Player ${controlIndex+1}';
|
||||||
|
list.data = storage.getActionConfig(controlIndex).data;
|
||||||
return this.controlIndex;
|
return this.controlIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,48 +31,34 @@ class BindEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onItemSelect(index:Int, value:ActionItem, view:ActionView):Void {
|
private function onItemSelect(index:Int, value:ActionItem, view:ActionView):Void {
|
||||||
BindEditor.i.push([view]).then(function(_) save());
|
view.edit();
|
||||||
}
|
|
||||||
|
|
||||||
private function screen():Void {
|
|
||||||
list.data = bindingToArray(SettingsStorage.buildGamepadBinding(GamepadView.ID));
|
|
||||||
list.toUpdate();
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function change():Void {
|
private function change():Void {
|
||||||
BindEditor.i.push(list.dataViews).then(function(_) save());
|
var p: Promise<Int> = Promise.promise(0);
|
||||||
|
for (view in list.views) {
|
||||||
|
var v: ActionView = cast view;
|
||||||
|
p = p.pipe(function(_):Promise<Int> return v.edit());
|
||||||
|
}
|
||||||
|
p.then(function(_) save());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clear():Void {
|
private function clear():Void {
|
||||||
list.data = bindingToArray(SettingsStorage.getDefaultBinding(-1));
|
for (item in list.data) {
|
||||||
|
item.key = -1;
|
||||||
|
}
|
||||||
|
list.data = list.data;
|
||||||
list.toUpdate();
|
list.toUpdate();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function default_():Void {
|
private function reset():Void {
|
||||||
list.data = bindingToArray(SettingsStorage.getDefaultBinding(controlIndex));
|
list.data = SettingsStorage.getDefaultActionConfig(controlIndex).data;
|
||||||
list.toUpdate();
|
list.toUpdate();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function save():Void {
|
private function save():Void {
|
||||||
storage.saveBinding(controlIndex, arrayToBinding(list.data));
|
storage.setActionConffig(controlIndex, new ActionConfig(list.data));
|
||||||
}
|
|
||||||
|
|
||||||
private static function bindingToArray(binding:Binding):Array<ActionItem> {
|
|
||||||
var result:Array<ActionItem> = [];
|
|
||||||
for (action in binding.keys()) {
|
|
||||||
result.push({action: action, bind: binding.get(action)});
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function arrayToBinding(array:Array<ActionItem>):Binding {
|
|
||||||
var result = new Binding();
|
|
||||||
for (item in array) {
|
|
||||||
result.set(item.action, item.bind);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,30 @@
|
|||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.width: 400
|
|
||||||
views:
|
views:
|
||||||
- id: label
|
- id: label
|
||||||
$type: haxework.view.form.LabelView
|
$type: haxework.view.LabelView
|
||||||
style: text
|
skinId: text
|
||||||
- id: panel
|
- $type: haxework.view.HGroupView
|
||||||
$type: haxework.view.group.GroupView
|
layout.margin: 10
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
rowSize: 2
|
|
||||||
margin: 10
|
|
||||||
geometry.width: 100%
|
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.ButtonView
|
- id: change
|
||||||
+onPress: ~screen()
|
$type: haxework.view.ButtonView
|
||||||
text: Screen
|
+onPress: $code:change()
|
||||||
- $type: haxework.view.form.ButtonView
|
skinId: button.simple
|
||||||
+onPress: ~change()
|
|
||||||
text: Change
|
text: Change
|
||||||
- $type: haxework.view.form.ButtonView
|
- id: clear
|
||||||
+onPress: ~clear()
|
$type: haxework.view.ButtonView
|
||||||
|
+onPress: $code:clear()
|
||||||
|
skinId: button.simple
|
||||||
text: Clear
|
text: Clear
|
||||||
- $type: haxework.view.form.ButtonView
|
- id: reset
|
||||||
+onPress: ~default_()
|
$type: haxework.view.ButtonView
|
||||||
text: Default
|
+onPress: $code:reset()
|
||||||
|
skinId: button.simple
|
||||||
|
text: Reset
|
||||||
- id: list
|
- id: list
|
||||||
$type: haxework.view.data.DataView
|
$type: haxework.view.DataView
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.VerticalLayout
|
$type: haxework.view.layout.VerticalLayout
|
||||||
factory: ~viewFactory
|
factory: $this:viewFactory
|
||||||
+onItemSelect: ~onItemSelect
|
+onItemSelect: $this:onItemSelect
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="arrow-alt-circle-left" class="svg-inline--fa fa-arrow-alt-circle-left fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 504C119 504 8 393 8 256S119 8 256 8s248 111 248 248-111 248-248 248zm116-292H256v-70.9c0-10.7-13-16.1-20.5-8.5L121.2 247.5c-4.7 4.7-4.7 12.2 0 16.9l114.3 114.9c7.6 7.6 20.5 2.2 20.5-8.5V300h116c6.6 0 12-5.4 12-12v-64c0-6.6-5.4-12-12-12z"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 503 B |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB |
@@ -8,8 +8,6 @@ typedef TeamId = String;
|
|||||||
|
|
||||||
typedef BrickType = String;
|
typedef BrickType = String;
|
||||||
|
|
||||||
typedef BrickIndex = Int;
|
|
||||||
|
|
||||||
typedef TankType = String;
|
typedef TankType = String;
|
||||||
|
|
||||||
typedef BonusType = String;
|
typedef BonusType = String;
|
||||||
@@ -26,16 +24,6 @@ abstract PlayerId(Array<Dynamic>) {
|
|||||||
|
|
||||||
private inline function get_index():Int return this[1];
|
private inline function get_index():Int return this[1];
|
||||||
|
|
||||||
public function compare(other:PlayerId):Int {
|
|
||||||
if (other == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (other.team != team) {
|
|
||||||
return team > other.team ? 1 : -1;
|
|
||||||
}
|
|
||||||
return index - other.index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:from static public inline function fromArray(value:Array<Dynamic>):PlayerId {
|
@:from static public inline function fromArray(value:Array<Dynamic>):PlayerId {
|
||||||
return new PlayerId(value[0], value[1]);
|
return new PlayerId(value[0], value[1]);
|
||||||
}
|
}
|
||||||
@@ -49,33 +37,5 @@ abstract PlayerId(Array<Dynamic>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract PackId(Array<Dynamic>) {
|
|
||||||
public static inline var DEFAULT = "standard";
|
|
||||||
|
|
||||||
public var type(get, never):GameType;
|
|
||||||
public var name(get, never):String;
|
|
||||||
|
|
||||||
public function new(type:GameType, name:String = DEFAULT) {
|
|
||||||
this = [type, name];
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_type():GameType return this[0];
|
|
||||||
|
|
||||||
private inline function get_name():String return this[1];
|
|
||||||
|
|
||||||
@:from static public inline function fromArray(value:Array<Dynamic>):PackId {
|
|
||||||
return new PackId(value[0], value[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@:to public inline function toString():String {
|
|
||||||
return '${type}_${name}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@:op(X == Y) static public inline function equals(x:PackId, y:PackId):Bool {
|
|
||||||
return x.type == y.type && x.name == y.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef LevelId = Int;
|
typedef LevelId = Int;
|
||||||
|
|
||||||
typedef PresetId = Int;
|
typedef PresetId = Int;
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import ru.m.tankz.config.Config;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface ILevelBundle {
|
interface ILevelBundle {
|
||||||
public function get(id:PackId):LevelPack;
|
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ import haxework.color.Color;
|
|||||||
import ru.m.tankz.control.Controller;
|
import ru.m.tankz.control.Controller;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
typedef CompleteRule = {
|
||||||
|
@:optional var team:TeamId;
|
||||||
|
}
|
||||||
|
|
||||||
typedef GameConfig = {
|
typedef GameConfig = {
|
||||||
var levels: Int;
|
var levels: Int;
|
||||||
var friendlyFire:Bool;
|
var friendlyFire:Bool;
|
||||||
|
var complete:Array<CompleteRule>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SpawnPoint = {
|
typedef SpawnPoint = {
|
||||||
@@ -18,26 +23,18 @@ typedef SpawnPoint = {
|
|||||||
var direction:String;
|
var direction:String;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef CellSize = {
|
|
||||||
var width:Float;
|
|
||||||
var height:Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef GridSize = {
|
|
||||||
var width:Int;
|
|
||||||
var height:Int;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef MapConfig = {
|
typedef MapConfig = {
|
||||||
var cell:CellSize;
|
var cellWidth:Float;
|
||||||
var grid:GridSize;
|
var cellHeight:Float;
|
||||||
|
var gridWidth:Int;
|
||||||
|
var gridHeight:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BrickConfig = {
|
typedef BrickConfig = {
|
||||||
var type:BrickType;
|
var type:BrickType;
|
||||||
var index:Int;
|
var index:Int;
|
||||||
var layer:Int;
|
var layer:Int;
|
||||||
var armor:Float;
|
var armor:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BulletConfig = {
|
typedef BulletConfig = {
|
||||||
@@ -58,13 +55,13 @@ typedef TankConfig = {
|
|||||||
@:optinal var hits:Int;
|
@:optinal var hits:Int;
|
||||||
@:optinal var upgrade:TankType;
|
@:optinal var upgrade:TankType;
|
||||||
@:optinal var downgrade:TankType;
|
@:optinal var downgrade:TankType;
|
||||||
@:optinal var score:Null<Int>;
|
@:optinal var score:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BonusConfig = {
|
typedef BonusConfig = {
|
||||||
var type:BonusType;
|
var type:BonusType;
|
||||||
@:optional var duration:Null<Int>;
|
@:optional var duration:Int;
|
||||||
@:optinal var score:Null<Int>;
|
@:optinal var score:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TankSpawn = {
|
typedef TankSpawn = {
|
||||||
@@ -83,7 +80,7 @@ typedef PlayerConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef EagleConfig = {
|
typedef EagleConfig = {
|
||||||
@:optional var score:Null<Int>;
|
@:optional var score:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TeamConfig = {
|
typedef TeamConfig = {
|
||||||
@@ -102,24 +99,31 @@ typedef GamePreset = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef LevelConfig = {
|
typedef LevelConfig = {
|
||||||
@:optional var packId:PackId;
|
|
||||||
@:optional var id:LevelId;
|
@:optional var id:LevelId;
|
||||||
var data:Array<BrickIndex>;
|
var data:Array<BrickConfig>;
|
||||||
@:optional var name:String;
|
@:optional var name:String;
|
||||||
@:optional var points:Array<SpawnPoint>;
|
@:optional var points:Array<SpawnPoint>;
|
||||||
@:optional var size:{width:Int, height:Int};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef LevelPack = {
|
typedef PlayerControl = {
|
||||||
var id:PackId;
|
var playerId:PlayerId;
|
||||||
var data:Array<LevelConfig>;
|
var control:String;
|
||||||
|
@:optional var color:Null<Int>;
|
||||||
|
@:optional var name:String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef ControlPreset = {
|
||||||
|
var id:Int;
|
||||||
|
var name:String;
|
||||||
|
var values:Array<PlayerControl>;
|
||||||
|
};
|
||||||
|
|
||||||
typedef ConfigSource = {
|
typedef ConfigSource = {
|
||||||
var game:GameConfig;
|
var game:GameConfig;
|
||||||
var map: MapConfig;
|
var map: MapConfig;
|
||||||
var bricks: Array<BrickConfig>;
|
var bricks: Array<BrickConfig>;
|
||||||
var presets: Array<GamePreset>;
|
var presets: Array<GamePreset>;
|
||||||
|
var controls: Array<ControlPreset>;
|
||||||
var points: Array<SpawnPoint>;
|
var points: Array<SpawnPoint>;
|
||||||
var tanks: Array<TankConfig>;
|
var tanks: Array<TankConfig>;
|
||||||
var bonuses: Array<BonusConfig>;
|
var bonuses: Array<BonusConfig>;
|
||||||
@@ -132,8 +136,11 @@ class Config {
|
|||||||
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>;
|
||||||
public var presets(default, null):Array<GamePreset>;
|
public var presets(default, null):Array<GamePreset>;
|
||||||
|
public var controls(default, null):Array<ControlPreset>;
|
||||||
public var points(default, null):Array<SpawnPoint>;
|
public var points(default, null):Array<SpawnPoint>;
|
||||||
public var bonuses(default, null):Array<BonusConfig>;
|
public var bonuses(default, null):Array<BonusConfig>;
|
||||||
|
public var mapWidth(get, null):Float;
|
||||||
|
public var mapHeight(get, null):Float;
|
||||||
|
|
||||||
private var brickMap:Map<BrickType, BrickConfig>;
|
private var brickMap:Map<BrickType, BrickConfig>;
|
||||||
private var brickMapByIndex:Map<Int, BrickConfig>;
|
private var brickMapByIndex:Map<Int, BrickConfig>;
|
||||||
@@ -144,7 +151,7 @@ class Config {
|
|||||||
private var playersMap:Map<String, PlayerConfig>;
|
private var playersMap:Map<String, PlayerConfig>;
|
||||||
|
|
||||||
public static function fromSource(type:GameType, source:ConfigSource):Config {
|
public static function fromSource(type:GameType, source:ConfigSource):Config {
|
||||||
return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses);
|
return new Config(type, source.game, source.map, source.bricks, source.presets, source.controls, source.points, source.tanks, source.bonuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function new(
|
public function new(
|
||||||
@@ -153,6 +160,7 @@ class Config {
|
|||||||
map:MapConfig,
|
map:MapConfig,
|
||||||
bricks:Array<BrickConfig>,
|
bricks:Array<BrickConfig>,
|
||||||
presets:Array<GamePreset>,
|
presets:Array<GamePreset>,
|
||||||
|
controls:Array<ControlPreset>,
|
||||||
points:Array<SpawnPoint>,
|
points:Array<SpawnPoint>,
|
||||||
tanks:Array<TankConfig>,
|
tanks:Array<TankConfig>,
|
||||||
bonuses:Array<BonusConfig>
|
bonuses:Array<BonusConfig>
|
||||||
@@ -162,6 +170,7 @@ class Config {
|
|||||||
this.map = map;
|
this.map = map;
|
||||||
this.bricks = bricks;
|
this.bricks = bricks;
|
||||||
this.presets = presets;
|
this.presets = presets;
|
||||||
|
this.controls = controls;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.tanks = tanks;
|
this.tanks = tanks;
|
||||||
this.bonuses = bonuses;
|
this.bonuses = bonuses;
|
||||||
@@ -199,6 +208,14 @@ class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_mapWidth():Float {
|
||||||
|
return map.cellWidth * map.gridWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_mapHeight():Float {
|
||||||
|
return map.cellHeight * map.gridHeight;
|
||||||
|
}
|
||||||
|
|
||||||
public function getBrick(type:BrickType):BrickConfig {
|
public function getBrick(type:BrickType):BrickConfig {
|
||||||
return brickMap.get(type);
|
return brickMap.get(type);
|
||||||
}
|
}
|
||||||
@@ -249,6 +266,10 @@ class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isHuman(playerId:PlayerId) {
|
public function isHuman(playerId:PlayerId) {
|
||||||
return ControllerParser.fromString(getPlayer(playerId).control).match(HUMAN(_));
|
var controller:Controller = AController.fromString(getPlayer(playerId).control);
|
||||||
|
return switch controller {
|
||||||
|
case HUMAN(_): true;
|
||||||
|
case _: false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ enum TankAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Control {
|
class Control {
|
||||||
|
public var type:String;
|
||||||
public var playerId(default, null):PlayerId;
|
public var playerId(default, null):PlayerId;
|
||||||
public var tankId(default, default):Int;
|
public var tankId(default, default):Int;
|
||||||
private var handler:IGame;
|
private var handler:IGame;
|
||||||
|
|||||||
@@ -6,23 +6,21 @@ enum Controller {
|
|||||||
BOT(type:String);
|
BOT(type:String);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ControllerParser {
|
abstract AController(Controller) {
|
||||||
|
|
||||||
public static function fromString(value:String):Controller {
|
public inline function new(value:Controller) {
|
||||||
return switch value {
|
this = value;
|
||||||
case null: NONE;
|
|
||||||
case x: switch x.split("-") {
|
|
||||||
case ["human", index]: HUMAN(Std.parseInt(index));
|
|
||||||
case ["bot", type]: BOT(type);
|
|
||||||
case _: NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function defaultName(controller:Controller):String {
|
@:from public static function fromString(value:String):AController {
|
||||||
return switch controller {
|
return new AController(switch value.split("-") {
|
||||||
case HUMAN(index): 'Player ${index + 1}';
|
case ["human", index]: HUMAN(Std.parseInt(index));
|
||||||
case BOT(_) | NONE: null;
|
case ["bot", type]: BOT(type);
|
||||||
}
|
case _: NONE;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@:to public inline function toController():Controller {
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import haxework.color.Color;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
typedef PlayerControl = {
|
|
||||||
var playerId:PlayerId;
|
|
||||||
var controller:Controller;
|
|
||||||
@:optional var color:Color;
|
|
||||||
@:optional var name:String;
|
|
||||||
}
|
|
||||||
@@ -21,9 +21,9 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
|
|
||||||
public var allEntities(default, null):Map<Int, Entity>;
|
public var allEntities(default, null):Map<Int, Entity>;
|
||||||
|
|
||||||
public function new(config:Config, size:GridSize = null) {
|
public function new(config:Config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
map = new LevelMap(config.map, size);
|
map = new LevelMap(config.map);
|
||||||
allEntities = new Map();
|
allEntities = new Map();
|
||||||
entities = new Map();
|
entities = new Map();
|
||||||
ticker = new Ticker();
|
ticker = new Ticker();
|
||||||
@@ -112,7 +112,6 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (withCollision != null) break;
|
|
||||||
|
|
||||||
for (other in entities.iterator()) {
|
for (other in entities.iterator()) {
|
||||||
if (other != ent && other != null) {
|
if (other != ent && other != null) {
|
||||||
@@ -121,6 +120,7 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withCollision != null) break;
|
if (withCollision != null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.tankz.engine;
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
typedef Action = {
|
typedef Action = {
|
||||||
var id:Int;
|
|
||||||
var time:Int;
|
var time:Int;
|
||||||
var action:Void->Void;
|
var action:Void->Void;
|
||||||
}
|
}
|
||||||
@@ -13,7 +12,6 @@ class Ticker implements ITicker {
|
|||||||
private var passed:Int;
|
private var passed:Int;
|
||||||
private var last_tick:Int;
|
private var last_tick:Int;
|
||||||
private var actions:Array<Action>;
|
private var actions:Array<Action>;
|
||||||
private var actionId = 0;
|
|
||||||
|
|
||||||
private static var TIME = Timer.stamp();
|
private static var TIME = Timer.stamp();
|
||||||
|
|
||||||
@@ -60,23 +58,17 @@ class Ticker implements ITicker {
|
|||||||
var action = it.next();
|
var action = it.next();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (action != null && time >= action.time) {
|
while (action != null && time >= action.time) {
|
||||||
|
action.action();
|
||||||
i++;
|
i++;
|
||||||
action = it.next();
|
action = it.next();
|
||||||
}
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
var timeActions = actions.slice(0, i);
|
|
||||||
actions = actions.slice(i);
|
actions = actions.slice(i);
|
||||||
for (action in timeActions) {
|
|
||||||
//L.d("Ticker", 'action: ${action.id} ${action.time} on ${time}');
|
|
||||||
action.action();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emit(fun:Void->Void, delay:Int):Void {
|
public function emit(action:Void->Void, delay:Int):Void {
|
||||||
var action:Action = {action:fun, time:time+delay, id:++actionId};
|
actions.push({action:action, time:time+delay});
|
||||||
//L.d("Ticker", 'emit: ${action.id} ${action.time}');
|
|
||||||
actions.push(action);
|
|
||||||
actions.sort(function(a, b) return a.time - b.time);
|
actions.sort(function(a, b) return a.time - b.time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {
|
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {
|
||||||
return new Rectangle(
|
return new Rectangle(
|
||||||
(point.x + 1) * config.map.cell.width - width / 2,
|
(point.x + 1) * config.map.cellWidth - width / 2,
|
||||||
(point.y + 1) * config.map.cell.height - height / 2,
|
(point.y + 1) * config.map.cellHeight - height / 2,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
Direction.fromString(point.direction)
|
Direction.fromString(point.direction)
|
||||||
@@ -39,7 +39,7 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildEagle(point:EntityPoint, teamId:TeamId):Eagle {
|
public function buildEagle(point:EntityPoint, teamId:TeamId):Eagle {
|
||||||
var eageleConfig = config.getTeam(teamId).eagle;
|
var eageleConfig = config.getTeam(teamId).eagle;
|
||||||
var eagle = new Eagle(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), teamId, eageleConfig);
|
var eagle = new Eagle(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), teamId, eageleConfig);
|
||||||
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
||||||
return eagle;
|
return eagle;
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildBonus(point:EntityPoint, type:BonusType):Bonus {
|
public function buildBonus(point:EntityPoint, type:BonusType):Bonus {
|
||||||
var bonusConfig = config.getBonus(type);
|
var bonusConfig = config.getBonus(type);
|
||||||
var bonus = new Bonus(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), bonusConfig);
|
var bonus = new Bonus(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), bonusConfig);
|
||||||
return bonus;
|
return bonus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.geom.Position;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.control.Controller;
|
import ru.m.tankz.control.Controller;
|
||||||
import ru.m.tankz.control.IControlFactory;
|
import ru.m.tankz.control.IControlFactory;
|
||||||
import ru.m.tankz.control.NoneControlFactory;
|
import ru.m.tankz.control.NoneControlFactory;
|
||||||
import ru.m.tankz.control.PlayerControl;
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.engine.IEngine;
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
@@ -23,16 +25,17 @@ import ru.m.tankz.Type;
|
|||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
public var level(default, null):LevelConfig;
|
|
||||||
public var engine(default, null):IEngine;
|
public var engine(default, null):IEngine;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
public var pause(default, set):Bool;
|
public var pause(default, set):Bool;
|
||||||
public var controls(default, null):Map<String, Control>;
|
|
||||||
|
private var controls:Map<String, Control>;
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
public function new(type:GameType) {
|
public function new(state:GameState) {
|
||||||
this.type = type;
|
this.type = state.type;
|
||||||
|
this.state = state;
|
||||||
this.teams = new Map();
|
this.teams = new Map();
|
||||||
this.config = configBundle.get(type);
|
this.config = configBundle.get(type);
|
||||||
this.controlFactory = new NoneControlFactory();
|
this.controlFactory = new NoneControlFactory();
|
||||||
@@ -51,6 +54,13 @@ import ru.m.tankz.Type;
|
|||||||
|
|
||||||
private function changePause(value:Bool):Void {}
|
private function changePause(value:Bool):Void {}
|
||||||
|
|
||||||
|
private function applyPosition(entity:Entity, position:Position):Void {
|
||||||
|
entity.rect.center = new Point(position.x, position.y);
|
||||||
|
if (position.direction != null) {
|
||||||
|
entity.rect.direction = position.direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public inline function getTeam(teamId:TeamId):Team {
|
public inline function getTeam(teamId:TeamId):Team {
|
||||||
return teams[teamId];
|
return teams[teamId];
|
||||||
}
|
}
|
||||||
@@ -61,11 +71,14 @@ import ru.m.tankz.Type;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(start):
|
case START(state):
|
||||||
onStart(start);
|
this.state = state;
|
||||||
case COMPLETE(result):
|
case COMPLETE(state, winnerId):
|
||||||
this.state = result.state;
|
this.state = state;
|
||||||
this.winner = result.winner;
|
this.winner = winnerId;
|
||||||
|
case SPAWN(EAGLE(id, rect, teamId)):
|
||||||
|
var team = getTeam(teamId);
|
||||||
|
team.eagleId = id;
|
||||||
case SPAWN(TANK(id, rect, playerId, info)):
|
case SPAWN(TANK(id, rect, playerId, info)):
|
||||||
if (controls.exists(playerId)) {
|
if (controls.exists(playerId)) {
|
||||||
var control = controls[playerId];
|
var control = controls[playerId];
|
||||||
@@ -84,11 +97,9 @@ import ru.m.tankz.Type;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onStart(start:Start):Void {
|
public function start():Void {
|
||||||
this.state = start.state;
|
var level:LevelConfig = state.level;
|
||||||
this.level = start.level;
|
var points:Array<SpawnPoint> = level.points != null ? level.points : config.points;
|
||||||
// ToDo: Spawner not in Team?
|
|
||||||
var points:Array<SpawnPoint> = level != null && level.points != null ? level.points : config.points;
|
|
||||||
for (teamConfig in state.preset.teams) {
|
for (teamConfig in state.preset.teams) {
|
||||||
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
||||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||||
@@ -100,7 +111,6 @@ import ru.m.tankz.Type;
|
|||||||
}
|
}
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
for (player in team.players.iterator()) {
|
for (player in team.players.iterator()) {
|
||||||
var controller = ControllerParser.fromString(player.config.control);
|
|
||||||
var playerControl = controlsById.get(player.id);
|
var playerControl = controlsById.get(player.id);
|
||||||
if (playerControl != null) {
|
if (playerControl != null) {
|
||||||
if (playerControl.color != null) {
|
if (playerControl.color != null) {
|
||||||
@@ -109,11 +119,9 @@ import ru.m.tankz.Type;
|
|||||||
if (playerControl.name != null) {
|
if (playerControl.name != null) {
|
||||||
player.state.name = playerControl.name;
|
player.state.name = playerControl.name;
|
||||||
}
|
}
|
||||||
if (playerControl.controller != null && !playerControl.controller.match(NONE)) {
|
|
||||||
controller = playerControl.controller;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var control = controlFactory.build(player.id, controller);
|
var controlType:Controller = AController.fromString(playerControl != null ? playerControl.control : player.config.control);
|
||||||
|
var control = controlFactory.build(player.id, controlType);
|
||||||
if (control != null) {
|
if (control != null) {
|
||||||
controls[player.id] = control;
|
controls[player.id] = control;
|
||||||
control.bind(this, engine);
|
control.bind(this, engine);
|
||||||
@@ -125,9 +133,6 @@ import ru.m.tankz.Type;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start():Void {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
for (control in controls) {
|
for (control in controls) {
|
||||||
control.dispose();
|
control.dispose();
|
||||||
|
|||||||
@@ -3,21 +3,9 @@ package ru.m.tankz.game;
|
|||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import ru.m.geom.Position;
|
import ru.m.geom.Position;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.config.Config;
|
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
typedef Start = {
|
|
||||||
var state:GameState;
|
|
||||||
var level:LevelConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef Result = {
|
|
||||||
var state:GameState;
|
|
||||||
var level:LevelConfig;
|
|
||||||
var winner:TeamId;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef TankInfo = {
|
typedef TankInfo = {
|
||||||
var type:TankType;
|
var type:TankType;
|
||||||
var hits:Int;
|
var hits:Int;
|
||||||
@@ -44,8 +32,8 @@ enum SpawnEvent {
|
|||||||
|
|
||||||
typedef Shot = {
|
typedef Shot = {
|
||||||
var tankId:Int;
|
var tankId:Int;
|
||||||
@:optional var bulletId:Null<Int>;
|
@:optional var bulletId:Int;
|
||||||
@:optional var score:Null<Int>;
|
@:optional var score:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HitEvent {
|
enum HitEvent {
|
||||||
@@ -85,13 +73,13 @@ enum ChangeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GameEvent {
|
enum GameEvent {
|
||||||
START(start:Start);
|
START(state:GameState);
|
||||||
SPAWN(event:SpawnEvent);
|
SPAWN(event:SpawnEvent);
|
||||||
MOVE(event:MoveEvent);
|
MOVE(event:MoveEvent);
|
||||||
STOP(event:StopEvent);
|
STOP(event:StopEvent);
|
||||||
HIT(event:HitEvent);
|
HIT(event:HitEvent);
|
||||||
DESTROY(event:DestroyEvent);
|
DESTROY(event:DestroyEvent);
|
||||||
CHANGE(event:ChangeEvent);
|
CHANGE(event:ChangeEvent);
|
||||||
COMPLETE(result:Result);
|
COMPLETE(state:GameState, winnerId:TeamId);
|
||||||
ACTION(tankId:Int, action:TankAction);
|
ACTION(tankId:Int, action:TankAction);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,13 @@ typedef LevelProgress = {
|
|||||||
var presets:Map<Int, LevelResult>;
|
var presets:Map<Int, LevelResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PackProgress {
|
class GameProgress {
|
||||||
|
|
||||||
public var id(default, null):PackId;
|
|
||||||
|
|
||||||
|
public var type(default, null):GameType;
|
||||||
private var completed(default, null):Map<Int, LevelProgress>;
|
private var completed(default, null):Map<Int, LevelProgress>;
|
||||||
|
|
||||||
public function new(id:PackId) {
|
public function new(type:GameType) {
|
||||||
this.id = id;
|
this.type = type;
|
||||||
this.completed = new Map();
|
this.completed = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ class PackProgress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isPresetAvailable(levelId:LevelId, presetId:PresetId):Bool {
|
public function isPresetAvailable(levelId:LevelId, presetId:PresetId):Bool {
|
||||||
return isLevelAvailable(levelId) && (presetId == 0 || (completed.exists(levelId) && completed.get(levelId).presets.get(presetId - 1) != null));
|
return presetId == 0 || completed.exists(levelId) && completed.get(levelId).presets.get(presetId - 1) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPresetCompleted(levelId:LevelId, presetId:PresetId):Bool {
|
public function isPresetCompleted(levelId:LevelId, presetId:PresetId):Bool {
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user