diff --git a/src/app/haxe/ru/m/puzzlez/PuzzlezApp.hx b/src/app/haxe/ru/m/puzzlez/PuzzlezApp.hx index d4f22b7..8003694 100644 --- a/src/app/haxe/ru/m/puzzlez/PuzzlezApp.hx +++ b/src/app/haxe/ru/m/puzzlez/PuzzlezApp.hx @@ -1,14 +1,14 @@ package ru.m.puzzlez; -import ru.m.puzzlez.image.PixabayImageSource; -import ru.m.puzzlez.render.part.IPartBuilder; -import ru.m.puzzlez.image.AssetImageSource; -import ru.m.puzzlez.image.ImageSourceBundle; -import ru.m.puzzlez.settings.Settings; -import ru.m.puzzlez.view.PuzzlezAppView; import hw.app.App; import hw.app.Const; import hw.log.TraceLogger; +import ru.m.puzzlez.image.ImageSourceBundle; +import ru.m.puzzlez.render.part.IPartBuilder; +import ru.m.puzzlez.settings.Settings; +import ru.m.puzzlez.source.AssetImageSource; +import ru.m.puzzlez.source.PixabayImageSource; +import ru.m.puzzlez.view.PuzzlezAppView; import ru.m.update.Updater; class PuzzlezApp { diff --git a/src/app/haxe/ru/m/puzzlez/image/AssetImageSource.hx b/src/app/haxe/ru/m/puzzlez/image/AssetImageSource.hx deleted file mode 100644 index 4b2b14f..0000000 --- a/src/app/haxe/ru/m/puzzlez/image/AssetImageSource.hx +++ /dev/null @@ -1,26 +0,0 @@ -package ru.m.puzzlez.image; - -import openfl.utils.Assets; -import promhx.Promise; -import ru.m.data.DataSource; -import ru.m.puzzlez.image.ImageSource; -import ru.m.puzzlez.proto.game.ImageId; - -class AssetImageSource implements ImageSource { - public var id(default, never):String = "asset"; - - public function new() { - } - - public function getPage(page:Page):Promise> { - return Promise.promise({ - page: page, - data: [], - total: 0, - }); - } - - public function load(id:String):Promise { - return Promise.promise(ImageValue.BITMAP(Assets.getBitmapData(id))); - } -} diff --git a/src/app/haxe/ru/m/puzzlez/source/AssetImageSource.hx b/src/app/haxe/ru/m/puzzlez/source/AssetImageSource.hx new file mode 100644 index 0000000..b90e871 --- /dev/null +++ b/src/app/haxe/ru/m/puzzlez/source/AssetImageSource.hx @@ -0,0 +1,41 @@ +package ru.m.puzzlez.source; + +import openfl.utils.AssetType; +import openfl.utils.Assets; +import promhx.Promise; +import ru.m.data.DataSource; +import ru.m.puzzlez.image.ImageSource; +import ru.m.puzzlez.proto.game.ImageId; + +class AssetImageSource implements ImageSource { + public var id(default, never):String = "asset"; + + private var _data:Array; + private var data(get, null):Array; + + private function get_data():Array { + if (_data == null) { + _data = resolveData(); + } + return _data; + } + + public function new() { + } + + private function resolveData():Array { + return [for (name in Assets.list(AssetType.IMAGE).filter((name:String) -> name.substr(0, 15) == "resources/image")) new ImageId().setSource(id).setId(name)]; + } + + public function getPage(page:Page):Promise> { + return Promise.promise({ + page: page, + data: data.slice(page.index * page.count, page.count), + total: data.length, + }); + } + + public function load(id:String):Promise { + return Promise.promise(ImageValue.BITMAP(Assets.getBitmapData(id))); + } +} diff --git a/src/app/haxe/ru/m/puzzlez/image/PixabayImageSource.hx b/src/app/haxe/ru/m/puzzlez/source/PixabayImageSource.hx similarity index 90% rename from src/app/haxe/ru/m/puzzlez/image/PixabayImageSource.hx rename to src/app/haxe/ru/m/puzzlez/source/PixabayImageSource.hx index 157cd85..d2f77c3 100644 --- a/src/app/haxe/ru/m/puzzlez/image/PixabayImageSource.hx +++ b/src/app/haxe/ru/m/puzzlez/source/PixabayImageSource.hx @@ -1,4 +1,4 @@ -package ru.m.puzzlez.image; +package ru.m.puzzlez.source; import promhx.Promise; import ru.m.data.DataSource; @@ -17,7 +17,7 @@ class PixabayImageSource implements ImageSource { } public function getPage(page:Page):Promise> { - return this.api.getPage(page.index + 1, page.count).then((response:PixabayResponse) -> { + return this.api.getPage(page.index + 1, page.count, page.params.get("category")).then((response:PixabayResponse) -> { var data:Array = []; for (hit in response.hits) { imageUrlsCache.set(hit.id, hit.largeImageURL); diff --git a/src/app/haxe/ru/m/puzzlez/view/ImageSourceFrame.hx b/src/app/haxe/ru/m/puzzlez/view/ImageSourceFrame.hx index 13d03d8..bf66a1a 100644 --- a/src/app/haxe/ru/m/puzzlez/view/ImageSourceFrame.hx +++ b/src/app/haxe/ru/m/puzzlez/view/ImageSourceFrame.hx @@ -3,7 +3,7 @@ package ru.m.puzzlez.view; import hw.view.form.LabelView; import hw.view.frame.FrameSwitcher; import hw.view.frame.FrameView; -import ru.m.puzzlez.image.GameUtil; +import ru.m.data.DataSource.PageParams; import ru.m.puzzlez.image.ImageSourceBundle; import ru.m.puzzlez.proto.game.ImageId; import ru.m.puzzlez.view.common.ImageDataList; @@ -11,6 +11,7 @@ import ru.m.puzzlez.view.common.ImageDataList; typedef ImageSourceConfig = { var title:String; var sourceId:String; + @:optional var params:PageParams; } @:template class ImageSourceFrame extends FrameView { @@ -29,15 +30,16 @@ typedef ImageSourceConfig = { images.reset(); if (data != null) { header.text = data.title; - // images.page.filter = data.filter; + images.page.params = data.params; images.source = sourceBundle.get(data.sourceId); images.refresh(); } } private function start(imageId:ImageId):Void { - var state = GameUtil.buildState(GameUtil.buildPreset(imageId, 2, 2)); - switcher.change(GameFrame.ID, state); + //var state = GameUtil.buildState(GameUtil.buildPreset(imageId, 2, 2)); + //switcher.change(GameFrame.ID, state); + switcher.change(PresetFrame.ID, imageId); } private function back():Void { diff --git a/src/app/haxe/ru/m/puzzlez/view/PresetFrame.hx b/src/app/haxe/ru/m/puzzlez/view/PresetFrame.hx index ac93618..370aeaa 100644 --- a/src/app/haxe/ru/m/puzzlez/view/PresetFrame.hx +++ b/src/app/haxe/ru/m/puzzlez/view/PresetFrame.hx @@ -6,9 +6,7 @@ import hw.view.form.ToggleButtonView; import hw.view.frame.FrameSwitcher; import hw.view.frame.FrameView; import ru.m.puzzlez.image.GameUtil; -import ru.m.puzzlez.net.Network; import ru.m.puzzlez.proto.game.ImageId; -import ru.m.puzzlez.settings.ImageStorage; import ru.m.puzzlez.view.common.PresetView; @:template class PresetFrame extends FrameView { @@ -17,9 +15,8 @@ import ru.m.puzzlez.view.common.PresetView; @:view("image") var imageView:PresetView; @:view("sizes") var sizesView:DataView; - @:provide var imageStorage:ImageStorage; @:provide var switcher:FrameSwitcher; - @:provide var network:Network; + //@:provide var network:Network; private var imageId:ImageId; @@ -57,13 +54,13 @@ import ru.m.puzzlez.view.common.PresetView; private function start(online:Bool = false):Void { if (online) { - network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state)); + //network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state)); } else { switcher.change(GameFrame.ID, imageView.state); } } private function back():Void { - switcher.change(ImageListFrame.ID); + switcher.change(ImageSourceFrame.ID); } } diff --git a/src/app/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml b/src/app/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml index e08c951..703df28 100644 --- a/src/app/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml +++ b/src/app/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml @@ -7,7 +7,7 @@ views: factory: _start_: {$class: ru.m.puzzlez.view.StartFrame} _source_: {$class: ru.m.puzzlez.view.ImageSourceFrame} - #_preset_: {$class: ru.m.puzzlez.view.PresetFrame} + _preset_: {$class: ru.m.puzzlez.view.PresetFrame} _game_: {$class: ru.m.puzzlez.view.GameFrame} - $type: hw.view.group.HGroupView geometry.position: absolute diff --git a/src/app/haxe/ru/m/puzzlez/view/StartFrame.hx b/src/app/haxe/ru/m/puzzlez/view/StartFrame.hx index 61acab2..557d0e1 100644 --- a/src/app/haxe/ru/m/puzzlez/view/StartFrame.hx +++ b/src/app/haxe/ru/m/puzzlez/view/StartFrame.hx @@ -1,14 +1,17 @@ package ru.m.puzzlez.view; +import hw.view.data.DataView; import hw.view.form.ButtonView; import hw.view.frame.FrameSwitcher; import hw.view.frame.FrameView; +import ru.m.pixabay.PixabayApi; import ru.m.puzzlez.view.ImageSourceFrame; import ru.m.update.Updater; @:template class StartFrame extends FrameView { public static var ID = "start"; + @:view var sources:DataView; @:view var updateButton:ButtonView; @:provide var switcher:FrameSwitcher; @@ -16,9 +19,22 @@ import ru.m.update.Updater; public function new() { super(ID); + var data:Array = []; + data.push({title: "Assets", sourceId: "asset"}); + // data.push({title: "Files", sourceId: "file"}); + for (type in AbstractEnumTools.getValues(PixabayCategory)) { + data.push({title: type, sourceId: "pixabay", params: ["category" => type]}); + } + sources.data = data; } - public function openSource(source:ImageSourceConfig):Void { + private function sourceViewFactory(index:Int, source:ImageSourceConfig):ButtonView { + var result = new ButtonView(); + result.text = source.title; + return result; + } + + public function showSource(source:ImageSourceConfig):Void { switcher.change(ImageSourceFrame.ID, source); } diff --git a/src/app/haxe/ru/m/puzzlez/view/StartFrame.yaml b/src/app/haxe/ru/m/puzzlez/view/StartFrame.yaml index 2e01cef..40301f3 100644 --- a/src/app/haxe/ru/m/puzzlez/view/StartFrame.yaml +++ b/src/app/haxe/ru/m/puzzlez/view/StartFrame.yaml @@ -15,10 +15,18 @@ views: - $type: hw.view.form.LabelView text: $r:text:app.name font.size: 50 - - $type: hw.view.form.ButtonView - text: Pixabay - geometry.hAlign: center - +onPress: "~openSource({title: 'Pixabay', sourceId: 'pixabay'})" + - id: sources + $type: hw.view.data.DataView + layout: + $type: hw.view.layout.TailLayout + rowSize: 5 + margin: 10 + vAlign: middle + geometry.stretch: true + factory: ~sourceViewFactory + +onDataSelect: ~showSource + geometry.margin: 5 + overflow.y: scroll - $type: hw.view.form.LabelView text: $r:text:app.version geometry.position: absolute