From 39a6e900a4e5d000b975bfd2f24846489eb1aa82 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:31:40 +1000 Subject: [PATCH] Inspecting now logs to the chat TODO: make configurable! --- .../opensb/rendering/{ => sprites}/error.png | Bin .../rendering/{ => sprites}/error_left.png | Bin .../rendering/{ => sprites}/error_right.png | Bin source/frontend/StarMainInterface.cpp | 35 +++++++++++------- source/game/StarChatTypes.cpp | 2 +- source/game/StarPlayer.cpp | 16 +++++--- source/game/StarPlayer.hpp | 2 +- source/game/StarWorldClient.cpp | 2 +- 8 files changed, 35 insertions(+), 22 deletions(-) rename assets/opensb/rendering/{ => sprites}/error.png (100%) rename assets/opensb/rendering/{ => sprites}/error_left.png (100%) rename assets/opensb/rendering/{ => sprites}/error_right.png (100%) diff --git a/assets/opensb/rendering/error.png b/assets/opensb/rendering/sprites/error.png similarity index 100% rename from assets/opensb/rendering/error.png rename to assets/opensb/rendering/sprites/error.png diff --git a/assets/opensb/rendering/error_left.png b/assets/opensb/rendering/sprites/error_left.png similarity index 100% rename from assets/opensb/rendering/error_left.png rename to assets/opensb/rendering/sprites/error_left.png diff --git a/assets/opensb/rendering/error_right.png b/assets/opensb/rendering/sprites/error_right.png similarity index 100% rename from assets/opensb/rendering/error_right.png rename to assets/opensb/rendering/sprites/error_right.png diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index f9e8d57..153ce07 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -760,23 +760,30 @@ void MainInterface::update(float dt) { 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(); }); - for (auto action : portraitActions) { - PortraitChatAction portraitAction = action.get(); + for (auto& action : chatActions) { + if (action.is()) { + PortraitChatAction& portraitAction = action.get(); - String name; - if (auto npc = as(worldClient->entity(portraitAction.entity))) - name = npc->name(); + String name; + if (auto npc = as(worldClient->entity(portraitAction.entity))) + name = npc->name(); - ChatReceivedMessage message = { - { MessageContext::World }, - ServerConnectionId, - Text::stripEscapeCodes(name), - Text::stripEscapeCodes(portraitAction.text), - Text::stripEscapeCodes(portraitAction.portrait.replace("", "0")) - }; - m_chat->addMessages({message}, false); + ChatReceivedMessage message = { + {MessageContext::World}, + ServerConnectionId, + Text::stripEscapeCodes(name), + Text::stripEscapeCodes(portraitAction.text), + Text::stripEscapeCodes(portraitAction.portrait.replace("", "0"))}; + m_chat->addMessages({message}, false); + } else if (action.is()) { + SayChatAction& sayAction = action.get(); + + if (sayAction.config) { + if (auto message = sayAction.config.opt("message")) + m_chat->addMessages({ChatReceivedMessage(*message)}, sayAction.config.getBool("showPane", false)); + } + } } m_chatBubbleManager->addChatActions(chatActions); diff --git a/source/game/StarChatTypes.cpp b/source/game/StarChatTypes.cpp index a717be3..79dfc4f 100644 --- a/source/game/StarChatTypes.cpp +++ b/source/game/StarChatTypes.cpp @@ -55,7 +55,7 @@ ChatReceivedMessage::ChatReceivedMessage(Json const& json) : ChatReceivedMessage fromConnection = json.getUInt("fromConnection", 0); fromNick = json.getString("fromNick", ""); portrait = json.getString("portrait", ""); - text = json.getString("text"); + text = json.getString("text", ""); } Json ChatReceivedMessage::toJson() const { diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 8b15254..94ed991 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -976,15 +976,21 @@ void Player::update(float dt, uint64_t) { }); } - for (auto tool : {m_tools->primaryHandItem(), m_tools->altHandItem()}) { + for (auto& tool : {m_tools->primaryHandItem(), m_tools->altHandItem()}) { if (auto inspectionTool = as(tool)) { - for (auto ir : inspectionTool->pullInspectionResults()) { + for (auto& ir : inspectionTool->pullInspectionResults()) { if (ir.objectName) { m_questManager->receiveMessage("objectScanned", true, {*ir.objectName, *ir.entityId}); m_log->addScannedObject(*ir.objectName); } - addChatMessage(ir.message); + addChatMessage(ir.message, JsonObject{ + {"message", JsonObject{ + {"context", JsonObject{{"mode", "RadioMessage"}}}, + {"fromConnection", world()->connection()}, + {"text", ir.message} + }} + }); } } } @@ -2178,12 +2184,12 @@ void Player::queueItemPickupMessage(ItemPtr const& item) { m_queuedItemPickups.append(item); } -void Player::addChatMessage(String const& message) { +void Player::addChatMessage(String const& message, Json const& config) { starAssert(!isSlave()); m_chatMessage = message; m_chatMessageUpdated = true; m_chatMessageChanged = true; - m_pendingChatActions.append(SayChatAction{entityId(), message, mouthPosition()}); + m_pendingChatActions.append(SayChatAction{entityId(), message, mouthPosition(), config}); } void Player::addEmote(HumanoidEmote const& emote, Maybe emoteCooldown) { diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp index fb32005..d6750a5 100644 --- a/source/game/StarPlayer.hpp +++ b/source/game/StarPlayer.hpp @@ -381,7 +381,7 @@ public: void queueUIMessage(String const& message) override; void queueItemPickupMessage(ItemPtr const& item); - void addChatMessage(String const& message); + void addChatMessage(String const& message, Json const& config = {}); void addEmote(HumanoidEmote const& emote, Maybe emoteCooldown = {}); pair currentEmote() const; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index ef5daa2..aa6f293 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -496,7 +496,7 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) { else { // this is THEIR problem!! Logger::error("WorldClient: Exception caught in {}::render ({}): {}", EntityTypeNames.getRight(entity->entityType()), entity->entityId(), e.what()); auto toolUser = as(entity); - String image = toolUser ? strf("/rendering/error_{}.png", DirectionNames.getRight(toolUser->facingDirection())) : "/rendering/error.png"; + String image = toolUser ? strf("/rendering/sprites/error_{}.png", DirectionNames.getRight(toolUser->facingDirection())) : "/rendering/sprites/error.png"; Color color = Color::rgbf(0.8f + (float)sin(m_currentTime * Constants::pi * 2.0) * 0.2f, 0.0f, 0.0f); auto drawable = Drawable::makeImage(image, 1.0f / TilePixels, true, entity->position(), color); drawable.fullbright = true;