[update] PuzzleImageView clean/remove buttons
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
include ':android'
|
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ class PuzzlezTheme extends Theme {
|
|||||||
"font.color" => Color.fromString("red"),
|
"font.color" => Color.fromString("red"),
|
||||||
], "text"));
|
], "text"));
|
||||||
registerButton("close", "times-circle-solid.svg", false, 0xcc5500);
|
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 {
|
private function registerButton(name:String, resource:String, solid:Bool = false, color:Color = null):Void {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class FileSource implements IImageSource<Dynamic> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getList(?type:Dynamic):Promise<Array<ImageId>> {
|
public function getList(?type:Dynamic):Promise<Array<ImageId>> {
|
||||||
return Promise.promise([for (name in Reflect.fields(listData.data)) new ImageId(id, name)]);
|
return Promise.promise([for (key in Reflect.fields(listData.data)) ImageId.fromString(key)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadImage(id:ImageId, preview:Bool = false):Promise<BitmapData> {
|
public function loadImage(id:ImageId, preview:Bool = false):Promise<BitmapData> {
|
||||||
@@ -42,7 +42,7 @@ class FileSource implements IImageSource<Dynamic> {
|
|||||||
var fileData = SharedObject.getLocal(imageId);
|
var fileData = SharedObject.getLocal(imageId);
|
||||||
fileData.setProperty("image", data.toHex());
|
fileData.setProperty("image", data.toHex());
|
||||||
fileData.flush();
|
fileData.flush();
|
||||||
listData.setProperty(name, true);
|
listData.setProperty(imageId, true);
|
||||||
listData.flush();
|
listData.flush();
|
||||||
return imageId;
|
return imageId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,15 +29,16 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
switcher.change(GameFrame.ID, storage.read(id));
|
switcher.change(GameFrame.ID, storage.read(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onAction(id:ImageId, action:Action):Void {
|
private function onAction(imageId:ImageId, action:Action):Void {
|
||||||
switch action {
|
switch action {
|
||||||
case REMOVE:
|
case CLEAN:
|
||||||
ConfirmView.confirm("Delete?").then(function(result) {
|
ConfirmView.confirm("Delete state?").then(function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
storage.delete(id);
|
storage.delete(imageId);
|
||||||
images.data = storage.listIds();
|
images.data = storage.listIds();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,16 +56,27 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
case REMOVE:
|
case REMOVE:
|
||||||
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
||||||
if (fileSource != null) {
|
if (fileSource != null) {
|
||||||
ConfirmView.confirm("Delete?").then(function(result) {
|
ConfirmView.confirm("Delete image?").then(function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
fileSource.remove(imageId);
|
fileSource.remove(imageId);
|
||||||
loading.promise = fileSource.getList().then(function(result) images.data = result);
|
refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
case CLEAN:
|
||||||
|
ConfirmView.confirm("Delete state?").then(function(result) {
|
||||||
|
if (result) {
|
||||||
|
gameStorage.delete(imageId);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function refresh():Void {
|
||||||
|
loading.promise = source.source.getList().then(function(result) images.data = result);
|
||||||
|
}
|
||||||
|
|
||||||
private function start(imageId:ImageId):Void {
|
private function start(imageId:ImageId):Void {
|
||||||
var state = gameStorage.read(imageId);
|
var state = gameStorage.read(imageId);
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import haxework.view.group.GroupView;
|
|||||||
import haxework.view.ImageView;
|
import haxework.view.ImageView;
|
||||||
import ru.m.puzzlez.core.GameUtil;
|
import ru.m.puzzlez.core.GameUtil;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
|
import ru.m.puzzlez.source.FileSource;
|
||||||
import ru.m.puzzlez.storage.GameStorage;
|
import ru.m.puzzlez.storage.GameStorage;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
|
|
||||||
enum Action {
|
enum Action {
|
||||||
|
CLEAN;
|
||||||
REMOVE;
|
REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ enum Action {
|
|||||||
|
|
||||||
@:view("image") var imageView:ImageView;
|
@:view("image") var imageView:ImageView;
|
||||||
@:view("label") var labelView:LabelView;
|
@:view("label") var labelView:LabelView;
|
||||||
|
@:view("clean") var cleanButton:ButtonView;
|
||||||
@:view("remove") var removeButton:ButtonView;
|
@:view("remove") var removeButton:ButtonView;
|
||||||
@:provide static var imageStorage:ImageStorage;
|
@:provide static var imageStorage:ImageStorage;
|
||||||
@:provide static var gameStorage:GameStorage;
|
@:provide static var gameStorage:GameStorage;
|
||||||
@@ -45,6 +48,8 @@ enum Action {
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
|
cleanButton.visible = false;
|
||||||
|
removeButton.visible = false;
|
||||||
loading = new LoadingWrapper(this);
|
loading = new LoadingWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +68,9 @@ enum Action {
|
|||||||
if (state != null) {
|
if (state != null) {
|
||||||
var progress = GameUtil.calcProgress(state);
|
var progress = GameUtil.calcProgress(state);
|
||||||
result.text = '${progress.complete}/${progress.total}';
|
result.text = '${progress.complete}/${progress.total}';
|
||||||
|
result.cleanButton.visible = true;
|
||||||
|
} else if (imageId.source == FileSource.ID) {
|
||||||
|
result.removeButton.visible = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,11 @@ views:
|
|||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
propagation: false
|
propagation: false
|
||||||
geometry.hAlign: right
|
geometry.hAlign: right
|
||||||
style: button.close.small
|
style: button.close-red.small
|
||||||
+onPress: ~emit(Action.REMOVE)
|
+onPress: ~emit(Action.REMOVE)
|
||||||
|
- id: clean
|
||||||
|
$type: haxework.view.form.ButtonView
|
||||||
|
propagation: false
|
||||||
|
geometry.hAlign: right
|
||||||
|
style: button.close.small
|
||||||
|
+onPress: ~emit(Action.CLEAN)
|
||||||
|
|||||||
Reference in New Issue
Block a user