diff --git a/src/haxe/ru/m/puzzlez/core/ImageListSource.hx b/src/haxe/ru/m/puzzlez/core/ImageListSource.hx new file mode 100644 index 0000000..22383a7 --- /dev/null +++ b/src/haxe/ru/m/puzzlez/core/ImageListSource.hx @@ -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; + @:optional var filter:Filter; +} diff --git a/src/haxe/ru/m/puzzlez/source/PixabaySource.hx b/src/haxe/ru/m/puzzlez/source/PixabaySource.hx index 7ffa94d..040c098 100644 --- a/src/haxe/ru/m/puzzlez/source/PixabaySource.hx +++ b/src/haxe/ru/m/puzzlez/source/PixabaySource.hx @@ -8,6 +8,7 @@ import promhx.Promise; import ru.m.data.IDataSource; import ru.m.pixabay.PixabayApi; import ru.m.puzzlez.core.Id; +import ru.m.puzzlez.core.ImageListSource; import ru.m.puzzlez.storage.CacheStorage; 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], + } + } } diff --git a/src/haxe/ru/m/puzzlez/storage/GameStorage.hx b/src/haxe/ru/m/puzzlez/storage/GameStorage.hx index 1cc7a90..a6cae1f 100644 --- a/src/haxe/ru/m/puzzlez/storage/GameStorage.hx +++ b/src/haxe/ru/m/puzzlez/storage/GameStorage.hx @@ -1,8 +1,9 @@ package ru.m.puzzlez.storage; +import ru.m.data.DataStorage; import ru.m.puzzlez.core.GameState; import ru.m.puzzlez.core.Id; -import ru.m.data.DataStorage; +import ru.m.puzzlez.core.ImageListSource; @:provide class GameStorage extends DataStorage { inline private static var NAME = "game"; @@ -15,4 +16,12 @@ import ru.m.data.DataStorage; new Converter(id -> id.toString(), data -> ImageId.fromString(data)) ); } + + public function statusSource(status:GameStatus):ImageListSource { + return { + title: status, + source: this, + filter: ["status" => status], + } + } } diff --git a/src/haxe/ru/m/puzzlez/view/GameFrame.hx b/src/haxe/ru/m/puzzlez/view/GameFrame.hx index f18ac5f..ba4983f 100644 --- a/src/haxe/ru/m/puzzlez/view/GameFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/GameFrame.hx @@ -92,7 +92,7 @@ import ru.m.puzzlez.view.popup.PreviewPopup; (game.state.status == COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?")) .then(result -> { if (result) { - switcher.change(GameListFrame.ID, game.state.status); + switcher.change(ImageListFrame.ID, storage.statusSource(game.state.status)); } }); } diff --git a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx b/src/haxe/ru/m/puzzlez/view/GameListFrame.hx deleted file mode 100644 index da89816..0000000 --- a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx +++ /dev/null @@ -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 { - - 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); - } -} diff --git a/src/haxe/ru/m/puzzlez/view/GameListFrame.yaml b/src/haxe/ru/m/puzzlez/view/GameListFrame.yaml deleted file mode 100644 index 48390ae..0000000 --- a/src/haxe/ru/m/puzzlez/view/GameListFrame.yaml +++ /dev/null @@ -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() diff --git a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx index 939646e..2de2473 100644 --- a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx @@ -3,8 +3,10 @@ package ru.m.puzzlez.view; import haxework.view.form.ButtonView; import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameView; +import ru.m.puzzlez.core.ImageListSource; import ru.m.puzzlez.FileUtil; import ru.m.puzzlez.source.FileSource; +import ru.m.puzzlez.storage.GameStorage; import ru.m.puzzlez.storage.ImageStorage; import ru.m.puzzlez.view.common.ImageDataList; @@ -14,6 +16,7 @@ import ru.m.puzzlez.view.common.ImageDataList; @:view("images") var imagesView:ImageDataList; @:view var select:ButtonView; + @:provide var gameStorage:GameStorage; @:provide var imageStorage:ImageStorage; @:provide var switcher:FrameSwitcher; @@ -24,8 +27,9 @@ import ru.m.puzzlez.view.common.ImageDataList; override public function onShow(data:ImageListSource):Void { imagesView.reset(); if (data != null) { - select.visible = data.source.id == FileSource.ID; - imagesView.page.filter = ["type" => data.type]; + // ToDo: + //select.visible = data.source.id == FileSource.ID; + imagesView.page.filter = data.filter; imagesView.source = data.source; imagesView.refresh(); } diff --git a/src/haxe/ru/m/puzzlez/view/ImageListSource.hx b/src/haxe/ru/m/puzzlez/view/ImageListSource.hx deleted file mode 100644 index 59f8042..0000000 --- a/src/haxe/ru/m/puzzlez/view/ImageListSource.hx +++ /dev/null @@ -1,8 +0,0 @@ -package ru.m.puzzlez.view; - -import ru.m.puzzlez.source.IImageSource; - -typedef ImageListSource = { - var source:IImageSource; - @:optional var type:Dynamic; -} diff --git a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml index a05d4b9..1a53b8c 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml +++ b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml @@ -6,7 +6,6 @@ views: style: dark factory: _start_: {$class: ru.m.puzzlez.view.StartFrame} - _game_list_: {$class: ru.m.puzzlez.view.GameListFrame} _image_list_: {$class: ru.m.puzzlez.view.ImageListFrame} _preset_: {$class: ru.m.puzzlez.view.PresetFrame} _game_: {$class: ru.m.puzzlez.view.GameFrame} diff --git a/src/haxe/ru/m/puzzlez/view/StartFrame.hx b/src/haxe/ru/m/puzzlez/view/StartFrame.hx index d0675ff..fc952a9 100644 --- a/src/haxe/ru/m/puzzlez/view/StartFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/StartFrame.hx @@ -4,10 +4,10 @@ import haxework.view.data.DataView; import haxework.view.form.ButtonView; import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameView; -import haxework.view.popup.ConfirmView; import ru.m.data.IDataSource; import ru.m.pixabay.PixabayApi; import ru.m.puzzlez.core.GameState.GameStatus; +import ru.m.puzzlez.core.ImageListSource; import ru.m.puzzlez.source.AssetSource; import ru.m.puzzlez.source.FileSource; import ru.m.puzzlez.source.PixabaySource; @@ -31,10 +31,11 @@ import ru.m.update.Updater; public function new() { super(ID); var data:Array = []; - data.push({source: storage.sources.get(AssetSource.ID), type: "asset"}); - data.push({source: storage.sources.get(FileSource.ID), type: "file"}); + data.push({title: "Assets", source: storage.sources.get(AssetSource.ID)}); + 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)) { - data.push({source: storage.sources.get(PixabaySource.ID), type: type}); + data.push(pixabay.categorySource(type)); } sources.data = data; } @@ -66,7 +67,7 @@ import ru.m.update.Updater; private function sourceViewFactory(index:Int, source:ImageListSource):ButtonView { var result = new ButtonView(); - result.text = Std.string(source.type != null ? source.type : "custom"); + result.text = source.title; return result; } @@ -74,13 +75,7 @@ import ru.m.update.Updater; switcher.change(ImageListFrame.ID, source); } - private function clean():Void { - ConfirmView.confirm("Really clean all saved data?").then(result -> { - if (result) { - //gameStorage.clear(); - var fileSource:FileSource = cast storage.sources.get(FileSource.ID); - fileSource.clean(); - } - }); + private function games(status:GameStatus):Void { + switcher.change(ImageListFrame.ID, gameStorage.statusSource(status)); } } diff --git a/src/haxe/ru/m/puzzlez/view/StartFrame.yaml b/src/haxe/ru/m/puzzlez/view/StartFrame.yaml index c724ff4..c4c16ff 100644 --- a/src/haxe/ru/m/puzzlez/view/StartFrame.yaml +++ b/src/haxe/ru/m/puzzlez/view/StartFrame.yaml @@ -35,18 +35,13 @@ views: - id: load $type: haxework.view.form.ButtonView text: Load - +onPress: ~switcher.change('game_list', 'started') + +onPress: ~games('started') - id: complete $type: haxework.view.form.ButtonView text: Complete - +onPress: ~switcher.change('game_list', 'complete') + +onPress: ~games('complete') - $type: haxework.view.SpriteView geometry.width: 100% - - $type: haxework.view.form.ButtonView - style: button.red - text: Clean - +onPress: ~clean() - visible: false - id: update $type: haxework.view.form.ButtonView style: button.active