Ability to open chat while hidden

This commit is contained in:
Syniis 2024-01-30 20:23:25 +01:00
parent 1cb0b6a84e
commit aa35ed9e93
2 changed files with 29 additions and 9 deletions
voxygen/src/hud

@ -19,7 +19,6 @@ use conrod_core::{
};
use i18n::Localization;
use i18n_helpers::localize_chat_message;
use inline_tweak::tweak;
use std::collections::{HashSet, VecDeque};
use vek::Vec2;
@ -195,6 +194,7 @@ pub enum Event {
ResizeChat(Vec2<f64>),
MoveChat(Vec2<f64>),
UpdateUnread(Vec<bool>),
CloseChat,
}
impl<'a> Widget for Chat<'a> {
@ -261,8 +261,9 @@ impl<'a> Widget for Chat<'a> {
.sum();
if !pos_delta.is_approx_zero() {
let pos = (self.chat_pos + pos_delta).map(|e| e.max(0.)).map2(
self.global_state.window.logical_size() - self.chat_size
+ Vec2::unit_y() * CHAT_TAB_HEIGHT,
self.global_state.window.logical_size()
- self.chat_size
- Vec2::unit_y() * CHAT_TAB_HEIGHT,
|e, bounds| e.min(bounds),
);
@ -528,7 +529,7 @@ impl<'a> Widget for Chat<'a> {
// Message box
Rectangle::fill([self.chat_size.x, self.chat_size.y])
.rgba(0.0, 0.0, 0.0, chat_settings.chat_opacity)
.rgba(0.0, 0.0, 0.0, chat_settings.chat_opacity + 0.1)
.and(|r| {
if input_focused && !chat_in_screen_upper {
r.up_from(
@ -807,10 +808,21 @@ impl<'a> Widget for Chat<'a> {
} else if keyboard_capturer == Some(id) {
events.push(Event::Focus(state.ids.chat_input));
}
// If either Return or Enter is pressed and the input box is not empty, send the current message.
else if ui.widget_input(state.ids.chat_input).presses().key().any(
|key_press| matches!(key_press.key, Key::Return | Key::NumPadEnter if !state.input.message.is_empty()),
) {
// If either Return or Enter is pressed and the input box is not empty, send the current
// message.
else if ui
.widget_input(state.ids.chat_input)
.presses()
.key()
.any(|key_press| {
let has_message = !state.input.message.is_empty();
let pressed = matches!(key_press.key, Key::Return | Key::NumPadEnter);
if pressed {
events.push(Event::CloseChat);
}
has_message && pressed
})
{
let msg = state.input.message.clone();
state.update(|s| {
s.input.message.clear();

@ -1297,6 +1297,7 @@ pub struct Hud {
chat_size: Vec2<f64>,
chat_pos: Vec2<f64>,
unread_tabs: Vec<bool>,
force_chat: bool,
}
impl Hud {
@ -1435,6 +1436,7 @@ impl Hud {
chat_size: Vec2::new(DEFAULT_CHAT_BOX_WIDTH, DEFAULT_CHAT_BOX_HEIGHT),
chat_pos: Vec2::new(10.0, 10.0),
unread_tabs: vec![false; global_state.settings.chat.chat_tabs.len()],
force_chat: false,
}
}
@ -3493,7 +3495,7 @@ impl Hud {
// Draw this after loot scroller and subtitles so it can be dragged
// even when hovering over them
// TODO look into parenting and then settings movable widgets to floating
if global_state.settings.interface.toggle_chat {
if global_state.settings.interface.toggle_chat || self.force_chat {
for event in Chat::new(
&mut self.new_messages,
client,
@ -3543,6 +3545,9 @@ impl Hud {
chat::Event::UpdateUnread(unread) => {
self.unread_tabs = unread;
},
chat::Event::CloseChat => {
self.force_chat = false;
},
}
}
}
@ -4721,6 +4726,7 @@ impl Hud {
self.ui.focus_widget(if self.typing() {
None
} else {
self.force_chat = true;
Some(self.ids.chat)
});
true
@ -4728,6 +4734,7 @@ impl Hud {
WinEvent::InputUpdate(GameInput::Escape, true) => {
if self.typing() {
self.ui.focus_widget(None);
self.force_chat = false;
} else if self.show.trade {
self.events.push(Event::TradeAction(TradeAction::Decline));
} else {
@ -4753,6 +4760,7 @@ impl Hud {
GameInput::Command if state => {
self.force_chat_input = Some("/".to_owned());
self.force_chat_cursor = Some(Index { line: 0, char: 1 });
self.force_chat = true;
self.ui.focus_widget(Some(self.ids.chat));
true
},