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

@ -24,7 +24,8 @@ BaseScriptPane::BaseScriptPane(Json config) : Pane(), m_rawConfig(config) {
} else {
m_config = assets->fetchJson(config);
}
m_interactive = config.getBool("interactive", true);
m_reader = make_shared<GuiReader>();
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::rawConfig() const { return m_rawConfig; }
bool BaseScriptPane::interactive() const { return m_interactive; }
PanePtr BaseScriptPane::createTooltip(Vec2I const& screenPosition) {
auto result = m_script.invoke<Json>("createTooltip", screenPosition);
if (result && !result.value().isNull()) {

View File

@ -29,6 +29,8 @@ public:
Json const& config() const;
Json const& rawConfig() const;
bool interactive() const override;
PanePtr createTooltip(Vec2I const& screenPosition) override;
Maybe<String> cursorOverride(Vec2I const& screenPosition) override;
protected:
@ -41,6 +43,8 @@ protected:
Map<CanvasWidgetPtr, String> m_canvasClickCallbacks;
Map<CanvasWidgetPtr, String> m_canvasKeyCallbacks;
bool m_interactive;
bool m_callbacksAdded;
LuaUpdatableComponent<LuaBaseComponent> m_script;
};

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@
#include "StarPane.hpp"
#include "StarOrderedMap.hpp"
#include "StarBiMap.hpp"
namespace Star {
@ -25,6 +26,8 @@ enum class PaneLayer {
// handled by GUI panes (such as wires)
World
};
extern EnumMap<PaneLayer> const PaneLayerNames;
// 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