82 lines
2.9 KiB
Haxe
82 lines
2.9 KiB
Haxe
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.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;
|
|
import ru.m.puzzlez.storage.GameStorage;
|
|
import ru.m.puzzlez.storage.ImageStorage;
|
|
import ru.m.update.Updater;
|
|
|
|
@:template class StartFrame extends FrameView<Dynamic> {
|
|
public static var ID = "start";
|
|
|
|
@:view var sources:DataView<ImageListSource, ButtonView>;
|
|
@:view("load") var loadButton:ButtonView;
|
|
@:view("complete") var completeButton:ButtonView;
|
|
@:view("update") var updateButton:ButtonView;
|
|
|
|
@:provide var storage:ImageStorage;
|
|
@:provide var switcher:FrameSwitcher;
|
|
@:provide var gameStorage:GameStorage;
|
|
@:provide static var appUpdater:Updater;
|
|
|
|
public function new() {
|
|
super(ID);
|
|
var data:Array<ImageListSource> = [];
|
|
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(pixabay.categorySource(type));
|
|
}
|
|
sources.data = data;
|
|
}
|
|
|
|
private function refresh():Void {
|
|
var startedRequest:Page = {index: 0, count: 0, filter: ["status" => STARTED]};
|
|
gameStorage.getIndexPage(startedRequest).then(page -> {
|
|
var total = page.total;
|
|
loadButton.text = 'Resume (${total})';
|
|
loadButton.disabled = total == 0;
|
|
});
|
|
var completeRequest:Page = {index: 0, count: 0, filter: ["status" => COMPLETE]};
|
|
gameStorage.getIndexPage(completeRequest).then(page -> {
|
|
var total = page.total;
|
|
completeButton.text = 'Complete (${total})';
|
|
completeButton.disabled = total == 0;
|
|
});
|
|
}
|
|
|
|
override public function onShow(data:Dynamic):Void {
|
|
refresh();
|
|
appUpdater.check().then((info:Null<PackageInfo>) -> {
|
|
if (info != null) {
|
|
updateButton.visible = true;
|
|
updateButton.text = 'Update ${info.version}';
|
|
}
|
|
});
|
|
}
|
|
|
|
private function sourceViewFactory(index:Int, source:ImageListSource):ButtonView {
|
|
var result = new ButtonView();
|
|
result.text = source.title;
|
|
return result;
|
|
}
|
|
|
|
private function load(source:ImageListSource):Void {
|
|
switcher.change(ImageListFrame.ID, source);
|
|
}
|
|
|
|
private function games(status:GameStatus):Void {
|
|
switcher.change(ImageListFrame.ID, gameStorage.statusSource(status));
|
|
}
|
|
}
|