[client] add CreateGamePopup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.13.3",
|
"version": "0.13.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||||
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId))));
|
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectSlot(slot:SlotProto):Void {
|
public function selectSlot(slot:SlotProto):Void {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ views:
|
|||||||
- $type: haxework.view.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
skinId: container
|
skinId: container
|
||||||
geometry.padding: 20
|
geometry.padding: 20
|
||||||
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- id: header
|
- id: header
|
||||||
$type: haxework.view.LabelView
|
$type: haxework.view.LabelView
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.view.network;
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.view.popup.CreateGamePopup;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.list.VListView;
|
import haxework.view.list.VListView;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
@@ -27,7 +28,11 @@ import ru.m.tankz.proto.room.RoomProto;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function create():Void {
|
private function create():Void {
|
||||||
network.createGame("classic", 0);
|
CreateGamePopup.instance.show().then(function(result) {
|
||||||
|
if (result != null) {
|
||||||
|
network.createGame(result.type, result.level);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onRoomList(data:Array<RoomProto>):Void {
|
private function onRoomList(data:Array<RoomProto>):Void {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.m.tankz.view.network;
|
|||||||
import haxework.view.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView;
|
import haxework.view.list.ListView;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
@:template class SlotItemView extends HGroupView implements IListItemView<RoomSlotProto> {
|
@:template class SlotItemView extends HGroupView implements IListItemView<RoomSlotProto> {
|
||||||
@@ -12,9 +13,12 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
|||||||
|
|
||||||
@:view var label:LabelView;
|
@:view var label:LabelView;
|
||||||
|
|
||||||
|
@:provide static var network:NetworkManager;
|
||||||
|
|
||||||
private function set_data(value:RoomSlotProto):RoomSlotProto {
|
private function set_data(value:RoomSlotProto):RoomSlotProto {
|
||||||
data = value;
|
data = value;
|
||||||
label.text = '${value.slot.team}-${value.slot.index} ${value.hasUser() ? value.user.name : '(NONE)'}';
|
label.text = '${value.slot.team}-${value.slot.index} ${value.hasUser() ? value.user.name : '(NONE)'}';
|
||||||
|
label.skinId = (value.hasUser() && value.user.uuid == network.user.uuid) ? "text.box.active" : "text.box";
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
72
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
72
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.popup.PopupView;
|
||||||
|
import haxework.view.ToggleButtonView;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
private typedef Result = {
|
||||||
|
var type:GameType;
|
||||||
|
var level:LevelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template class CreateGamePopup extends PopupView<Result> {
|
||||||
|
|
||||||
|
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||||
|
@:view("level") var levelView:DataView<LevelId, ToggleButtonView>;
|
||||||
|
|
||||||
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
|
private var type:GameType;
|
||||||
|
private var level:LevelId;
|
||||||
|
|
||||||
|
override private function onShow():Void {
|
||||||
|
super.onShow();
|
||||||
|
onGameTypeSelect(0, "classic", typeView.dataViews[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function submit():Void {
|
||||||
|
close({type:type, level:level});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function gameTypeViewFactory(index:Int, type:GameType):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = "button.simple";
|
||||||
|
result.text = type;
|
||||||
|
result.on = type == this.type;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameTypeSelect(index:Int, value:GameType, view:ToggleButtonView):Void {
|
||||||
|
this.type = value;
|
||||||
|
for (v in typeView.dataViews) {
|
||||||
|
v.on = v == view;
|
||||||
|
}
|
||||||
|
levelView.data = [for (i in 0...configBundle.get(type).game.levels) i];
|
||||||
|
onLevelSelect(0, 0, levelView.dataViews[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function levelViewFactory(index:Int, value:LevelId):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = "button.level";
|
||||||
|
result.text = Std.string(value);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onLevelSelect(index:Int, level:LevelId, view:ToggleButtonView):Void {
|
||||||
|
this.level = level;
|
||||||
|
for (v in levelView.dataViews) {
|
||||||
|
v.on = v == view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var instance(get, null):CreateGamePopup;
|
||||||
|
|
||||||
|
private static function get_instance():CreateGamePopup {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new CreateGamePopup();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
68
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
68
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
view:
|
||||||
|
$type: haxework.view.VGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
geometry.size.width: 600
|
||||||
|
skinId: window
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: name
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.margin.left: 10
|
||||||
|
layout.hAlign: left
|
||||||
|
skinId: text
|
||||||
|
text: New game
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: window.close
|
||||||
|
+onPress: $code:reject('close')
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 20
|
||||||
|
layout.margin: 5
|
||||||
|
layout.hAlign: center
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Type
|
||||||
|
- id: type
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.HorizontalLayout
|
||||||
|
margin: 10
|
||||||
|
factory: $this:gameTypeViewFactory
|
||||||
|
+onItemSelect: $this:onGameTypeSelect
|
||||||
|
data:
|
||||||
|
- "classic"
|
||||||
|
- "dota"
|
||||||
|
- "death"
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Level
|
||||||
|
- id: level
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onItemSelect: $this:onLevelSelect
|
||||||
|
geometry.padding: 10
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.margin: 5
|
||||||
|
skinId: panel
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Create
|
||||||
|
+onPress: $code:submit()
|
||||||
@@ -8,7 +8,7 @@ import haxework.view.popup.PopupView;
|
|||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.GameProgress;
|
||||||
|
|
||||||
typedef Result = {
|
private typedef Result = {
|
||||||
var control:ControlPreset;
|
var control:ControlPreset;
|
||||||
var preset:GamePreset;
|
var preset:GamePreset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,14 @@ view:
|
|||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
skinId: text
|
skinId: text
|
||||||
text: Password
|
text: Password
|
||||||
|
visible: false
|
||||||
- id: password
|
- id: password
|
||||||
$type: haxework.view.InputView
|
$type: haxework.view.InputView
|
||||||
textField.displayAsPassword: true
|
textField.displayAsPassword: true
|
||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.size.height: 28
|
geometry.size.height: 28
|
||||||
skinId: text.box
|
skinId: text.box
|
||||||
|
visible: false
|
||||||
- id: error
|
- id: error
|
||||||
$type: haxework.view.TextView
|
$type: haxework.view.TextView
|
||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ message CreateRequest {
|
|||||||
|
|
||||||
message JoinRequest {
|
message JoinRequest {
|
||||||
int32 gameId = 1;
|
int32 gameId = 1;
|
||||||
|
bool restore = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LeaveRequest {
|
message LeaveRequest {
|
||||||
|
|||||||
@@ -92,6 +92,12 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
} else if (request.room.hasJoin()) {
|
} else if (request.room.hasJoin()) {
|
||||||
gameId = request.room.join.gameId;
|
gameId = request.room.join.gameId;
|
||||||
gameManager.join(gameId, user);
|
gameManager.join(gameId, user);
|
||||||
|
var game = gameManager.gamesById[gameId];
|
||||||
|
if (request.room.join.restore && game.room.game.started) {
|
||||||
|
for (event in game.restore()) {
|
||||||
|
send(new Response().setGameEvent(new GameEventResponse().setTime(0).setEvent(Serializer.run(event))));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (request.room.hasLeave()) {
|
} else if (request.room.hasLeave()) {
|
||||||
gameManager.leave(user);
|
gameManager.leave(user);
|
||||||
} else if (request.room.hasSlot()) {
|
} else if (request.room.hasSlot()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user