From 43c5be94553b316e45cd50d098a5cbed8a9488b8 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 10 Aug 2015 12:13:38 +0300 Subject: [PATCH] big update --- src/client/haxe/layout/frames/auth.json | 43 ++++ src/client/haxe/layout/frames/game.json | 19 ++ src/client/haxe/layout/frames/game_list.json | 24 +++ src/client/haxe/layout/frames/game_ready.json | 30 +++ .../haxe/layout/frames/person_list.json | 14 ++ src/client/haxe/layout/main.json | 46 +++++ src/client/haxe/layout/styles.json | 12 ++ src/client/haxe/ru/m/tankz/Client.hx | 30 +-- src/client/haxe/ru/m/tankz/render/IRender.hx | 3 +- src/client/haxe/ru/m/tankz/render/Render.hx | 4 +- .../haxe/ru/m/tankz/view/frames/AuthFrame.hx | 63 +++--- .../haxe/ru/m/tankz/view/frames/GameFrame.hx | 19 +- .../ru/m/tankz/view/frames/GameListFrame.hx | 19 +- .../ru/m/tankz/view/frames/GameReadyFrame.hx | 18 +- .../ru/m/tankz/view/frames/PersonListFrame.hx | 20 +- src/client/resources/gui/main.json | 82 -------- src/client/resources/layout/main.json | 189 ------------------ .../haxe/ru/m/core/connect/BaseConnection.hx | 32 +-- .../haxe/ru/m/core/connect/IConnection.hx | 8 +- .../m/core/connect/flash/FlashConnection.hx | 40 ++-- .../haxe/ru/m/core/connect/js/JsConnection.hx | 32 +-- .../ru/m/core/connect/neko/NekoConnection.hx | 4 +- .../m/core/connect/neko/NekoWebConnection.hx | 4 +- .../haxe/ru/m/tankz/server/session/Session.hx | 6 +- 24 files changed, 323 insertions(+), 438 deletions(-) create mode 100644 src/client/haxe/layout/frames/auth.json create mode 100644 src/client/haxe/layout/frames/game.json create mode 100644 src/client/haxe/layout/frames/game_list.json create mode 100644 src/client/haxe/layout/frames/game_ready.json create mode 100644 src/client/haxe/layout/frames/person_list.json create mode 100755 src/client/haxe/layout/main.json create mode 100644 src/client/haxe/layout/styles.json delete mode 100755 src/client/resources/gui/main.json delete mode 100755 src/client/resources/layout/main.json diff --git a/src/client/haxe/layout/frames/auth.json b/src/client/haxe/layout/frames/auth.json new file mode 100644 index 0000000..6e5308d --- /dev/null +++ b/src/client/haxe/layout/frames/auth.json @@ -0,0 +1,43 @@ +{ + "pWidth": 100, "pHeight": 100, "layoutMargin": 3, + "views": [ + { + "@type": "haxework.gui.HGroupView", + "contentSize": true, + "views": [ + { + "@type": "haxework.gui.LabelView", + "width": 150, "height": 25, "text": "Login" + }, + { + "id": "loginInput", "@type": "haxework.gui.InputView", + "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, + "width": 200, "height": 25, "text": "" + } + ] + }, + { + "@type": "haxework.gui.HGroupView", + "contentSize": true, + "views": [ + { + "@type": "haxework.gui.LabelView", + "width": 150, "height": 25, "text": "Password" + }, + { + "id": "passwordInput", "@type": "haxework.gui.InputView", + "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, + "width": 200, "height": 25, "text": "" + } + ] + }, + + { + "id": "authButton", + "@type": "haxework.gui.ButtonView", + "width": 100, "height": 45, + "text": "Auth", + "@style": "button_skin" + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/game.json b/src/client/haxe/layout/frames/game.json new file mode 100644 index 0000000..0c2cb3a --- /dev/null +++ b/src/client/haxe/layout/frames/game.json @@ -0,0 +1,19 @@ +{ + "pWidth": 100, "pHeight": 100, + "views": [ + { + "id": "name", "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 25, "text": "" + }, + { + "id": "restart", "@type": "haxework.gui.ButtonView", + "width": 100, "height": 45, + "text": "Restart", + "@style": "button_skin" + }, + { + "id": "render", "@type": "ru.m.tankz.render.Render", + "contentSize": true + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/game_list.json b/src/client/haxe/layout/frames/game_list.json new file mode 100644 index 0000000..c466a82 --- /dev/null +++ b/src/client/haxe/layout/frames/game_list.json @@ -0,0 +1,24 @@ +{ + "pWidth": 100, "pHeight": 100, + "views": [ + { + "id": "name", "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 25, "text": "" + }, + { + "id": "create", "@type": "haxework.gui.ButtonView", + "width": 100, "height": 45, + "text": "Create", + "@style": "button_skin" + }, + { + "id": "list", "@type": "haxework.gui.list.VListView", + "factory": "@class:ru.m.tankz.view.frames.list.GameView", + "scroll": { + "@type": "haxework.gui.list.VScrollView", + "skin": {"@type": "haxework.gui.list.VScrollSkin"} + }, + "pWidth": 100, "pHeight": 100, "layoutMargin": 5 + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/game_ready.json b/src/client/haxe/layout/frames/game_ready.json new file mode 100644 index 0000000..5804b37 --- /dev/null +++ b/src/client/haxe/layout/frames/game_ready.json @@ -0,0 +1,30 @@ +{ + "pWidth": 100, "pHeight": 100, + "views": [ + { + "id": "name", "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 25, "text": "" + }, + { + "id": "start", "@type": "haxework.gui.ButtonView", + "width": 100, "height": 45, + "text": "Start", + "@style": "button_skin" + }, + { + "id": "exit", "@type": "haxework.gui.ButtonView", + "width": 100, "height": 45, + "text": "Exit", + "@style": "button_skin" + }, + { + "id": "list", "@type": "haxework.gui.list.VListView", + "factory": "@class:ru.m.tankz.view.frames.list.PersonView", + "scroll": { + "@type": "haxework.gui.list.VScrollView", + "skin": {"@type": "haxework.gui.list.VScrollSkin"} + }, + "pWidth": 100, "pHeight": 100, "layoutMargin": 5 + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/person_list.json b/src/client/haxe/layout/frames/person_list.json new file mode 100644 index 0000000..a2b0e05 --- /dev/null +++ b/src/client/haxe/layout/frames/person_list.json @@ -0,0 +1,14 @@ +{ + "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10, + "views": [ + { + "id": "list", "@type": "haxework.gui.list.VListView", + "factory": "@class:ru.m.tankz.view.frames.list.PersonView", + "scroll": { + "@type": "haxework.gui.list.VScrollView", + "skin": {"@type": "haxework.gui.list.VScrollSkin"} + }, + "pWidth": 100, "pHeight": 100, "layoutMargin": 5 + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/main.json b/src/client/haxe/layout/main.json new file mode 100755 index 0000000..306c63a --- /dev/null +++ b/src/client/haxe/layout/main.json @@ -0,0 +1,46 @@ +{ + "@type": "haxework.gui.VGroupView", + "pWidth": 100, "pHeight": 100, + "views": [ + { + "id":"top", "@type": "haxework.gui.HGroupView", + "pWidth": 100, "height": 30, + "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0x105000"}, + "views": [ + { + "id": "logout", "@type": "haxework.gui.ButtonView", + "width": 100, "height": 30, + "text": "Logout", + "@style": "button_skin" + } + ] + }, + { + "id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher", + "pWidth": 100, "pHeight": 100, + "skin": {"@type": "haxework.gui.skin.BitmapSkin", "image": "@asset:image:resources/images/background.png", "fillType": "REPEAT"}, + "views": [ + { + "id": "auth", + "@type": "ru.m.tankz.view.frames.AuthFrame" + }, + { + "id": "person_list", + "@type": "ru.m.tankz.view.frames.PersonListFrame" + }, + { + "id": "game_list", + "@type": "ru.m.tankz.view.frames.GameListFrame" + }, + { + "id": "game_ready", + "@type": "ru.m.tankz.view.frames.GameReadyFrame" + }, + { + "id": "game", + "@type": "ru.m.tankz.view.frames.GameFrame" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/client/haxe/layout/styles.json b/src/client/haxe/layout/styles.json new file mode 100644 index 0000000..c5ff294 --- /dev/null +++ b/src/client/haxe/layout/styles.json @@ -0,0 +1,12 @@ +{ + "button_skin": { + "skin": { + "@type": "haxework.gui.skin.ButtonBitmapSkin", + "upImage": "@asset:image:resources/images/control/button_normal.png", + "downImage": "@asset:image:resources/images/control/button_down.png", + "overImage": "@asset:image:resources/images/control/button_over.png", + "fillType": "NINEPATH" + }, + "fontColor": "0xffffff" + } +} \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 72ebef4..2ab4edf 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -1,22 +1,25 @@ package ru.m.tankz; +import haxework.gui.VGroupView; +import haxework.gui.ViewBuilder; import haxework.gui.ButtonView; import flash.display.Sprite; import haxework.gui.IGroupView; import ru.m.tankz.PacketBuilder; import haxework.log.JSLogger; import ru.m.tankz.data.GameData; -import haxework.frame.IFrameSwitcher; +import haxework.gui.frame.IFrameSwitcher; import haxework.provider.Provider; import ru.m.tankz.view.frames.AuthFrame; -import haxework.frame.FrameSwitcher; +import haxework.gui.frame.FrameSwitcher; import haxework.gui.Root; -import haxework.gui.GuiBuilder; -import haxe.Json; import openfl.Assets; import ru.m.core.connect.IConnection; import haxework.log.TraceLogger; +@:template("layout/main.json", "layout/styles.json") +class MainView extends VGroupView implements ViewBuilder {} + class Client implements IConnectionHandler { private static inline var TAG = "Tankz"; @@ -31,28 +34,25 @@ class Client implements IConnectionHandler { } - private var view:IGroupView; - private var logout:ButtonView; + private var view:MainView; private var switcher:FrameSwitcher; public function new() { - var bytes = Assets.getBytes("resources/layout/main.json"); - var form:Dynamic = Json.parse(bytes.readUTFBytes(bytes.bytesAvailable)); - view = GuiBuilder.build(form); - new Root(view); - switcher = view.findViewById("switcher"); - logout = view.findViewById("top:logout"); - logout.onPress = this; + view = new MainView(); + Root.bind(view); + switcher = view.switcher; + view.logout.onPress = this; Provider.setFactory(GameData, GameData); Provider.set(IFrameSwitcher, switcher); Provider.set(IPacketBuilder, new PacketBuilder()); #if flash - Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001, this)); + Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001)); #elseif html5 - Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001, this)); + Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001)); #end + Provider.get(IConnection).handler.addListener(this); switcher.change(AuthFrame.ID); } diff --git a/src/client/haxe/ru/m/tankz/render/IRender.hx b/src/client/haxe/ru/m/tankz/render/IRender.hx index 84ba073..7dd366f 100755 --- a/src/client/haxe/ru/m/tankz/render/IRender.hx +++ b/src/client/haxe/ru/m/tankz/render/IRender.hx @@ -1,9 +1,8 @@ package ru.m.tankz.render; -import flash.display.Sprite; import haxework.gui.IView; import ru.m.tankz.game.ITankz; -interface IRender extends IView { +interface IRender extends IView { public function draw(game:ITankz):Void; } diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index bc2b5ef..d0c1b42 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -14,8 +14,8 @@ class Render extends SpriteView implements IRender { super(); mapLayer = new Sprite(); tankLayer = new Sprite(); - content.addChild(mapLayer); - content.addChild(tankLayer); + contentAsSprite.addChild(mapLayer); + contentAsSprite.addChild(tankLayer); } public function draw(game:ITankz):Void { diff --git a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx index 9ecafe4..5d1264f 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx @@ -1,11 +1,12 @@ package ru.m.tankz.view.frames; +import haxework.gui.ViewBuilder; import ru.m.core.connect.IConnection; import ru.m.tankz.data.GameData; import flash.net.SharedObject; import ru.m.tankz.proto.ErrorResponse; import protohx.Message; -import haxework.frame.IFrameSwitcher; +import haxework.gui.frame.IFrameSwitcher; import ru.m.tankz.proto.LoginRequest; import ru.m.tankz.proto.LoginResponse; import haxework.provider.Provider; @@ -14,7 +15,8 @@ import haxework.gui.InputView; import haxework.gui.ButtonView; import haxework.gui.VGroupView; -class AuthFrame extends VGroupView implements IPacketHandler { +@:template("layout/frames/auth.json", "layout/styles.json") +class AuthFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements IConnectionHandler { private static inline var TAG = "AuthFrame"; @@ -22,18 +24,9 @@ class AuthFrame extends VGroupView implements IPacketHandler { private var so:SharedObject; - private var loginInput:InputView; - private var passwordInput:InputView; - - public function new() { - super(); + public function init() { so = SharedObject.getLocal("auth", "/"); - } - - public function init():Void { - findViewById("auth", ButtonView).onPress = this; - loginInput = findViewById("login:input"); - passwordInput = findViewById("password:input"); + authButton.onPress = this; passwordInput.textField.displayAsPassword = true; if (so.data.login != null && so.data.password != null) { loginInput.text = so.data.login; @@ -41,8 +34,9 @@ class AuthFrame extends VGroupView implements IPacketHandler { } } - public function onShow():Void { - Provider.get(IConnection).packetHandler = this; + public function onShow() { + Provider.get(IConnection).handler.addListener(this); + Provider.get(IConnection).packetHandler.addListener(this); if (so.data.login != null && so.data.password != null) { loginInput.text = so.data.login; passwordInput.text = so.data.password; @@ -53,21 +47,18 @@ class AuthFrame extends VGroupView implements IPacketHandler { } } - public function onPress(_):Void { - var login:String = loginInput.text; - var password:String = Md5.encode(passwordInput.text); - var connection:IConnection = Provider.get(IConnection); - connection.connect() - .success(function(_) { - L.d(TAG, "Connected"); - connection.send(new LoginRequest().setLogin(login).setPassword(password)); - }) - .fail(function(error) { - L.e(TAG, "Auth", error); - }); - + public function onHide() { + Provider.get(IConnection).handler.removeListener(this); + Provider.get(IConnection).packetHandler.removeListener(this); } + public function onPress(_) { + Provider.get(IConnection).connect(); + } + + /** + * IPacketHandler + **/ public function onLoginResponse(packet:LoginResponse):Void { so.setProperty("login", loginInput.text); so.setProperty("password", passwordInput.text); @@ -82,4 +73,20 @@ class AuthFrame extends VGroupView implements IPacketHandler { public function onPacket(packet:Message):Void {} + /** + * IConnectionHandler + **/ + public function onConnected():Void { + Provider.get(IConnection).send( + new LoginRequest() + .setLogin(loginInput.text) + .setPassword(Md5.encode(passwordInput.text)) + ); + } + + public function onDisconnected():Void {} + + public function onError(error:Dynamic):Void { + L.e(TAG, "Auth", error); + } } \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx index f06c69c..791db3c 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx @@ -1,31 +1,28 @@ package ru.m.tankz.view.frames; +import haxework.gui.ViewBuilder; import ru.m.tankz.config.TankzConfig; -import ru.m.tankz.render.IRender; import flash.events.Event; import ru.m.tankz.game.Tankz; import ru.m.tankz.game.ITankz; -import ru.m.core.connect.IConnection; import haxework.gui.LabelView; import haxework.gui.ButtonView; import haxework.provider.Provider; import ru.m.tankz.data.GameData; import haxework.gui.VGroupView; -import ru.m.tankz.render.Render; -class GameFrame extends VGroupView { +@:template("layout/frames/game.json", "layout/styles.json") +class GameFrame extends VGroupView implements ViewBuilder { private static inline var TAG = "GameFrame"; public static inline var ID = "game"; - private var render:IRender; private var game:ITankz; private var config:TankzConfig; - public function new() { - super(); + public function init():Void { game = new Tankz(); config = { map: { @@ -35,16 +32,12 @@ class GameFrame extends VGroupView { gridHeight: 26 } }; - } - - public function init():Void { - render = findViewById("render"); - findViewById("restart", ButtonView).onPress = this; + restart.onPress = this; } public function onShow():Void { var person = Provider.get(GameData).person; - findViewById("name", LabelView).text = person.name; + name.text = person.name; game.init(config); content.addEventListener(Event.ENTER_FRAME, updateGame); } diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx index 56a39d3..d57bb33 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx @@ -1,11 +1,11 @@ package ru.m.tankz.view.frames; +import haxework.gui.ViewBuilder; import ru.m.tankz.proto.JoinGameResponse; import ru.m.tankz.proto.JoinGameRequest; import ru.m.tankz.proto.CreateGameResponse; import ru.m.tankz.proto.CreateGameRequest; -import ru.m.tankz.view.frames.list.GameView; -import haxework.frame.IFrameSwitcher; +import haxework.gui.frame.IFrameSwitcher; import haxework.gui.ButtonView; import haxework.gui.LabelView; import ru.m.tankz.proto.GamesResponse; @@ -19,18 +19,13 @@ import haxework.provider.Provider; import haxework.gui.list.VListView; import haxework.gui.VGroupView; -class GameListFrame extends VGroupView implements IPacketHandler implements ListViewListener { +@:template("layout/frames/game_list.json", "layout/styles.json") +class GameListFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener { private static inline var TAG = "GameListFrame"; public static inline var ID = "game_list"; - private var list:VListView; - - public function new() { - super(); - } - public function init() { list = findViewById("list"); list.dispatcher.addListener(this); @@ -39,10 +34,14 @@ class GameListFrame extends VGroupView implements IPacketHandler implements List public function onShow() { findViewById("name", LabelView).text = Provider.get(GameData).person.name; - Provider.get(IConnection).packetHandler = this; + Provider.get(IConnection).packetHandler.addListener(this); Provider.get(IConnection).send(new GamesRequest()); } + public function onHide() { + Provider.get(IConnection).packetHandler.removeListener(this); + } + public function onListItemClick(item:IListItemView):Void { L.d(TAG, "game selected: ", item.data.id); Provider.get(IConnection).send(new JoinGameRequest().setGameId(item.data.id)); diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx index 3e67004..b6815f8 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx @@ -1,7 +1,8 @@ package ru.m.tankz.view.frames; +import haxework.gui.ViewBuilder; import ru.m.tankz.proto.ExitGameResponse; -import haxework.frame.IFrameSwitcher; +import haxework.gui.frame.IFrameSwitcher; import ru.m.tankz.proto.GamesResponse; import ru.m.tankz.proto.ExitGameRequest; import ru.m.tankz.proto.StartGameResponse; @@ -15,18 +16,13 @@ import haxework.provider.Provider; import haxework.gui.VGroupView; import ru.m.core.connect.IConnection; -class GameReadyFrame extends VGroupView implements IPacketHandler { +@:template("layout/frames/game_ready.json", "layout/styles.json") +class GameReadyFrame extends VGroupView implements ViewBuilder implements IPacketHandler { private static inline var TAG = "GameReadyFrame"; public static inline var ID = "game_ready"; - private var list:VListView; - - public function new() { - super(); - } - public function init() { list = findViewById("list"); //list.dispatcher.addListener(this); @@ -35,10 +31,14 @@ class GameReadyFrame extends VGroupView implements IPacketHandler { } public function onShow() { - Provider.get(IConnection).packetHandler = this; + Provider.get(IConnection).packetHandler.addListener(this); list.data = Provider.get(GameData).game.persons; } + public function onHide() { + Provider.get(IConnection).packetHandler.removeListener(this); + } + public function onStartGameResponse(packet:StartGameResponse):Void { Provider.get(GameData).game = packet.game; Provider.get(IFrameSwitcher).change(GameFrame.ID); diff --git a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx index 0136d9b..db961c4 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx @@ -1,31 +1,25 @@ package ru.m.tankz.view.frames; +import haxework.gui.ViewBuilder; import ru.m.tankz.view.frames.GameListFrame; -import haxework.frame.IFrameSwitcher; +import haxework.gui.frame.IFrameSwitcher; import ru.m.tankz.proto.PersonSelectResponse; import ru.m.tankz.proto.PersonSelectRequest; import haxework.gui.list.ListView; import protohx.Message; import ru.m.core.connect.IConnection; -import ru.m.tankz.view.frames.list.PersonView; import ru.m.tankz.data.GameData; import haxework.provider.Provider; import ru.m.tankz.proto.Person; -import haxework.gui.list.VListView; import haxework.gui.HGroupView; -class PersonListFrame extends HGroupView implements IPacketHandler implements ListViewListener { +@:template("layout/frames/person_list.json", "layout/styles.json") +class PersonListFrame extends HGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener { private static inline var TAG = "PersonListFrame"; public static inline var ID = "person_list"; - private var list:VListView; - - public function new() { - super(); - } - public function init() { list = findViewById("list"); list.dispatcher.addListener(this); @@ -33,7 +27,11 @@ class PersonListFrame extends HGroupView implements IPacketHandler implements Li public function onShow() { list.data = Provider.get(GameData).account.persons; - Provider.get(IConnection).packetHandler = this; + Provider.get(IConnection).packetHandler.addListener(this); + } + + public function onHide() { + Provider.get(IConnection).packetHandler.removeListener(this); } public function onListItemClick(item:IListItemView):Void { diff --git a/src/client/resources/gui/main.json b/src/client/resources/gui/main.json deleted file mode 100755 index 6e23bd5..0000000 --- a/src/client/resources/gui/main.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "type":"haxework.frame.FrameSwitcher", - "skin":{"type":"haxework.gui.skin.BitmapSkin", "image":"@~image:resources/images/background.png", "fillType":"REPEAT"}, - "views":[ - { - "id":"menu", "type":"haxework.gui.VGroupView", - "pWidth":100, "pHeight":100, - "views":[ - { - "id":"logo", "type":"haxework.gui.SpriteView", "contentSize":true, - "skin":{"type":"haxework.gui.skin.BitmapSkin", "image":"@~image:resources/images/logo/logo.png"} - }, - { - "type":"haxework.gui.VGroupView", "contentSize":true, - "views":[ - { - "id":"start1", "type":"haxework.gui.ButtonView", "_include":"button", - "text":"1 Player", "onPress":"#listener" - }, - { - "id":"start2", "type":"haxework.gui.ButtonView", "_include":"button", - "text":"2 Player", "onPress":"#listener" - }, - { - "id":"options", "type":"haxework.gui.ButtonView", "_include":"button", - "text":"Options", "onPress":"#listener" - }, - { - "id":"about", "type":"haxework.gui.ButtonView", "_include":"button", - "text":"About", "onPress":"#listener" - } - ] - } - ] - }, - { - "id":"game", "type":"haxework.gui.HGroupView", - "pWidth":100, "pHeight":100, - "views":[ - { - "id":"map", "type":"haxework.gui.SpriteView", - "pHeight":100, "r":1, - "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"} - }, - { - "type":"haxework.gui.VGroupView", - "pWidth":100, "pHeight":100, - "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"} - } - ] - }, - { - "id":"about", "type":"haxework.gui.VGroupView", - "pWidth":100, "pHeight":100, - "views":[ - { - "type":"haxework.gui.LabelView", "text":"@text:about", - "fontFamily":"@text:font", "fontEmbed":true, "fontSize":48, "contentSize":true - }, - {"type":"haxework.gui.SpriteView", "height":400}, - { - "id":"back", "type":"haxework.gui.ButtonView", "_include":"button", - "text":"Back", "onPress":"#listener" - } - ] - } - ], - - "_includes":{ - "button":{ - "width":250, "height":60, - "skin":{ - "type":"haxework.gui.skin.ButtonBitmapSkin", - "upImage":"@~image:resources/images/control/button_normal.png", - "overImage":"@~image:resources/images/control/button_over.png", - "downImage":"@~image:resources/images/control/button_down.png", - "fillType":"NINEPATH" - }, - "fontFamily":"@text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20 - } - } -} \ No newline at end of file diff --git a/src/client/resources/layout/main.json b/src/client/resources/layout/main.json deleted file mode 100755 index 10c2d52..0000000 --- a/src/client/resources/layout/main.json +++ /dev/null @@ -1,189 +0,0 @@ -{ - "_includes": { - "button_skin": { - "skin": { - "type": "haxework.gui.skin.ButtonBitmapSkin", - "upImage": "@~image:resources/images/control/button_normal.png", - "downImage": "@~image:resources/images/control/button_down.png", - "overImage": "@~image:resources/images/control/button_over.png", - "fillType": "NINEPATH" - }, - "fontColor": "0xffffff" - } - }, - - "type": "haxework.gui.VGroupView", - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id":"top", "type": "haxework.gui.HGroupView", - "pWidth": 100, "height": 30, - "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0x105000"}, - "views": [ - { - "id": "logout", "type": "haxework.gui.ButtonView", - "width": 100, "height": 30, - "text": "Logout", - "_include": "button_skin" - } - ] - }, - { - "id": "switcher", "type": "haxework.frame.FrameSwitcher", - "pWidth": 100, "pHeight": 100, - "skin": {"type": "haxework.gui.skin.BitmapSkin", "image": "@~image:resources/images/background.png", "fillType": "REPEAT"}, - "views": [ - - { - "id": "auth", "type": "ru.m.tankz.view.frames.AuthFrame", - "pWidth": 100, "pHeight": 100, "layoutMargin": 3, - "views": [ - { - "id": "login", "type": "haxework.gui.HGroupView", - "contentSize": true, - "views": [ - { - "type": "haxework.gui.LabelView", - "width": 150, "height": 25, "text": "Login" - }, - { - "id": "input", "type": "haxework.gui.InputView", - "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, - "width": 200, "height": 25, "text": "" - } - ] - }, - { - "id": "password", "type": "haxework.gui.HGroupView", - "contentSize": true, - "views": [ - { - "type": "haxework.gui.LabelView", - "width": 150, "height": 25, "text": "Password" - }, - { - "id": "input", "type": "haxework.gui.InputView", - "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, - "width": 200, "height": 25, "text": "" - } - ] - }, - - { - "id": "auth", - "type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Auth", - "_include": "button_skin" - } - ] - }, - - - { - "id": "person_list", "type": "ru.m.tankz.view.frames.PersonListFrame", - "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10, - "views": [ - { - "id": "list", "type": "haxework.gui.list.VListView", - "factory": { - "type": "~ru.m.tankz.view.frames.list.PersonView" - }, - "scroll": { - "type": "haxework.gui.list.VScrollView", - "skin": {"type": "haxework.gui.list.VScrollSkin"} - }, - "pWidth": 100, "pHeight": 100, "layoutMargin": 5 - } - ] - }, - - - { - "id": "game_list", "type": "ru.m.tankz.view.frames.GameListFrame", - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id": "name", "type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" - }, - { - "id": "create", "type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Create", - "_include": "button_skin" - }, - { - "id": "list", "type": "haxework.gui.list.VListView", - "factory": { - "type": "~ru.m.tankz.view.frames.list.GameView" - }, - "scroll": { - "type": "haxework.gui.list.VScrollView", - "skin": {"type": "haxework.gui.list.VScrollSkin"} - }, - "pWidth": 100, "pHeight": 100, "layoutMargin": 5 - } - ] - }, - - - { - "id": "game_ready", "type": "ru.m.tankz.view.frames.GameReadyFrame", - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id": "name", "type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" - }, - { - "id": "start", "type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Start", - "_include": "button_skin" - }, - { - "id": "exit", "type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Exit", - "_include": "button_skin" - }, - { - "id": "list", "type": "haxework.gui.list.VListView", - "factory": { - "type": "~ru.m.tankz.view.frames.list.PersonView" - }, - "scroll": { - "type": "haxework.gui.list.VScrollView", - "skin": {"type": "haxework.gui.list.VScrollSkin"} - }, - "pWidth": 100, "pHeight": 100, "layoutMargin": 5 - } - ] - }, - - - { - "id": "game", "type": "ru.m.tankz.view.frames.GameFrame", - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id": "name", "type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" - }, - { - "id": "restart", "type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Restart", - "_include": "button_skin" - }, - { - "id": "render", "type": "ru.m.tankz.render.Render", - "contentSize": true - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/common/haxe/ru/m/core/connect/BaseConnection.hx b/src/common/haxe/ru/m/core/connect/BaseConnection.hx index 0a84ee8..d72e9cb 100755 --- a/src/common/haxe/ru/m/core/connect/BaseConnection.hx +++ b/src/common/haxe/ru/m/core/connect/BaseConnection.hx @@ -1,26 +1,27 @@ package ru.m.core.connect; +import haxework.dispath.Dispatcher; +import haxework.dispath.IDispatcher; import haxework.provider.Provider; -import haxework.net.callback.ICallback; import haxe.io.Bytes; import protohx.Message; import ru.m.core.connect.IConnection; class BaseConnection implements IConnection { - public var handler(default,default):IConnectionHandler; - public var packetHandler(default,default):IPacketHandler; + public var handler(default,default):IDispatcher; + public var packetHandler(default,default):IDispatcher; public var connected(default, null):Bool; public var queue(default, null):PacketQueue; public var builder(default, null):IPacketBuilder; - public function new(?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler) { + public function new() { this.builder = Provider.get(IPacketBuilder); this.queue = new PacketQueue(builder); - this.packetHandler = packetHandler; - this.handler = handler; + this.handler = new Dispatcher(); + this.packetHandler = new Dispatcher(); } - public function connect():ICallback { + public function connect():Void { throw "Not implemented"; } @@ -36,7 +37,7 @@ class BaseConnection implements IConnection { receive(packet); } catch (error:Dynamic) { trace(error); - handler.onError(error); + handler.dispatch(function(h) h.onError(error)); } } } @@ -46,13 +47,14 @@ class BaseConnection implements IConnection { public function receive(packet:Message):Void { L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop()); - if (packetHandler == null) return; var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop(); - var method = Reflect.field(packetHandler, name); - if (method != null && Reflect.isFunction(method)) { - Reflect.callMethod(packetHandler, method, [packet]); - } else { - packetHandler.onPacket(packet); - } + packetHandler.dispatch(function(h) { + var method = Reflect.field(h, name); + if (method != null && Reflect.isFunction(method)) { + Reflect.callMethod(h, method, [packet]); + } else { + h.onPacket(packet); + } + }); } } \ No newline at end of file diff --git a/src/common/haxe/ru/m/core/connect/IConnection.hx b/src/common/haxe/ru/m/core/connect/IConnection.hx index a25a01d..809744c 100755 --- a/src/common/haxe/ru/m/core/connect/IConnection.hx +++ b/src/common/haxe/ru/m/core/connect/IConnection.hx @@ -1,17 +1,17 @@ package ru.m.core.connect; -import haxework.net.callback.ICallback; +import haxework.dispath.IDispatcher; import haxe.io.Bytes; import protohx.Message; interface IConnection { public var connected(default,null):Bool; - public var handler(default,default):IConnectionHandler; - public var packetHandler(default,default):IPacketHandler; + public var handler(default,default):IDispatcher; + public var packetHandler(default,default):IDispatcher; public var builder(default,null):IPacketBuilder; - public function connect():ICallback; + public function connect():Void; public function disconnect():Void; public function send(packet:Message):Void; public function pushData(bytes:Bytes):Void; diff --git a/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx b/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx index dce9993..8ab1825 100755 --- a/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx +++ b/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx @@ -1,7 +1,5 @@ package ru.m.core.connect.flash; -import haxework.net.callback.Callback; -import haxework.net.callback.ICallback; import ru.m.core.connect.IConnection.IConnectionHandler; import flash.utils.Endian; import haxe.io.BytesOutput; @@ -20,10 +18,8 @@ class FlashConnection extends BaseConnection { private var port:Int; private var socket:Socket; - private var callback:ICallback; - - public function new(host:String, port:Int, ?handler:IConnectionHandler = null) { - super(handler); + public function new(host:String, port:Int) { + super(); this.host = host; this.port = port; connected = false; @@ -36,55 +32,43 @@ class FlashConnection extends BaseConnection { socket.endian = Endian.LITTLE_ENDIAN; } - override public function connect():ICallback { - callback = Callback.build(); + override public function connect():Void { socket.connect(host, port); - return callback; } override public function disconnect():Void { if (socket.connected) { socket.close(); connected = false; - if (handler != null) handler.onDisconnected(); + handler.dispatch(function(h) h.onDisconnected()); } } private function onError(event:ErrorEvent):Void { socket.close(); connected = false; - if (handler != null) handler.onError(event); - if (callback != null) { - var c = callback; - callback = null; - c.callFail(event); - } + handler.dispatch(function(h) h.onError(event)); } private function onConnect(_):Void { connected = true; - if (handler != null) handler.onConnected(); - if (callback != null) { - var c = callback; - callback = null; - c.callSuccess(null); - } + handler.dispatch(function(h) h.onConnected()); } private function onClose(_):Void { socket.close(); connected = false; - if (handler != null) handler.onDisconnected(); + handler.dispatch(function(h) h.onDisconnected()); } private function onSocketData(_):Void { try { - var b = new flash.utils.ByteArray(); - socket.readBytes(b); - var bs = Bytes.ofData(cast b); - pushData(bs); + var b = new flash.utils.ByteArray(); + socket.readBytes(b); + var bs = Bytes.ofData(cast b); + pushData(bs); } catch (error:Dynamic) { - handler.onError(error); + handler.dispatch(function(h) h.onError(error)); } } diff --git a/src/common/haxe/ru/m/core/connect/js/JsConnection.hx b/src/common/haxe/ru/m/core/connect/js/JsConnection.hx index b469e55..6772511 100644 --- a/src/common/haxe/ru/m/core/connect/js/JsConnection.hx +++ b/src/common/haxe/ru/m/core/connect/js/JsConnection.hx @@ -1,8 +1,6 @@ package ru.m.core.connect.js; import ru.m.core.Base64; -import haxework.net.callback.Callback; -import haxework.net.callback.ICallback; import ru.m.core.connect.IConnection.IConnectionHandler; import protohx.Message; import haxe.io.Bytes; @@ -23,10 +21,8 @@ class JsConnection extends BaseConnection { private var port:Int; private var socket:WebSocket; - private var callback:ICallback; - - public function new(host:String, port:Int, ?handler:IConnectionHandler = null) { - super(handler); + public function new(host:String, port:Int) { + super(); this.host = host; this.port = port; connected = false; @@ -36,8 +32,7 @@ class JsConnection extends BaseConnection { return untyped __js__("self.socket = new WebSocket('ws://'+host+':'+port); "); } - override public function connect():ICallback { - callback = Callback.build(); + override public function connect():Void { var self = this; var decodeBytes = Base64.decodeBase64; socket = buildSocket(host, port); @@ -45,40 +40,29 @@ class JsConnection extends BaseConnection { socket.onclose = this.onClose; socket.onerror = this.onError; socket.onmessage = this.onSocketData; - return callback; } override public function disconnect():Void { socket.close(); connected = false; - if (handler != null) handler.onDisconnected(); + handler.dispatch(function(h) h.onDisconnected()); } private function onError(event:Dynamic):Void { socket.close(); connected = false; - if (handler != null) handler.onError(event); - if (callback != null) { - var c = callback; - callback = null; - c.callFail(event); - } + handler.dispatch(function(h) h.onError(event)); } private function onConnect(_):Void { connected = true; - if (handler != null) handler.onConnected(); - if (callback != null) { - var c = callback; - callback = null; - c.callSuccess(null); - } + handler.dispatch(function(h) h.onConnected()); } private function onClose(_):Void { socket.close(); connected = false; - if (handler != null) handler.onDisconnected(); + handler.dispatch(function(h) h.onDisconnected()); } private function onSocketData(event:Dynamic):Void { @@ -87,7 +71,7 @@ class JsConnection extends BaseConnection { var packet = WebSocketTools.string2packet(data, builder); receive(packet); } catch (error:Dynamic) { - handler.onError(error); + handler.dispatch(function(h) h.onError(error)); } } diff --git a/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx b/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx index 5f4bd1b..6ea0e44 100755 --- a/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx +++ b/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx @@ -10,8 +10,8 @@ class NekoConnection extends BaseConnection { public var socket(default, null):Socket; - public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) { - super(handler, packetHandler); + public function new(socket:Socket) { + super(); this.socket = socket; socket.setFastSend(true); socket.output.bigEndian = false; diff --git a/src/common/haxe/ru/m/core/connect/neko/NekoWebConnection.hx b/src/common/haxe/ru/m/core/connect/neko/NekoWebConnection.hx index bb85c6c..b751baa 100644 --- a/src/common/haxe/ru/m/core/connect/neko/NekoWebConnection.hx +++ b/src/common/haxe/ru/m/core/connect/neko/NekoWebConnection.hx @@ -11,8 +11,8 @@ class NekoWebConnection extends NekoConnection { private var opened:Bool; - public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) { - super(socket, handler, packetHandler); + public function new(socket:Socket) { + super(socket); opened = false; } diff --git a/src/server/haxe/ru/m/tankz/server/session/Session.hx b/src/server/haxe/ru/m/tankz/server/session/Session.hx index 8b79c2c..77783f0 100755 --- a/src/server/haxe/ru/m/tankz/server/session/Session.hx +++ b/src/server/haxe/ru/m/tankz/server/session/Session.hx @@ -105,10 +105,12 @@ class Session implements IConnectionHandler implements IPacketHandler { } else { var str:String = bytes.getString(0, bytes.length); if (StringTools.startsWith(str, "GET")) { - connection = new NekoWebConnection(socket, this, this); + connection = new NekoWebConnection(socket); } else { - connection = new NekoConnection(socket, this, this); + connection = new NekoConnection(socket); } + connection.handler.addListener(this); + connection.packetHandler.addListener(this); connection.pushData(bytes); } }