ScriptPanes can specify paneLayer and interactive

This commit is contained in:
Kae 2023-07-30 00:41:38 +10:00
parent 057f3727de
commit ffd1507f72
6 changed files with 36 additions and 4 deletions

View File

@ -25,6 +25,7 @@ BaseScriptPane::BaseScriptPane(Json config) : Pane(), m_rawConfig(config) {
m_config = assets->fetchJson(config); m_config = assets->fetchJson(config);
} }
m_interactive = config.getBool("interactive", true);
m_reader = make_shared<GuiReader>(); m_reader = make_shared<GuiReader>();
m_reader->registerCallback("close", [this](Widget*) { dismiss(); }); m_reader->registerCallback("close", [this](Widget*) { dismiss(); });
@ -100,6 +101,8 @@ bool BaseScriptPane::sendEvent(InputEvent const& event) {
Json const& BaseScriptPane::config() const { return m_config; } Json const& BaseScriptPane::config() const { return m_config; }
Json const& BaseScriptPane::rawConfig() const { return m_rawConfig; } Json const& BaseScriptPane::rawConfig() const { return m_rawConfig; }
bool BaseScriptPane::interactive() const { return m_interactive; }
PanePtr BaseScriptPane::createTooltip(Vec2I const& screenPosition) { PanePtr BaseScriptPane::createTooltip(Vec2I const& screenPosition) {
auto result = m_script.invoke<Json>("createTooltip", screenPosition); auto result = m_script.invoke<Json>("createTooltip", screenPosition);
if (result && !result.value().isNull()) { if (result && !result.value().isNull()) {

View File

@ -29,6 +29,8 @@ public:
Json const& config() const; Json const& config() const;
Json const& rawConfig() const; Json const& rawConfig() const;
bool interactive() const override;
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:
@ -41,6 +43,8 @@ protected:
Map<CanvasWidgetPtr, String> m_canvasClickCallbacks; Map<CanvasWidgetPtr, String> m_canvasClickCallbacks;
Map<CanvasWidgetPtr, String> m_canvasKeyCallbacks; Map<CanvasWidgetPtr, String> m_canvasKeyCallbacks;
bool m_interactive;
bool m_callbacksAdded; bool m_callbacksAdded;
LuaUpdatableComponent<LuaBaseComponent> m_script; LuaUpdatableComponent<LuaBaseComponent> m_script;
}; };

View File

@ -9,7 +9,7 @@
namespace Star { namespace Star {
JoinRequestDialog::JoinRequestDialog() {} JoinRequestDialog::JoinRequestDialog() : m_confirmed(false) {}
void JoinRequestDialog::displayRequest(String const& userName, function<void(P2PJoinRequestReply)> callback) { void JoinRequestDialog::displayRequest(String const& userName, function<void(P2PJoinRequestReply)> callback) {
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();

View File

@ -1565,8 +1565,12 @@ void MainInterface::displayScriptPane(ScriptPanePtr& scriptPane, EntityId source
if (sourceEntity != NullEntityId) if (sourceEntity != NullEntityId)
m_interactionScriptPanes[sourceEntity] = scriptPane; m_interactionScriptPanes[sourceEntity] = scriptPane;
PaneLayer layer = PaneLayer::Window;
if (auto layerName = scriptPane->config().optString("paneLayer"))
layer = PaneLayerNames.getLeft(*layerName);
if (scriptPane->openWithInventory()) { if (scriptPane->openWithInventory()) {
m_paneManager.displayPane(PaneLayer::Window, scriptPane, [this](PanePtr const&) { m_paneManager.displayPane(layer, scriptPane, [this](PanePtr const&) {
if (auto player = m_client->mainPlayer()) if (auto player = m_client->mainPlayer())
player->clearSwap(); player->clearSwap();
m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
@ -1575,7 +1579,7 @@ void MainInterface::displayScriptPane(ScriptPanePtr& scriptPane, EntityId source
m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory),
scriptPane, Root::singleton().assets()->json("/interface.config:bringAdjacentWindowGap").toFloat()); scriptPane, Root::singleton().assets()->json("/interface.config:bringAdjacentWindowGap").toFloat());
} else { } else {
m_paneManager.displayPane(PaneLayer::Window, scriptPane); m_paneManager.displayPane(layer, scriptPane);
} }
} }

View File

@ -6,6 +6,14 @@
namespace Star { namespace Star {
EnumMap<PaneLayer> const PaneLayerNames{
{PaneLayer::Tooltip, "Tooltip"},
{PaneLayer::ModalWindow, "ModalWindow"},
{PaneLayer::Window, "Window"},
{PaneLayer::Hud, "Hud"},
{PaneLayer::World, "World"}
};
PaneManager::PaneManager() PaneManager::PaneManager()
: m_context(GuiContext::singletonPtr()), m_prevInterfaceScale(1) { : m_context(GuiContext::singletonPtr()), m_prevInterfaceScale(1) {
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
@ -350,24 +358,34 @@ Vec2I PaneManager::calculateNewInterfacePosition(PanePtr const& pane, float inte
switch (pane->anchor()) { switch (pane->anchor()) {
case PaneAnchor::None: case PaneAnchor::None:
scale = Mat3F::scaling(interfaceScaleRatio, Vec2F(windowSize()) / 2); scale = Mat3F::scaling(interfaceScaleRatio, Vec2F(windowSize()) / 2);
break;
case PaneAnchor::BottomLeft: case PaneAnchor::BottomLeft:
scale = Mat3F::scaling(interfaceScaleRatio); scale = Mat3F::scaling(interfaceScaleRatio);
break;
case PaneAnchor::BottomRight: case PaneAnchor::BottomRight:
scale = Mat3F::scaling(interfaceScaleRatio, {size[0], 0}); scale = Mat3F::scaling(interfaceScaleRatio, {size[0], 0});
break;
case PaneAnchor::TopLeft: case PaneAnchor::TopLeft:
scale = Mat3F::scaling(interfaceScaleRatio, {0, size[1]}); scale = Mat3F::scaling(interfaceScaleRatio, {0, size[1]});
break;
case PaneAnchor::TopRight: case PaneAnchor::TopRight:
scale = Mat3F::scaling(interfaceScaleRatio, size); scale = Mat3F::scaling(interfaceScaleRatio, size);
break;
case PaneAnchor::CenterTop: case PaneAnchor::CenterTop:
scale = Mat3F::scaling(interfaceScaleRatio, {size[0] / 2, size[1]}); scale = Mat3F::scaling(interfaceScaleRatio, {size[0] / 2, size[1]});
break;
case PaneAnchor::CenterBottom: case PaneAnchor::CenterBottom:
scale = Mat3F::scaling(interfaceScaleRatio, {size[0] / 2, 0}); scale = Mat3F::scaling(interfaceScaleRatio, {size[0] / 2, 0});
break;
case PaneAnchor::CenterLeft: case PaneAnchor::CenterLeft:
scale = Mat3F::scaling(interfaceScaleRatio, {0, size[1] / 2}); scale = Mat3F::scaling(interfaceScaleRatio, {0, size[1] / 2});
break;
case PaneAnchor::CenterRight: case PaneAnchor::CenterRight:
scale = Mat3F::scaling(interfaceScaleRatio, {size[0], size[1] / 2}); scale = Mat3F::scaling(interfaceScaleRatio, {size[0], size[1] / 2});
break;
case PaneAnchor::Center: case PaneAnchor::Center:
scale = Mat3F::scaling(interfaceScaleRatio, size / 2); scale = Mat3F::scaling(interfaceScaleRatio, size / 2);
break;
default: default:
scale = Mat3F::scaling(interfaceScaleRatio, Vec2F(windowSize()) / 2); scale = Mat3F::scaling(interfaceScaleRatio, Vec2F(windowSize()) / 2);
} }

View File

@ -3,6 +3,7 @@
#include "StarPane.hpp" #include "StarPane.hpp"
#include "StarOrderedMap.hpp" #include "StarOrderedMap.hpp"
#include "StarBiMap.hpp"
namespace Star { namespace Star {
@ -25,6 +26,8 @@ enum class PaneLayer {
// handled by GUI panes (such as wires) // handled by GUI panes (such as wires)
World World
}; };
extern EnumMap<PaneLayer> const PaneLayerNames;
// This class handles a set of panes to be drawn as a collective windowing // This class handles a set of panes to be drawn as a collective windowing
// interface. It is a set of panes on separate distinct layers, where each // interface. It is a set of panes on separate distinct layers, where each