diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 7c03f37b..095c874d 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -6,10 +6,10 @@ Cancel=Отмена Back=Назад Continue=Продолжить Add=Добавить +Converting world...=Выполняется конвертация мира... error.pack-not-found=Не удалось найти пакет error.dependency-not-found=Используемая зависимость не найдена - pack.remove-confirm=Удалить весь поставляемый паком контент из мира (безвозвратно)? # Меню diff --git a/src/engine.cpp b/src/engine.cpp index 518fbd14..0855f345 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -26,7 +26,7 @@ #include "graphics/ImageData.h" #include "frontend/gui/GUI.h" #include "frontend/screens.h" -#include "frontend/menu.h" +#include "frontend/menu/menu.h" #include "util/platform.h" #include "coders/json.h" diff --git a/src/files/WorldConverter.cpp b/src/files/WorldConverter.cpp index ddf2e993..fe77cfc0 100644 --- a/src/files/WorldConverter.cpp +++ b/src/files/WorldConverter.cpp @@ -92,3 +92,7 @@ void WorldConverter::write() { std::cout << "writing world" << std::endl; wfile->write(nullptr, content); } + +uint WorldConverter::getTotalTasks() const { + return tasks.size(); +} diff --git a/src/files/WorldConverter.h b/src/files/WorldConverter.h index 180a78d0..031b69cd 100644 --- a/src/files/WorldConverter.h +++ b/src/files/WorldConverter.h @@ -4,6 +4,7 @@ #include #include #include +#include "../typedefs.h" namespace fs = std::filesystem; @@ -37,6 +38,8 @@ public: void convertNext(); void write(); + + uint getTotalTasks() const; }; #endif // FILES_WORLD_CONVERTER_H_ diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index 293f4432..743e6c35 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -84,6 +84,12 @@ void GUI::actMouse(float delta) { * @param delta delta time */ void GUI::act(float delta) { + while (!postRunnables.empty()) { + runnable callback = postRunnables.back(); + postRunnables.pop(); + callback(); + } + container->setSize(glm::vec2(Window::width, Window::height)); container->act(delta); auto prevfocus = focus; @@ -176,3 +182,7 @@ void GUI::setFocus(std::shared_ptr node) { std::shared_ptr GUI::getContainer() const { return container; } + +void GUI::postRunnable(runnable callback) { + postRunnables.push(callback); +} diff --git a/src/frontend/gui/GUI.h b/src/frontend/gui/GUI.h index fa9437ff..33e57a52 100644 --- a/src/frontend/gui/GUI.h +++ b/src/frontend/gui/GUI.h @@ -1,6 +1,7 @@ #ifndef FRONTEND_GUI_GUI_H_ #define FRONTEND_GUI_GUI_H_ +#include #include #include #include @@ -8,6 +9,8 @@ #include #include +#include "../../delegates.h" + class GfxContext; class Assets; class Camera; @@ -58,6 +61,7 @@ namespace gui { std::unique_ptr uicamera; std::shared_ptr menu; + std::queue postRunnables; void actMouse(float delta); public: GUI(); @@ -113,6 +117,8 @@ namespace gui { /** Get the main container */ std::shared_ptr getContainer() const; + + void postRunnable(runnable callback); }; } diff --git a/src/frontend/gui/containers.cpp b/src/frontend/gui/containers.cpp index e743f5af..7d43db58 100644 --- a/src/frontend/gui/containers.cpp +++ b/src/frontend/gui/containers.cpp @@ -34,6 +34,11 @@ std::shared_ptr Container::getAt(glm::vec2 pos, std::shared_ptr } void Container::act(float delta) { + for (auto node : nodes) { + if (node->isVisible()) { + node->act(delta); + } + } for (IntervalEvent& event : intervalEvents) { event.timer += delta; if (event.timer > event.interval) { @@ -50,12 +55,6 @@ void Container::act(float delta) { return event.repeat == 0; } ), intervalEvents.end()); - - for (auto node : nodes) { - if (node->isVisible()) { - node->act(delta); - } - } } void Container::scrolled(int value) { @@ -109,12 +108,6 @@ void Container::drawBackground(const GfxContext* pctx, Assets* assets) { batch->rect(coord.x, coord.y, size.x, size.y); } -void Container::addBack(std::shared_ptr node) { - nodes.insert(nodes.begin(), node); - node->setParent(this); - refresh(); -} - void Container::add(std::shared_ptr node) { nodes.push_back(node); node->setParent(this); diff --git a/src/frontend/gui/containers.h b/src/frontend/gui/containers.h index cc8cc414..b64c0720 100644 --- a/src/frontend/gui/containers.h +++ b/src/frontend/gui/containers.h @@ -39,7 +39,6 @@ namespace gui { virtual void drawBackground(const GfxContext* pctx, Assets* assets); virtual void draw(const GfxContext* pctx, Assets* assets) override; virtual std::shared_ptr getAt(glm::vec2 pos, std::shared_ptr self) override; - virtual void addBack(std::shared_ptr node); virtual void add(std::shared_ptr node); virtual void add(std::shared_ptr node, glm::vec2 coord); virtual void remove(std::shared_ptr node); diff --git a/src/frontend/menu.cpp b/src/frontend/menu.cpp deleted file mode 100644 index b053f709..00000000 --- a/src/frontend/menu.cpp +++ /dev/null @@ -1,763 +0,0 @@ -#include "menu.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "gui/GUI.h" -#include "gui/containers.h" -#include "gui/controls.h" -#include "screens.h" - -#include "../coders/png.h" -#include "../util/stringutil.h" -#include "../files/engine_paths.h" -#include "../files/WorldConverter.h" -#include "../files/WorldFiles.h" -#include "../world/World.h" -#include "../world/WorldGenerators.h" -#include "../world/Level.h" -#include "../window/Events.h" -#include "../window/Window.h" -#include "../engine.h" -#include "../settings.h" -#include "../delegates.h" -#include "../content/Content.h" -#include "../content/ContentLUT.h" -#include "../content/ContentPack.h" - -#include "gui/gui_util.h" -#include "locale/langs.h" - -using glm::vec2; -using glm::vec4; - -namespace fs = std::filesystem; -using namespace gui; - -namespace menus { - std::string generatorID; -} - -inline uint64_t randU64() { - srand(time(NULL)); - return rand() ^ (rand() << 8) ^ - (rand() << 16) ^ (rand() << 24) ^ - ((uint64_t)rand() << 32) ^ - ((uint64_t)rand() << 40) ^ - ((uint64_t)rand() << 56); -} - -static std::shared_ptr