-
This commit is contained in:
@@ -32,3 +32,26 @@ message ErrorResponse {
|
|||||||
required int32 code = 1;
|
required int32 code = 1;
|
||||||
required string message = 2;
|
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;
|
||||||
|
}
|
||||||
@@ -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"},
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
|
||||||
"pWidth":100, "pHeight":100, "layoutMargin":3, "paddings":10,
|
"pWidth":100, "pHeight":100, "layoutMargin":3, "paddings":10,
|
||||||
"views":[
|
"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",
|
"id":"game", "type":"ru.m.tankz.view.frames.GameFrame",
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
|
||||||
|
|||||||
@@ -19,11 +19,13 @@ import haxework.log.TraceLogger;
|
|||||||
|
|
||||||
class Client implements IConnectionHandler {
|
class Client implements IConnectionHandler {
|
||||||
|
|
||||||
private static inline var TAG = "Armageddon";
|
private static inline var TAG = "Tankz";
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
|
#if flash
|
||||||
L.push(new JSLogger());
|
L.push(new JSLogger());
|
||||||
|
#end
|
||||||
L.d(TAG, Meta.getVersion());
|
L.d(TAG, Meta.getVersion());
|
||||||
new Client();
|
new Client();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
so.setProperty("password", passwordInput.text);
|
so.setProperty("password", passwordInput.text);
|
||||||
so.flush();
|
so.flush();
|
||||||
Provider.get(GameData).account = packet.account;
|
Provider.get(GameData).account = packet.account;
|
||||||
Provider.get(IFrameSwitcher).change(PersonFrame.ID);
|
Provider.get(IFrameSwitcher).change(PersonListFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onErrorResponse(packet:ErrorResponse):Void {
|
public function onErrorResponse(packet:ErrorResponse):Void {
|
||||||
|
|||||||
69
src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
Normal file
69
src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
Normal file
@@ -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<Game> {
|
||||||
|
|
||||||
|
private static inline var TAG = "GameListFrame";
|
||||||
|
|
||||||
|
public static inline var ID = "game_list";
|
||||||
|
|
||||||
|
private var list:VListView<Game>;
|
||||||
|
|
||||||
|
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<Game>):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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import ru.m.tankz.view.frames.GameListFrame;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.frame.IFrameSwitcher;
|
||||||
import ru.m.tankz.proto.PersonSelectResponse;
|
import ru.m.tankz.proto.PersonSelectResponse;
|
||||||
import ru.m.tankz.proto.PersonSelectRequest;
|
import ru.m.tankz.proto.PersonSelectRequest;
|
||||||
@@ -13,11 +14,11 @@ import ru.m.tankz.proto.Person;
|
|||||||
import haxework.gui.list.VListView;
|
import haxework.gui.list.VListView;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
class PersonFrame extends HGroupView implements IPacketHandler implements ListViewListener<Person> {
|
class PersonListFrame extends HGroupView implements IPacketHandler implements ListViewListener<Person> {
|
||||||
|
|
||||||
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<Person>;
|
private var list:VListView<Person>;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ class PersonFrame extends HGroupView implements IPacketHandler implements ListVi
|
|||||||
|
|
||||||
public function onPersonSelectResponse(packet:PersonSelectResponse):Void {
|
public function onPersonSelectResponse(packet:PersonSelectResponse):Void {
|
||||||
Provider.get(GameData).person = packet.person;
|
Provider.get(GameData).person = packet.person;
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
Provider.get(IFrameSwitcher).change(GameListFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPacket(packet:Message):Void {}
|
public function onPacket(packet:Message):Void {}
|
||||||
31
src/client/haxe/ru/m/tankz/view/frames/game/GameView.hx
Normal file
31
src/client/haxe/ru/m/tankz/view/frames/game/GameView.hx
Normal file
@@ -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<Game> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,10 @@ import ru.m.tankz.proto.LoginResponse;
|
|||||||
import ru.m.tankz.proto.PersonSelectRequest;
|
import ru.m.tankz.proto.PersonSelectRequest;
|
||||||
import ru.m.tankz.proto.PersonSelectResponse;
|
import ru.m.tankz.proto.PersonSelectResponse;
|
||||||
import ru.m.tankz.proto.ErrorResponse;
|
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 {
|
class PacketBuilder implements IPacketBuilder {
|
||||||
|
|
||||||
@@ -19,6 +23,12 @@ class PacketBuilder implements IPacketBuilder {
|
|||||||
0x0002 => LoginResponse,
|
0x0002 => LoginResponse,
|
||||||
0x0003 => PersonSelectRequest,
|
0x0003 => PersonSelectRequest,
|
||||||
0x0004 => PersonSelectResponse
|
0x0004 => PersonSelectResponse
|
||||||
|
],
|
||||||
|
0x02 => [
|
||||||
|
0x0001 => GamesRequest,
|
||||||
|
0x0002 => GamesResponse,
|
||||||
|
0x0003 => CreateGameRequest,
|
||||||
|
0x0004 => CreateGameResponse,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package ru.m.tankz.server.session;
|
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 ru.m.core.connect.neko.NekoWebConnection;
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
import ru.m.tankz.proto.PersonSelectResponse;
|
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.server.db.Db;
|
||||||
import ru.m.tankz.proto.LoginResponse;
|
import ru.m.tankz.proto.LoginResponse;
|
||||||
import ru.m.tankz.proto.LoginRequest;
|
import ru.m.tankz.proto.LoginRequest;
|
||||||
|
import ru.m.tankz.proto.GamesRequest;
|
||||||
|
import ru.m.tankz.proto.GamesResponse;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
import sys.net.Socket;
|
import sys.net.Socket;
|
||||||
|
|
||||||
class Session implements IConnectionHandler implements IPacketHandler {
|
class Session implements IConnectionHandler implements IPacketHandler {
|
||||||
|
|
||||||
|
private static var game_id:Int = 0;
|
||||||
|
private static var games:Array<Game> = new Array<Game>();
|
||||||
|
|
||||||
|
|
||||||
public var account(default, null):Account;
|
public var account(default, null):Account;
|
||||||
|
|
||||||
private var connection(default, null):IConnection;
|
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 {
|
public function onPacket(packet:Message):Void {
|
||||||
trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop());
|
trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user