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

View File

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

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.bot; package ru.m.tankz.bot;
import ru.m.tankz.core.Eagle;
import haxe.Timer; import haxe.Timer;
import ru.m.tankz.core.EntityType; import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.Tank; import ru.m.tankz.core.Tank;
@@ -81,6 +82,11 @@ class HardBotControl extends BotControl {
} }
private function calcTurn():Void { private function calcTurn():Void {
turn(BotHelper.randomDirection()); 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.ILevelBundle;
import ru.m.tankz.bundle.ConfigBundle; import ru.m.tankz.bundle.ConfigBundle;
import ru.m.tankz.bundle.IConfigBundle; import ru.m.tankz.bundle.IConfigBundle;
import flash.text.Font;
import haxework.gui.ButtonView; import haxework.gui.ButtonView;
import haxework.gui.frame.FrameSwitcher; import haxework.gui.frame.FrameSwitcher;
import haxework.gui.VGroupView; import haxework.gui.VGroupView;
@@ -58,10 +57,7 @@ class Editor {
public function new() { public function new() {
resources = new Resources(); resources = new Resources();
resources.text.put('version', '${Const.VERSION}');
var font:Font = Font.enumerateFonts()[0];
resources.text.put('font', 'Bookman Old Style');
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
Style.register(); Style.register();

View File

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

View File

@@ -17,18 +17,6 @@ views:
skinId: button.simple skinId: button.simple
text: DotA text: DotA
+onPress: $this:onPress +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 - id: fileNameLabel
$type: haxework.gui.LabelView $type: haxework.gui.LabelView
# map # map
@@ -52,3 +40,15 @@ views:
hAlign: center hAlign: center
margin: 5 margin: 5
factory: $code:ru.m.tankz.editor.level.BrickView.factory 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; package ru.m.tankz.editor.frame;
import ru.m.tankz.editor.tank.TankView; import ru.m.tankz.editor.tank.TankView;
import haxework.gui.IGroupView;
import haxework.color.Color;
import haxework.gui.InputView; 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'; public static inline var ID = 'tank';
@:view var tank(default, null):TankView; @:view var tanks(default, null):IGroupView;
@:view var colorR(default, null):InputView; @:view("color") var colorLabel(default, null):InputView;
@:view var colorG(default, null):InputView; private var color(default, set):Color;
@:view var colorB(default, null):InputView;
public function onShow():Void { public function onShow():Void {
onChange(); color = 0x00ff00;
} }
public function onChange(?_):Void { private function set_color(value:Color):Color {
tank.color = '#${colorR.text}${colorG.text}${colorB.text}'; 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.size.stretch: true
geometry.padding: 10
layout.hAlign: center layout.hAlign: center
layout.margin: 10
views: views:
- $type: ru.m.tankz.editor.tank.TankView - id: tanks
geometry.margin.right: 20 $type: haxework.gui.GroupView
image: "$asset:image:resources/image/tank/bc-0.png" layout:
color: 0xff4422 $type: haxework.gui.layout.TailLayout
- $type: ru.m.tankz.editor.tank.TankView rowSize: 4
geometry.margin.right: 20 margin: 20
image: "$asset:image:resources/image/tank/bc-0.png" views:
color: 0xf055a0 - $type: ru.m.tankz.editor.tank.TankView
- $type: ru.m.tankz.editor.tank.TankView image: "$asset:image:resources/image/tank/pa-0.png"
geometry.margin.right: 20 - $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/bc-0.png" image: "$asset:image:resources/image/tank/pb-0.png"
color: 0x2244ff - $type: ru.m.tankz.editor.tank.TankView
- id: tank image: "$asset:image:resources/image/tank/pc-0.png"
$type: ru.m.tankz.editor.tank.TankView - $type: ru.m.tankz.editor.tank.TankView
geometry.margin.right: 20 image: "$asset:image:resources/image/tank/pd-0.png"
image: "$asset:image:resources/image/tank/bc-0.png" - $type: ru.m.tankz.editor.tank.TankView
- id: colorR 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
image: "$asset:image:resources/image/tank/bc-0.png"
- $type: ru.m.tankz.editor.tank.TankView
image: "$asset:image:resources/image/tank/bd-0.png"
- id: color
$type: haxework.gui.InputView $type: haxework.gui.InputView
+onChange: $this:onChange skinId: text.box
geometry.size.fixed: [30, 20] +onChange: $code:function(value) color = value
text: "a0" geometry.size.width: 120
skin: layout.hAlign: right
- $type: haxework.gui.skin.ColorSkin - $type: ru.m.tankz.editor.ColorView
color: 0xffffff +onSelect: $code:function(value) color = value
- 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB