[common] update level config, spawns points
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.m.tankz.editor;
|
||||
|
||||
|
||||
import ru.m.tankz.editor.MapEditView.Brush;
|
||||
import ru.m.tankz.game.DotaGame;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.list.VListView;
|
||||
@@ -28,10 +29,10 @@ interface EditorViewLayout {
|
||||
var saveButton(default, null):ButtonView;
|
||||
var fileNameLabel(default, null):LabelView;
|
||||
var mapView(default, null):MapEditView;
|
||||
var spawnPointList(default, null):VListView<SpawnPoint>;
|
||||
var brickList(default, null):VListView<BrickConfig>;
|
||||
}
|
||||
|
||||
|
||||
@:template("ru/m/tankz/editor/Editor.yaml")
|
||||
class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {}
|
||||
|
||||
@@ -73,14 +74,38 @@ class Editor {
|
||||
view.saveButton.onPress = this;
|
||||
|
||||
config = ConfigBundle.get(DotaGame.TYPE);
|
||||
view.mapView.config = config.map;
|
||||
view.mapView.config = config;
|
||||
view.mapView.data = LevelBundle.empty(config);
|
||||
|
||||
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.spawnPointList.data = config.points;
|
||||
|
||||
view.brickList.dispatcher.addListener(onBrickItemSelect);
|
||||
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<BrickConfig>) {
|
||||
view.mapView.brush = Brush.BRICK(item.data);
|
||||
resetSelected();
|
||||
cast(item, BrickView).selected = true; }
|
||||
});
|
||||
|
||||
view.spawnPointList.dispatcher.addListener({
|
||||
onListItemClick: function(item:IListItemView<SpawnPoint>) {
|
||||
view.mapView.brush = Brush.POINT(item.data);
|
||||
resetSelected();
|
||||
cast(item, SpawnPointView).selected = true;
|
||||
}
|
||||
});
|
||||
|
||||
view.mapView.brush = Brush.BRICK(view.brickList.data[0]);
|
||||
cast(view.brickList.items[0], BrickView).selected = true;
|
||||
}
|
||||
|
||||
public function onPress(v:ButtonView):Void {
|
||||
@@ -100,12 +125,4 @@ class Editor {
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function onBrickItemSelect(item:IListItemView<BrickConfig>):Void {
|
||||
view.mapView.brick = item.data;
|
||||
for (v in view.brickList.items) {
|
||||
cast(v, BrickView).selected = false;
|
||||
}
|
||||
cast(item, BrickView).selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,21 @@ views:
|
||||
- $type: haxework.gui.HGroupView
|
||||
contentSize: true
|
||||
views:
|
||||
- id: spawnPointList
|
||||
$type: haxework.gui.list.VListView<SpawnPoint>
|
||||
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
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.editor;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.geom.Point;
|
||||
import flash.events.MouseEvent;
|
||||
import ru.m.tankz.map.Brick;
|
||||
@@ -12,19 +14,71 @@ import ru.m.tankz.map.LevelMap;
|
||||
import haxework.gui.SpriteView;
|
||||
|
||||
|
||||
class SpawnPointEntity extends Entity {
|
||||
|
||||
public var point(default, null):SpawnPoint;
|
||||
|
||||
public function new(point:SpawnPoint, rect:Rectangle) {
|
||||
super(rect);
|
||||
this.point = point;
|
||||
}
|
||||
}
|
||||
|
||||
class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
|
||||
|
||||
private var cellX:Int;
|
||||
private var cellY:Int;
|
||||
|
||||
public function new(value:SpawnPoint, config:MapConfig) {
|
||||
super(new SpawnPointEntity(value, new Rectangle(
|
||||
value.x * config.cellWidth,
|
||||
value.y * config.cellHeight,
|
||||
config.cellWidth * 2,
|
||||
config.cellHeight * 2
|
||||
)));
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (cellX != value.point.x || cellY != value.point.y) {
|
||||
cellX = value.point.x;
|
||||
cellY = value.point.y;
|
||||
value.rect.x = cellX * (value.rect.width / 2);
|
||||
value.rect.y = cellY * (value.rect.height / 2);
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
override private function getImage():String {
|
||||
return switch(value.point.type) {
|
||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
||||
case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png';
|
||||
case x: 'resources/images/eagle/eagle-1.png';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum Brush {
|
||||
POINT(point:SpawnPoint);
|
||||
BRICK(brick:BrickConfig);
|
||||
}
|
||||
|
||||
|
||||
//ToDo: copy paste from ru.m.tankz.render.Render
|
||||
class MapEditView extends SpriteView {
|
||||
|
||||
public var config(default, set):MapConfig;
|
||||
public var data(get, set):Array<BrickConfig>;
|
||||
public var config(default, set):Config;
|
||||
public var data(get, set):LevelConfig;
|
||||
public var map(default, null):LevelMap;
|
||||
public var brick(default, default):BrickConfig;
|
||||
public var brush(default, default):Brush;
|
||||
|
||||
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
|
||||
|
||||
private var backgroundLayer:Sprite;
|
||||
private var upLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
private var spawnLayer:Sprite;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
@@ -33,9 +87,11 @@ class MapEditView extends SpriteView {
|
||||
backgroundLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
groundLayer = new Sprite();
|
||||
spawnLayer = new Sprite();
|
||||
contentAsSprite.addChild(backgroundLayer);
|
||||
contentAsSprite.addChild(groundLayer);
|
||||
contentAsSprite.addChild(upLayer);
|
||||
contentAsSprite.addChild(spawnLayer);
|
||||
contentAsSprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
reset();
|
||||
}
|
||||
@@ -54,8 +110,20 @@ class MapEditView extends SpriteView {
|
||||
private function onMouseMove(event:MouseEvent):Void {
|
||||
var b = map.getPointBrick(new Point(event.localX, event.localY));
|
||||
if (b != null) {
|
||||
b.config = brick;
|
||||
drawMap();
|
||||
switch (brush) {
|
||||
case Brush.POINT(point):
|
||||
for (p in config.points) {
|
||||
if (p.team == point.team && p.type == point.type && p.index == point.index) {
|
||||
p.x = b.cellX;
|
||||
p.y = b.cellY;
|
||||
drawMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
case Brush.BRICK(brick):
|
||||
b.config = brick;
|
||||
drawMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +138,7 @@ class MapEditView extends SpriteView {
|
||||
items = new Map();
|
||||
clearLayer(groundLayer);
|
||||
clearLayer(upLayer);
|
||||
clearLayer(spawnLayer);
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
@@ -114,25 +183,44 @@ class MapEditView extends SpriteView {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (point in config.points) {
|
||||
var key = '${point.team}:${point.type}:${point.index}';
|
||||
if (!items.exists(key)) {
|
||||
items[key] = new SpawnPointItem(point, config.map);
|
||||
spawnLayer.addChild(items[key].view);
|
||||
}
|
||||
}
|
||||
for (item in items) {
|
||||
item.update();
|
||||
}
|
||||
}
|
||||
|
||||
private function set_config(value:MapConfig):MapConfig {
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
map = new LevelMap(config);
|
||||
map = new LevelMap(config.map);
|
||||
invalidate();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function get_data():Array<BrickConfig> {
|
||||
return map.bricks.map(function(brick:Brick) return brick.config);
|
||||
private function get_data():LevelConfig {
|
||||
return {
|
||||
data: map.bricks.map(function(brick:Brick) return brick.config),
|
||||
points: config.points,
|
||||
}
|
||||
}
|
||||
|
||||
private function set_data(value:Array<BrickConfig>):Array<BrickConfig> {
|
||||
private function set_data(value:LevelConfig):LevelConfig {
|
||||
reset();
|
||||
map.setData(value);
|
||||
map.setData(value.data);
|
||||
if (value.points != null) for (point in value.points) {
|
||||
for (p in config.points) {
|
||||
if (p.team == point.team && p.type == point.type && p.index == point.index) {
|
||||
p.x = point.x;
|
||||
p.y = point.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
return value;
|
||||
}
|
||||
|
||||
57
src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx
Normal file
57
src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx
Normal file
@@ -0,0 +1,57 @@
|
||||
package ru.m.tankz.editor;
|
||||
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.Shape;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.SpriteView;
|
||||
import openfl.utils.Assets;
|
||||
import ru.m.tankz.config.Config;
|
||||
|
||||
|
||||
class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):SpawnPoint;
|
||||
public var selected(default, set):Bool;
|
||||
|
||||
private var imageView:Bitmap;
|
||||
private var selectView:Shape;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
width = 52;
|
||||
height = 52;
|
||||
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:SpawnPoint):SpawnPoint {
|
||||
data = value;
|
||||
var src = switch(value.type) {
|
||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
||||
case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png';
|
||||
case x: 'resources/images/eagle/eagle-1.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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user