From 4fc0ae103e390f80f1df680738b3e5ef3475b1f9 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 13 Feb 2018 17:57:07 +0300 Subject: [PATCH] [editor] added frame switcher --- src/editor/haxe/ru/m/tankz/editor/Editor.hx | 112 +++--------------- src/editor/haxe/ru/m/tankz/editor/Editor.yaml | 106 +++++------------ src/editor/haxe/ru/m/tankz/editor/Style.json | 18 +++ src/editor/haxe/ru/m/tankz/editor/Style.yaml | 13 ++ .../ru/m/tankz/editor/frame/LevelFrame.hx | 108 +++++++++++++++++ .../ru/m/tankz/editor/frame/LevelFrame.yaml | 66 +++++++++++ .../haxe/ru/m/tankz/editor/frame/TankFrame.hx | 22 ++++ .../ru/m/tankz/editor/frame/TankFrame.yaml | 3 + 8 files changed, 276 insertions(+), 172 deletions(-) create mode 100644 src/editor/haxe/ru/m/tankz/editor/Style.json create mode 100644 src/editor/haxe/ru/m/tankz/editor/Style.yaml create mode 100644 src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx create mode 100644 src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml create mode 100644 src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx create mode 100644 src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.hx b/src/editor/haxe/ru/m/tankz/editor/Editor.hx index a94af0f..5fc592a 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -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; - var brickList(default, null):VListView; + 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) { - view.mapView.brush = Brush.BRICK(item.data); - resetSelected(); - cast(item, BrickView).selected = true; } - }); - - view.spawnPointList.dispatcher.addListener({ - onListItemClick: function(item:IListItemView) { - 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()); } } diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml index a204f97..6c04d31 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml @@ -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: - - $type: haxework.gui.HGroupView - pWidth: 100 - height: 20 - views: - - id: gameClassicButton - $type: haxework.gui.ButtonView - text: Classic - contentSize: true - skin: - $type: haxework.gui.skin.ButtonColorSkin - color: 0xaaff00 - - id: gameDotaButton - $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 - 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 - 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 + - id: level + $type: ru.m.tankz.editor.frame.LevelFrame + - id: tank + $type: ru.m.tankz.editor.frame.TankFrame + # Tabs + - $type: haxework.gui.HGroupView + vAlign: TOP + hAlign: CENTER + contentSize: true + inLayout: false + views: + - id: btn_level + $type: haxework.gui.ButtonView + text: Level + '@style': button + onPress: '@link:handler' + - id: btn_tank + $type: haxework.gui.ButtonView + 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' diff --git a/src/editor/haxe/ru/m/tankz/editor/Style.json b/src/editor/haxe/ru/m/tankz/editor/Style.json new file mode 100644 index 0000000..a31e5aa --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/Style.json @@ -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" + } +} diff --git a/src/editor/haxe/ru/m/tankz/editor/Style.yaml b/src/editor/haxe/ru/m/tankz/editor/Style.yaml new file mode 100644 index 0000000..e7c338a --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/Style.yaml @@ -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 diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx new file mode 100644 index 0000000..5abd1c8 --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx @@ -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; + var brickList(default, null):VListView; +} + +@: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) { + mapView.brush = Brush.BRICK(item.data); + resetSelected(); + cast(item, BrickView).selected = true; } + }); + + spawnPointList.dispatcher.addListener({ + onListItemClick: function(item:IListItemView) { + 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 _: + } + } +} diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml new file mode 100644 index 0000000..44ea5bb --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml @@ -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 + 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 + 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 diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx new file mode 100644 index 0000000..9b83615 --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx @@ -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 { + + } +} diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml new file mode 100644 index 0000000..77a920a --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml @@ -0,0 +1,3 @@ +$type: haxework.gui.VGroupView +pWidth: 100 +pHeight: 100 \ No newline at end of file