veloren_voxygen/hud/settings_window/
chat.rs

1use super::{RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
2
3use crate::{
4    GlobalState,
5    hud::{ChatTab, Show, TEXT_COLOR, TEXT_GRAY_COLOR, UI_HIGHLIGHT_0, UI_MAIN, img_ids::Imgs},
6    session::settings_change::{Chat as ChatChange, Chat::*},
7    settings::chat::MAX_CHAT_TABS,
8    ui::{ImageSlider, ToggleButton, fonts::Fonts},
9};
10use conrod_core::{
11    Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, color,
12    position::Relative,
13    widget::{self, Button, DropDownList, Image, Rectangle, Text, TextEdit},
14    widget_ids,
15};
16use i18n::Localization;
17use std::cmp::Ordering;
18
19widget_ids! {
20    struct Ids {
21        window,
22        window_r,
23        general_txt,
24        transp_text,
25        transp_slider,
26        transp_value,
27        lock_chat_text,
28        lock_chat_button,
29        char_name_text,
30        char_name_button,
31        reset_chat_button,
32
33        //Tabs
34        tabs_frame,
35        tabs_bg,
36        tabs_text,
37        tab_align,
38        tab_add,
39        tabs[],
40
41        //tab content
42        tab_content_align,
43        tab_content_align_r,
44        tab_label_text,
45        tab_label_input,
46        tab_label_bg,
47        btn_tab_delete,
48
49        text_messages,
50        btn_messages_all,
51        text_messages_all,
52        btn_messages_world,
53        text_messages_world,
54        icon_messages_world,
55        btn_messages_region,
56        text_messages_region,
57        icon_messages_region,
58        btn_messages_faction,
59        text_messages_faction,
60        icon_messages_faction,
61        btn_messages_group,
62        text_messages_group,
63        icon_messages_group,
64        btn_messages_say,
65        text_messages_say,
66        icon_messages_say,
67
68        text_activity,
69        list_activity,
70
71        text_death,
72        list_death,
73
74        show_chat_timestamp_label,
75        show_chat_timestamp_toggle,
76    }
77}
78
79#[derive(WidgetCommon)]
80pub struct Chat<'a> {
81    global_state: &'a GlobalState,
82    show: &'a Show,
83    imgs: &'a Imgs,
84    fonts: &'a Fonts,
85    localized_strings: &'a Localization,
86    #[conrod(common_builder)]
87    common: widget::CommonBuilder,
88}
89impl<'a> Chat<'a> {
90    pub fn new(
91        global_state: &'a GlobalState,
92        show: &'a Show,
93        imgs: &'a Imgs,
94        fonts: &'a Fonts,
95        localized_strings: &'a Localization,
96    ) -> Self {
97        Self {
98            global_state,
99            show,
100            imgs,
101            fonts,
102            localized_strings,
103            common: widget::CommonBuilder::default(),
104        }
105    }
106}
107
108pub struct State {
109    ids: Ids,
110}
111pub enum Event {
112    ChangeChatSettingsTab(Option<usize>),
113    ChatChange(ChatChange),
114}
115
116impl Widget for Chat<'_> {
117    type Event = Vec<Event>;
118    type State = State;
119    type Style = ();
120
121    fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
122        State {
123            ids: Ids::new(id_gen),
124        }
125    }
126
127    fn style(&self) -> Self::Style {}
128
129    fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
130        common_base::prof_span!("Chat::update");
131        let widget::UpdateArgs { state, ui, .. } = args;
132
133        let mut events = Vec::new();
134        let chat_settings = &self.global_state.settings.chat;
135        // Alignment
136        // Settings Window
137        Rectangle::fill_with(args.rect.dim(), color::TRANSPARENT)
138            .xy(args.rect.xy())
139            .graphics_for(args.id)
140            .scroll_kids()
141            .scroll_kids_vertically()
142            .set(state.ids.window, ui);
143        // Right Side
144        Rectangle::fill_with([args.rect.w() / 2.0, args.rect.h()], color::TRANSPARENT)
145            .top_right_of(state.ids.window)
146            .set(state.ids.window_r, ui);
147
148        // General Title
149        Text::new(&self.localized_strings.get_msg("hud-settings-general"))
150            .top_left_with_margins_on(state.ids.window, 5.0, 5.0)
151            .font_size(self.fonts.cyri.scale(18))
152            .font_id(self.fonts.cyri.conrod_id)
153            .color(TEXT_COLOR)
154            .set(state.ids.general_txt, ui);
155
156        // Chat Transparency
157        Text::new(
158            &self
159                .localized_strings
160                .get_msg("hud-settings-background_opacity"),
161        )
162        .down_from(state.ids.general_txt, 20.0)
163        .font_size(self.fonts.cyri.scale(14))
164        .font_id(self.fonts.cyri.conrod_id)
165        .color(TEXT_COLOR)
166        .set(state.ids.transp_text, ui);
167        if let Some(new_val) = ImageSlider::continuous(
168            chat_settings.chat_opacity,
169            0.0,
170            1.0,
171            self.imgs.slider_indicator,
172            self.imgs.slider,
173        )
174        .w_h(104.0, 22.0)
175        .down_from(state.ids.transp_text, 10.0)
176        .track_breadth(12.0)
177        .slider_length(10.0)
178        .pad_track((5.0, 5.0))
179        .set(state.ids.transp_slider, ui)
180        {
181            events.push(Event::ChatChange(Transparency(new_val)));
182        }
183
184        Text::new(&format!("{:.2}", chat_settings.chat_opacity,))
185            .right_from(state.ids.transp_slider, 8.0)
186            .font_size(self.fonts.cyri.scale(14))
187            .graphics_for(state.ids.transp_slider)
188            .font_id(self.fonts.cyri.conrod_id)
189            .color(TEXT_COLOR)
190            .set(state.ids.transp_value, ui);
191
192        // Lock chat size/position toggle button
193        Text::new(&self.localized_strings.get_msg("hud-settings-lock_chat"))
194            .down_from(state.ids.transp_slider, 10.0)
195            .font_size(self.fonts.cyri.scale(14))
196            .font_id(self.fonts.cyri.conrod_id)
197            .color(TEXT_COLOR)
198            .set(state.ids.lock_chat_text, ui);
199
200        if chat_settings.lock_chat
201            != ToggleButton::new(
202                chat_settings.lock_chat,
203                self.imgs.checkbox,
204                self.imgs.checkbox_checked,
205            )
206            .w_h(18.0, 18.0)
207            .right_from(state.ids.lock_chat_text, 10.0)
208            .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
209            .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
210            .set(state.ids.lock_chat_button, ui)
211        {
212            events.push(Event::ChatChange(LockChat(!chat_settings.lock_chat)));
213        }
214
215        // "Show character names in chat" toggle button
216        Text::new(
217            &self
218                .localized_strings
219                .get_msg("hud-settings-chat_character_name"),
220        )
221        .down_from(state.ids.lock_chat_text, 10.0)
222        .font_size(self.fonts.cyri.scale(14))
223        .font_id(self.fonts.cyri.conrod_id)
224        .color(TEXT_COLOR)
225        .set(state.ids.char_name_text, ui);
226
227        if chat_settings.chat_character_name
228            != ToggleButton::new(
229                chat_settings.chat_character_name,
230                self.imgs.checkbox,
231                self.imgs.checkbox_checked,
232            )
233            .w_h(18.0, 18.0)
234            .right_from(state.ids.char_name_text, 10.0)
235            .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
236            .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
237            .set(state.ids.char_name_button, ui)
238        {
239            events.push(Event::ChatChange(CharName(
240                !chat_settings.chat_character_name,
241            )));
242        }
243
244        // "Show chat message timestamp" toggle button
245        Text::new(
246            &self
247                .localized_strings
248                .get_msg("hud-settings-show_chat_timestamp"),
249        )
250        .down_from(state.ids.char_name_text, 10.0)
251        .font_size(self.fonts.cyri.scale(14))
252        .font_id(self.fonts.cyri.conrod_id)
253        .color(TEXT_COLOR)
254        .set(state.ids.show_chat_timestamp_label, ui);
255
256        if chat_settings.show_chat_timestamp
257            != ToggleButton::new(
258                chat_settings.show_chat_timestamp,
259                self.imgs.checkbox,
260                self.imgs.checkbox_checked,
261            )
262            .w_h(18.0, 18.0)
263            .right_from(state.ids.show_chat_timestamp_label, 10.0)
264            .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
265            .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
266            .set(state.ids.show_chat_timestamp_toggle, ui)
267        {
268            events.push(Event::ChatChange(ShowChatTimestamp(
269                !chat_settings.show_chat_timestamp,
270            )));
271        }
272
273        // Reset the chat settings to the default settings
274        if Button::image(self.imgs.button)
275            .w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT)
276            .hover_image(self.imgs.button_hover)
277            .press_image(self.imgs.button_press)
278            .down_from(state.ids.show_chat_timestamp_label, 20.0)
279            .label(&self.localized_strings.get_msg("hud-settings-reset_chat"))
280            .label_font_size(self.fonts.cyri.scale(14))
281            .label_color(TEXT_COLOR)
282            .label_font_id(self.fonts.cyri.conrod_id)
283            .label_y(Relative::Scalar(2.0))
284            .set(state.ids.reset_chat_button, ui)
285            .was_clicked()
286        {
287            events.push(Event::ChatChange(ResetChatSettings));
288        }
289
290        // Tabs Title
291        Text::new(&self.localized_strings.get_msg("hud-settings-chat_tabs"))
292            .top_left_with_margins_on(state.ids.window_r, 5.0, 5.0)
293            .font_size(self.fonts.cyri.scale(18))
294            .font_id(self.fonts.cyri.conrod_id)
295            .color(TEXT_COLOR)
296            .set(state.ids.tabs_text, ui);
297
298        // bg and frame
299        Image::new(self.imgs.chat_tab_settings_bg)
300            .w_h(390.0, 270.0)
301            .color(Some(UI_MAIN))
302            .down_from(state.ids.tabs_text, 20.0)
303            .set(state.ids.tabs_bg, ui);
304
305        Image::new(self.imgs.chat_tab_settings_frame)
306            .w_h(390.0, 270.0)
307            .color(Some(UI_HIGHLIGHT_0))
308            .down_from(state.ids.tabs_text, 20.0)
309            .set(state.ids.tabs_frame, ui);
310
311        // Tabs Alignment
312        Rectangle::fill_with([390.0, 20.0], color::TRANSPARENT)
313            .down_from(state.ids.tabs_text, 20.0)
314            .set(state.ids.tab_align, ui);
315
316        // Tabs Settings Alignment
317        Rectangle::fill_with([390.0, 250.0], color::TRANSPARENT)
318            .down_from(state.ids.tab_align, 0.0)
319            .set(state.ids.tab_content_align, ui);
320        Rectangle::fill_with([195.0, 250.0], color::TRANSPARENT)
321            .top_right_of(state.ids.tab_content_align)
322            .set(state.ids.tab_content_align_r, ui);
323
324        let chat_tabs = &chat_settings.chat_tabs;
325        if state.ids.tabs.len() < chat_tabs.len() {
326            state.update(|s| {
327                s.ids
328                    .tabs
329                    .resize(chat_tabs.len(), &mut ui.widget_id_generator())
330            });
331        }
332        for (i, chat_tab) in chat_tabs.iter().enumerate() {
333            let is_selected = self
334                .show
335                .chat_tab_settings_index
336                .map(|index| index == i)
337                .unwrap_or(false);
338
339            let button = Button::image(if is_selected {
340                self.imgs.selection
341            } else {
342                self.imgs.nothing
343            })
344            .w_h(390.0 / (MAX_CHAT_TABS as f64), 19.0)
345            .hover_image(self.imgs.selection_hover)
346            .press_image(self.imgs.selection_press)
347            .image_color(color::rgba(1.0, 0.82, 0.27, 1.0))
348            .label(chat_tab.label.as_str())
349            .label_font_size(self.fonts.cyri.scale(12))
350            .label_font_id(self.fonts.cyri.conrod_id)
351            .label_color(TEXT_COLOR)
352            .label_y(Relative::Scalar(1.0));
353
354            let button = if i == 0 {
355                button.top_left_with_margins_on(state.ids.tab_align, 1.0, 1.0)
356            } else {
357                button.right_from(state.ids.tabs[i - 1], 0.0)
358            };
359            if button.set(state.ids.tabs[i], ui).was_clicked() {
360                events.push(Event::ChangeChatSettingsTab(if is_selected {
361                    None
362                } else {
363                    Some(i)
364                }));
365            }
366        }
367        //Add button
368        if chat_tabs.len() < MAX_CHAT_TABS {
369            let add_tab_button = Button::image(self.imgs.settings_plus)
370                .hover_image(self.imgs.settings_plus_hover)
371                .press_image(self.imgs.settings_plus_press)
372                .w_h(19.0, 19.0);
373
374            let add_tab_button = if chat_tabs.is_empty() {
375                add_tab_button.top_left_with_margins_on(state.ids.tab_align, 1.0, 1.0)
376            } else {
377                add_tab_button.right_from(state.ids.tabs[chat_tabs.len() - 1], 0.0)
378            };
379
380            if add_tab_button.set(state.ids.tab_add, ui).was_clicked() {
381                let index = chat_tabs.len();
382                events.push(Event::ChatChange(ChatTabInsert(index, ChatTab::default())));
383                events.push(Event::ChangeChatSettingsTab(Some(index)));
384            }
385        }
386
387        //Content
388        if let Some((index, chat_tab)) = self
389            .show
390            .chat_tab_settings_index
391            .and_then(|i| chat_tabs.get(i).map(|ct| (i, ct)))
392        {
393            let mut updated_chat_tab = chat_tab.clone();
394
395            Text::new(&self.localized_strings.get_msg("hud-settings-label"))
396                .top_left_with_margins_on(state.ids.tab_content_align, 5.0, 25.0)
397                .font_size(self.fonts.cyri.scale(16))
398                .font_id(self.fonts.cyri.conrod_id)
399                .color(TEXT_COLOR)
400                .set(state.ids.tab_label_text, ui);
401
402            Rectangle::fill([90.0, 20.0])
403                .right_from(state.ids.tab_label_text, 5.0)
404                .color(color::rgba(0.0, 0.0, 0.0, 0.7))
405                .set(state.ids.tab_label_bg, ui);
406
407            if let Some(label) = TextEdit::new(chat_tab.label.as_str())
408                .right_from(state.ids.tab_label_text, 10.0)
409                .y_relative_to(state.ids.tab_label_text, -3.0)
410                .w_h(75.0, 20.0)
411                .font_id(self.fonts.cyri.conrod_id)
412                .font_size(self.fonts.cyri.scale(14))
413                .color(TEXT_COLOR)
414                .set(state.ids.tab_label_input, ui)
415            {
416                updated_chat_tab.label = label;
417            }
418
419            if Button::image(self.imgs.button)
420                .hover_image(self.imgs.button_hover)
421                .press_image(self.imgs.button_press)
422                .w_h(100.0, 30.0)
423                .label(&self.localized_strings.get_msg("hud-settings-delete"))
424                .label_font_size(self.fonts.cyri.scale(14))
425                .label_font_id(self.fonts.cyri.conrod_id)
426                .label_color(TEXT_COLOR)
427                .label_y(Relative::Scalar(1.0))
428                .bottom_right_with_margins_on(state.ids.tab_content_align, 10.0, 10.0)
429                .set(state.ids.btn_tab_delete, ui)
430                .was_clicked()
431            {
432                events.push(Event::ChatChange(ChatTabRemove(index)));
433                events.push(Event::ChangeChatSettingsTab(None));
434
435                if let Some(chat_tab_index) = chat_settings.chat_tab_index {
436                    match chat_tab_index.cmp(&index) {
437                        Ordering::Equal => {
438                            events.push(Event::ChatChange(ChangeChatTab(None)));
439                        },
440                        Ordering::Greater => {
441                            events.push(Event::ChatChange(ChangeChatTab(Some(index - 1))));
442                        },
443                        _ => {},
444                    }
445                }
446            }
447
448            //helper methods to reduce on repeated code
449            //(TODO: perhaps introduce a checkbox with label widget)
450            let create_toggle = |selected, enabled| {
451                ToggleButton::new(selected, self.imgs.checkbox, self.imgs.checkbox_checked)
452                    .and(|button| {
453                        if enabled {
454                            button
455                                .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
456                                .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
457                        } else {
458                            button.image_colors(TEXT_GRAY_COLOR, TEXT_GRAY_COLOR)
459                        }
460                    })
461                    .w_h(16.0, 16.0)
462            };
463
464            let create_toggle_text = |text, enabled| {
465                Text::new(text)
466                    .font_id(self.fonts.cyri.conrod_id)
467                    .font_size(self.fonts.cyri.scale(14))
468                    .color(if enabled { TEXT_COLOR } else { TEXT_GRAY_COLOR })
469            };
470
471            let create_toggle_icon = |img, enabled: bool| {
472                Image::new(img)
473                    .and_if(!enabled, |image| image.color(Some(TEXT_GRAY_COLOR)))
474                    .w_h(18.0, 18.0)
475            };
476
477            //Messages
478            Text::new(&self.localized_strings.get_msg("hud-settings-messages"))
479                .font_id(self.fonts.cyri.conrod_id)
480                .font_size(self.fonts.cyri.scale(16))
481                .color(TEXT_COLOR)
482                .top_left_with_margins_on(state.ids.tab_content_align, 35.0, 15.0)
483                .set(state.ids.text_messages, ui);
484
485            // Toggle all options
486            if chat_tab.filter.message_all
487                != ToggleButton::new(
488                    chat_tab.filter.message_all,
489                    self.imgs.checkbox,
490                    self.imgs.checkbox_checked,
491                )
492                .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
493                .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
494                .w_h(18.0, 18.0)
495                .down_from(state.ids.text_messages, 10.0)
496                .set(state.ids.btn_messages_all, ui)
497            {
498                updated_chat_tab.filter.message_all = !chat_tab.filter.message_all;
499            };
500
501            Text::new(&self.localized_strings.get_msg("hud-settings-show_all"))
502                .font_id(self.fonts.cyri.conrod_id)
503                .font_size(self.fonts.cyri.scale(16))
504                .color(TEXT_COLOR)
505                .right_from(state.ids.btn_messages_all, 5.0)
506                .set(state.ids.text_messages_all, ui);
507
508            //Messages - group
509            if chat_tab.filter.message_group
510                != create_toggle(chat_tab.filter.message_group, !chat_tab.filter.message_all)
511                    .down_from(state.ids.btn_messages_all, 10.0)
512                    .set(state.ids.btn_messages_group, ui)
513                && !chat_tab.filter.message_all
514            {
515                updated_chat_tab.filter.message_group = !chat_tab.filter.message_group;
516            }
517
518            let group_text = self.localized_strings.get_msg("hud-settings-group");
519            create_toggle_text(&group_text, !chat_tab.filter.message_all)
520                .right_from(state.ids.btn_messages_group, 5.0)
521                .set(state.ids.text_messages_group, ui);
522
523            create_toggle_icon(self.imgs.chat_group_small, !chat_tab.filter.message_all)
524                .right_from(state.ids.text_messages_group, 5.0)
525                .set(state.ids.icon_messages_group, ui);
526
527            //Messages - faction
528            if chat_tab.filter.message_faction
529                != create_toggle(
530                    chat_tab.filter.message_faction,
531                    !chat_tab.filter.message_all,
532                )
533                .down_from(state.ids.btn_messages_group, 10.0)
534                .set(state.ids.btn_messages_faction, ui)
535                && !chat_tab.filter.message_all
536            {
537                updated_chat_tab.filter.message_faction = !chat_tab.filter.message_faction;
538            }
539
540            let faction_text = self.localized_strings.get_msg("hud-settings-faction");
541            create_toggle_text(&faction_text, !chat_tab.filter.message_all)
542                .right_from(state.ids.btn_messages_faction, 5.0)
543                .set(state.ids.text_messages_faction, ui);
544
545            create_toggle_icon(self.imgs.chat_faction_small, !chat_tab.filter.message_all)
546                .right_from(state.ids.text_messages_faction, 5.0)
547                .set(state.ids.icon_messages_faction, ui);
548
549            //Messages - world
550            if chat_tab.filter.message_world
551                != create_toggle(chat_tab.filter.message_world, !chat_tab.filter.message_all)
552                    .down_from(state.ids.btn_messages_faction, 10.0)
553                    .set(state.ids.btn_messages_world, ui)
554                && !chat_tab.filter.message_all
555            {
556                updated_chat_tab.filter.message_world = !chat_tab.filter.message_world;
557            }
558
559            let world_text = self.localized_strings.get_msg("hud-settings-world");
560            create_toggle_text(&world_text, !chat_tab.filter.message_all)
561                .right_from(state.ids.btn_messages_world, 5.0)
562                .set(state.ids.text_messages_world, ui);
563
564            create_toggle_icon(self.imgs.chat_world_small, !chat_tab.filter.message_all)
565                .right_from(state.ids.text_messages_world, 5.0)
566                .set(state.ids.icon_messages_world, ui);
567
568            //Messages - region
569            if chat_tab.filter.message_region
570                != create_toggle(chat_tab.filter.message_region, !chat_tab.filter.message_all)
571                    .down_from(state.ids.btn_messages_world, 10.0)
572                    .set(state.ids.btn_messages_region, ui)
573                && !chat_tab.filter.message_all
574            {
575                updated_chat_tab.filter.message_region = !chat_tab.filter.message_region;
576            }
577
578            let region_text = self.localized_strings.get_msg("hud-settings-region");
579            create_toggle_text(&region_text, !chat_tab.filter.message_all)
580                .right_from(state.ids.btn_messages_region, 5.0)
581                .set(state.ids.text_messages_region, ui);
582
583            create_toggle_icon(self.imgs.chat_region_small, !chat_tab.filter.message_all)
584                .right_from(state.ids.text_messages_region, 5.0)
585                .set(state.ids.icon_messages_region, ui);
586
587            //Messages - say
588            if chat_tab.filter.message_say
589                != create_toggle(chat_tab.filter.message_say, !chat_tab.filter.message_all)
590                    .down_from(state.ids.btn_messages_region, 10.0)
591                    .set(state.ids.btn_messages_say, ui)
592                && !chat_tab.filter.message_all
593            {
594                updated_chat_tab.filter.message_say = !chat_tab.filter.message_say;
595            }
596
597            let say_text = self.localized_strings.get_msg("hud-settings-say");
598            create_toggle_text(&say_text, !chat_tab.filter.message_all)
599                .right_from(state.ids.btn_messages_say, 5.0)
600                .set(state.ids.text_messages_say, ui);
601
602            create_toggle_icon(self.imgs.chat_say_small, !chat_tab.filter.message_all)
603                .right_from(state.ids.text_messages_say, 5.0)
604                .set(state.ids.icon_messages_say, ui);
605
606            //Activity
607            Text::new(&self.localized_strings.get_msg("hud-settings-activity"))
608                .top_left_with_margins_on(state.ids.tab_content_align_r, 0.0, 5.0)
609                .align_middle_y_of(state.ids.text_messages)
610                .font_size(self.fonts.cyri.scale(16))
611                .font_id(self.fonts.cyri.conrod_id)
612                .color(TEXT_COLOR)
613                .set(state.ids.text_activity, ui);
614
615            if let Some(clicked) = DropDownList::new(
616                &[
617                    &self.localized_strings.get_msg("hud-settings-none"),
618                    &self.localized_strings.get_msg("hud-settings-all"),
619                    &self.localized_strings.get_msg("hud-settings-group_only"),
620                ],
621                Some(if chat_tab.filter.activity_all {
622                    //all
623                    1
624                } else if chat_tab.filter.activity_group {
625                    //group only
626                    2
627                } else {
628                    //none
629                    0
630                }),
631            )
632            .w_h(100.0, 20.0)
633            .color(color::hsl(0.0, 0.0, 0.1))
634            .label_color(TEXT_COLOR)
635            .label_font_id(self.fonts.cyri.conrod_id)
636            .label_font_size(self.fonts.cyri.scale(14))
637            .label_y(Relative::Scalar(1.0))
638            .down_from(state.ids.text_activity, 10.0)
639            .set(state.ids.list_activity, ui)
640            {
641                match clicked {
642                    0 => {
643                        updated_chat_tab.filter.activity_all = false;
644                        updated_chat_tab.filter.activity_group = false;
645                    },
646                    1 => {
647                        updated_chat_tab.filter.activity_all = true;
648                    },
649                    2 => {
650                        updated_chat_tab.filter.activity_all = false;
651                        updated_chat_tab.filter.activity_group = true;
652                    },
653                    _ => unreachable!(),
654                }
655            }
656
657            //Death
658            Text::new(&self.localized_strings.get_msg("hud-settings-death"))
659                .down_from(state.ids.list_activity, 20.0)
660                .font_size(self.fonts.cyri.scale(16))
661                .font_id(self.fonts.cyri.conrod_id)
662                .color(TEXT_COLOR)
663                .set(state.ids.text_death, ui);
664
665            if let Some(clicked) = DropDownList::new(
666                &[
667                    &self.localized_strings.get_msg("hud-settings-none"),
668                    &self.localized_strings.get_msg("hud-settings-all"),
669                    &self.localized_strings.get_msg("hud-settings-group_only"),
670                ],
671                Some(if chat_tab.filter.death_all {
672                    //all
673                    1
674                } else if chat_tab.filter.death_group {
675                    //group only
676                    2
677                } else {
678                    //none
679                    0
680                }),
681            )
682            .w_h(100.0, 20.0)
683            .color(color::hsl(0.0, 0.0, 0.1))
684            .label_color(TEXT_COLOR)
685            .label_font_id(self.fonts.cyri.conrod_id)
686            .label_font_size(self.fonts.cyri.scale(14))
687            .label_y(Relative::Scalar(1.0))
688            .down_from(state.ids.text_death, 10.0)
689            .set(state.ids.list_death, ui)
690            {
691                match clicked {
692                    0 => {
693                        updated_chat_tab.filter.death_all = false;
694                        updated_chat_tab.filter.death_group = false;
695                    },
696                    1 => {
697                        updated_chat_tab.filter.death_all = true;
698                    },
699                    2 => {
700                        updated_chat_tab.filter.death_all = false;
701                        updated_chat_tab.filter.death_group = true;
702                    },
703                    _ => unreachable!(),
704                }
705            }
706
707            if chat_tab != &updated_chat_tab {
708                //insert to front to avoid errors where the tab is moved or removed
709                events.insert(0, Event::ChatChange(ChatTabUpdate(index, updated_chat_tab)));
710            }
711        }
712
713        events
714    }
715}