summaryrefslogtreecommitdiff
path: root/editor/action_map_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/action_map_editor.cpp')
-rw-r--r--editor/action_map_editor.cpp55
1 files changed, 38 insertions, 17 deletions
diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp
index 49c79d709b..462f314471 100644
--- a/editor/action_map_editor.cpp
+++ b/editor/action_map_editor.cpp
@@ -136,10 +136,9 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
TreeItem *input_item = category->get_first_child();
if (input_item != nullptr) {
- // has_type this should be always true, unless the tree structure has been misconfigured.
- bool has_type = input_item->get_parent()->has_meta("__type");
- int input_type = input_item->get_parent()->get_meta("__type");
- if (!has_type) {
+ // input_type should always be > 0, unless the tree structure has been misconfigured.
+ int input_type = input_item->get_parent()->get_meta("__type", 0);
+ if (input_type == 0) {
return;
}
@@ -645,6 +644,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() {
tab_container = memnew(TabContainer);
tab_container->set_use_hidden_tabs_for_min_size(true);
tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ tab_container->set_theme_type_variation("TabContainerOdd");
tab_container->connect("tab_selected", callable_mp(this, &InputEventConfigurationDialog::_tab_selected));
main_vbox->add_child(tab_container);
@@ -720,7 +720,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() {
for (int i = 0; i < MOD_MAX; i++) {
String name = mods[i];
mod_checkboxes[i] = memnew(CheckBox);
- mod_checkboxes[i]->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_mod_toggled), varray(i));
+ mod_checkboxes[i]->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_mod_toggled).bind(i));
mod_checkboxes[i]->set_text(name);
mod_container->add_child(mod_checkboxes[i]);
}
@@ -791,6 +791,24 @@ void ActionMapEditor::_add_action_pressed() {
_add_action(add_edit->get_text());
}
+String ActionMapEditor::_check_new_action_name(const String &p_name) {
+ if (p_name.is_empty() || !_is_action_name_valid(p_name)) {
+ return TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'");
+ }
+
+ if (_has_action(p_name)) {
+ return vformat(TTR("An action with the name '%s' already exists."), p_name);
+ }
+
+ return "";
+}
+
+void ActionMapEditor::_add_edit_text_changed(const String &p_name) {
+ String error = _check_new_action_name(p_name);
+ add_button->set_tooltip(error);
+ add_button->set_disabled(!error.is_empty());
+}
+
bool ActionMapEditor::_has_action(const String &p_name) const {
for (const ActionInfo &action_info : actions_cache) {
if (p_name == action_info.name) {
@@ -801,13 +819,9 @@ bool ActionMapEditor::_has_action(const String &p_name) const {
}
void ActionMapEditor::_add_action(const String &p_name) {
- if (p_name.is_empty() || !_is_action_name_valid(p_name)) {
- show_message(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
- return;
- }
-
- if (_has_action(p_name)) {
- show_message(vformat(TTR("An action with the name '%s' already exists."), p_name));
+ String error = _check_new_action_name(p_name);
+ if (!error.is_empty()) {
+ show_message(error);
return;
}
@@ -855,7 +869,11 @@ void ActionMapEditor::_action_edited() {
}
}
-void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_id) {
+void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
+ if (p_button != MouseButton::LEFT) {
+ return;
+ }
+
ItemButton option = (ItemButton)p_id;
TreeItem *item = Object::cast_to<TreeItem>(p_item);
@@ -913,7 +931,7 @@ void ActionMapEditor::_tree_item_activated() {
return;
}
- _tree_button_pressed(item, 2, BUTTON_EDIT_EVENT);
+ _tree_button_pressed(item, 2, BUTTON_EDIT_EVENT, MouseButton::LEFT);
}
void ActionMapEditor::set_show_builtin_actions(bool p_show) {
@@ -1181,7 +1199,7 @@ void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) {
ActionMapEditor::ActionMapEditor() {
// Main Vbox Container
VBoxContainer *main_vbox = memnew(VBoxContainer);
- main_vbox->set_anchors_and_offsets_preset(PRESET_WIDE);
+ main_vbox->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
add_child(main_vbox);
HBoxContainer *top_hbox = memnew(HBoxContainer);
@@ -1208,13 +1226,16 @@ ActionMapEditor::ActionMapEditor() {
add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_edit->set_placeholder(TTR("Add New Action"));
add_edit->set_clear_button_enabled(true);
+ add_edit->connect("text_changed", callable_mp(this, &ActionMapEditor::_add_edit_text_changed));
add_edit->connect("text_submitted", callable_mp(this, &ActionMapEditor::_add_action));
add_hbox->add_child(add_edit);
- Button *add_button = memnew(Button);
+ add_button = memnew(Button);
add_button->set_text(TTR("Add"));
add_button->connect("pressed", callable_mp(this, &ActionMapEditor::_add_action_pressed));
add_hbox->add_child(add_button);
+ // Disable the button and set its tooltip.
+ _add_edit_text_changed(add_edit->get_text());
main_vbox->add_child(add_hbox);
@@ -1233,7 +1254,7 @@ ActionMapEditor::ActionMapEditor() {
action_tree->set_column_custom_minimum_width(2, 50 * EDSCALE);
action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited));
action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated));
- action_tree->connect("button_pressed", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
+ action_tree->connect("button_clicked", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
main_vbox->add_child(action_tree);
action_tree->set_drag_forwarding(this);