[editor] update

This commit is contained in:
2018-02-05 20:46:11 +03:00
parent b36fd77d74
commit feb5bafe72
9 changed files with 100 additions and 37 deletions

View File

@@ -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<BrickConfig> {
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;
}
}

View File

@@ -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<BrickConfig>;
}
@@ -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<BrickConfig>):Void {
view.mapView.brick = item.data;
}
}

View File

@@ -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<BrickConfig>
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

View File

@@ -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<BrickConfig>;
public var map(default, null):LevelMap;
public var brick(default, default):BrickConfig;
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
@@ -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);
}