Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
/* clang-format off */
{ "ui_accept", TTRC("Accept") },
{ "ui_select", TTRC("Select") },
{ "ui_dialog_positive_option", TTRC("Positive Option") },
{ "ui_dialog_negative_option", TTRC("Negative Option") },
{ "ui_cancel", TTRC("Cancel") },
{ "ui_close_dialog", TTRC("Close Dialog") },
{ "ui_focus_next", TTRC("Focus Next") },
Expand Down Expand Up @@ -470,6 +472,14 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
default_builtin_cache.insert("ui_cancel", inputs);

inputs = List<Ref<InputEvent>>();
inputs.push_back(InputEventKey::create_reference(Key::Y));
default_builtin_cache.insert("ui_dialog_positive_option", inputs);

inputs = List<Ref<InputEvent>>();
inputs.push_back(InputEventKey::create_reference(Key::N));
default_builtin_cache.insert("ui_dialog_negative_option", inputs);

inputs = List<Ref<InputEvent>>();
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
default_builtin_cache.insert("ui_close_dialog", inputs);
Expand Down
8 changes: 8 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,14 @@
Default [InputEventAction] to cut a selection to the clipboard.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
</member>
<member name="input/ui_dialog_negative_option" type="Dictionary" setter="" getter="">
Default [InputEventAction] to press the negative action button in a dialog box, like "discard changes." Not to be confused with cancel, which is done with [code]ui_close_dialog[/code].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Default [InputEventAction] to press the negative action button in a dialog box, like "discard changes." Not to be confused with cancel, which is done with [code]ui_close_dialog[/code].
Default [InputEventAction] to press the negative action button in a dialog box, like choosing "no" in a confirmation dialog or "discard changes". Not to be confused with closing a dialog (similar to clicking its close button), which is done with [code]ui_close_dialog[/code].

[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
</member>
<member name="input/ui_dialog_positive_option" type="Dictionary" setter="" getter="">
Default [InputEventAction] to press the positive action button in a dialog box, like "save changes" or press an "ok" button.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Default [InputEventAction] to press the positive action button in a dialog box, like "save changes" or press an "ok" button.
Default [InputEventAction] to press the positive action button in a dialog box, like choosing "yes" in a confirmation dialog or "save changes".

[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
</member>
<member name="input/ui_down" type="Dictionary" setter="" getter="">
Default [InputEventAction] to move down in the UI.
[b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified.
Expand Down
4 changes: 3 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9202,14 +9202,16 @@ EditorNode::EditorNode() {

confirmation = memnew(ConfirmationDialog);
confirmation_button = confirmation->add_button(TTRC("Don't Save"), DisplayServer::get_singleton()->get_swap_cancel_ok(), "discard");
confirmation->set_negative_action_button(confirmation_button);
gui_base->add_child(confirmation);
confirmation->set_min_size(Vector2(450.0 * EDSCALE, 0));
confirmation->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_confirm_current));
confirmation->connect("custom_action", callable_mp(this, &EditorNode::_discard_changes));
confirmation->connect("canceled", callable_mp(this, &EditorNode::_cancel_confirmation));

save_confirmation = memnew(ConfirmationDialog);
save_confirmation->add_button(TTRC("Don't Save"), DisplayServer::get_singleton()->get_swap_cancel_ok(), "discard");
Button *dont_save_button = save_confirmation->add_button(TTRC("Don't Save"), DisplayServer::get_singleton()->get_swap_cancel_ok(), "discard");
save_confirmation->set_negative_action_button(dont_save_button);
gui_base->add_child(save_confirmation);
save_confirmation->set_min_size(Vector2(450.0 * EDSCALE, 0));
save_confirmation->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_confirm_current));
Expand Down
10 changes: 10 additions & 0 deletions scene/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ void AcceptDialog::_button_visibility_changed(Button *button) {
}
}

Button *ConfirmationDialog::get_negative_action_button() {
return negative_action_button;
}

void ConfirmationDialog::set_negative_action_button(Button *p_new_negative_action_button) {
negative_action_button = p_new_negative_action_button;
negative_action_button->set_shortcut(Shortcut::make_from_action("ui_dialog_negative_option"));
}

Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) {
Button *button = memnew(Button);
button->set_text(p_text);
Expand Down Expand Up @@ -492,6 +501,7 @@ AcceptDialog::AcceptDialog() {
buttons_hbox->add_spacer();
ok_button = memnew(Button);
set_default_ok_text(ETR("OK"));
ok_button->set_shortcut(Shortcut::make_from_action("ui_dialog_positive_option"));
buttons_hbox->add_child(ok_button);
// Ensure hiding OK button will hide one of the initial spacers.
Control *bound_spacer = buttons_hbox->add_spacer();
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ class AcceptDialog : public Window {
class ConfirmationDialog : public AcceptDialog {
GDCLASS(ConfirmationDialog, AcceptDialog);
Button *cancel = nullptr;
Button *negative_action_button = nullptr;

protected:
static void _bind_methods();

public:
Button *get_cancel_button();
Button *get_negative_action_button();
void set_negative_action_button(Button *p_new_negative_action_button);

void set_cancel_button_text(String p_cancel_button_text);
String get_cancel_button_text() const;
Expand Down
Loading