diff --git a/proto/base.proto b/proto/base.proto index 35201a0..964cfe0 100755 --- a/proto/base.proto +++ b/proto/base.proto @@ -31,4 +31,27 @@ message PersonSelectResponse { message ErrorResponse { required int32 code = 1; required string message = 2; +} + + + +message Game { + required int32 id = 1; + repeated Person persons = 2; +} + +message GamesRequest { + +} + +message GamesResponse { + repeated Game games = 1; +} + +message CreateGameRequest { + +} + +message CreateGameResponse { + required Game game = 1; } \ No newline at end of file diff --git a/res/layout/main.json b/res/layout/main.json index 3af625e..7c7c42c 100755 --- a/res/layout/main.json +++ b/res/layout/main.json @@ -51,7 +51,7 @@ { - "id":"person", "type":"ru.m.tankz.view.frames.PersonFrame", + "id":"person_list", "type":"ru.m.tankz.view.frames.PersonListFrame", "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"}, "pWidth":100, "pHeight":100, "layoutMargin":3, "paddings":10, "views":[ @@ -69,6 +69,43 @@ ] }, + + { + "id":"game_list", "type":"ru.m.tankz.view.frames.GameListFrame", + "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"}, + "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":30, + "skin":{"type":"haxework.gui.skin.ButtonColorSkin"}, + "text":"Create" + }, + { + "id":"logout", "type":"haxework.gui.ButtonView", + "width":100, "height":30, + "skin":{"type":"haxework.gui.skin.ButtonColorSkin"}, + "text":"Logout" + }, + { + "id":"list", "type":"haxework.gui.list.VListView", + "factory":{ + "type":"~ru.m.tankz.view.frames.game.GameView" + }, + "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", "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"}, diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 27bc880..8206a47 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -19,11 +19,13 @@ import haxework.log.TraceLogger; class Client implements IConnectionHandler { - private static inline var TAG = "Armageddon"; + private static inline var TAG = "Tankz"; public static function main() { L.push(new TraceLogger()); + #if flash L.push(new JSLogger()); + #end L.d(TAG, Meta.getVersion()); new Client(); } 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 777eb20..ec52ebb 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx @@ -74,7 +74,7 @@ class AuthFrame extends VGroupView implements IPacketHandler { so.setProperty("password", passwordInput.text); so.flush(); Provider.get(GameData).account = packet.account; - Provider.get(IFrameSwitcher).change(PersonFrame.ID); + Provider.get(IFrameSwitcher).change(PersonListFrame.ID); } public function onErrorResponse(packet:ErrorResponse):Void { diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx new file mode 100644 index 0000000..ae0fb46 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx @@ -0,0 +1,69 @@ +package ru.m.tankz.view.frames; + +import ru.m.tankz.proto.CreateGameResponse; +import ru.m.tankz.proto.CreateGameRequest; +import ru.m.tankz.view.frames.game.GameView; +import haxework.frame.IFrameSwitcher; +import haxework.gui.ButtonView; +import haxework.gui.LabelView; +import ru.m.tankz.proto.GamesResponse; +import ru.m.tankz.proto.GamesRequest; +import ru.m.tankz.proto.Game; +import haxework.gui.list.ListView; +import protohx.Message; +import ru.m.core.connect.IConnection; +import ru.m.tankz.data.GameData; +import haxework.provider.Provider; +import haxework.gui.list.VListView; +import haxework.gui.VGroupView; + +class GameListFrame extends VGroupView 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); + findViewById("logout", ButtonView).onPress = this; + findViewById("create", ButtonView).onPress = this; + } + + public function onShow() { + findViewById("name", LabelView).text = Provider.get(GameData).person.name; + Provider.get(IConnection).packetHandler = this; + Provider.get(IConnection).send(new GamesRequest()); + } + + public function onListItemClick(item:IListItemView):Void { + L.d(TAG, "game selected: ", item.data.id); + Provider.get(IFrameSwitcher).change(GameFrame.ID); + } + + public function onGamesResponse(packet:GamesResponse):Void { + list.data = packet.games; + } + + public function onCreateGameResponse(packet:CreateGameResponse):Void { + list.data.push(packet.game); + list.update(); + } + + public function onPacket(packet:Message):Void {} + + public function onPress(view:ButtonView):Void { + switch (view.id) { + case "logout": + Provider.get(IConnection).disconnect(); + case "create": + Provider.get(IConnection).send(new CreateGameRequest()); + } + } +} diff --git a/src/client/haxe/ru/m/tankz/view/frames/PersonFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx similarity index 76% rename from src/client/haxe/ru/m/tankz/view/frames/PersonFrame.hx rename to src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx index b949cd7..1346263 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/PersonFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx @@ -1,5 +1,6 @@ package ru.m.tankz.view.frames; +import ru.m.tankz.view.frames.GameListFrame; import haxework.frame.IFrameSwitcher; import ru.m.tankz.proto.PersonSelectResponse; import ru.m.tankz.proto.PersonSelectRequest; @@ -13,11 +14,11 @@ import ru.m.tankz.proto.Person; import haxework.gui.list.VListView; import haxework.gui.HGroupView; -class PersonFrame extends HGroupView implements IPacketHandler implements ListViewListener { +class PersonListFrame extends HGroupView implements IPacketHandler implements ListViewListener { - private static inline var TAG = "PersonFrame"; + private static inline var TAG = "PersonListFrame"; - public static inline var ID = "person"; + public static inline var ID = "person_list"; private var list:VListView; @@ -41,7 +42,7 @@ class PersonFrame extends HGroupView implements IPacketHandler implements ListVi public function onPersonSelectResponse(packet:PersonSelectResponse):Void { Provider.get(GameData).person = packet.person; - Provider.get(IFrameSwitcher).change(GameFrame.ID); + Provider.get(IFrameSwitcher).change(GameListFrame.ID); } public function onPacket(packet:Message):Void {} diff --git a/src/client/haxe/ru/m/tankz/view/frames/game/GameView.hx b/src/client/haxe/ru/m/tankz/view/frames/game/GameView.hx new file mode 100644 index 0000000..2dc88cc --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/frames/game/GameView.hx @@ -0,0 +1,31 @@ +package ru.m.tankz.view.frames.game; + +import ru.m.tankz.proto.Game; +import haxework.gui.list.ListView.IListItemView; +import haxework.gui.LabelView; +import haxework.gui.skin.ColorSkin; +import haxework.gui.HGroupView; + +class GameView extends HGroupView implements IListItemView { + + public var item_index(default, default):Int; + public var data(default, set):Game; + + private var nameLabel:LabelView; + + public function new() { + super(); + pWidth = 100; + height = 50; + skin = new ColorSkin(0xffffff); + + nameLabel = new LabelView(); + addView(nameLabel); + } + + private function set_data(value:Game):Game { + this.data = value; + nameLabel.text = "Game_" + this.data.id; + return this.data; + } +} \ No newline at end of file diff --git a/src/common/haxe/ru/m/tankz/PacketBuilder.hx b/src/common/haxe/ru/m/tankz/PacketBuilder.hx index d542d6f..b880771 100755 --- a/src/common/haxe/ru/m/tankz/PacketBuilder.hx +++ b/src/common/haxe/ru/m/tankz/PacketBuilder.hx @@ -7,6 +7,10 @@ import ru.m.tankz.proto.LoginResponse; import ru.m.tankz.proto.PersonSelectRequest; import ru.m.tankz.proto.PersonSelectResponse; import ru.m.tankz.proto.ErrorResponse; +import ru.m.tankz.proto.GamesRequest; +import ru.m.tankz.proto.GamesResponse; +import ru.m.tankz.proto.CreateGameRequest; +import ru.m.tankz.proto.CreateGameResponse; class PacketBuilder implements IPacketBuilder { @@ -19,6 +23,12 @@ class PacketBuilder implements IPacketBuilder { 0x0002 => LoginResponse, 0x0003 => PersonSelectRequest, 0x0004 => PersonSelectResponse + ], + 0x02 => [ + 0x0001 => GamesRequest, + 0x0002 => GamesResponse, + 0x0003 => CreateGameRequest, + 0x0004 => CreateGameResponse, ] ]; diff --git a/src/client/haxe/ru/m/tankz/config/TankzConfig.hx b/src/common/haxe/ru/m/tankz/config/TankzConfig.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/config/TankzConfig.hx rename to src/common/haxe/ru/m/tankz/config/TankzConfig.hx diff --git a/src/client/haxe/ru/m/tankz/core/Direction.hx b/src/common/haxe/ru/m/tankz/core/Direction.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/Direction.hx rename to src/common/haxe/ru/m/tankz/core/Direction.hx diff --git a/src/client/haxe/ru/m/tankz/core/Entity.hx b/src/common/haxe/ru/m/tankz/core/Entity.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/Entity.hx rename to src/common/haxe/ru/m/tankz/core/Entity.hx diff --git a/src/client/haxe/ru/m/tankz/core/IEntity.hx b/src/common/haxe/ru/m/tankz/core/IEntity.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/IEntity.hx rename to src/common/haxe/ru/m/tankz/core/IEntity.hx diff --git a/src/client/haxe/ru/m/tankz/core/IMobileEntity.hx b/src/common/haxe/ru/m/tankz/core/IMobileEntity.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/IMobileEntity.hx rename to src/common/haxe/ru/m/tankz/core/IMobileEntity.hx diff --git a/src/client/haxe/ru/m/tankz/core/ITank.hx b/src/common/haxe/ru/m/tankz/core/ITank.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/ITank.hx rename to src/common/haxe/ru/m/tankz/core/ITank.hx diff --git a/src/client/haxe/ru/m/tankz/core/MobileEntity.hx b/src/common/haxe/ru/m/tankz/core/MobileEntity.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/MobileEntity.hx rename to src/common/haxe/ru/m/tankz/core/MobileEntity.hx diff --git a/src/client/haxe/ru/m/tankz/core/PlayerTank.hx b/src/common/haxe/ru/m/tankz/core/PlayerTank.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/PlayerTank.hx rename to src/common/haxe/ru/m/tankz/core/PlayerTank.hx diff --git a/src/client/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/core/Tank.hx rename to src/common/haxe/ru/m/tankz/core/Tank.hx diff --git a/src/client/haxe/ru/m/tankz/game/ITankz.hx b/src/common/haxe/ru/m/tankz/game/ITankz.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/game/ITankz.hx rename to src/common/haxe/ru/m/tankz/game/ITankz.hx diff --git a/src/client/haxe/ru/m/tankz/game/Tankz.hx b/src/common/haxe/ru/m/tankz/game/Tankz.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/game/Tankz.hx rename to src/common/haxe/ru/m/tankz/game/Tankz.hx diff --git a/src/client/haxe/ru/m/tankz/map/ITankzMap.hx b/src/common/haxe/ru/m/tankz/map/ITankzMap.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/map/ITankzMap.hx rename to src/common/haxe/ru/m/tankz/map/ITankzMap.hx diff --git a/src/client/haxe/ru/m/tankz/map/TankzMap.hx b/src/common/haxe/ru/m/tankz/map/TankzMap.hx similarity index 100% rename from src/client/haxe/ru/m/tankz/map/TankzMap.hx rename to src/common/haxe/ru/m/tankz/map/TankzMap.hx 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 6408c55..9e413f5 100755 --- a/src/server/haxe/ru/m/tankz/server/session/Session.hx +++ b/src/server/haxe/ru/m/tankz/server/session/Session.hx @@ -1,5 +1,8 @@ package ru.m.tankz.server.session; +import ru.m.tankz.proto.Game; +import ru.m.tankz.proto.CreateGameResponse; +import ru.m.tankz.proto.CreateGameRequest; import ru.m.core.connect.neko.NekoWebConnection; import haxe.io.Bytes; import ru.m.tankz.proto.PersonSelectResponse; @@ -10,12 +13,18 @@ import ru.m.tankz.proto.ErrorResponse; import ru.m.tankz.server.db.Db; import ru.m.tankz.proto.LoginResponse; import ru.m.tankz.proto.LoginRequest; +import ru.m.tankz.proto.GamesRequest; +import ru.m.tankz.proto.GamesResponse; import protohx.Message; import ru.m.core.connect.IConnection; import sys.net.Socket; class Session implements IConnectionHandler implements IPacketHandler { + private static var game_id:Int = 0; + private static var games:Array = new Array(); + + public var account(default, null):Account; private var connection(default, null):IConnection; @@ -81,6 +90,16 @@ class Session implements IConnectionHandler implements IPacketHandler { } } + public function onGamesRequest(packet:GamesRequest):Void { + connection.send(new GamesResponse().setGames(games)); + } + + public function onCreateGameRequest(packet:CreateGameRequest):Void { + var game = new Game().setId(game_id++); + games.push(game); + connection.send(new CreateGameResponse().setGame(game)); + } + public function onPacket(packet:Message):Void { trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop()); }