From feb5bafe72a1f98f49a08cc9675be0cb355e30eb Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 5 Feb 2018 20:46:11 +0300 Subject: [PATCH] [editor] update --- .../haxe/ru/m/tankz/render/RenderItem.hx | 7 +++-- .../haxe/ru/m/tankz/view/frames/LevelFrame.hx | 2 +- src/client/resources/dota/levels/level000.txt | 31 +------------------ .../haxe/ru/m/tankz/config/LevelBundle.hx | 4 +++ src/common/haxe/ru/m/tankz/map/LevelMap.hx | 6 ++++ .../haxe/ru/m/tankz/editor/BrickView.hx | 26 ++++++++++++++++ src/editor/haxe/ru/m/tankz/editor/Editor.hx | 16 ++++++++-- src/editor/haxe/ru/m/tankz/editor/Editor.yaml | 22 +++++++++++-- .../haxe/ru/m/tankz/editor/MapEditView.hx | 23 ++++++++++++++ 9 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 src/editor/haxe/ru/m/tankz/editor/BrickView.hx diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index 9fe3cd7..a76bdca 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -78,6 +78,7 @@ class BitmapItem extends RenderItem { class BrickItem extends RenderItem { private var broken:Int; + private var type:Int; public function new(value:Brick) { super(value); @@ -104,8 +105,10 @@ class BrickItem extends RenderItem { override public function update():Void { super.update(); var b = value.broken; - if (b != this.broken) { - this.broken = b; + var t = value.config.type; + if (b != broken || t != type) { + broken = b; + type = t; redraw(); } } diff --git a/src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx index 4e238f3..4b3dc0d 100644 --- a/src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/LevelFrame.hx @@ -15,7 +15,7 @@ interface LevelFrameLayout { @:template("layout/frames/level.json", "layout/styles.json") -class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout implements ListViewListener { +class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout { public static inline var ID = "level"; public function init():Void { diff --git a/src/client/resources/dota/levels/level000.txt b/src/client/resources/dota/levels/level000.txt index 65ec086..2e6a368 100644 --- a/src/client/resources/dota/levels/level000.txt +++ b/src/client/resources/dota/levels/level000.txt @@ -1,30 +1 @@ -0000000000000000000000000000000000005500 -0000000000000000000000000000000000005500 -0000000000000000000000000000000000005555 -0000000000000000000000000000000000005555 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -0000000000000000000000000000000000000000 -5555000000000000000000000000000000000000 -5555000000000000000000000000000000000000 -0055000000000000000000000000000000000000 -0055000000000000000000000000000000000000 +000044000000000000000000005500004400550000004400000000000000000000550000440055000000440000004400003333000055000044005555000044000000440000333300005500004400555500004422442244000000000000550000440000000000442244224400000000000055000044000000000000000000444444555544444400442200330000000000000044444455554444440044220033005555333333554422220000222244000022003300555533333355442222000022224400002200330000000000000044220000000022440000440033000000000000004422000000002244000044003300000000000000550000555500005500002200000000000000000055000055550000550000220000004444444400005500445555440055000044444444444444440000550044555544005500004444444400000022000055000055550000550000000000000000002200005500005555000055000000000000003300440000442200000000224400000000000000330044000044220000000022440000000000000033002200004422220000222244553333335555003300220000442222000022224455333333555500330022440044444455554444440000000000000033002244004444445555444444000000000000000000440000550000000000004422442244000000000044000055000000000000442244224400005555004400005500003333000044000000440000555500440000550000333300004400000044000000550044000055000000000000000000004400000055004400005500000000000000000000440000 \ No newline at end of file diff --git a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx index c5bcf43..10681cb 100644 --- a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx @@ -29,6 +29,10 @@ class LevelBundle { return bricks.map(function(brick:BrickConfig) return brick.type).join(''); } + public static function empty(config:Config):Array { + return [for (i in 0...config.map.gridWidth*config.map.gridHeight) config.bricks[1]]; + } + public static function get(type:GameType, config:Config, level:Int):Array { var data:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt'); return loads(config, data); diff --git a/src/common/haxe/ru/m/tankz/map/LevelMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx index b91d7fe..7a4c036 100755 --- a/src/common/haxe/ru/m/tankz/map/LevelMap.hx +++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx @@ -62,4 +62,10 @@ class LevelMap { public function getBrick(cell:GridCell):Brick { return bricksMap.get(cell.position); } + + public function getPointBrick(point:Point):Brick { + var cellX:Int = Math.floor(point.x / config.cellWidth); + var cellY:Int = Math.floor(point.y / config.cellHeight); + return bricks[cellX + cellY * config.gridWidth]; + } } diff --git a/src/editor/haxe/ru/m/tankz/editor/BrickView.hx b/src/editor/haxe/ru/m/tankz/editor/BrickView.hx new file mode 100644 index 0000000..8967153 --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/BrickView.hx @@ -0,0 +1,26 @@ +package ru.m.tankz.editor; + +import flash.display.Bitmap; +import haxework.gui.list.ListView.IListItemView; +import haxework.gui.SpriteView; +import openfl.utils.Assets; +import ru.m.tankz.config.Config.BrickConfig; + + +class BrickView extends SpriteView implements IListItemView { + + public var item_index(default, default):Int; + public var data(default, set):BrickConfig; + + 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; + } + return data; + } +} \ 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 ff3819a..73e6486 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -1,7 +1,10 @@ package ru.m.tankz.editor; -import ru.m.tankz.editor.FileUtil.FileContent; +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; @@ -25,6 +28,7 @@ interface EditorViewLayout { var saveButton(default, null):ButtonView; var fileNameLabel(default, null):LabelView; var mapView(default, null):MapEditView; + var brickList(default, null):VListView; } @@ -68,8 +72,13 @@ class Editor { view.openButton.onPress = this; view.saveButton.onPress = this; - config = ConfigBundle.get(ClassicGame.TYPE); + 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); } public function onPress(v:ButtonView):Void { @@ -90,4 +99,7 @@ class Editor { } } + public function onListItemClick(item:IListItemView):Void { + view.mapView.brick = item.data; + } } diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml index a4114ed..4339e84 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml @@ -27,9 +27,27 @@ views: - id: fileNameLabel $type: haxework.gui.LabelView contentSize: true - - id: mapView - $type: ru.m.tankz.editor.MapEditView + - $type: haxework.gui.HGroupView contentSize: true + views: + - 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: 10 + pHeight: 100 + skin: + $type: haxework.gui.list.VScrollSkin + skin: + $type: haxework.gui.skin.ColorSkin + color: 0x000000 + alpha: 0.0 - $type: haxework.gui.LabelView inLayout: false contentSize: true diff --git a/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx b/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx index 53efb5e..f9cce1b 100644 --- a/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx +++ b/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx @@ -1,5 +1,7 @@ package ru.m.tankz.editor; +import ru.m.geom.Point; +import flash.events.MouseEvent; import ru.m.tankz.map.Brick; import flash.display.DisplayObjectContainer; import flash.display.Graphics; @@ -16,6 +18,7 @@ class MapEditView extends SpriteView { public var config(default, set):MapConfig; public var data(get, set):Array; public var map(default, null):LevelMap; + public var brick(default, default):BrickConfig; private var items:Map>; @@ -33,9 +36,29 @@ class MapEditView extends SpriteView { contentAsSprite.addChild(backgroundLayer); contentAsSprite.addChild(groundLayer); contentAsSprite.addChild(upLayer); + contentAsSprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); reset(); } + private function onMouseDown(event:MouseEvent):Void { + contentAsSprite.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); + contentAsSprite.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); + onMouseMove(event); + } + + private function onMouseUp(event:MouseEvent):Void { + contentAsSprite.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); + contentAsSprite.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); + } + + private function onMouseMove(event:MouseEvent):Void { + var b = map.getPointBrick(new Point(event.localX, event.localY)); + if (b != null) { + b.config = brick; + drawMap(); + } + } + private function clearLayer(layer:DisplayObjectContainer) { while (layer.numChildren > 0) layer.removeChildAt(0); }