[editor] added frame switcher
This commit is contained in:
@@ -1,42 +1,25 @@
|
||||
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 haxework.resources.Resources;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.log.TraceLogger;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.GroupView;
|
||||
import haxework.log.JSLogger;
|
||||
import haxework.log.SocketLogger;
|
||||
import haxework.gui.Root;
|
||||
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 {
|
||||
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>;
|
||||
var switcher(default, null):FrameSwitcher;
|
||||
}
|
||||
|
||||
@: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 Editor {
|
||||
@@ -58,9 +41,7 @@ class Editor {
|
||||
new Editor();
|
||||
}
|
||||
|
||||
|
||||
private var view:EditorView;
|
||||
private var config:Config;
|
||||
|
||||
public function new() {
|
||||
Provider.setFactory(IResources, Resources);
|
||||
@@ -69,75 +50,14 @@ class Editor {
|
||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
||||
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
|
||||
|
||||
view = new EditorView();
|
||||
view = new EditorView({handler: this});
|
||||
Root.bind(view);
|
||||
view.content.stage.stageFocusRect = false;
|
||||
|
||||
view.gameClassicButton.onPress = this;
|
||||
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;
|
||||
view.switcher.change(LevelFrame.ID);
|
||||
}
|
||||
|
||||
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) {
|
||||
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.switcher.change(v.id.split('btn_').pop());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,88 +2,42 @@ $type: haxework.gui.GroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- $type: haxework.gui.VGroupView
|
||||
# Switcher
|
||||
- id: switcher
|
||||
$type: haxework.gui.frame.FrameSwitcher
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
skin:
|
||||
$type: haxework.gui.skin.BitmapSkin
|
||||
image: '@asset:image:resources/images/background.png'
|
||||
fillType: REPEAT
|
||||
views:
|
||||
- id: level
|
||||
$type: ru.m.tankz.editor.frame.LevelFrame
|
||||
- id: tank
|
||||
$type: ru.m.tankz.editor.frame.TankFrame
|
||||
# Tabs
|
||||
- $type: haxework.gui.HGroupView
|
||||
pWidth: 100
|
||||
height: 20
|
||||
vAlign: TOP
|
||||
hAlign: CENTER
|
||||
contentSize: true
|
||||
inLayout: false
|
||||
views:
|
||||
- id: gameClassicButton
|
||||
- id: btn_level
|
||||
$type: haxework.gui.ButtonView
|
||||
text: Classic
|
||||
contentSize: true
|
||||
skin:
|
||||
$type: haxework.gui.skin.ButtonColorSkin
|
||||
color: 0xaaff00
|
||||
- id: gameDotaButton
|
||||
text: Level
|
||||
'@style': button
|
||||
onPress: '@link:handler'
|
||||
- id: btn_tank
|
||||
$type: haxework.gui.ButtonView
|
||||
text: DotA
|
||||
contentSize: true
|
||||
skin:
|
||||
$type: haxework.gui.skin.ButtonColorSkin
|
||||
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
|
||||
text: Tank
|
||||
'@style': button
|
||||
onPress: '@link:handler'
|
||||
# Version
|
||||
- $type: haxework.gui.LabelView
|
||||
inLayout: false
|
||||
contentSize: true
|
||||
vAlign: BOTTOM
|
||||
hAlign: RIGHT
|
||||
'@style': label
|
||||
text: '@res:text:version'
|
||||
|
||||
18
src/editor/haxe/ru/m/tankz/editor/Style.json
Normal file
18
src/editor/haxe/ru/m/tankz/editor/Style.json
Normal 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"
|
||||
}
|
||||
}
|
||||
13
src/editor/haxe/ru/m/tankz/editor/Style.yaml
Normal file
13
src/editor/haxe/ru/m/tankz/editor/Style.yaml
Normal 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
|
||||
108
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx
Normal file
108
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx
Normal 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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
66
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml
Normal file
66
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml
Normal 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
|
||||
22
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx
Normal file
22
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx
Normal 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 {
|
||||
|
||||
}
|
||||
}
|
||||
3
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml
Normal file
3
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
$type: haxework.gui.VGroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
Reference in New Issue
Block a user