[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

@@ -78,6 +78,7 @@ class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
class BrickItem extends RenderItem<Brick, Shape> { class BrickItem extends RenderItem<Brick, Shape> {
private var broken:Int; private var broken:Int;
private var type:Int;
public function new(value:Brick) { public function new(value:Brick) {
super(value); super(value);
@@ -104,8 +105,10 @@ class BrickItem extends RenderItem<Brick, Shape> {
override public function update():Void { override public function update():Void {
super.update(); super.update();
var b = value.broken; var b = value.broken;
if (b != this.broken) { var t = value.config.type;
this.broken = b; if (b != broken || t != type) {
broken = b;
type = t;
redraw(); redraw();
} }
} }

View File

@@ -15,7 +15,7 @@ interface LevelFrameLayout {
@:template("layout/frames/level.json", "layout/styles.json") @:template("layout/frames/level.json", "layout/styles.json")
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout implements ListViewListener<Int> { class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
public static inline var ID = "level"; public static inline var ID = "level";
public function init():Void { public function init():Void {

View File

@@ -1,30 +1 @@
0000000000000000000000000000000000005500 000044000000000000000000005500004400550000004400000000000000000000550000440055000000440000004400003333000055000044005555000044000000440000333300005500004400555500004422442244000000000000550000440000000000442244224400000000000055000044000000000000000000444444555544444400442200330000000000000044444455554444440044220033005555333333554422220000222244000022003300555533333355442222000022224400002200330000000000000044220000000022440000440033000000000000004422000000002244000044003300000000000000550000555500005500002200000000000000000055000055550000550000220000004444444400005500445555440055000044444444444444440000550044555544005500004444444400000022000055000055550000550000000000000000002200005500005555000055000000000000003300440000442200000000224400000000000000330044000044220000000022440000000000000033002200004422220000222244553333335555003300220000442222000022224455333333555500330022440044444455554444440000000000000033002244004444445555444444000000000000000000440000550000000000004422442244000000000044000055000000000000442244224400005555004400005500003333000044000000440000555500440000550000333300004400000044000000550044000055000000000000000000004400000055004400005500000000000000000000440000
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

View File

@@ -29,6 +29,10 @@ class LevelBundle {
return bricks.map(function(brick:BrickConfig) return brick.type).join(''); return bricks.map(function(brick:BrickConfig) return brick.type).join('');
} }
public static function empty(config:Config):Array<BrickConfig> {
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<BrickConfig> { public static function get(type:GameType, config:Config, level:Int):Array<BrickConfig> {
var data:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt'); var data:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt');
return loads(config, data); return loads(config, data);

View File

@@ -62,4 +62,10 @@ class LevelMap {
public function getBrick(cell:GridCell):Brick { public function getBrick(cell:GridCell):Brick {
return bricksMap.get(cell.position); 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];
}
} }

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; 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 haxework.gui.LabelView;
import ru.m.tankz.config.Config; import ru.m.tankz.config.Config;
import ru.m.tankz.config.LevelBundle; import ru.m.tankz.config.LevelBundle;
@@ -25,6 +28,7 @@ interface EditorViewLayout {
var saveButton(default, null):ButtonView; var saveButton(default, null):ButtonView;
var fileNameLabel(default, null):LabelView; var fileNameLabel(default, null):LabelView;
var mapView(default, null):MapEditView; var mapView(default, null):MapEditView;
var brickList(default, null):VListView<BrickConfig>;
} }
@@ -68,8 +72,13 @@ class Editor {
view.openButton.onPress = this; view.openButton.onPress = this;
view.saveButton.onPress = this; view.saveButton.onPress = this;
config = ConfigBundle.get(ClassicGame.TYPE); config = ConfigBundle.get(DotaGame.TYPE);
view.mapView.config = config.map; 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 { 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 - id: fileNameLabel
$type: haxework.gui.LabelView $type: haxework.gui.LabelView
contentSize: true contentSize: true
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: mapView - id: mapView
$type: ru.m.tankz.editor.MapEditView $type: ru.m.tankz.editor.MapEditView
contentSize: true 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 - $type: haxework.gui.LabelView
inLayout: false inLayout: false
contentSize: true contentSize: true

View File

@@ -1,5 +1,7 @@
package ru.m.tankz.editor; package ru.m.tankz.editor;
import ru.m.geom.Point;
import flash.events.MouseEvent;
import ru.m.tankz.map.Brick; import ru.m.tankz.map.Brick;
import flash.display.DisplayObjectContainer; import flash.display.DisplayObjectContainer;
import flash.display.Graphics; import flash.display.Graphics;
@@ -16,6 +18,7 @@ class MapEditView extends SpriteView {
public var config(default, set):MapConfig; public var config(default, set):MapConfig;
public var data(get, set):Array<BrickConfig>; public var data(get, set):Array<BrickConfig>;
public var map(default, null):LevelMap; public var map(default, null):LevelMap;
public var brick(default, default):BrickConfig;
private var items:Map<String, RenderItem<Dynamic, Dynamic>>; private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
@@ -33,9 +36,29 @@ class MapEditView extends SpriteView {
contentAsSprite.addChild(backgroundLayer); contentAsSprite.addChild(backgroundLayer);
contentAsSprite.addChild(groundLayer); contentAsSprite.addChild(groundLayer);
contentAsSprite.addChild(upLayer); contentAsSprite.addChild(upLayer);
contentAsSprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
reset(); 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) { private function clearLayer(layer:DisplayObjectContainer) {
while (layer.numChildren > 0) layer.removeChildAt(0); while (layer.numChildren > 0) layer.removeChildAt(0);
} }