[editor] MapFrame rework

This commit is contained in:
2019-06-13 16:23:22 +03:00
parent 5798fa9db7
commit dc1279f636
9 changed files with 97 additions and 102 deletions

View File

@@ -1,9 +1,7 @@
package ru.m.tankz.editor.view;
import haxework.view.ButtonView;
import haxework.view.DataView;
import haxework.view.InputView;
import haxework.view.LabelView;
import haxework.view.VGroupView;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.config.Config;
@@ -12,7 +10,6 @@ import ru.m.tankz.editor.view.map.BrickView;
import ru.m.tankz.editor.view.map.MapEditView;
import ru.m.tankz.editor.view.map.SpawnPointView;
import ru.m.tankz.preset.ClassicGame;
import ru.m.tankz.preset.DotaGame;
import ru.m.tankz.Type;
import ru.m.tankz.util.LevelUtil;
@@ -20,11 +17,9 @@ import ru.m.tankz.util.LevelUtil;
public static inline var ID = 'map';
public static inline var TAG = 'map';
@:view var gameClassicButton:ButtonView;
@:view var gameDotaButton:ButtonView;
@:view var openButton:ButtonView;
@:view var saveButton:ButtonView;
@:view var fileNameLabel:LabelView;
public var type(default, set):GameType;
private var fileName:String;
@:view var levelName:InputView;
@:view var mapView:MapEditView;
@:view var spawnPointList:DataView<SpawnPoint, SpawnPointView>;
@@ -36,80 +31,66 @@ import ru.m.tankz.util.LevelUtil;
@:provide var config:Config;
public function init():Void {
var resetSelected = function() {
for (v in brickList.views) {
cast(v, BrickView).selected = false;
}
for (v in spawnPointList.views) {
cast(v, SpawnPointView).selected = false;
}
};
brickList.onItemSelect.connect(function(index:Int, value:BrickConfig, item:BrickView):Void {
mapView.brush = Brush.BRICK(item.data);
resetSelected();
item.selected = true;
});
spawnPointList.onItemSelect.connect(function(index:Int, value:SpawnPoint, item:SpawnPointView):Void {
mapView.brush = Brush.POINT(item.data);
resetSelected();
item.selected = true;
});
setGameType(ClassicGame.TYPE);
fileName = "level000.txt";
type = ClassicGame.TYPE;
}
/*public function onShow():Void {
if (config == null) {
setGameType(ClassicGame.TYPE);
private function set_type(value:GameType):GameType {
if (type != value) {
type = value;
config = configBundle.get(type);
mapView.config = config;
brickList.data = config.bricks.filter(function(brick) return brick.index > -1);
spawnPointList.data = config.points;
selectBrick(brickList.data[0]);
resetSize();
}
}*/
private function setGameType(type:GameType):Void {
config = configBundle.get(type);
mapView.config = config;
brickList.data = config.bricks.filter(function(brick) return brick.index > -1);
spawnPointList.data = config.points;
mapView.brush = Brush.BRICK(brickList.data[0]);
cast(brickList.views[0], BrickView).selected = true;
return type;
}
public function onPress(v:ButtonView):Void {
switch (v.id) {
case 'gameClassicButton':
setGameType(ClassicGame.TYPE);
case 'gameDotaButton':
setGameType(DotaGame.TYPE);
case 'openButton':
L.d(TAG, 'OPEN');
FileUtil.browse().then(function(content:FileContent) {
fileNameLabel.text = content.name;
var data = LevelUtil.loads(config, content.content);
mapView.gridSize = data.size;
mapView.data = data;
levelName.text = data.name;
if (data.size != null) {
widthInput.text = Std.string(data.size.width);
heightInput.text = Std.string(data.size.height);
} else {
widthInput.text = "";
heightInput.text = "";
}
});
case 'saveButton':
L.d(TAG, 'SAVE');
var data = mapView.data;
data.name = levelName.text;
FileUtil.save({
name: fileNameLabel.text,
content: LevelUtil.dumps(config, data),
});
case _:
private function updateSelected(brick:BrickConfig = null, point:SpawnPoint = null) {
for (v in brickList.dataViews) {
v.selected = v.data == brick;
}
for (v in spawnPointList.dataViews) {
v.selected = v.data == point;
}
}
private function selectBrick(brick:BrickConfig):Void {
mapView.brush = BRICK(brick);
updateSelected(brick);
}
private function selectSpawnPoint(point:SpawnPoint):Void {
mapView.brush = POINT(point);
updateSelected(null, point);
}
private function open():Void {
FileUtil.browse().then(function(content:FileContent) {
fileName = content.name;
var data = LevelUtil.loads(config, content.content);
mapView.gridSize = data.size;
mapView.data = data;
levelName.text = data.name;
if (data.size != null) {
widthInput.text = Std.string(data.size.width);
heightInput.text = Std.string(data.size.height);
} else {
widthInput.text = Std.string(config.map.grid.width);
heightInput.text = Std.string(config.map.grid.height);
}
});
}
private function save():Void {
var data = mapView.data;
data.name = levelName.text;
FileUtil.save({
name: fileName,
content: LevelUtil.dumps(config, data),
});
}
private function applySize():Void {
@@ -117,6 +98,8 @@ import ru.m.tankz.util.LevelUtil;
}
private function resetSize():Void {
widthInput.text = Std.string(config.map.grid.width);
heightInput.text = Std.string(config.map.grid.height);
mapView.gridSize = null;
}
}

View File

@@ -11,43 +11,48 @@ views:
- $type: haxework.view.ButtonView
skinId: button.simple
text: Classic
+onPress: $code:setGameType('classic')
+onPress: $code:function(_) type = 'classic'
- $type: haxework.view.ButtonView
skinId: button.simple
text: DotA
+onPress: $code:setGameType('dota')
+onPress: $code:function(_) type = 'dota'
- $type: haxework.view.ButtonView
skinId: button.simple
text: DeathMatch
+onPress: $code:setGameType('death')
- id: fileNameLabel
$type: haxework.view.LabelView
skinId: text
text: level000.txt
- id: levelName
$type: haxework.view.InputView
skinId: text.box
geometry.size.width: 300
geometry.size.height: 26
text: ""
+onPress: $code:function(_) type = 'death'
- $type: haxework.view.HGroupView
layout.vAlign: middle
views:
- $type: haxework.view.LabelView
skinId: text
text: "Name:"
- id: levelName
$type: haxework.view.InputView
skinId: text.box
geometry.size.width: 300
geometry.size.height: 26
text: ""
- $type: haxework.view.LabelView
skinId: text
text: "Size:"
geometry.margin.left: 20
- id: width
$type: haxework.view.InputView
skinId: text.box
geometry.size.fixed: [50, 26]
- $type: haxework.view.LabelView
skinId: text
text: "x"
- id: height
$type: haxework.view.InputView
skinId: text.box
geometry.size.fixed: [50, 26]
- $type: haxework.view.ButtonView
skinId: button.simple
text: apply
+onPress: "$code:applySize()"
skinId: button.start.small
+onPress: $code:applySize()
- $type: haxework.view.ButtonView
skinId: button.simple
text: reset
+onPress: "$code:resetSize()"
skinId: button.close.small
+onPress: $code:resetSize()
# map
- $type: haxework.view.HGroupView
views:
@@ -59,6 +64,7 @@ views:
hAlign: center
margin: 5
factory: $code:ru.m.tankz.editor.view.map.SpawnPointView.factory
+onDataSelect: $this:selectSpawnPoint
- id: mapView
$type: ru.m.tankz.editor.view.map.MapEditView
- id: brickList
@@ -69,6 +75,7 @@ views:
hAlign: center
margin: 5
factory: $code:ru.m.tankz.editor.view.map.BrickView.factory
+onDataSelect: $this:selectBrick
- $type: haxework.view.HGroupView
layout.margin: 5
views:
@@ -76,9 +83,9 @@ views:
$type: haxework.view.ButtonView
skinId: button.simple
text: Open
+onPress: $this:onPress
+onPress: $code:open()
- id: saveButton
$type: haxework.view.ButtonView
skinId: button.simple
text: Save
+onPress: $this:onPress
+onPress: $code:save()