Task interface
This commit is contained in:
+35
-20
@@ -8,6 +8,7 @@
|
||||
#include <filesystem>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "../../interfaces/Task.h"
|
||||
#include "../../graphics/ui/GUI.h"
|
||||
#include "../../graphics/ui/gui_util.h"
|
||||
#include "../../graphics/ui/elements/containers.h"
|
||||
@@ -104,35 +105,27 @@ static void show_content_missing(
|
||||
menu->setPage("missing-content");
|
||||
}
|
||||
|
||||
void show_process_panel(Engine* engine, std::shared_ptr<WorldConverter> converter, runnable postRunnable) {
|
||||
void show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text=L"") {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = menus::create_page(engine, "process", 400, 0.5f, 1);
|
||||
|
||||
panel->add(std::make_shared<Label>(langs::get(L"Converting world...")));
|
||||
if (!text.empty()) {
|
||||
panel->add(std::make_shared<Label>(langs::get(text)));
|
||||
}
|
||||
|
||||
auto label = std::make_shared<Label>(L"0%");
|
||||
panel->add(label);
|
||||
|
||||
uint initialTasks = converter->getTotalTasks();
|
||||
uint initialWork = task->getWorkRemaining();
|
||||
|
||||
panel->listenInterval(0.01f, [=]() {
|
||||
if (!converter->hasNext()) {
|
||||
converter->write();
|
||||
task->update();
|
||||
|
||||
menu->reset();
|
||||
menu->setPage("main", false);
|
||||
engine->getGUI()->postRunnable([=]() {
|
||||
postRunnable();
|
||||
});
|
||||
return;
|
||||
}
|
||||
converter->convertNext();
|
||||
|
||||
uint tasksDone = initialTasks-converter->getTotalTasks();
|
||||
float progress = tasksDone/static_cast<float>(initialTasks);
|
||||
uint tasksDone = task->getWorkDone();
|
||||
float progress = tasksDone/static_cast<float>(initialWork);
|
||||
label->setText(
|
||||
std::to_wstring(tasksDone)+
|
||||
L"/"+std::to_wstring(initialTasks)+L" ("+
|
||||
L"/"+std::to_wstring(initialWork)+L" ("+
|
||||
std::to_wstring(int(progress*100))+L"%)"
|
||||
);
|
||||
});
|
||||
@@ -141,6 +134,27 @@ void show_process_panel(Engine* engine, std::shared_ptr<WorldConverter> converte
|
||||
menu->setPage("process", false);
|
||||
}
|
||||
|
||||
std::shared_ptr<WorldConverter> create_converter(
|
||||
Engine* engine,
|
||||
fs::path folder,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut,
|
||||
runnable postRunnable)
|
||||
{
|
||||
auto converter = std::make_shared<WorldConverter>(folder, content, lut);
|
||||
converter->setOnComplete([=](){
|
||||
converter->write();
|
||||
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->reset();
|
||||
menu->setPage("main", false);
|
||||
engine->getGUI()->postRunnable([=]() {
|
||||
postRunnable();
|
||||
});
|
||||
});
|
||||
return converter;
|
||||
}
|
||||
|
||||
void show_convert_request(
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
@@ -149,7 +163,8 @@ void show_convert_request(
|
||||
runnable postRunnable
|
||||
) {
|
||||
guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"), [=]() {
|
||||
show_process_panel(engine, std::make_shared<WorldConverter>(folder, content, lut), postRunnable);
|
||||
auto converter = create_converter(engine, folder, content, lut, postRunnable);
|
||||
show_process_panel(engine, converter, L"Converting world...");
|
||||
}, L"", langs::get(L"Cancel"));
|
||||
}
|
||||
|
||||
@@ -210,9 +225,9 @@ void menus::open_world(std::string name, Engine* engine, bool confirmConvert) {
|
||||
show_content_missing(engine, content, lut);
|
||||
} else {
|
||||
if (confirmConvert) {
|
||||
show_process_panel(engine, std::make_shared<WorldConverter>(folder, content, lut), [=](){
|
||||
show_process_panel(engine, create_converter(engine, folder, content, lut, [=]() {
|
||||
open_world(name, engine, false);
|
||||
});
|
||||
}), L"Converting world...");
|
||||
} else {
|
||||
show_convert_request(engine, content, lut, folder, [=](){
|
||||
open_world(name, engine, false);
|
||||
|
||||
Reference in New Issue
Block a user