Exemplo n.º 1
0
void PopupMenu::_set_items(const Array& p_items){

	ERR_FAIL_COND(p_items.size() % 10);
	clear();

	for(int i=0;i<p_items.size();i+=10) {

		String text=p_items[i+0];
		Ref<Texture> icon=p_items[i+1];
		bool checkable=p_items[i+2];
		bool checked=p_items[i+3];
		bool disabled=p_items[i+4];

		int id=p_items[i+5];
		int accel=p_items[i+6];
		Variant meta=p_items[i+7];
		String subm=p_items[i+8];
		bool sep=p_items[i+9];

		int idx=get_item_count();
		add_item(text,id);
		set_item_icon(idx,icon);
		set_item_as_checkable(idx,checkable);
		set_item_checked(idx,checked);
		set_item_disabled(idx,disabled);
		set_item_ID(idx,id);
		set_item_metadata(idx,meta);
		set_item_as_separator(idx,sep);
		set_item_accelerator(idx,accel);
		set_item_submenu(idx,subm);
	}


}
bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) {

	String name = p_name;
	int idx = name.get_slice("/",0).to_int();
	String what=name.get_slice("/",1);

	if (what=="text")
		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")
		set_item_checked(idx,p_value);
	else if (what=="id")
		set_item_id(idx,p_value);
	else if (what=="enabled")
		set_item_enabled(idx,p_value);
	else if (what=="separator")
		set_item_separator(idx,p_value);
	else
		return false;

	return true;
}
bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {

	String name = p_name;
	int idx = name.get_slice("/", 0).to_int();
	String what = name.get_slice("/", 1);

	if (what == "text")
		set_item_text(idx, p_value);
	else if (what == "icon")
		set_item_icon(idx, p_value);
	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);
	else if (what == "enabled")
		set_item_enabled(idx, p_value);
	else if (what == "separator")
		set_item_separator(idx, p_value);
	else
		return false;

	return true;
}
Exemplo n.º 4
0
void PopupMenu::_set_items(const Array &p_items) {

	ERR_FAIL_COND(p_items.size() % 10);
	clear();

	for (int i = 0; i < p_items.size(); i += 10) {

		String text = p_items[i + 0];
		Ref<Texture> icon = p_items[i + 1];
		// For compatibility, use false/true for no/checkbox and integers for other values
		bool checkable = p_items[i + 2];
		bool radio_checkable = (int)p_items[i + 2] == Item::CHECKABLE_TYPE_RADIO_BUTTON;
		bool checked = p_items[i + 3];
		bool disabled = p_items[i + 4];

		int id = p_items[i + 5];
		int accel = p_items[i + 6];
		Variant meta = p_items[i + 7];
		String subm = p_items[i + 8];
		bool sep = p_items[i + 9];

		int idx = get_item_count();
		add_item(text, id);
		set_item_icon(idx, icon);
		if (checkable) {
			if (radio_checkable) {
				set_item_as_radio_checkable(idx, true);
			} else {
				set_item_as_checkable(idx, true);
			}
		}
		set_item_checked(idx, checked);
		set_item_disabled(idx, disabled);
		set_item_id(idx, id);
		set_item_metadata(idx, meta);
		set_item_as_separator(idx, sep);
		set_item_accelerator(idx, accel);
		set_item_submenu(idx, subm);
	}
}