Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d5148e0a5 | |||
| 262221d969 | |||
| 9eccb263c0 | |||
| ba90b90cd3 | |||
| 94340bddb1 | |||
| 3361d252ee | |||
| 637772f2dd | |||
| f703c76c21 | |||
| 5fe307a218 | |||
| 670a11d6ba | |||
| 1ec1c3baae | |||
| 24f5b0c218 | |||
| b7bc1d244f | |||
| fbc9238d2f | |||
| eb7c311bb6 | |||
| 9640414ba4 | |||
| bc95ca03e2 | |||
| d0ebf05f1c | |||
| 91dd84a437 | |||
| 1b36016a1a | |||
| db0adbac30 | |||
| 948648b313 | |||
| 73822dc95a | |||
| 282bc68734 | |||
| 2ff374abb6 | |||
| f999c66fea | |||
| 2b3f368e0f | |||
| c0ab953115 | |||
| e39de4467d | |||
| 4c3f1ca0fc | |||
| 7fa5a4e048 | |||
| dc1279f636 | |||
| 5798fa9db7 | |||
| c534cf20fd | |||
| 38e14c9269 | |||
| a66b72ba22 | |||
| 2c42d993ca | |||
| a49d673f25 | |||
| ee5de9f3db | |||
| 94b3a94cbb | |||
| caab6ba3a3 | |||
| 7f70c49b87 | |||
| 8f50da64c2 | |||
| 982ca09a23 | |||
| dbf30decae | |||
| abd1b834d7 | |||
| 6ad9076987 | |||
| 78bbf5264e | |||
| 4c8ae66624 | |||
| 5a3d5b974e | |||
| fb9a28c126 | |||
| 7115ea8ac2 |
29
CHANGELOG.md
Normal file
29
CHANGELOG.md
Normal file
@@ -0,0 +1,29 @@
|
||||
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,73 +1,11 @@
|
||||
* build
|
||||
* gulp 100%
|
||||
* linux 100%
|
||||
* deb-package 100%
|
||||
* windows 0%
|
||||
* exe-package 0% (inno setup)
|
||||
|
||||
* deploy
|
||||
* capistrano 100%
|
||||
|
||||
* 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%
|
||||
* **shovel** bonus with armor bricks
|
||||
* bonuses in dota/death mod
|
||||
* tanks and bullets speed balancing
|
||||
* result frame update (next game select, only human player info)
|
||||
* network game series
|
||||
* map packs (create in editor, import in game, save imported in local storage)
|
||||
* update bots
|
||||
* improve bonuses system
|
||||
* screen gamepad on mobiles
|
||||
* resize render on mobiles
|
||||
* save state in classic game
|
||||
|
||||
22
gulpfile.js
22
gulpfile.js
@@ -1,4 +1,6 @@
|
||||
const gulp = require('gulp');
|
||||
const zip = require('gulp-zip');
|
||||
const foreach = require('gulp-foreach');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const Config = require('./config.json');
|
||||
const packageInfo = require('./package.json');
|
||||
@@ -25,6 +27,19 @@ 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:
|
||||
* windows target
|
||||
@@ -46,7 +61,11 @@ const config = new Project.Config({
|
||||
'src-gen/haxe',
|
||||
],
|
||||
assets: [
|
||||
'src/common/resources'
|
||||
'src/common/resources',
|
||||
'target/levels'
|
||||
],
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||
@@ -141,6 +160,7 @@ const server = new Project(
|
||||
*/
|
||||
module.exports.default = gulp.series(
|
||||
exports.clean,
|
||||
exports.levels,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:flash:html'],
|
||||
module.exports['client:html5:build'],
|
||||
|
||||
2386
package-lock.json
generated
2386
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,15 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.13.0",
|
||||
"version": "0.16.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "^0.0.19",
|
||||
"gulp-foreach": "^0.1.0",
|
||||
"gulp-haxetool": "0.0.20",
|
||||
"gulp-zip": "^5.0.0",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"protoFiles": [
|
||||
"src/common/proto/core.proto",
|
||||
"src/common/proto/game.proto",
|
||||
"src/common/proto/room.proto",
|
||||
"src/common/proto/pack.proto"
|
||||
],
|
||||
"cleanOut": true,
|
||||
|
||||
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
enum DeviceAction {
|
||||
DIRECTION(direction:Direction);
|
||||
KEY(code:Int);
|
||||
}
|
||||
7
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
7
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package ru.m.control;
|
||||
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
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;
|
||||
}
|
||||
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
@@ -0,0 +1,62 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.m.display;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
class DisplayObjectContainerExtender {
|
||||
|
||||
public static function childrenIterator():Iterator<DisplayObject> {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||
if (self.contains(child)) {
|
||||
return self.removeChild(child);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
||||
throw "Not implemented";
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,35 @@ package ru.m.skin;
|
||||
|
||||
import format.SVG;
|
||||
import haxework.color.Color;
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.skin.ISkin;
|
||||
|
||||
class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
using StringTools;
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
private var svg:String;
|
||||
private var color:Color;
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
|
||||
public function new(svg:String, color:Color) {
|
||||
public function new(?svg:String, ?color:Color) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
init();
|
||||
}
|
||||
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||
}
|
||||
|
||||
private function init():Void {
|
||||
svgs = new Map<ButtonState, SVG>();
|
||||
svgs.set(ButtonState.UP, buildSVG(color));
|
||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||
svgs.set(ButtonState.DISABLED, buildSVG(ColorUtil.grey(color)));
|
||||
svgs = new Map();
|
||||
svgs.set(UP, buildSVG(color));
|
||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
@@ -37,7 +39,8 @@ class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5));
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
// ToDo: padding
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
|
||||
126
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
126
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
@@ -0,0 +1,126 @@
|
||||
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,7 +26,6 @@ class Client {
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
Style.register();
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.launch();
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import haxework.view.theme.ITheme;
|
||||
import flash.Lib;
|
||||
import haxework.animate.FadeAnimate;
|
||||
import haxework.animate.UnFadeAnimate;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.resources.Resources;
|
||||
import haxework.view.popup.PopupManager;
|
||||
import lime.ui.Gamepad;
|
||||
import lime.ui.Joystick;
|
||||
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.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
@@ -15,23 +23,25 @@ import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.MultiplayerStorage;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
class Init {
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
@:provide static var resources:IResources;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var settingsStorage:SettingsStorage;
|
||||
@:provide static var multiplayerStorage:MultiplayerStorage;
|
||||
@:provide static var multiplayerStorage:NetworkStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var networkManager:NetworkManager;
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private static function buildConnection():IConnection<Request, Response> {
|
||||
var host:String = CompilationOption.get("host");
|
||||
@@ -47,11 +57,12 @@ class Init {
|
||||
}
|
||||
|
||||
public static function init():Void {
|
||||
theme = new AppTheme();
|
||||
resources = new Resources();
|
||||
levelBundle = new LevelBundle();
|
||||
configBundle = new ConfigBundle();
|
||||
settingsStorage = new SettingsStorage();
|
||||
multiplayerStorage = new MultiplayerStorage();
|
||||
multiplayerStorage = new NetworkStorage();
|
||||
gameStorage = new GameStorage();
|
||||
recordStorage = new RecordStorage();
|
||||
soundManager = new SoundManager();
|
||||
@@ -62,5 +73,22 @@ class Init {
|
||||
|
||||
connection = buildConnection();
|
||||
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,7 +5,8 @@ import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.Lib;
|
||||
import haxework.view.core.Size;
|
||||
import haxework.view.geometry.Size;
|
||||
import ru.m.tankz.AppTheme;
|
||||
|
||||
class Progress extends Sprite {
|
||||
|
||||
@@ -105,10 +106,10 @@ class Preloader extends Sprite {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
Lib.current.stage.color = Style.lightColor;
|
||||
Lib.current.stage.color = AppTheme.COLORS.light;
|
||||
progress = new Progress();
|
||||
progress.color = Style.darkColor;
|
||||
progress.backColor = Style.lightColor;
|
||||
progress.color = AppTheme.COLORS.dark;
|
||||
progress.backColor = AppTheme.COLORS.light;
|
||||
progress.size = [200, 200];
|
||||
addChild(progress);
|
||||
onResize(null);
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
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 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 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(ColorUtil.multiply(lightColor, 1.5), 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(ColorUtil.multiply(lightColor, 1.5), 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),
|
||||
]);
|
||||
|
||||
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 {
|
||||
if (!_cache.exists(type)) {
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
}
|
||||
return _cache.get(type);
|
||||
|
||||
@@ -7,17 +7,25 @@ import ru.m.tankz.util.LevelUtil;
|
||||
|
||||
class LevelBundle implements ILevelBundle {
|
||||
|
||||
private var cache:Map<String, LevelConfig> = new Map();
|
||||
private var _cache:Map<String, LevelPack> = new Map();
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
||||
var key = '${type}:${levelId}';
|
||||
if (!cache.exists(key)) {
|
||||
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
||||
cache[key] = LevelUtil.loads(config, data);
|
||||
cache[key].id = levelId;
|
||||
private function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('levels/${id}.zip');
|
||||
return {
|
||||
id: id,
|
||||
data: LevelUtil.unpack(bytes).map(function(level) {
|
||||
level.packId = id;
|
||||
return level;
|
||||
}),
|
||||
};
|
||||
}
|
||||
return cache[key];
|
||||
|
||||
public function get(id:PackId):LevelPack {
|
||||
if (!_cache.exists(id)) {
|
||||
_cache.set(id, resolve(id));
|
||||
}
|
||||
return _cache.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
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 Map<Int, TankAction>();
|
||||
for (item in data) {
|
||||
result[item.key] = item.action;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
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,60 +1,85 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import flash.events.FocusEvent;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.Lib;
|
||||
import flash.ui.Keyboard;
|
||||
import haxe.Timer;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.control.DeviceAction;
|
||||
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.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
@:provide var storage:SettingsStorage;
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private var keyBinding:KeyBinding;
|
||||
private var moveQueue:Array<Int>;
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimer:Timer;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
this.keyBinding = storage.getActionConfig(controlIndex).asKeyBinding();
|
||||
moveQueue = new Array<Int>();
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
||||
var config = storage.getBinding(controlIndex);
|
||||
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 = [];
|
||||
}
|
||||
|
||||
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();
|
||||
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 {
|
||||
super.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
override public function stop():Void {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
if (on) {
|
||||
if (moveQueue.indexOf(direction) == -1) {
|
||||
moveQueue.unshift(direction);
|
||||
}
|
||||
} else {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
if (on) {
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(300);
|
||||
shotTimer.run = shot;
|
||||
shot();
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function onKeyUp(event:KeyboardEvent):Void {
|
||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||
case TankAction.MOVE(direction):
|
||||
moveQueue.remove(event.keyCode);
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
} else {
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
case TankAction.STOP:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,17 +90,13 @@ class HumanControl extends Control {
|
||||
|
||||
private function updateMove():Void {
|
||||
if (moveQueue.length == 0) {
|
||||
action(TankAction.STOP);
|
||||
action(STOP);
|
||||
} else {
|
||||
switch (keyBinding.get(moveQueue[0])) {
|
||||
case TankAction.MOVE(direction):
|
||||
action(TankAction.MOVE(direction));
|
||||
case _:
|
||||
}
|
||||
action(MOVE(moveQueue[0]));
|
||||
}
|
||||
}
|
||||
|
||||
private function shot():Void {
|
||||
action(TankAction.SHOT);
|
||||
action(SHOT);
|
||||
}
|
||||
}
|
||||
|
||||
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
@@ -0,0 +1,11 @@
|
||||
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,29 +0,0 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.control.LocalControlFactory;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.record.GameRecorder;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
class LocalGame extends GameRunner {
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
private var recorder:GameRecorder;
|
||||
|
||||
public function new(state:GameState) {
|
||||
super(state);
|
||||
controlFactory = new LocalControlFactory();
|
||||
recorder = new GameRecorder();
|
||||
connect(recorder);
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case GameEvent.COMPLETE(_, _):
|
||||
disconnect(recorder);
|
||||
recorder.onGameEvent(event); //ToDo:
|
||||
recordStorage.save(recorder.record);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import haxe.Unserializer;
|
||||
import ru.m.tankz.control.NetworkControlFactory;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
|
||||
class NetworkGame extends Game {
|
||||
|
||||
private var network:NetworkManager;
|
||||
|
||||
public function new(network:NetworkManager) {
|
||||
super(new GameState(network.game.type, 0, network.game.level));
|
||||
this.network = network;
|
||||
this.controlFactory = new NetworkControlFactory();
|
||||
network.gameEventSignal.connect(onGameEventProto);
|
||||
}
|
||||
|
||||
private function onGameEventProto(game:GameEventResponse):Void {
|
||||
var time = game.time;
|
||||
var eventStr = game.event;
|
||||
var event:GameEvent = Unserializer.run(eventStr);
|
||||
gameEventSignal.emit(event);
|
||||
}
|
||||
|
||||
override public function start():Void {
|
||||
var player = Lambda.find(network.game.players, function(player) return player.user.uuid == network.user.uuid);
|
||||
if (player != null) {
|
||||
state.controls.push({playerId: [player.team, player.index], control: "human-0"});
|
||||
}
|
||||
super.start();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package ru.m.tankz.control;
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalControlFactory extends BaseControlFactory {
|
||||
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
@@ -0,0 +1,41 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import ru.m.tankz.local.LocalControlFactory;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalGame extends GameRunner {
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result): updateProgress(result);
|
||||
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,5 +1,6 @@
|
||||
package ru.m.tankz.control;
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.control;
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class NetworkControlFactory extends BaseControlFactory {
|
||||
@@ -7,4 +9,8 @@ class NetworkControlFactory extends BaseControlFactory {
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new NetworkControl(id, index);
|
||||
}
|
||||
|
||||
override private function buildBot(id:PlayerId, type:String):Control {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
@@ -0,0 +1,54 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import haxe.Unserializer;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.network.NetworkControlFactory;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
class NetworkGame extends Game {
|
||||
|
||||
private var network:NetworkManager;
|
||||
|
||||
public function new(network:NetworkManager) {
|
||||
super(network.room.game.type);
|
||||
this.network = network;
|
||||
this.controlFactory = new NetworkControlFactory();
|
||||
network.gameEventSignal.connect(onGameEventProto);
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
}
|
||||
|
||||
private function onGameEventProto(game:GameEventResponse):Void {
|
||||
var time = game.event.time;
|
||||
var eventStr = game.event.event;
|
||||
var event:GameEvent = Unserializer.run(eventStr);
|
||||
gameEventSignal.emit(event);
|
||||
}
|
||||
|
||||
private function onConnectionState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
network.joinGame(network.room.game.id);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
override private function onStart(start:Start):Void {
|
||||
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||
if (slot != null) {
|
||||
start.state.controls.push({playerId: [slot.slot.team, slot.slot.index], controller: HUMAN(0)});
|
||||
}
|
||||
super.onStart(start);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,28 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.proto.game.GameEventProto;
|
||||
import ru.m.tankz.proto.room.SlotProto;
|
||||
import ru.m.tankz.proto.room.SlotRequest;
|
||||
import haxe.Serializer;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
import ru.m.tankz.proto.game.GameChangeProto;
|
||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||
import ru.m.tankz.proto.pack.LoginRequest;
|
||||
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||
import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.tankz.proto.pack.StartGameRequest;
|
||||
import ru.m.tankz.storage.MultiplayerStorage;
|
||||
import ru.m.tankz.proto.room.CreateRequest;
|
||||
import ru.m.tankz.proto.room.JoinRequest;
|
||||
import ru.m.tankz.proto.room.LeaveRequest;
|
||||
import ru.m.tankz.proto.room.RoomListRequest;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
import ru.m.tankz.proto.room.RoomRequest;
|
||||
import ru.m.tankz.proto.room.StartRequest;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
|
||||
typedef ClientConnection = IConnection<Request, Response>;
|
||||
|
||||
@@ -35,31 +38,30 @@ enum ConnectionState {
|
||||
class NetworkManager {
|
||||
|
||||
public var state(default, null):ConnectionState;
|
||||
public var game(default, null):GameProto;
|
||||
public var room(default, null):RoomProto;
|
||||
public var user(default, null):UserProto;
|
||||
|
||||
public var stateSignal:Signal<ConnectionState>;
|
||||
public var listGameSignal:Signal<Array<GameProto>>;
|
||||
public var gameSignal:Signal<GameProto>;
|
||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
||||
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||
public var roomSignal:Signal<RoomProto>;
|
||||
public var gameEventSignal:Signal<GameEventResponse>;
|
||||
|
||||
@:provide private var connection:ClientConnection;
|
||||
@:provide private var storage:MultiplayerStorage;
|
||||
@:provide private var storage:NetworkStorage;
|
||||
|
||||
private var reconnectTimer:Timer;
|
||||
private var reconnectDelay:Int;
|
||||
|
||||
public function new() {
|
||||
reconnectDelay = 500;
|
||||
stateSignal = new Signal();
|
||||
listGameSignal = new Signal();
|
||||
gameSignal = new Signal();
|
||||
gameUpdateSignal = new Signal();
|
||||
listRoomSignal = new Signal();
|
||||
roomSignal = new Signal();
|
||||
gameEventSignal = new Signal();
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
var user = storage.user;
|
||||
if (user != null) {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
connect();
|
||||
}
|
||||
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
@@ -68,61 +70,83 @@ class NetworkManager {
|
||||
}
|
||||
|
||||
public function login(name:String, uuid:String = null):Void {
|
||||
updateState(CONNECT);
|
||||
connection.connect().then(function(c:ClientConnection) {
|
||||
updateState(LOGIN);
|
||||
c.send(new Request().setLogin(
|
||||
connection.send(new Request().setLogin(
|
||||
new LoginRequest()
|
||||
.setUuid(uuid)
|
||||
.setName(name)
|
||||
));
|
||||
}).catchError(function(error) {
|
||||
updateState(ERROR(error));
|
||||
});
|
||||
}
|
||||
|
||||
public function logout():Void {
|
||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||
}
|
||||
|
||||
public function listGame():Void {
|
||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
||||
public function listGame(subscribe:Bool):Void {
|
||||
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||
}
|
||||
|
||||
public function createGame(type:String, level:Int):Void {
|
||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type).setLevel(level)));
|
||||
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type).setLevel(level))));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int):Void {
|
||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
||||
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||
}
|
||||
|
||||
public function selectSlot(slot:SlotProto):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
||||
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||
}
|
||||
|
||||
public function startGame():Void {
|
||||
connection.send(new Request().setStartGame(new StartGameRequest()));
|
||||
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||
}
|
||||
|
||||
public function action(tankId:Int, action:TankAction):Void {
|
||||
connection.send(new Request().setGameEvent(new GameEventRequest().setTime(0).setEvent(
|
||||
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
|
||||
new GameEventProto().setTime(0).setEvent(
|
||||
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||
)));
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
private function connect():Void {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.stop();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
reconnectTimer = null;
|
||||
updateState(CONNECT);
|
||||
connection.connect().catchError(function(error) {});
|
||||
}
|
||||
|
||||
private function reconnect():Void {
|
||||
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||
if (reconnectTimer == null) {
|
||||
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
updateState(switch event {
|
||||
case CONNECTED:
|
||||
L.d('Network', '$event');
|
||||
CONNECTED;
|
||||
case DISCONNECTED:
|
||||
L.d('Network', '$event');
|
||||
OFFLINE;
|
||||
case ERROR(error):
|
||||
L.e('Network', '$error', error);
|
||||
ERROR(error);
|
||||
case CONNECTED: CONNECTED;
|
||||
case DISCONNECTED: OFFLINE;
|
||||
case ERROR(error): ERROR(error);
|
||||
});
|
||||
switch event {
|
||||
case CONNECTED:
|
||||
reconnectDelay = 500;
|
||||
var user = storage.user;
|
||||
if (user != null) {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
case DISCONNECTED | ERROR(_):
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private function onResponse(packet:Response):Void {
|
||||
@@ -137,25 +161,11 @@ class NetworkManager {
|
||||
} else if (packet.hasLogout()) {
|
||||
storage.user = null;
|
||||
updateState(CONNECTED);
|
||||
} else if (packet.hasListGame()) {
|
||||
listGameSignal.emit(packet.listGame.games);
|
||||
} else if (packet.hasCreateGame()) {
|
||||
game = packet.createGame.game;
|
||||
gameSignal.emit(game);
|
||||
} else if (packet.hasJoinGame()) {
|
||||
game = packet.joinGame.game;
|
||||
gameSignal.emit(game);
|
||||
} else if (packet.hasLeaveGame()) {
|
||||
if (packet.leaveGame.user.uuid == user.uuid) {
|
||||
game = null;
|
||||
gameSignal.emit(null);
|
||||
} else {
|
||||
game = packet.leaveGame.game;
|
||||
gameSignal.emit(game);
|
||||
}
|
||||
} else if (packet.hasStartGame()) {
|
||||
game = packet.startGame.game;
|
||||
gameSignal.emit(game);
|
||||
} else if (packet.hasRoomList()) {
|
||||
listRoomSignal.emit(packet.roomList.rooms);
|
||||
} else if (packet.hasRoom()) {
|
||||
room = packet.room.room;
|
||||
roomSignal.emit(room);
|
||||
} else if (packet.hasGameEvent()) {
|
||||
gameEventSignal.emit(packet.gameEvent);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import ru.m.tankz.game.IGame;
|
||||
|
||||
interface IRender extends IView<Dynamic> extends GameListener {
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
public function draw():Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import haxe.Timer;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.SpriteView;
|
||||
import promhx.Promise;
|
||||
import ru.m.animate.Animate;
|
||||
@@ -21,10 +21,15 @@ import ru.m.tankz.render.item.EagleRenderItem;
|
||||
import ru.m.tankz.render.item.IRenderItem;
|
||||
import ru.m.tankz.render.item.TankRenderItem;
|
||||
import ru.m.tankz.Type;
|
||||
using ru.m.display.DisplayObjectContainerExtender;
|
||||
|
||||
class Render extends SpriteView implements IRender {
|
||||
|
||||
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 groundLayer:Sprite;
|
||||
@@ -50,19 +55,34 @@ class Render extends SpriteView implements IRender {
|
||||
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 {
|
||||
return config = value;
|
||||
config = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var width = config.map.cellWidth * config.map.gridWidth;
|
||||
var height = config.map.cellHeight * config.map.gridHeight;
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(0, 0, width, height);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
setContentSize(width, height);
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
@@ -76,7 +96,9 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
||||
while (layer.numChildren > 0) {
|
||||
layer.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
@@ -93,9 +115,10 @@ class Render extends SpriteView implements IRender {
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
case START(start):
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_, _):
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case SPAWN(BRICK(bricks)):
|
||||
drawBackground();
|
||||
@@ -121,6 +144,7 @@ class Render extends SpriteView implements IRender {
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
@@ -183,9 +207,7 @@ class Render extends SpriteView implements IRender {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
if (shot.score != 0) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
@@ -202,18 +224,14 @@ class Render extends SpriteView implements IRender {
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
if (shot.score != 0) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
if (shot.score != 0) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
@@ -236,21 +254,23 @@ class Render extends SpriteView implements IRender {
|
||||
return animate.play().then(function(animate:Animate):Void {
|
||||
// ToDo: clean animates on reset
|
||||
if (upperLayer.contains(animate)) {
|
||||
upperLayer.removeChild(animate);
|
||||
upperLayer.removeChildSafety(animate);
|
||||
}
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private function showScore(point:Point, score:Int):Void {
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.skinId = "text";
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChild(view.content), 1000);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import ru.m.geom.Rectangle;
|
||||
class RenderItem implements IRenderItem {
|
||||
|
||||
public var view(get, null):DisplayObject;
|
||||
public var content(get, null):DisplayObject;
|
||||
|
||||
public var rect(default, null):Rectangle;
|
||||
|
||||
@@ -18,16 +19,26 @@ class RenderItem implements IRenderItem {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
private function get_content():DisplayObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function move(position:Position):Void {
|
||||
view.x = rect.x = position.x;
|
||||
view.y = rect.y = position.y;
|
||||
if (position.direction != null) {
|
||||
rect.direction = position.direction;
|
||||
if (content != null) {
|
||||
content.rotation = rect.direction.angle;
|
||||
content.x = - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
content.y = - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
} else {
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update():Void {}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import haxework.view.theme.ITheme;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.BitmapData;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import haxework.color.Color;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
@@ -16,11 +21,15 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
public var bonus(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
|
||||
private var container:Sprite;
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var nameView:TextField;
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
@@ -29,13 +38,29 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function buildNameView():TextField {
|
||||
var result = new BitmapTextField();
|
||||
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
||||
result.embedFonts = theme.font.embed;
|
||||
result.autoSize = TextFieldAutoSize.LEFT;
|
||||
result.shadowColor = 0x000000;
|
||||
result.stroke = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
override private function get_content():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
||||
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
||||
@@ -105,6 +130,16 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
return moves;
|
||||
}
|
||||
|
||||
private function set_name(value:String):String {
|
||||
if (name != value) {
|
||||
name = value;
|
||||
nameView.text = name;
|
||||
nameView.x = (rect.width - nameView.width) / 2;
|
||||
nameView.y = -nameView.height / 2; //(rect.height - nameView.height) / 2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (moves) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.GameProgress;
|
||||
import ru.m.tankz.Type.GameType;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class GameStorage extends SharedObjectStorage {
|
||||
|
||||
@@ -12,11 +12,11 @@ class GameStorage extends SharedObjectStorage {
|
||||
super('game_${VERSION}');
|
||||
}
|
||||
|
||||
public function get(type:GameType):GameProgress {
|
||||
return exists(type) ? read(type) : new GameProgress(type);
|
||||
public function get(id:PackId):PackProgress {
|
||||
return exists(id) ? read(id) : new PackProgress(id);
|
||||
}
|
||||
|
||||
public function set(progress:GameProgress):Void {
|
||||
write(progress.type, progress);
|
||||
public function set(progress:PackProgress):Void {
|
||||
write(progress.id, progress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
|
||||
class MultiplayerStorage extends SharedObjectStorage {
|
||||
class NetworkStorage extends SharedObjectStorage {
|
||||
|
||||
public var user(get, set):User;
|
||||
|
||||
public function new() {
|
||||
super("multiplayer");
|
||||
super("network");
|
||||
}
|
||||
|
||||
private inline function get_user():User {
|
||||
@@ -3,50 +3,64 @@ package ru.m.tankz.storage;
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import haxework.utils.ObjectUtil;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.tankz.control.Control.TankAction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class SettingsStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 3;
|
||||
|
||||
public function new() {
|
||||
super("settings");
|
||||
super('settings_${VERSION}');
|
||||
}
|
||||
|
||||
public function getActionConfig(index:Int):ActionConfig {
|
||||
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
||||
public function getBinding(index:Int):Binding {
|
||||
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||
}
|
||||
|
||||
public function setActionConffig(index:Int, value:ActionConfig) {
|
||||
public function saveBinding(index:Int, value:Binding) {
|
||||
write('action:$index', value);
|
||||
}
|
||||
|
||||
public static function getDefaultActionConfig(index:Int):ActionConfig {
|
||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : empty);
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
||||
}
|
||||
|
||||
private static var defaults:Map<Int, ActionConfig> = [
|
||||
0 => new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
||||
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
||||
]),
|
||||
1 => new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||
]),
|
||||
public static function buildGamepadBinding(id:Int):Binding {
|
||||
var device = GAMEPAD(id);
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||
SHOT => {device: device, action: KEY(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},
|
||||
]);
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
-1 => [
|
||||
MOVE(Direction.TOP) => null,
|
||||
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)},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -4,17 +4,23 @@ import flash.events.KeyboardEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.group.VGroupView;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
|
||||
@:template class ClientView extends FrameSwitcher {
|
||||
@:template class ClientView extends VGroupView {
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var resources:IResources;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var game:IGame;
|
||||
|
||||
public function init():Void {
|
||||
resources.text.put('version', '${Const.VERSION}');
|
||||
switcher = this;
|
||||
switcher = switcherView;
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
@@ -22,11 +28,15 @@ import ru.m.tankz.sound.SoundManager;
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||
switch event.keyCode {
|
||||
case Keyboard.ESCAPE:
|
||||
change(StartFrame.ID);
|
||||
switcher.change(MenuFrame.ID);
|
||||
case Keyboard.M:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case Keyboard.P:
|
||||
if (game != null) {
|
||||
game.pause = !game.pause;
|
||||
}
|
||||
}
|
||||
});
|
||||
change(StartFrame.ID);
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
---
|
||||
$type: haxework.view.frame.FrameSwitcher
|
||||
geometry.size.stretch: true
|
||||
skinId: dark
|
||||
views:
|
||||
- id: start
|
||||
$type: ru.m.tankz.view.StartFrame
|
||||
- id: level
|
||||
$type: ru.m.tankz.view.LevelFrame
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.GameFrame
|
||||
- id: result
|
||||
$type: ru.m.tankz.view.ResultFrame
|
||||
- id: settings
|
||||
$type: ru.m.tankz.view.SettingsFrame
|
||||
- id: record
|
||||
$type: ru.m.tankz.view.RecordFrame
|
||||
- id: game_list
|
||||
$type: ru.m.tankz.view.network.GameListFrame
|
||||
- id: game_room
|
||||
$type: ru.m.tankz.view.network.GameRoomFrame
|
||||
- $type: haxework.view.frame.FrameSwitcher
|
||||
id: switcher
|
||||
geometry.stretch: true
|
||||
style: dark
|
||||
factory:
|
||||
_menu_: {$class: ru.m.tankz.view.MenuFrame}
|
||||
_level_: {$class: ru.m.tankz.view.LevelFrame}
|
||||
_start_: {$class: ru.m.tankz.view.StartFrame}
|
||||
_game_: {$class: ru.m.tankz.view.GameFrame}
|
||||
_result_: {$class: ru.m.tankz.view.ResultFrame}
|
||||
_settings_: {$class: ru.m.tankz.view.SettingsFrame}
|
||||
_record_: {$class: ru.m.tankz.view.RecordFrame}
|
||||
_room_list_: {$class: ru.m.tankz.view.network.RoomListFrame}
|
||||
_room_: {$class: ru.m.tankz.view.network.RoomFrame}
|
||||
|
||||
@@ -1,36 +1,68 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxe.ds.Option;
|
||||
import haxework.view.layout.DefaultLayout;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.VGroupView;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.record.GamePlayer;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.local.LocalGame;
|
||||
import ru.m.tankz.network.NetworkGame;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.view.game.GameView;
|
||||
import ru.m.tankz.view.GamepadView;
|
||||
|
||||
@:template class GameFrame extends VGroupView implements GameListener {
|
||||
@:template class GameFrame extends FrameView<GameInit> implements GameListener {
|
||||
public static inline var ID = "game";
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
@: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 state:GameState;
|
||||
@:provide var record:GameRecord;
|
||||
@:provide("next") var nextState:GameState;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var gameStorage:GameStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
@:provide var game:IGame;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
public function onShow():Void {
|
||||
private var game:IGame;
|
||||
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;
|
||||
soundManager.config = game.config;
|
||||
gameView.render.config = game.config;
|
||||
@@ -53,42 +85,19 @@ import ru.m.tankz.view.game.GameView;
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
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;
|
||||
}
|
||||
case COMPLETE(result):
|
||||
stop();
|
||||
switcher.change(ResultFrame.ID);
|
||||
switcher.change(ResultFrame.ID, result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
override public function onHide():Void {
|
||||
stop();
|
||||
soundManager.stopAll();
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
switcher.change(LevelFrame.ID);
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
---
|
||||
style: container
|
||||
overflow.x: crop
|
||||
overflow.y: crop
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
views:
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.game.GameView
|
||||
# - $type: haxework.view.HGroupView
|
||||
# skinId: panel
|
||||
# views:
|
||||
# - id: close
|
||||
# $type: haxework.view.ButtonView
|
||||
# skinId: button.close
|
||||
# +onPress: $code:close()
|
||||
- id: gamepad
|
||||
$type: ru.m.tankz.view.GamepadView
|
||||
geometry.position: absolute
|
||||
geometry.stretch: true
|
||||
visible: false
|
||||
|
||||
160
src/client/haxe/ru/m/tankz/view/GamepadView.hx
Normal file
160
src/client/haxe/ru/m/tankz/view/GamepadView.hx
Normal file
@@ -0,0 +1,160 @@
|
||||
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,70 +1,61 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.LocalGame;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.popup.LevelPopup;
|
||||
import ru.m.tankz.Type.PackId;
|
||||
|
||||
@:template class LevelFrame extends VGroupView {
|
||||
@:template class LevelFrame extends FrameView<PackId> {
|
||||
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 levels:DataView<LevelId, ButtonView>;
|
||||
@:view var levels:DataView<LevelConfig, ButtonView>;
|
||||
|
||||
@:provide var state:GameState;
|
||||
@:provide var game:IGame;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var levelBundle:ILevelBundle;
|
||||
@:provide var storage:GameStorage;
|
||||
private var pack:LevelPack;
|
||||
private var config(get, never):Config;
|
||||
|
||||
private var levelPopup:LevelPopup;
|
||||
|
||||
public function onShow():Void {
|
||||
header.text = state.type;
|
||||
levels.data = [for (i in 0...state.config.game.levels) i];
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||
state.levelId = level.id;
|
||||
state.presetId = preset.id;
|
||||
state.controls = control.values;
|
||||
game = new LocalGame(state);
|
||||
switcher.change(GameFrame.ID);
|
||||
private function get_config():Config {
|
||||
return configBundle.get(pack.id.type);
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, levelId:LevelId):ButtonView {
|
||||
var progress = storage.get(state.type);
|
||||
override public function onShow(data:PackId):Void {
|
||||
header.text = data.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();
|
||||
result.skinId = "button.level";
|
||||
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(levelId, p.id) ? '*' : '_'].join('');
|
||||
result.text = '${levelId}\n${presetsLine}';
|
||||
result.disabled = !progress.isLevelAvailable(levelId);
|
||||
result.style = "button.level";
|
||||
var presetsLine = [for (p in config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||
result.text = '${level.id}\n${presetsLine}';
|
||||
result.disabled = !progress.isLevelAvailable(level.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLevelSelect(index:Int, levelId:LevelId, view:ButtonView):Void {
|
||||
if (!storage.get(state.type).isLevelAvailable(levelId)) {
|
||||
return;
|
||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||
if (storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||
switcher.change(StartFrame.ID, {
|
||||
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,24 +1,29 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
- id: levels
|
||||
$type: haxework.view.DataView
|
||||
geometry.size.width: 100%
|
||||
$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: $this:levelViewFactory
|
||||
+onItemSelect: $this:onLevelSelect
|
||||
factory: ~levelViewFactory
|
||||
+onItemSelect: ~onLevelSelect
|
||||
geometry.padding: 10
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:switcher.change('start')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
96
src/client/haxe/ru/m/tankz/view/MenuFrame.hx
Normal file
96
src/client/haxe/ru/m/tankz/view/MenuFrame.hx
Normal file
@@ -0,0 +1,96 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
65
src/client/haxe/ru/m/tankz/view/MenuFrame.yaml
Normal file
65
src/client/haxe/ru/m/tankz/view/MenuFrame.yaml
Normal file
@@ -0,0 +1,65 @@
|
||||
---
|
||||
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,32 +1,27 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.list.ListView;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:template class RecordFrame extends VGroupView {
|
||||
@:template class RecordFrame extends FrameView<Dynamic> {
|
||||
|
||||
public static var ID(default, never):String = "record";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
|
||||
@:view var data:VListView<GameRecordInfo>;
|
||||
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var record:GameRecord;
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
override public function onShow(_:Dynamic):Void {
|
||||
var data = Lambda.array(recordStorage);
|
||||
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||
this.data.data = data;
|
||||
}
|
||||
|
||||
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
||||
|
||||
}
|
||||
|
||||
private function close() {
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
geometry.padding: 20
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
- $type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
text: Records
|
||||
- id: data
|
||||
$type: haxework.view.list.VListView
|
||||
factory: $code:function() return new ru.m.tankz.view.common.RecordView()
|
||||
+onItemSelect: $this:onRecordSelect
|
||||
factory: ~function() return new ru.m.tankz.view.common.RecordView()
|
||||
geometry.margin.top: 20
|
||||
geometry.size.stretch: true
|
||||
geometry.stretch: true
|
||||
scroll:
|
||||
$type: haxework.view.list.VScrollBarView
|
||||
skinId: scroll
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:close()
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
@@ -1,53 +1,80 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.form.LabelView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
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.storage.GameStorage;
|
||||
import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
@:template class ResultFrame extends VGroupView {
|
||||
@:template class ResultFrame extends FrameView<Result> {
|
||||
public static var ID(default, never):String = "result";
|
||||
|
||||
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
||||
@:view("next") var nextButton:ButtonView;
|
||||
@:view("level") var levelLabel:LabelView;
|
||||
@:view("next") var nextButton:ButtonView;
|
||||
|
||||
@:provide var frames:FrameSwitcher;
|
||||
@:provide var state:GameState;
|
||||
@:provide("next") var nextState:GameState;
|
||||
@:provide var game:IGame;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||
private var result:Result;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function playerViewFactory(index:Int, player:PlayerState):LifeView {
|
||||
var view = new LifeView();
|
||||
var playerConfig = state.config.getPlayer(player.id);
|
||||
var playerConfig = result.state.config.getPlayer(player.id);
|
||||
var tankType = playerConfig.tanks[0].type;
|
||||
var tankConfig = state.config.getTank(tankType);
|
||||
var tankConfig = result.state.config.getTank(tankType);
|
||||
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||
view.color = state.getPlayerColor(player.id);
|
||||
view.color = result.state.getPlayerColor(player.id);
|
||||
view.life = player.frags;
|
||||
view.score = player.score;
|
||||
return view;
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
resultView.data = Lambda.array(state.players);
|
||||
levelLabel.text = 'Level ${state.levelId}';
|
||||
nextButton.visible = nextState != null;
|
||||
override public function onShow(data:Result):Void {
|
||||
result = data;
|
||||
var players = Lambda.array(result.state.players);
|
||||
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 next() {
|
||||
if (nextState != null) {
|
||||
game = new GameRunner(nextState);
|
||||
frames.change(GameFrame.ID);
|
||||
private function levels():Void {
|
||||
frames.change(LevelFrame.ID, result.level.packId);
|
||||
}
|
||||
|
||||
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() {
|
||||
frames.change(LevelFrame.ID);
|
||||
private function close():Void {
|
||||
frames.change(MenuFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
font.align: center
|
||||
- id: result
|
||||
$type: haxework.view.DataView
|
||||
factory: $this:playerViewFactory
|
||||
$type: haxework.view.data.DataView
|
||||
factory: ~playerViewFactory
|
||||
geometry.height: 100%
|
||||
overflow.y: scroll
|
||||
geometry.margin.top: 20
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
hAlign: right
|
||||
margin: 10
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: close
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:close()
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 100%
|
||||
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.ButtonView
|
||||
skinId: button.next
|
||||
+onPress: $code:next()
|
||||
$type: haxework.view.form.ButtonView
|
||||
text: Next
|
||||
+onPress: ~next()
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.VGroupView;
|
||||
|
||||
@:template class SettingsFrame extends VGroupView {
|
||||
import haxework.view.frame.FrameView;
|
||||
|
||||
@:template class SettingsFrame extends FrameView<Dynamic> {
|
||||
public static var ID(default, never):String = "settings";
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
- $type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
text: Settings
|
||||
- $type: haxework.view.HGroupView
|
||||
layout.margin: 20
|
||||
- $type: haxework.view.group.GroupView
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
overflow.y: scroll
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
vAlign: top
|
||||
margin: 20
|
||||
views:
|
||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||
- id: settings0
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 0
|
||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||
- id: settings1
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 1
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:switcher.change('start')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
@@ -1,76 +1,113 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.Type.GameType;
|
||||
import ru.m.tankz.view.popup.FontPopup;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.common.SlotView;
|
||||
|
||||
@:template class StartFrame extends VGroupView {
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
@:template class StartFrame extends FrameView<Start> {
|
||||
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
@:view var username:LabelView;
|
||||
@:view("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
@:view("network") var networkButton:ButtonView;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
|
||||
@:provide var state:GameState;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
private var progress:PackProgress;
|
||||
|
||||
private var fontPopup:FontPopup;
|
||||
@:view var header:LabelView;
|
||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||
@:view("slots") var slotsView:DataView<PlayerControl, SlotView>;
|
||||
|
||||
public function onShow():Void {
|
||||
onConnectionState(network.state);
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
private var humanIndex:Int = 0;
|
||||
private var humanTotal:Int = 2;
|
||||
|
||||
|
||||
private var start:Start;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
override public function onShow(data:Start):Void {
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
this.progress = storage.get(start.level.packId);
|
||||
header.text = '${start.state.type} - ${start.level.id}. ${start.level.name != null ? start.level.name : "#"}';
|
||||
presetsView.data = start.state.config.presets;
|
||||
slotsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
private function onConnectionState(state:ConnectionState):Void {
|
||||
trace("state", state);
|
||||
setUser(switch state {
|
||||
case ONLINE(user): user;
|
||||
case _: null;
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
private function setUser(value:User):Void {
|
||||
username.text = value == null ? "" : value.name;
|
||||
loginButton.visible = value == null;
|
||||
logoutButton.visible = value != null;
|
||||
networkButton.disabled = value == null;
|
||||
}
|
||||
}
|
||||
controls.sort(function(a, b) return a.playerId.compare(b.playerId));
|
||||
if (controls.length > 0) {
|
||||
controls[0].controller = HUMAN(0);
|
||||
controls[0].name = ControllerParser.defaultName(controls[0].controller);
|
||||
}
|
||||
return controls;
|
||||
}
|
||||
|
||||
private function startGame(type:GameType):Void {
|
||||
state = new GameState(type);
|
||||
switcher.change(LevelFrame.ID);
|
||||
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 login():Void {
|
||||
LoginPopup.instance.show().then(function(user:User):Void {
|
||||
L.d("Login", 'user: $user');
|
||||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
value.controller = controller;
|
||||
value.name = ControllerParser.defaultName(controller);
|
||||
}
|
||||
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
||||
var result = new ButtonView();
|
||||
result.style = 'button${!progress.isPresetCompleted(start.level.id, value.id) ? ".active" : ""}';
|
||||
result.text = value.name;
|
||||
result.disabled = !progress.isPresetAvailable(start.level.id, value.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function choiceFont():Void {
|
||||
if (fontPopup == null) {
|
||||
fontPopup = new FontPopup();
|
||||
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,63 +1,39 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
- id: slots
|
||||
$type: haxework.view.data.DataView
|
||||
geometry.padding: 10
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
layout.hAlign: center
|
||||
overflow.y: scroll
|
||||
factory: ~slotViewFactory
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
# $type: haxework.view.layout.TailLayout
|
||||
margin: 5
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
text: Tank'z
|
||||
skinId: font
|
||||
fontSize: 100
|
||||
geometry.margin.bottom: 30
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('classic')
|
||||
text: Classic
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('dota')
|
||||
text: DotA
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('death')
|
||||
text: DeathMatch
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:switcher.change('record')
|
||||
text: Records
|
||||
- id: network
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:switcher.change('game_list')
|
||||
text: Network
|
||||
disabled: true
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
views:
|
||||
- id: settings
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.settings
|
||||
+onPress: $code:switcher.change('settings')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 100%
|
||||
- id: username
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text
|
||||
geometry.margin.right: 10
|
||||
- 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.LabelView
|
||||
geometry.hAlign: right
|
||||
geometry.vAlign: top
|
||||
geometry.padding: [20, 5]
|
||||
geometry.position: absolute
|
||||
geometry.margin: [0, 20, 20, 0]
|
||||
skinId: text.box
|
||||
text: $r:text:version
|
||||
geometry.width: 50%
|
||||
- id: presets
|
||||
$type: haxework.view.data.DataView
|
||||
factory: ~presetViewFactory
|
||||
+onDataSelect: ~onPresetSelect
|
||||
layout:
|
||||
$type: haxework.view.layout.HorizontalLayout
|
||||
hAlign: center
|
||||
margin: 5
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("level", start.level.packId)
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.ImageView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.form.LabelView;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
@:template class LifeView extends HGroupView {
|
||||
@:provide static var currentState:GameState;
|
||||
|
||||
@:view("tank") public var tankImage:ImageView;
|
||||
@:view("life") public var lifeLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
public var playerId(default, default):PlayerId;
|
||||
public var state(null, set):PlayerState;
|
||||
public var tank(null, set):String;
|
||||
public var color(null, set):Int;
|
||||
public var color(null, set):Color;
|
||||
public var life(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
|
||||
private inline function set_state(value:PlayerState):PlayerState {
|
||||
state = value;
|
||||
toUpdate();
|
||||
playerId = value.id;
|
||||
tank = value.tank;
|
||||
color = value.color;
|
||||
life = value.life;
|
||||
score = value.score;
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -33,7 +38,7 @@ import ru.m.tankz.game.GameState;
|
||||
return tank;
|
||||
}
|
||||
|
||||
private inline function set_color(value:Int):Int {
|
||||
private inline function set_color(value:Color):Color {
|
||||
tankImage.color = value;
|
||||
return value;
|
||||
}
|
||||
@@ -48,17 +53,6 @@ import ru.m.tankz.game.GameState;
|
||||
return value;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (state != null && currentState != null) {
|
||||
var tankConfig = currentState.config.getTank(state.tank);
|
||||
tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||
color = currentState.config.getColor(state.id);
|
||||
life = state.life;
|
||||
score = state.score;
|
||||
}
|
||||
}
|
||||
|
||||
public static inline function factory(index:Int, data:PlayerState):LifeView {
|
||||
var result = new LifeView();
|
||||
result.state = data;
|
||||
|
||||
@@ -4,10 +4,12 @@ views:
|
||||
- id: tank
|
||||
$type: haxework.view.ImageView
|
||||
- id: life
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 50
|
||||
geometry.height: 38
|
||||
- id: score
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [100, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import haxework.resources.IResources;
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.skin.ISkin;
|
||||
import haxework.view.ToggleButtonView;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type.TeamId;
|
||||
|
||||
class TeamButton extends ToggleButtonView {
|
||||
public var team(default, set):TeamId;
|
||||
|
||||
private function set_team(value:TeamId):TeamId {
|
||||
if (team != value) {
|
||||
team = value;
|
||||
text = team.substr(0, 1).toUpperCase() + team.substr(1);
|
||||
}
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
class TeamSkin implements ISkin<TeamButton> {
|
||||
|
||||
@:provide private static var resources:IResources;
|
||||
|
||||
public var color(default, default):Int;
|
||||
|
||||
public function new(color:Int) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:TeamButton):Void {
|
||||
view.fontColor = view.on ? 0xffffff : resources.color.get("dark");
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(view.on ? color : resources.color.get("light"));
|
||||
graphics.lineStyle(2, color, 0.5);
|
||||
graphics.drawRoundRect(0, 0, view.width, view.height, 5, 5);
|
||||
graphics.endFill();
|
||||
graphics.lineStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@:template class PlayerView extends HGroupView {
|
||||
private static inline var TEAM_NONE:TeamId = "none";
|
||||
|
||||
public var item_index(default, set):Int;
|
||||
public var data(default, set):Array<PlayerState>;
|
||||
public var colorize:Bool;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
||||
|
||||
@:provide var state:GameState;
|
||||
|
||||
private var player:PlayerState;
|
||||
|
||||
private function teamViewFactory(index:Int, team:TeamId) {
|
||||
var view = new TeamButton();
|
||||
var color = getTeamColor(team);
|
||||
view.skin = [Style.text(color), new TeamSkin(color)];
|
||||
view.geometry.padding = [10, 5];
|
||||
view.team = team;
|
||||
view.on = team == TEAM_NONE;
|
||||
return view;
|
||||
}
|
||||
|
||||
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
|
||||
data = value;
|
||||
teams.data = [TEAM_NONE].concat([for (team in state.preset.teams) team.id]);
|
||||
return data;
|
||||
}
|
||||
|
||||
private function getTeamColor(teamId:TeamId):Int {
|
||||
var color = 0xaaaaaa;
|
||||
for (team in state.preset.teams) {
|
||||
if (team.id == teamId) {
|
||||
if (!team.color.zero) color = team.color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_item_index(value:Int):Int {
|
||||
item_index = value;
|
||||
label.text = 'Player ${item_index+1}';
|
||||
return item_index;
|
||||
}
|
||||
|
||||
private function onTeamSelect(team:TeamId) {
|
||||
if (player != null) {
|
||||
player.controller = NONE;
|
||||
player.color = 0;
|
||||
player = null;
|
||||
}
|
||||
for (p in data) {
|
||||
if (p.id.team == team) {
|
||||
switch (p.controller) {
|
||||
case NONE:
|
||||
player = p;
|
||||
player.controller = HUMAN(item_index);
|
||||
if (colorize) {
|
||||
player.color = ColorUtil.multiply(state.config.getTeam(team).color, 1.7);
|
||||
}
|
||||
break;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (view in teams.views) {
|
||||
var button = cast(view, TeamButton);
|
||||
button.on = team == button.team;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
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,11 +1,10 @@
|
||||
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.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@@ -20,7 +19,6 @@ import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var game:IGame;
|
||||
|
||||
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
||||
if (data != value) {
|
||||
@@ -35,8 +33,7 @@ import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
private function play():Void {
|
||||
var record = recordStorage.read(data.id);
|
||||
game = new GamePlayer(record);
|
||||
switcher.change(GameFrame.ID);
|
||||
switcher.change(GameFrame.ID, RECORD(record));
|
||||
}
|
||||
|
||||
private function delete():Void {
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
---
|
||||
geometry.size.height: 38
|
||||
geometry.height: 38
|
||||
layout.margin: 5
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: play
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.start.small
|
||||
+onPress: $code:play()
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.start.small
|
||||
+onPress: ~play()
|
||||
- id: date
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [250, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
geometry.height: 38
|
||||
- id: type
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [250, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
geometry.height: 38
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
- id: preset
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
- id: delete
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.close.small
|
||||
+onPress: $code:delete()
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.close.small
|
||||
+onPress: ~delete()
|
||||
|
||||
30
src/client/haxe/ru/m/tankz/view/common/SlotView.hx
Normal file
30
src/client/haxe/ru/m/tankz/view/common/SlotView.hx
Normal file
@@ -0,0 +1,30 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/client/haxe/ru/m/tankz/view/common/SlotView.yaml
Normal file
24
src/client/haxe/ru/m/tankz/view/common/SlotView.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
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;
|
||||
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.group.VGroupView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
@@ -21,7 +21,6 @@ import ru.m.tankz.view.common.LifeView;
|
||||
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
||||
|
||||
public function refresh(state:GameState):Void {
|
||||
level.text = 'Level ${state.levelId}';
|
||||
bot.life = state.getTeamLife(ClassicGame.BOT);
|
||||
player1.life = state.getPlayerLife(player1Id);
|
||||
player1.score = state.getPlayerScore(player1Id);
|
||||
@@ -36,8 +35,9 @@ import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state):
|
||||
refresh(state);
|
||||
case START(start):
|
||||
this.level.text = 'Level ${start.level.id}';
|
||||
refresh(start.state);
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
if (teamId == ClassicGame.BOT) {
|
||||
bot.life = life;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
---
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
geometry.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: right
|
||||
layout.hAlign: left
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.size.width: 100%
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 38
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.height: 50%
|
||||
geometry.height: 50%
|
||||
- id: bot
|
||||
$type: ru.m.tankz.view.common.LifeView
|
||||
tank: ba
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.group.VGroupView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.preset.DeathGame;
|
||||
import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
|
||||
@@ -14,15 +16,31 @@ import ru.m.tankz.view.common.LifeView;
|
||||
@:view var level:LabelView;
|
||||
@:view var players:DataView<PlayerState, LifeView>;
|
||||
|
||||
@:provide var configBundle:IConfigBundle;
|
||||
|
||||
private function getView(playerId):LifeView {
|
||||
for (view in players.dataViews) {
|
||||
if (view.playerId == playerId) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state):
|
||||
level.text = 'Level ${state.levelId}';
|
||||
players.data = Lambda.array(state.players);
|
||||
case START(start):
|
||||
this.level.text = 'Level ${start.level.id}';
|
||||
players.data = Lambda.array(start.state.players);
|
||||
case SPAWN(TANK(_, _, playerId, info)):
|
||||
var skin = configBundle.get(DeathGame.TYPE).getTank(info.type).skin;
|
||||
getView(playerId).tank = skin;
|
||||
getView(playerId).color = info.color;
|
||||
case CHANGE(PLAYER_LIFE(playerId, life)):
|
||||
getView(playerId).life = life;
|
||||
case CHANGE(PLAYER_SCORE(playerId, score)):
|
||||
getView(playerId).score = score;
|
||||
case _:
|
||||
for (view in players.views) {
|
||||
view.toUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
---
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
geometry.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: right
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.size.width: 100%
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 38
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.height: 50%
|
||||
geometry.height: 50%
|
||||
- id: players
|
||||
$type: haxework.view.DataView
|
||||
$type: haxework.view.data.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
factory: $code:ru.m.tankz.view.common.LifeView.factory
|
||||
factory: ~ru.m.tankz.view.common.LifeView.factory
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
@@ -17,7 +17,6 @@ import ru.m.tankz.view.common.LifeView;
|
||||
@:view var level:LabelView;
|
||||
|
||||
public function refresh(state:GameState):Void {
|
||||
level.text = 'Level ${state.levelId}';
|
||||
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
||||
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
||||
dire.life = state.getTeamLife(DotaGame.DIRE);
|
||||
@@ -34,8 +33,9 @@ import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state):
|
||||
refresh(state);
|
||||
case START(start):
|
||||
this.level.text = 'Level ${start.level.id}';
|
||||
refresh(start.state);
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
getLifeView(teamId).life = life;
|
||||
case CHANGE(TEAM_SCORE(teamId, score)):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
geometry.size.width: 100%
|
||||
geometry.width: 100%
|
||||
layout.margin: 20
|
||||
views:
|
||||
- id: radiant
|
||||
@@ -7,14 +7,14 @@ views:
|
||||
tank: bc
|
||||
color: 0xff4422
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 25%
|
||||
geometry.width: 25%
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.size.width: 50%
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 38
|
||||
geometry.width: 50%
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 25%
|
||||
geometry.width: 25%
|
||||
- id: dire
|
||||
$type: ru.m.tankz.view.common.LifeView
|
||||
tank: bc
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import haxework.view.IGroupView;
|
||||
import haxework.view.VGroupView;
|
||||
import haxework.view.group.IGroupView;
|
||||
import haxework.view.group.VGroupView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.preset.DeathGame;
|
||||
@@ -50,4 +50,18 @@ import ru.m.tankz.Type;
|
||||
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:
|
||||
- id: top
|
||||
$type: haxework.view.GroupView
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.hAlign: center
|
||||
geometry.size.width: 100%
|
||||
- $type: haxework.view.HGroupView
|
||||
geometry.width: 100%
|
||||
- $type: haxework.view.group.HGroupView
|
||||
views:
|
||||
- id: left
|
||||
$type: haxework.view.GroupView
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.size.height: 100%
|
||||
geometry.height: 100%
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
- id: right
|
||||
$type: haxework.view.GroupView
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.size.height: 100%
|
||||
geometry.height: 100%
|
||||
- id: bottom
|
||||
$type: haxework.view.GroupView
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.hAlign: center
|
||||
geometry.size.width: 100%
|
||||
geometry.width: 100%
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
|
||||
@:template class GameItemView extends HGroupView implements IListItemView<GameProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):GameProto;
|
||||
|
||||
@:view var label:LabelView;
|
||||
|
||||
private function set_data(value:GameProto):GameProto {
|
||||
data = value;
|
||||
label.text = '[${value.creator.name}] ${value.type} ${value.level} (${value.players.length})';
|
||||
return data;
|
||||
}
|
||||
|
||||
public static function factory():GameItemView {
|
||||
return new GameItemView();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
geometry.size.width: 100%
|
||||
geometry.size.height: 48
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.stretch: true
|
||||
skinId: text.box
|
||||
@@ -1,54 +0,0 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
|
||||
@:template class GameListFrame extends VGroupView {
|
||||
public static inline var ID = "game_list";
|
||||
|
||||
@:view var games:VListView<GameProto>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
public function onShow():Void {
|
||||
network.listGameSignal.connect(onGameList);
|
||||
network.gameSignal.connect(onGame);
|
||||
network.stateSignal.connect(onState);
|
||||
network.listGame();
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
network.listGameSignal.disconnect(onGameList);
|
||||
network.gameSignal.disconnect(onGame);
|
||||
network.stateSignal.disconnect(onState);
|
||||
}
|
||||
|
||||
private function create():Void {
|
||||
network.createGame("classic", 0);
|
||||
}
|
||||
|
||||
private function onState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(_):
|
||||
case _: switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
private function onGameList(data:Array<GameProto>):Void {
|
||||
games.data = data;
|
||||
}
|
||||
|
||||
private function onGame(game:GameProto):Void {
|
||||
if (game != null) {
|
||||
switcher.change(GameRoomFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
private function selectGame(game:GameProto):Void {
|
||||
network.joinGame(game.id);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
geometry.padding: 20
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.LabelView
|
||||
geometry.margin.bottom: 20
|
||||
skinId: text.header
|
||||
text: Games List
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.simple
|
||||
text: Create
|
||||
+onPress: $code:create()
|
||||
- id: games
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.size.stretch: true
|
||||
factory: $code:ru.m.tankz.view.network.GameItemView.factory
|
||||
geometry.margin: 10
|
||||
+onItemSelect: $code:function(item) selectGame(item.data)
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:switcher.change('start')
|
||||
@@ -1,65 +0,0 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.TextView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.NetworkGame;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
import ru.m.tankz.proto.core.GameStateProto;
|
||||
import ru.m.tankz.proto.core.PlayerProto;
|
||||
|
||||
@:template class GameRoomFrame extends VGroupView {
|
||||
|
||||
public static inline var ID = "game_room";
|
||||
|
||||
@:view var start:ButtonView;
|
||||
@:view var info:TextView;
|
||||
@:view var players:VListView<PlayerProto>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var game:IGame;
|
||||
|
||||
private function refresh(game:GameProto):Void {
|
||||
if (game != null) {
|
||||
start.visible = game.creator.uuid == network.user.uuid;
|
||||
info.text = '[${game.creator.name}] ${game.type} ${game.level} (${game.players.length})';
|
||||
players.data = game.players;
|
||||
if (game.state == GameStateProto.STARTED) {
|
||||
this.game = new NetworkGame(network);
|
||||
switcher.change(GameFrame.ID);
|
||||
}
|
||||
} else {
|
||||
Timer.delay(function() switcher.change(GameListFrame.ID), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
refresh(network.game);
|
||||
network.gameSignal.connect(onGame);
|
||||
network.stateSignal.connect(onState);
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
network.gameSignal.disconnect(onGame);
|
||||
network.stateSignal.disconnect(onState);
|
||||
// ToDo:
|
||||
//network.leaveGame();
|
||||
}
|
||||
|
||||
private function onGame(game:GameProto):Void {
|
||||
refresh(game);
|
||||
}
|
||||
|
||||
private function onState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(_):
|
||||
case _: switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
geometry.padding: 20
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.LabelView
|
||||
geometry.margin.bottom: 20
|
||||
skinId: text.header
|
||||
text: Game Room
|
||||
- id: start
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.simple
|
||||
text: Start
|
||||
+onPress: $code:network.startGame()
|
||||
visible: false
|
||||
- id: info
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.width: 100%
|
||||
skinId: text.box
|
||||
- id: players
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.size.stretch: true
|
||||
factory: $code:ru.m.tankz.view.network.PlayerItemView.factory
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:network.leaveGame()
|
||||
@@ -1,24 +0,0 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.proto.core.PlayerProto;
|
||||
|
||||
@:template class PlayerItemView extends HGroupView implements IListItemView<PlayerProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):PlayerProto;
|
||||
|
||||
@:view var label:LabelView;
|
||||
|
||||
private function set_data(value:PlayerProto):PlayerProto {
|
||||
data = value;
|
||||
label.text = '${value.user.name}';
|
||||
return data;
|
||||
}
|
||||
|
||||
public static function factory():PlayerItemView {
|
||||
return new PlayerItemView();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
geometry.size.width: 100%
|
||||
geometry.size.height: 48
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.stretch: true
|
||||
skinId: text.box
|
||||
49
src/client/haxe/ru/m/tankz/view/network/RoomFrame.hx
Normal file
49
src/client/haxe/ru/m/tankz/view/network/RoomFrame.hx
Normal file
@@ -0,0 +1,49 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.text.TextView;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
@:template class RoomFrame extends FrameView<RoomProto> {
|
||||
|
||||
public static inline var ID = "room";
|
||||
|
||||
@:view var start:ButtonView;
|
||||
@:view var info:TextView;
|
||||
@:view var slots:VListView<RoomSlotProto>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function refresh(room:RoomProto):Void {
|
||||
if (room != null) {
|
||||
start.visible = room.creator.uuid == network.user.uuid;
|
||||
info.text = '${room.game.type} #${room.game.level}';
|
||||
slots.data = room.slots;
|
||||
if (room.game.started) {
|
||||
switcher.change(GameFrame.ID, NETWORK(network));
|
||||
}
|
||||
} else {
|
||||
Timer.delay(function() switcher.change(RoomListFrame.ID), 1);
|
||||
}
|
||||
}
|
||||
|
||||
override public function onShow(data:RoomProto):Void {
|
||||
refresh(data);
|
||||
network.roomSignal.connect(refresh);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
network.roomSignal.disconnect(refresh);
|
||||
}
|
||||
}
|
||||
39
src/client/haxe/ru/m/tankz/view/network/RoomFrame.yaml
Normal file
39
src/client/haxe/ru/m/tankz/view/network/RoomFrame.yaml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
geometry.stretch: true
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
views:
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
geometry.padding: 20
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.margin.bottom: 20
|
||||
style: text.header
|
||||
text: Game Room
|
||||
- $type: haxework.view.group.HGroupView
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: info
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.padding: [30, 10]
|
||||
style: text.box
|
||||
- id: start
|
||||
$type: haxework.view.form.ButtonView
|
||||
text: Start
|
||||
+onPress: ~network.startGame()
|
||||
visible: false
|
||||
- id: leave
|
||||
$type: haxework.view.form.ButtonView
|
||||
text: Leave
|
||||
+onPress: ~network.leaveGame()
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100%
|
||||
geometry.height: 3
|
||||
style: line
|
||||
- id: slots
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.tankz.view.network.SlotItemView.factory
|
||||
40
src/client/haxe/ru/m/tankz/view/network/RoomItemView.hx
Normal file
40
src/client/haxe/ru/m/tankz/view/network/RoomItemView.hx
Normal file
@@ -0,0 +1,40 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
|
||||
@:template class RoomItemView extends HGroupView implements IListItemView<RoomProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):RoomProto;
|
||||
|
||||
@:view("creator") var creatorView:LabelView;
|
||||
@:view("type") var typeView:LabelView;
|
||||
@:view("users") var usersView:LabelView;
|
||||
@:view("join") var joinButton:ButtonView;
|
||||
|
||||
@:provide static var network:NetworkManager;
|
||||
|
||||
private function set_data(value:RoomProto):RoomProto {
|
||||
data = value;
|
||||
creatorView.style = value.creator.uuid == network.user.uuid ? "text.box.active" : "text.box";
|
||||
creatorView.text = value.creator.name;
|
||||
typeView.text = '${value.game.type} #${value.game.level}';
|
||||
var used = value.slots.filter(function(slot:RoomSlotProto) return slot.hasUser()).length;
|
||||
usersView.text = value.game.started ? 'started' : '${used}/${value.slots.length}';
|
||||
return data;
|
||||
}
|
||||
|
||||
private function join():Void {
|
||||
network.joinGame(data.game.id, true);
|
||||
}
|
||||
|
||||
public static function factory():RoomItemView {
|
||||
return new RoomItemView();
|
||||
}
|
||||
}
|
||||
26
src/client/haxe/ru/m/tankz/view/network/RoomItemView.yaml
Normal file
26
src/client/haxe/ru/m/tankz/view/network/RoomItemView.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
# geometry.width: 100%
|
||||
geometry.height: 48
|
||||
layout.margin: 10
|
||||
layout.hAlign: center
|
||||
views:
|
||||
- id: creator
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 200
|
||||
style: text.box
|
||||
- id: type
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 200
|
||||
style: text.box
|
||||
- id: users
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 150
|
||||
style: text.box
|
||||
- id: join
|
||||
$type: haxework.view.form.ButtonView
|
||||
geometry.height: 100%
|
||||
text: Join
|
||||
+onPress: ~join()
|
||||
51
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx
Normal file
51
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx
Normal file
@@ -0,0 +1,51 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.VListView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
import ru.m.tankz.view.popup.CreateGamePopup;
|
||||
|
||||
@:template class RoomListFrame extends FrameView<Dynamic> {
|
||||
public static inline var ID = "room_list";
|
||||
|
||||
@:view var games:VListView<RoomProto>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(_:Dynamic):Void {
|
||||
network.listRoomSignal.connect(onRoomList);
|
||||
network.roomSignal.connect(onRoom);
|
||||
network.listGame(true);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
network.listRoomSignal.disconnect(onRoomList);
|
||||
network.roomSignal.disconnect(onRoom);
|
||||
network.listGame(false);
|
||||
}
|
||||
|
||||
private function create():Void {
|
||||
CreateGamePopup.instance.show().then(function(result) {
|
||||
if (result != null) {
|
||||
network.createGame(result.type, result.level.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function onRoomList(data:Array<RoomProto>):Void {
|
||||
games.data = data;
|
||||
}
|
||||
|
||||
private function onRoom(room:RoomProto):Void {
|
||||
if (room != null) {
|
||||
switcher.change(RoomFrame.ID, room);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.yaml
Normal file
22
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
geometry.stretch: true
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
views:
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
geometry.padding: 20
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.margin.bottom: 20
|
||||
style: text.header
|
||||
text: Games List
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Create
|
||||
+onPress: ~create()
|
||||
- id: games
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.tankz.view.network.RoomItemView.factory
|
||||
geometry.margin: 10
|
||||
43
src/client/haxe/ru/m/tankz/view/network/SlotItemView.hx
Normal file
43
src/client/haxe/ru/m/tankz/view/network/SlotItemView.hx
Normal file
@@ -0,0 +1,43 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
@:template class SlotItemView extends HGroupView implements IListItemView<RoomSlotProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):RoomSlotProto;
|
||||
|
||||
@:view("type") var typeView:LabelView;
|
||||
@:view("user") var userView:LabelView;
|
||||
@:view("select") var selectButton:ButtonView;
|
||||
|
||||
@:provide static var network:NetworkManager;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
|
||||
private function set_data(value:RoomSlotProto):RoomSlotProto {
|
||||
data = value;
|
||||
typeView.text = '${value.slot.team} #${value.slot.index}';
|
||||
userView.text = value.hasUser() ? value.user.name : "(NONE)";
|
||||
userView.visible = value.hasUser();
|
||||
selectButton.visible = !value.hasUser();
|
||||
userView.style = (value.hasUser() && value.user.uuid == network.user.uuid) ? "text.box.active" : "text.box";
|
||||
var config = configBundle.get(network.room.game.type);
|
||||
var color = config.getColor([value.slot.team, value.slot.index]);
|
||||
typeView.font.color = color;
|
||||
return data;
|
||||
}
|
||||
|
||||
private function select():Void {
|
||||
network.selectSlot(data.slot);
|
||||
}
|
||||
|
||||
public static function factory():SlotItemView {
|
||||
return new SlotItemView();
|
||||
}
|
||||
}
|
||||
24
src/client/haxe/ru/m/tankz/view/network/SlotItemView.yaml
Normal file
24
src/client/haxe/ru/m/tankz/view/network/SlotItemView.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
geometry.height: 48
|
||||
geometry.padding: 2
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: type
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 100%
|
||||
geometry.width: 150
|
||||
- $type: haxework.view.group.HGroupView
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
geometry.height: 100%
|
||||
geometry.width: 300
|
||||
views:
|
||||
- id: user
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.stretch: true
|
||||
style: text.box
|
||||
- id: select
|
||||
$type: haxework.view.form.ButtonView
|
||||
text: Select
|
||||
+onPress: ~select()
|
||||
74
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
74
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
@@ -0,0 +1,74 @@
|
||||
package ru.m.tankz.view.popup;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.popup.PopupView;
|
||||
import haxework.view.form.ToggleButtonView;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
private typedef Result = {
|
||||
var type:GameType;
|
||||
var level:LevelConfig;
|
||||
}
|
||||
|
||||
@:template class CreateGamePopup extends PopupView<Result> {
|
||||
|
||||
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||
@:view("level") var levelView:DataView<LevelConfig, ToggleButtonView>;
|
||||
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
private var type:GameType;
|
||||
private var level:LevelConfig;
|
||||
|
||||
override private function onShow():Void {
|
||||
super.onShow();
|
||||
onGameTypeSelect(0, "classic", typeView.dataViews[0]);
|
||||
}
|
||||
|
||||
private function submit():Void {
|
||||
close({type:type, level:level});
|
||||
}
|
||||
|
||||
private function gameTypeViewFactory(index:Int, type:GameType):ToggleButtonView {
|
||||
var result = new ToggleButtonView();
|
||||
result.text = type;
|
||||
result.on = type == this.type;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onGameTypeSelect(index:Int, value:GameType, view:ToggleButtonView):Void {
|
||||
this.type = value;
|
||||
for (v in typeView.dataViews) {
|
||||
v.on = v == view;
|
||||
}
|
||||
levelView.data = levelBundle.get(new PackId(value)).data;
|
||||
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, value:LevelConfig):ToggleButtonView {
|
||||
var result = new ToggleButtonView();
|
||||
result.style = "button.level";
|
||||
result.text = Std.string(value.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ToggleButtonView):Void {
|
||||
this.level = level;
|
||||
for (v in levelView.dataViews) {
|
||||
v.on = v == view;
|
||||
}
|
||||
}
|
||||
|
||||
public static var instance(get, null):CreateGamePopup;
|
||||
|
||||
private static function get_instance():CreateGamePopup {
|
||||
if (instance == null) {
|
||||
instance = new CreateGamePopup();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
71
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
71
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
view:
|
||||
$type: haxework.view.group.VGroupView
|
||||
layout.hAlign: center
|
||||
geometry.stretch: true
|
||||
geometry.margin: 10
|
||||
style: window
|
||||
views:
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.width: 100%
|
||||
geometry.padding: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: name
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 100%
|
||||
geometry.margin.left: 10
|
||||
layout.hAlign: left
|
||||
style: text
|
||||
text: New game
|
||||
- $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()
|
||||
@@ -1,41 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
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')
|
||||
@@ -1,63 +0,0 @@
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
---
|
||||
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;
|
||||
|
||||
import haxework.log.BaseLogger.LoggerUtil;
|
||||
import haxework.view.InputView;
|
||||
import haxework.view.form.InputView;
|
||||
import haxework.view.popup.PopupView;
|
||||
import haxework.view.TextView;
|
||||
import haxework.view.text.TextView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
|
||||
@:template class LoginPopup extends PopupView<User> {
|
||||
|
||||
@@ -2,63 +2,64 @@
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
view:
|
||||
$type: haxework.view.VGroupView
|
||||
$type: haxework.view.group.VGroupView
|
||||
layout.hAlign: center
|
||||
geometry.size.width: 400
|
||||
# geometry.size.height: 400
|
||||
skinId: window
|
||||
geometry.width: 400
|
||||
# geometry.height: 400
|
||||
style: window
|
||||
views:
|
||||
- $type: haxework.view.HGroupView
|
||||
geometry.size.width: 100%
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.width: 100%
|
||||
geometry.padding: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: name
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.width: 100%
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 100%
|
||||
geometry.margin.left: 10
|
||||
layout.hAlign: left
|
||||
skinId: text
|
||||
style: text
|
||||
text: Login
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: window.close
|
||||
+onPress: $code:reject('close')
|
||||
- $type: haxework.view.VGroupView
|
||||
geometry.size.width: 100%
|
||||
# geometry.size.stretch: true
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: window.close
|
||||
+onPress: ~reject('close')
|
||||
- $type: haxework.view.group.VGroupView
|
||||
geometry.width: 100%
|
||||
# geometry.stretch: true
|
||||
geometry.padding: 20
|
||||
layout.margin: 5
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
geometry.size.width: 100%
|
||||
skinId: text
|
||||
- $type: haxework.view.form.LabelView
|
||||
geometry.width: 100%
|
||||
style: text
|
||||
text: Username
|
||||
- id: username
|
||||
$type: haxework.view.InputView
|
||||
geometry.size.width: 100%
|
||||
geometry.size.height: 28
|
||||
skinId: text.box
|
||||
- $type: haxework.view.LabelView
|
||||
geometry.size.width: 100%
|
||||
skinId: text
|
||||
$type: haxework.view.form.InputView
|
||||
geometry.width: 100%
|
||||
geometry.height: 28
|
||||
style: text.box
|
||||
- $type: haxework.view.form.LabelView
|
||||
geometry.width: 100%
|
||||
style: text
|
||||
text: Password
|
||||
visible: false
|
||||
- id: password
|
||||
$type: haxework.view.InputView
|
||||
$type: haxework.view.form.InputView
|
||||
textField.displayAsPassword: true
|
||||
geometry.size.width: 100%
|
||||
geometry.size.height: 28
|
||||
skinId: text.box
|
||||
geometry.width: 100%
|
||||
geometry.height: 28
|
||||
style: text.box
|
||||
visible: false
|
||||
- id: error
|
||||
$type: haxework.view.TextView
|
||||
geometry.size.width: 100%
|
||||
skinId: text
|
||||
$type: haxework.view.text.TextView
|
||||
geometry.width: 100%
|
||||
style: text
|
||||
fill: false
|
||||
- $type: haxework.view.HGroupView
|
||||
- $type: haxework.view.group.HGroupView
|
||||
layout.hAlign: center
|
||||
layout.margin: 5
|
||||
skinId: panel
|
||||
style: panel
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.simple
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Submit
|
||||
+onPress: $code:submit()
|
||||
+onPress: ~submit()
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package ru.m.tankz.view.settings;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.list.ListView.IListItemView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import openfl.Assets;
|
||||
import openfl.events.KeyboardEvent;
|
||||
import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
typedef ActionItem = {
|
||||
var action:TankAction;
|
||||
var bind:BindAction;
|
||||
}
|
||||
|
||||
class KeyboardMap {
|
||||
|
||||
private var data:Map<Int, String>;
|
||||
@@ -26,9 +29,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();
|
||||
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||
}
|
||||
@@ -39,12 +42,12 @@ class KeyboardMap {
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):ActionItem;
|
||||
|
||||
public var edit(default, set):Bool;
|
||||
|
||||
@:view var action(default, null):LabelView;
|
||||
@:view var key(default, null):LabelView;
|
||||
|
||||
private var editDeferred: Deferred<Int>;
|
||||
|
||||
private static function actionLabel(action: TankAction): String {
|
||||
private static function actionLabel(action:TankAction):String {
|
||||
return switch (action) {
|
||||
case TankAction.SHOT: "SHOT";
|
||||
case TankAction.MOVE(d): 'MOVE_$d';
|
||||
@@ -52,32 +55,25 @@ class KeyboardMap {
|
||||
}
|
||||
}
|
||||
|
||||
private static function keyLabel(key: Int): String {
|
||||
return KeyboardMap.getName(key);
|
||||
private static function bindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
|
||||
private function set_data(value:ActionItem):ActionItem {
|
||||
data = value;
|
||||
action.text = actionLabel(data.action);
|
||||
key.text = keyLabel(data.key);
|
||||
key.text = bindLabel(data.bind);
|
||||
return data;
|
||||
}
|
||||
|
||||
public function edit():Promise<Int> {
|
||||
action.skinId = key.skinId = "text.box.active";
|
||||
toRedraw();
|
||||
editDeferred = new Deferred();
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
return editDeferred.promise();
|
||||
private function set_edit(value:Bool):Bool {
|
||||
if (edit != value) {
|
||||
edit = value;
|
||||
action.style = key.style = edit ? "text.box.active" : "text.box";
|
||||
}
|
||||
|
||||
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;
|
||||
return edit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ geometry.margin: 5
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: action
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.fixed: [200, 38]
|
||||
skinId: text.box
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 180
|
||||
geometry.height: 38
|
||||
style: text.box
|
||||
- id: key
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.fixed: [200, 38]
|
||||
skinId: text.box
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 250
|
||||
geometry.height: 38
|
||||
style: text.box
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user