This commit is contained in:
2015-08-14 16:24:42 +03:00
parent 39ab8d30e6
commit 3643be4cd8
24 changed files with 314 additions and 71 deletions

View File

@@ -1,5 +1,7 @@
package ru.m.tankz;
import haxework.resources.Resources;
import haxework.resources.IResources;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.gui.ButtonView;
@@ -35,16 +37,14 @@ class Client implements IConnectionHandler {
private var view:MainView;
private var switcher:FrameSwitcher;
public function new() {
view = new MainView();
Root.bind(view);
switcher = view.switcher;
view.logout.onPress = this;
Provider.setFactory(IResources, Resources);
Provider.setFactory(GameData, GameData);
Provider.set(IFrameSwitcher, switcher);
var font = Assets.getFont("resources/fonts/8-BIT WONDER.TTF");
Provider.get(IResources).text.put("fontName", font.fontName);
Provider.set(IPacketBuilder, new PacketBuilder());
#if flash
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
@@ -53,7 +53,12 @@ class Client implements IConnectionHandler {
#end
Provider.get(IConnection).handler.addListener(this);
switcher.change(AuthFrame.ID);
view = new MainView();
Provider.set(IFrameSwitcher, view.switcher);
Root.bind(view);
view.logout.onPress = this;
view.switcher.change(AuthFrame.ID);
}
public function onPress(view:ButtonView):Void {
@@ -66,11 +71,11 @@ class Client implements IConnectionHandler {
public function onConnected():Void {}
public function onDisconnected():Void {
switcher.change(AuthFrame.ID);
view.switcher.change(AuthFrame.ID);
}
public function onError(error:Dynamic):Void {
L.e(TAG, "", error);
switcher.change(AuthFrame.ID);
view.switcher.change(AuthFrame.ID);
}
}

View File

@@ -1,5 +1,8 @@
package ru.m.tankz.render;
import ru.m.tankz.core.Direction;
import flash.geom.Matrix;
import openfl.Assets;
import ru.m.tankz.core.Bullet;
import ru.m.tankz.core.Tank;
import flash.display.Sprite;
@@ -51,22 +54,34 @@ class Render extends SpriteView implements IRender {
for (e in game.mobileEntities) {
if (Std.is(e, Tank)) {
g.beginFill(0xff0000);
var m = new Matrix();
m.rotate(calcRotate(e.direction));
m.translate(e.x, e.y);
g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m);
g.drawRect(e.x, e.y, e.width, e.height);
g.endFill();
g.beginFill(0x990000);
g.drawRect(
e.x + e.width / 2 - e.width / 8 + e.direction.x * e.width / 4,
e.y + e.height / 2 - e.height / 8 + e.direction.y * e.height / 4,
e.width / 4,
e.height / 4
);
g.endFill();
} else if (Std.is(e, Bullet)) {
g.beginFill(0xff0000);
var m = new Matrix();
m.rotate(calcRotate(e.direction));
m.translate(e.x, e.y);
g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m);
g.drawRect(e.x, e.y, e.width, e.height);
g.endFill();
}
}
}
private function calcRotate(direction:Direction):Float {
return (if (direction == Direction.RIGHT) {
0;
} else if (direction == Direction.LEFT) {
180;
} else if (direction == Direction.TOP) {
270;
} else if (direction == Direction.BOTTOM) {
90;
} else {
0;
}) / (Math.PI * 2);
}
}

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.view.frames;
import haxework.resources.IResources;
import haxework.gui.ViewBuilder;
import ru.m.core.connect.IConnection;
import ru.m.tankz.data.GameData;
@@ -63,6 +64,7 @@ class AuthFrame extends VGroupView implements ViewBuilder implements IPacketHand
so.setProperty("login", loginInput.text);
so.setProperty("password", passwordInput.text);
so.flush();
Provider.get(IResources).text.put("userName", packet.account.login);
Provider.get(GameData).account = packet.account;
Provider.get(IFrameSwitcher).change(PersonListFrame.ID);
}

View File

@@ -11,10 +11,10 @@ import ru.m.core.connect.IConnection;
import ru.m.tankz.data.GameData;
import haxework.provider.Provider;
import ru.m.tankz.proto.Person;
import haxework.gui.HGroupView;
import haxework.gui.VGroupView;
@:template("layout/frames/person_list.json", "layout/styles.json")
class PersonListFrame extends HGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener<Person> {
class PersonListFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener<Person> {
private static inline var TAG = "PersonListFrame";

View File

@@ -1,28 +1,16 @@
package ru.m.tankz.view.frames.list;
import haxework.gui.ViewBuilder;
import haxework.gui.list.ListView.IListItemView;
import haxework.gui.LabelView;
import ru.m.tankz.proto.Person;
import haxework.gui.skin.ColorSkin;
import haxework.gui.HGroupView;
class PersonView extends HGroupView implements IListItemView<Person> {
@:template("layout/other.json@person", "layout/styles.json")
class PersonView extends HGroupView implements ViewBuilder implements IListItemView<Person> {
public var item_index(default, default):Int;
public var data(default, set):Person;
private var nameLabel:LabelView;
public function new() {
super();
pWidth = 100;
height = 50;
skin = new ColorSkin(0xffffff);
nameLabel = new LabelView();
addView(nameLabel);
}
private function set_data(value:Person):Person {
this.data = value;
nameLabel.text = this.data.name;