add on_screen_change project script event & fix UIDocument::rebuildIndices & move menu background to project script
This commit is contained in:
@@ -60,6 +60,17 @@ static std::unique_ptr<ImageData> load_icon() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static std::unique_ptr<scripting::IProjectScript> load_project_script() {
|
||||
io::path scriptFile = "project:project_script.lua";
|
||||
if (io::exists(scriptFile)) {
|
||||
logger.info() << "starting project script";
|
||||
return scripting::load_project_script(scriptFile);
|
||||
} else {
|
||||
logger.warning() << "project script does not exists";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Engine::Engine() = default;
|
||||
Engine::~Engine() = default;
|
||||
|
||||
@@ -166,12 +177,15 @@ void Engine::initialize(CoreParameters coreParameters) {
|
||||
}
|
||||
});
|
||||
scripting::initialize(this);
|
||||
|
||||
if (!isHeadless()) {
|
||||
gui->setPageLoader(scripting::create_page_loader());
|
||||
}
|
||||
keepAlive(settings.ui.language.observe([this](auto lang) {
|
||||
langs::setup(lang, paths.resPaths.collectRoots());
|
||||
}, true));
|
||||
|
||||
projectScript = load_project_script();
|
||||
}
|
||||
|
||||
void Engine::loadSettings() {
|
||||
@@ -228,6 +242,7 @@ void Engine::run() {
|
||||
}
|
||||
}
|
||||
|
||||
#include "graphics/ui/elements/Container.hpp"
|
||||
void Engine::postUpdate() {
|
||||
network->update();
|
||||
postRunnables.run();
|
||||
@@ -270,6 +285,7 @@ void Engine::saveSettings() {
|
||||
}
|
||||
|
||||
void Engine::close() {
|
||||
projectScript.reset();
|
||||
saveSettings();
|
||||
logger.info() << "shutting down";
|
||||
if (screen) {
|
||||
@@ -349,6 +365,12 @@ void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||
audio::reset_channel(audio::get_channel_index("regular"));
|
||||
audio::reset_channel(audio::get_channel_index("ambient"));
|
||||
this->screen = std::move(screen);
|
||||
if (this->screen) {
|
||||
this->screen->onOpen();
|
||||
}
|
||||
if (projectScript && this->screen) {
|
||||
projectScript->onScreenChange(this->screen->getName());
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::onWorldOpen(std::unique_ptr<Level> level, int64_t localPlayer) {
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace devtools {
|
||||
class Editor;
|
||||
}
|
||||
|
||||
namespace scripting {
|
||||
class IProjectScript;
|
||||
}
|
||||
|
||||
class initialize_error : public std::runtime_error {
|
||||
public:
|
||||
initialize_error(const std::string& message) : std::runtime_error(message) {}
|
||||
@@ -71,6 +75,7 @@ class Engine : public util::ObjectsKeeper {
|
||||
std::unique_ptr<Input> input;
|
||||
std::unique_ptr<gui::GUI> gui;
|
||||
std::unique_ptr<devtools::Editor> editor;
|
||||
std::unique_ptr<scripting::IProjectScript> projectScript;
|
||||
PostRunnables postRunnables;
|
||||
Time time;
|
||||
OnWorldOpen levelConsumer;
|
||||
@@ -178,4 +183,8 @@ public:
|
||||
const Project& getProject() {
|
||||
return *project;
|
||||
}
|
||||
|
||||
scripting::IProjectScript* getProjectScript() {
|
||||
return projectScript.get();
|
||||
}
|
||||
};
|
||||
|
||||
+3
-14
@@ -5,10 +5,10 @@
|
||||
#include "devtools/Project.hpp"
|
||||
#include "frontend/screens/MenuScreen.hpp"
|
||||
#include "frontend/screens/LevelScreen.hpp"
|
||||
#include "interfaces/Process.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
#include "graphics/ui/elements/Container.hpp"
|
||||
|
||||
static debug::Logger logger("mainloop");
|
||||
|
||||
@@ -31,26 +31,15 @@ void Mainloop::run() {
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
io::path projectScript = "project:project_script.lua";
|
||||
std::unique_ptr<Process> process;
|
||||
if (io::exists(projectScript)) {
|
||||
logger.info() << "starting project script";
|
||||
process = scripting::start_coroutine(projectScript);
|
||||
} else {
|
||||
logger.warning() << "project script does not exists";
|
||||
}
|
||||
|
||||
logger.info() << "starting menu screen";
|
||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||
|
||||
logger.info() << "main loop started";
|
||||
while (!window.isShouldClose()){
|
||||
if (process) {
|
||||
process->update();
|
||||
}
|
||||
time.update(window.time());
|
||||
engine.updateFrontend();
|
||||
|
||||
if (!window.isIconified()) {
|
||||
engine.renderFrame();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user