diff --git a/assets/voxygen/element/ui/chat/icons/mod_badge.png b/assets/voxygen/element/ui/chat/icons/mod_badge.png new file mode 100644 index 0000000000..7498881d47 --- /dev/null +++ b/assets/voxygen/element/ui/chat/icons/mod_badge.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9ee20a866d4b3a47fbd6ae2a9469797eeb65d1c3adca29c8c1b88c7de19865d +size 394 diff --git a/assets/voxygen/i18n/en/hud/chat.ftl b/assets/voxygen/i18n/en/hud/chat.ftl index 36e860132c..a97baf64df 100644 --- a/assets/voxygen/i18n/en/hud/chat.ftl +++ b/assets/voxygen/i18n/en/hud/chat.ftl @@ -32,7 +32,6 @@ hud-chat-default_death_msg = [{ $name }] died ## Utils hud-chat-all = All hud-chat-you = You -hud-chat-mod = Mod hud-chat-chat_tab_hover_tooltip = Right click for settings hud-loot-pickup-msg = {$actor} picked up { $amount -> [one] { $item } diff --git a/voxygen/i18n-helpers/src/lib.rs b/voxygen/i18n-helpers/src/lib.rs index 9caa7a0ca5..181a0c2e3e 100644 --- a/voxygen/i18n-helpers/src/lib.rs +++ b/voxygen/i18n-helpers/src/lib.rs @@ -213,15 +213,16 @@ pub fn localize_chat_message( fn insert_alias(you: bool, info: PlayerInfo, localisation: &Localization) -> String { const YOU: &str = "hud-chat-you"; - const MOD: &str = "hud-chat-mod"; + // Leave space for a mod badge icon. + const MOD_SPACING: &str = " "; match (info.is_moderator, you) { (false, false) => info.player_alias, (false, true) => localisation.get_msg(YOU).to_string(), - (true, false) => format!("{} - {}", &localisation.get_msg(MOD), info.player_alias), + (true, false) => format!("{}{}", MOD_SPACING, info.player_alias), (true, true) => format!( - "{} - {}", - &localisation.get_msg(MOD), - &localisation.get_msg(YOU) + "{}{}", + MOD_SPACING, + &localisation.get_msg(YOU), ), } } diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 39b340e22e..c7a18b3363 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -31,6 +31,7 @@ widget_ids! { chat_arrow, chat_icon_align, chat_icons[], + chat_badges[], chat_tab_align, chat_tab_all, @@ -440,7 +441,17 @@ impl<'a> Widget for Chat<'a> { true } }) + .map(|m| { + let is_moderator = m.chat_type.uid().and_then(|uid| self.client.lookup_msg_context(&m).player_alias.get(&uid).map(|i| i.is_moderator)).unwrap_or(false); + (is_moderator, m) + }) .collect::>(); + let n_badges = messages.iter().filter(|t| t.0).count(); + if state.ids.chat_badges.len() < n_badges { + state.update(|s| { + s.ids.chat_badges.resize(n_badges, &mut ui.widget_id_generator()) + }) + } Rectangle::fill_with([CHAT_ICON_WIDTH, CHAT_BOX_HEIGHT], color::TRANSPARENT) .top_left_with_margins_on(state.ids.message_box_bg, 0.0, 0.0) .crop_kids() @@ -451,10 +462,11 @@ impl<'a> Widget for Chat<'a> { .scroll_kids_vertically() .set(state.ids.message_box, ui); + let mut badge_id = 0; while let Some(item) = items.next(ui) { // This would be easier if conrod used the v-metrics from rusttype. if item.i < messages.len() { - let message = &messages[item.i]; + let (is_moderator, message) = &messages[item.i]; let (color, icon) = render_chat_line(&message.chat_type, self.imgs); // For each ChatType needing localization get/set matching pre-formatted // localized string. This string will be formatted with the data @@ -473,6 +485,18 @@ impl<'a> Widget for Chat<'a> { _ => 0.0, }; item.set(text.h(y), ui); + + // If the user is a moderator display a moderator icon with their alias. + if *is_moderator { + Image::new(self.imgs.chat_moderator_badge) + .w_h(CHAT_ICON_WIDTH, CHAT_ICON_HEIGHT) + .top_left_with_margins_on(item.widget_id, 2.0, 7.0) + .parent(state.ids.message_box_bg) + .set(state.ids.chat_badges[badge_id], ui); + + badge_id += 1; + } + let icon_id = state.ids.chat_icons[item.i]; Image::new(icon) .w_h(CHAT_ICON_WIDTH, CHAT_ICON_HEIGHT) diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 80a02f5168..cac95e08c1 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -674,6 +674,8 @@ image_ids! { chat_tell: "voxygen.element.ui.chat.icons.tell", chat_world: "voxygen.element.ui.chat.icons.world", + chat_moderator_badge: "voxygen.element.ui.chat.icons.mod_badge", + // Buffs buff_plus_0: "voxygen.element.de_buffs.buff_plus_0", buff_saturation_0: "voxygen.element.de_buffs.buff_saturation_0",