From e64aabfcf1237639fa5d53ed7e02c3a6510f4a0c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 23 Jun 2023 20:24:40 +1000 Subject: [PATCH] add Nametag Directives --- assets/opensb/interface.config.patch | 5 ++++ .../opensb/interface/chat/chat.config.patch | 2 +- source/core/StarJson.cpp | 2 +- source/core/StarJson.hpp | 2 +- source/frontend/StarChatBubbleSeparation.hpp | 12 ++++---- source/frontend/StarMainInterface.cpp | 2 +- source/frontend/StarNameplatePainter.cpp | 28 +++++++++++++------ source/frontend/StarNameplatePainter.hpp | 4 +++ 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/assets/opensb/interface.config.patch b/assets/opensb/interface.config.patch index a6b2856..1048500 100644 --- a/assets/opensb/interface.config.patch +++ b/assets/opensb/interface.config.patch @@ -1,4 +1,9 @@ { + "nametag" : { + "showMasterNames" : true, + "fontDirectives" : "?border=2;444;4440", + "inspectOpacityRate" : 0.15 + }, "font" : { "defaultDirectives" : "", "defaultFont" : "" diff --git a/assets/opensb/interface/chat/chat.config.patch b/assets/opensb/interface/chat/chat.config.patch index db2650d..f8a8caa 100644 --- a/assets/opensb/interface/chat/chat.config.patch +++ b/assets/opensb/interface/chat/chat.config.patch @@ -1,7 +1,7 @@ { "config" : { "font" : { - "directives" : "?border=1;000;0000", + "directives" : "?border=1;333a;3330", "padding" : [1, 1] // Padding to prevent border clipping at the edges of the log canvas while keeping compat with mods that patch the canvas size }, "colors" : { diff --git a/source/core/StarJson.cpp b/source/core/StarJson.cpp index 341a23c..3f65e33 100644 --- a/source/core/StarJson.cpp +++ b/source/core/StarJson.cpp @@ -659,7 +659,7 @@ uint64_t Json::queryUInt(String const& query, uint64_t def) const { return def; } -String Json::queryString(String const& query, String def) const { +String Json::queryString(String const& query, String const& def) const { auto json = JsonPath::pathFind(*this, JsonPath::parseQueryPath, query); if (json && *json) return json->toString(); diff --git a/source/core/StarJson.hpp b/source/core/StarJson.hpp index 6ccc2a4..8c256f4 100644 --- a/source/core/StarJson.hpp +++ b/source/core/StarJson.hpp @@ -201,7 +201,7 @@ public: bool queryBool(String const& path, bool def) const; int64_t queryInt(String const& path, int64_t def) const; uint64_t queryUInt(String const& path, uint64_t def) const; - String queryString(String const& path, String def) const; + String queryString(String const& path, String const& def) const; JsonArray queryArray(String const& path, JsonArray def) const; JsonObject queryObject(String const& path, JsonObject def) const; diff --git a/source/frontend/StarChatBubbleSeparation.hpp b/source/frontend/StarChatBubbleSeparation.hpp index d3a2bdc..88a860c 100644 --- a/source/frontend/StarChatBubbleSeparation.hpp +++ b/source/frontend/StarChatBubbleSeparation.hpp @@ -139,13 +139,11 @@ void BubbleSeparator::forEach(function func) { RectF boundBox = bubble.boundBox.translated(positionDelta); RectF separated = separateBubble(m_sortedLeftEdges, m_sortedRightEdges, boundBox); anyMoved = true; - bubble = Bubble{bubble.contents, - bubble.idealDestination, - bubble.idealDestination, - boundBox, - bubble.idealDestination + separated.min() - boundBox.min(), - separated, - bubble.currentPosition + positionDelta}; + bubble.currentDestination = bubble.idealDestination; + bubble.boundBox = boundBox; + bubble.separatedPosition = bubble.idealDestination + separated.min() - boundBox.min(); + bubble.separatedBox = separated; + bubble.currentPosition += positionDelta; } }); if (anyMoved) diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index 4f40694..6c5dc1d 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -754,6 +754,7 @@ void MainInterface::update() { m_nameplatePainter->update(m_client->worldClient(), m_worldPainter->camera(), m_client->worldClient()->interactiveHighlightMode()); m_questIndicatorPainter->update(m_client->worldClient(), m_worldPainter->camera()); + m_chatBubbleManager->setCamera(m_worldPainter->camera()); if (auto worldClient = m_client->worldClient()) { auto chatActions = worldClient->pullPendingChatActions(); auto portraitActions = chatActions.filtered([](ChatAction action) { return action.is(); }); @@ -778,7 +779,6 @@ void MainInterface::update() { m_chatBubbleManager->addChatActions(chatActions); m_chatBubbleManager->update(worldClient); } - m_chatBubbleManager->setCamera(m_worldPainter->camera()); if (auto container = m_client->worldClient()->get(m_containerInteractor->openContainerId())) { if (!m_client->worldClient()->playerCanReachEntity(container->entityId()) diff --git a/source/frontend/StarNameplatePainter.cpp b/source/frontend/StarNameplatePainter.cpp index 1259cea..ef472d4 100644 --- a/source/frontend/StarNameplatePainter.cpp +++ b/source/frontend/StarNameplatePainter.cpp @@ -11,12 +11,16 @@ NameplatePainter::NameplatePainter() { auto assets = Root::singleton().assets(); Json nametagConfig = assets->json("/interface.config:nametag"); + m_showMasterNames = nametagConfig.getBool("showMasterNames"); m_opacityRate = nametagConfig.getFloat("opacityRate"); + m_inspectOpacityRate = nametagConfig.queryFloat("inspectOpacityRate", m_opacityRate); m_offset = jsonToVec2F(nametagConfig.get("offset")); - m_font = nametagConfig.optString("font").value(""); - m_statusFont = nametagConfig.optString("font").value(m_font); + m_font = nametagConfig.queryString("font", ""); + m_fontDirectives = nametagConfig.queryString("fontDirectives", ""); m_fontSize = nametagConfig.getFloat("fontSize"); - m_statusFontSize = nametagConfig.getFloat("statusFontSize"); + m_statusFont = nametagConfig.queryString("font", m_font); + m_statusFontDirectives = nametagConfig.queryString("fontDirectives", m_fontDirectives); + m_statusFontSize = nametagConfig.queryFloat("statusFontSize", m_fontSize); m_statusOffset = jsonToVec2F(nametagConfig.get("statusOffset")); m_statusColor = jsonToColor(nametagConfig.get("statusColor")); m_opacityBoost = nametagConfig.getFloat("opacityBoost"); @@ -29,7 +33,7 @@ void NameplatePainter::update(WorldClientPtr const& world, WorldCamera const& ca Set foundEntities; for (auto const& entity : world->query(camera.worldScreenRect())) { - if (entity->isMaster() || !entity->displayNametag()) + if ((entity->isMaster() && !m_showMasterNames) || !entity->displayNametag()) continue; if (auto player = as(entity)) { if (player->isTeleporting()) @@ -57,7 +61,7 @@ void NameplatePainter::update(WorldClientPtr const& world, WorldCamera const& ca nametag.color = entity->nametagColor(); bool fullyOnScreen = world->geometry().rectContains(camera.worldScreenRect(), entity->position()); if (inspectionMode) - nametag.opacity = 1.0f; + nametag.opacity = approach(1.0f, nametag.opacity, m_inspectOpacityRate); else if (fullyOnScreen) nametag.opacity = approach(0.0f, nametag.opacity, m_opacityRate); else @@ -77,21 +81,25 @@ void NameplatePainter::render() { return; context.setFont(m_font); + context.setFontProcessingDirectives(m_fontDirectives); context.setFontSize(m_fontSize); auto color = Color::rgb(nametag.color); color.setAlphaF(nametag.opacity); - auto statusColor = m_statusColor; - statusColor.setAlphaF(nametag.opacity); context.setFontColor(color.toRgba()); context.setFontMode(FontMode::Shadow); context.renderText(nametag.name, namePosition(bubble.currentPosition)); if (nametag.statusText) { - context.setFontSize(m_statusFontSize); - context.setFont(m_statusFont); + auto statusColor = m_statusColor; + statusColor.setAlphaF(nametag.opacity); context.setFontColor(statusColor.toRgba()); + + context.setFontSize(m_statusFontSize); + context.setFontProcessingDirectives(m_statusFontDirectives); + context.setFont(m_statusFont); + context.renderText(*nametag.statusText, statusPosition(bubble.currentPosition)); } }); @@ -111,10 +119,12 @@ TextPositioning NameplatePainter::statusPosition(Vec2F bubblePosition) const { RectF NameplatePainter::determineBoundBox(Vec2F bubblePosition, Nametag const& nametag) const { auto& context = GuiContext::singleton(); context.setFontSize(m_fontSize); + context.setFontProcessingDirectives(m_fontDirectives); context.setFont(m_font); RectF nametagBox = context.determineTextSize(nametag.name, namePosition(bubblePosition)); if (nametag.statusText) { context.setFontSize(m_statusFontSize); + context.setFontProcessingDirectives(m_statusFontDirectives); context.setFont(m_statusFont); nametagBox.combine(context.determineTextSize(*nametag.statusText, statusPosition(bubblePosition))); } diff --git a/source/frontend/StarNameplatePainter.hpp b/source/frontend/StarNameplatePainter.hpp index 51af619..08c7827 100644 --- a/source/frontend/StarNameplatePainter.hpp +++ b/source/frontend/StarNameplatePainter.hpp @@ -31,10 +31,14 @@ private: TextPositioning statusPosition(Vec2F bubblePosition) const; RectF determineBoundBox(Vec2F bubblePosition, Nametag const& nametag) const; + bool m_showMasterNames; float m_opacityRate; + float m_inspectOpacityRate; Vec2F m_offset; String m_font; String m_statusFont; + String m_fontDirectives; + String m_statusFontDirectives; float m_fontSize; float m_statusFontSize; Vec2F m_statusOffset;