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