diff --git a/common/src/comp/chat.rs b/common/src/comp/chat.rs index 420f46bdea..383de9e0fa 100644 --- a/common/src/comp/chat.rs +++ b/common/src/comp/chat.rs @@ -103,18 +103,18 @@ impl ChatMsg { } } - pub fn icon(&self) -> SpeechBubbleIcon { + pub fn icon(&self) -> SpeechBubbleType { match &self.chat_type { - ChatType::Broadcast => SpeechBubbleIcon::None, - ChatType::Private => SpeechBubbleIcon::None, - ChatType::Kill => SpeechBubbleIcon::None, - ChatType::Tell(_u, _) => SpeechBubbleIcon::Tell, - ChatType::Say(_u) => SpeechBubbleIcon::Say, - ChatType::Group(_u, _s) => SpeechBubbleIcon::Group, - ChatType::Faction(_u, _s) => SpeechBubbleIcon::Faction, - ChatType::Region(_u) => SpeechBubbleIcon::Region, - ChatType::World(_u) => SpeechBubbleIcon::World, - ChatType::Npc(_u, _r) => SpeechBubbleIcon::None, + ChatType::Broadcast => SpeechBubbleType::None, + ChatType::Private => SpeechBubbleType::None, + ChatType::Kill => SpeechBubbleType::None, + ChatType::Tell(_u, _) => SpeechBubbleType::None, + ChatType::Say(_u) => SpeechBubbleType::None, + ChatType::Group(_u, _s) => SpeechBubbleType::None, + ChatType::Faction(_u, _s) => SpeechBubbleType::None, + ChatType::Region(_u) => SpeechBubbleType::None, + ChatType::World(_u) => SpeechBubbleType::None, + ChatType::Npc(_u, _r) => SpeechBubbleType::None, } } @@ -169,7 +169,7 @@ pub enum SpeechBubbleMessage { Localized(String, u16), } -pub enum SpeechBubbleIcon { +pub enum SpeechBubbleType { // One for each chat mode Tell, Say, @@ -186,7 +186,7 @@ pub enum SpeechBubbleIcon { /// Adds a speech bubble above the character pub struct SpeechBubble { pub message: SpeechBubbleMessage, - pub icon: SpeechBubbleIcon, + pub icon: SpeechBubbleType, pub timeout: Instant, } @@ -194,7 +194,7 @@ impl SpeechBubble { /// Default duration in seconds of speech bubbles pub const DEFAULT_DURATION: f64 = 5.0; - pub fn npc_new(i18n_key: &str, r: u16, icon: SpeechBubbleIcon) -> Self { + pub fn npc_new(i18n_key: &str, r: u16, icon: SpeechBubbleType) -> Self { let message = SpeechBubbleMessage::Localized(i18n_key.to_string(), r); let timeout = Instant::now() + Duration::from_secs_f64(SpeechBubble::DEFAULT_DURATION); Self { @@ -204,7 +204,7 @@ impl SpeechBubble { } } - pub fn player_new(message: &str, icon: SpeechBubbleIcon) -> Self { + pub fn player_new(message: &str, icon: SpeechBubbleType) -> Self { let message = SpeechBubbleMessage::Plain(message.to_string()); let timeout = Instant::now() + Duration::from_secs_f64(SpeechBubble::DEFAULT_DURATION); Self { diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index b560cfa039..2cb45d8d84 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -25,7 +25,7 @@ pub use body::{ humanoid, object, quadruped_medium, quadruped_small, AllBodies, Body, BodyData, }; pub use character_state::{Attacking, CharacterState, StateUpdate}; -pub use chat::{ChatMode, ChatMsg, ChatType, Faction, Group, SpeechBubble, SpeechBubbleIcon}; +pub use chat::{ChatMode, ChatMsg, ChatType, Faction, Group, SpeechBubble, SpeechBubbleType}; pub use controller::{ Climb, ControlAction, ControlEvent, Controller, ControllerInputs, Input, InventoryManip, MountState, Mounting, diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 747e5545eb..d47596a61e 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -47,7 +47,10 @@ use crate::{ GlobalState, }; use client::Client; -use common::{assets::load_expect, comp, sync::Uid, terrain::TerrainChunk, vol::RectRasterableVol}; +use common::{ + assets::load_expect, comp, comp::SpeechBubbleType, sync::Uid, terrain::TerrainChunk, + vol::RectRasterableVol, +}; use conrod_core::{ text::cursor::Index, widget::{self, Button, Image, Text}, @@ -469,6 +472,7 @@ pub struct Hud { new_messages: VecDeque, new_notifications: VecDeque, speech_bubbles: HashMap, + bubble_type: SpeechBubbleType, show: Show, //never_show: bool, //intro: bool, @@ -536,6 +540,7 @@ impl Hud { new_messages: VecDeque::new(), new_notifications: VecDeque::new(), speech_bubbles: HashMap::new(), + bubble_type: SpeechBubbleType::None, //intro: false, //intro_2: false, show: Show { @@ -1015,6 +1020,7 @@ impl Hud { overhead::Overhead::new( &name, bubble, + &self.bubble_type, stats, energy, own_level, diff --git a/voxygen/src/hud/overhead.rs b/voxygen/src/hud/overhead.rs index 5dbb1c8b33..cd6c11e28c 100644 --- a/voxygen/src/hud/overhead.rs +++ b/voxygen/src/hud/overhead.rs @@ -1,10 +1,13 @@ -use super::{img_ids::Imgs, HP_COLOR, LOW_HP_COLOR, MANA_COLOR}; +use super::{ + img_ids::Imgs, FACTION_COLOR, GROUP_COLOR, HP_COLOR, LOW_HP_COLOR, MANA_COLOR, SAY_COLOR, + TELL_COLOR, TEXT_BG, TEXT_COLOR, +}; use crate::{ i18n::VoxygenLocalization, settings::GameplaySettings, ui::{fonts::ConrodVoxygenFonts, Ingameable}, }; -use common::comp::{Energy, SpeechBubble, SpeechBubbleIcon, Stats}; +use common::comp::{Energy, SpeechBubble, SpeechBubbleType, Stats}; use conrod_core::{ position::Align, widget::{self, Image, Rectangle, Text}, @@ -56,6 +59,7 @@ pub struct Overhead<'a> { voxygen_i18n: &'a std::sync::Arc, imgs: &'a Imgs, fonts: &'a ConrodVoxygenFonts, + bubble_type: &SpeechBubbleType, #[conrod(common_builder)] common: widget::CommonBuilder, } @@ -65,6 +69,7 @@ impl<'a> Overhead<'a> { pub fn new( name: &'a str, bubble: Option<&'a SpeechBubble>, + bubble_type: &'a SpeechBubbleType, stats: &'a Stats, energy: &'a Energy, own_level: u32, @@ -77,6 +82,7 @@ impl<'a> Overhead<'a> { Self { name, bubble, + bubble_type, stats, energy, own_level, @@ -150,17 +156,25 @@ impl<'a> Widget for Overhead<'a> { let localizer = |s: &str, i| -> String { self.voxygen_i18n.get_variation(&s, i).to_string() }; let bubble_contents: String = bubble.message(localizer); - let mut text = Text::new(&bubble_contents) .font_id(self.fonts.cyri.conrod_id) .font_size(18) .up_from(state.ids.name, 20.0) .x_align_to(state.ids.name, Align::Middle) .parent(id); - text = if dark_mode { - text.color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) - } else { - text.color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) + + text = match self.bubble_type { + SpeechBubbleType::Tell => text.color(TELL_COLOR), + SpeechBubbleType::Say => text.color(SAY_COLOR), + SpeechBubbleType::Group => text.color(GROUP_COLOR), + SpeechBubbleType::Faction => text.color(FACTION_COLOR), + _ => { + if dark_mode { + text.color(TEXT_COLOR) + } else { + text.color(TEXT_BG) + } + }, }; if let Some(w) = text.get_w(ui) { if w > 250.0 { @@ -371,14 +385,14 @@ impl<'a> Widget for Overhead<'a> { fn bubble_icon(sb: &SpeechBubble, imgs: &Imgs) -> conrod_core::image::Id { match sb.icon { // One for each chat mode - SpeechBubbleIcon::Tell => imgs.chat_tell_small, - SpeechBubbleIcon::Say => imgs.chat_say_small, - SpeechBubbleIcon::Region => imgs.chat_region_small, - SpeechBubbleIcon::Group => imgs.chat_group_small, - SpeechBubbleIcon::Faction => imgs.chat_faction_small, - SpeechBubbleIcon::World => imgs.chat_world_small, - SpeechBubbleIcon::Quest => imgs.nothing, // TODO not implemented - SpeechBubbleIcon::Trade => imgs.nothing, // TODO not implemented - SpeechBubbleIcon::None => imgs.nothing, // No icon (default for npcs) + SpeechBubbleType::Tell => imgs.chat_tell_small, + SpeechBubbleType::Say => imgs.chat_say_small, + SpeechBubbleType::Region => imgs.chat_region_small, + SpeechBubbleType::Group => imgs.chat_group_small, + SpeechBubbleType::Faction => imgs.chat_faction_small, + SpeechBubbleType::World => imgs.chat_world_small, + SpeechBubbleType::Quest => imgs.nothing, // TODO not implemented + SpeechBubbleType::Trade => imgs.nothing, // TODO not implemented + SpeechBubbleType::None => imgs.nothing, // No icon (default for npcs) } }