From bac0ba468f34b8c35d2932d71cce83965419607f Mon Sep 17 00:00:00 2001 From: ubruntu Date: Sun, 11 Jul 2021 18:27:34 +0000 Subject: [PATCH] Replace "Player 1" with an NPC name when trading with an NPC --- voxygen/src/hud/trade.rs | 11 +++++++++-- voxygen/src/session/mod.rs | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index 3d48fdf92e..d12a78c75c 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -17,7 +17,7 @@ use client::Client; use common::{ comp::{ inventory::item::{MaterialStatManifest, Quality}, - Inventory, + Inventory, Stats, }, trade::{PendingTrade, SitePrices, TradeAction, TradePhase}, }; @@ -169,7 +169,7 @@ impl<'a> Trade<'a> { (x, is_ours) if ours == is_ours => x, _ => check_if_us(1)?.0, }; - // TODO: update in accordence with https://gitlab.com/veloren/veloren/-/issues/960 + // TODO: update in accordance with https://gitlab.com/veloren/veloren/-/issues/960 let inventory = inventories.get(entity)?; // Alignment for Grid @@ -188,6 +188,13 @@ impl<'a> Trade<'a> { .player_list() .get(&uid) .map(|info| info.player_alias.clone()) + .or_else(|| { + self.client + .state() + .read_storage::() + .get(entity) + .map(|e| e.name.to_owned()) + }) .unwrap_or_else(|| format!("Player {}", who)); let offer_header = self diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index b2f835909a..44c35839da 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -15,7 +15,7 @@ use common::{ inventory::slot::{EquipSlot, Slot}, invite::InviteKind, item::{tool::ToolKind, ItemDef, ItemDesc}, - ChatMsg, ChatType, InputKind, InventoryUpdateEvent, Pos, UtteranceKind, Vel, + ChatMsg, ChatType, InputKind, InventoryUpdateEvent, Pos, Stats, UtteranceKind, Vel, }, consts::{MAX_MOUNT_RANGE, MAX_PICKUP_RANGE}, outcome::Outcome, @@ -164,7 +164,15 @@ impl SessionState { }; let target_name = match client.player_list().get(&target) { Some(info) => info.player_alias.clone(), - None => format!("", target), + None => match client.state().ecs().entity_from_uid(target.0) { + Some(entity) => { + let stats = client.state().read_storage::(); + stats + .get(entity) + .map_or(format!("", target), |e| e.name.to_owned()) + }, + None => format!("", target), + }, }; let answer_str = match answer { InviteAnswer::Accepted => "accepted", @@ -698,7 +706,13 @@ impl PlayState for SessionState { .get(&uid) .map(|info| info.player_alias.clone()) .unwrap_or_else(|| { - format!("", uid) + let stats = client + .state() + .read_storage::(); + stats.get(entity).map_or( + format!("", uid), + |e| e.name.to_owned(), + ) }); let msg = global_state .i18n