use crate::hud::ChatTab;
use common::{
comp::{ChatMsg, ChatType},
uid::Uid,
};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
pub const MAX_CHAT_TABS: usize = 5;
pub const DEFAULT_CHAT_BOX_WIDTH: f64 = 470.0;
pub const DEFAULT_CHAT_BOX_HEIGHT: f64 = 150.0;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct ChatFilter {
pub message_all: bool,
pub message_world: bool,
pub message_region: bool,
pub message_say: bool,
pub message_group: bool,
pub message_faction: bool,
pub activity_all: bool,
pub activity_group: bool,
pub death_all: bool,
pub death_group: bool,
}
impl ChatFilter {
pub fn satisfies(&self, chat_msg: &ChatMsg, group_members: &HashSet<&Uid>) -> bool {
match &chat_msg.chat_type {
ChatType::Online(u) | ChatType::Offline(u) => {
self.activity_all || (self.activity_group && group_members.contains(u))
},
ChatType::CommandInfo | ChatType::CommandError => true,
ChatType::Kill(_, u) => self.death_all || self.death_group && group_members.contains(u),
ChatType::GroupMeta(_) => true, ChatType::FactionMeta(_) => true, ChatType::Tell(..) => true,
ChatType::Say(_) => self.message_all || self.message_say,
ChatType::Group(..) => self.message_all || self.message_group,
ChatType::Faction(..) => self.message_all || self.message_faction,
ChatType::Region(_) => self.message_all || self.message_region,
ChatType::World(_) => self.message_all || self.message_world,
ChatType::Npc(..) => true,
ChatType::NpcSay(..) => true,
ChatType::NpcTell(..) => true,
ChatType::Meta => true,
}
}
}
impl Default for ChatFilter {
fn default() -> Self {
Self {
message_all: true,
message_world: true,
message_region: true,
message_say: true,
message_group: true,
message_faction: true,
activity_all: false,
activity_group: true,
death_all: false,
death_group: true,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct ChatSettings {
pub chat_opacity: f32,
pub chat_character_name: bool,
pub chat_tabs: Vec<ChatTab>,
pub chat_tab_index: Option<usize>,
pub chat_cmd_prefix: char,
pub chat_pos_x: f64,
pub chat_pos_y: f64,
pub chat_size_x: f64,
pub chat_size_y: f64,
}
impl Default for ChatSettings {
fn default() -> Self {
Self {
chat_opacity: 0.4,
chat_character_name: true,
chat_tabs: vec![ChatTab::default()],
chat_tab_index: Some(0),
chat_cmd_prefix: '/',
chat_pos_x: 10.0,
chat_pos_y: 10.0,
chat_size_x: DEFAULT_CHAT_BOX_WIDTH,
chat_size_y: DEFAULT_CHAT_BOX_HEIGHT,
}
}
}