From c923f4f13b1cade968bb6fec585a242b62d35715 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 4 Jul 2023 22:36:27 +1000 Subject: [PATCH] pane lua stuff --- source/core/StarLua.hpp | 7 +- source/core/StarLuaConverters.cpp | 12 ++ source/core/StarLuaConverters.hpp | 6 + source/frontend/CMakeLists.txt | 2 - source/frontend/StarBaseScriptPane.cpp | 65 ++------- source/frontend/StarBaseScriptPane.hpp | 7 +- source/frontend/StarContainerInterface.cpp | 2 +- source/frontend/StarInterfaceLuaBindings.cpp | 12 ++ source/frontend/StarMainInterfaceTypes.cpp | 26 ++++ source/frontend/StarMainInterfaceTypes.hpp | 2 + source/frontend/StarScriptPane.cpp | 19 +-- source/frontend/StarScriptPane.hpp | 3 +- source/windowing/CMakeLists.txt | 2 + source/windowing/StarGuiReader.hpp | 1 + source/windowing/StarListWidget.hpp | 1 - source/windowing/StarPane.cpp | 131 ++++++++++++++---- source/windowing/StarPane.hpp | 7 + .../windowing/StarRegisteredPaneManager.hpp | 10 ++ .../StarWidgetLuaBindings.cpp | 5 +- .../StarWidgetLuaBindings.hpp | 2 +- 20 files changed, 205 insertions(+), 117 deletions(-) rename source/{frontend => windowing}/StarWidgetLuaBindings.cpp (99%) rename source/{frontend => windowing}/StarWidgetLuaBindings.hpp (96%) diff --git a/source/core/StarLua.hpp b/source/core/StarLua.hpp index 41310a3..500923d 100644 --- a/source/core/StarLua.hpp +++ b/source/core/StarLua.hpp @@ -526,6 +526,10 @@ public: template LuaFunction createFunctionWithSignature(Function&& func); + LuaFunction createWrappedFunction(LuaDetail::LuaWrappedFunction function); + + LuaFunction createRawFunction(lua_CFunction func); + LuaThread createThread(); template @@ -639,9 +643,6 @@ private: int placeHandle(); - LuaFunction createWrappedFunction(LuaDetail::LuaWrappedFunction function); - LuaFunction createRawFunction(lua_CFunction func); - void pushLuaValue(lua_State* state, LuaValue const& luaValue); LuaValue popLuaValue(lua_State* state); diff --git a/source/core/StarLuaConverters.cpp b/source/core/StarLuaConverters.cpp index 9cd44e3..e170da5 100644 --- a/source/core/StarLuaConverters.cpp +++ b/source/core/StarLuaConverters.cpp @@ -39,4 +39,16 @@ Maybe LuaConverter::to(LuaEngine& engine, LuaValue const& v) { return {}; } +LuaValue LuaConverter::from(LuaEngine& engine, LuaCallbacks const& c) { + auto table = engine.createTable(0, c.callbacks().size()); + for (auto& callback : c.callbacks()) + table.set(callback.first, engine.createWrappedFunction(callback.second)); + + return table; +} + +Maybe LuaConverter::to(LuaEngine& engine, LuaValue const& v) { + return {}; +} + } diff --git a/source/core/StarLuaConverters.hpp b/source/core/StarLuaConverters.hpp index c20442f..eb06e35 100644 --- a/source/core/StarLuaConverters.hpp +++ b/source/core/StarLuaConverters.hpp @@ -259,6 +259,12 @@ struct LuaConverter { static Maybe to(LuaEngine& engine, LuaValue const& v); }; +template <> +struct LuaConverter { + static LuaValue from(LuaEngine& engine, LuaCallbacks const& c); + static Maybe to(LuaEngine& engine, LuaValue const& v); +}; + } #endif diff --git a/source/frontend/CMakeLists.txt b/source/frontend/CMakeLists.txt index 4772aa0..ea6edc6 100644 --- a/source/frontend/CMakeLists.txt +++ b/source/frontend/CMakeLists.txt @@ -55,7 +55,6 @@ SET (star_frontend_HEADERS StarSongbookInterface.hpp StarStatusPane.hpp StarTeleportDialog.hpp - StarWidgetLuaBindings.hpp StarWireInterface.hpp ) @@ -104,7 +103,6 @@ SET (star_frontend_SOURCES StarSongbookInterface.cpp StarStatusPane.cpp StarTeleportDialog.cpp - StarWidgetLuaBindings.cpp StarWireInterface.cpp ) diff --git a/source/frontend/StarBaseScriptPane.cpp b/source/frontend/StarBaseScriptPane.cpp index a174622..0254e46 100644 --- a/source/frontend/StarBaseScriptPane.cpp +++ b/source/frontend/StarBaseScriptPane.cpp @@ -24,15 +24,17 @@ BaseScriptPane::BaseScriptPane(Json config) : Pane() { } else { m_config = assets->fetchJson(config); } - m_reader.registerCallback("close", [this](Widget*) { dismiss(); }); + + m_reader = make_shared(); + m_reader->registerCallback("close", [this](Widget*) { dismiss(); }); for (auto const& callbackName : jsonToStringList(m_config.get("scriptWidgetCallbacks", JsonArray{}))) { - m_reader.registerCallback(callbackName, [this, callbackName](Widget* widget) { + m_reader->registerCallback(callbackName, [this, callbackName](Widget* widget) { m_script.invoke(callbackName, widget->name(), widget->data()); }); } - m_reader.construct(assets->fetchJson(m_config.get("gui")), this); + m_reader->construct(assets->fetchJson(m_config.get("gui")), this); for (auto pair : m_config.getObject("canvasClickCallbacks", {})) m_canvasClickCallbacks.set(findChild(pair.first), pair.second.toString()); @@ -53,7 +55,7 @@ void BaseScriptPane::displayed() { Pane::displayed(); if (!m_callbacksAdded) { m_script.addCallbacks("pane", makePaneCallbacks()); - m_script.addCallbacks("widget", LuaBindings::makeWidgetCallbacks(this, &m_reader)); + m_script.addCallbacks("widget", LuaBindings::makeWidgetCallbacks(this, m_reader)); m_script.addCallbacks("config", LuaBindings::makeConfigCallbacks( [this](String const& name, Json const& def) { return m_config.query(name, def); })); @@ -81,10 +83,6 @@ void BaseScriptPane::tick() { m_script.invoke(p.second, (int)keyEvent.key, keyEvent.keyDown); } - m_playingSounds.filter([](pair const& p) { - return p.second->finished() == false; - }); - m_script.update(m_script.updateDt()); } @@ -106,7 +104,7 @@ PanePtr BaseScriptPane::createTooltip(Vec2I const& screenPosition) { return SimpleTooltipBuilder::buildTooltip(result->toString()); } else { PanePtr tooltip = make_shared(); - m_reader.construct(*result, tooltip.get()); + m_reader->construct(*result, tooltip.get()); return tooltip; } } else { @@ -131,53 +129,8 @@ Maybe BaseScriptPane::cursorOverride(Vec2I const& screenPosition) { return {}; } -LuaCallbacks BaseScriptPane::makePaneCallbacks() { - LuaCallbacks callbacks; - - callbacks.registerCallback("dismiss", [this]() { dismiss(); }); - - callbacks.registerCallback("playSound", - [this](String const& audio, Maybe loops, Maybe volume) { - auto assets = Root::singleton().assets(); - auto config = Root::singleton().configuration(); - auto audioInstance = make_shared(*assets->audio(audio)); - audioInstance->setVolume(volume.value(1.0)); - audioInstance->setLoops(loops.value(0)); - auto& guiContext = GuiContext::singleton(); - guiContext.playAudio(audioInstance); - m_playingSounds.append({audio, move(audioInstance)}); - }); - - callbacks.registerCallback("stopAllSounds", [this](String const& audio) { - m_playingSounds.filter([audio](pair const& p) { - if (p.first == audio) { - p.second->stop(); - return false; - } - return true; - }); - }); - - callbacks.registerCallback("setTitle", [this](String const& title, String const& subTitle) { - setTitleString(title, subTitle); - }); - - callbacks.registerCallback("setTitleIcon", [this](String const& image) { - if (auto icon = as(titleIcon())) - icon->setImage(image); - }); - - callbacks.registerCallback("addWidget", [this](Json const& newWidgetConfig, Maybe const& newWidgetName) { - String name = newWidgetName.value(strf("{}", Random::randu64())); - WidgetPtr newWidget = m_reader.makeSingle(name, newWidgetConfig); - this->addChild(name, newWidget); - }); - - callbacks.registerCallback("removeWidget", [this](String const& widgetName) { - this->removeChild(widgetName); - }); - - return callbacks; +GuiReaderPtr BaseScriptPane::reader() { + return m_reader; } } diff --git a/source/frontend/StarBaseScriptPane.hpp b/source/frontend/StarBaseScriptPane.hpp index f88cd40..b5aa502 100644 --- a/source/frontend/StarBaseScriptPane.hpp +++ b/source/frontend/StarBaseScriptPane.hpp @@ -12,6 +12,8 @@ STAR_CLASS(BaseScriptPane); // A more 'raw' script pane that doesn't depend on a world being present. // Requires a derived class to provide a Lua root. +// Should maybe move into windowing? + class BaseScriptPane : public Pane { public: BaseScriptPane(Json config); @@ -27,17 +29,16 @@ public: PanePtr createTooltip(Vec2I const& screenPosition) override; Maybe cursorOverride(Vec2I const& screenPosition) override; protected: - virtual LuaCallbacks makePaneCallbacks(); + virtual GuiReaderPtr reader(); Json m_config; - GuiReader m_reader; + GuiReaderPtr m_reader; Map m_canvasClickCallbacks; Map m_canvasKeyCallbacks; bool m_callbacksAdded; LuaUpdatableComponent m_script; - List> m_playingSounds; }; } diff --git a/source/frontend/StarContainerInterface.cpp b/source/frontend/StarContainerInterface.cpp index 9f80a94..10da82f 100644 --- a/source/frontend/StarContainerInterface.cpp +++ b/source/frontend/StarContainerInterface.cpp @@ -34,7 +34,7 @@ ContainerPane::ContainerPane(WorldClientPtr worldClient, PlayerPtr player, Conta m_script.emplace(); m_script->setScripts(*scripts); } - m_script->addCallbacks("widget", LuaBindings::makeWidgetCallbacks(this, &m_reader)); + m_script->addCallbacks("widget", LuaBindings::makeWidgetCallbacks(this)); m_script->addCallbacks("config", LuaBindings::makeConfigCallbacks( [guiConfig](String const& name, Json const& def) { return guiConfig.query(name, def); })); diff --git a/source/frontend/StarInterfaceLuaBindings.cpp b/source/frontend/StarInterfaceLuaBindings.cpp index a9257aa..65bcd68 100644 --- a/source/frontend/StarInterfaceLuaBindings.cpp +++ b/source/frontend/StarInterfaceLuaBindings.cpp @@ -3,6 +3,7 @@ #include "StarJsonExtra.hpp" #include "StarLuaGameConverters.hpp" #include "StarMainInterface.hpp" +#include "StarGuiContext.hpp" namespace Star { @@ -15,6 +16,17 @@ LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) { return {}; }); + + callbacks.registerCallback("bindRegisteredPane", [mainInterface](String const& registeredPaneName) -> Maybe { + if (auto pane = mainInterface->paneManager()->maybeRegisteredPane(MainInterfacePanesNames.getLeft(registeredPaneName))) + return pane->makePaneCallbacks(); + return {}; + }); + + callbacks.registerCallback("scale", [mainInterface]() -> int { + return GuiContext::singleton().interfaceScale(); + }); + return callbacks; } diff --git a/source/frontend/StarMainInterfaceTypes.cpp b/source/frontend/StarMainInterfaceTypes.cpp index 0731574..1d67292 100644 --- a/source/frontend/StarMainInterfaceTypes.cpp +++ b/source/frontend/StarMainInterfaceTypes.cpp @@ -6,6 +6,32 @@ namespace Star { +EnumMap const MainInterfacePanesNames{ + {MainInterfacePanes::EscapeDialog, "EscapeDialog"}, + {MainInterfacePanes::Inventory, "Inventory"}, + {MainInterfacePanes::Codex, "Codex"}, + {MainInterfacePanes::Cockpit, "Cockpit"}, + {MainInterfacePanes::Tech, "Tech"}, + {MainInterfacePanes::Songbook, "Songbook"}, + {MainInterfacePanes::Ai, "Ai"}, + {MainInterfacePanes::Popup, "Popup"}, + {MainInterfacePanes::Confirmation, "Confirmation"}, + {MainInterfacePanes::JoinRequest, "JoinRequest"}, + {MainInterfacePanes::Options, "Options"}, + {MainInterfacePanes::QuestLog, "QuestLog"}, + {MainInterfacePanes::ActionBar, "ActionBar"}, + {MainInterfacePanes::TeamBar, "TeamBar"}, + {MainInterfacePanes::StatusPane, "StatusPane"}, + {MainInterfacePanes::Chat, "Chat"}, + {MainInterfacePanes::WireInterface, "WireInterface"}, + {MainInterfacePanes::PlanetText, "PlanetText"}, + {MainInterfacePanes::RadioMessagePopup, "RadioMessagePopup"}, + {MainInterfacePanes::CraftingPlain, "CraftingPlain"}, + {MainInterfacePanes::QuestTracker, "QuestTracker"}, + {MainInterfacePanes::MmUpgrade, "MmUpgrade"}, + {MainInterfacePanes::Collections, "Collections"} +}; + MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() { auto& root = Root::singleton(); auto assets = root.assets(); diff --git a/source/frontend/StarMainInterfaceTypes.hpp b/source/frontend/StarMainInterfaceTypes.hpp index e09892c..70fdee1 100644 --- a/source/frontend/StarMainInterfaceTypes.hpp +++ b/source/frontend/StarMainInterfaceTypes.hpp @@ -37,6 +37,8 @@ enum class MainInterfacePanes { Collections }; +extern EnumMap const MainInterfacePanesNames; + typedef RegisteredPaneManager MainInterfacePaneManager; struct MainInterfaceConfig { diff --git a/source/frontend/StarScriptPane.cpp b/source/frontend/StarScriptPane.cpp index b09211d..3de3c26 100644 --- a/source/frontend/StarScriptPane.cpp +++ b/source/frontend/StarScriptPane.cpp @@ -48,25 +48,10 @@ void ScriptPane::dismissed() { } void ScriptPane::tick() { - BaseScriptPane::tick(); - if (m_sourceEntityId != NullEntityId && !m_client->worldClient()->playerCanReachEntity(m_sourceEntityId)) dismiss(); - for (auto p : m_canvasClickCallbacks) { - for (auto const& clickEvent : p.first->pullClickEvents()) - m_script.invoke(p.second, jsonFromVec2I(clickEvent.position), (uint8_t)clickEvent.button, clickEvent.buttonDown); - } - for (auto p : m_canvasKeyCallbacks) { - for (auto const& keyEvent : p.first->pullKeyEvents()) - m_script.invoke(p.second, (int)keyEvent.key, keyEvent.keyDown); - } - - m_playingSounds.filter([](pair const& p) { - return p.second->finished() == false; - }); - - m_script.update(m_script.updateDt()); + BaseScriptPane::tick(); } PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) { @@ -76,7 +61,7 @@ PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) { return SimpleTooltipBuilder::buildTooltip(result->toString()); } else { PanePtr tooltip = make_shared(); - m_reader.construct(*result, tooltip.get()); + m_reader->construct(*result, tooltip.get()); return tooltip; } } else { diff --git a/source/frontend/StarScriptPane.hpp b/source/frontend/StarScriptPane.hpp index d994b68..229ebbb 100644 --- a/source/frontend/StarScriptPane.hpp +++ b/source/frontend/StarScriptPane.hpp @@ -22,9 +22,8 @@ public: bool openWithInventory() const; -private: LuaCallbacks makePaneCallbacks() override; - +private: UniverseClientPtr m_client; EntityId m_sourceEntityId; }; diff --git a/source/windowing/CMakeLists.txt b/source/windowing/CMakeLists.txt index 18e035d..5db1ce6 100644 --- a/source/windowing/CMakeLists.txt +++ b/source/windowing/CMakeLists.txt @@ -38,6 +38,7 @@ SET (star_windowing_HEADERS StarTextBoxWidget.hpp StarVerticalLayout.hpp StarWidget.hpp + StarWidgetLuaBindings.hpp StarWidgetParsing.hpp ) @@ -70,6 +71,7 @@ SET (star_windowing_SOURCES StarTextBoxWidget.cpp StarVerticalLayout.cpp StarWidget.cpp + StarWidgetLuaBindings.cpp StarWidgetParsing.cpp ) diff --git a/source/windowing/StarGuiReader.hpp b/source/windowing/StarGuiReader.hpp index f42a037..e031f62 100644 --- a/source/windowing/StarGuiReader.hpp +++ b/source/windowing/StarGuiReader.hpp @@ -6,6 +6,7 @@ namespace Star { STAR_EXCEPTION(GUIBuilderException, StarException); +STAR_CLASS(GuiReader); class GuiReader : public WidgetParser { public: diff --git a/source/windowing/StarListWidget.hpp b/source/windowing/StarListWidget.hpp index 8f511e3..8bb63db 100644 --- a/source/windowing/StarListWidget.hpp +++ b/source/windowing/StarListWidget.hpp @@ -6,7 +6,6 @@ namespace Star { -STAR_CLASS(GuiReader); STAR_CLASS(ListWidget); class ListWidget : public Widget { diff --git a/source/windowing/StarPane.cpp b/source/windowing/StarPane.cpp index 69cbabf..a2d32ad 100644 --- a/source/windowing/StarPane.cpp +++ b/source/windowing/StarPane.cpp @@ -2,6 +2,10 @@ #include "StarRoot.hpp" #include "StarJsonExtra.hpp" #include "StarAssets.hpp" +#include "StarWidgetLuaBindings.hpp" +#include "StarLuaConverters.hpp" +#include "StarImageWidget.hpp" +#include "StarGuiReader.hpp" namespace Star { @@ -187,35 +191,6 @@ Pane* Pane::window() { return this; } -void Pane::renderImpl() { - if (m_bgFooter != "") - m_context->drawInterfaceQuad(m_bgFooter, Vec2F(position())); - - if (m_bgBody != "") - m_context->drawInterfaceQuad(m_bgBody, Vec2F(position()) + Vec2F(0, m_footerSize[1])); - - if (m_bgHeader != "") { - auto headerPos = Vec2F(position()) + Vec2F(0, m_footerSize[1] + m_bodySize[1]); - m_context->drawInterfaceQuad(m_bgHeader, headerPos); - - if (m_icon) { - m_icon->setPosition(Vec2I(0, m_footerSize[1] + m_bodySize[1]) + m_iconOffset); - m_icon->render(m_drawingArea); - m_context->resetInterfaceScissorRect(); - } - - m_context->setFont(m_font); - m_context->setFontSize(m_fontSize); - m_context->setFontColor(m_titleColor.toRgba()); - m_context->setFontMode(FontMode::Shadow); - m_context->renderInterfaceText(m_title, {headerPos + Vec2F(m_titleOffset)}); - m_context->setFontColor(m_subTitleColor.toRgba()); - m_context->renderInterfaceText(m_subTitle, {headerPos + Vec2F(m_subTitleOffset)}); - m_context->setFontMode(FontMode::Normal); - m_context->setDefaultFont(); - } -} - void Pane::update() { if (m_visible) { for (auto const& widget : m_members) { @@ -228,7 +203,11 @@ void Pane::update() { } } -void Pane::tick() {} +void Pane::tick() { + m_playingSounds.filter([](pair const& p) { + return p.second->finished() == false; + }); +} bool Pane::dragActive() const { return m_dragActive; @@ -369,4 +348,96 @@ Maybe Pane::cursorOverride(Vec2I const&) { return {}; } +LuaCallbacks Pane::makePaneCallbacks() { + LuaCallbacks callbacks; + + callbacks.registerCallback("toWidget", [this]() -> LuaCallbacks { + return LuaBindings::makeWidgetCallbacks(this, reader()); + }); + + callbacks.registerCallback("dismiss", [this]() { dismiss(); }); + + callbacks.registerCallback("playSound", + [this](String const& audio, Maybe loops, Maybe volume) { + auto assets = Root::singleton().assets(); + auto config = Root::singleton().configuration(); + auto audioInstance = make_shared(*assets->audio(audio)); + audioInstance->setVolume(volume.value(1.0)); + audioInstance->setLoops(loops.value(0)); + auto& guiContext = GuiContext::singleton(); + guiContext.playAudio(audioInstance); + m_playingSounds.append({audio, move(audioInstance)}); + }); + + callbacks.registerCallback("stopAllSounds", [this](Maybe const& audio) { + m_playingSounds.filter([audio](pair const& p) { + if (!audio || p.first == *audio) { + p.second->stop(); + return false; + } + return true; + }); + }); + + callbacks.registerCallback("setTitle", [this](String const& title, String const& subTitle) { + setTitleString(title, subTitle); + }); + + callbacks.registerCallback("setTitleIcon", [this](String const& image) { + if (auto icon = as(titleIcon())) + icon->setImage(image); + }); + + callbacks.registerCallback("getPosition", [this]() -> Vec2I { return relativePosition(); }); + callbacks.registerCallback("setPosition", [this](Vec2I const& position) { setPosition(position); }); + callbacks.registerCallback("getSize", [this]() -> Vec2I { return size(); }); + callbacks.registerCallback("setSize", [this](Vec2I const& size) { setSize(size); }); + + callbacks.registerCallback("addWidget", [this](Json const& newWidgetConfig, Maybe const& newWidgetName) -> LuaCallbacks { + String name = newWidgetName.value(toString(Random::randu64())); + WidgetPtr newWidget = reader()->makeSingle(name, newWidgetConfig); + this->addChild(name, newWidget); + return LuaBindings::makeWidgetCallbacks(newWidget.get(), reader()); + }); + + callbacks.registerCallback("removeWidget", [this](String const& widgetName) -> bool { + return this->removeChild(widgetName); + }); + + return callbacks; +} + +GuiReaderPtr Pane::reader() { + return make_shared(); +} + +void Pane::renderImpl() { + if (m_bgFooter != "") + m_context->drawInterfaceQuad(m_bgFooter, Vec2F(position())); + + if (m_bgBody != "") + m_context->drawInterfaceQuad(m_bgBody, Vec2F(position()) + Vec2F(0, m_footerSize[1])); + + if (m_bgHeader != "") { + auto headerPos = Vec2F(position()) + Vec2F(0, m_footerSize[1] + m_bodySize[1]); + m_context->drawInterfaceQuad(m_bgHeader, headerPos); + + if (m_icon) { + m_icon->setPosition(Vec2I(0, m_footerSize[1] + m_bodySize[1]) + m_iconOffset); + m_icon->render(m_drawingArea); + m_context->resetInterfaceScissorRect(); + } + + m_context->setFont(m_font); + m_context->setFontSize(m_fontSize); + m_context->setFontColor(m_titleColor.toRgba()); + m_context->setFontMode(FontMode::Shadow); + m_context->renderInterfaceText(m_title, {headerPos + Vec2F(m_titleOffset)}); + m_context->setFontColor(m_subTitleColor.toRgba()); + m_context->renderInterfaceText(m_subTitle, {headerPos + Vec2F(m_subTitleOffset)}); + m_context->setFontMode(FontMode::Normal); + m_context->setDefaultFont(); + } +} + } diff --git a/source/windowing/StarPane.hpp b/source/windowing/StarPane.hpp index ce78337..7a466b4 100644 --- a/source/windowing/StarPane.hpp +++ b/source/windowing/StarPane.hpp @@ -7,6 +7,9 @@ namespace Star { STAR_CLASS(Pane); +STAR_CLASS(LuaCallbacks); +STAR_CLASS(AudioInstance); +STAR_CLASS(GuiReader); enum class PaneAnchor { None, @@ -89,7 +92,9 @@ public: virtual PanePtr createTooltip(Vec2I const& screenPosition); virtual Maybe cursorOverride(Vec2I const& screenPosition); + virtual LuaCallbacks makePaneCallbacks(); protected: + virtual GuiReaderPtr reader(); virtual void renderImpl(); String m_bgHeader; @@ -124,6 +129,8 @@ protected: PaneAnchor m_anchor; Vec2I m_anchorOffset; bool m_hasDisplayed; + + List> m_playingSounds; }; } diff --git a/source/windowing/StarRegisteredPaneManager.hpp b/source/windowing/StarRegisteredPaneManager.hpp index 4038525..ebb158d 100644 --- a/source/windowing/StarRegisteredPaneManager.hpp +++ b/source/windowing/StarRegisteredPaneManager.hpp @@ -19,6 +19,8 @@ public: template shared_ptr registeredPane(KeyT const& paneId) const; + template + shared_ptr maybeRegisteredPane(KeyT const& paneId) const; // Displays a registred pane if it is not already displayed. Returns true // if it is newly displayed. @@ -53,6 +55,14 @@ shared_ptr RegisteredPaneManager::registeredPane(KeyT const& paneId) co throw GuiException(strf("No pane named '{}' found in RegisteredPaneManager", outputAny(paneId))); } +template +template +shared_ptr RegisteredPaneManager::maybeRegisteredPane(KeyT const& paneId) const { + if (auto v = m_registeredPanes.ptr(paneId)) + return convert(v->pane); + return {}; +} + template void RegisteredPaneManager::registerPane( KeyT paneId, PaneLayer paneLayer, PanePtr pane, DismissCallback onDismiss) { diff --git a/source/frontend/StarWidgetLuaBindings.cpp b/source/windowing/StarWidgetLuaBindings.cpp similarity index 99% rename from source/frontend/StarWidgetLuaBindings.cpp rename to source/windowing/StarWidgetLuaBindings.cpp index fb84ff8..62d2be6 100644 --- a/source/frontend/StarWidgetLuaBindings.cpp +++ b/source/windowing/StarWidgetLuaBindings.cpp @@ -89,7 +89,10 @@ LuaMethods LuaUserDataMethods::make() { return methods; } -LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReader* reader) { +LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr reader) { + if (!reader) + reader = make_shared(); + LuaCallbacks callbacks; // a bit miscellaneous, but put this here since widgets have access to gui context diff --git a/source/frontend/StarWidgetLuaBindings.hpp b/source/windowing/StarWidgetLuaBindings.hpp similarity index 96% rename from source/frontend/StarWidgetLuaBindings.hpp rename to source/windowing/StarWidgetLuaBindings.hpp index 48d6ab2..d133760 100644 --- a/source/frontend/StarWidgetLuaBindings.hpp +++ b/source/windowing/StarWidgetLuaBindings.hpp @@ -18,7 +18,7 @@ struct LuaUserDataMethods { }; namespace LuaBindings { - LuaCallbacks makeWidgetCallbacks(Widget* parentWidget, GuiReader* reader); + LuaCallbacks makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr reader = {}); } }