Inspecting now logs to the chat

TODO: make configurable!
This commit is contained in:
Kae 2024-06-17 20:31:40 +10:00
parent f7d2303fe0
commit 39a6e900a4
8 changed files with 35 additions and 22 deletions

View File

Before

Width:  |  Height:  |  Size: 145 B

After

Width:  |  Height:  |  Size: 145 B

View File

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 178 B

View File

Before

Width:  |  Height:  |  Size: 174 B

After

Width:  |  Height:  |  Size: 174 B

View File

@ -760,10 +760,10 @@ 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>();
for (auto& action : chatActions) {
if (action.is<PortraitChatAction>()) {
PortraitChatAction& portraitAction = action.get<PortraitChatAction>();
String name;
if (auto npc = as<Npc>(worldClient->entity(portraitAction.entity)))
@ -774,9 +774,16 @@ void MainInterface::update(float dt) {
ServerConnectionId,
Text::stripEscapeCodes(name),
Text::stripEscapeCodes(portraitAction.text),
Text::stripEscapeCodes(portraitAction.portrait.replace("<frame>", "0"))
};
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);

View File

@ -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 {

View File

@ -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) {

View File

@ -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;

View File

@ -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;