diff --git a/package.json b/package.json index 7136012..4d725ec 100755 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "yaml": "1.3.0", "orm": "2.1.0", "yield": "2.0.0", - "haxe-crypto": "0.0.7" + "haxe-crypto": "0.0.7", + "svg": "1.1.2" }, "dependencies": { "gulp-add": "0.0.2" diff --git a/src/client/haxe/ru/m/draw/BitmapUtil.hx b/src/client/haxe/ru/m/draw/BitmapUtil.hx index a29ae45..3dec2ef 100644 --- a/src/client/haxe/ru/m/draw/BitmapUtil.hx +++ b/src/client/haxe/ru/m/draw/BitmapUtil.hx @@ -1,10 +1,10 @@ package ru.m.draw; +import haxework.color.Color; import flash.geom.ColorTransform; import flash.geom.Rectangle; import flash.display.BitmapData; - class BitmapUtil { public static function colorize(data: BitmapData, color: Color):BitmapData { diff --git a/src/client/haxe/ru/m/skin/ButtonSVGSkin.hx b/src/client/haxe/ru/m/skin/ButtonSVGSkin.hx new file mode 100644 index 0000000..bfcbb63 --- /dev/null +++ b/src/client/haxe/ru/m/skin/ButtonSVGSkin.hx @@ -0,0 +1,44 @@ +package ru.m.skin; + +import haxework.color.ColorUtil; +import haxework.color.Color; +import haxework.gui.ButtonView; +import format.SVG; +import haxework.gui.skin.ISkin; + +class ButtonSVGSkin implements ISkin { + + private var svg:String; + private var color:Color; + + private var svgs:Map; + + public function new(svg:String, color:Color) { + this.svg = svg; + this.color = color; + init(); + } + + private inline function buildSVG(color:Color):SVG { + return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}')); + } + + private function init():Void { + svgs = new Map(); + svgs.set(ButtonState.UP, buildSVG(color)); + svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24))); + svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24))); + } + + public function draw(view:ButtonView):Void { + var svg = svgs.get(view.state); + var graphics = view.content.graphics; + graphics.beginFill(0, 0); + graphics.drawRect(0, 0, view.width, view.height); + graphics.beginFill(color); + graphics.lineStyle(2, ColorUtil.multiply(color, 1.5)); + svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8)); + graphics.lineStyle(); + graphics.endFill(); + } +} diff --git a/src/client/haxe/ru/m/tankz/Style.hx b/src/client/haxe/ru/m/tankz/Style.hx index 9357a60..dd0125c 100644 --- a/src/client/haxe/ru/m/tankz/Style.hx +++ b/src/client/haxe/ru/m/tankz/Style.hx @@ -1,11 +1,10 @@ package ru.m.tankz; -import haxework.gui.utils.ColorUtils; +import haxework.color.ColorUtil; import haxework.gui.skin.Skin; -import haxework.gui.skin.ButtonBitmapSkin; -import haxework.gui.utils.DrawUtil; import haxework.resources.IResources; import openfl.Assets; +import ru.m.skin.ButtonSVGSkin; class Style { @@ -17,40 +16,40 @@ class Style { private static var fontFamily = "Courirer New"; public static function register() { - var button = new ButtonBitmapSkin(); - button.fillType = FillType.NINEPATH; - button.upImage = Assets.getBitmapData("resources/image/ui/button/normal.png"); - button.downImage = Assets.getBitmapData("resources/image/ui/button/down.png"); - button.overImage = Assets.getBitmapData("resources/image/ui/button/over.png"); - resources.skin.put("light", [Skin.color(lightColor)]); resources.skin.put("dark", [Skin.color(darkColor)]); resources.skin.put("text", [Skin.text(textColor, 16, fontFamily)]); resources.skin.put("button", [ - button, + Skin.buttonColor(lightColor), Skin.text(textColor, 18, fontFamily), - Skin.size(250, 60) + Skin.size(250, 50) ]); resources.skin.put("button.simple", [ Skin.buttonColor(lightColor), Skin.text(textColor, 16, fontFamily), - Skin.size(100, 36), + Skin.size(100, 38), ]); resources.skin.put("button.tab", [ Skin.tabColor(lightColor), Skin.text(textColor, 16, fontFamily), - Skin.size(200, 36), - ]); - resources.skin.put("button.close", [ - new ButtonBitmapSkin(Assets.getBitmapData("resources/image/ui/close.png")) + Skin.size(200, 38), ]); resources.skin.put("border", [ - Skin.border(ColorUtils.multiply(lightColor, 1.5), 1, 2), + Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2), ]); resources.skin.put("button.level", [ Skin.buttonColor(lightColor), Skin.text(textColor, 24, fontFamily), Skin.size(64, 64), ]); + + resources.skin.put("button.settings", [ + Skin.size(64, 64), + new ButtonSVGSkin(Assets.getText("resources/image/icon/cog-solid.svg"), lightColor) + ]); + resources.skin.put("button.close", [ + Skin.size(64, 64), + new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor) + ]); } } diff --git a/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml b/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml index 88b772f..6d8ed89 100644 --- a/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml +++ b/src/client/haxe/ru/m/tankz/frame/StartFrame.yaml @@ -7,6 +7,7 @@ views: image: $asset:image:resources/image/ui/logo.png geometry.margin.bottom: 15 - $type: haxework.gui.VGroupView + layout.margin: 3 views: - id: classic $type: haxework.gui.ButtonView @@ -40,7 +41,8 @@ views: geometry.margin.bottom: 10 geometry.vAlign: bottom geometry.hAlign: left - skin: - - $type: haxework.gui.skin.ButtonBitmapSkin - image: $asset:image:resources/image/ui/settings.png + skinId: button.settings + # skin: + # - $type: haxework.gui.skin.ButtonBitmapSkin + # image: $asset:image:resources/image/ui/settings.png +onPress: $this:onPress diff --git a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx index 19ed981..990080d 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx +++ b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx @@ -1,19 +1,17 @@ package ru.m.tankz.frame.common; -import ru.m.draw.Color; -import ru.m.tankz.bundle.IConfigBundle; -import haxework.gui.skin.ColorSkin; +import haxework.color.Color; import haxework.gui.ButtonView; import haxework.gui.HGroupView; import haxework.gui.LabelView; import haxework.gui.list.ListView; -import haxework.gui.skin.ButtonBitmapSkin; +import haxework.gui.skin.Skin; import openfl.Assets; +import ru.m.tankz.bundle.IConfigBundle; import ru.m.tankz.control.Control; import ru.m.tankz.game.GameState; import ru.m.tankz.Type; - @:template class PlayerView extends HGroupView implements IListItemView { public var item_index(default, default):Int; @@ -25,14 +23,10 @@ import ru.m.tankz.Type; @:provide var state:GameState; @:provide var configBundle:IConfigBundle; - private function init():Void { - control.onPress.connect(onPress); - } - private function set_data(value:PlayerId):PlayerId { data = value; indexLabel.text = '${value.team} ${Std.string(data.index + 1)}'; - var color:Color = 0xffffff; + var color = 0xffffff; var config = configBundle.get(state.type); var preset = config.getPreset(state.presetId); for (team in preset.teams) { @@ -49,16 +43,15 @@ import ru.m.tankz.Type; preset.teams; } } - indexLabel.fontColor = cast color; + indexLabel.fontColor = color; var controlType = state.control.get(value); var image = Assets.getBitmapData('resources/image/ui/control/${controlType}.png'); - control.skin = [new ButtonBitmapSkin(image)]; - // ToDo: - //control.geometry.size.fixed = [image.width, image.height]; + control.skin = [Skin.buttonBitmap(image)]; + indexLabel.update(); return data; } - public function onPress(view:ButtonView):Void { + public function toggleControl():Void { if (data != null && data.index > -1) { var controlType = switch state.control.get(data) { case Control.BOT: Control.HUMAN; diff --git a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml index 20438e6..f4f200c 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml +++ b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml @@ -6,7 +6,6 @@ layout.margin: 10 views: - id: index $type: haxework.gui.LabelView - skinId: text geometry.size.stretch: true skin: - $type: haxework.gui.skin.ColorSkin @@ -16,3 +15,4 @@ views: shadowColor: 0x000000 - id: control $type: haxework.gui.ButtonView + +onPress: $code:toggleControl() diff --git a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx index b603de7..85ff38c 100644 --- a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx +++ b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx @@ -1,5 +1,6 @@ package ru.m.tankz.network; +import haxework.signal.Signal; import ru.m.tankz.proto.pack.GameRequest; import ru.m.tankz.proto.core.GameProto; import ru.m.tankz.proto.pack.StartGameRequest; @@ -11,7 +12,6 @@ import ru.m.tankz.proto.pack.JoinGameRequest; import ru.m.tankz.proto.pack.LeaveGameRequest; import ru.m.tankz.proto.pack.CreateGameRequest; import ru.m.connect.IConnection; -import ru.m.signal.Signal; import ru.m.tankz.proto.core.GameInfoProto; import ru.m.tankz.proto.pack.ListGameRequest; import ru.m.tankz.proto.pack.LoginRequest; diff --git a/src/client/haxe/ru/m/tankz/render/AnimateBundle.hx b/src/client/haxe/ru/m/tankz/render/AnimateBundle.hx index bdc9475..d162514 100644 --- a/src/client/haxe/ru/m/tankz/render/AnimateBundle.hx +++ b/src/client/haxe/ru/m/tankz/render/AnimateBundle.hx @@ -1,7 +1,7 @@ package ru.m.tankz.render; +import haxework.color.Color; import ru.m.draw.BitmapUtil; -import ru.m.draw.Color; import flash.display.BitmapData; import openfl.Assets; import ru.m.animate.Animate; diff --git a/src/client/resources/image/icon/cog-solid.svg b/src/client/resources/image/icon/cog-solid.svg new file mode 100644 index 0000000..0bc8d22 --- /dev/null +++ b/src/client/resources/image/icon/cog-solid.svg @@ -0,0 +1 @@ + diff --git a/src/client/resources/image/icon/times-circle-solid.svg b/src/client/resources/image/icon/times-circle-solid.svg new file mode 100644 index 0000000..9046b0f --- /dev/null +++ b/src/client/resources/image/icon/times-circle-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/client/resources/image/ui/button/down.png b/src/client/resources/image/ui/button/down.png deleted file mode 100644 index 7e8a4bf..0000000 Binary files a/src/client/resources/image/ui/button/down.png and /dev/null differ diff --git a/src/client/resources/image/ui/button/normal.png b/src/client/resources/image/ui/button/normal.png deleted file mode 100644 index a55b5cd..0000000 Binary files a/src/client/resources/image/ui/button/normal.png and /dev/null differ diff --git a/src/client/resources/image/ui/button/over.png b/src/client/resources/image/ui/button/over.png deleted file mode 100644 index 34c7232..0000000 Binary files a/src/client/resources/image/ui/button/over.png and /dev/null differ diff --git a/src/client/resources/image/ui/close.png b/src/client/resources/image/ui/close.png deleted file mode 100644 index 1867d86..0000000 Binary files a/src/client/resources/image/ui/close.png and /dev/null differ diff --git a/src/client/resources/image/ui/settings.png b/src/client/resources/image/ui/settings.png deleted file mode 100644 index 498edad..0000000 Binary files a/src/client/resources/image/ui/settings.png and /dev/null differ diff --git a/src/common/haxe/ru/m/connect/BaseConnection.hx b/src/common/haxe/ru/m/connect/BaseConnection.hx index 31c19d7..a718faf 100755 --- a/src/common/haxe/ru/m/connect/BaseConnection.hx +++ b/src/common/haxe/ru/m/connect/BaseConnection.hx @@ -1,11 +1,11 @@ package ru.m.connect; +import haxework.signal.Signal; import haxe.io.Bytes; import promhx.Deferred; import promhx.Promise; import protohx.Message; import ru.m.connect.IConnection; -import ru.m.signal.Signal; class BaseConnection implements IConnection { @@ -51,4 +51,4 @@ class BaseConnection implements IConnection { #if proto_debug L.d('Proto', 'receive: ${packet}'); #end receiveHandler.emit(packet); } -} \ No newline at end of file +} diff --git a/src/common/haxe/ru/m/connect/IConnection.hx b/src/common/haxe/ru/m/connect/IConnection.hx index a2dbdd7..596394f 100755 --- a/src/common/haxe/ru/m/connect/IConnection.hx +++ b/src/common/haxe/ru/m/connect/IConnection.hx @@ -1,9 +1,9 @@ package ru.m.connect; +import haxework.signal.Signal; import haxe.io.Bytes; import promhx.Promise; import protohx.Message; -import ru.m.signal.Signal; enum ConnectionEvent { diff --git a/src/common/haxe/ru/m/draw/Color.hx b/src/common/haxe/ru/m/draw/Color.hx deleted file mode 100644 index 5b67b1f..0000000 --- a/src/common/haxe/ru/m/draw/Color.hx +++ /dev/null @@ -1,47 +0,0 @@ -package ru.m.draw; - -abstract Color(Int) { - public var alpha(get, never):Int; - public var red(get, never):Int; - public var green(get, never):Int; - public var blue(get, never):Int; - public var zero(get, never):Bool; - - public inline function new(value:Int) { - this = value; - } - - private inline function get_alpha():Int { - return (this >> 24) & 255; - } - - private inline function get_red():Int { - return (this >> 16) & 255; - } - - private inline function get_green():Int { - return (this >> 8) & 255; - } - - private inline function get_blue():Int { - return this & 255; - } - - private inline function get_zero():Bool { - return green == 0 && red == 0 && blue == 0; - } - - @:from - static public inline function fromInt(value:Int):Color { - return new Color(value); - } - - @:from - static public inline function fromString(value:String):Color { - return new Color(Std.parseInt('0x${value.split('#').pop()}')); - } - - public function toString():String { - return 'Color(${red},${green},${blue})'; - } -} diff --git a/src/common/haxe/ru/m/signal/Signal.hx b/src/common/haxe/ru/m/signal/Signal.hx deleted file mode 100644 index 31a0cbe..0000000 --- a/src/common/haxe/ru/m/signal/Signal.hx +++ /dev/null @@ -1,53 +0,0 @@ -package ru.m.signal; - -typedef Signal = Signal1; - -typedef Receiver1 = A -> Void; - -class Signal1 { - - private var receivers:Array>; - - public function new() { - receivers = []; - } - - public function connect(receiver:Receiver1):Void { - receivers.push(receiver); - } - - public function disconnect(receiver:Receiver1):Void { - receivers.remove(receiver); - } - - public function emit(a:A):Void { - for (receiver in receivers) { - receiver(a); - } - } -} - -typedef Receiver2 = A -> B -> Void; - -class Signal2 { - - private var receivers:Array>; - - public function new() { - receivers = []; - } - - public function connect(receiver:Receiver2):Void { - receivers.push(receiver); - } - - public function disconnect(receiver:Receiver2):Void { - receivers.remove(receiver); - } - - public function emit(a:A, b:B):Void { - for (receiver in receivers) { - receiver(a, b); - } - } -} diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 4d29dc8..927d7b9 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -1,9 +1,8 @@ package ru.m.tankz.config; -import ru.m.draw.Color; +import haxework.color.Color; import ru.m.tankz.Type; - typedef CompleteRule = { @:optional var team:TeamId; } diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index a357596..c055080 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -1,6 +1,6 @@ package ru.m.tankz.core; -import ru.m.draw.Color; +import haxework.color.Color; import ru.m.geom.Direction; import ru.m.geom.Point; import ru.m.geom.Rectangle; @@ -8,7 +8,6 @@ import ru.m.tankz.config.Config; import ru.m.tankz.core.Bullet; import ru.m.tankz.Type; - class Tank extends MobileEntity { public var playerId(default, null):PlayerId; public var config(default, set):TankConfig; diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index d97ff12..26bb4ec 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -1,8 +1,8 @@ package ru.m.tankz.engine; +import haxework.signal.Signal; import ru.m.geom.Line; import ru.m.geom.Point; -import ru.m.signal.Signal; import ru.m.tankz.config.Config; import ru.m.tankz.control.Control; import ru.m.tankz.core.Bullet;