BBParam editor: Combine type+mode functionality in one button

Previously, we had two buttons: "mode switch" and "type choice".
Now replaced with the One Button to rule them all!
This commit is contained in:
Serhii Snitsaruk 2024-03-12 18:06:10 +01:00
parent ca6b497019
commit 39c4511249
4 changed files with 30 additions and 47 deletions

View File

@ -1,7 +1,7 @@
/**
* editor_property_bb_param.cpp
* =============================================================================
* Copyright 2021-2023 Serhii Snitsaruk
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
@ -17,9 +17,9 @@
#include "../blackboard/bb_param/bb_param.h"
#include "../blackboard/bb_param/bb_variant.h"
#include "../util/limbo_string_names.h"
#include "editor_property_variable_name.h"
#include "mode_switch_button.h"
#include "../util/limbo_string_names.h"
#include "core/error/error_macros.h"
#include "core/io/marshalls.h"
@ -253,15 +253,18 @@ void EditorPropertyBBParam::_value_edited(const String &p_property, Variant p_va
_get_edited_param()->set_saved_value(p_value);
}
void EditorPropertyBBParam::_mode_changed() {
_get_edited_param()->set_value_source(mode_button->get_mode() == Mode::SPECIFY_VALUE ? BBParam::SAVED_VALUE : BBParam::BLACKBOARD_VAR);
update_property();
}
void EditorPropertyBBParam::_type_selected(int p_index) {
Ref<BBVariant> param = _get_edited_param();
Ref<BBParam> param = _get_edited_param();
ERR_FAIL_COND(param.is_null());
param->set_type(Variant::Type(p_index));
if (p_index == ID_BIND_VAR) {
param->set_value_source(BBParam::BLACKBOARD_VAR);
} else {
param->set_value_source(BBParam::SAVED_VALUE);
Ref<BBVariant> variant_param = param;
if (variant_param.is_valid()) {
variant_param->set_type(Variant::Type(p_index));
}
}
update_property();
}
@ -270,36 +273,27 @@ void EditorPropertyBBParam::_variable_edited(const String &p_property, Variant p
}
void EditorPropertyBBParam::update_property() {
if (mode_button->get_mode() == -1) {
if (!initialized) {
// Initialize UI -- needed after https://github.com/godotengine/godot/commit/db7175458a0532f1efe733f303ad2b55a02a52a5
_notification(NOTIFICATION_THEME_CHANGED);
}
Ref<BBParam> param = _get_edited_param();
bool is_variant_param = param->is_class_ptr(BBVariant::get_class_ptr_static());
if (param->get_value_source() == BBParam::BLACKBOARD_VAR) {
_remove_value_editor();
variable_editor->set_object_and_property(param.ptr(), SNAME("variable"));
variable_editor->update_property();
variable_editor->show();
mode_button->call_deferred(SNAME("set_mode"), Mode::BIND_VAR, true);
type_choice->hide();
bottom_container->hide();
type_choice->set_icon(get_editor_theme_icon(SNAME("BTSetVar")));
} else {
_create_value_editor(param->get_type());
variable_editor->hide();
value_editor->show();
value_editor->set_object_and_property(param.ptr(), SNAME("saved_value"));
value_editor->update_property();
mode_button->call_deferred(SNAME("set_mode"), Mode::SPECIFY_VALUE, true);
type_choice->set_visible(is_variant_param);
}
if (is_variant_param) {
Variant::Type t = Variant::Type(param->get_type());
String type_name = Variant::get_type_name(t);
type_choice->set_icon(get_editor_theme_icon(type_name));
type_choice->set_icon(get_editor_theme_icon(Variant::get_type_name(param->get_type())));
}
}
@ -324,17 +318,14 @@ void EditorPropertyBBParam::_notification(int p_what) {
type_choice->set_icon(get_editor_theme_icon(type));
}
// Initialize mode button.
mode_button->clear();
mode_button->add_mode(Mode::SPECIFY_VALUE, get_editor_theme_icon(SNAME("LimboSpecifyValue")), TTR("Mode: Set a specific value.\nClick to switch modes."));
mode_button->add_mode(Mode::BIND_VAR, get_editor_theme_icon(SNAME("BTSetVar")), TTR("Mode: Use a blackboard variable.\nClick to switch modes."));
mode_button->set_mode(_get_edited_param()->get_value_source() == BBParam::BLACKBOARD_VAR ? Mode::BIND_VAR : Mode::SPECIFY_VALUE, true);
bool is_variant_param = _get_edited_param()->is_class_ptr(BBVariant::get_class_ptr_static());
// Initialize type choice.
PopupMenu *type_menu = type_choice->get_popup();
type_menu->clear();
type_menu->add_icon_item(get_editor_theme_icon(SNAME("BTSetVar")), TTR("Blackboard Variable"), ID_BIND_VAR);
type_menu->add_separator();
Ref<BBParam> param = _get_edited_param();
bool is_variant_param = param->is_class_ptr(BBVariant::get_class_ptr_static());
if (is_variant_param) {
// Initialize type choice.
PopupMenu *type_menu = type_choice->get_popup();
type_menu->clear();
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (i == Variant::RID || i == Variant::CALLABLE || i == Variant::SIGNAL) {
continue;
@ -343,8 +334,11 @@ void EditorPropertyBBParam::_notification(int p_what) {
type_menu->add_icon_item(get_editor_theme_icon(type), type, i);
}
} else { // Not a variant param.
type_choice->hide();
String type = Variant::get_type_name(param->get_type());
type_menu->add_icon_item(get_editor_theme_icon(type), type, param->get_type());
}
initialized = true;
} break;
}
}
@ -358,11 +352,6 @@ EditorPropertyBBParam::EditorPropertyBBParam() {
bottom_container->set_theme_type_variation("MarginContainer4px");
add_child(bottom_container);
mode_button = memnew(ModeSwitchButton);
hbox->add_child(mode_button);
mode_button->set_focus_mode(FOCUS_NONE);
mode_button->connect(LW_NAME(mode_changed), callable_mp(this, &EditorPropertyBBParam::_mode_changed));
type_choice = memnew(MenuButton);
hbox->add_child(type_choice);
type_choice->get_popup()->connect(LW_NAME(id_pressed), callable_mp(this, &EditorPropertyBBParam::_type_selected));

View File

@ -1,7 +1,7 @@
/**
* editor_property_bb_param.h
* =============================================================================
* Copyright 2021-2023 Serhii Snitsaruk
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
@ -32,19 +32,16 @@ class EditorPropertyBBParam : public EditorProperty {
GDCLASS(EditorPropertyBBParam, EditorProperty);
private:
enum Mode {
SPECIFY_VALUE,
BIND_VAR,
};
const int ID_BIND_VAR = 1000;
bool initialized = false;
StringName param_type;
PropertyHint property_hint = PROPERTY_HINT_NONE;
Mode mode = Mode::SPECIFY_VALUE;
HBoxContainer *hbox = nullptr;
MarginContainer *bottom_container = nullptr;
HBoxContainer *editor_hbox = nullptr;
ModeSwitchButton *mode_button = nullptr;
EditorProperty *value_editor = nullptr;
EditorPropertyVariableName *variable_editor = nullptr;
MenuButton *type_choice = nullptr;
@ -56,7 +53,6 @@ private:
void _value_edited(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false);
void _variable_edited(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false);
void _mode_changed();
void _type_selected(int p_index);
protected:

View File

@ -82,7 +82,6 @@ LimboExtractSubtree = "res://addons/limboai/icons/LimboExtractSubtree.svg"
LimboHSM = "res://addons/limboai/icons/LimboHSM.svg"
LimboPercent = "res://addons/limboai/icons/LimboPercent.svg"
LimboSelectAll = "res://addons/limboai/icons/LimboSelectAll.svg"
LimboSpecifyValue = "res://addons/limboai/icons/LimboSpecifyValue.svg"
LimboState = "res://addons/limboai/icons/LimboState.svg"
LimboVarAdd = "res://addons/limboai/icons/LimboVarAdd.svg"
LimboVarExists = "res://addons/limboai/icons/LimboVarExists.svg"

View File

@ -1 +0,0 @@
<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path clip-rule="evenodd" d="m0 0h16v16h-16z"/></clipPath><path d="m0 0h16v16h-16z" fill="none"/><g clip-path="url(#a)"><path d="m0 0h16v16h-16z" fill="none"/><g fill="#e0e0e0"><path d="m15.504 3.051v9.899c0 1.408-1.143 2.55-2.551 2.55h-9.899c-1.408 0-2.551-1.142-2.551-2.55v-9.899c0-1.408 1.143-2.551 2.551-2.551h9.899c1.408 0 2.551 1.143 2.551 2.551zm-1.001 0c0-.857-.695-1.551-1.55-1.551h-9.899c-.857 0-1.55.694-1.55 1.551v9.899c0 .855.693 1.55 1.55 1.55h9.899c.855 0 1.55-.695 1.55-1.55z"/><path d="m5.002 7.272c-.344 0-.652-.085-.924-.255s-.486-.417-.642-.741-.234-.716-.234-1.176.078-.852.234-1.176.37-.571.642-.741.58-.255.924-.255c.348 0 .657.085.927.255s.483.417.639.741.234.716.234 1.176-.078.852-.234 1.176-.369.571-.639.741-.579.255-.927.255zm0-.822c.164 0 .307-.046.429-.138s.218-.238.288-.438.105-.458.105-.774-.035-.574-.105-.774-.166-.346-.288-.438-.265-.138-.429-.138c-.16 0-.301.046-.423.138s-.218.238-.288.438-.105.458-.105.774.035.574.105.774.166.346.288.438.263.138.423.138z" fill-rule="nonzero"/><path d="m10.485 3.78h-.84v-.78h1.812v4.2h-.972z"/><path d="m4.936 9.58h-.84v-.78h1.812v4.2h-.972z"/><path d="m10.998 13.072c-.344 0-.652-.085-.924-.255s-.486-.417-.642-.741-.234-.716-.234-1.176.078-.852.234-1.176.37-.571.642-.741.58-.255.924-.255c.348 0 .657.085.927.255s.483.417.639.741.234.716.234 1.176-.078.852-.234 1.176-.369.571-.639.741-.579.255-.927.255zm0-.822c.164 0 .307-.046.429-.138s.218-.238.288-.438.105-.458.105-.774-.035-.574-.105-.774-.166-.346-.288-.438-.265-.138-.429-.138c-.16 0-.301.046-.423.138s-.218.238-.288.438-.105.458-.105.774.035.574.105.774.166.346.288.438.263.138.423.138z" fill-rule="nonzero"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 1.8 KiB