From db5b805276c6f953580ec0f19ac2b60c174495ce Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 6 Feb 2018 10:54:48 +0300 Subject: [PATCH] [editor] ui update --- .../haxe/ru/m/tankz/render/RenderItem.hx | 16 ++++--- .../haxe/ru/m/tankz/editor/BrickView.hx | 45 +++++++++++++++---- src/editor/haxe/ru/m/tankz/editor/Editor.hx | 14 ++++-- src/editor/haxe/ru/m/tankz/editor/Editor.yaml | 2 +- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index a76bdca..57c76ae 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -91,15 +91,17 @@ class BrickItem extends RenderItem { var g = view.graphics; g.clear(); if (value.destroyed) return; - g.beginBitmapFill(image); - g.drawRect(0, 0, value.rect.width, value.rect.height); - for (c in value.cells) { - if (c.destroyed) { - g.beginFill(0x000000); - g.drawRect(c.rect.x - value.rect.x, c.rect.y - value.rect.y, c.rect.width, c.rect.height); + if (value.config.type > 0) { + g.beginBitmapFill(image); + g.drawRect(0, 0, value.rect.width, value.rect.height); + for (c in value.cells) { + if (c.destroyed) { + g.beginFill(0x000000); + g.drawRect(c.rect.x - value.rect.x, c.rect.y - value.rect.y, c.rect.width, c.rect.height); + } } + g.endFill(); } - g.endFill(); } override public function update():Void { diff --git a/src/editor/haxe/ru/m/tankz/editor/BrickView.hx b/src/editor/haxe/ru/m/tankz/editor/BrickView.hx index 8967153..7fe5022 100644 --- a/src/editor/haxe/ru/m/tankz/editor/BrickView.hx +++ b/src/editor/haxe/ru/m/tankz/editor/BrickView.hx @@ -1,26 +1,53 @@ package ru.m.tankz.editor; import flash.display.Bitmap; -import haxework.gui.list.ListView.IListItemView; +import flash.display.Shape; +import haxework.gui.list.ListView; import haxework.gui.SpriteView; import openfl.utils.Assets; -import ru.m.tankz.config.Config.BrickConfig; +import ru.m.tankz.config.Config; class BrickView extends SpriteView implements IListItemView { public var item_index(default, default):Int; public var data(default, set):BrickConfig; + public var selected(default, set):Bool; + + private var imageView:Bitmap; + private var selectView:Shape; + + public function new() { + super(); + width = 26; + height = 26; + selectView = createSelectView(width, height); + selectView.visible = false; + contentAsSprite.addChild(selectView); + imageView = new Bitmap(); + contentAsSprite.addChild(imageView); + } + + private static function createSelectView(width:Float, height:Float):Shape { + var view = new Shape(); + view.graphics.lineStyle(4, 0x33ff00); + view.graphics.drawRect(0, 0, width, height); + view.graphics.lineStyle(); + return view; + } private function set_data(value:BrickConfig):BrickConfig { data = value; - if (value.type > -1) { - var src = 'resources/images/map/map_${value.type}.png'; - var image = Assets.getBitmapData(src); - contentAsSprite.addChild(new Bitmap(image)); - width = image.width; - height = image.height; - } + var src = 'resources/images/map/map_${value.type}.png'; + imageView.bitmapData = Assets.getBitmapData(src); + imageView.x = (width - imageView.width) / 2; + imageView.y = (height - imageView.height) / 2; return data; } + + private function set_selected(value:Bool):Bool { + selected = value; + selectView.visible = value; + return selected; + } } \ No newline at end of file diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.hx b/src/editor/haxe/ru/m/tankz/editor/Editor.hx index 73e6486..32cf2c6 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -75,10 +75,12 @@ class Editor { config = ConfigBundle.get(DotaGame.TYPE); view.mapView.config = config.map; view.mapView.data = LevelBundle.empty(config); - view.mapView.brick = config.bricks[0]; - view.brickList.data = config.bricks; - view.brickList.dispatcher.addListener(this); + view.brickList.data = config.bricks.filter(function(brick) return brick.type > -1); + view.mapView.brick = view.brickList.data[0]; + cast(view.brickList.items[0], BrickView).selected = true; + + view.brickList.dispatcher.addListener(onBrickItemSelect); } public function onPress(v:ButtonView):Void { @@ -99,7 +101,11 @@ class Editor { } } - public function onListItemClick(item:IListItemView):Void { + private function onBrickItemSelect(item:IListItemView):Void { view.mapView.brick = item.data; + for (v in view.brickList.items) { + cast(v, BrickView).selected = false; + } + cast(item, BrickView).selected = true; } } diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml index 4339e84..5759a4c 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml @@ -40,7 +40,7 @@ views: pHeight: 100 scroll: $type: haxework.gui.list.VScrollView - width: 10 + width: 0 pHeight: 100 skin: $type: haxework.gui.list.VScrollSkin