[editor] added frame switcher

This commit is contained in:
2018-02-13 17:57:07 +03:00
parent bd86412d83
commit 4fc0ae103e
8 changed files with 276 additions and 172 deletions

View File

@@ -1,42 +1,25 @@
package ru.m.tankz.editor; package ru.m.tankz.editor;
import ru.m.tankz.Type;
import ru.m.tankz.editor.MapEditView;
import ru.m.tankz.game.DotaGame;
import haxework.gui.list.ListView;
import haxework.gui.list.VListView;
import ru.m.tankz.editor.FileUtil;
import haxework.gui.LabelView;
import ru.m.tankz.config.Config;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.config.ConfigBundle;
import haxework.gui.ButtonView;
import haxework.gui.Root;
import flash.text.Font; import flash.text.Font;
import haxework.resources.Resources; import haxework.gui.ButtonView;
import haxework.resources.IResources; import haxework.gui.frame.FrameSwitcher;
import haxework.provider.Provider;
import haxework.log.TraceLogger;
import haxework.gui.ViewBuilder;
import haxework.gui.GroupView; import haxework.gui.GroupView;
import haxework.log.JSLogger; import haxework.gui.Root;
import haxework.log.SocketLogger; import haxework.gui.ViewBuilder;
import haxework.log.TraceLogger;
import haxework.provider.Provider;
import haxework.resources.IResources;
import haxework.resources.Resources;
import ru.m.tankz.view.frames.LevelFrame;
#if flash import haxework.log.JSLogger; #end
#if debug import haxework.log.SocketLogger; #end
interface EditorViewLayout { interface EditorViewLayout {
var gameClassicButton(default, null):ButtonView; var switcher(default, null):FrameSwitcher;
var gameDotaButton(default, null):ButtonView;
var openButton(default, null):ButtonView;
var saveButton(default, null):ButtonView;
var fileNameLabel(default, null):LabelView;
var mapView(default, null):MapEditView;
var spawnPointList(default, null):VListView<SpawnPoint>;
var brickList(default, null):VListView<BrickConfig>;
} }
@:template("ru/m/tankz/editor/Editor.yaml") @:template("ru/m/tankz/editor/Editor.yaml", "ru/m/tankz/editor/Style.json")
class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {} class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {}
class Editor { class Editor {
@@ -58,9 +41,7 @@ class Editor {
new Editor(); new Editor();
} }
private var view:EditorView; private var view:EditorView;
private var config:Config;
public function new() { public function new() {
Provider.setFactory(IResources, Resources); Provider.setFactory(IResources, Resources);
@@ -69,75 +50,14 @@ class Editor {
Provider.get(IResources).text.put("font", "Bookman Old Style"); Provider.get(IResources).text.put("font", "Bookman Old Style");
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}'); Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
view = new EditorView(); view = new EditorView({handler: this});
Root.bind(view); Root.bind(view);
view.content.stage.stageFocusRect = false; view.content.stage.stageFocusRect = false;
view.gameClassicButton.onPress = this; view.switcher.change(LevelFrame.ID);
view.gameDotaButton.onPress = this;
view.openButton.onPress = this;
view.saveButton.onPress = this;
var resetSelected = function() {
for (v in view.brickList.items) {
cast(v, BrickView).selected = false;
}
for (v in view.spawnPointList.items) {
cast(v, SpawnPointView).selected = false;
}
};
view.brickList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<BrickConfig>) {
view.mapView.brush = Brush.BRICK(item.data);
resetSelected();
cast(item, BrickView).selected = true; }
});
view.spawnPointList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<SpawnPoint>) {
view.mapView.brush = Brush.POINT(item.data);
resetSelected();
cast(item, SpawnPointView).selected = true;
}
});
setGameType(ClassicGame.TYPE);
}
private function setGameType(type:GameType):Void {
config = ConfigBundle.get(type);
Provider.set(Config, config);
view.mapView.config = config;
view.mapView.data = LevelBundle.empty(config);
view.brickList.data = config.bricks.filter(function(brick) return brick.index > -1);
view.spawnPointList.data = config.points;
view.mapView.brush = Brush.BRICK(view.brickList.data[0]);
cast(view.brickList.items[0], BrickView).selected = true;
} }
public function onPress(v:ButtonView):Void { public function onPress(v:ButtonView):Void {
switch (v.id) { view.switcher.change(v.id.split('btn_').pop());
case 'gameClassicButton':
setGameType(ClassicGame.TYPE);
case 'gameDotaButton':
setGameType(DotaGame.TYPE);
case 'openButton':
L.d(TAG, 'OPEN');
FileUtil.browse().then(function(content:FileContent) {
view.fileNameLabel.text = content.name;
view.mapView.data = LevelBundle.loads(config, content.content);
});
case 'saveButton':
L.d(TAG, 'SAVE');
FileUtil.save({
name: view.fileNameLabel.text,
content: LevelBundle.dumps(config, view.mapView.data),
});
case _:
}
} }
} }

View File

@@ -2,88 +2,42 @@ $type: haxework.gui.GroupView
pWidth: 100 pWidth: 100
pHeight: 100 pHeight: 100
views: views:
- $type: haxework.gui.VGroupView # Switcher
- id: switcher
$type: haxework.gui.frame.FrameSwitcher
pWidth: 100 pWidth: 100
pHeight: 100 pHeight: 100
skin:
$type: haxework.gui.skin.BitmapSkin
image: '@asset:image:resources/images/background.png'
fillType: REPEAT
views: views:
- id: level
$type: ru.m.tankz.editor.frame.LevelFrame
- id: tank
$type: ru.m.tankz.editor.frame.TankFrame
# Tabs
- $type: haxework.gui.HGroupView - $type: haxework.gui.HGroupView
pWidth: 100 vAlign: TOP
height: 20 hAlign: CENTER
contentSize: true
inLayout: false
views: views:
- id: gameClassicButton - id: btn_level
$type: haxework.gui.ButtonView $type: haxework.gui.ButtonView
text: Classic text: Level
contentSize: true '@style': button
skin: onPress: '@link:handler'
$type: haxework.gui.skin.ButtonColorSkin - id: btn_tank
color: 0xaaff00
- id: gameDotaButton
$type: haxework.gui.ButtonView $type: haxework.gui.ButtonView
text: DotA text: Tank
contentSize: true '@style': button
skin: onPress: '@link:handler'
$type: haxework.gui.skin.ButtonColorSkin # Version
color: 0xaaff00
- $type: haxework.gui.HGroupView
pWidth: 100
height: 20
views:
- id: openButton
$type: haxework.gui.ButtonView
text: Open
contentSize: true
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
- id: saveButton
$type: haxework.gui.ButtonView
text: Save
contentSize: true
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
- id: fileNameLabel
$type: haxework.gui.LabelView
contentSize: true
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: spawnPointList
$type: haxework.gui.list.VListView<SpawnPoint>
factory: '@class:ru.m.tankz.editor.SpawnPointView'
width: 56
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- id: mapView
$type: ru.m.tankz.editor.MapEditView
contentSize: true
- id: brickList
$type: haxework.gui.list.VListView<BrickConfig>
factory: '@class:ru.m.tankz.editor.BrickView'
width: 30
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- $type: haxework.gui.LabelView - $type: haxework.gui.LabelView
inLayout: false inLayout: false
contentSize: true contentSize: true
vAlign: BOTTOM vAlign: BOTTOM
hAlign: RIGHT hAlign: RIGHT
'@style': label
text: '@res:text:version' text: '@res:text:version'

View File

@@ -0,0 +1,18 @@
{
"button": {
"width": 150,
"height": 20,
"margins": 2,
"skin": {
"@type": "haxework.gui.skin.ButtonColorSkin",
"color": "0xaaff00"
}
},
"label": {
"fontColor": "0xffffff",
"fontEmbed": false,
"fontFamily": "@res:text:fontName",
"fontSize": 16,
"shadowColor": "0x000000"
}
}

View File

@@ -0,0 +1,13 @@
button:
height: 20
width: 150
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
label:
fontColor: 0xffffff
fontEmbed: false
fontFamily: '@res:text:fontName'
fontSize: 16
shadowColor: 0x000000

View File

@@ -0,0 +1,108 @@
package ru.m.tankz.editor.frame;
import haxework.gui.ButtonView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import haxework.gui.list.VListView;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.provider.Provider;
import ru.m.tankz.config.Config;
import ru.m.tankz.config.ConfigBundle;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.editor.FileUtil;
import ru.m.tankz.editor.MapEditView.Brush;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.DotaGame;
import ru.m.tankz.Type;
interface LevelFrameLayout {
var gameClassicButton(default, null):ButtonView;
var gameDotaButton(default, null):ButtonView;
var openButton(default, null):ButtonView;
var saveButton(default, null):ButtonView;
var fileNameLabel(default, null):LabelView;
var mapView(default, null):MapEditView;
var spawnPointList(default, null):VListView<SpawnPoint>;
var brickList(default, null):VListView<BrickConfig>;
}
@:template('ru/m/tankz/editor/frame/LevelFrame.yaml', 'ru/m/tankz/editor/Style.json')
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
public static inline var ID = 'level';
public static inline var TAG = 'level';
private var config:Config;
public function init():Void {
gameClassicButton.onPress = this;
gameDotaButton.onPress = this;
openButton.onPress = this;
saveButton.onPress = this;
var resetSelected = function() {
for (v in brickList.items) {
cast(v, BrickView).selected = false;
}
for (v in spawnPointList.items) {
cast(v, SpawnPointView).selected = false;
}
};
brickList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<BrickConfig>) {
mapView.brush = Brush.BRICK(item.data);
resetSelected();
cast(item, BrickView).selected = true; }
});
spawnPointList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<SpawnPoint>) {
mapView.brush = Brush.POINT(item.data);
resetSelected();
cast(item, SpawnPointView).selected = true;
}
});
}
public function onShow():Void {
setGameType(ClassicGame.TYPE);
}
private function setGameType(type:GameType):Void {
config = ConfigBundle.get(type);
Provider.set(Config, config);
mapView.config = config;
mapView.data = LevelBundle.empty(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.items[0], BrickView).selected = true;
}
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;
mapView.data = LevelBundle.loads(config, content.content);
});
case 'saveButton':
L.d(TAG, 'SAVE');
FileUtil.save({
name: fileNameLabel.text,
content: LevelBundle.dumps(config, mapView.data),
});
case _:
}
}
}

View File

@@ -0,0 +1,66 @@
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
layoutMargin: 2
views:
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: gameClassicButton
$type: haxework.gui.ButtonView
text: Classic
'@style': button
- id: gameDotaButton
$type: haxework.gui.ButtonView
text: DotA
'@style': button
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: openButton
$type: haxework.gui.ButtonView
text: Open
'@style': button
- id: saveButton
$type: haxework.gui.ButtonView
text: Save
'@style': button
- id: fileNameLabel
$type: haxework.gui.LabelView
contentSize: true
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: spawnPointList
$type: haxework.gui.list.VListView<SpawnPoint>
factory: '@class:ru.m.tankz.editor.SpawnPointView'
width: 56
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- id: mapView
$type: ru.m.tankz.editor.MapEditView
contentSize: true
- id: brickList
$type: haxework.gui.list.VListView<BrickConfig>
factory: '@class:ru.m.tankz.editor.BrickView'
width: 30
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0

View File

@@ -0,0 +1,22 @@
package ru.m.tankz.editor.frame;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
interface TankFrameLayout {
}
@:template('ru/m/tankz/editor/frame/TankFrame.yaml')
class TankFrame extends VGroupView implements ViewBuilder implements TankFrameLayout {
public static inline var ID = 'tank';
public function init():Void {
}
public function onShow():Void {
}
}

View File

@@ -0,0 +1,3 @@
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100