remove keybind_mode, instead use left click(m1) for set and right click(m2) for unset

This commit is contained in:
miocore 2024-04-15 18:34:22 +03:00
parent a019eceb06
commit 8710aaa07b
3 changed files with 22 additions and 34 deletions

View File

@ -144,6 +144,9 @@ hud-settings-language_send_to_server = Send the configured language to servers (
hud-settings-awaitingkey = Press a key... hud-settings-awaitingkey = Press a key...
hud-settings-unbound = None hud-settings-unbound = None
hud-settings-reset_keybinds = Reset to defaults hud-settings-reset_keybinds = Reset to defaults
hud-settings-keybind-helper =
M1 to set
M2 to unset
hud-settings-chat_tabs = Chat Tabs hud-settings-chat_tabs = Chat Tabs
hud-settings-label = Label: hud-settings-label = Label:
hud-settings-delete = Delete hud-settings-delete = Delete

View File

@ -22,7 +22,7 @@ widget_ids! {
window_r, window_r,
window_scrollbar, window_scrollbar,
reset_controls_button, reset_controls_button,
keybinding_mode_button, keybind_helper,
controls_alignment_rectangle, controls_alignment_rectangle,
controls_texts[], controls_texts[],
controls_buttons[], controls_buttons[],
@ -174,16 +174,15 @@ impl<'a> Widget for Controls<'a> {
}; };
let text_width = text_widget.get_w(ui).unwrap_or(0.0); let text_width = text_widget.get_w(ui).unwrap_or(0.0);
text_widget.set(text_id, ui); text_widget.set(text_id, ui);
if button_widget button_widget
.right_from(text_id, 350.0 - text_width) .right_from(text_id, 350.0 - text_width)
.set(button_id, ui) .set(button_id, ui);
.was_clicked()
{ for _ in ui.widget_input(button_id).clicks().left() {
if self.global_state.window.keybinding_mode { events.push(ChangeBinding(game_input));
events.push(ChangeBinding(game_input)); }
} else { for _ in ui.widget_input(button_id).clicks().right() {
events.push(RemoveBinding(game_input)); events.push(RemoveBinding(game_input));
}
} }
// Set the previous id to the current one for the next cycle // Set the previous id to the current one for the next cycle
previous_element_id = Some(text_id); previous_element_id = Some(text_id);
@ -224,26 +223,16 @@ impl<'a> Widget for Controls<'a> {
}) })
.unwrap_or(0.0); .unwrap_or(0.0);
let toggle_widget = Button::new() let keybind_helper_text = self
.label(if self.global_state.window.keybinding_mode { .localized_strings
"remap" .get_msg("hud-settings-keybind-helper");
} else { let keybind_helper = Text::new(&keybind_helper_text)
"clear" .color(TEXT_COLOR)
}) .font_id(self.fonts.cyri.conrod_id)
.label_color(TEXT_COLOR) .font_size(self.fonts.cyri.scale(18));
.label_font_id(self.fonts.cyri.conrod_id) keybind_helper
.label_font_size(self.fonts.cyri.scale(15)) .top_right_with_margins_on(state.ids.window, offset + 5.0, 10.0)
.w(100.0) .set(state.ids.keybind_helper, ui);
.rgba(0.0, 0.0, 0.0, 0.0)
.border_rgba(0.0, 0.0, 0.0, 255.0)
.label_y(Relative::Scalar(1.0));
if toggle_widget
.top_right_with_margins_on(state.ids.window, offset + 10.0, 15.0)
.set(state.ids.keybinding_mode_button, ui)
.was_clicked()
{
events.push(ToggleKeybindingMode);
}
// Add an empty text widget to simulate some bottom margin, because conrod sucks // Add an empty text widget to simulate some bottom margin, because conrod sucks
if let Some(prev_id) = previous_element_id { if let Some(prev_id) = previous_element_id {

View File

@ -49,7 +49,6 @@ pub enum Chat {
pub enum Control { pub enum Control {
ChangeBinding(GameInput), ChangeBinding(GameInput),
RemoveBinding(GameInput), RemoveBinding(GameInput),
ToggleKeybindingMode,
ResetKeyBindings, ResetKeyBindings,
} }
#[derive(Clone)] #[derive(Clone)]
@ -363,9 +362,6 @@ impl SettingsChange {
Control::RemoveBinding(game_input) => { Control::RemoveBinding(game_input) => {
settings.controls.remove_binding(game_input); settings.controls.remove_binding(game_input);
}, },
Control::ToggleKeybindingMode => {
global_state.window.toggle_keybinding_mode();
},
Control::ResetKeyBindings => { Control::ResetKeyBindings => {
settings.controls = ControlSettings::default(); settings.controls = ControlSettings::default();
}, },