diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 0ec72a8..2dfa04c 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -1,13 +1,8 @@ package ru.m.tankz; -import ru.m.tankz.network.NetworkManager; -import ru.m.tankz.storage.UserStorage; -import openfl.Assets; -import ru.m.tankz.sound.SoundManager; import flash.events.KeyboardEvent; import flash.text.Font; import flash.ui.Keyboard; -import haxework.gui.ButtonView; import haxework.gui.frame.IFrameSwitcher; import haxework.gui.Root; import haxework.gui.VGroupView; @@ -16,29 +11,20 @@ import haxework.log.TraceLogger; import haxework.provider.Provider; import haxework.resources.IResources; import haxework.resources.Resources; +import openfl.Assets; import ru.m.connect.IConnection; -import ru.m.tankz.bundle.ConfigBundle; -import ru.m.tankz.bundle.IConfigBundle; -import ru.m.tankz.bundle.ILevelBundle; -import ru.m.tankz.bundle.LevelBundle; import ru.m.tankz.frame.StartFrame; -import ru.m.tankz.game.ClassicGame; -import ru.m.tankz.game.DotaGame; -import ru.m.tankz.game.Game; import ru.m.tankz.PacketBuilder; -import ru.m.tankz.storage.SaveStorage; #if flash import haxework.log.JSLogger; #end #if debug import haxework.log.SocketLogger; #end -interface ClientViewLayout { +interface ClientLayout { var switcher(default, null):IFrameSwitcher; } @:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml') -class ClientView extends VGroupView implements ClientViewLayout implements ViewBuilder {} - -class Client implements IConnectionHandler { +class Client extends VGroupView implements ClientLayout implements ViewBuilder { private static inline var TAG = 'Tankz'; @@ -51,16 +37,15 @@ class Client implements IConnectionHandler { L.push(new SocketLogger()); #end Const.init(); + Init.init(); L.d(TAG, 'Debug: ${Const.DEBUG}'); L.i(TAG, 'Version: ${Const.VERSION}'); L.i(TAG, 'Build: ${Const.BUILD}'); - new Client(); + var client:Client = new Client(); + Root.bind(client); } - - private var view:ClientView; - - public function new() { + public function init() { Provider.setFactory(IResources, Resources); var font:Font = Font.enumerateFonts()[0]; @@ -78,49 +63,20 @@ class Client implements IConnectionHandler { Provider.get(IConnection).handler.addListener(this); - view = new ClientView(); - Provider.set(IFrameSwitcher, view.switcher); - Root.bind(view); - view.content.stage.stageFocusRect = false; + Provider.set(IFrameSwitcher, switcher); + content.stage.stageFocusRect = false; - view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void { + content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void { if (event.keyCode == Keyboard.ESCAPE) { - view.switcher.change(StartFrame.ID); + switcher.change(StartFrame.ID); } }); - Provider.setFactory(IConfigBundle, ConfigBundle); - Provider.setFactory(ILevelBundle, LevelBundle); - Provider.setFactory(SaveStorage, SaveStorage); - Provider.setFactory(UserStorage, UserStorage); - Provider.setFactory(SoundManager, SoundManager); - Provider.setFactory(NetworkManager, NetworkManager); - Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE); - Provider.setFactory(Game, DotaGame, DotaGame.TYPE); - L.d(TAG, 'resources'); for (resource in Assets.list()) { L.d(TAG, '\t${resource}'); } - view.switcher.change(StartFrame.ID); - } - - public function onPress(view:ButtonView):Void { - switch (view.id) { - case 'logout': - Provider.get(IConnection).disconnect(); - } - } - - public function onConnected():Void {} - - public function onDisconnected():Void { - view.switcher.change(StartFrame.ID); - } - - public function onError(error:Dynamic):Void { - L.e(TAG, '', error); - //view.switcher.change(StartFrame.ID); + switcher.change(StartFrame.ID); } } diff --git a/src/client/haxe/ru/m/tankz/Init.hx b/src/client/haxe/ru/m/tankz/Init.hx new file mode 100644 index 0000000..ebf8d91 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/Init.hx @@ -0,0 +1,29 @@ +package ru.m.tankz; + +import haxework.provider.Provider; +import ru.m.tankz.bundle.ConfigBundle; +import ru.m.tankz.bundle.IConfigBundle; +import ru.m.tankz.bundle.ILevelBundle; +import ru.m.tankz.bundle.LevelBundle; +import ru.m.tankz.game.ClassicGame; +import ru.m.tankz.game.DotaGame; +import ru.m.tankz.game.Game; +import ru.m.tankz.network.NetworkManager; +import ru.m.tankz.sound.SoundManager; +import ru.m.tankz.storage.SaveStorage; +import ru.m.tankz.storage.UserStorage; + + +class Init { + + public static function init():Void { + Provider.setFactory(IConfigBundle, ConfigBundle); + Provider.setFactory(ILevelBundle, LevelBundle); + Provider.setFactory(SaveStorage, SaveStorage); + Provider.setFactory(UserStorage, UserStorage); + Provider.setFactory(SoundManager, SoundManager); + Provider.setFactory(NetworkManager, NetworkManager); + Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE); + Provider.setFactory(Game, DotaGame, DotaGame.TYPE); + } +} diff --git a/src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx b/src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx index 74b96dc..29a44c1 100644 --- a/src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx @@ -1,5 +1,9 @@ package ru.m.tankz.frame; +import ru.m.tankz.proto.core.Game; +import haxework.gui.list.ListView; +import haxework.gui.IGroupView; +import haxework.gui.frame.IFrameSwitcher; import haxework.gui.ButtonView; import haxework.gui.InputView; import haxework.gui.LabelView; @@ -10,9 +14,16 @@ import ru.m.tankz.network.NetworkManager; interface NetworkFrameLayout { + var frameSwitcher(default, null):IFrameSwitcher; + + var loginFrame(default, null):IGroupView; var stateLabel(default, null):LabelView; var nameInput(default, null):InputView; var loginButton(default, null):ButtonView; + + var gameListFrame(default, null):IGroupView; + var createGameButton(default, null):ButtonView; + var gameList(default, null):ListView; } @:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml") @@ -27,6 +38,7 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF public function init():Void { loginButton.onPress = this; + createGameButton.onPress = this; } public function onShow():Void { @@ -38,6 +50,12 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF private function onStateChange(state:String):Void { loginButton.disabled = !(state == "offline" || state == "error"); stateLabel.text = state; + if (state == 'online') { + gameList.data = []; + frameSwitcher.change(gameListFrame.id); + } else { + frameSwitcher.change(loginFrame.id); + } } public function onHide():Void { @@ -45,6 +63,11 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF } public function onPress(view:ButtonView):Void { - network.login(nameInput.text); + switch (view.id) { + case 'loginButton': + network.login(nameInput.text); + case 'createGameButton': + + } } } \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml b/src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml index 91152ec..6a8bb9b 100644 --- a/src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml +++ b/src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml @@ -2,22 +2,59 @@ pWidth: 100 pHeight: 100 views: - - id: stateLabel - $type: haxework.gui.LabelView - $style: label - text: offline - width: 200 - height: 50 - - id: nameInput - $type: haxework.gui.InputView - $style: label - width: 200 - height: 50 - text: User - skin: - $type: haxework.gui.skin.ColorSkin - color: '#444444' - - id: loginButton - $type: haxework.gui.ButtonView - $style: button - text: Login \ No newline at end of file +- id: frameSwitcher + $type: haxework.gui.frame.FrameSwitcher + pWidth: 100 + pHeight: 100 + views: + # login + - id: loginFrame + $type: haxework.gui.VGroupView + pWidth: 100 + pHeight: 100 + views: + - id: stateLabel + $type: haxework.gui.LabelView + $style: label + text: offline + width: 200 + height: 50 + - id: nameInput + $type: haxework.gui.InputView + $style: label + width: 200 + height: 50 + text: User + skin: + $type: haxework.gui.skin.ColorSkin + color: '#444444' + - id: loginButton + $type: haxework.gui.ButtonView + $style: button + text: Login + # game list + - id: gameListFrame + $type: haxework.gui.VGroupView + pWidth: 100 + pHeight: 100 + views: + - id: createGameButton + $type: haxework.gui.ButtonView + $style: button + text: Create + - id: gameList + $type: haxework.gui.list.VListView + factory: "@class:ru.m.tankz.frame.network.GameItemView" + pWidth: 100 + pHeight: 100 + paddings: 10 + scroll: + $type: haxework.gui.list.VScrollView + width: 10 + pHeight: 100 + skin: + $type: haxework.gui.list.VScrollSkin + skin: + $type: haxework.gui.skin.ColorSkin + color: "#000000" + alpha: 0 \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx b/src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx new file mode 100755 index 0000000..f69185a --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx @@ -0,0 +1,25 @@ +package ru.m.tankz.frame.network; + +import ru.m.tankz.proto.core.Game; +import haxework.gui.HGroupView; +import haxework.gui.LabelView; +import haxework.gui.list.ListView; +import haxework.gui.ViewBuilder; + + +interface GameItemViewLayout { + var label(default, null):LabelView; +} + +@:template("ru/m/tankz/frame/network/GameItemView.yaml", "ru/m/tankz/Style.yaml") +class GameItemView extends HGroupView implements ViewBuilder implements IListItemView implements GameItemViewLayout { + + public var item_index(default, default):Int; + public var data(default, set):Game; + + private function set_data(value:Game):Game { + data = value; + label.text = '${data.type}'; + return data; + } +} \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml b/src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml new file mode 100644 index 0000000..1cf0139 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml @@ -0,0 +1,15 @@ +--- +width: 440 +height: 44 +margins: 5 +views: +- id: label + $type: haxework.gui.LabelView + $style: label + pWidth: 100 + pHeight: 100 + text: "" +skin: + $type: haxework.gui.skin.ColorSkin + color: "#000000" + alpha: 0.2 diff --git a/src/common/haxe/ru/m/connect/IConnection.hx b/src/common/haxe/ru/m/connect/IConnection.hx index dda625f..c66e3ac 100755 --- a/src/common/haxe/ru/m/connect/IConnection.hx +++ b/src/common/haxe/ru/m/connect/IConnection.hx @@ -1,41 +1,42 @@ package ru.m.connect; -import promhx.Promise; -import haxework.dispath.IDispatcher; import haxe.io.Bytes; +import hxsignal.impl.Signal1; +import promhx.Promise; import protohx.Message; + interface IConnection { - public var connected(default,null):Bool; - public var handler(default,default):IDispatcher; - public var packetHandler(default,default):IDispatcher; + public var connected(default, null):Bool; + public var handler(default, default):Signal1; + public var packetHandler(default, default):Signal1; - public var builder(default,null):IPacketBuilder; + public var builder(default, null):IPacketBuilder; - public function connect():Void; - public function disconnect():Void; - public function send(packet:Message):Void; - public function pushData(bytes:Bytes):Void; + public function connect():Promise; + public function disconnect():Void; + public function send(packet:Message):Void; + public function pushData(bytes:Bytes):Void; - public function receive(packet:Message):Void; + public function receive(packet:Message):Void; } interface IConnectionHandler { - public function onConnected():Void; - public function onDisconnected():Void; - public function onError(error:Dynamic):Void; + public function onConnected():Void; + public function onDisconnected():Void; + public function onError(error:Dynamic):Void; } interface IPacketHandler { - public function onPacket(packet:Message):Void; + public function onPacket(packet:Message):Void; } typedef PacketMeta = { - var family:Int; - var id:Int; + var family:Int; + var id:Int; } interface IPacketBuilder { - public function packetMeta(packet:Message):PacketMeta; - public function buildPacket(meta:PacketMeta):Message; + public function packetMeta(packet:Message):PacketMeta; + public function buildPacket(meta:PacketMeta):Message; } \ No newline at end of file