Moderator badge

This commit is contained in:
Isse 2023-01-28 02:45:05 +01:00
parent 0543c265c8
commit d949348661
5 changed files with 36 additions and 7 deletions

BIN
assets/voxygen/element/ui/chat/icons/mod_badge.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -32,7 +32,6 @@ hud-chat-default_death_msg = [{ $name }] died
## Utils ## Utils
hud-chat-all = All hud-chat-all = All
hud-chat-you = You hud-chat-you = You
hud-chat-mod = Mod
hud-chat-chat_tab_hover_tooltip = Right click for settings hud-chat-chat_tab_hover_tooltip = Right click for settings
hud-loot-pickup-msg = {$actor} picked up { $amount -> hud-loot-pickup-msg = {$actor} picked up { $amount ->
[one] { $item } [one] { $item }

View File

@ -213,15 +213,16 @@ pub fn localize_chat_message(
fn insert_alias(you: bool, info: PlayerInfo, localisation: &Localization) -> String { fn insert_alias(you: bool, info: PlayerInfo, localisation: &Localization) -> String {
const YOU: &str = "hud-chat-you"; 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) { match (info.is_moderator, you) {
(false, false) => info.player_alias, (false, false) => info.player_alias,
(false, true) => localisation.get_msg(YOU).to_string(), (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!( (true, true) => format!(
"{} - {}", "{}{}",
&localisation.get_msg(MOD), MOD_SPACING,
&localisation.get_msg(YOU) &localisation.get_msg(YOU),
), ),
} }
} }

View File

@ -31,6 +31,7 @@ widget_ids! {
chat_arrow, chat_arrow,
chat_icon_align, chat_icon_align,
chat_icons[], chat_icons[],
chat_badges[],
chat_tab_align, chat_tab_align,
chat_tab_all, chat_tab_all,
@ -440,7 +441,17 @@ impl<'a> Widget for Chat<'a> {
true 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::<Vec<_>>(); .collect::<Vec<_>>();
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) 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) .top_left_with_margins_on(state.ids.message_box_bg, 0.0, 0.0)
.crop_kids() .crop_kids()
@ -451,10 +462,11 @@ impl<'a> Widget for Chat<'a> {
.scroll_kids_vertically() .scroll_kids_vertically()
.set(state.ids.message_box, ui); .set(state.ids.message_box, ui);
let mut badge_id = 0;
while let Some(item) = items.next(ui) { while let Some(item) = items.next(ui) {
// This would be easier if conrod used the v-metrics from rusttype. // This would be easier if conrod used the v-metrics from rusttype.
if item.i < messages.len() { 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); let (color, icon) = render_chat_line(&message.chat_type, self.imgs);
// For each ChatType needing localization get/set matching pre-formatted // For each ChatType needing localization get/set matching pre-formatted
// localized string. This string will be formatted with the data // localized string. This string will be formatted with the data
@ -473,6 +485,18 @@ impl<'a> Widget for Chat<'a> {
_ => 0.0, _ => 0.0,
}; };
item.set(text.h(y), ui); 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]; let icon_id = state.ids.chat_icons[item.i];
Image::new(icon) Image::new(icon)
.w_h(CHAT_ICON_WIDTH, CHAT_ICON_HEIGHT) .w_h(CHAT_ICON_WIDTH, CHAT_ICON_HEIGHT)

View File

@ -674,6 +674,8 @@ image_ids! {
chat_tell: "voxygen.element.ui.chat.icons.tell", chat_tell: "voxygen.element.ui.chat.icons.tell",
chat_world: "voxygen.element.ui.chat.icons.world", chat_world: "voxygen.element.ui.chat.icons.world",
chat_moderator_badge: "voxygen.element.ui.chat.icons.mod_badge",
// Buffs // Buffs
buff_plus_0: "voxygen.element.de_buffs.buff_plus_0", buff_plus_0: "voxygen.element.de_buffs.buff_plus_0",
buff_saturation_0: "voxygen.element.de_buffs.buff_saturation_0", buff_saturation_0: "voxygen.element.de_buffs.buff_saturation_0",