[proto] update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import ru.m.tankz.proto.core.User;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.IGroupView;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
@@ -24,6 +25,10 @@ interface NetworkFrameLayout {
|
||||
var gameListFrame(default, null):IGroupView;
|
||||
var createGameButton(default, null):ButtonView;
|
||||
var gameList(default, null):ListView<Game>;
|
||||
|
||||
var gameFrame(default, null):IGroupView;
|
||||
var leaveGameButton(default, null):ButtonView;
|
||||
var userList(default, null):ListView<User>;
|
||||
}
|
||||
|
||||
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
@@ -32,13 +37,19 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
||||
|
||||
private var network(get, never):NetworkManager;
|
||||
|
||||
private function get_network():NetworkManager {
|
||||
private inline function get_network():NetworkManager {
|
||||
return Provider.get(NetworkManager);
|
||||
}
|
||||
|
||||
public function init():Void {
|
||||
loginButton.onPress = this;
|
||||
createGameButton.onPress = this;
|
||||
leaveGameButton.onPress = this;
|
||||
gameList.dispatcher.addListener({
|
||||
onListItemClick: function(item:IListItemView<Game>):Void {
|
||||
network.joinGame(item.data.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
@@ -53,12 +64,30 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
||||
if (state == 'online') {
|
||||
gameList.data = [];
|
||||
frameSwitcher.change(gameListFrame.id);
|
||||
network.listGameSignal.connect(onListGame);
|
||||
network.gameSignal.connect(onGame);
|
||||
network.listGame();
|
||||
} else {
|
||||
frameSwitcher.change(loginFrame.id);
|
||||
}
|
||||
}
|
||||
|
||||
private function onListGame(games:Array<Game>):Void {
|
||||
gameList.data = games;
|
||||
}
|
||||
|
||||
private function onGame(game:Game):Void {
|
||||
if (game != null) {
|
||||
userList.data = game.players;
|
||||
frameSwitcher.change(gameFrame.id);
|
||||
} else {
|
||||
frameSwitcher.change(gameListFrame.id);
|
||||
}
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
network.listGameSignal.disconnect(onListGame);
|
||||
network.gameSignal.disconnect(onGame);
|
||||
network.stateSignal.disconnect(onStateChange);
|
||||
}
|
||||
|
||||
@@ -67,7 +96,9 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
||||
case 'loginButton':
|
||||
network.login(nameInput.text);
|
||||
case 'createGameButton':
|
||||
|
||||
network.createGame('classic');
|
||||
case 'leaveGameButton':
|
||||
network.leaveGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,32 @@ views:
|
||||
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
|
||||
# game list
|
||||
- id: gameFrame
|
||||
$type: haxework.gui.VGroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: leaveGameButton
|
||||
$type: haxework.gui.ButtonView
|
||||
$style: button
|
||||
text: Leave
|
||||
- id: userList
|
||||
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.User>
|
||||
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
paddings: 10
|
||||
scroll:
|
||||
$type: haxework.gui.list.VScrollView
|
||||
width: 10
|
||||
|
||||
25
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
25
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
@@ -0,0 +1,25 @@
|
||||
package ru.m.tankz.frame.network;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.tankz.proto.core.User;
|
||||
|
||||
|
||||
interface UserItemViewLayout {
|
||||
var label(default, null):LabelView;
|
||||
}
|
||||
|
||||
@:template("ru/m/tankz/frame/network/UserItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class UserItemView extends HGroupView implements ViewBuilder implements IListItemView<User> implements UserItemViewLayout {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):User;
|
||||
|
||||
private function set_data(value:User):User {
|
||||
data = value;
|
||||
label.text = '${data.uuid} -- ${data.name}';
|
||||
return data;
|
||||
}
|
||||
}
|
||||
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
@@ -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
|
||||
@@ -1,8 +1,13 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.signal.Signal;
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||
import ru.m.tankz.proto.pack.LoginRequest;
|
||||
import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
@@ -15,6 +20,8 @@ class NetworkManager {
|
||||
|
||||
public var state(default, null):String;
|
||||
public var stateSignal:Signal<String>;
|
||||
public var listGameSignal:Signal<Array<Game>>;
|
||||
public var gameSignal:Signal<Game>;
|
||||
public var user(default, null):User;
|
||||
|
||||
private var connection(get, never):ClientConnection;
|
||||
@@ -30,6 +37,8 @@ class NetworkManager {
|
||||
|
||||
public function new() {
|
||||
stateSignal = new Signal<String>();
|
||||
listGameSignal = new Signal<Array<Game>>();
|
||||
gameSignal = new Signal<Game>();
|
||||
updateState('offline');
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
@@ -57,6 +66,22 @@ class NetworkManager {
|
||||
}).catchError(function(_) {});
|
||||
}
|
||||
|
||||
public function listGame():Void {
|
||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
||||
}
|
||||
|
||||
public function createGame(type:String):Void {
|
||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type)));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int):Void {
|
||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
L.d('Network', '${event}');
|
||||
updateState(switch (event) {
|
||||
@@ -74,6 +99,17 @@ class NetworkManager {
|
||||
};
|
||||
storage.write(user);
|
||||
updateState('online');
|
||||
} else if (packet.hasLogout()) {
|
||||
user = null;
|
||||
updateState('connected');
|
||||
} else if (packet.hasListGame()) {
|
||||
listGameSignal.emit(packet.listGame.games);
|
||||
} else if (packet.hasCreateGame()) {
|
||||
gameSignal.emit(packet.createGame.game);
|
||||
} else if (packet.hasJoinGame()) {
|
||||
gameSignal.emit(packet.joinGame.game);
|
||||
} else if (packet.hasLeaveGame()) {
|
||||
gameSignal.emit(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user