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
+1 -1
View File
@@ -5,7 +5,7 @@
#include <functional> #include <functional>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "../graphics/ui/elements/UINode.h" #include "../graphics/ui/elements/UINode.hpp"
#include "../graphics/ui/elements/layout/Container.hpp" #include "../graphics/ui/elements/layout/Container.hpp"
#include "../items/ItemStack.h" #include "../items/ItemStack.h"
#include "../typedefs.h" #include "../typedefs.h"
+1 -1
View File
@@ -1,7 +1,7 @@
#include "UiDocument.h" #include "UiDocument.h"
#include "../files/files.h" #include "../files/files.h"
#include "../graphics/ui/elements/UINode.h" #include "../graphics/ui/elements/UINode.hpp"
#include "../graphics/ui/gui_xml.h" #include "../graphics/ui/gui_xml.h"
#include "../logic/scripting/scripting.h" #include "../logic/scripting/scripting.h"
#include "InventoryView.h" #include "InventoryView.h"
+1 -1
View File
@@ -15,7 +15,7 @@
#include "../graphics/core/Texture.h" #include "../graphics/core/Texture.h"
#include "../graphics/render/BlocksPreview.h" #include "../graphics/render/BlocksPreview.h"
#include "../graphics/render/WorldRenderer.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/Menu.hpp"
#include "../graphics/ui/elements/layout/Panel.hpp" #include "../graphics/ui/elements/layout/Panel.hpp"
#include "../graphics/ui/elements/display/Plotter.hpp" #include "../graphics/ui/elements/display/Plotter.hpp"
+34 -2
View File
@@ -1,14 +1,14 @@
#include "menu.hpp" #include "menu.hpp"
#include <string>
#include <memory>
#include <filesystem> #include <filesystem>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "../delegates.h" #include "../delegates.h"
#include "../engine.h" #include "../engine.h"
#include "../interfaces/Task.h"
#include "../files/engine_paths.h" #include "../files/engine_paths.h"
#include "../graphics/ui/elements/display/Label.hpp" #include "../graphics/ui/elements/display/Label.hpp"
#include "../graphics/ui/elements/layout/Panel.hpp"
#include "../graphics/ui/elements/layout/Menu.hpp" #include "../graphics/ui/elements/layout/Menu.hpp"
#include "../graphics/ui/gui_util.h" #include "../graphics/ui/gui_util.h"
#include "../graphics/ui/GUI.h" #include "../graphics/ui/GUI.h"
@@ -16,6 +16,7 @@
#include "../settings.h" #include "../settings.h"
#include "../util/stringutil.h" #include "../util/stringutil.h"
#include "../window/Window.h" #include "../window/Window.h"
#include "locale/langs.h"
#include "UiDocument.h" #include "UiDocument.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -46,3 +47,34 @@ void menus::create_menus(Engine* engine) {
return document->getRoot(); 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);
}
+5
View File
@@ -1,12 +1,17 @@
#ifndef FRONTEND_MENU_MENU_HPP_ #ifndef FRONTEND_MENU_MENU_HPP_
#define FRONTEND_MENU_MENU_HPP_ #define FRONTEND_MENU_MENU_HPP_
#include <string>
#include <memory>
class Task;
class Engine; class Engine;
namespace menus { namespace menus {
/// @brief Create development version label at the top-right screen corner /// @brief Create development version label at the top-right screen corner
void create_version_label(Engine* engine); void create_version_label(Engine* engine);
void create_menus(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_ #endif // FRONTEND_MENU_MENU_HPP_
+1 -1
View File
@@ -1,5 +1,5 @@
#include "GUI.h" #include "GUI.h"
#include "elements/UINode.h" #include "elements/UINode.hpp"
#include "elements/layout/Menu.hpp" #include "elements/layout/Menu.hpp"
#include <iostream> #include <iostream>
+1 -1
View File
@@ -1,4 +1,4 @@
#include "UINode.h" #include "UINode.hpp"
#include "layout/Container.hpp" #include "layout/Container.hpp"
#include "../../core/Batch2D.h" #include "../../core/Batch2D.h"
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_ #ifndef GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
#define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_ #define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
#include "../UINode.h" #include "../UINode.hpp"
namespace gui { namespace gui {
class TrackBar : public UINode { class TrackBar : public UINode {
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_IMAGE_HPP_ #ifndef GRAPHICS_UI_ELEMENTS_IMAGE_HPP_
#define GRAPHICS_UI_ELEMENTS_IMAGE_HPP_ #define GRAPHICS_UI_ELEMENTS_IMAGE_HPP_
#include "../UINode.h" #include "../UINode.hpp"
namespace gui { namespace gui {
class Image : public UINode { class Image : public UINode {
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_LABEL_HPP_ #ifndef GRAPHICS_UI_ELEMENTS_LABEL_HPP_
#define GRAPHICS_UI_ELEMENTS_LABEL_HPP_ #define GRAPHICS_UI_ELEMENTS_LABEL_HPP_
#include "../UINode.h" #include "../UINode.hpp"
namespace gui { namespace gui {
class Label : public UINode { class Label : public UINode {
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_ #ifndef GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_
#define GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_ #define GRAPHICS_UI_ELEMENTS_PLOTTER_HPP_
#include "../UINode.h" #include "../UINode.hpp"
#include "../../../../typedefs.h" #include "../../../../typedefs.h"
#include <memory> #include <memory>
@@ -1,7 +1,7 @@
#ifndef GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_ #ifndef GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_
#define GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_ #define GRAPHICS_UI_ELEMENTS_CONTAINER_HPP_
#include "../UINode.h" #include "../UINode.hpp"
#include "../commons.hpp" #include "../commons.hpp"
#include <vector> #include <vector>
+10 -53
View File
@@ -7,6 +7,7 @@
#include "../files/WorldConverter.h" #include "../files/WorldConverter.h"
#include "../frontend/locale/langs.h" #include "../frontend/locale/langs.h"
#include "../frontend/screens.h" #include "../frontend/screens.h"
#include "../frontend/menu.hpp"
#include "../graphics/ui/elements/display/Label.hpp" #include "../graphics/ui/elements/display/Label.hpp"
#include "../graphics/ui/elements/control/Button.hpp" #include "../graphics/ui/elements/control/Button.hpp"
#include "../graphics/ui/elements/layout/Panel.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( std::shared_ptr<Task> create_converter(
Engine* engine, Engine* engine,
fs::path folder, fs::path folder,
@@ -108,7 +64,7 @@ void show_convert_request(
) { ) {
guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"), [=]() { guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"), [=]() {
auto converter = create_converter(engine, folder, content, lut, postRunnable); 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")); }, L"", langs::get(L"Cancel"));
} }
@@ -119,10 +75,11 @@ static void show_content_missing(
) { ) {
auto* gui = engine->getGUI(); auto* gui = engine->getGUI();
auto menu = gui->getMenu(); auto menu = gui->getMenu();
auto panel = create_page(engine, "missing-content", 500, 0.5f, 8); auto panel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
"<panel size='500' color='#00000080' padding='8'>"
panel->add(std::make_shared<gui::Label>(langs::get(L"menu.missing-content"))); "<label>@menu.missing-content</label>"
"</panel>"
));
auto subpanel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create( auto subpanel = std::dynamic_pointer_cast<gui::Panel>(guiutil::create(
"<panel size='480,100' color='#00000080' scrollable='true' max-length='400'>" "<panel size='480,100' color='#00000080' scrollable='true' max-length='400'>"
"</panel>" "</panel>"
@@ -131,13 +88,12 @@ static void show_content_missing(
for (auto& entry : lut->getMissingContent()) { for (auto& entry : lut->getMissingContent()) {
std::string contentname = contenttype_name(entry.type); 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'>" "<panel size='500,20' color='0' orientation='horizontal' padding='2'>"
"<label color='#80808080'>["+contentname+"]</label>" "<label color='#80808080'>["+contentname+"]</label>"
"<label color='#FF333380'>"+entry.name+"</label>" "<label color='#FF333380'>"+entry.name+"</label>"
"</panel>" "</panel>"
)); ));
subpanel->add(hpanel);
} }
panel->add(std::make_shared<gui::Button>( panel->add(std::make_shared<gui::Button>(
@@ -145,6 +101,7 @@ static void show_content_missing(
menu->back(); menu->back();
} }
)); ));
menu->addPage("missing-content", panel);
menu->setPage("missing-content"); menu->setPage("missing-content");
} }
@@ -181,7 +138,7 @@ void EngineController::openWorld(std::string name, bool confirmConvert) {
show_content_missing(engine, content, lut); show_content_missing(engine, content, lut);
} else { } else {
if (confirmConvert) { 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); openWorld(name, false);
}), L"Converting world..."); }), L"Converting world...");
} else { } else {
+1 -1
View File
@@ -9,7 +9,7 @@
#include "../../../engine.h" #include "../../../engine.h"
#include "../../../assets/Assets.h" #include "../../../assets/Assets.h"
#include "../../../graphics/ui/gui_util.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/Button.hpp"
#include "../../../graphics/ui/elements/control/CheckBox.hpp" #include "../../../graphics/ui/elements/control/CheckBox.hpp"
#include "../../../graphics/ui/elements/control/TextBox.hpp" #include "../../../graphics/ui/elements/control/TextBox.hpp"