-
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package ru.m.armageddon.client;
|
||||
|
||||
import ru.m.armageddon.proto.ErrorResponse;
|
||||
import ru.m.armageddon.proto.Account;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.Root;
|
||||
@@ -8,8 +10,6 @@ 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.LoginResponse;
|
||||
import protohx.Message;
|
||||
import haxe.crypto.Md5;
|
||||
@@ -30,11 +30,12 @@ class Client implements IConnectionHandler {
|
||||
|
||||
|
||||
private var connection:IConnection;
|
||||
private var user:User;
|
||||
private var account:Account;
|
||||
|
||||
private var loginButton:ButtonView;
|
||||
private var connectionStateLabel:LabelView;
|
||||
private var nicknameLabel:LabelView;
|
||||
private var errorLabel:LabelView;
|
||||
|
||||
public function new() {
|
||||
var bytes = Assets.getBytes("res/layout/main.json");
|
||||
@@ -44,19 +45,21 @@ class Client implements IConnectionHandler {
|
||||
loginButton = v.findViewById("panel:login");
|
||||
connectionStateLabel = v.findViewById("panel:connection_state");
|
||||
nicknameLabel = v.findViewById("panel:nickname");
|
||||
errorLabel = v.findViewById("error");
|
||||
|
||||
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;
|
||||
nicknameLabel.text = account == null ? "" : account.login;
|
||||
loginButton.disabled = connection.connected && account != null;
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case "login":
|
||||
errorLabel.text = "";
|
||||
connection.connect();
|
||||
}
|
||||
}
|
||||
@@ -71,17 +74,23 @@ class Client implements IConnectionHandler {
|
||||
}
|
||||
|
||||
public function onDisconnected():Void {
|
||||
this.user = null;
|
||||
account = null;
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
public function onError(error:Dynamic):Void {
|
||||
this.user = null;
|
||||
account = null;
|
||||
errorLabel.text = Std.string(error);
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
public function onLoginResponse(packet:LoginResponse):Void {
|
||||
this.user = packet.user;
|
||||
account = packet.account;
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
public function onErrorResponse(packet:ErrorResponse):Void {
|
||||
errorLabel.text = packet.message;
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user