-
This commit is contained in:
@@ -5,12 +5,15 @@
|
|||||||
<source path="src/common/haxe"/>
|
<source path="src/common/haxe"/>
|
||||||
<source path="src/client/haxe"/>
|
<source path="src/client/haxe"/>
|
||||||
<source path="src-gen/haxe"/>
|
<source path="src-gen/haxe"/>
|
||||||
|
<assets path="res" include="*"/>
|
||||||
<haxelib name="openfl"/>
|
<haxelib name="openfl"/>
|
||||||
<haxelib name="protohx"/>
|
<haxelib name="protohx"/>
|
||||||
<haxelib name="haxework" version="git"/>
|
<haxelib name="haxework" version="git"/>
|
||||||
<window width="800" height="600" if="desktop"/>
|
<window width="800" height="600" if="desktop"/>
|
||||||
<window width="800" height="600" if="flash"/>
|
<window width="800" height="600" if="flash"/>
|
||||||
<window width="0" height="0" if="html5"/>
|
<window width="0" height="0" if="html5"/>
|
||||||
|
<haxeflag name="-D" value="swf-gpu"/>
|
||||||
|
<haxeflag name="-D" value="native-trace"/>
|
||||||
<haxeflag name="-dce" value="no"/>
|
<haxeflag name="-dce" value="no"/>
|
||||||
<haxeflag name="-debug"/>
|
<haxeflag name="-debug"/>
|
||||||
<haxeflag name="--macro" value="Meta.set('0.0.0')"/>
|
<haxeflag name="--macro" value="Meta.set('0.0.0')"/>
|
||||||
|
|||||||
50
res/layout/main.json
Executable file
50
res/layout/main.json
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"type":"haxework.gui.VGroupView",
|
||||||
|
"paddings":10,
|
||||||
|
"layoutMargin":10,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x000000"},
|
||||||
|
"views":[
|
||||||
|
{
|
||||||
|
"id":"panel",
|
||||||
|
"type":"haxework.gui.HGroupView",
|
||||||
|
"layoutHAlign":"LEFT",
|
||||||
|
"pWidth":100,
|
||||||
|
"height":30,
|
||||||
|
"paddings":3,
|
||||||
|
"layoutMargin":3,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x505050"},
|
||||||
|
"views":[
|
||||||
|
{
|
||||||
|
"id":"login",
|
||||||
|
"type":"haxework.gui.ButtonView",
|
||||||
|
"width":100,
|
||||||
|
"pHeight":100,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
|
||||||
|
"text":"Login",
|
||||||
|
"onPress":"#listener"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"connection_state",
|
||||||
|
"type":"haxework.gui.LabelView",
|
||||||
|
"width":150,
|
||||||
|
"pHeight":100,
|
||||||
|
"text":"Disconnected"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"nickname",
|
||||||
|
"type":"haxework.gui.LabelView",
|
||||||
|
"width":150,
|
||||||
|
"pHeight":100,
|
||||||
|
"text":""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type":"haxework.gui.SpriteView",
|
||||||
|
"pWidth":100,
|
||||||
|
"pHeight":100,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x000000"}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
package ru.m.armageddon.client;
|
package ru.m.armageddon.client;
|
||||||
|
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.Root;
|
||||||
|
import haxework.gui.GuiBuilder;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import haxework.gui.IGroupView;
|
||||||
|
import haxe.Json;
|
||||||
|
import openfl.Assets;
|
||||||
|
import haxe.Timer;
|
||||||
import ru.m.armageddon.proto.User;
|
import ru.m.armageddon.proto.User;
|
||||||
import ru.m.armageddon.proto.LoginResponse;
|
import ru.m.armageddon.proto.LoginResponse;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import haxe.crypto.Md5;
|
import haxe.crypto.Md5;
|
||||||
import flash.Lib;
|
|
||||||
import flash.events.MouseEvent;
|
|
||||||
import ru.m.armageddon.core.connect.flash.FlashConnection;
|
import ru.m.armageddon.core.connect.flash.FlashConnection;
|
||||||
import ru.m.armageddon.core.connect.IConnection;
|
import ru.m.armageddon.core.connect.IConnection;
|
||||||
import haxework.log.TraceLogger;
|
import haxework.log.TraceLogger;
|
||||||
@@ -25,15 +32,37 @@ class Client implements IConnectionHandler {
|
|||||||
private var connection:IConnection;
|
private var connection:IConnection;
|
||||||
private var user:User;
|
private var user:User;
|
||||||
|
|
||||||
public function new() {
|
private var loginButton:ButtonView;
|
||||||
connection = new FlashConnection("localhost", 5000, this);
|
private var connectionStateLabel:LabelView;
|
||||||
|
private var nicknameLabel:LabelView;
|
||||||
|
|
||||||
Lib.current.stage.addEventListener(MouseEvent.CLICK, function(_) {
|
public function new() {
|
||||||
onConnected();
|
var bytes = Assets.getBytes("res/layout/main.json");
|
||||||
});
|
var form:Dynamic = Json.parse(bytes.readUTFBytes(bytes.bytesAvailable));
|
||||||
|
var v:IGroupView<Sprite> = GuiBuilder.build(form, {listener:this});
|
||||||
|
new Root(v);
|
||||||
|
loginButton = v.findViewById("panel:login");
|
||||||
|
connectionStateLabel = v.findViewById("panel:connection_state");
|
||||||
|
nicknameLabel = v.findViewById("panel:nickname");
|
||||||
|
|
||||||
|
connection = new FlashConnection("localhost", 5000, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function refreshUI():Void {
|
||||||
|
connectionStateLabel.text = connection.connected ? "Connected" : "Disconnected";
|
||||||
|
nicknameLabel.text = user == null ? "" : user.nickname;
|
||||||
|
loginButton.disabled = connection.connected && user != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
switch (view.id) {
|
||||||
|
case "login":
|
||||||
|
connection.connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onConnected():Void {
|
public function onConnected():Void {
|
||||||
|
refreshUI();
|
||||||
connection.send(
|
connection.send(
|
||||||
new LoginRequest()
|
new LoginRequest()
|
||||||
.setLogin("shmyga")
|
.setLogin("shmyga")
|
||||||
@@ -42,16 +71,18 @@ class Client implements IConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onDisconnected():Void {
|
public function onDisconnected():Void {
|
||||||
|
this.user = null;
|
||||||
|
refreshUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onError(error:Dynamic):Void {
|
public function onError(error:Dynamic):Void {
|
||||||
|
this.user = null;
|
||||||
|
refreshUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onLoginResponse(packet:LoginResponse):Void {
|
public function onLoginResponse(packet:LoginResponse):Void {
|
||||||
this.user = packet.user;
|
this.user = packet.user;
|
||||||
L.d(TAG, "Loginned: " + user.nickname);
|
refreshUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPacket(packet:Message):Void {
|
public function onPacket(packet:Message):Void {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import protohx.Message;
|
|||||||
import ru.m.armageddon.core.connect.IConnection;
|
import ru.m.armageddon.core.connect.IConnection;
|
||||||
|
|
||||||
class BaseConnection implements IConnection {
|
class BaseConnection implements IConnection {
|
||||||
|
public var connected(default, null):Bool;
|
||||||
|
|
||||||
private var builder:IPacketBuilder;
|
private var builder:IPacketBuilder;
|
||||||
private var handler:IConnectionHandler;
|
private var handler:IConnectionHandler;
|
||||||
@@ -14,6 +15,8 @@ class BaseConnection implements IConnection {
|
|||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function connect():Void {}
|
||||||
|
|
||||||
public function pushData(bytes:Bytes):Void {}
|
public function pushData(bytes:Bytes):Void {}
|
||||||
|
|
||||||
public function send(packet:Message):Void {}
|
public function send(packet:Message):Void {}
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import haxe.io.Bytes;
|
|||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
|
|
||||||
interface IConnection {
|
interface IConnection {
|
||||||
|
public var connected(default, null):Bool;
|
||||||
|
|
||||||
private var builder:IPacketBuilder;
|
private var builder:IPacketBuilder;
|
||||||
private var handler:IConnectionHandler;
|
private var handler:IConnectionHandler;
|
||||||
|
|
||||||
|
public function connect():Void;
|
||||||
public function send(packet:Message):Void;
|
public function send(packet:Message):Void;
|
||||||
public function pushData(bytes:Bytes):Void;
|
public function pushData(bytes:Bytes):Void;
|
||||||
private function receive(packet:Message):Void;
|
private function receive(packet:Message):Void;
|
||||||
|
|||||||
@@ -14,10 +14,15 @@ import flash.net.Socket;
|
|||||||
|
|
||||||
class FlashConnection extends BaseConnection {
|
class FlashConnection extends BaseConnection {
|
||||||
|
|
||||||
|
private var host:String;
|
||||||
|
private var port:Int;
|
||||||
private var socket:Socket;
|
private var socket:Socket;
|
||||||
|
|
||||||
public function new(host:String, port:Int, handler:IConnectionHandler) {
|
public function new(host:String, port:Int, handler:IConnectionHandler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
connected = false;
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||||
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||||
@@ -25,18 +30,27 @@ class FlashConnection extends BaseConnection {
|
|||||||
socket.addEventListener(Event.CONNECT, onConnect);
|
socket.addEventListener(Event.CONNECT, onConnect);
|
||||||
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
|
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
|
||||||
socket.endian = Endian.LITTLE_ENDIAN;
|
socket.endian = Endian.LITTLE_ENDIAN;
|
||||||
|
//socket.connect(host, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function connect():Void {
|
||||||
socket.connect(host, port);
|
socket.connect(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onError(event:ErrorEvent):Void {
|
private function onError(event:ErrorEvent):Void {
|
||||||
|
socket.close();
|
||||||
|
connected = false;
|
||||||
handler.onError(event);
|
handler.onError(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onConnect(_):Void {
|
private function onConnect(_):Void {
|
||||||
|
connected = true;
|
||||||
handler.onConnected();
|
handler.onConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onClose(_):Void {
|
private function onClose(_):Void {
|
||||||
|
socket.close();
|
||||||
|
connected = false;
|
||||||
handler.onDisconnected();
|
handler.onDisconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user