diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-06-17 20:31:40 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-06-17 20:31:40 +1000 |
commit | 39a6e900a4e5d000b975bfd2f24846489eb1aa82 (patch) | |
tree | 652aa5522bef39b85e961a0ea843c238b8787be6 | |
parent | f7d2303fe0b6ca1198c23af7b8e1c809d803d142 (diff) |
Inspecting now logs to the chat
TODO: make configurable!
-rw-r--r-- | assets/opensb/rendering/sprites/error.png (renamed from assets/opensb/rendering/error.png) | bin | 145 -> 145 bytes | |||
-rw-r--r-- | assets/opensb/rendering/sprites/error_left.png (renamed from assets/opensb/rendering/error_left.png) | bin | 178 -> 178 bytes | |||
-rw-r--r-- | assets/opensb/rendering/sprites/error_right.png (renamed from assets/opensb/rendering/error_right.png) | bin | 174 -> 174 bytes | |||
-rw-r--r-- | source/frontend/StarMainInterface.cpp | 41 | ||||
-rw-r--r-- | source/game/StarChatTypes.cpp | 2 | ||||
-rw-r--r-- | source/game/StarPlayer.cpp | 16 | ||||
-rw-r--r-- | source/game/StarPlayer.hpp | 2 | ||||
-rw-r--r-- | source/game/StarWorldClient.cpp | 2 |
8 files changed, 38 insertions, 25 deletions
diff --git a/assets/opensb/rendering/error.png b/assets/opensb/rendering/sprites/error.png Binary files differindex b5bd3e7..b5bd3e7 100644 --- a/assets/opensb/rendering/error.png +++ b/assets/opensb/rendering/sprites/error.png diff --git a/assets/opensb/rendering/error_left.png b/assets/opensb/rendering/sprites/error_left.png Binary files differindex 2f4ec6f..2f4ec6f 100644 --- a/assets/opensb/rendering/error_left.png +++ b/assets/opensb/rendering/sprites/error_left.png diff --git a/assets/opensb/rendering/error_right.png b/assets/opensb/rendering/sprites/error_right.png Binary files differindex 1fadd17..1fadd17 100644 --- a/assets/opensb/rendering/error_right.png +++ b/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<PortraitChatAction>(); }); - - for (auto action : portraitActions) { - PortraitChatAction portraitAction = action.get<PortraitChatAction>(); - - String name; - if (auto npc = as<Npc>(worldClient->entity(portraitAction.entity))) - name = npc->name(); - - ChatReceivedMessage message = { - { MessageContext::World }, - ServerConnectionId, - Text::stripEscapeCodes(name), - Text::stripEscapeCodes(portraitAction.text), - Text::stripEscapeCodes(portraitAction.portrait.replace("<frame>", "0")) - }; - m_chat->addMessages({message}, false); + + for (auto& action : chatActions) { + if (action.is<PortraitChatAction>()) { + PortraitChatAction& portraitAction = action.get<PortraitChatAction>(); + + String name; + if (auto npc = as<Npc>(worldClient->entity(portraitAction.entity))) + name = npc->name(); + + ChatReceivedMessage message = { + {MessageContext::World}, + ServerConnectionId, + Text::stripEscapeCodes(name), + Text::stripEscapeCodes(portraitAction.text), + Text::stripEscapeCodes(portraitAction.portrait.replace("<frame>", "0"))}; + m_chat->addMessages({message}, false); + } else if (action.is<SayChatAction>()) { + SayChatAction& sayAction = action.get<SayChatAction>(); + + 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<InspectionTool>(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<float> 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<float> emoteCooldown = {}); pair<HumanoidEmote, float> 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<ToolUserEntity>(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; |