pane lua stuff

This commit is contained in:
Kae 2023-07-04 22:36:27 +10:00
parent 5df9adcd0e
commit c923f4f13b
20 changed files with 205 additions and 117 deletions

View File

@ -526,6 +526,10 @@ public:
template <typename Return, typename... Args, typename Function> template <typename Return, typename... Args, typename Function>
LuaFunction createFunctionWithSignature(Function&& func); LuaFunction createFunctionWithSignature(Function&& func);
LuaFunction createWrappedFunction(LuaDetail::LuaWrappedFunction function);
LuaFunction createRawFunction(lua_CFunction func);
LuaThread createThread(); LuaThread createThread();
template <typename T> template <typename T>
@ -639,9 +643,6 @@ private:
int placeHandle(); int placeHandle();
LuaFunction createWrappedFunction(LuaDetail::LuaWrappedFunction function);
LuaFunction createRawFunction(lua_CFunction func);
void pushLuaValue(lua_State* state, LuaValue const& luaValue); void pushLuaValue(lua_State* state, LuaValue const& luaValue);
LuaValue popLuaValue(lua_State* state); LuaValue popLuaValue(lua_State* state);

View File

@ -39,4 +39,16 @@ Maybe<Color> LuaConverter<Color>::to(LuaEngine& engine, LuaValue const& v) {
return {}; return {};
} }
LuaValue LuaConverter<LuaCallbacks>::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<LuaCallbacks> LuaConverter<LuaCallbacks>::to(LuaEngine& engine, LuaValue const& v) {
return {};
}
} }

View File

@ -259,6 +259,12 @@ struct LuaConverter<Color> {
static Maybe<Color> to(LuaEngine& engine, LuaValue const& v); static Maybe<Color> to(LuaEngine& engine, LuaValue const& v);
}; };
template <>
struct LuaConverter<LuaCallbacks> {
static LuaValue from(LuaEngine& engine, LuaCallbacks const& c);
static Maybe<LuaCallbacks> to(LuaEngine& engine, LuaValue const& v);
};
} }
#endif #endif

View File

@ -55,7 +55,6 @@ SET (star_frontend_HEADERS
StarSongbookInterface.hpp StarSongbookInterface.hpp
StarStatusPane.hpp StarStatusPane.hpp
StarTeleportDialog.hpp StarTeleportDialog.hpp
StarWidgetLuaBindings.hpp
StarWireInterface.hpp StarWireInterface.hpp
) )
@ -104,7 +103,6 @@ SET (star_frontend_SOURCES
StarSongbookInterface.cpp StarSongbookInterface.cpp
StarStatusPane.cpp StarStatusPane.cpp
StarTeleportDialog.cpp StarTeleportDialog.cpp
StarWidgetLuaBindings.cpp
StarWireInterface.cpp StarWireInterface.cpp
) )

View File

@ -24,15 +24,17 @@ BaseScriptPane::BaseScriptPane(Json config) : Pane() {
} else { } else {
m_config = assets->fetchJson(config); m_config = assets->fetchJson(config);
} }
m_reader.registerCallback("close", [this](Widget*) { dismiss(); });
m_reader = make_shared<GuiReader>();
m_reader->registerCallback("close", [this](Widget*) { dismiss(); });
for (auto const& callbackName : jsonToStringList(m_config.get("scriptWidgetCallbacks", JsonArray{}))) { 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_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", {})) for (auto pair : m_config.getObject("canvasClickCallbacks", {}))
m_canvasClickCallbacks.set(findChild<CanvasWidget>(pair.first), pair.second.toString()); m_canvasClickCallbacks.set(findChild<CanvasWidget>(pair.first), pair.second.toString());
@ -53,7 +55,7 @@ void BaseScriptPane::displayed() {
Pane::displayed(); Pane::displayed();
if (!m_callbacksAdded) { if (!m_callbacksAdded) {
m_script.addCallbacks("pane", makePaneCallbacks()); 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) { m_script.addCallbacks("config", LuaBindings::makeConfigCallbacks( [this](String const& name, Json const& def) {
return m_config.query(name, 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_script.invoke(p.second, (int)keyEvent.key, keyEvent.keyDown);
} }
m_playingSounds.filter([](pair<String, AudioInstancePtr> const& p) {
return p.second->finished() == false;
});
m_script.update(m_script.updateDt()); m_script.update(m_script.updateDt());
} }
@ -106,7 +104,7 @@ PanePtr BaseScriptPane::createTooltip(Vec2I const& screenPosition) {
return SimpleTooltipBuilder::buildTooltip(result->toString()); return SimpleTooltipBuilder::buildTooltip(result->toString());
} else { } else {
PanePtr tooltip = make_shared<Pane>(); PanePtr tooltip = make_shared<Pane>();
m_reader.construct(*result, tooltip.get()); m_reader->construct(*result, tooltip.get());
return tooltip; return tooltip;
} }
} else { } else {
@ -131,53 +129,8 @@ Maybe<String> BaseScriptPane::cursorOverride(Vec2I const& screenPosition) {
return {}; return {};
} }
LuaCallbacks BaseScriptPane::makePaneCallbacks() { GuiReaderPtr BaseScriptPane::reader() {
LuaCallbacks callbacks; return m_reader;
callbacks.registerCallback("dismiss", [this]() { dismiss(); });
callbacks.registerCallback("playSound",
[this](String const& audio, Maybe<int> loops, Maybe<float> volume) {
auto assets = Root::singleton().assets();
auto config = Root::singleton().configuration();
auto audioInstance = make_shared<AudioInstance>(*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<String, AudioInstancePtr> 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<ImageWidget>(titleIcon()))
icon->setImage(image);
});
callbacks.registerCallback("addWidget", [this](Json const& newWidgetConfig, Maybe<String> 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;
} }
} }

View File

@ -12,6 +12,8 @@ STAR_CLASS(BaseScriptPane);
// A more 'raw' script pane that doesn't depend on a world being present. // A more 'raw' script pane that doesn't depend on a world being present.
// Requires a derived class to provide a Lua root. // Requires a derived class to provide a Lua root.
// Should maybe move into windowing?
class BaseScriptPane : public Pane { class BaseScriptPane : public Pane {
public: public:
BaseScriptPane(Json config); BaseScriptPane(Json config);
@ -27,17 +29,16 @@ public:
PanePtr createTooltip(Vec2I const& screenPosition) override; PanePtr createTooltip(Vec2I const& screenPosition) override;
Maybe<String> cursorOverride(Vec2I const& screenPosition) override; Maybe<String> cursorOverride(Vec2I const& screenPosition) override;
protected: protected:
virtual LuaCallbacks makePaneCallbacks(); virtual GuiReaderPtr reader();
Json m_config; Json m_config;
GuiReader m_reader; GuiReaderPtr m_reader;
Map<CanvasWidgetPtr, String> m_canvasClickCallbacks; Map<CanvasWidgetPtr, String> m_canvasClickCallbacks;
Map<CanvasWidgetPtr, String> m_canvasKeyCallbacks; Map<CanvasWidgetPtr, String> m_canvasKeyCallbacks;
bool m_callbacksAdded; bool m_callbacksAdded;
LuaUpdatableComponent<LuaBaseComponent> m_script; LuaUpdatableComponent<LuaBaseComponent> m_script;
List<pair<String, AudioInstancePtr>> m_playingSounds;
}; };
} }

View File

@ -34,7 +34,7 @@ ContainerPane::ContainerPane(WorldClientPtr worldClient, PlayerPtr player, Conta
m_script.emplace(); m_script.emplace();
m_script->setScripts(*scripts); 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) { m_script->addCallbacks("config", LuaBindings::makeConfigCallbacks( [guiConfig](String const& name, Json const& def) {
return guiConfig.query(name, def); return guiConfig.query(name, def);
})); }));

View File

@ -3,6 +3,7 @@
#include "StarJsonExtra.hpp" #include "StarJsonExtra.hpp"
#include "StarLuaGameConverters.hpp" #include "StarLuaGameConverters.hpp"
#include "StarMainInterface.hpp" #include "StarMainInterface.hpp"
#include "StarGuiContext.hpp"
namespace Star { namespace Star {
@ -15,6 +16,17 @@ LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) {
return {}; return {};
}); });
callbacks.registerCallback("bindRegisteredPane", [mainInterface](String const& registeredPaneName) -> Maybe<LuaCallbacks> {
if (auto pane = mainInterface->paneManager()->maybeRegisteredPane(MainInterfacePanesNames.getLeft(registeredPaneName)))
return pane->makePaneCallbacks();
return {};
});
callbacks.registerCallback("scale", [mainInterface]() -> int {
return GuiContext::singleton().interfaceScale();
});
return callbacks; return callbacks;
} }

View File

@ -6,6 +6,32 @@
namespace Star { namespace Star {
EnumMap<MainInterfacePanes> 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() { MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
auto& root = Root::singleton(); auto& root = Root::singleton();
auto assets = root.assets(); auto assets = root.assets();

View File

@ -37,6 +37,8 @@ enum class MainInterfacePanes {
Collections Collections
}; };
extern EnumMap<MainInterfacePanes> const MainInterfacePanesNames;
typedef RegisteredPaneManager<MainInterfacePanes> MainInterfacePaneManager; typedef RegisteredPaneManager<MainInterfacePanes> MainInterfacePaneManager;
struct MainInterfaceConfig { struct MainInterfaceConfig {

View File

@ -48,25 +48,10 @@ void ScriptPane::dismissed() {
} }
void ScriptPane::tick() { void ScriptPane::tick() {
BaseScriptPane::tick();
if (m_sourceEntityId != NullEntityId && !m_client->worldClient()->playerCanReachEntity(m_sourceEntityId)) if (m_sourceEntityId != NullEntityId && !m_client->worldClient()->playerCanReachEntity(m_sourceEntityId))
dismiss(); dismiss();
for (auto p : m_canvasClickCallbacks) { BaseScriptPane::tick();
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<String, AudioInstancePtr> const& p) {
return p.second->finished() == false;
});
m_script.update(m_script.updateDt());
} }
PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) { PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) {
@ -76,7 +61,7 @@ PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) {
return SimpleTooltipBuilder::buildTooltip(result->toString()); return SimpleTooltipBuilder::buildTooltip(result->toString());
} else { } else {
PanePtr tooltip = make_shared<Pane>(); PanePtr tooltip = make_shared<Pane>();
m_reader.construct(*result, tooltip.get()); m_reader->construct(*result, tooltip.get());
return tooltip; return tooltip;
} }
} else { } else {

View File

@ -22,9 +22,8 @@ public:
bool openWithInventory() const; bool openWithInventory() const;
private:
LuaCallbacks makePaneCallbacks() override; LuaCallbacks makePaneCallbacks() override;
private:
UniverseClientPtr m_client; UniverseClientPtr m_client;
EntityId m_sourceEntityId; EntityId m_sourceEntityId;
}; };

View File

@ -38,6 +38,7 @@ SET (star_windowing_HEADERS
StarTextBoxWidget.hpp StarTextBoxWidget.hpp
StarVerticalLayout.hpp StarVerticalLayout.hpp
StarWidget.hpp StarWidget.hpp
StarWidgetLuaBindings.hpp
StarWidgetParsing.hpp StarWidgetParsing.hpp
) )
@ -70,6 +71,7 @@ SET (star_windowing_SOURCES
StarTextBoxWidget.cpp StarTextBoxWidget.cpp
StarVerticalLayout.cpp StarVerticalLayout.cpp
StarWidget.cpp StarWidget.cpp
StarWidgetLuaBindings.cpp
StarWidgetParsing.cpp StarWidgetParsing.cpp
) )

View File

@ -6,6 +6,7 @@
namespace Star { namespace Star {
STAR_EXCEPTION(GUIBuilderException, StarException); STAR_EXCEPTION(GUIBuilderException, StarException);
STAR_CLASS(GuiReader);
class GuiReader : public WidgetParser { class GuiReader : public WidgetParser {
public: public:

View File

@ -6,7 +6,6 @@
namespace Star { namespace Star {
STAR_CLASS(GuiReader);
STAR_CLASS(ListWidget); STAR_CLASS(ListWidget);
class ListWidget : public Widget { class ListWidget : public Widget {

View File

@ -2,6 +2,10 @@
#include "StarRoot.hpp" #include "StarRoot.hpp"
#include "StarJsonExtra.hpp" #include "StarJsonExtra.hpp"
#include "StarAssets.hpp" #include "StarAssets.hpp"
#include "StarWidgetLuaBindings.hpp"
#include "StarLuaConverters.hpp"
#include "StarImageWidget.hpp"
#include "StarGuiReader.hpp"
namespace Star { namespace Star {
@ -187,35 +191,6 @@ Pane* Pane::window() {
return this; 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() { void Pane::update() {
if (m_visible) { if (m_visible) {
for (auto const& widget : m_members) { for (auto const& widget : m_members) {
@ -228,7 +203,11 @@ void Pane::update() {
} }
} }
void Pane::tick() {} void Pane::tick() {
m_playingSounds.filter([](pair<String, AudioInstancePtr> const& p) {
return p.second->finished() == false;
});
}
bool Pane::dragActive() const { bool Pane::dragActive() const {
return m_dragActive; return m_dragActive;
@ -369,4 +348,96 @@ Maybe<String> Pane::cursorOverride(Vec2I const&) {
return {}; 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<int> loops, Maybe<float> volume) {
auto assets = Root::singleton().assets();
auto config = Root::singleton().configuration();
auto audioInstance = make_shared<AudioInstance>(*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<String> const& audio) {
m_playingSounds.filter([audio](pair<String, AudioInstancePtr> 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<ImageWidget>(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<String> 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<GuiReader>();
}
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();
}
}
} }

View File

@ -7,6 +7,9 @@
namespace Star { namespace Star {
STAR_CLASS(Pane); STAR_CLASS(Pane);
STAR_CLASS(LuaCallbacks);
STAR_CLASS(AudioInstance);
STAR_CLASS(GuiReader);
enum class PaneAnchor { enum class PaneAnchor {
None, None,
@ -89,7 +92,9 @@ public:
virtual PanePtr createTooltip(Vec2I const& screenPosition); virtual PanePtr createTooltip(Vec2I const& screenPosition);
virtual Maybe<String> cursorOverride(Vec2I const& screenPosition); virtual Maybe<String> cursorOverride(Vec2I const& screenPosition);
virtual LuaCallbacks makePaneCallbacks();
protected: protected:
virtual GuiReaderPtr reader();
virtual void renderImpl(); virtual void renderImpl();
String m_bgHeader; String m_bgHeader;
@ -124,6 +129,8 @@ protected:
PaneAnchor m_anchor; PaneAnchor m_anchor;
Vec2I m_anchorOffset; Vec2I m_anchorOffset;
bool m_hasDisplayed; bool m_hasDisplayed;
List<pair<String, AudioInstancePtr>> m_playingSounds;
}; };
} }

View File

@ -19,6 +19,8 @@ public:
template <typename T = Pane> template <typename T = Pane>
shared_ptr<T> registeredPane(KeyT const& paneId) const; shared_ptr<T> registeredPane(KeyT const& paneId) const;
template <typename T = Pane>
shared_ptr<T> maybeRegisteredPane(KeyT const& paneId) const;
// Displays a registred pane if it is not already displayed. Returns true // Displays a registred pane if it is not already displayed. Returns true
// if it is newly displayed. // if it is newly displayed.
@ -53,6 +55,14 @@ shared_ptr<T> RegisteredPaneManager<KeyT>::registeredPane(KeyT const& paneId) co
throw GuiException(strf("No pane named '{}' found in RegisteredPaneManager", outputAny(paneId))); throw GuiException(strf("No pane named '{}' found in RegisteredPaneManager", outputAny(paneId)));
} }
template <typename KeyT>
template <typename T>
shared_ptr<T> RegisteredPaneManager<KeyT>::maybeRegisteredPane(KeyT const& paneId) const {
if (auto v = m_registeredPanes.ptr(paneId))
return convert<T>(v->pane);
return {};
}
template <typename KeyT> template <typename KeyT>
void RegisteredPaneManager<KeyT>::registerPane( void RegisteredPaneManager<KeyT>::registerPane(
KeyT paneId, PaneLayer paneLayer, PanePtr pane, DismissCallback onDismiss) { KeyT paneId, PaneLayer paneLayer, PanePtr pane, DismissCallback onDismiss) {

View File

@ -89,7 +89,10 @@ LuaMethods<CanvasWidgetPtr> LuaUserDataMethods<CanvasWidgetPtr>::make() {
return methods; return methods;
} }
LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReader* reader) { LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr reader) {
if (!reader)
reader = make_shared<GuiReader>();
LuaCallbacks callbacks; LuaCallbacks callbacks;
// a bit miscellaneous, but put this here since widgets have access to gui context // a bit miscellaneous, but put this here since widgets have access to gui context

View File

@ -18,7 +18,7 @@ struct LuaUserDataMethods<CanvasWidgetPtr> {
}; };
namespace LuaBindings { namespace LuaBindings {
LuaCallbacks makeWidgetCallbacks(Widget* parentWidget, GuiReader* reader); LuaCallbacks makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr reader = {});
} }
} }