[add] (render) add RenderManager
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "puzzlez",
|
"name": "puzzlez",
|
||||||
"version": "0.3.6",
|
"version": "0.3.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package ru.m.puzzlez;
|
|||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import flash.system.Capabilities;
|
import flash.system.Capabilities;
|
||||||
|
|
||||||
class Const {
|
@:singleton class Const {
|
||||||
public static var FPS:Int;
|
public var FPS(default, null):Int;
|
||||||
public static var BUILD:String;
|
public var BUILD(default, null):String;
|
||||||
public static var VERSION:String;
|
public var VERSION(default, null):String;
|
||||||
public static var NAME:String;
|
public var NAME(default, null):String;
|
||||||
public static var DEBUG:Bool;
|
public var DEBUG(default, null):Bool;
|
||||||
|
|
||||||
public static function init():Void {
|
public function new():Void {
|
||||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||||
BUILD = CompilationOption.get("build");
|
BUILD = CompilationOption.get("build");
|
||||||
VERSION = Lib.current.stage.application.meta.get("version");
|
VERSION = Lib.current.stage.application.meta.get("version");
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ class PuzzlezApp extends App {
|
|||||||
GameStorage;
|
GameStorage;
|
||||||
ImageStorage;
|
ImageStorage;
|
||||||
SettingsStorage;
|
SettingsStorage;
|
||||||
Const.init();
|
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/puzzlez/packages.json");
|
updater = new Updater(Const.instance.VERSION, "https://shmyga.ru/repo/puzzlez/packages.json");
|
||||||
var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png"));
|
var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png"));
|
||||||
var view = new PuzzlezAppView();
|
var view = new PuzzlezAppView();
|
||||||
app.start(view);
|
app.start(view);
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ class PuzzlezTheme extends Theme {
|
|||||||
register(new Style("icon.image", [
|
register(new Style("icon.image", [
|
||||||
"skin.svg" => Assets.getText("resources/icon/image-polaroid.svg"),
|
"skin.svg" => Assets.getText("resources/icon/image-polaroid.svg"),
|
||||||
]));
|
]));
|
||||||
|
register(new Style("icon.lock", [
|
||||||
|
"skin.svg" => Assets.getText("resources/icon/lock-alt-solid.svg"),
|
||||||
|
]));
|
||||||
|
register(new Style("icon.restore", [
|
||||||
|
"skin.svg" => Assets.getText("resources/icon/window-restore-solid.svg"),
|
||||||
|
]));
|
||||||
register(new Style("icon.small", [
|
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),
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ import ru.m.puzzlez.core.GameEvent;
|
|||||||
interface IRender extends IView<Dynamic> {
|
interface IRender extends IView<Dynamic> {
|
||||||
public var signal(default, null):Signal<GameEvent>;
|
public var signal(default, null):Signal<GameEvent>;
|
||||||
public var scale(get, set):Float;
|
public var scale(get, set):Float;
|
||||||
|
public var manager(default, null):RenderManager;
|
||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void;
|
public function onGameEvent(event:GameEvent):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.puzzlez.render;
|
package ru.m.puzzlez.render;
|
||||||
|
|
||||||
import ru.m.puzzlez.storage.SettingsStorage;
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.PNGEncoderOptions;
|
import flash.display.PNGEncoderOptions;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
@@ -18,11 +17,13 @@ import ru.m.puzzlez.core.GameState;
|
|||||||
import ru.m.puzzlez.core.PartLocation;
|
import ru.m.puzzlez.core.PartLocation;
|
||||||
import ru.m.puzzlez.render.ImagePartBuilder;
|
import ru.m.puzzlez.render.ImagePartBuilder;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
|
import ru.m.puzzlez.storage.SettingsStorage;
|
||||||
|
|
||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
public var signal(default, null):Signal<GameEvent>;
|
public var signal(default, null):Signal<GameEvent>;
|
||||||
public var scale(get, set):Float;
|
public var scale(get, set):Float;
|
||||||
|
public var manager(default, null):RenderManager;
|
||||||
|
|
||||||
@:provide static var settings:SettingsStorage;
|
@:provide static var settings:SettingsStorage;
|
||||||
|
|
||||||
@@ -42,23 +43,29 @@ class Render extends SpriteView implements IRender {
|
|||||||
private var image:BitmapData;
|
private var image:BitmapData;
|
||||||
|
|
||||||
private var progress:ProgressView;
|
private var progress:ProgressView;
|
||||||
|
private var container:Sprite;
|
||||||
private var tableView:Sprite;
|
private var tableView:Sprite;
|
||||||
private var imageView:Sprite;
|
private var imageView:Sprite;
|
||||||
private var parts:Map<Int, PartView>;
|
private var parts:Map<Int, PartView>;
|
||||||
private var activePart:PartView;
|
private var activePart:PartView;
|
||||||
private var activePoint:Point;
|
private var activePoint:Point;
|
||||||
|
|
||||||
|
private var movePoint:FlashPoint;
|
||||||
|
|
||||||
@:provide var imageStorage:ImageStorage;
|
@:provide var imageStorage:ImageStorage;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
|
container = new Sprite();
|
||||||
|
content.addChild(container);
|
||||||
|
manager = new RenderManager(content, container);
|
||||||
progress = new ProgressView();
|
progress = new ProgressView();
|
||||||
signal = new Signal();
|
signal = new Signal();
|
||||||
tableView = new Sprite();
|
tableView = new Sprite();
|
||||||
tableView.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
tableView.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
imageView = new Sprite();
|
imageView = new Sprite();
|
||||||
tableView.addChild(imageView);
|
tableView.addChild(imageView);
|
||||||
content.addChild(tableView);
|
container.addChild(tableView);
|
||||||
parts = new Map();
|
parts = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +178,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pointPart != null) {
|
if (pointPart != null) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
if (event.ctrlKey) {
|
if (event.ctrlKey) {
|
||||||
save(pointPart);
|
save(pointPart);
|
||||||
return;
|
return;
|
||||||
@@ -212,7 +220,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
file.save(data, "icon.png");
|
file.save(data, "icon.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clean() {
|
public function clean() {
|
||||||
for (partView in parts) {
|
for (partView in parts) {
|
||||||
if (partView.parent != null) {
|
if (partView.parent != null) {
|
||||||
partView.parent.removeChild(partView);
|
partView.parent.removeChild(partView);
|
||||||
|
|||||||
52
src/haxe/ru/m/puzzlez/render/RenderManager.hx
Normal file
52
src/haxe/ru/m/puzzlez/render/RenderManager.hx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package ru.m.puzzlez.render;
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import flash.events.MouseEvent;
|
||||||
|
import flash.geom.Point;
|
||||||
|
|
||||||
|
class RenderManager {
|
||||||
|
|
||||||
|
public var locked(default, default):Bool;
|
||||||
|
|
||||||
|
private var content:DisplayObject;
|
||||||
|
private var container:DisplayObject;
|
||||||
|
private var movePoint:Point;
|
||||||
|
|
||||||
|
public function new(content:DisplayObject, container:DisplayObject) {
|
||||||
|
this.content = content;
|
||||||
|
this.container = container;
|
||||||
|
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseDown(event:MouseEvent):Void {
|
||||||
|
if (locked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
movePoint = new Point(event.stageX, event.stageY);
|
||||||
|
content.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseMove(event:MouseEvent):Void {
|
||||||
|
var newPoint = new Point(event.stageX, event.stageY);
|
||||||
|
var diff = newPoint.subtract(movePoint);
|
||||||
|
container.x += diff.x;
|
||||||
|
container.y += diff.y;
|
||||||
|
movePoint = newPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseUp(event:MouseEvent):Void {
|
||||||
|
content.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
|
movePoint = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset():Void {
|
||||||
|
container.x = 0;
|
||||||
|
container.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispose():Void {
|
||||||
|
content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,20 +67,18 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
|||||||
|
|
||||||
private function onGameEvent(event:GameEvent):Void {
|
private function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(_) | ACTION(PART_PUT(_, _)):
|
||||||
toSave();
|
|
||||||
case ACTION(PART_PUT(_, _)):
|
|
||||||
toSave();
|
toSave();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function showPreview():Void {
|
private function showPreview():Void {
|
||||||
PreviewPopup.showPreview(game.state);
|
PreviewPopup.instance.showPreview(game.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function choiseBackground():Void {
|
private function choiseBackground():Void {
|
||||||
BackgroundPopup.choise(settings.background).then(background -> {
|
BackgroundPopup.instance.choise(settings.background).then(background -> {
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
settings.background = background;
|
settings.background = background;
|
||||||
render.toRedraw();
|
render.toRedraw();
|
||||||
|
|||||||
@@ -6,14 +6,27 @@ views:
|
|||||||
- $type: haxework.view.group.VGroupView
|
- $type: haxework.view.group.VGroupView
|
||||||
geometry.height: 100%
|
geometry.height: 100%
|
||||||
geometry.padding: 5
|
geometry.padding: 5
|
||||||
|
layout.margin: 10
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.form.ButtonView
|
||||||
style: icon.image
|
style: icon.image
|
||||||
+onPress: ~showPreview()
|
+onPress: ~showPreview()
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.stretch: true
|
geometry.stretch: true
|
||||||
|
- $type: haxework.view.form.ToggleButtonView
|
||||||
|
style: icon.lock
|
||||||
|
on: true
|
||||||
|
+onPress: |
|
||||||
|
~button -> {
|
||||||
|
render.manager.locked = !render.manager.locked;
|
||||||
|
cast(button, haxework.view.form.ToggleButtonView).on = !render.manager.locked;
|
||||||
|
}
|
||||||
|
- $type: haxework.view.form.ButtonView
|
||||||
|
style: icon.restore
|
||||||
|
+onPress: ~render.manager.reset()
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.form.ButtonView
|
||||||
style: icon.setting
|
style: icon.setting
|
||||||
|
geometry.margin.top: 30
|
||||||
+onPress: ~choiseBackground()
|
+onPress: ~choiseBackground()
|
||||||
- id: render
|
- id: render
|
||||||
$type: ru.m.puzzlez.render.Render
|
$type: ru.m.puzzlez.render.Render
|
||||||
@@ -24,5 +37,5 @@ views:
|
|||||||
geometry.position: absolute
|
geometry.position: absolute
|
||||||
geometry.hAlign: right
|
geometry.hAlign: right
|
||||||
geometry.vAlign: top
|
geometry.vAlign: top
|
||||||
geometry.margin: [0, 5, 5, 0]
|
geometry.margin: 5
|
||||||
+onPress: ~back()
|
+onPress: ~back()
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ import haxework.view.group.VGroupView;
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
Const.init();
|
resources.text.put("version", Const.instance.VERSION);
|
||||||
resources.text.put("version", Const.VERSION);
|
resources.text.put("name", Const.instance.NAME);
|
||||||
resources.text.put("name", Const.NAME);
|
|
||||||
switcher = switcherView;
|
switcher = switcherView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import ru.m.puzzlez.core.Id.ImageId;
|
|||||||
import ru.m.puzzlez.render.Background;
|
import ru.m.puzzlez.render.Background;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
|
|
||||||
@:template class BackgroundPopup extends PopupView<Background> {
|
@:singleton @:template class BackgroundPopup extends PopupView<Background> {
|
||||||
|
|
||||||
private static var colorsList:Array<Color> = [
|
private static var colorsList:Array<Color> = [
|
||||||
'#FFFFFF',
|
'#FFFFFF',
|
||||||
@@ -42,7 +42,7 @@ import ru.m.puzzlez.storage.ImageStorage;
|
|||||||
|
|
||||||
public var selected(default, set):Background;
|
public var selected(default, set):Background;
|
||||||
|
|
||||||
@:provide var imageStorage:ImageStorage;
|
@:provide static var imageStorage:ImageStorage;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
@@ -87,9 +87,8 @@ import ru.m.puzzlez.storage.ImageStorage;
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function choise(current:Background):Promise<Background> {
|
public function choise(current:Background):Promise<Background> {
|
||||||
var result = new BackgroundPopup();
|
selected = current;
|
||||||
result.selected = current;
|
return show();
|
||||||
return result.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,19 @@ import flash.events.MouseEvent;
|
|||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.puzzlez.core.GameState;
|
import ru.m.puzzlez.core.GameState;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
|
||||||
import ru.m.puzzlez.view.common.PresetView;
|
import ru.m.puzzlez.view.common.PresetView;
|
||||||
|
|
||||||
@:template class PreviewPopup extends PopupView<Dynamic> {
|
@:singleton @:template class PreviewPopup extends PopupView<Dynamic> {
|
||||||
|
|
||||||
@:view("preview") var previewView:PresetView;
|
@:view("preview") var previewView:PresetView;
|
||||||
@:provide static var imageStorage:ImageStorage;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
content.addEventListener(MouseEvent.CLICK, _ -> close(null));
|
content.addEventListener(MouseEvent.CLICK, _ -> close(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function showPreview(state:GameState):Promise<Dynamic> {
|
public function showPreview(state:GameState):Promise<Dynamic> {
|
||||||
var result = new PreviewPopup();
|
previewView.state = state;
|
||||||
result.previewView.state = state;
|
return show();
|
||||||
return result.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.m.skin;
|
|||||||
import format.SVG;
|
import format.SVG;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.form.ButtonView;
|
||||||
|
import haxework.view.form.ToggleButtonView;
|
||||||
import haxework.view.skin.ISkin;
|
import haxework.view.skin.ISkin;
|
||||||
|
|
||||||
using StringTools;
|
using StringTools;
|
||||||
@@ -47,6 +48,12 @@ using haxework.color.ColorUtil;
|
|||||||
update();
|
update();
|
||||||
var svg = svgs.get(view.state);
|
var svg = svgs.get(view.state);
|
||||||
var graphics = view.content.graphics;
|
var graphics = view.content.graphics;
|
||||||
|
var color = this.color;
|
||||||
|
if (Std.is(view, ToggleButtonView)) {
|
||||||
|
if (!cast(view, ToggleButtonView).on) {
|
||||||
|
color = color.multiply(0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
graphics.beginFill(0, 0);
|
graphics.beginFill(0, 0);
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
graphics.beginFill(color);
|
graphics.beginFill(color);
|
||||||
|
|||||||
6
src/resources/icon/lock-alt-solid.svg
Normal file
6
src/resources/icon/lock-alt-solid.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lock-alt" role="img"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-lock-alt fa-w-14 fa-2x">
|
||||||
|
<path fill="currentColor"
|
||||||
|
d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zM264 392c0 22.1-17.9 40-40 40s-40-17.9-40-40v-48c0-22.1 17.9-40 40-40s40 17.9 40 40v48zm32-168H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"
|
||||||
|
class=""></path>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 582 B |
6
src/resources/icon/window-restore-solid.svg
Normal file
6
src/resources/icon/window-restore-solid.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="window-restore" role="img"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-window-restore fa-w-16 fa-2x">
|
||||||
|
<path fill="currentColor"
|
||||||
|
d="M512 48v288c0 26.5-21.5 48-48 48h-48V176c0-44.1-35.9-80-80-80H128V48c0-26.5 21.5-48 48-48h288c26.5 0 48 21.5 48 48zM384 176v288c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V176c0-26.5 21.5-48 48-48h288c26.5 0 48 21.5 48 48zm-68 28c0-6.6-5.4-12-12-12H76c-6.6 0-12 5.4-12 12v52h252v-52z"
|
||||||
|
class=""></path>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 580 B |
Reference in New Issue
Block a user