[client] update network view
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
29
src/client/haxe/ru/m/tankz/Init.hx
Normal file
29
src/client/haxe/ru/m/tankz/Init.hx
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<Game>;
|
||||
}
|
||||
|
||||
@: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 {
|
||||
switch (view.id) {
|
||||
case 'loginButton':
|
||||
network.login(nameInput.text);
|
||||
case 'createGameButton':
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,17 @@
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- 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
|
||||
@@ -21,3 +32,29 @@ views:
|
||||
$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<ru.m.tankz.proto.core.Game>
|
||||
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
|
||||
25
src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx
Executable file
25
src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx
Executable file
@@ -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<Game> 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;
|
||||
}
|
||||
}
|
||||
15
src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml
Normal file
15
src/client/haxe/ru/m/tankz/frame/network/GameItemView.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,18 +1,19 @@
|
||||
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<IConnectionHandler>;
|
||||
public var packetHandler(default,default):IDispatcher<IPacketHandler>;
|
||||
public var connected(default, null):Bool;
|
||||
public var handler(default, default):Signal1<IConnectionHandler>;
|
||||
public var packetHandler(default, default):Signal1<IPacketHandler>;
|
||||
|
||||
public var builder(default,null):IPacketBuilder;
|
||||
public var builder(default, null):IPacketBuilder;
|
||||
|
||||
public function connect():Void;
|
||||
public function connect():Promise<IConnection>;
|
||||
public function disconnect():Void;
|
||||
public function send(packet:Message):Void;
|
||||
public function pushData(bytes:Bytes):Void;
|
||||
|
||||
Reference in New Issue
Block a user