minor refactor

This commit is contained in:
MihailRis 2024-04-21 02:37:44 +03:00
parent 599665d349
commit d213902648
15 changed files with 60 additions and 66 deletions

View File

@ -5,7 +5,7 @@
#include <functional>
#include <glm/glm.hpp>
#include "../graphics/ui/elements/UINode.h"
#include "../graphics/ui/elements/UINode.hpp"
#include "../graphics/ui/elements/layout/Container.hpp"
#include "../items/ItemStack.h"
#include "../typedefs.h"

View File

@ -1,7 +1,7 @@
#include "UiDocument.h"
#include "../files/files.h"
#include "../graphics/ui/elements/UINode.h"
#include "../graphics/ui/elements/UINode.hpp"
#include "../graphics/ui/gui_xml.h"
#include "../logic/scripting/scripting.h"
#include "InventoryView.h"

View File

@ -15,7 +15,7 @@
#include "../graphics/core/Texture.h"
#include "../graphics/render/BlocksPreview.h"
#include "../graphics/render/WorldRenderer.h"
#include "../graphics/ui/elements/UINode.h"
#include "../graphics/ui/elements/UINode.hpp"
#include "../graphics/ui/elements/layout/Menu.hpp"
#include "../graphics/ui/elements/layout/Panel.hpp"
#include "../graphics/ui/elements/display/Plotter.hpp"

View File

@ -1,14 +1,14 @@
#include "menu.hpp"
#include <string>
#include <memory>
#include <filesystem>
#include <glm/glm.hpp>
#include "../delegates.h"
#include "../engine.h"
#include "../interfaces/Task.h"
#include "../files/engine_paths.h"
#include "../graphics/ui/elements/display/Label.hpp"
#include "../graphics/ui/elements/layout/Panel.hpp"
#include "../graphics/ui/elements/layout/Menu.hpp"
#include "../graphics/ui/gui_util.h"
#include "../graphics/ui/GUI.h"
@ -16,6 +16,7 @@
#include "../settings.h"
#include "../util/stringutil.h"
#include "../window/Window.h"
#include "locale/langs.h"
#include "UiDocument.h"
namespace fs = std::filesystem;
@ -46,3 +47,34 @@ void menus::create_menus(Engine* engine) {
return document->getRoot();
});
}
void menus::show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text) {
auto menu = engine->getGUI()->getMenu();
auto panel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
"<panel size='400' padding='8' interval='1' color='#00000080/>"
));
if (!text.empty()) {
panel->add(std::make_shared<gui::Label>(langs::get(text)));
}
auto label = std::make_shared<gui::Label>(L"0%");
panel->add(label);
uint initialWork = task->getWorkTotal();
panel->listenInterval(0.01f, [=]() {
task->update();
uint tasksDone = task->getWorkDone();
float progress = tasksDone/static_cast<float>(initialWork);
label->setText(
std::to_wstring(tasksDone)+
L"/"+std::to_wstring(initialWork)+L" ("+
std::to_wstring(static_cast<int>(progress*100))+L"%)"
);
});
menu->reset();
menu->addPage("process", panel);
menu->setPage("process", false);
}

View File

@ -1,12 +1,17 @@
#ifndef FRONTEND_MENU_MENU_HPP_
#define FRONTEND_MENU_MENU_HPP_
#include <string>
#include <memory>
class Task;
class Engine;
namespace menus {
/// @brief Create development version label at the top-right screen corner
void create_version_label(Engine* engine);
void create_menus(Engine* engine);
void show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text=L"");
}
#endif // FRONTEND_MENU_MENU_HPP_

View File

@ -1,5 +1,5 @@
#include "GUI.h"
#include "elements/UINode.h"
#include "elements/UINode.hpp"
#include "elements/layout/Menu.hpp"
#include <iostream>

View File

@ -1,4 +1,4 @@
#include "UINode.h"
#include "UINode.hpp"
#include "layout/Container.hpp"
#include "../../core/Batch2D.h"

View File

@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
#define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
#include "../UINode.h"
#include "../UINode.hpp"
namespace gui {
class TrackBar : public UINode {

View File

@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_IMAGE_HPP_
#define GRAPHICS_UI_ELEMENTS_IMAGE_HPP_
#include "../UINode.h"
#include "../UINode.hpp"
namespace gui {
class Image : public UINode {

View File

@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_LABEL_HPP_
#define GRAPHICS_UI_ELEMENTS_LABEL_HPP_
#include "../UINode.h"
#include "../UINode.hpp"
namespace gui {
class Label : public UINode {

View File

@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_
#define GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_
#include "../UINode.h"
#include "../UINode.hpp"
#include "../../../../typedefs.h"
#include <memory>

View File

@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_
#define GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_
#include "../UINode.h"
#include "../UINode.hpp"
#include "../commons.hpp"
#include <vector>

View File

@ -7,6 +7,7 @@
#include "../files/WorldConverter.h"
#include "../frontend/locale/langs.h"
#include "../frontend/screens.h"
#include "../frontend/menu.hpp"
#include "../graphics/ui/elements/display/Label.hpp"
#include "../graphics/ui/elements/control/Button.hpp"
#include "../graphics/ui/elements/layout/Panel.hpp"
@ -37,51 +38,6 @@ void EngineController::deleteWorld(std::string name) {
});
}
static std::shared_ptr<gui::Panel> create_page(
Engine* engine,
std::string name,
int width,
float opacity,
int interval
) {
auto menu = engine->getGUI()->getMenu();
auto panel = std::make_shared<gui::Panel>(
glm::vec2(width, 200), glm::vec4(8.0f), interval
);
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, opacity));
menu->addPage(name, panel);
return panel;
}
void show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text=L"") {
auto menu = engine->getGUI()->getMenu();
auto panel = create_page(engine, "process", 400, 0.5f, 1);
if (!text.empty()) {
panel->add(std::make_shared<gui::Label>(langs::get(text)));
}
auto label = std::make_shared<gui::Label>(L"0%");
panel->add(label);
uint initialWork = task->getWorkTotal();
panel->listenInterval(0.01f, [=]() {
task->update();
uint tasksDone = task->getWorkDone();
float progress = tasksDone/static_cast<float>(initialWork);
label->setText(
std::to_wstring(tasksDone)+
L"/"+std::to_wstring(initialWork)+L" ("+
std::to_wstring(int(progress*100))+L"%)"
);
});
menu->reset();
menu->setPage("process", false);
}
std::shared_ptr<Task> create_converter(
Engine* engine,
fs::path folder,
@ -108,7 +64,7 @@ void show_convert_request(
) {
guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"), [=]() {
auto converter = create_converter(engine, folder, content, lut, postRunnable);
show_process_panel(engine, converter, L"Converting world...");
menus::show_process_panel(engine, converter, L"Converting world...");
}, L"", langs::get(L"Cancel"));
}
@ -119,10 +75,11 @@ static void show_content_missing(
) {
auto* gui = engine->getGUI();
auto menu = gui->getMenu();
auto panel = create_page(engine, "missing-content", 500, 0.5f, 8);
panel->add(std::make_shared<gui::Label>(langs::get(L"menu.missing-content")));
auto panel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
"<panel size='500' color='#00000080' padding='8'>"
"<label>@menu.missing-content</label>"
"</panel>"
));
auto subpanel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
"<panel size='480,100' color='#00000080' scrollable='true' max-length='400'>"
"</panel>"
@ -131,13 +88,12 @@ static void show_content_missing(
for (auto& entry : lut->getMissingContent()) {
std::string contentname = contenttype_name(entry.type);
auto hpanel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
subpanel->add(guiutil::create(
"<panel size='500,20' color='0' orientation='horizontal' padding='2'>"
"<label color='#80808080'>["+contentname+"]</label>"
"<label color='#FF333380'>"+entry.name+"</label>"
"</panel>"
));
subpanel->add(hpanel);
}
panel->add(std::make_shared<gui::Button>(
@ -145,6 +101,7 @@ static void show_content_missing(
menu->back();
}
));
menu->addPage("missing-content", panel);
menu->setPage("missing-content");
}
@ -181,7 +138,7 @@ void EngineController::openWorld(std::string name, bool confirmConvert) {
show_content_missing(engine, content, lut);
} else {
if (confirmConvert) {
show_process_panel(engine, create_converter(engine, folder, content, lut, [=]() {
menus::show_process_panel(engine, create_converter(engine, folder, content, lut, [=]() {
openWorld(name, false);
}), L"Converting world...");
} else {

View File

@ -9,7 +9,7 @@
#include "../../../engine.h"
#include "../../../assets/Assets.h"
#include "../../../graphics/ui/gui_util.h"
#include "../../../graphics/ui/elements/UINode.h"
#include "../../../graphics/ui/elements/UINode.hpp"
#include "../../../graphics/ui/elements/control/Button.hpp"
#include "../../../graphics/ui/elements/control/CheckBox.hpp"
#include "../../../graphics/ui/elements/control/TextBox.hpp"