You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add PropertyListHelper in all simple cases
This commit is contained in:
@@ -153,54 +153,25 @@ void MenuButton::_notification(int p_what) {
|
||||
}
|
||||
|
||||
bool MenuButton::_set(const StringName &p_name, const Variant &p_value) {
|
||||
Vector<String> components = String(p_name).split("/", true, 2);
|
||||
if (components.size() >= 2 && components[0] == "popup") {
|
||||
const String sname = p_name;
|
||||
if (property_helper.is_property_valid(sname)) {
|
||||
bool valid;
|
||||
popup->set(String(p_name).trim_prefix("popup/"), p_value, &valid);
|
||||
popup->set(sname.trim_prefix("popup/"), p_value, &valid);
|
||||
return valid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MenuButton::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
Vector<String> components = String(p_name).split("/", true, 2);
|
||||
if (components.size() >= 2 && components[0] == "popup") {
|
||||
const String sname = p_name;
|
||||
if (property_helper.is_property_valid(sname)) {
|
||||
bool valid;
|
||||
r_ret = popup->get(String(p_name).trim_prefix("popup/"), &valid);
|
||||
r_ret = popup->get(sname.trim_prefix("popup/"), &valid);
|
||||
return valid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MenuButton::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
for (int i = 0; i < popup->get_item_count(); i++) {
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, vformat("popup/item_%d/text", i)));
|
||||
|
||||
PropertyInfo pi = PropertyInfo(Variant::OBJECT, vformat("popup/item_%d/icon", i), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D");
|
||||
pi.usage &= ~(popup->get_item_icon(i).is_null() ? PROPERTY_USAGE_STORAGE : 0);
|
||||
p_list->push_back(pi);
|
||||
|
||||
pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/checkable", i), PROPERTY_HINT_ENUM, "No,As Checkbox,As Radio Button");
|
||||
pi.usage &= ~(!popup->is_item_checkable(i) ? PROPERTY_USAGE_STORAGE : 0);
|
||||
p_list->push_back(pi);
|
||||
|
||||
pi = PropertyInfo(Variant::BOOL, vformat("popup/item_%d/checked", i));
|
||||
pi.usage &= ~(!popup->is_item_checked(i) ? PROPERTY_USAGE_STORAGE : 0);
|
||||
p_list->push_back(pi);
|
||||
|
||||
pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/id", i), PROPERTY_HINT_RANGE, "0,10,1,or_greater");
|
||||
p_list->push_back(pi);
|
||||
|
||||
pi = PropertyInfo(Variant::BOOL, vformat("popup/item_%d/disabled", i));
|
||||
pi.usage &= ~(!popup->is_item_disabled(i) ? PROPERTY_USAGE_STORAGE : 0);
|
||||
p_list->push_back(pi);
|
||||
|
||||
pi = PropertyInfo(Variant::BOOL, vformat("popup/item_%d/separator", i));
|
||||
pi.usage &= ~(!popup->is_item_separator(i) ? PROPERTY_USAGE_STORAGE : 0);
|
||||
p_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void MenuButton::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_popup"), &MenuButton::get_popup);
|
||||
ClassDB::bind_method(D_METHOD("show_popup"), &MenuButton::show_popup);
|
||||
@@ -215,6 +186,17 @@ void MenuButton::_bind_methods() {
|
||||
ADD_ARRAY_COUNT("Items", "item_count", "set_item_count", "get_item_count", "popup/item_");
|
||||
|
||||
ADD_SIGNAL(MethodInfo("about_to_popup"));
|
||||
|
||||
PopupMenu::Item defaults(true);
|
||||
|
||||
base_property_helper.set_prefix("popup/item_");
|
||||
base_property_helper.register_property(PropertyInfo(Variant::STRING, "text"), defaults.text);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::INT, "checkable", PROPERTY_HINT_ENUM, "No,As Checkbox,As Radio Button"), defaults.checkable_type);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "checked"), defaults.checked);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::INT, "id", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), defaults.id);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "disabled"), defaults.disabled);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "separator"), defaults.separator);
|
||||
}
|
||||
|
||||
void MenuButton::set_disable_shortcuts(bool p_disabled) {
|
||||
@@ -235,6 +217,8 @@ MenuButton::MenuButton(const String &p_text) :
|
||||
add_child(popup, false, INTERNAL_MODE_FRONT);
|
||||
popup->connect("about_to_popup", callable_mp(this, &MenuButton::_popup_visibility_changed).bind(true));
|
||||
popup->connect("popup_hide", callable_mp(this, &MenuButton::_popup_visibility_changed).bind(false));
|
||||
|
||||
property_helper.setup_for_instance(base_property_helper, this);
|
||||
}
|
||||
|
||||
MenuButton::~MenuButton() {
|
||||
|
||||
Reference in New Issue
Block a user