veloren_voxygen/settings/
chat.rs

1use crate::hud::ChatTab;
2use common::{
3    comp::{ChatMsg, ChatType},
4    uid::Uid,
5};
6use serde::{Deserialize, Serialize};
7use std::collections::HashSet;
8
9pub const MAX_CHAT_TABS: usize = 5;
10pub const DEFAULT_CHAT_BOX_WIDTH: f64 = 470.0;
11pub const DEFAULT_CHAT_BOX_HEIGHT: f64 = 150.0;
12
13#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
14pub struct ChatFilter {
15    //messages
16    pub message_all: bool,
17    pub message_world: bool,
18    pub message_region: bool,
19    pub message_say: bool,
20    pub message_group: bool,
21    pub message_faction: bool,
22    //activity (login/logout)
23    pub activity_all: bool,
24    pub activity_group: bool,
25    //deaths
26    pub death_all: bool,
27    pub death_group: bool,
28}
29impl ChatFilter {
30    pub fn satisfies(&self, chat_msg: &ChatMsg, group_members: &HashSet<&Uid>) -> bool {
31        match &chat_msg.chat_type {
32            ChatType::Online(u) | ChatType::Offline(u) => {
33                self.activity_all || (self.activity_group && group_members.contains(u))
34            },
35            ChatType::CommandInfo | ChatType::CommandError => true,
36            ChatType::Kill(_, u) => self.death_all || self.death_group && group_members.contains(u),
37            ChatType::GroupMeta(_) => true,   //todo
38            ChatType::FactionMeta(_) => true, //todo
39            ChatType::Tell(..) => true,
40            ChatType::Say(_) => self.message_all || self.message_say,
41            ChatType::Group(..) => self.message_all || self.message_group,
42            ChatType::Faction(..) => self.message_all || self.message_faction,
43            ChatType::Region(_) => self.message_all || self.message_region,
44            ChatType::World(_) => self.message_all || self.message_world,
45            ChatType::Npc(..) => true,
46            ChatType::NpcSay(..) => true,
47            ChatType::NpcTell(..) => true,
48            ChatType::Meta => true,
49        }
50    }
51}
52impl Default for ChatFilter {
53    fn default() -> Self {
54        Self {
55            message_all: true,
56            message_world: true,
57            message_region: true,
58            message_say: true,
59            message_group: true,
60            message_faction: true,
61
62            activity_all: false,
63            activity_group: true,
64
65            death_all: false,
66            death_group: true,
67        }
68    }
69}
70
71#[derive(Clone, Debug, Serialize, Deserialize)]
72#[serde(default)]
73pub struct ChatSettings {
74    pub chat_opacity: f32,
75    pub chat_character_name: bool,
76    pub chat_tabs: Vec<ChatTab>,
77    pub chat_tab_index: Option<usize>,
78    pub chat_cmd_prefix: char,
79    pub chat_pos_x: f64,
80    pub chat_pos_y: f64,
81    pub chat_size_x: f64,
82    pub chat_size_y: f64,
83}
84
85impl Default for ChatSettings {
86    fn default() -> Self {
87        Self {
88            chat_opacity: 0.4,
89            chat_character_name: true,
90            chat_tabs: vec![ChatTab::default()],
91            chat_tab_index: Some(0),
92            chat_cmd_prefix: '/',
93            chat_pos_x: 10.0,
94            chat_pos_y: 10.0,
95            chat_size_x: DEFAULT_CHAT_BOX_WIDTH,
96            chat_size_y: DEFAULT_CHAT_BOX_HEIGHT,
97        }
98    }
99}