[editor] add ColorView

This commit is contained in:
2019-03-25 16:01:37 +03:00
parent 216e1aa476
commit a9b591a7ca
10 changed files with 115 additions and 73 deletions

View File

@@ -1,4 +1,3 @@
"use strict";
const gulp = require('gulp');
const gulpClean = require('gulp-clean');
const Config = require('./config.json');
@@ -69,7 +68,9 @@ const client = new Project(
name: 'client',
sources: ['src/client/haxe'],
main: 'ru.m.tankz.Client',
assets: ['src/client/resources'],
assets: [
'src/client/resources',
],
meta: {
width: 1024,
height: 768,
@@ -88,12 +89,17 @@ const client = new Project(
*/
const editor = new Project(
Project.BuildSystem.OPENFL,
[
Project.Platform.FLASH,
],
config.branch({
name: 'editor',
sources: ['src/client/haxe', 'src/editor/haxe'],
main: 'ru.m.tankz.editor.Editor',
assets: ['src/client/resources'],
assets: [
'src/client/resources',
'src/editor/resources',
],
meta: {
filename: 'editor',
width: 1024,

View File

@@ -4,7 +4,7 @@ import ru.m.geom.Direction;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.control.Control.ControlHandler;
import ru.m.tankz.control.Control;
import ru.m.tankz.Type;
class BotHelper {

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.bot;
import ru.m.tankz.core.Eagle;
import haxe.Timer;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.Tank;
@@ -81,6 +82,11 @@ class HardBotControl extends BotControl {
}
private function calcTurn():Void {
var eagle:Eagle = BotHelper.findEagle(playerId.team, handler);
if (eagle != null && Math.random() > 0.5) {
turn(BotHelper.getDirectionTo(tank, eagle));
} else {
turn(BotHelper.randomDirection());
}
}
}

View File

@@ -0,0 +1,36 @@
package ru.m.tankz.editor;
import flash.events.MouseEvent;
import haxework.color.Color;
import haxework.gui.ImageView;
import haxework.signal.Signal;
import openfl.Assets;
class ColorView extends ImageView {
public var onSelect(default, null):Signal<Color> = new Signal();
public function new() {
super(Assets.getBitmapData("resources/image/colors.png"));
content.cacheAsBitmap = true;
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private function onMouseDown(event:MouseEvent):Void {
content.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
onMouseMove(event);
}
private function onMouseMove(event:MouseEvent):Void {
if (event.localX >= width || event.localY >= height) {
return;
}
onSelect.emit(image.getPixel32(Std.int(event.localX), Std.int(event.localY)));
}
private function onMouseUp(event:MouseEvent):Void {
content.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
}

View File

@@ -8,7 +8,6 @@ import ru.m.tankz.bundle.LevelBundle;
import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.bundle.ConfigBundle;
import ru.m.tankz.bundle.IConfigBundle;
import flash.text.Font;
import haxework.gui.ButtonView;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.VGroupView;
@@ -58,10 +57,7 @@ class Editor {
public function new() {
resources = new Resources();
var font:Font = Font.enumerateFonts()[0];
resources.text.put('font', 'Bookman Old Style');
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
resources.text.put('version', '${Const.VERSION}');
Style.register();

View File

@@ -35,7 +35,7 @@ views:
- $type: haxework.gui.LabelView
skinId: text
geometry.position: absolute
geometry.vAlign: bottom
geometry.vAlign: top
geometry.hAlign: right
geometry.margin: 10
text: $r:text:version

View File

@@ -17,18 +17,6 @@ views:
skinId: button.simple
text: DotA
+onPress: $this:onPress
- $type: haxework.gui.HGroupView
views:
- id: openButton
$type: haxework.gui.ButtonView
skinId: button.simple
text: Open
+onPress: $this:onPress
- id: saveButton
$type: haxework.gui.ButtonView
skinId: button.simple
text: Save
+onPress: $this:onPress
- id: fileNameLabel
$type: haxework.gui.LabelView
# map
@@ -52,3 +40,15 @@ views:
hAlign: center
margin: 5
factory: $code:ru.m.tankz.editor.level.BrickView.factory
- $type: haxework.gui.HGroupView
views:
- id: openButton
$type: haxework.gui.ButtonView
skinId: button.simple
text: Open
+onPress: $this:onPress
- id: saveButton
$type: haxework.gui.ButtonView
skinId: button.simple
text: Save
+onPress: $this:onPress

View File

@@ -1,22 +1,28 @@
package ru.m.tankz.editor.frame;
import ru.m.tankz.editor.tank.TankView;
import haxework.gui.IGroupView;
import haxework.color.Color;
import haxework.gui.InputView;
import haxework.gui.HGroupView;
import haxework.gui.VGroupView;
@:template class TankFrame extends HGroupView {
@:template class TankFrame extends VGroupView {
public static inline var ID = 'tank';
@:view var tank(default, null):TankView;
@:view var colorR(default, null):InputView;
@:view var colorG(default, null):InputView;
@:view var colorB(default, null):InputView;
@:view var tanks(default, null):IGroupView;
@:view("color") var colorLabel(default, null):InputView;
private var color(default, set):Color;
public function onShow():Void {
onChange();
color = 0x00ff00;
}
public function onChange(?_):Void {
tank.color = '#${colorR.text}${colorG.text}${colorB.text}';
private function set_color(value:Color):Color {
color = value;
colorLabel.text = value.toString();
for (view in tanks.views) {
cast(view, TankView).color = color;
}
return color;
}
}

View File

@@ -1,45 +1,37 @@
---
$type: haxework.gui.HGroupView
geometry.size.stretch: true
geometry.padding: 10
layout.hAlign: center
layout.margin: 10
views:
- id: tanks
$type: haxework.gui.GroupView
layout:
$type: haxework.gui.layout.TailLayout
rowSize: 4
margin: 20
views:
- $type: ru.m.tankz.editor.tank.TankView
geometry.margin.right: 20
image: "$asset:image:resources/image/tank/bc-0.png"
color: 0xff4422
image: "$asset:image:resources/image/tank/pa-0.png"
- $type: ru.m.tankz.editor.tank.TankView
geometry.margin.right: 20
image: "$asset:image:resources/image/tank/bc-0.png"
color: 0xf055a0
image: "$asset:image:resources/image/tank/pb-0.png"
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/pc-0.png"
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/pd-0.png"
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/ba-0.png"
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/bb-0.png"
- $type: ru.m.tankz.editor.tank.TankView
geometry.margin.right: 20
image: "$asset:image:resources/image/tank/bc-0.png"
color: 0x2244ff
- id: tank
$type: ru.m.tankz.editor.tank.TankView
geometry.margin.right: 20
image: "$asset:image:resources/image/tank/bc-0.png"
- id: colorR
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/bd-0.png"
- id: color
$type: haxework.gui.InputView
+onChange: $this:onChange
geometry.size.fixed: [30, 20]
text: "a0"
skin:
- $type: haxework.gui.skin.ColorSkin
color: 0xffffff
- id: colorG
$type: haxework.gui.InputView
+onChange: $this:onChange
geometry.size.fixed: [30, 20]
text: "55"
skin:
- $type: haxework.gui.skin.ColorSkin
color: 0xffffff
- id: colorB
$type: haxework.gui.InputView
+onChange: $this:onChange
geometry.size.fixed: [30, 20]
text: "f0"
skin:
- $type: haxework.gui.skin.ColorSkin
color: 0xffffff
skinId: text.box
+onChange: $code:function(value) color = value
geometry.size.width: 120
layout.hAlign: right
- $type: ru.m.tankz.editor.ColorView
+onSelect: $code:function(value) color = value

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB