[update] implement geom from haxework
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
package ru.m.puzzlez;
|
|
||||||
|
|
||||||
import flash.display.BitmapData;
|
|
||||||
import flash.filters.ColorMatrixFilter;
|
|
||||||
import flash.geom.Point;
|
|
||||||
import flash.Lib;
|
|
||||||
import openfl.Assets;
|
|
||||||
|
|
||||||
class LinuxIcon {
|
|
||||||
|
|
||||||
private static function prepareIcon(bitmap:BitmapData):BitmapData {
|
|
||||||
var matrix:Array<Float> = [];
|
|
||||||
matrix = matrix.concat([0, 0, 1, 0, 0]);
|
|
||||||
matrix = matrix.concat([0, 1, 0, 0, 0]);
|
|
||||||
matrix = matrix.concat([1, 0, 0, 0, 0]);
|
|
||||||
matrix = matrix.concat([0, 0, 0, 1, 0]);
|
|
||||||
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
|
|
||||||
var bitmap:BitmapData = bitmap.clone();
|
|
||||||
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function apply() {
|
|
||||||
var icon = Assets.getBitmapData("resources/icon.png");
|
|
||||||
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,10 +8,7 @@ class PuzzlezApp extends App {
|
|||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
#if linux
|
var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png"));
|
||||||
LinuxIcon.apply();
|
|
||||||
#end
|
|
||||||
var app = new PuzzlezApp(new PuzzlezTheme());
|
|
||||||
var view = new PuzzlezAppView();
|
var view = new PuzzlezAppView();
|
||||||
app.start(view);
|
app.start(view);
|
||||||
view.launch();
|
view.launch();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.puzzlez;
|
package ru.m.puzzlez;
|
||||||
|
|
||||||
|
import haxework.view.geometry.VAlign;
|
||||||
|
import haxework.view.geometry.HAlign;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import haxework.view.geometry.Box;
|
import haxework.view.geometry.Box;
|
||||||
import haxework.view.geometry.SizeValue;
|
import haxework.view.geometry.SizeValue;
|
||||||
@@ -11,7 +13,9 @@ class PuzzlezTheme extends Theme {
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super({embed: true}, {light: "gray"}, {base: 22});
|
super({embed: true}, {light: "gray"}, {base: 22});
|
||||||
data.get("frame").data.set("geometry.padding", Box.fromFloat(8));
|
register(new Style("frame", [
|
||||||
|
"geometry.padding" => Box.fromFloat(8),
|
||||||
|
]));
|
||||||
register(new Style("view", [
|
register(new Style("view", [
|
||||||
"skin.background.color" => colors.light,
|
"skin.background.color" => colors.light,
|
||||||
"skin.border.color" => colors.border,
|
"skin.border.color" => colors.border,
|
||||||
@@ -22,25 +26,31 @@ class PuzzlezTheme extends Theme {
|
|||||||
register(new Style("text.error", [
|
register(new Style("text.error", [
|
||||||
"font.color" => Color.fromString("red"),
|
"font.color" => Color.fromString("red"),
|
||||||
], "text"));
|
], "text"));
|
||||||
registerButton("close", "times-circle-solid.svg", false, 0xcc5500);
|
|
||||||
registerButton("close-red", "times-circle-solid.svg", false, 0xcc0000);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function registerButton(name:String, resource:String, solid:Bool = false, color:Color = null):Void {
|
|
||||||
if (color == null) {
|
|
||||||
color = colors.light;
|
|
||||||
}
|
|
||||||
var size = 42;
|
var size = 42;
|
||||||
var smallSize = 32;
|
var smallSize = 32;
|
||||||
register(new Style('button.$name', [
|
register(new Style("icon", [
|
||||||
"geometry.width" => SizeValue.fromInt(size),
|
"geometry.width" => SizeValue.fromInt(size),
|
||||||
"geometry.height" => SizeValue.fromInt(size),
|
"geometry.height" => SizeValue.fromInt(size),
|
||||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), color, solid),
|
"skin" => function() return new ButtonSVGSkin(),
|
||||||
]));
|
]));
|
||||||
register(new Style('button.$name.small', [
|
register(new Style("icon.close", [
|
||||||
|
"skin.svg" => Assets.getText("resources/image/icon/times-circle-solid.svg"),
|
||||||
|
]));
|
||||||
|
register(new Style("icon.small", [
|
||||||
"geometry.width" => SizeValue.fromInt(smallSize),
|
"geometry.width" => SizeValue.fromInt(smallSize),
|
||||||
"geometry.height" => SizeValue.fromInt(smallSize),
|
"geometry.height" => SizeValue.fromInt(smallSize),
|
||||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), color, solid),
|
]));
|
||||||
|
register(new Style("icon.red", [
|
||||||
|
"skin.color" => 0xcc0000,
|
||||||
|
]));
|
||||||
|
register(new Style("icon.orange", [
|
||||||
|
"skin.color" => 0xcc5500,
|
||||||
|
]));
|
||||||
|
register(new Style("icon.control", [
|
||||||
|
"geometry.hAlign" => HAlign.RIGHT,
|
||||||
|
"geometry.vAlign" => VAlign.TOP,
|
||||||
|
"geometry.margin" => Box.fromFloat(3),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Point;
|
import haxework.geom.Point;
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import ru.m.puzzlez.core.GameEvent;
|
import ru.m.puzzlez.core.GameEvent;
|
||||||
import ru.m.puzzlez.core.PartLocation;
|
import ru.m.puzzlez.core.PartLocation;
|
||||||
@@ -66,7 +66,7 @@ class Game implements IGame {
|
|||||||
signal.emit(CHANGE(PART_UPDATE(id, part.location)));
|
signal.emit(CHANGE(PART_UPDATE(id, part.location)));
|
||||||
case ACTION(PART_PUT(id, point)):
|
case ACTION(PART_PUT(id, point)):
|
||||||
var part:Part = partsById[id];
|
var part:Part = partsById[id];
|
||||||
var target:Point = state.preset.imageRect.topLeft.clone();
|
var target:Point = state.preset.imageRect.position.clone();
|
||||||
target = target.add(new Point(part.gridX * part.rect.width, part.gridY * part.rect.height));
|
target = target.add(new Point(part.gridX * part.rect.width, part.gridY * part.rect.height));
|
||||||
var d = distance(target, point);
|
var d = distance(target, point);
|
||||||
if (d < 70) {
|
if (d < 70) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Point;
|
import haxework.geom.Point;
|
||||||
|
|
||||||
enum GameAction {
|
enum GameAction {
|
||||||
PART_TAKE(id:Int);
|
PART_TAKE(id:Int);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
|
|
||||||
typedef GamePreset = {
|
typedef GamePreset = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Point;
|
import haxework.geom.Point;
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
import ru.m.puzzlez.core.BoundType;
|
import ru.m.puzzlez.core.BoundType;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
@@ -90,7 +90,7 @@ class GameUtil {
|
|||||||
var parts:Array<Part> = [];
|
var parts:Array<Part> = [];
|
||||||
var partWidth = preset.imageRect.width / preset.grid.width;
|
var partWidth = preset.imageRect.width / preset.grid.width;
|
||||||
var partHeight = preset.imageRect.height / preset.grid.height;
|
var partHeight = preset.imageRect.height / preset.grid.height;
|
||||||
var topLeft = preset.imageRect.topLeft;
|
var position = preset.imageRect.position;
|
||||||
var boundsMap = new BoundsMap(preset.grid);
|
var boundsMap = new BoundsMap(preset.grid);
|
||||||
for (y in 0...preset.grid.height) {
|
for (y in 0...preset.grid.height) {
|
||||||
for (x in 0...preset.grid.width) {
|
for (x in 0...preset.grid.width) {
|
||||||
@@ -113,7 +113,7 @@ class GameUtil {
|
|||||||
bounds.bottom = boundsMap.buildNonePartBound();
|
bounds.bottom = boundsMap.buildNonePartBound();
|
||||||
}
|
}
|
||||||
var id = (x << 16) + y;
|
var id = (x << 16) + y;
|
||||||
var position = new Point(topLeft.x + x * partWidth, topLeft.y + y * partHeight);
|
var position = new Point(position.x + x * partWidth, position.y + y * partHeight);
|
||||||
parts.push({
|
parts.push({
|
||||||
id: id,
|
id: id,
|
||||||
gridX: x,
|
gridX: x,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
|
|
||||||
typedef PartBound = {
|
typedef PartBound = {
|
||||||
var spike:BoundType;
|
var spike:BoundType;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.puzzlez.core;
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
import flash.geom.Point;
|
import haxework.geom.Point;
|
||||||
|
|
||||||
enum PartLocation {
|
enum PartLocation {
|
||||||
//PANEL(index:Int);
|
//PANEL(index:Int);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package ru.m.puzzlez.render;
|
package ru.m.puzzlez.render;
|
||||||
|
|
||||||
|
import haxework.geom.Point;
|
||||||
import flash.display.Bitmap;
|
import flash.display.Bitmap;
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.PixelSnapping;
|
import flash.display.PixelSnapping;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.geom.Point;
|
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
|
|
||||||
class PartView extends Sprite {
|
class PartView extends Sprite {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package ru.m.puzzlez.render;
|
package ru.m.puzzlez.render;
|
||||||
|
|
||||||
|
import haxework.geom.Point;
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.PNGEncoderOptions;
|
import flash.display.PNGEncoderOptions;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
import flash.geom.Point;
|
import flash.geom.Point as FlashPoint;
|
||||||
import flash.geom.Rectangle;
|
import flash.geom.Rectangle;
|
||||||
import flash.net.FileReference;
|
import flash.net.FileReference;
|
||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
@@ -138,7 +139,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
}
|
}
|
||||||
activePart = part;
|
activePart = part;
|
||||||
tableView.setChildIndex(activePart, tableView.numChildren - 1);
|
tableView.setChildIndex(activePart, tableView.numChildren - 1);
|
||||||
activePoint = tableView.globalToLocal(new Point(event.stageX, event.stageY));
|
activePoint = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY));
|
||||||
tableView.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
tableView.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
tableView.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
tableView.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
signal.emit(ACTION(PART_TAKE(activePart.id)));
|
signal.emit(ACTION(PART_TAKE(activePart.id)));
|
||||||
@@ -146,14 +147,14 @@ class Render extends SpriteView implements IRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseMove(event:MouseEvent):Void {
|
private function onMouseMove(event:MouseEvent):Void {
|
||||||
var newPoint = tableView.globalToLocal(new Point(event.stageX, event.stageY));
|
var newPoint:Point = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY));
|
||||||
var partPosition = activePart.position.add(newPoint).subtract(activePoint);
|
var partPosition = activePart.position.add(newPoint).subtract(activePoint);
|
||||||
signal.emit(ACTION(PART_MOVE(activePart.id, partPosition.clone())));
|
signal.emit(ACTION(PART_MOVE(activePart.id, partPosition.clone())));
|
||||||
activePoint = newPoint;
|
activePoint = newPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseUp(event:MouseEvent):Void {
|
private function onMouseUp(event:MouseEvent):Void {
|
||||||
var newPoint = tableView.globalToLocal(new Point(event.stageX, event.stageY));
|
var newPoint:Point = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY));
|
||||||
var partPosition = activePart.position.add(newPoint).subtract(activePoint);
|
var partPosition = activePart.position.add(newPoint).subtract(activePoint);
|
||||||
signal.emit(ACTION(PART_PUT(activePart.id, partPosition.clone())));
|
signal.emit(ACTION(PART_PUT(activePart.id, partPosition.clone())));
|
||||||
tableView.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
tableView.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import flash.filters.BitmapFilter;
|
|||||||
import flash.filters.BitmapFilterQuality;
|
import flash.filters.BitmapFilterQuality;
|
||||||
import flash.filters.DropShadowFilter;
|
import flash.filters.DropShadowFilter;
|
||||||
import flash.geom.Matrix;
|
import flash.geom.Matrix;
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
import ru.m.puzzlez.render.mask.PartMask;
|
import ru.m.puzzlez.render.mask.PartMask;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.puzzlez.render.mask;
|
package ru.m.puzzlez.render.mask;
|
||||||
|
|
||||||
import flash.display.GraphicsPathCommand;
|
import flash.display.GraphicsPathCommand;
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
import openfl.Vector;
|
import openfl.Vector;
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
import ru.m.puzzlez.render.mask.IPartMaskBuilder;
|
import ru.m.puzzlez.render.mask.IPartMaskBuilder;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.puzzlez.render.mask;
|
package ru.m.puzzlez.render.mask;
|
||||||
|
|
||||||
import flash.display.GraphicsPathCommand;
|
import flash.display.GraphicsPathCommand;
|
||||||
import flash.geom.Rectangle;
|
|
||||||
import flash.Vector;
|
import flash.Vector;
|
||||||
|
import haxework.geom.Rectangle;
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
|
|
||||||
typedef DrawPath = {
|
typedef DrawPath = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.puzzlez.render.mask;
|
package ru.m.puzzlez.render.mask;
|
||||||
|
|
||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
import flash.geom.Rectangle;
|
import haxework.geom.Rectangle;
|
||||||
import ru.m.puzzlez.core.Part;
|
import ru.m.puzzlez.core.Part;
|
||||||
import ru.m.puzzlez.render.mask.IPartMaskBuilder;
|
import ru.m.puzzlez.render.mask.IPartMaskBuilder;
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class LoadingWrapper {
|
|||||||
private function set_promise(value:Promise<Dynamic>):Promise<Dynamic> {
|
private function set_promise(value:Promise<Dynamic>):Promise<Dynamic> {
|
||||||
state = LOADING;
|
state = LOADING;
|
||||||
value
|
value
|
||||||
.then(function(_) state = NONE);
|
.then(function(_) state = NONE)
|
||||||
//.catchError(function(error) state = ERROR(error));
|
.catchError(function(error) state = ERROR(error));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class LoadingWrapper {
|
|||||||
overlay = loadingView;
|
overlay = loadingView;
|
||||||
case ERROR(error):
|
case ERROR(error):
|
||||||
cast(errorView, TextView).text = Std.string(error);
|
cast(errorView, TextView).text = Std.string(error);
|
||||||
//overlay = errorView;
|
overlay = errorView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ views:
|
|||||||
- id: remove
|
- id: remove
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
propagation: false
|
propagation: false
|
||||||
geometry.hAlign: right
|
style: icon.control.small.close.red
|
||||||
style: button.close-red.small
|
|
||||||
+onPress: ~emit(Action.REMOVE)
|
+onPress: ~emit(Action.REMOVE)
|
||||||
- id: clean
|
- id: clean
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
propagation: false
|
propagation: false
|
||||||
geometry.hAlign: right
|
style: icon.control.small.close.orange
|
||||||
style: button.close.small
|
|
||||||
+onPress: ~emit(Action.CLEAN)
|
+onPress: ~emit(Action.CLEAN)
|
||||||
|
|||||||
@@ -15,31 +15,36 @@ using haxework.color.ColorUtil;
|
|||||||
@:style(false) public var solid:Null<Bool>;
|
@:style(false) public var solid:Null<Bool>;
|
||||||
|
|
||||||
private var svgs:Map<ButtonState, SVG>;
|
private var svgs:Map<ButtonState, SVG>;
|
||||||
|
private var needUpdate:Bool;
|
||||||
|
|
||||||
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.solid = solid;
|
this.solid = solid;
|
||||||
init(solid);
|
this.needUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function buildSVG(color:Color):SVG {
|
private inline function buildSVG(color:Color):SVG {
|
||||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init(solid:Bool):Void {
|
private function update():Void {
|
||||||
var color = color;
|
if (needUpdate && svg != null) {
|
||||||
if (solid) {
|
var color = color;
|
||||||
color = color.multiply(1.5);
|
if (solid) {
|
||||||
|
color = color.multiply(1.5);
|
||||||
|
}
|
||||||
|
svgs = new Map();
|
||||||
|
svgs.set(UP, buildSVG(color));
|
||||||
|
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||||
|
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||||
|
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||||
|
needUpdate = false;
|
||||||
}
|
}
|
||||||
svgs = new Map();
|
|
||||||
svgs.set(UP, buildSVG(color));
|
|
||||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
|
||||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
|
||||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(view:ButtonView):Void {
|
public function draw(view:ButtonView):Void {
|
||||||
|
update();
|
||||||
var svg = svgs.get(view.state);
|
var svg = svgs.get(view.state);
|
||||||
var graphics = view.content.graphics;
|
var graphics = view.content.graphics;
|
||||||
graphics.beginFill(0, 0);
|
graphics.beginFill(0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user