Add a bunch of grab focuses for UI
This commit is contained in:
parent
43991a4fa0
commit
8e8812ee64
@ -39,6 +39,7 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_next = Callable()
|
||||
theme = ExtResource("3_dfnwm")
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_7j863")
|
||||
|
||||
@ -229,3 +230,4 @@ current = true
|
||||
[connection signal="pressed" from="lobby/v_box_container3/h_box_container/exit_button" to="lobby" method="exit"]
|
||||
[connection signal="pressed" from="lobby/v_box_container3/h_box_container/options_button" to="lobby" method="open_options"]
|
||||
[connection signal="pressed" from="lobby/v_box_container3/h_box_container/settings_button" to="lobby/settings" method="open"]
|
||||
[connection signal="on_close" from="lobby/settings" to="lobby" method="focus_next"]
|
||||
|
||||
@ -59,6 +59,10 @@ impl IPanel for GameFinishedScreen {
|
||||
.on_saved()
|
||||
.connect_other(self, Self::on_replay_saved);
|
||||
}
|
||||
|
||||
if let Some(focus) = &mut self.base_mut().find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -114,11 +114,15 @@ impl IControl for Hud {
|
||||
fn input(&mut self, event: Gd<InputEvent>) {
|
||||
if event.is_action_pressed("pause") {
|
||||
if let Some(pause_panel) = &mut self.pause_panel {
|
||||
let is_visible = pause_panel.is_visible();
|
||||
pause_panel.set_visible(!is_visible);
|
||||
let was_visible = pause_panel.is_visible();
|
||||
pause_panel.set_visible(!was_visible);
|
||||
if !pause_panel.is_visible() {
|
||||
if let Some(settings_panel) = &mut self.settings_panel {
|
||||
settings_panel.set_visible(false);
|
||||
settings_panel.bind_mut().close();
|
||||
}
|
||||
} else {
|
||||
if let Some(focus) = &mut pause_panel.find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
self.update_lock();
|
||||
|
||||
@ -2,8 +2,8 @@ use std::collections::HashMap;
|
||||
|
||||
use godot::{
|
||||
classes::{
|
||||
Button, CheckBox, CompressedTexture2D, Control, GridContainer, IPanel, Label, LineEdit,
|
||||
OptionButton, Os, Panel, SpinBox, TabContainer, VBoxContainer,
|
||||
Button, CheckBox, CompressedTexture2D, Control, GridContainer, IPanel, InputEvent, Label,
|
||||
LineEdit, OptionButton, Os, Panel, SpinBox, TabContainer, VBoxContainer,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
@ -223,6 +223,14 @@ impl IPanel for LobbyPanel {
|
||||
MusicManager::singleton()
|
||||
.bind_mut()
|
||||
.play(Some(Music::MainMenu), false);
|
||||
|
||||
self.focus_next();
|
||||
}
|
||||
|
||||
fn input(&mut self, event: Gd<InputEvent>) {
|
||||
if event.is_action_pressed("ui_cancel") {
|
||||
self.close_options();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,13 +243,19 @@ impl LobbyPanel {
|
||||
fn open_options(&mut self) {
|
||||
if let Some(panel) = &mut self.options_panel {
|
||||
panel.set_visible(true);
|
||||
if let Some(focus) = &mut panel.find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[func]
|
||||
fn close_options(&mut self) {
|
||||
if let Some(panel) = &mut self.options_panel {
|
||||
if let Some(panel) = &mut self.options_panel
|
||||
&& panel.is_visible()
|
||||
{
|
||||
panel.set_visible(false);
|
||||
self.focus_next();
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,6 +551,13 @@ impl LobbyPanel {
|
||||
}
|
||||
nodes
|
||||
}
|
||||
|
||||
#[func]
|
||||
pub fn focus_next(&mut self) {
|
||||
if let Some(focus) = &mut self.base_mut().find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_control(control: Gd<Control>, value: GameOptionValue) {
|
||||
|
||||
@ -33,6 +33,10 @@ impl IPanel for ReplayFinishedScreen {
|
||||
GameManager::singleton().bind().go_to_main_menu();
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(focus) = &mut self.base_mut().find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user