[network] update
This commit is contained in:
@@ -20,11 +20,6 @@ import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.MultiplayerStorage;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
#if flash
|
||||
import flash.Lib;
|
||||
#elseif html5
|
||||
import js.Browser;
|
||||
#end
|
||||
|
||||
class Init {
|
||||
|
||||
@@ -41,19 +36,16 @@ class Init {
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
|
||||
private static function getHost():String {
|
||||
private static function buildConnection():IConnection<Request, Response> {
|
||||
var host:String = CompilationOption.get("host");
|
||||
var port:Int = CompilationOption.get("port");
|
||||
L.d("Init", 'connect to $host:$port');
|
||||
#if flash
|
||||
var url = Lib.current.loaderInfo.url;
|
||||
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
|
||||
if (r.match(url) && !(r.matched(1) == "app")) {
|
||||
return r.matched(2);
|
||||
} else {
|
||||
return "localhost";
|
||||
}
|
||||
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||
#elseif html5
|
||||
return Browser.location.hostname;
|
||||
return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||
#else
|
||||
return "localhost";
|
||||
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -72,15 +64,7 @@ class Init {
|
||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||
|
||||
var host:String = getHost();
|
||||
L.d('Init', 'host: ${host}');
|
||||
#if flash
|
||||
connection = new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response);
|
||||
#elseif html5
|
||||
connection = new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response);
|
||||
#else
|
||||
connection = new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, 5000, Response);
|
||||
#end
|
||||
connection = buildConnection();
|
||||
networkManager = new NetworkManager();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,18 +133,21 @@ class NetworkManager {
|
||||
listGameSignal.emit(packet.listGame.games);
|
||||
} else if (packet.hasCreateGame()) {
|
||||
game = packet.createGame.game;
|
||||
gameSignal.emit(packet.createGame.game);
|
||||
gameSignal.emit(game);
|
||||
} else if (packet.hasJoinGame()) {
|
||||
game = packet.createGame.game;
|
||||
gameSignal.emit(packet.joinGame.game);
|
||||
game = packet.joinGame.game;
|
||||
gameSignal.emit(game);
|
||||
} else if (packet.hasLeaveGame()) {
|
||||
if (packet.leaveGame.user.uuid == user.uuid) {
|
||||
game = null;
|
||||
gameSignal.emit(null);
|
||||
} else {
|
||||
gameSignal.emit(packet.leaveGame.game);
|
||||
game = packet.leaveGame.game;
|
||||
gameSignal.emit(game);
|
||||
}
|
||||
} else if (packet.hasStartGame()) {
|
||||
gameSignal.emit(packet.startGame.game);
|
||||
game = packet.startGame.game;
|
||||
gameSignal.emit(game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.list.ListView.IListItemView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
|
||||
@:template class GameItemView extends HGroupView implements IListItemView<GameProto> {
|
||||
@@ -14,7 +14,7 @@ import ru.m.tankz.proto.core.GameProto;
|
||||
|
||||
private function set_data(value:GameProto):GameProto {
|
||||
data = value;
|
||||
label.text = '${value.id}. ${value.type} - ${value.level} (${value.creator.name})';
|
||||
label.text = '[${value.creator.name}] ${value.type} ${value.level} (${value.players.length})';
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ import ru.m.tankz.proto.core.GameProto;
|
||||
}
|
||||
|
||||
private function onGame(game:GameProto):Void {
|
||||
switcher.change(GameRoomFrame.ID);
|
||||
if (game != null) {
|
||||
switcher.change(GameRoomFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
private function selectGame(game:GameProto):Void {
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.TextView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
@:template class GameRoomFrame extends VGroupView {
|
||||
|
||||
public static inline var ID = "game_room";
|
||||
|
||||
@:view var info:TextView;
|
||||
@:view var players:VListView<UserProto>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
private function refresh(game:GameProto):Void {
|
||||
info.text = '${game.id}. ${game.type}';
|
||||
if (game != null) {
|
||||
info.text = '[${game.creator.name}] ${game.type} ${game.level} (${game.players.length})';
|
||||
players.data = game.players;
|
||||
} else {
|
||||
Timer.delay(function() switcher.change(GameListFrame.ID), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
|
||||
@@ -10,11 +10,16 @@ views:
|
||||
skinId: text.header
|
||||
text: Game Room
|
||||
- id: info
|
||||
$type: haxework.view.TextView
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.width: 100%
|
||||
skinId: text.box
|
||||
- id: players
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.size.stretch: true
|
||||
factory: $code:ru.m.tankz.view.network.PlayerItemView.factory
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
views:
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:switcher.change('start')
|
||||
+onPress: $code:network.leaveGame()
|
||||
|
||||
24
src/client/haxe/ru/m/tankz/view/network/PlayerItemView.hx
Normal file
24
src/client/haxe/ru/m/tankz/view/network/PlayerItemView.hx
Normal file
@@ -0,0 +1,24 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
@:template class PlayerItemView extends HGroupView implements IListItemView<UserProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):UserProto;
|
||||
|
||||
@:view var label:LabelView;
|
||||
|
||||
private function set_data(value:UserProto):UserProto {
|
||||
data = value;
|
||||
label.text = '${value.name}';
|
||||
return data;
|
||||
}
|
||||
|
||||
public static function factory():PlayerItemView {
|
||||
return new PlayerItemView();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
geometry.size.width: 100%
|
||||
geometry.size.height: 48
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.view.LabelView
|
||||
geometry.size.stretch: true
|
||||
skinId: text.box
|
||||
Reference in New Issue
Block a user