diff --git a/gulpfile.js b/gulpfile.js index b04e493..fd855e1 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -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, + [ + 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, diff --git a/src/common/haxe/ru/m/tankz/bot/BotHelper.hx b/src/common/haxe/ru/m/tankz/bot/BotHelper.hx index 5b319db..63d1b43 100644 --- a/src/common/haxe/ru/m/tankz/bot/BotHelper.hx +++ b/src/common/haxe/ru/m/tankz/bot/BotHelper.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx b/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx index 17ea6d8..28fc66b 100644 --- a/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx +++ b/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx @@ -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 { - 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()); + } } } diff --git a/src/editor/haxe/ru/m/tankz/editor/ColorView.hx b/src/editor/haxe/ru/m/tankz/editor/ColorView.hx new file mode 100644 index 0000000..fcd4f73 --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/ColorView.hx @@ -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 = 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); + } +} diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.hx b/src/editor/haxe/ru/m/tankz/editor/Editor.hx index a894735..7d16075 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -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(); diff --git a/src/editor/haxe/ru/m/tankz/editor/EditorView.yaml b/src/editor/haxe/ru/m/tankz/editor/EditorView.yaml index 92d286f..493ac85 100644 --- a/src/editor/haxe/ru/m/tankz/editor/EditorView.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/EditorView.yaml @@ -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 diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml index ce2dcdf..807377c 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml @@ -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 diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx index 7c62030..4c10bdb 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx +++ b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx @@ -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; } } diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml index 565ec2e..7e3f647 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml @@ -1,45 +1,37 @@ --- -$type: haxework.gui.HGroupView geometry.size.stretch: true +geometry.padding: 10 layout.hAlign: center +layout.margin: 10 views: - - $type: ru.m.tankz.editor.tank.TankView - geometry.margin.right: 20 - image: "$asset:image:resources/image/tank/bc-0.png" - color: 0xff4422 - - $type: ru.m.tankz.editor.tank.TankView - geometry.margin.right: 20 - image: "$asset:image:resources/image/tank/bc-0.png" - color: 0xf055a0 - - $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 + - id: tanks + $type: haxework.gui.GroupView + layout: + $type: haxework.gui.layout.TailLayout + rowSize: 4 + margin: 20 + views: + - $type: ru.m.tankz.editor.tank.TankView + image: "$asset:image:resources/image/tank/pa-0.png" + - $type: ru.m.tankz.editor.tank.TankView + 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 + 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 - +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 diff --git a/src/editor/resources/image/colors.png b/src/editor/resources/image/colors.png new file mode 100644 index 0000000..396dd9b Binary files /dev/null and b/src/editor/resources/image/colors.png differ