Added chat toggle

This commit is contained in:
Joshua Barretto 2021-06-21 20:16:03 +01:00
parent 8ab222bf80
commit b84708ca75
6 changed files with 74 additions and 38 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added debug line info to release builds, enhancing the usefulness of panic backtraces
- NPCs and animals can now make sounds in response to certain events
- Players can press H to greet others
- Ability to toggle chat visibility
### Changed
- Entity-entity pushback is no longer applied in forced movement states like rolling and leaping.

View File

@ -11,6 +11,7 @@
"hud.settings.help_window": "Help Window",
"hud.settings.debug_info": "Debug Info",
"hud.settings.show_hitboxes": "Show hitboxes",
"hud.settings.show_chat": "Show chat",
"hud.settings.tips_on_startup": "Tips-On-Startup",
"hud.settings.ui_scale": "UI-Scale",
"hud.settings.relative_scaling": "Relative Scaling",

View File

@ -2706,43 +2706,45 @@ impl Hud {
.retain(|m| !matches!(m.chat_type, comp::ChatType::Npc(_, _)));
// Chat box
for event in Chat::new(
&mut self.new_messages,
&client,
global_state,
self.pulse,
&self.imgs,
&self.fonts,
i18n,
)
.and_then(self.force_chat_input.take(), |c, input| c.input(input))
.and_then(self.tab_complete.take(), |c, input| {
c.prepare_tab_completion(input)
})
.and_then(self.force_chat_cursor.take(), |c, pos| c.cursor_pos(pos))
.set(self.ids.chat, ui_widgets)
{
match event {
chat::Event::TabCompletionStart(input) => {
self.tab_complete = Some(input);
},
chat::Event::SendMessage(message) => {
events.push(Event::SendMessage(message));
},
chat::Event::SendCommand(name, args) => {
events.push(Event::SendCommand(name, args));
},
chat::Event::Focus(focus_id) => {
self.to_focus = Some(Some(focus_id));
},
chat::Event::ChangeChatTab(tab) => {
events.push(Event::SettingsChange(ChatChange::ChangeChatTab(tab).into()));
},
chat::Event::ShowChatTabSettings(tab) => {
self.show.chat_tab_settings_index = Some(tab);
self.show.settings_tab = SettingsTab::Chat;
self.show.settings(true);
},
if global_state.settings.interface.toggle_chat {
for event in Chat::new(
&mut self.new_messages,
&client,
global_state,
self.pulse,
&self.imgs,
&self.fonts,
i18n,
)
.and_then(self.force_chat_input.take(), |c, input| c.input(input))
.and_then(self.tab_complete.take(), |c, input| {
c.prepare_tab_completion(input)
})
.and_then(self.force_chat_cursor.take(), |c, pos| c.cursor_pos(pos))
.set(self.ids.chat, ui_widgets)
{
match event {
chat::Event::TabCompletionStart(input) => {
self.tab_complete = Some(input);
},
chat::Event::SendMessage(message) => {
events.push(Event::SendMessage(message));
},
chat::Event::SendCommand(name, args) => {
events.push(Event::SendCommand(name, args));
},
chat::Event::Focus(focus_id) => {
self.to_focus = Some(Some(focus_id));
},
chat::Event::ChangeChatTab(tab) => {
events.push(Event::SettingsChange(ChatChange::ChangeChatTab(tab).into()));
},
chat::Event::ShowChatTabSettings(tab) => {
self.show.chat_tab_settings_index = Some(tab);
self.show.settings_tab = SettingsTab::Chat;
self.show.settings(true);
},
}
}
}

View File

@ -38,6 +38,8 @@ widget_ids! {
debug_button_label,
hitboxes_button,
hitboxes_button_label,
chat_button,
chat_button_label,
ch_title,
ch_transp_slider,
ch_transp_value,
@ -266,9 +268,33 @@ impl<'a> Widget for Interface<'a> {
.color(TEXT_COLOR)
.set(state.ids.hitboxes_button_label, ui);
// Chat
let show_chat = ToggleButton::new(
self.global_state.settings.interface.toggle_chat,
self.imgs.checkbox,
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.down_from(state.ids.hitboxes_button, 8.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.chat_button, ui);
if self.global_state.settings.interface.toggle_chat != show_chat {
events.push(ToggleChat(show_chat));
}
Text::new(&self.localized_strings.get("hud.settings.show_chat"))
.right_from(state.ids.chat_button, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.graphics_for(state.ids.chat_button)
.color(TEXT_COLOR)
.set(state.ids.chat_button_label, ui);
// Ui Scale
Text::new(&self.localized_strings.get("hud.settings.ui_scale"))
.down_from(state.ids.hitboxes_button, 20.0)
.down_from(state.ids.chat_button, 20.0)
.font_size(self.fonts.cyri.scale(18))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)

View File

@ -97,6 +97,7 @@ pub enum Interface {
ToggleHelp(bool),
ToggleDebug(bool),
ToggleHitboxes(bool),
ToggleChat(bool),
ToggleTips(bool),
CrosshairTransp(f32),
@ -450,6 +451,9 @@ impl SettingsChange {
Interface::ToggleHitboxes(toggle_hitboxes) => {
settings.interface.toggle_hitboxes = toggle_hitboxes;
},
Interface::ToggleChat(toggle_chat) => {
settings.interface.toggle_chat = toggle_chat;
},
Interface::ToggleTips(loading_tips) => {
settings.interface.loading_tips = loading_tips;
},

View File

@ -11,6 +11,7 @@ use vek::*;
pub struct InterfaceSettings {
pub toggle_debug: bool,
pub toggle_hitboxes: bool,
pub toggle_chat: bool,
pub sct: bool,
pub sct_player_batch: bool,
pub sct_damage_batch: bool,
@ -46,6 +47,7 @@ impl Default for InterfaceSettings {
Self {
toggle_debug: false,
toggle_hitboxes: false,
toggle_chat: true,
sct: true,
sct_player_batch: false,
sct_damage_batch: false,