[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"),
|
||||
], "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 {
|
||||
|
||||
@@ -20,7 +20,7 @@ class FileSource implements IImageSource<Dynamic> {
|
||||
}
|
||||
|
||||
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> {
|
||||
@@ -42,7 +42,7 @@ class FileSource implements IImageSource<Dynamic> {
|
||||
var fileData = SharedObject.getLocal(imageId);
|
||||
fileData.setProperty("image", data.toHex());
|
||||
fileData.flush();
|
||||
listData.setProperty(name, true);
|
||||
listData.setProperty(imageId, true);
|
||||
listData.flush();
|
||||
return imageId;
|
||||
}
|
||||
|
||||
@@ -29,15 +29,16 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
||||
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 {
|
||||
case REMOVE:
|
||||
ConfirmView.confirm("Delete?").then(function(result) {
|
||||
case CLEAN:
|
||||
ConfirmView.confirm("Delete state?").then(function(result) {
|
||||
if (result) {
|
||||
storage.delete(id);
|
||||
storage.delete(imageId);
|
||||
images.data = storage.listIds();
|
||||
}
|
||||
});
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,14 +56,25 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
||||
case REMOVE:
|
||||
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
||||
if (fileSource != null) {
|
||||
ConfirmView.confirm("Delete?").then(function(result) {
|
||||
ConfirmView.confirm("Delete image?").then(function(result) {
|
||||
if (result) {
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,10 +7,12 @@ import haxework.view.group.GroupView;
|
||||
import haxework.view.ImageView;
|
||||
import ru.m.puzzlez.core.GameUtil;
|
||||
import ru.m.puzzlez.core.Id;
|
||||
import ru.m.puzzlez.source.FileSource;
|
||||
import ru.m.puzzlez.storage.GameStorage;
|
||||
import ru.m.puzzlez.storage.ImageStorage;
|
||||
|
||||
enum Action {
|
||||
CLEAN;
|
||||
REMOVE;
|
||||
}
|
||||
|
||||
@@ -38,6 +40,7 @@ enum Action {
|
||||
|
||||
@:view("image") var imageView:ImageView;
|
||||
@:view("label") var labelView:LabelView;
|
||||
@:view("clean") var cleanButton:ButtonView;
|
||||
@:view("remove") var removeButton:ButtonView;
|
||||
@:provide static var imageStorage:ImageStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@@ -45,6 +48,8 @@ enum Action {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
cleanButton.visible = false;
|
||||
removeButton.visible = false;
|
||||
loading = new LoadingWrapper(this);
|
||||
}
|
||||
|
||||
@@ -63,6 +68,9 @@ enum Action {
|
||||
if (state != null) {
|
||||
var progress = GameUtil.calcProgress(state);
|
||||
result.text = '${progress.complete}/${progress.total}';
|
||||
result.cleanButton.visible = true;
|
||||
} else if (imageId.source == FileSource.ID) {
|
||||
result.removeButton.visible = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,5 +12,11 @@ views:
|
||||
$type: haxework.view.form.ButtonView
|
||||
propagation: false
|
||||
geometry.hAlign: right
|
||||
style: button.close.small
|
||||
style: button.close-red.small
|
||||
+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