[remove] remove GameListFrame
This commit is contained in:
10
src/haxe/ru/m/puzzlez/core/ImageListSource.hx
Normal file
10
src/haxe/ru/m/puzzlez/core/ImageListSource.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.m.puzzlez.core;
|
||||||
|
|
||||||
|
import ru.m.data.IDataSource;
|
||||||
|
import ru.m.puzzlez.core.Id;
|
||||||
|
|
||||||
|
typedef ImageListSource = {
|
||||||
|
var title:String;
|
||||||
|
var source:IDataIndex<ImageId>;
|
||||||
|
@:optional var filter:Filter;
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import promhx.Promise;
|
|||||||
import ru.m.data.IDataSource;
|
import ru.m.data.IDataSource;
|
||||||
import ru.m.pixabay.PixabayApi;
|
import ru.m.pixabay.PixabayApi;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
|
import ru.m.puzzlez.core.ImageListSource;
|
||||||
import ru.m.puzzlez.storage.CacheStorage;
|
import ru.m.puzzlez.storage.CacheStorage;
|
||||||
|
|
||||||
class PixabaySource implements IImageSource {
|
class PixabaySource implements IImageSource {
|
||||||
@@ -41,4 +42,12 @@ class PixabaySource implements IImageSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function categorySource(category:PixabayCategory):ImageListSource {
|
||||||
|
return {
|
||||||
|
title: category,
|
||||||
|
source: this,
|
||||||
|
filter: ["type" => category],
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package ru.m.puzzlez.storage;
|
package ru.m.puzzlez.storage;
|
||||||
|
|
||||||
|
import ru.m.data.DataStorage;
|
||||||
import ru.m.puzzlez.core.GameState;
|
import ru.m.puzzlez.core.GameState;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
import ru.m.data.DataStorage;
|
import ru.m.puzzlez.core.ImageListSource;
|
||||||
|
|
||||||
@:provide class GameStorage extends DataStorage<ImageId, GameState> {
|
@:provide class GameStorage extends DataStorage<ImageId, GameState> {
|
||||||
inline private static var NAME = "game";
|
inline private static var NAME = "game";
|
||||||
@@ -15,4 +16,12 @@ import ru.m.data.DataStorage;
|
|||||||
new Converter<ImageId, String>(id -> id.toString(), data -> ImageId.fromString(data))
|
new Converter<ImageId, String>(id -> id.toString(), data -> ImageId.fromString(data))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function statusSource(status:GameStatus):ImageListSource {
|
||||||
|
return {
|
||||||
|
title: status,
|
||||||
|
source: this,
|
||||||
|
filter: ["status" => status],
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
|||||||
(game.state.status == COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?"))
|
(game.state.status == COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?"))
|
||||||
.then(result -> {
|
.then(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
switcher.change(GameListFrame.ID, game.state.status);
|
switcher.change(ImageListFrame.ID, storage.statusSource(game.state.status));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package ru.m.puzzlez.view;
|
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
|
||||||
import haxework.view.frame.FrameView;
|
|
||||||
import ru.m.puzzlez.core.GameState;
|
|
||||||
import ru.m.puzzlez.storage.GameStorage;
|
|
||||||
import ru.m.puzzlez.view.common.ImageDataList;
|
|
||||||
|
|
||||||
@:template class GameListFrame extends FrameView<GameStatus> {
|
|
||||||
|
|
||||||
public static var ID(default, never) = "game_list";
|
|
||||||
|
|
||||||
@:view("images") var imagesView:ImageDataList;
|
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
|
||||||
@:provide var storage:GameStorage;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(ID);
|
|
||||||
imagesView.source = storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onShow(data:GameStatus):Void {
|
|
||||||
imagesView.reset();
|
|
||||||
imagesView.page.filter = ["status" => data];
|
|
||||||
imagesView.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function back():Void {
|
|
||||||
switcher.change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
style: frame
|
|
||||||
views:
|
|
||||||
- id: images
|
|
||||||
$type: ru.m.puzzlez.view.common.ImageDataList
|
|
||||||
geometry.stretch: true
|
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
text: Back
|
|
||||||
geometry.position: absolute
|
|
||||||
geometry.hAlign: right
|
|
||||||
geometry.vAlign: top
|
|
||||||
+onPress: ~back()
|
|
||||||
@@ -3,8 +3,10 @@ package ru.m.puzzlez.view;
|
|||||||
import haxework.view.form.ButtonView;
|
import haxework.view.form.ButtonView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.frame.FrameView;
|
||||||
|
import ru.m.puzzlez.core.ImageListSource;
|
||||||
import ru.m.puzzlez.FileUtil;
|
import ru.m.puzzlez.FileUtil;
|
||||||
import ru.m.puzzlez.source.FileSource;
|
import ru.m.puzzlez.source.FileSource;
|
||||||
|
import ru.m.puzzlez.storage.GameStorage;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
import ru.m.puzzlez.view.common.ImageDataList;
|
import ru.m.puzzlez.view.common.ImageDataList;
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ import ru.m.puzzlez.view.common.ImageDataList;
|
|||||||
@:view("images") var imagesView:ImageDataList;
|
@:view("images") var imagesView:ImageDataList;
|
||||||
@:view var select:ButtonView;
|
@:view var select:ButtonView;
|
||||||
|
|
||||||
|
@:provide var gameStorage:GameStorage;
|
||||||
@:provide var imageStorage:ImageStorage;
|
@:provide var imageStorage:ImageStorage;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
|
||||||
@@ -24,8 +27,9 @@ import ru.m.puzzlez.view.common.ImageDataList;
|
|||||||
override public function onShow(data:ImageListSource):Void {
|
override public function onShow(data:ImageListSource):Void {
|
||||||
imagesView.reset();
|
imagesView.reset();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
select.visible = data.source.id == FileSource.ID;
|
// ToDo:
|
||||||
imagesView.page.filter = ["type" => data.type];
|
//select.visible = data.source.id == FileSource.ID;
|
||||||
|
imagesView.page.filter = data.filter;
|
||||||
imagesView.source = data.source;
|
imagesView.source = data.source;
|
||||||
imagesView.refresh();
|
imagesView.refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package ru.m.puzzlez.view;
|
|
||||||
|
|
||||||
import ru.m.puzzlez.source.IImageSource;
|
|
||||||
|
|
||||||
typedef ImageListSource = {
|
|
||||||
var source:IImageSource;
|
|
||||||
@:optional var type:Dynamic;
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ views:
|
|||||||
style: dark
|
style: dark
|
||||||
factory:
|
factory:
|
||||||
_start_: {$class: ru.m.puzzlez.view.StartFrame}
|
_start_: {$class: ru.m.puzzlez.view.StartFrame}
|
||||||
_game_list_: {$class: ru.m.puzzlez.view.GameListFrame}
|
|
||||||
_image_list_: {$class: ru.m.puzzlez.view.ImageListFrame}
|
_image_list_: {$class: ru.m.puzzlez.view.ImageListFrame}
|
||||||
_preset_: {$class: ru.m.puzzlez.view.PresetFrame}
|
_preset_: {$class: ru.m.puzzlez.view.PresetFrame}
|
||||||
_game_: {$class: ru.m.puzzlez.view.GameFrame}
|
_game_: {$class: ru.m.puzzlez.view.GameFrame}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import haxework.view.data.DataView;
|
|||||||
import haxework.view.form.ButtonView;
|
import haxework.view.form.ButtonView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.frame.FrameView;
|
||||||
import haxework.view.popup.ConfirmView;
|
|
||||||
import ru.m.data.IDataSource;
|
import ru.m.data.IDataSource;
|
||||||
import ru.m.pixabay.PixabayApi;
|
import ru.m.pixabay.PixabayApi;
|
||||||
import ru.m.puzzlez.core.GameState.GameStatus;
|
import ru.m.puzzlez.core.GameState.GameStatus;
|
||||||
|
import ru.m.puzzlez.core.ImageListSource;
|
||||||
import ru.m.puzzlez.source.AssetSource;
|
import ru.m.puzzlez.source.AssetSource;
|
||||||
import ru.m.puzzlez.source.FileSource;
|
import ru.m.puzzlez.source.FileSource;
|
||||||
import ru.m.puzzlez.source.PixabaySource;
|
import ru.m.puzzlez.source.PixabaySource;
|
||||||
@@ -31,10 +31,11 @@ import ru.m.update.Updater;
|
|||||||
public function new() {
|
public function new() {
|
||||||
super(ID);
|
super(ID);
|
||||||
var data:Array<ImageListSource> = [];
|
var data:Array<ImageListSource> = [];
|
||||||
data.push({source: storage.sources.get(AssetSource.ID), type: "asset"});
|
data.push({title: "Assets", source: storage.sources.get(AssetSource.ID)});
|
||||||
data.push({source: storage.sources.get(FileSource.ID), type: "file"});
|
data.push({title: "Files", source: storage.sources.get(FileSource.ID)});
|
||||||
|
var pixabay:PixabaySource = cast storage.sources.get(PixabaySource.ID);
|
||||||
for (type in AbstractEnumTools.getValues(PixabayCategory)) {
|
for (type in AbstractEnumTools.getValues(PixabayCategory)) {
|
||||||
data.push({source: storage.sources.get(PixabaySource.ID), type: type});
|
data.push(pixabay.categorySource(type));
|
||||||
}
|
}
|
||||||
sources.data = data;
|
sources.data = data;
|
||||||
}
|
}
|
||||||
@@ -66,7 +67,7 @@ import ru.m.update.Updater;
|
|||||||
|
|
||||||
private function sourceViewFactory(index:Int, source:ImageListSource):ButtonView {
|
private function sourceViewFactory(index:Int, source:ImageListSource):ButtonView {
|
||||||
var result = new ButtonView();
|
var result = new ButtonView();
|
||||||
result.text = Std.string(source.type != null ? source.type : "custom");
|
result.text = source.title;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,13 +75,7 @@ import ru.m.update.Updater;
|
|||||||
switcher.change(ImageListFrame.ID, source);
|
switcher.change(ImageListFrame.ID, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clean():Void {
|
private function games(status:GameStatus):Void {
|
||||||
ConfirmView.confirm("Really clean all saved data?").then(result -> {
|
switcher.change(ImageListFrame.ID, gameStorage.statusSource(status));
|
||||||
if (result) {
|
|
||||||
//gameStorage.clear();
|
|
||||||
var fileSource:FileSource = cast storage.sources.get(FileSource.ID);
|
|
||||||
fileSource.clean();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,13 @@ views:
|
|||||||
- id: load
|
- id: load
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
text: Load
|
text: Load
|
||||||
+onPress: ~switcher.change('game_list', 'started')
|
+onPress: ~games('started')
|
||||||
- id: complete
|
- id: complete
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
text: Complete
|
text: Complete
|
||||||
+onPress: ~switcher.change('game_list', 'complete')
|
+onPress: ~games('complete')
|
||||||
- $type: haxework.view.SpriteView
|
- $type: haxework.view.SpriteView
|
||||||
geometry.width: 100%
|
geometry.width: 100%
|
||||||
- $type: haxework.view.form.ButtonView
|
|
||||||
style: button.red
|
|
||||||
text: Clean
|
|
||||||
+onPress: ~clean()
|
|
||||||
visible: false
|
|
||||||
- id: update
|
- id: update
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
style: button.active
|
style: button.active
|
||||||
|
|||||||
Reference in New Issue
Block a user