Support radio-button entries in ItemListPlugin
(cherry picked from commit bf14a6deff
)
This commit is contained in:
parent
a525ea128d
commit
b5b0e42b85
|
@ -42,9 +42,18 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
|
|||
set_item_text(idx, p_value);
|
||||
else if (what == "icon")
|
||||
set_item_icon(idx, p_value);
|
||||
else if (what == "checkable")
|
||||
set_item_checkable(idx, p_value);
|
||||
else if (what == "checked")
|
||||
else if (what == "checkable") {
|
||||
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
||||
switch ((int)p_value) {
|
||||
case 0:
|
||||
case 1:
|
||||
set_item_checkable(idx, p_value);
|
||||
break;
|
||||
case 2:
|
||||
set_item_radio_checkable(idx, true);
|
||||
break;
|
||||
}
|
||||
} else if (what == "checked")
|
||||
set_item_checked(idx, p_value);
|
||||
else if (what == "id")
|
||||
set_item_id(idx, p_value);
|
||||
|
@ -68,9 +77,14 @@ bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
|
|||
r_ret = get_item_text(idx);
|
||||
else if (what == "icon")
|
||||
r_ret = get_item_icon(idx);
|
||||
else if (what == "checkable")
|
||||
r_ret = is_item_checkable(idx);
|
||||
else if (what == "checked")
|
||||
else if (what == "checkable") {
|
||||
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
||||
if (!is_item_checkable(idx)) {
|
||||
r_ret = 0;
|
||||
} else {
|
||||
r_ret = is_item_radio_checkable(idx) ? 2 : 1;
|
||||
}
|
||||
} else if (what == "checked")
|
||||
r_ret = is_item_checked(idx);
|
||||
else if (what == "id")
|
||||
r_ret = get_item_id(idx);
|
||||
|
@ -95,7 +109,7 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||
int flags = get_flags();
|
||||
|
||||
if (flags & FLAG_CHECKABLE) {
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable", PROPERTY_HINT_ENUM, "No,As checkbox,As radio button"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked"));
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,9 @@ public:
|
|||
virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); };
|
||||
|
||||
virtual void set_item_checkable(int p_idx, bool p_check) {}
|
||||
virtual void set_item_radio_checkable(int p_idx, bool p_check) {}
|
||||
virtual bool is_item_checkable(int p_idx) const { return false; };
|
||||
virtual bool is_item_radio_checkable(int p_idx) const { return false; };
|
||||
|
||||
virtual void set_item_checked(int p_idx, bool p_checked) {}
|
||||
virtual bool is_item_checked(int p_idx) const { return false; };
|
||||
|
@ -145,7 +147,9 @@ public:
|
|||
virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }
|
||||
|
||||
virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); }
|
||||
virtual void set_item_radio_checkable(int p_idx, bool p_check) { pp->set_item_as_radio_checkable(p_idx, p_check); }
|
||||
virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); }
|
||||
virtual bool is_item_radio_checkable(int p_idx) const { return pp->is_item_radio_checkable(p_idx); }
|
||||
|
||||
virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx, p_checked); }
|
||||
virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); }
|
||||
|
|
Loading…
Reference in New Issue