Esempio n. 1
0
void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {

	if (!efsd)
		return;

	for (int i = 0; i < efsd->get_subdir_count(); i++) {
		_fill_owners(efsd->get_subdir(i));
	}

	for (int i = 0; i < efsd->get_file_count(); i++) {

		Vector<String> deps = efsd->get_file_deps(i);
		//print_line(":::"+efsd->get_file_path(i));
		bool found = false;
		for (int j = 0; j < deps.size(); j++) {
			//print_line("\t"+deps[j]+" vs "+editing);
			if (deps[j] == editing) {
				//print_line("found");
				found = true;
				break;
			}
		}
		if (!found)
			continue;

		Ref<Texture> icon;
		String type = efsd->get_file_type(i);
		if (!has_icon(type, "EditorIcons")) {
			icon = get_icon("Object", "EditorIcons");
		} else {
			icon = get_icon(type, "EditorIcons");
		}

		owners->add_item(efsd->get_file_path(i), icon);
	}
}
Esempio n. 2
0
void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root) {

	if (p_types.has(p_type))
		return;
	if (!ObjectTypeDB::is_type(p_type, base) || p_type == base)
		return;

	String inherits = ObjectTypeDB::type_inherits_from(p_type);

	TreeItem *parent = p_root;

	if (inherits.length()) {

		if (!p_types.has(inherits)) {

			add_type(inherits, p_types, p_root);
		}

		if (p_types.has(inherits))
			parent = p_types[inherits];
	}

	TreeItem *item = tree->create_item(parent);
	item->set_text(0, p_type);
	if (!ObjectTypeDB::can_instance(p_type)) {
		item->set_custom_color(0, Color(0.5, 0.5, 0.5));
		item->set_selectable(0, false);
	}

	if (has_icon(p_type, "EditorIcons")) {

		item->set_icon(0, get_icon(p_type, "EditorIcons"));
	}

	p_types[p_type] = item;
}
Esempio n. 3
0
void EditorPath::_add_children_to_popup(Object* p_obj,int p_depth) {

	if (p_depth>8)
		return;

	List<PropertyInfo> pinfo;
	p_obj->get_property_list(&pinfo);
	for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_EDITOR))
			continue;
		if (E->get().hint!=PROPERTY_HINT_RESOURCE_TYPE)
			continue;

		Variant value = p_obj->get(E->get().name);
		if (value.get_type()!=Variant::OBJECT)
			continue;
		Object *obj = value;
		if (!obj)
			continue;

		Ref<Texture> icon;

		if (has_icon(obj->get_class(),"EditorIcons"))
			icon=get_icon(obj->get_class(),"EditorIcons");
		else
			icon=get_icon("Object","EditorIcons");

		int index = popup->get_item_count();
		popup->add_icon_item(icon,E->get().name.capitalize(),objects.size());
		popup->set_item_h_offset(index,p_depth*10*EDSCALE);
		objects.push_back(obj->get_instance_ID());

		_add_children_to_popup(obj,p_depth+1);
	}
}
Esempio n. 4
0
void EditorHelpIndex::add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root) {

	if (p_types.has(p_type))
		return;
//	if (!ObjectTypeDB::is_type(p_type,base) || p_type==base)
//		return;

	String inherits=EditorHelp::get_doc_data()->class_list[p_type].inherits;

	TreeItem *parent=p_root;


	if (inherits.length()) {

		if (!p_types.has(inherits)) {

			add_type(inherits,p_types,p_root);
		}

		if (p_types.has(inherits) )
			parent=p_types[inherits];
	}

	TreeItem *item = class_list->create_item(parent);
	item->set_metadata(0,p_type);
	item->set_tooltip(0,EditorHelp::get_doc_data()->class_list[p_type].brief_description);
	item->set_text(0,p_type);


	if (has_icon(p_type,"EditorIcons")) {

		item->set_icon(0, get_icon(p_type,"EditorIcons"));
	}

	p_types[p_type]=item;
}
Esempio n. 5
0
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) {

	for(int i=0;i<efsd->get_subdir_count();i++) {

		_parse_fs(efsd->get_subdir(i));
	}

	for(int i=0;i<efsd->get_file_count();i++) {

		String file = efsd->get_file_path(i);
		file=file.substr(6,file.length());
		if (ObjectTypeDB::is_type(efsd->get_file_type(i),base_type) && (search_box->get_text()=="" || file.findn(search_box->get_text())!=-1)) {

			TreeItem *root = search_options->get_root();
			TreeItem *ti = search_options->create_item(root);
			ti->set_text(0,file);
			Ref<Texture> icon = get_icon( (has_icon(efsd->get_file_type(i),"EditorIcons")?efsd->get_file_type(i):String("Object")),"EditorIcons");
			ti->set_icon(0,icon);
			if (root->get_children()==ti)
				ti->select(0);

		}
	}
}
bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &anode) {

	if (updating || _filter_edit != anode)
		return false;

	NodePath player_path = anode->get_tree()->get_animation_player();

	if (!anode->get_tree()->has_node(player_path)) {
		EditorNode::get_singleton()->show_warning(TTR("No animation player set, so unable to retrieve track names."));
		return false;
	}

	AnimationPlayer *player = Object::cast_to<AnimationPlayer>(anode->get_tree()->get_node(player_path));
	if (!player) {
		EditorNode::get_singleton()->show_warning(TTR("Player path set is invalid, so unable to retrieve track names."));
		return false;
	}

	Node *base = player->get_node(player->get_root());

	if (!base) {
		EditorNode::get_singleton()->show_warning(TTR("Animation player has no valid root node path, so unable to retrieve track names."));
		return false;
	}

	updating = true;

	Set<String> paths;
	{
		List<StringName> animations;
		player->get_animation_list(&animations);

		for (List<StringName>::Element *E = animations.front(); E; E = E->next()) {

			Ref<Animation> anim = player->get_animation(E->get());
			for (int i = 0; i < anim->get_track_count(); i++) {
				paths.insert(anim->track_get_path(i));
			}
		}
	}

	filter_enabled->set_pressed(anode->is_filter_enabled());
	filters->clear();
	TreeItem *root = filters->create_item();

	Map<String, TreeItem *> parenthood;

	for (Set<String>::Element *E = paths.front(); E; E = E->next()) {

		NodePath path = E->get();
		TreeItem *ti = NULL;
		String accum;
		for (int i = 0; i < path.get_name_count(); i++) {
			String name = path.get_name(i);
			if (accum != String()) {
				accum += "/";
			}
			accum += name;
			if (!parenthood.has(accum)) {
				if (ti) {
					ti = filters->create_item(ti);
				} else {
					ti = filters->create_item(root);
				}
				parenthood[accum] = ti;
				ti->set_text(0, name);
				ti->set_selectable(0, false);
				ti->set_editable(0, false);

				if (base->has_node(accum)) {
					Node *node = base->get_node(accum);
					if (has_icon(node->get_class(), "EditorIcons")) {
						ti->set_icon(0, get_icon(node->get_class(), "EditorIcons"));
					} else {
						ti->set_icon(0, get_icon("Node", "EditorIcons"));
					}
				}

			} else {
				ti = parenthood[accum];
			}
		}

		Node *node = NULL;
		if (base->has_node(accum)) {
			node = base->get_node(accum);
		}
		if (!node)
			continue; //no node, cant edit

		if (path.get_subname_count()) {

			String concat = path.get_concatenated_subnames();

			Skeleton *skeleton = Object::cast_to<Skeleton>(node);
			if (skeleton && skeleton->find_bone(concat) != -1) {
				//path in skeleton
				String bone = concat;
				int idx = skeleton->find_bone(bone);
				List<String> bone_path;
				while (idx != -1) {
					bone_path.push_front(skeleton->get_bone_name(idx));
					idx = skeleton->get_bone_parent(idx);
				}

				accum += ":";
				for (List<String>::Element *F = bone_path.front(); F; F = F->next()) {
					if (F != bone_path.front()) {
						accum += "/";
					}

					accum += F->get();
					if (!parenthood.has(accum)) {
						ti = filters->create_item(ti);
						parenthood[accum] = ti;
						ti->set_text(0, F->get());
						ti->set_selectable(0, false);
						ti->set_editable(0, false);
						ti->set_icon(0, get_icon("BoneAttachment", "EditorIcons"));
					} else {
						ti = parenthood[accum];
					}
				}

				ti->set_editable(0, true);
				ti->set_selectable(0, true);
				ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
				ti->set_text(0, concat);
				ti->set_checked(0, anode->is_path_filtered(path));
				ti->set_icon(0, get_icon("BoneAttachment", "EditorIcons"));
				ti->set_metadata(0, path);

			} else {
				//just a property
				ti = filters->create_item(ti);
				ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
				ti->set_text(0, concat);
				ti->set_editable(0, true);
				ti->set_selectable(0, true);
				ti->set_checked(0, anode->is_path_filtered(path));
				ti->set_metadata(0, path);
			}
		} else {
			if (ti) {
				//just a node, likely call or animation track
				ti->set_editable(0, true);
				ti->set_selectable(0, true);
				ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
				ti->set_checked(0, anode->is_path_filtered(path));
				ti->set_metadata(0, path);
			}
		}
	}

	updating = false;

	return true;
}
Esempio n. 7
0
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<String, Ref<Texture> > > &list) {

	if (!add_directories) {
		for (int i = 0; i < efsd->get_subdir_count(); i++) {

			_parse_fs(efsd->get_subdir(i), list);
		}
	}

	String search_text = search_box->get_text();

	if (add_directories) {
		String path = efsd->get_path();
		if (!path.ends_with("/"))
			path += "/";
		if (path != "res://") {
			path = path.substr(6, path.length());
			if (search_text.is_subsequence_ofi(path)) {
				Pair<String, Ref<Texture> > pair;
				pair.first = path;
				pair.second = get_icon("folder", "FileDialog");

				if (search_text != String() && list.size() > 0) {

					float this_sim = _path_cmp(search_text, path);
					float other_sim = _path_cmp(list[0].first, path);
					int pos = 1;

					while (pos < list.size() && this_sim <= other_sim) {
						other_sim = _path_cmp(list[pos++].first, path);
					}

					pos = this_sim >= other_sim ? pos - 1 : pos;
					list.insert(pos, pair);

				} else {
					list.push_back(pair);
				}
			}
		}
	}
	for (int i = 0; i < efsd->get_file_count(); i++) {

		String file = efsd->get_file_path(i);
		file = file.substr(6, file.length());

		if (ClassDB::is_parent_class(efsd->get_file_type(i), base_type) && (search_text.is_subsequence_ofi(file))) {
			Pair<String, Ref<Texture> > pair;
			pair.first = file;
			pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei);

			if (search_text != String() && list.size() > 0) {

				float this_sim = _path_cmp(search_text, file);
				float other_sim = _path_cmp(list[0].first, file);
				int pos = 1;

				while (pos < list.size() && this_sim <= other_sim) {
					other_sim = _path_cmp(list[pos++].first, file);
				}

				pos = this_sim >= other_sim ? pos - 1 : pos;
				list.insert(pos, pair);

			} else {

				list.push_back(pair);
			}
		}
	}

	if (add_directories) {
		for (int i = 0; i < efsd->get_subdir_count(); i++) {

			_parse_fs(efsd->get_subdir(i), list);
		}
	}
}
void EditorPropertyRootMotion::_node_assign() {

	NodePath current = get_edited_object()->get(get_edited_property());

	AnimationTree *atree = Object::cast_to<AnimationTree>(get_edited_object());
	if (!atree->has_node(atree->get_animation_player())) {
		EditorNode::get_singleton()->show_warning(TTR("AnimationTree has no path set to an AnimationPlayer"));
		return;
	}
	AnimationPlayer *player = Object::cast_to<AnimationPlayer>(atree->get_node(atree->get_animation_player()));
	if (!player) {
		EditorNode::get_singleton()->show_warning(TTR("Path to AnimationPlayer is invalid"));
		return;
	}

	Node *base = player->get_node(player->get_root());

	if (!base) {
		EditorNode::get_singleton()->show_warning(TTR("Animation player has no valid root node path, so unable to retrieve track names."));
		return;
	}

	Set<String> paths;
	{
		List<StringName> animations;
		player->get_animation_list(&animations);

		for (List<StringName>::Element *E = animations.front(); E; E = E->next()) {

			Ref<Animation> anim = player->get_animation(E->get());
			for (int i = 0; i < anim->get_track_count(); i++) {
				paths.insert(anim->track_get_path(i));
			}
		}
	}

	filters->clear();
	TreeItem *root = filters->create_item();

	Map<String, TreeItem *> parenthood;

	for (Set<String>::Element *E = paths.front(); E; E = E->next()) {

		NodePath path = E->get();
		TreeItem *ti = NULL;
		String accum;
		for (int i = 0; i < path.get_name_count(); i++) {
			String name = path.get_name(i);
			if (accum != String()) {
				accum += "/";
			}
			accum += name;
			if (!parenthood.has(accum)) {
				if (ti) {
					ti = filters->create_item(ti);
				} else {
					ti = filters->create_item(root);
				}
				parenthood[accum] = ti;
				ti->set_text(0, name);
				ti->set_selectable(0, false);
				ti->set_editable(0, false);

				if (base->has_node(accum)) {
					Node *node = base->get_node(accum);
					if (has_icon(node->get_class(), "EditorIcons")) {
						ti->set_icon(0, get_icon(node->get_class(), "EditorIcons"));
					} else {
						ti->set_icon(0, get_icon("Node", "EditorIcons"));
					}
				}

			} else {
				ti = parenthood[accum];
			}
		}

		Node *node = NULL;
		if (base->has_node(accum)) {
			node = base->get_node(accum);
		}
		if (!node)
			continue; //no node, cant edit

		if (path.get_subname_count()) {

			String concat = path.get_concatenated_subnames();

			Skeleton *skeleton = Object::cast_to<Skeleton>(node);
			if (skeleton && skeleton->find_bone(concat) != -1) {
				//path in skeleton
				String bone = concat;
				int idx = skeleton->find_bone(bone);
				List<String> bone_path;
				while (idx != -1) {
					bone_path.push_front(skeleton->get_bone_name(idx));
					idx = skeleton->get_bone_parent(idx);
				}

				accum += ":";
				for (List<String>::Element *F = bone_path.front(); F; F = F->next()) {
					if (F != bone_path.front()) {
						accum += "/";
					}

					accum += F->get();
					if (!parenthood.has(accum)) {
						ti = filters->create_item(ti);
						parenthood[accum] = ti;
						ti->set_text(0, F->get());
						ti->set_selectable(0, true);
						ti->set_editable(0, false);
						ti->set_icon(0, get_icon("BoneAttachment", "EditorIcons"));
						ti->set_metadata(0, accum);
					} else {
						ti = parenthood[accum];
					}
				}

				ti->set_selectable(0, true);
				ti->set_text(0, concat);
				ti->set_icon(0, get_icon("BoneAttachment", "EditorIcons"));
				ti->set_metadata(0, path);
				if (path == current) {
					ti->select(0);
				}

			} else {
				//just a property
				ti = filters->create_item(ti);
				ti->set_text(0, concat);
				ti->set_selectable(0, true);
				ti->set_metadata(0, path);
				if (path == current) {
					ti->select(0);
				}
			}
		} else {
			if (ti) {
				//just a node, likely call or animation track
				ti->set_selectable(0, true);
				ti->set_metadata(0, path);
				if (path == current) {
					ti->select(0);
				}
			}
		}
	}

	filters->ensure_cursor_is_visible();
	filter_dialog->popup_centered_ratio();
}
Esempio n. 9
0
void EditorPath::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_DRAW: {

			RID ci=get_canvas_item();
			Ref<Font> label_font = get_font("font","Label");
			Color label_color = get_color("font_color","Label");
			Size2i size = get_size();
			Ref<Texture> sn = get_icon("SmallNext","EditorIcons");

			int ofs=5;
			for(int i=0;i<history->get_path_size();i++) {

				Object *obj = ObjectDB::get_instance(history->get_path_object(i));
				if (!obj)
					continue;

				String type = obj->get_type();

				Ref<Texture> icon;

				if (has_icon(obj->get_type(),"EditorIcons"))
					icon=get_icon(obj->get_type(),"EditorIcons");
				else
					icon=get_icon("Object","EditorIcons");


				icon->draw(ci,Point2i(ofs,(size.height-icon->get_height())/2));

				ofs+=icon->get_width();

				if (i==history->get_path_size()-1) {
					//add name
					ofs+=4;
					int left = size.width - ofs;
					if (left<0)
						continue;
					String name;
					if (obj->cast_to<Resource>()) {

						Resource *r = obj->cast_to<Resource>();
						name=r->get_name();
						if (name=="")
							name=r->get_type();
					} else if (obj->cast_to<Node>()) {

						name=obj->cast_to<Node>()->get_name();
					} else if (obj->cast_to<Resource>() && obj->cast_to<Resource>()->get_name()!="") {
						name=obj->cast_to<Resource>()->get_name();
					} else {
						name=obj->get_type();
					}

					set_tooltip(obj->get_type());


					label_font->draw(ci,Point2i(ofs,(size.height-label_font->get_height())/2+label_font->get_ascent()),name,Color(1,1,1),left);
				} else {
					//add arrow

					//sn->draw(ci,Point2i(ofs,(size.height-sn->get_height())/2));
					//ofs+=sn->get_width();
					ofs+=5; //just looks better! somehow

				}
			}

		} break;
	}
}
Esempio n. 10
0
void CreateDialog::popup(bool p_dontclear) {

	recent->clear();

	FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::READ);

	if (f) {

		TreeItem *root = recent->create_item();

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {

				TreeItem *ti = recent->create_item(root);
				ti->set_text(0, l);
				if (has_icon(l, "EditorIcons")) {

					ti->set_icon(0, get_icon(l, "EditorIcons"));
				} else {
					ti->set_icon(0, get_icon("Object", "EditorIcons"));
				}
			}
		}

		memdelete(f);
	}

	favorites->clear();

	f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites." + base_type), FileAccess::READ);

	favorite_list.clear();

	if (f) {

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {
				favorite_list.push_back(l);
			}
		}

		memdelete(f);
	} else {
#if 0
// I think this was way too confusing
		if (base_type=="Node") {
			//harcode some favorites :D
			favorite_list.push_back("Panel");
			favorite_list.push_back("Button");
			favorite_list.push_back("Label");
			favorite_list.push_back("LineEdit");
			favorite_list.push_back("Node2D");
			favorite_list.push_back("Sprite");
			favorite_list.push_back("Camera2D");
			favorite_list.push_back("Area2D");
			favorite_list.push_back("CollisionShape2D");
			favorite_list.push_back("Spatial");
			favorite_list.push_back("Camera");
			favorite_list.push_back("Area");
			favorite_list.push_back("CollisionShape");
			favorite_list.push_back("TestCube");
			favorite_list.push_back("AnimationPlayer");

		}
#endif
	}

	_update_favorite_list();

	popup_centered_ratio();
	if (p_dontclear)
		search_box->select_all();
	else {
		search_box->clear();
	}
	search_box->grab_focus();

	_update_search();
}
Esempio n. 11
0
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {


	TreeItem *item = tree->create_item(p_parent);
	String dname=p_dir->get_name();
	if (dname=="")
		dname="res://";

	item->set_text(0,dname);
	item->set_icon(0,get_icon("Folder","EditorIcons"));
	item->set_selectable(0,true);
	String lpath = p_dir->get_path();
	if (lpath!="res://" && lpath.ends_with("/")) {
		lpath=lpath.substr(0,lpath.length()-1);
	}
	item->set_metadata(0,lpath);
	if (lpath==path) {
		item->select(0);
	}


	//item->set_custom_bg_color(0,get_color("prop_subsection","Editor"));

	bool has_items=false;

	for(int i=0;i<p_dir->get_subdir_count();i++) {

		if (_create_tree(item,p_dir->get_subdir(i)))
			has_items=true;
	}
#if 0
	for (int i=0;i<p_dir->get_file_count();i++) {

		String file_name = p_dir->get_file(i);
		String file_path = p_dir->get_file_path(i);

		// ScenesDockFilter::FILTER_PATH
		String search_from = file_path.right(6); // trim "res://"
		if (file_filter == ScenesDockFilter::FILTER_NAME)
			 search_from = file_name;
		else if (file_filter == ScenesDockFilter::FILTER_FOLDER)
			search_from = file_path.right(6).get_base_dir();

		if (search_term!="" && search_from.findn(search_term)==-1)
			continue;

		bool isfave = favorites.has(file_path);
		if (button_favorite->is_pressed() && !isfave)
			continue;

		TreeItem *fitem = tree->create_item(item);
		fitem->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		fitem->set_editable(0,true);
		fitem->set_checked(0,isfave);
		fitem->set_text(0,file_name);

		Ref<Texture> icon = get_icon( (has_icon(p_dir->get_file_type(i),"EditorIcons")?p_dir->get_file_type(i):String("Object")),"EditorIcons");
		fitem->set_icon(0, icon );


		fitem->set_metadata(0,file_path);
		//if (p_dir->files[i]->icon.is_valid()) {
//			fitem->set_icon(0,p_dir->files[i]->icon);
//		}
		has_items=true;

	}
#endif
	/*if (!has_items) {

		memdelete(item);
		return false;

	}*/

	return true;
}
Esempio n. 12
0
void EditorHelpSearch::_update_search() {

	search_options->clear();
	search_options->set_hide_root(true);

	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	List<String> type_list;
	ObjectTypeDB::get_type_list(&type_list);

	DocData *doc=EditorHelp::get_doc_data();
	String term = search_box->get_text();
	if (term.length()<3)
		return;

	TreeItem *root = search_options->create_item();



	Ref<Texture> def_icon = get_icon("Node","EditorIcons");
	//classes first
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {

		if (E->key().findn(term)!=-1) {

			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_name:"+E->key());
			item->set_text(0,E->key()+" (Class)");
			if (has_icon(E->key(),"EditorIcons"))
				item->set_icon(0,get_icon(E->key(),"EditorIcons"));
			else
				item->set_icon(0,def_icon);


		}

	}

	//class methods, etc second
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;

		for(int i=0;i<c.methods.size();i++) {
			if( (term.begins_with(".") && c.methods[i].name.begins_with(term.right(1)))
				|| (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length()-1).strip_edges()))
				|| (term.begins_with(".") && term.ends_with("(") && c.methods[i].name==term.substr(1,term.length()-2).strip_edges())
				|| c.methods[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.theme_properties.size();i++) {

			if (c.theme_properties[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_theme_item:"+E->key()+":"+c.theme_properties[i].name);
				item->set_text(0,E->key()+"."+c.theme_properties[i].name+" (Theme Item)");
				item->set_icon(0,cicon);
			}
		}


	}

	//same but descriptions

	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;

		if (c.description.findn(term)!=-1) {


			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_desc:"+E->key());
			item->set_text(0,E->key()+" (Class Description)");
			item->set_icon(0,cicon);

		}

		for(int i=0;i<c.methods.size();i++) {

			if (c.methods[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method_desc:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property_desc:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property Description)");
				item->set_icon(0,cicon);
			}
		}

	}

	get_ok()->set_disabled(root->get_children()==NULL);

}
Esempio n. 13
0
void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) {

	if (p_types.has(p_type))
		return;

	bool cpp_type = ClassDB::class_exists(p_type);
	EditorData &ed = EditorNode::get_singleton()->get_editor_data();

	if (p_type == base_type)
		return;

	if (cpp_type) {
		if (!ClassDB::is_parent_class(p_type, base_type))
			return;
	} else {
		if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type))
			return;

		String script_path = ScriptServer::get_global_class_path(p_type);
		if (script_path.find("res://addons/", 0) != -1) {
			if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3)))
				return;
		}
	}

	String inherits = cpp_type ? ClassDB::get_parent_class(p_type) : ed.script_class_get_base(p_type);

	TreeItem *parent = p_root;

	if (inherits.length()) {

		if (!p_types.has(inherits)) {

			add_type(inherits, p_types, p_root, to_select);
		}

		if (p_types.has(inherits))
			parent = p_types[inherits];
		else if (ScriptServer::is_global_class(inherits))
			return;
	}

	bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);

	TreeItem *item = search_options->create_item(parent);
	if (cpp_type) {
		item->set_text(0, p_type);
	} else {
		item->set_metadata(0, p_type);
		item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
	}
	if (!can_instance) {
		item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
		item->set_selectable(0, false);
	} else {
		bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type);
		String to_select_type = *to_select ? (*to_select)->get_text(0) : "";
		to_select_type = to_select_type.split(" ")[0];
		bool current_item_is_preffered;
		if (cpp_type) {
			current_item_is_preffered = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(to_select_type, preferred_search_result_type);
		} else {
			current_item_is_preffered = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type);
		}
		if (*to_select && p_type.length() < (*to_select)->get_text(0).length()) {
			current_item_is_preffered = true;
		}

		if (((!*to_select || current_item_is_preffered) && is_search_subsequence) || search_box->get_text() == p_type) {
			*to_select = item;
		}
	}

	if (bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) {
		item->set_collapsed(false);
	} else {
		// don't collapse search results
		bool collapse = (search_box->get_text() == "");
		// don't collapse the root node
		collapse &= (item != p_root);
		// don't collapse abstract nodes on the first tree level
		collapse &= ((parent != p_root) || (can_instance));
		item->set_collapsed(collapse);
	}

	const String &description = EditorHelp::get_doc_data()->class_list[p_type].brief_description;
	item->set_tooltip(0, description);

	if (cpp_type && has_icon(p_type, "EditorIcons")) {

		item->set_icon(0, get_icon(p_type, "EditorIcons"));
	} else if (!cpp_type && has_icon(ScriptServer::get_global_class_base(p_type), "EditorIcons")) {

		item->set_icon(0, get_icon(ScriptServer::get_global_class_base(p_type), "EditorIcons"));
	}

	p_types[p_type] = item;
}
Esempio n. 14
0
void SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) {
	
	if (!p_node)
		return;

	// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
	// which the editor needs not to know about.

	bool part_of_subscene=false;

	if (!display_foreign && p_node->get_owner()!=get_scene_node()  && p_node!=get_scene_node()) {

		if ((show_enabled_subscene || can_open_instance) && p_node->get_owner() && (get_scene_node()->is_editable_instance(p_node->get_owner()))) {

			part_of_subscene=true;
			//allow
		} else {
			return;
		}
	} else {
		part_of_subscene = get_scene_node()->get_scene_inherited_state().is_valid() && get_scene_node()->get_scene_inherited_state()->find_node_by_path(get_scene_node()->get_path_to(p_node))>=0;
	}

	TreeItem *item = tree->create_item(p_parent);
	item->set_text(0, p_node->get_name() );
	if (can_rename && !part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/)
		item->set_editable(0, true);

	item->set_selectable(0,true);
	if (can_rename) {

		bool collapsed = p_node->has_meta("_editor_collapsed") ? (bool)p_node->get_meta("_editor_collapsed") : false;
		if (collapsed)
			item->set_collapsed(true);
	}

	Ref<Texture> icon;
	if (p_node->has_meta("_editor_icon"))
		icon=p_node->get_meta("_editor_icon");
	else
		icon=get_icon( (has_icon(p_node->get_type(),"EditorIcons")?p_node->get_type():String("Object")),"EditorIcons");
	item->set_icon(0, icon );
	item->set_metadata( 0,p_node->get_path() );	

	if (part_of_subscene) {

		//item->set_selectable(0,marked_selectable);
		item->set_custom_color(0,Color(0.8,0.4,0.20));

	} else if (marked.has(p_node)) {
				
		item->set_selectable(0,marked_selectable);
		item->set_custom_color(0,Color(0.8,0.1,0.10));
	} else if (!marked_selectable && !marked_children_selectable) {

		Node *node=p_node;
		while(node) {
			if (marked.has(node)) {
				item->set_selectable(0,false);
				item->set_custom_color(0,Color(0.8,0.1,0.10));
				break;
			}
			node=node->get_parent();
		}
	}

	if (p_node==get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
		item->add_button(0,get_icon("InstanceOptions","EditorIcons"),BUTTON_SUBSCENE);
		item->set_tooltip(0,"Inherits: "+p_node->get_scene_inherited_state()->get_path()+"\nType: "+p_node->get_type());
	} else if (p_node!=get_scene_node() && p_node->get_filename()!="" && can_open_instance) {

		item->add_button(0,get_icon("InstanceOptions","EditorIcons"),BUTTON_SUBSCENE);
		item->set_tooltip(0,"Instance: "+p_node->get_filename()+"\nType: "+p_node->get_type());
	} else {
		item->set_tooltip(0,String(p_node->get_name())+"\nType: "+p_node->get_type());
	}

	if (can_open_instance) {

		if (!p_node->is_connected("script_changed",this,"_node_script_changed"))
			p_node->connect("script_changed",this,"_node_script_changed",varray(p_node));


		if (!p_node->get_script().is_null()) {

			item->add_button(0,get_icon("Script","EditorIcons"),BUTTON_SCRIPT);
		}

		if (p_node->is_type("CanvasItem")) {

			bool is_locked = p_node->has_meta("_edit_lock_");//_edit_group_
			if (is_locked)
				item->add_button(0,get_icon("Lock", "EditorIcons"), BUTTON_LOCK);

			bool is_grouped = p_node->has_meta("_edit_group_");
			if (is_grouped)
				item->add_button(0,get_icon("Group", "EditorIcons"), BUTTON_GROUP);

			bool h = p_node->call("is_hidden");
			if (h)
				item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY);
			else
				item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY);

			if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed"))
				p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node));

		} else if (p_node->is_type("Spatial")) {

			bool h = p_node->call("is_hidden");
			if (h)
				item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY);
			else
				item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY);

			if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed"))
				p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node));

		}

	}

	if (editor_selection) {
		if (editor_selection->is_selected(p_node)) {

			item->select(0);
		}
	}

	if (selected==p_node) {
		if (!editor_selection)
			item->select(0);
		item->set_as_cursor(0);
	}
		
	for (int i=0;i<p_node->get_child_count();i++) {
		
		_add_nodes(p_node->get_child(i),item);
	}
}
Esempio n. 15
0
bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd,HashMap<String,int>& refs,TreeItem* p_parent){


	if (!efsd)
		return false;

	bool has_childs=false;

	for(int i=0;i<efsd->get_subdir_count();i++) {

		TreeItem *dir_item=NULL;
		if (p_parent) {
			dir_item = files->create_item(p_parent);
			dir_item->set_text(0,efsd->get_subdir(i)->get_name());
			dir_item->set_icon(0,get_icon("folder","FileDialog"));

		}
		bool children = _fill_owners(efsd->get_subdir(i),refs,dir_item);

		if (p_parent) {
			if (!children) {
				memdelete(dir_item);
			} else {
				has_childs=true;
			}
		}

	}


	for(int i=0;i<efsd->get_file_count();i++) {

		if (!p_parent) {
			Vector<String> deps = efsd->get_file_deps(i);
			//print_line(":::"+efsd->get_file_path(i));
			for(int j=0;j<deps.size();j++) {

				if (!refs.has(deps[j])) {
					refs[deps[j]]=1;
				}
			}
		} else {

			String path = efsd->get_file_path(i);
			if (!refs.has(path)) {
				TreeItem *ti=files->create_item(p_parent);
				ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
				ti->set_text(0,efsd->get_file(i));
				ti->set_editable(0,true);

				String type=efsd->get_file_type(i);

				Ref<Texture> icon;
				if (has_icon(type,TTR("EditorIcons"))) {
					icon=get_icon(type,"EditorIcons");
				} else {
					icon=get_icon("Object","EditorIcons");
				}
				ti->set_icon(0,icon);
				int ds = efsd->get_file_deps(i).size();
				ti->set_text(1,itos(ds));
				if (ds) {
					ti->add_button(1,get_icon("Visible","EditorIcons"));
				}
				ti->set_metadata(0,path);
				has_childs=true;
			}
		}

	}

	return has_childs;
}
Esempio n. 16
0
void CreateDialog::_update_search() {


	search_options->clear();

	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	List<StringName> type_list;
	ObjectTypeDB::get_type_list(&type_list);

	HashMap<String,TreeItem*> types;

	TreeItem *root = search_options->create_item();

	root->set_text(0,base_type);
	if (has_icon(base_type,"EditorIcons")) {
		root->set_icon(0,get_icon(base_type,"EditorIcons"));
	}

	List<StringName>::Element *I=type_list.front();
	TreeItem *to_select=NULL;

	for(;I;I=I->next()) {



		String type=I->get();

		if (base_type=="Node" && type.begins_with("Editor"))
			continue; // do not show editor nodes

		if (!ObjectTypeDB::can_instance(type))
			continue; // cant create what can't be instanced

		if (search_box->get_text()=="") {
			add_type(type,types,root,&to_select);
		} else {

			bool found=false;
			String type=I->get();
			while(type!="" && ObjectTypeDB::is_type(type,base_type) && type!=base_type) {
				if (search_box->get_text().is_subsequence_ofi(type)) {

					found=true;
					break;
				}

				type=ObjectTypeDB::type_inherits_from(type);
			}


			if (found)
				add_type(I->get(),types,root,&to_select);
		}

		if (EditorNode::get_editor_data().get_custom_types().has(type) && ObjectTypeDB::is_type(type, base_type)) {
			//there are custom types based on this... cool.
			//print_line("there are custom types");


			const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
			for(int i=0;i<ct.size();i++) {

				bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);

				if (!show)
					continue;

				if (!types.has(type))
					add_type(type,types,root,&to_select);

				TreeItem *ti;
				if (types.has(type) )
					ti=types[type];
				else
					ti=search_options->get_root();


				TreeItem *item = search_options->create_item(ti);
				item->set_metadata(0,type);
				item->set_text(0,ct[i].name);
				if (ct[i].icon.is_valid()) {
					item->set_icon(0,ct[i].icon);

				}

				if (!to_select) {
					to_select=item;
				}

			}

		}
	}

	if (to_select)
		to_select->select(0);

	get_ok()->set_disabled(root->get_children()==NULL);

}
Esempio n. 17
0
void CallDialog::_update_method_list() {
	
	tree->clear();
	if (!object)
		return;
		
	TreeItem *root = tree->create_item();
	
	List<MethodInfo> method_list;
	object->get_method_list(&method_list);
	method_list.sort();
	methods.clear();
	
	List<String> inheritance_list;
	
	String type = object->get_type();
	
	while(type!="") {		
		inheritance_list.push_back( type );
		type=ObjectTypeDB::type_inherits_from(type);
	}
	
	TreeItem *selected_item=NULL;
	
	for(int i=0;i<inheritance_list.size();i++) {
	
		String type=inheritance_list[i];
		String parent_type=ObjectTypeDB::type_inherits_from(type);

		TreeItem *type_item=NULL;
	
		List<MethodInfo>::Element *N,*E=method_list.front();
		
		while(E) {

			N=E->next();

			if (parent_type!="" && ObjectTypeDB::get_method(parent_type,E->get().name)!=NULL) {
				E=N;
				continue;
			}
				
			if (!type_item) {
				type_item=tree->create_item(root);
				type_item->set_text(0,type);
				if (has_icon(type,"EditorIcons"))
					type_item->set_icon(0,get_icon(type,"EditorIcons"));
			}
				
			TreeItem *method_item = tree->create_item(type_item);
			method_item->set_text(0,E->get().name);
			method_item->set_metadata(0,methods.size());
			if (E->get().name==selected)
				selected_item=method_item;
			methods.push_back( E->get() );
			
			method_list.erase(E);
			E=N;
		}
	}
	
	
	
	if (selected_item)
		selected_item->select(0);
}
Esempio n. 18
0
void PropertySelector::_update_search() {


	if (properties)
		set_title(TTR("Select Property"));
	else
		set_title(TTR("Select Method"));

	search_options->clear();
	help_bit->set_text("");


	TreeItem *root = search_options->create_item();


	if (properties) {

		List<PropertyInfo> props;

		if (instance) {
			instance->get_property_list(&props,true);
		} else if (type!=Variant::NIL) {
			Variant v;
			if (type==Variant::INPUT_EVENT) {
				InputEvent ie;
				ie.type=event_type;
				v=ie;
			} else {
				Variant::CallError ce;
				v=Variant::construct(type,NULL,0,ce);
			}

			v.get_property_list(&props);
		} else {


			Object *obj = ObjectDB::get_instance(script);
			if (obj && obj->cast_to<Script>()) {

				props.push_back(PropertyInfo(Variant::NIL,"Script Variables",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_CATEGORY));
				obj->cast_to<Script>()->get_script_property_list(&props);
			}

			StringName base=base_type;
			while(base) {
				props.push_back(PropertyInfo(Variant::NIL,base,PROPERTY_HINT_NONE,"",PROPERTY_USAGE_CATEGORY));
				ObjectTypeDB::get_property_list(base,&props,true);
				base=ObjectTypeDB::type_inherits_from(base);
			}

		}

		TreeItem *category=NULL;

		bool found=false;

		Ref<Texture> type_icons[Variant::VARIANT_MAX]={
			Control::get_icon("MiniVariant","EditorIcons"),
			Control::get_icon("MiniBoolean","EditorIcons"),
			Control::get_icon("MiniInteger","EditorIcons"),
			Control::get_icon("MiniFloat","EditorIcons"),
			Control::get_icon("MiniString","EditorIcons"),
			Control::get_icon("MiniVector2","EditorIcons"),
			Control::get_icon("MiniRect2","EditorIcons"),
			Control::get_icon("MiniVector3","EditorIcons"),
			Control::get_icon("MiniMatrix2","EditorIcons"),
			Control::get_icon("MiniPlane","EditorIcons"),
			Control::get_icon("MiniQuat","EditorIcons"),
			Control::get_icon("MiniAabb","EditorIcons"),
			Control::get_icon("MiniMatrix3","EditorIcons"),
			Control::get_icon("MiniTransform","EditorIcons"),
			Control::get_icon("MiniColor","EditorIcons"),
			Control::get_icon("MiniImage","EditorIcons"),
			Control::get_icon("MiniPath","EditorIcons"),
			Control::get_icon("MiniRid","EditorIcons"),
			Control::get_icon("MiniObject","EditorIcons"),
			Control::get_icon("MiniInput","EditorIcons"),
			Control::get_icon("MiniDictionary","EditorIcons"),
			Control::get_icon("MiniArray","EditorIcons"),
			Control::get_icon("MiniRawArray","EditorIcons"),
			Control::get_icon("MiniIntArray","EditorIcons"),
			Control::get_icon("MiniFloatArray","EditorIcons"),
			Control::get_icon("MiniStringArray","EditorIcons"),
			Control::get_icon("MiniVector2Array","EditorIcons"),
			Control::get_icon("MiniVector3Array","EditorIcons"),
			Control::get_icon("MiniColorArray","EditorIcons")
		};


		for (List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
			if (E->get().usage==PROPERTY_USAGE_CATEGORY) {
				if (category && category->get_children()==NULL) {
					memdelete(category); //old category was unused
				}
				category = search_options->create_item(root);
				category->set_text(0,E->get().name);
				category->set_selectable(0,false);

				Ref<Texture> icon;
				if (E->get().name=="Script Variables") {
					icon=get_icon("Script","EditorIcons");
				} else if (has_icon(E->get().name,"EditorIcons")) {
					icon=get_icon(E->get().name,"EditorIcons");
				} else {
					icon=get_icon("Object","EditorIcons");
				}
				category->set_icon(0,icon);
				continue;
			}

			if (!(E->get().usage&PROPERTY_USAGE_EDITOR))
				continue;

			if (search_box->get_text()!=String() && E->get().name.find(search_box->get_text())==-1)
				continue;
			TreeItem *item = search_options->create_item(category?category:root);
			item->set_text(0,E->get().name);
			item->set_metadata(0,E->get().name);
			item->set_icon(0,type_icons[E->get().type]);

			if (!found && search_box->get_text()!=String() && E->get().name.find(search_box->get_text())!=-1) {
				item->select(0);
				found=true;
			}

			item->set_selectable(0,true);
		}

		if (category && category->get_children()==NULL) {
			memdelete(category); //old category was unused
		}
	} else {

		List<MethodInfo> methods;

		if (type!=Variant::NIL) {
			Variant v;
			Variant::CallError ce;
			v=Variant::construct(type,NULL,0,ce);
			v.get_method_list(&methods);
		} else {


			Object *obj = ObjectDB::get_instance(script);
			if (obj && obj->cast_to<Script>()) {

				methods.push_back(MethodInfo("*Script Methods"));
				obj->cast_to<Script>()->get_script_method_list(&methods);
			}

			StringName base=base_type;
			while(base) {
				methods.push_back(MethodInfo("*"+String(base)));
				ObjectTypeDB::get_method_list(base,&methods,true);
				base=ObjectTypeDB::type_inherits_from(base);
			}

		}

		TreeItem *category=NULL;

		bool found=false;
		bool script_methods=false;

		for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
			if (E->get().name.begins_with("*")) {
				if (category && category->get_children()==NULL) {
					memdelete(category); //old category was unused
				}
				category = search_options->create_item(root);
				category->set_text(0,E->get().name.replace_first("*",""));
				category->set_selectable(0,false);

				Ref<Texture> icon;
				script_methods=false;
				if (E->get().name=="*Script Methods") {
					icon=get_icon("Script","EditorIcons");
					script_methods=true;
				} else if (has_icon(E->get().name,"EditorIcons")) {
					icon=get_icon(E->get().name,"EditorIcons");
				} else {
					icon=get_icon("Object","EditorIcons");
				}
				category->set_icon(0,icon);

				continue;
			}

			String name = E->get().name.get_slice(":",0);
			if (!script_methods && name.begins_with("_") && !(E->get().flags&METHOD_FLAG_VIRTUAL))
				continue;

			if (search_box->get_text()!=String() && name.find(search_box->get_text())==-1)
				continue;

			TreeItem *item = search_options->create_item(category?category:root);

			MethodInfo mi=E->get();

			String desc;
			if (mi.name.find(":")!=-1) {
				desc=mi.name.get_slice(":",1)+" ";
				mi.name=mi.name.get_slice(":",0);
			} else if (mi.return_val.type!=Variant::NIL)
				desc=Variant::get_type_name(mi.return_val.type);
			else
				desc="void ";



			desc+=" "+mi.name+" ( ";

			for(int i=0;i<mi.arguments.size();i++) {

				if (i>0)
					desc+=", ";

				if (mi.arguments[i].type==Variant::NIL)
					desc+="var ";
				else if (mi.arguments[i].name.find(":")!=-1) {
					desc+=mi.arguments[i].name.get_slice(":",1)+" ";
					mi.arguments[i].name=mi.arguments[i].name.get_slice(":",0);
				} else
					desc+=Variant::get_type_name(mi.arguments[i].type)+" ";

				desc+=mi.arguments[i].name;

			}

			desc+=" )";

			item->set_text(0,desc);
			item->set_metadata(0,name);
			item->set_selectable(0,true);

			if (!found && search_box->get_text()!=String() && name.find(search_box->get_text())!=-1) {
				item->select(0);
				found=true;
			}

		}

		if (category && category->get_children()==NULL) {
			memdelete(category); //old category was unused
		}

	}

	get_ok()->set_disabled(root->get_children()==NULL);

}
Esempio n. 19
0
void FileSystemDock::_update_files(bool p_keep_selection) {

	Set<String> cselection;

	if (p_keep_selection) {

		for(int i=0;i<files->get_item_count();i++) {

			if (files->is_selected(i))
				cselection.insert(files->get_item_text(i));
		}
	}

	files->clear();

	current_path->set_text(path);


	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

	int thumbnail_size = EditorSettings::get_singleton()->get("filesystem_dock/thumbnail_size");
	thumbnail_size*=EDSCALE;
	Ref<Texture> folder_thumbnail;
	Ref<Texture> file_thumbnail;

	bool use_thumbnails = (display_mode == DISPLAY_THUMBNAILS);
	bool use_folders = search_box->get_text().length()==0 && split_mode;

	if (use_thumbnails) { //thumbnails

		files->set_max_columns(0);
		files->set_icon_mode(ItemList::ICON_MODE_TOP);
		files->set_fixed_column_width(thumbnail_size*3/2);
		files->set_max_text_lines(2);
		files->set_fixed_icon_size(Size2(thumbnail_size,thumbnail_size));

		if (!has_icon("ResizedFolder","EditorIcons")) {
			Ref<ImageTexture> folder = get_icon("FolderBig","EditorIcons");
			Image img = folder->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_folder = Ref<ImageTexture>( memnew( ImageTexture));
			resized_folder->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		folder_thumbnail = get_icon("ResizedFolder","EditorIcons");

		if (!has_icon("ResizedFile","EditorIcons")) {
			Ref<ImageTexture> file = get_icon("FileBig","EditorIcons");
			Image img = file->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_file = Ref<ImageTexture>( memnew( ImageTexture));
			resized_file->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

		file_thumbnail = get_icon("ResizedFile","EditorIcons");

	} else {

		files->set_icon_mode(ItemList::ICON_MODE_LEFT);
		files->set_max_columns(1);
		files->set_max_text_lines(1);
		files->set_fixed_column_width(0);
		files->set_fixed_icon_size(Size2());

	}

	if (use_folders) {

		if (path!="res://") {

			if (use_thumbnails) {
				files->add_item("..",folder_thumbnail,true);
			} else {
				files->add_item("..",get_icon("folder","FileDialog"),true);
			}

			String bd = path.get_base_dir();
			if (bd!="res://" && !bd.ends_with("/"))
				bd+="/";

			files->set_item_metadata(files->get_item_count()-1,bd);
		}

		for(int i=0;i<efd->get_subdir_count();i++) {

			String dname=efd->get_subdir(i)->get_name();


			if (use_thumbnails) {
				files->add_item(dname,folder_thumbnail,true);
			} else {
				files->add_item(dname,get_icon("folder","FileDialog"),true);
			}

			files->set_item_metadata(files->get_item_count()-1,path.plus_file(dname)+"/");

			if (cselection.has(dname))
				files->select(files->get_item_count()-1,false);
		}
	}


	List<FileInfo> filelist;

	if (search_box->get_text().length()) {

		if (search_box->get_text().length()>1) {
			_search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128);
		}

		filelist.sort();
	} else {

		for(int i=0;i<efd->get_file_count();i++) {

			FileInfo fi;
			fi.name=efd->get_file(i);
			fi.path=path.plus_file(fi.name);
			fi.type=efd->get_file_type(i);
			if (efd->get_file_meta(i)) {
				if (efd->is_missing_sources(i)) {
					fi.import_status=3;
				} else if (efd->have_sources_changed(i)) {
					fi.import_status=2;
				} else {
					fi.import_status=1;
				}

				for(int j=0;j<efd->get_source_count(i);j++) {
					String s = EditorImportPlugin::expand_source_path(efd->get_source_file(i,j));
					if (efd->is_source_file_missing(i,j)) {
						s+=" (Missing)";
					}
					fi.sources.push_back(s);
				}
			} else {
				fi.import_status=0;
			}



			filelist.push_back(fi);
		}
	}

	StringName ei="EditorIcons"; //make it faster..
	StringName oi="Object";


	for(List<FileInfo>::Element *E=filelist.front();E;E=E->next()) {
		String fname=E->get().name;
		String fp = E->get().path;
		StringName type = E->get().type;

		Ref<Texture> type_icon;

		String tooltip=fname;

		if (E->get().import_status==0) {

			if (has_icon(type,ei)) {
				type_icon=get_icon(type,ei);
			} else {
				type_icon=get_icon(oi,ei);
			}
		} else if (E->get().import_status==1) {
			type_icon=get_icon("DependencyOk","EditorIcons");
		} else if (E->get().import_status==2) {
			type_icon=get_icon("DependencyChanged","EditorIcons");
			tooltip+"\nStatus: Needs Re-Import";
		} else if (E->get().import_status==3) {
			type_icon=get_icon("ImportFail","EditorIcons");
			tooltip+"\nStatus: Missing Dependencies";
		}

		if (E->get().sources.size()) {
			for(int i=0;i<E->get().sources.size();i++) {
				tooltip+="\nSource: "+E->get().sources[i];
			}
		}



		if (use_thumbnails) {
			files->add_item(fname,file_thumbnail,true);
			files->set_item_metadata(files->get_item_count()-1,fp);
			files->set_item_tag_icon(files->get_item_count()-1,type_icon);
			Array udata;
			udata.resize(2);
			udata[0]=files->get_item_count()-1;
			udata[1]=fname;
			EditorResourcePreview::get_singleton()->queue_resource_preview(fp,this,"_thumbnail_done",udata);
		} else {
			files->add_item(fname,type_icon,true);
			files->set_item_metadata(files->get_item_count()-1,fp);

		}

		if (cselection.has(fname))
			files->select(files->get_item_count()-1,false);

		files->set_item_tooltip(files->get_item_count()-1,tooltip);


	}


}
Esempio n. 20
0
void CreateDialog::popup_create(bool p_dontclear) {

	recent->clear();

	FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::READ);

	if (f) {

		TreeItem *root = recent->create_item();

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {

				TreeItem *ti = recent->create_item(root);
				ti->set_text(0, l);
				if (has_icon(l, "EditorIcons")) {

					ti->set_icon(0, get_icon(l, "EditorIcons"));
				} else {
					ti->set_icon(0, get_icon("Object", "EditorIcons"));
				}
			}
		}

		memdelete(f);
	}

	favorites->clear();

	f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites." + base_type), FileAccess::READ);

	favorite_list.clear();

	if (f) {

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {
				favorite_list.push_back(l);
			}
		}

		memdelete(f);
	}

	_update_favorite_list();


	// Restore valid window bounds or pop up at default size.
	if (EditorSettings::get_singleton()->has("interface/dialogs/create_new_node_bounds")) {
		popup(EditorSettings::get_singleton()->get("interface/dialogs/create_new_node_bounds"));	
	} else {
		popup_centered_ratio();
	}


	if (p_dontclear)
		search_box->select_all();
	else {
		search_box->clear();
	}
	search_box->grab_focus();

	_update_search();
}
void EditorFileDialog::update_file_list() {


	int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
	Ref<Texture> folder_thumbnail;
	Ref<Texture> file_thumbnail;

	item_list->clear();

	if (display_mode==DISPLAY_THUMBNAILS) {

		item_list->set_max_columns(0);
		item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
		item_list->set_fixed_column_width(thumbnail_size*3/2);
		item_list->set_max_text_lines(2);
		item_list->set_min_icon_size(Size2(thumbnail_size,thumbnail_size));

		if (!has_icon("ResizedFolder","EditorIcons")) {
			Ref<ImageTexture> folder = get_icon("FolderBig","EditorIcons");
			Image img = folder->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_folder = Ref<ImageTexture>( memnew( ImageTexture));
			resized_folder->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		folder_thumbnail = get_icon("ResizedFolder","EditorIcons");

		if (!has_icon("ResizedFile","EditorIcons")) {
			Ref<ImageTexture> file = get_icon("FileBig","EditorIcons");
			Image img = file->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_file = Ref<ImageTexture>( memnew( ImageTexture));
			resized_file->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

		file_thumbnail = get_icon("ResizedFile","EditorIcons");

		preview_vb->hide();

	} else {

		item_list->set_icon_mode(ItemList::ICON_MODE_LEFT);
		item_list->set_max_columns(1);
		item_list->set_max_text_lines(1);
		item_list->set_fixed_column_width(0);
		item_list->set_min_icon_size(Size2());
		if (preview->get_texture().is_valid())
			preview_vb->show();

	}

	String cdir = dir_access->get_current_dir();
	bool skip_pp = access==ACCESS_RESOURCES && cdir=="res://";

	dir_access->list_dir_begin();


	Ref<Texture> folder = get_icon("folder","FileDialog");
	List<String> files;
	List<String> dirs;

	bool isdir;
	bool ishidden;
	bool show_hidden = show_hidden_files;
	String item;

	while ((item=dir_access->get_next(&isdir))!="") {

		ishidden = dir_access->current_is_hidden();

		if (show_hidden || !ishidden) {
			if (!isdir)
				files.push_back(item);
			else if (item!=".." || !skip_pp)
				dirs.push_back(item);
		}
	}

	dirs.sort_custom<NoCaseComparator>();
	files.sort_custom<NoCaseComparator>();

	while(!dirs.empty()) {

		if (dirs.front()->get()!=".") {
			item_list->add_item(dirs.front()->get()+"/");
			if (display_mode==DISPLAY_THUMBNAILS) {

				item_list->set_item_icon(item_list->get_item_count()-1,folder_thumbnail);
			} else {

				item_list->set_item_icon(item_list->get_item_count()-1,folder);
			}

			Dictionary d;
			d["name"]=dirs.front()->get();
			d["path"]=String();
			d["dir"]=true;
			item_list->set_item_metadata( item_list->get_item_count() -1, d);
		}
		dirs.pop_front();

	}

	dirs.clear();

	List<String> patterns;
	// build filter
	if (filter->get_selected()==filter->get_item_count()-1) {

		// match all
	} else if (filters.size()>1 && filter->get_selected()==0) {
		// match all filters
		for (int i=0;i<filters.size();i++) {

			String f=filters[i].get_slice(";",0);
			for (int j=0;j<f.get_slice_count(",");j++) {

				patterns.push_back(f.get_slice(",",j).strip_edges());
			}
		}
	} else {
		int idx=filter->get_selected();
		if (filters.size()>1)
			idx--;

		if (idx>=0 && idx<filters.size()) {

			String f=filters[idx].get_slice(";",0);
			for (int j=0;j<f.get_slice_count(",");j++) {

				patterns.push_back(f.get_slice(",",j).strip_edges());
			}
		}
	}


	String base_dir = dir_access->get_current_dir();


	while(!files.empty()) {

		bool match=patterns.empty();

		for(List<String>::Element *E=patterns.front();E;E=E->next()) {

			if (files.front()->get().matchn(E->get())) {

				match=true;
				break;
			}
		}

		if (match) {
			//TreeItem *ti=tree->create_item(root);
			//ti->set_text(0,files.front()->get());
			item_list->add_item(files.front()->get());

			if (get_icon_func) {


				Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
				//ti->set_icon(0,icon);
				if (display_mode==DISPLAY_THUMBNAILS) {

					item_list->set_item_icon(item_list->get_item_count()-1,file_thumbnail);
					item_list->set_item_tag_icon(item_list->get_item_count()-1,icon);
				} else {
					item_list->set_item_icon(item_list->get_item_count()-1,icon);
				}
			}

			if (mode==MODE_OPEN_DIR) {
				//disabled mode?
				//ti->set_custom_color(0,get_color("files_disabled"));
				//ti->set_selectable(0,false);
			}
			Dictionary d;
			d["name"]=files.front()->get();
			d["dir"]=false;
			String fullpath = base_dir.plus_file(files.front()->get());

			if (display_mode==DISPLAY_THUMBNAILS) {
				EditorResourcePreview::get_singleton()->queue_resource_preview(fullpath,this,"_thumbnail_result",fullpath);
			}
			d["path"]=base_dir.plus_file(files.front()->get());
			//ti->set_metadata(0,d);
			item_list->set_item_metadata(item_list->get_item_count()-1,d);

			if (file->get_text()==files.front()->get())
				item_list->set_current(item_list->get_item_count()-1);
		}

		files.pop_front();
	}

	if (favorites->get_current()>=0) {
		favorites->unselect(favorites->get_current());
	}

	favorite->set_pressed(false);
	fav_up->set_disabled(true);
	fav_down->set_disabled(true);
	for(int i=0;i<favorites->get_item_count();i++) {
		if (favorites->get_item_metadata(i)==base_dir) {
			favorites->select(i);
			favorite->set_pressed(true);
			if (i>0) {
				fav_up->set_disabled(false);
			}
			if (i<favorites->get_item_count()-1) {
				fav_down->set_disabled(false);
			}
			break;
		}

	}
	// ??
	//if (tree->get_root() && tree->get_root()->get_children())
	//	tree->get_root()->get_children()->select(0);

	files.clear();

}
Esempio n. 22
0
void EditorPath::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_MOUSE_ENTER: {
			mouse_over=true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {
			mouse_over=false;
			update();
		} break;
		case NOTIFICATION_DRAW: {

			RID ci=get_canvas_item();
			Ref<Font> label_font = get_font("font","Label");
			Size2i size = get_size();
			Ref<Texture> sn = get_icon("SmallNext","EditorIcons");
			Ref<StyleBox> sb = get_stylebox("pressed","Button");


			int ofs=sb->get_margin(MARGIN_LEFT);

			if (mouse_over) {
				draw_style_box(sb,Rect2(Point2(),get_size()));
			}

			for(int i=0;i<history->get_path_size();i++) {

				Object *obj = ObjectDB::get_instance(history->get_path_object(i));
				if (!obj)
					continue;

				String type = obj->get_class();

				Ref<Texture> icon;

				if (has_icon(obj->get_class(),"EditorIcons"))
					icon=get_icon(obj->get_class(),"EditorIcons");
				else
					icon=get_icon("Object","EditorIcons");


				icon->draw(ci,Point2i(ofs,(size.height-icon->get_height())/2));

				ofs+=icon->get_width();

				if (i==history->get_path_size()-1) {
					//add name
					ofs+=4;
					int left = size.width - ofs;
					if (left<0)
						continue;
					String name;
					if (obj->cast_to<Resource>()) {

						Resource *r = obj->cast_to<Resource>();
						if (r->get_path().is_resource_file())
							name=r->get_path().get_file();
						else
							name=r->get_name();

						if (name=="")
							name=r->get_class();
					} else if (obj->cast_to<Node>()) {

						name=obj->cast_to<Node>()->get_name();
					} else if (obj->cast_to<Resource>() && obj->cast_to<Resource>()->get_name()!="") {
						name=obj->cast_to<Resource>()->get_name();
					} else {
						name=obj->get_class();
					}

					set_tooltip(obj->get_class());


					label_font->draw(ci,Point2i(ofs,(size.height-label_font->get_height())/2+label_font->get_ascent()),name,Color(1,1,1),left);
				} else {
					//add arrow

					//sn->draw(ci,Point2i(ofs,(size.height-sn->get_height())/2));
					//ofs+=sn->get_width();
					ofs+=5; //just looks better! somehow

				}
			}

		} break;
	}
}
Esempio n. 23
0
void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_data) {



	if (p_msg=="debug_enter") {

		Array msg;
		msg.push_back("get_stack_dump");
		ppeer->put_var(msg);
		ERR_FAIL_COND(p_data.size()!=2);
		bool can_continue=p_data[0];
		String error = p_data[1];
		step->set_disabled(!can_continue);
		next->set_disabled(!can_continue);
		reason->set_text(error);
		reason->set_tooltip(error);
		breaked=true;
		dobreak->set_disabled(true);
		docontinue->set_disabled(false);
		emit_signal("breaked",true,can_continue);
		OS::get_singleton()->move_window_to_foreground();
		if (error!="") {
			tabs->set_current_tab(0);
		}

		profiler->set_enabled(false);

		EditorNode::get_singleton()->get_pause_button()->set_pressed(true);


		EditorNode::get_singleton()->make_bottom_panel_item_visible(this);

	} else if (p_msg=="debug_exit") {

		breaked=false;
		step->set_disabled(true);
		next->set_disabled(true);
		reason->set_text("");
		reason->set_tooltip("");
		back->set_disabled(true);
		forward->set_disabled(true);
		dobreak->set_disabled(false);
		docontinue->set_disabled(true);
		emit_signal("breaked",false,false,Variant());
		//tabs->set_current_tab(0);
		profiler->set_enabled(true);
		profiler->disable_seeking();

		EditorNode::get_singleton()->get_pause_button()->set_pressed(false);


	} else if (p_msg=="message:click_ctrl") {

		clicked_ctrl->set_text(p_data[0]);
		clicked_ctrl_type->set_text(p_data[1]);

	} else if (p_msg=="message:scene_tree") {

		inspect_scene_tree->clear();
		Map<int,TreeItem*> lv;

		updating_scene_tree=true;

		for(int i=0;i<p_data.size();i+=4) {

			TreeItem *p;
			int level = p_data[i];
			if (level==0) {
				p = NULL;
			} else {
				ERR_CONTINUE(!lv.has(level-1));
				p=lv[level-1];
			}


			TreeItem *it = inspect_scene_tree->create_item(p);

			ObjectID id = ObjectID(p_data[i+3]);

			it->set_text(0,p_data[i+1]);
			if (has_icon(p_data[i+2],"EditorIcons"))
				it->set_icon(0,get_icon(p_data[i+2],"EditorIcons"));
			it->set_metadata(0,id);
			if (id==inspected_object_id) {
				it->select(0);
			}

			if (p) {
				if (!unfold_cache.has(id)) {
					it->set_collapsed(true);
				}
			} else {
				if (unfold_cache.has(id)) { //reverse for root
					it->set_collapsed(true);
				}
			}
			lv[level]=it;
		}
		updating_scene_tree=false;

		le_clear->set_disabled(false);
		le_set->set_disabled(false);
	} else if (p_msg=="message:inspect_object") {


		ObjectID id = p_data[0];
		String type = p_data[1];
		Variant path = p_data[2]; //what to do yet, i don't  know
		int prop_count=p_data[3];

		int idx=4;


		if (inspected_object->last_edited_id!=id) {
			inspected_object->prop_list.clear();
			inspected_object->prop_values.clear();
		}

		for(int i=0;i<prop_count;i++) {

			PropertyInfo pinfo;
			pinfo.name=p_data[idx++];
			pinfo.type=Variant::Type(int(p_data[idx++]));
			pinfo.hint=PropertyHint(int(p_data[idx++]));
			pinfo.hint_string=p_data[idx++];
			if (pinfo.name.begins_with("*")) {
				pinfo.name=pinfo.name.substr(1,pinfo.name.length());
				pinfo.usage=PROPERTY_USAGE_CATEGORY;
			} else {
				pinfo.usage=PROPERTY_USAGE_EDITOR;
			}

			if (inspected_object->last_edited_id!=id) {
				//don't update.. it's the same, instead refresh
				inspected_object->prop_list.push_back(pinfo);
			}


			inspected_object->prop_values[pinfo.name]=p_data[idx++];

			if (inspected_object->last_edited_id==id) {
				//same, just update value, don't rebuild
				inspected_object->update_single(pinfo.name.ascii().get_data());
			}

		}



		if (inspected_object->last_edited_id!=id) {
			//only if different
			inspected_object->update();
		}

		inspected_object->last_edited_id=id;


		inspect_properties->edit(inspected_object);

	} else if (p_msg=="message:video_mem") {

		vmem_tree->clear();
		TreeItem* root=vmem_tree->create_item();

		int total=0;

		for(int i=0;i<p_data.size();i+=4) {

			TreeItem *it = vmem_tree->create_item(root);
			String type=p_data[i+1];
			int bytes=p_data[i+3].operator int();
			it->set_text(0,p_data[i+0]); //path
			it->set_text(1,type); //type
			it->set_text(2,p_data[i+2]); //type
			it->set_text(3,String::humanize_size(bytes)); //type
			total+=bytes;

			if (has_icon(type,"EditorIcons"))
				it->set_icon(0,get_icon(type,"EditorIcons"));
		}

		vmem_total->set_tooltip(TTR("Bytes:")+" "+itos(total));
		vmem_total->set_text(String::humanize_size(total));

	} else if (p_msg=="stack_dump") {

		stack_dump->clear();
		TreeItem *r = stack_dump->create_item();

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

			Dictionary d = p_data[i];
			ERR_CONTINUE(!d.has("function"));
			ERR_CONTINUE(!d.has("file"));
			ERR_CONTINUE(!d.has("line"));
			ERR_CONTINUE(!d.has("id"));
			TreeItem *s = stack_dump->create_item(r);
			d["frame"]=i;
			s->set_metadata(0,d);

//			String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
			String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"]);
			s->set_text(0,line);

			if (i==0)
				s->select(0);
		}
	} else if (p_msg=="stack_frame_vars") {


		variables->clear();



		int ofs =0;
		int mcount = p_data[ofs];

		ofs++;
		for(int i=0;i<mcount;i++) {

			String n = p_data[ofs+i*2+0];
			Variant v = p_data[ofs+i*2+1];

			if (n.begins_with("*")) {

				n=n.substr(1,n.length());
			}

			variables->add_property("members/"+n,v);
		}
		ofs+=mcount*2;

		mcount = p_data[ofs];

		ofs++;
		for(int i=0;i<mcount;i++) {

			String n = p_data[ofs+i*2+0];
			Variant v = p_data[ofs+i*2+1];

			if (n.begins_with("*")) {

				n=n.substr(1,n.length());
			}


			variables->add_property("locals/"+n,v);
		}

		variables->update();
		inspector->edit(variables);

	} else if (p_msg=="output") {

		//OUT
		for(int i=0;i<p_data.size();i++) {

			String t = p_data[i];
			//LOG

			if (EditorNode::get_log()->is_hidden()) {
				log_forced_visible=true;
				if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
					EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
				}
			}
			EditorNode::get_log()->add_message(t);

		}

	} else if (p_msg=="performance") {
		Array arr = p_data[0];
		Vector<float> p;
		p.resize(arr.size());
		for(int i=0;i<arr.size();i++) {
			p[i]=arr[i];
			if (i<perf_items.size()) {
				perf_items[i]->set_text(1,rtos(p[i]));
				if (p[i]>perf_max[i])
					perf_max[i]=p[i];
			}

		}
		perf_history.push_front(p);
		perf_draw->update();

	} else if (p_msg=="error") {

		Array err = p_data[0];

		Array vals;
		vals.push_back(err[0]);
		vals.push_back(err[1]);
		vals.push_back(err[2]);
		vals.push_back(err[3]);

		bool warning = err[9];
		bool e;
		String time = String("%d:%02d:%02d:%04d").sprintf(vals,&e);
		String txt=time+" - "+(err[8].is_zero()?String(err[7]):String(err[8]));

		String tooltip=TTR("Type:")+String(warning?TTR("Warning"):TTR("Error"));
		tooltip+="\n"+TTR("Description:")+" "+String(err[8]);
		tooltip+="\n"+TTR("Time:")+" "+time;
		tooltip+="\nC "+TTR("Error:")+" "+String(err[7]);
		tooltip+="\nC "+TTR("Source:")+" "+String(err[5])+":"+String(err[6]);
		tooltip+="\nC "+TTR("Function:")+" "+String(err[4]);



		error_list->add_item(txt,EditorNode::get_singleton()->get_gui_base()->get_icon(warning?"Warning":"Error","EditorIcons"));
		error_list->set_item_tooltip( error_list->get_item_count() -1,tooltip );

		int scc = p_data[1];

		Array stack;
		stack.resize(scc);
		for(int i=0;i<scc;i++) {
			stack[i]=p_data[2+i];
		}

		error_list->set_item_metadata( error_list->get_item_count() -1,stack );

		error_count++;
		/*
		int count = p_data[1];

		Array cstack;

		OutputError oe = errors.front()->get();

		packet_peer_stream->put_var(oe.hr);
		packet_peer_stream->put_var(oe.min);
		packet_peer_stream->put_var(oe.sec);
		packet_peer_stream->put_var(oe.msec);
		packet_peer_stream->put_var(oe.source_func);
		packet_peer_stream->put_var(oe.source_file);
		packet_peer_stream->put_var(oe.source_line);
		packet_peer_stream->put_var(oe.error);
		packet_peer_stream->put_var(oe.error_descr);
		packet_peer_stream->put_var(oe.warning);
		packet_peer_stream->put_var(oe.callstack);
		*/

	} else if (p_msg=="profile_sig") {
		//cache a signature
		print_line("SIG: "+String(Variant(p_data)));
		profiler_signature[p_data[1]]=p_data[0];

	} else if (p_msg=="profile_frame" || p_msg=="profile_total") {

		EditorProfiler::Metric metric;
		metric.valid=true;
		metric.frame_number=p_data[0];
		metric.frame_time=p_data[1];
		metric.idle_time=p_data[2];
		metric.fixed_time=p_data[3];
		metric.fixed_frame_time=p_data[4];
		int frame_data_amount = p_data[6];
		int frame_function_amount = p_data[7];


		if (frame_data_amount) {
			EditorProfiler::Metric::Category frame_time;
			frame_time.signature="category_frame_time";
			frame_time.name="Frame Time";
			frame_time.total_time=metric.frame_time;

			EditorProfiler::Metric::Category::Item item;
			item.calls=1;
			item.line=0;
			item.name="Fixed Time";
			item.total=metric.fixed_time;
			item.self=item.total;
			item.signature="fixed_time";


			frame_time.items.push_back(item);

			item.name="Idle Time";
			item.total=metric.idle_time;
			item.self=item.total;
			item.signature="idle_time";

			frame_time.items.push_back(item);

			item.name="Fixed Frame Time";
			item.total=metric.fixed_frame_time;
			item.self=item.total;
			item.signature="fixed_frame_time";

			frame_time.items.push_back(item);

			metric.categories.push_back(frame_time);

		}



		int idx=8;
		for(int i=0;i<frame_data_amount;i++) {

			EditorProfiler::Metric::Category c;
			String name=p_data[idx++];
			Array values=p_data[idx++];
			c.name=name.capitalize();
			c.items.resize(values.size()/2);
			c.total_time=0;
			c.signature="categ::"+name;
			for(int i=0;i<values.size();i+=2) {

				EditorProfiler::Metric::Category::Item item;
				item.name=values[i];
				item.calls=1;
				item.self=values[i+1];
				item.total=item.self;
				item.signature="categ::"+name+"::"+item.name;
				item.name=item.name.capitalize();
				c.total_time+=item.total;
				c.items[i/2]=item;


			}
			metric.categories.push_back(c);
		}

		EditorProfiler::Metric::Category funcs;
		funcs.total_time=p_data[5]; //script time
		funcs.items.resize(frame_function_amount);
		funcs.name="Script Functions";
		funcs.signature="script_functions";
		for(int i=0;i<frame_function_amount;i++) {

			int signature = p_data[idx++];
			int calls = p_data[idx++];
			float total = p_data[idx++];
			float self = p_data[idx++];



			EditorProfiler::Metric::Category::Item item;
			if (profiler_signature.has(signature)) {

				item.signature=profiler_signature[signature];

				String name = profiler_signature[signature];
				Vector<String> strings = name.split("::");
				if (strings.size()==3) {
					item.name=strings[2];
					item.script=strings[0];
					item.line=strings[1].to_int();
				}

			} else {
				item.name="SigErr "+itos(signature);
			}




			item.calls=calls;
			item.self=self;
			item.total=total;
			funcs.items[i]=item;

		}

		metric.categories.push_back(funcs);

		if (p_msg=="profile_frame")
			profiler->add_frame_metric(metric,false);
		else
			profiler->add_frame_metric(metric,true);

	} else if (p_msg=="kill_me") {

		editor->call_deferred("stop_child_process");
	}

}
Esempio n. 24
0
void Button::_notification(int p_what) {
	
	if (p_what==NOTIFICATION_DRAW) {
		
		RID ci = get_canvas_item();
		Size2 size=get_size();
		Color color;

		//print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
		
		switch( get_draw_mode() ) {
		
			case DRAW_NORMAL: {
			
				if (!flat)
					get_stylebox("normal" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color");			
			} break;
			case DRAW_PRESSED: {
			
				get_stylebox("pressed" )->draw(  ci, Rect2(Point2(0,0), size) );
				if (has_color("font_color_pressed"))
					color=get_color("font_color_pressed");
				else
					color=get_color("font_color");
			
			} break;
			case DRAW_HOVER: {
			
				get_stylebox("hover" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color_hover");
				
			} break;
			case DRAW_DISABLED: {

				get_stylebox("disabled" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color_disabled");
			
			} break;
		}

		if (has_focus()) {

			Ref<StyleBox> style = get_stylebox("focus");
			style->draw(ci,Rect2(Point2(),size));
		}

		Ref<StyleBox> style = get_stylebox("normal" );
		Ref<Font> font=get_font("font");
		Ref<Texture> _icon;
		if (icon.is_null() && has_icon("icon"))
			_icon=Control::get_icon("icon");
		else
			_icon=icon;

		Point2 icon_ofs = (!_icon.is_null())?Point2( _icon->get_width() + get_constant("hseparation"), 0):Point2();
		int text_clip=size.width - style->get_minimum_size().width - icon_ofs.width;
		Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( text ) )/2.0;

		switch(align) {
			case ALIGN_LEFT: {
				text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x;
				text_ofs.y+=style->get_offset().y;
			} break;
			case ALIGN_CENTER: {
				if (text_ofs.x<0)
					text_ofs.x=0;
				text_ofs+=icon_ofs;
				text_ofs+=style->get_offset();
			} break;
			case ALIGN_RIGHT: {
				text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( text ).x;
				text_ofs.y+=style->get_offset().y;
			} break;
		}


		text_ofs.y+=font->get_ascent();
		font->draw( ci, text_ofs.floor(), text, color,clip_text?text_clip:-1);
		if (!_icon.is_null()) {

			int valign = size.height-style->get_minimum_size().y;
		
			_icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) );
		}


				
	}
}
Esempio n. 25
0
void CreateDialog::_update_search() {

	search_options->clear();
	favorite->set_disabled(true);

	help_bit->set_text("");
	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	HashMap<String, TreeItem *> types;

	TreeItem *root = search_options->create_item();
	EditorData &ed = EditorNode::get_singleton()->get_editor_data();

	root->set_text(0, base_type);
	if (has_icon(base_type, "EditorIcons")) {
		root->set_icon(0, get_icon(base_type, "EditorIcons"));
	}

	TreeItem *to_select = search_box->get_text() == base_type ? root : NULL;

	for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {

		String type = I->get();
		bool cpp_type = ClassDB::class_exists(type);

		if (base_type == "Node" && type.begins_with("Editor"))
			continue; // do not show editor nodes

		if (cpp_type && !ClassDB::can_instance(type))
			continue; // can't create what can't be instanced

		bool skip = false;
		if (cpp_type) {
			for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
				if (ClassDB::is_parent_class(type, E->get()))
					skip = true;
			}
			if (skip)
				continue;
		}

		if (search_box->get_text() == "") {
			add_type(type, types, root, &to_select);
		} else {

			bool found = false;
			String type = I->get();
			while (type != "" && (cpp_type ? ClassDB::is_parent_class(type, base_type) : ed.script_class_is_parent(type, base_type)) && type != base_type) {
				if (search_box->get_text().is_subsequence_ofi(type)) {

					found = true;
					break;
				}

				type = ClassDB::get_parent_class(type);
			}

			if (found)
				add_type(I->get(), types, root, &to_select);
		}

		if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) {
			//there are custom types based on this... cool.

			const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
			for (int i = 0; i < ct.size(); i++) {

				bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);

				if (!show)
					continue;

				if (!types.has(type))
					add_type(type, types, root, &to_select);

				TreeItem *ti;
				if (types.has(type))
					ti = types[type];
				else
					ti = search_options->get_root();

				TreeItem *item = search_options->create_item(ti);
				item->set_metadata(0, type);
				item->set_text(0, ct[i].name);
				if (ct[i].icon.is_valid()) {
					item->set_icon(0, ct[i].icon);
				}

				if (!to_select || ct[i].name == search_box->get_text()) {
					to_select = item;
				}
			}
		}
	}

	if (search_box->get_text() == "") {
		to_select = root;
	}

	if (to_select) {
		to_select->select(0);
		search_options->scroll_to_item(to_select);
		favorite->set_disabled(false);
		favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1);
	}

	get_ok()->set_disabled(root->get_children() == NULL);
}
Esempio n. 26
0
void ConnectionsDock::update_tree() {

	tree->clear();

	if (!selectedNode)
		return;

	TreeItem *root = tree->create_item();

	List<MethodInfo> node_signals;

	selectedNode->get_signal_list(&node_signals);

	//node_signals.sort_custom<_ConnectionsDockMethodInfoSort>();
	bool did_script = false;
	StringName base = selectedNode->get_class();

	while (base) {

		List<MethodInfo> node_signals;
		Ref<Texture> icon;
		String name;

		if (!did_script) {

			Ref<Script> scr = selectedNode->get_script();
			if (scr.is_valid()) {
				scr->get_script_signal_list(&node_signals);
				if (scr->get_path().is_resource_file())
					name = scr->get_path().get_file();
				else
					name = scr->get_class();

				if (has_icon(scr->get_class(), "EditorIcons")) {
					icon = get_icon(scr->get_class(), "EditorIcons");
				}
			}

		} else {

			ClassDB::get_signal_list(base, &node_signals, true);
			if (has_icon(base, "EditorIcons")) {
				icon = get_icon(base, "EditorIcons");
			}
			name = base;
		}

		TreeItem *pitem = NULL;

		if (node_signals.size()) {
			pitem = tree->create_item(root);
			pitem->set_text(0, name);
			pitem->set_icon(0, icon);
			pitem->set_selectable(0, false);
			pitem->set_editable(0, false);
			pitem->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
			node_signals.sort();
		}

		for (List<MethodInfo>::Element *E = node_signals.front(); E; E = E->next()) {

			MethodInfo &mi = E->get();

			String signaldesc;
			signaldesc = mi.name + "(";
			PoolStringArray argnames;
			if (mi.arguments.size()) {
				signaldesc += " ";
				for (int i = 0; i < mi.arguments.size(); i++) {

					PropertyInfo &pi = mi.arguments[i];

					if (i > 0)
						signaldesc += ", ";
					String tname = "var";
					if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
						tname = pi.class_name.operator String();
					} else if (pi.type != Variant::NIL) {
						tname = Variant::get_type_name(pi.type);
					}
					signaldesc += tname + " " + (pi.name == "" ? String("arg " + itos(i)) : pi.name);
					argnames.push_back(pi.name + ":" + tname);
				}
				signaldesc += " ";
			}

			signaldesc += ")";

			TreeItem *item = tree->create_item(pitem);
			item->set_text(0, signaldesc);
			Dictionary sinfo;
			sinfo["name"] = mi.name;
			sinfo["args"] = argnames;
			item->set_metadata(0, sinfo);
			item->set_icon(0, get_icon("Signal", "EditorIcons"));

			List<Object::Connection> connections;
			selectedNode->get_signal_connection_list(mi.name, &connections);

			for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {

				Object::Connection &c = F->get();
				if (!(c.flags & CONNECT_PERSIST))
					continue;

				Node *target = Object::cast_to<Node>(c.target);
				if (!target)
					continue;

				String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()";
				if (c.flags & CONNECT_DEFERRED)
					path += " (deferred)";
				if (c.flags & CONNECT_ONESHOT)
					path += " (oneshot)";
				if (c.binds.size()) {

					path += " binds( ";
					for (int i = 0; i < c.binds.size(); i++) {

						if (i > 0)
							path += ", ";
						path += c.binds[i].operator String();
					}
					path += " )";
				}

				TreeItem *item2 = tree->create_item(item);
				item2->set_text(0, path);
				item2->set_metadata(0, c);
				item2->set_icon(0, get_icon("Slot", "EditorIcons"));
			}
		}

		if (!did_script) {
			did_script = true;
		} else {
			base = ClassDB::get_parent_class(base);
		}
	}

	connect_button->set_text(TTR("Connect"));
	connect_button->set_disabled(true);
}
Esempio n. 27
0
bool SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) {

	if (!p_node)
		return false;

	// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
	// which the editor needs not to know about.

	bool part_of_subscene=false;

	if (!display_foreign && p_node->get_owner()!=get_scene_node()  && p_node!=get_scene_node()) {

		if ((show_enabled_subscene || can_open_instance) && p_node->get_owner() && (get_scene_node()->is_editable_instance(p_node->get_owner()))) {

			part_of_subscene=true;
			//allow
		} else {
			return false;
		}
	} else {
		part_of_subscene = p_node!=get_scene_node() && get_scene_node()->get_scene_inherited_state().is_valid() && get_scene_node()->get_scene_inherited_state()->find_node_by_path(get_scene_node()->get_path_to(p_node))>=0;
	}

	TreeItem *item = tree->create_item(p_parent);
	item->set_text(0, p_node->get_name() );
	if (can_rename && !part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/)
		item->set_editable(0, true);

	item->set_selectable(0,true);
	if (can_rename) {
#ifdef ENABLE_DEPRECATED
		if (p_node->has_meta("_editor_collapsed")) {
			//remove previous way of storing folding, which did not get along with scene inheritance and instancing
			if ((bool)p_node->get_meta("_editor_collapsed"))
				p_node->set_display_folded(true);
			p_node->set_meta("_editor_collapsed",Variant());
		}
#endif
		bool collapsed = p_node->is_displayed_folded();
		if (collapsed)
			item->set_collapsed(true);
	}

	Ref<Texture> icon;
	if (p_node->has_meta("_editor_icon"))
		icon=p_node->get_meta("_editor_icon");
	else
		icon=get_icon( (has_icon(p_node->get_type(),"EditorIcons")?p_node->get_type():String("Object")),"EditorIcons");
	item->set_icon(0, icon );
	item->set_metadata( 0,p_node->get_path() );

	if (part_of_subscene) {

		//item->set_selectable(0,marked_selectable);
		item->set_custom_color(0,Color(0.8,0.4,0.20));

	} else if (marked.has(p_node)) {

		item->set_selectable(0,marked_selectable);
		item->set_custom_color(0,Color(0.8,0.1,0.10));
	} else if (!marked_selectable && !marked_children_selectable) {

		Node *node=p_node;
		while(node) {
			if (marked.has(node)) {
				item->set_selectable(0,false);
				item->set_custom_color(0,Color(0.8,0.1,0.10));
				break;
			}
			node=node->get_parent();
		}
	}



	if (can_rename) { //should be can edit..

		String warning = p_node->get_configuration_warning();
		if (warning!=String()) {
			item->add_button(0,get_icon("NodeWarning","EditorIcons"),BUTTON_WARNING);
		}

		bool has_connections = p_node->has_persistent_signal_connections();
		bool has_groups = p_node->has_persistent_groups();

		if (has_connections && has_groups) {
			item->add_button(0,get_icon("ConnectionAndGroups","EditorIcons"),BUTTON_SIGNALS);
		} else if (has_connections) {
			item->add_button(0,get_icon("Connect","EditorIcons"),BUTTON_SIGNALS);
		} else if (has_groups) {
			item->add_button(0,get_icon("Groups","EditorIcons"),BUTTON_GROUPS);
		}
	}

	if (p_node==get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
		item->add_button(0,get_icon("InstanceOptions","EditorIcons"),BUTTON_SUBSCENE);
		item->set_tooltip(0,TTR("Inherits:")+" "+p_node->get_scene_inherited_state()->get_path()+"\n"+TTR("Type:")+" "+p_node->get_type());
	} else if (p_node!=get_scene_node() && p_node->get_filename()!="" && can_open_instance) {

		item->add_button(0,get_icon("InstanceOptions","EditorIcons"),BUTTON_SUBSCENE);
		item->set_tooltip(0,TTR("Instance:")+" "+p_node->get_filename()+"\n"+TTR("Type:")+" "+p_node->get_type());
	} else {
		item->set_tooltip(0,String(p_node->get_name())+"\n"+TTR("Type:")+" "+p_node->get_type());
	}

	if (can_open_instance) {

		if (!p_node->is_connected("script_changed",this,"_node_script_changed"))
			p_node->connect("script_changed",this,"_node_script_changed",varray(p_node));


		if (!p_node->get_script().is_null()) {

			item->add_button(0,get_icon("Script","EditorIcons"),BUTTON_SCRIPT);
		}

		if (p_node->is_type("CanvasItem")) {

			bool is_locked = p_node->has_meta("_edit_lock_");//_edit_group_
			if (is_locked)
				item->add_button(0,get_icon("Lock", "EditorIcons"), BUTTON_LOCK);

			bool is_grouped = p_node->has_meta("_edit_group_");
			if (is_grouped)
				item->add_button(0,get_icon("Group", "EditorIcons"), BUTTON_GROUP);

			bool h = p_node->call("is_hidden");
			if (h)
				item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY);
			else
				item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY);

			if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed"))
				p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node));

		} else if (p_node->is_type("Spatial")) {

			bool h = p_node->call("is_hidden");
			if (h)
				item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY);
			else
				item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY);

			if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed"))
				p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node));

		}

	}

	if (editor_selection) {
		if (editor_selection->is_selected(p_node)) {

			item->select(0);
		}
	}

	if (selected==p_node) {
		if (!editor_selection)
			item->select(0);
		item->set_as_cursor(0);
	}

	bool keep= (filter.is_subsequence_ofi(String(p_node->get_name())));

	for (int i=0;i<p_node->get_child_count();i++) {

		bool child_keep = _add_nodes(p_node->get_child(i),item);

		keep = keep || child_keep;

	}

	if (!keep) {
		memdelete(item);
		return false;
	} else {
		return true;
	}

}
Esempio n. 28
0
void CreateDialog::add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root,TreeItem **to_select) {

    if (p_types.has(p_type))
        return;
    if (!ObjectTypeDB::is_type(p_type,base_type) || p_type==base_type)
        return;

    String inherits=ObjectTypeDB::type_inherits_from(p_type);

    TreeItem *parent=p_root;


    if (inherits.length()) {

        if (!p_types.has(inherits)) {

            add_type(inherits,p_types,p_root,to_select);
        }

        if (p_types.has(inherits) )
            parent=p_types[inherits];
    }

    TreeItem *item = search_options->create_item(parent);
    item->set_text(0,p_type);
    if (!ObjectTypeDB::can_instance(p_type)) {
        item->set_custom_color(0, Color(0.5,0.5,0.5) );
        item->set_selectable(0,false);
    } else {

        if (!*to_select && (search_box->get_text()=="" || p_type.findn(search_box->get_text())!=-1)) {
            *to_select=item;
        }

    }

    if (bool(EditorSettings::get_singleton()->get("scenetree_editor/start_create_dialog_fully_expanded"))) {
        item->set_collapsed(false);
    } else {
        // don't collapse search results
        bool collapse = (search_box->get_text() == "");
        // don't collapse the root node
        collapse &= (item != p_root);
        // don't collapse abstract nodes on the first tree level
        collapse &= ((parent != p_root) || (ObjectTypeDB::can_instance(p_type)));
        item->set_collapsed(collapse);
    }

    const String& description = EditorHelp::get_doc_data()->class_list[p_type].brief_description;
    item->set_tooltip(0,description);


    if (has_icon(p_type,"EditorIcons")) {

        item->set_icon(0, get_icon(p_type,"EditorIcons"));
    }



    p_types[p_type]=item;
}
Esempio n. 29
0
void ScenesDock::_update_files(bool p_keep_selection) {

	Set<String> cselection;

	if (p_keep_selection) {

		for(int i=0;i<files->get_item_count();i++) {

			if (files->is_selected(i))
				cselection.insert(files->get_item_text(i));
		}
	}

	files->clear();

	current_path->set_text(path);


	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

	int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
	Ref<Texture> folder_thumbnail;
	Ref<Texture> file_thumbnail;

	bool use_thumbnails=!display_mode->is_pressed();
	bool use_folders = !search_box->is_visible() && split_mode;

	if (use_thumbnails) { //thumbnails

		files->set_max_columns(0);
		files->set_icon_mode(ItemList::ICON_MODE_TOP);
		files->set_fixed_column_width(thumbnail_size*3/2);
		files->set_max_text_lines(2);
		files->set_min_icon_size(Size2(thumbnail_size,thumbnail_size));

		if (!has_icon("ResizedFolder","EditorIcons")) {
			Ref<ImageTexture> folder = get_icon("FolderBig","EditorIcons");
			Image img = folder->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_folder = Ref<ImageTexture>( memnew( ImageTexture));
			resized_folder->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		folder_thumbnail = get_icon("ResizedFolder","EditorIcons");

		if (!has_icon("ResizedFile","EditorIcons")) {
			Ref<ImageTexture> file = get_icon("FileBig","EditorIcons");
			Image img = file->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_file = Ref<ImageTexture>( memnew( ImageTexture));
			resized_file->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

		file_thumbnail = get_icon("ResizedFile","EditorIcons");

	} else {

		files->set_icon_mode(ItemList::ICON_MODE_LEFT);
		files->set_max_columns(1);
		files->set_max_text_lines(1);
		files->set_fixed_column_width(0);
		files->set_min_icon_size(Size2());

	}

	if (use_folders) {

		if (path!="res://") {

			if (use_thumbnails) {
				files->add_item("..",folder_thumbnail,true);
			} else {
				files->add_item("..",get_icon("folder","FileDialog"),true);
			}

			String bd = path.get_base_dir();
			if (bd!="res://" && !bd.ends_with("/"))
				bd+="/";

			files->set_item_metadata(files->get_item_count()-1,bd);
		}

		for(int i=0;i<efd->get_subdir_count();i++) {

			String dname=efd->get_subdir(i)->get_name();


			if (use_thumbnails) {
				files->add_item(dname,folder_thumbnail,true);
			} else {
				files->add_item(dname,get_icon("folder","FileDialog"),true);
			}

			files->set_item_metadata(files->get_item_count()-1,path.plus_file(dname)+"/");

			if (cselection.has(dname))
				files->select(files->get_item_count()-1,false);
		}
	}


	List<FileInfo> filelist;

	if (search_box->is_visible()) {

		if (search_box->get_text().length()>1) {
			_search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128);
		}

		filelist.sort();
	} else {

		for(int i=0;i<efd->get_file_count();i++) {

			FileInfo fi;
			fi.name=efd->get_file(i);
			fi.path=path.plus_file(fi.name);
			fi.type=efd->get_file_type(i);

			filelist.push_back(fi);
		}
	}

	StringName ei="EditorIcons"; //make it faster..
	StringName oi="Object";


	for(List<FileInfo>::Element *E=filelist.front();E;E=E->next()) {
		String fname=E->get().name;
		String fp = E->get().path;
		StringName type = E->get().type;

		Ref<Texture> type_icon;

		if (has_icon(type,ei)) {
			type_icon=get_icon(type,ei);
		} else {
			type_icon=get_icon(oi,ei);
		}

		if (use_thumbnails) {
			files->add_item(fname,file_thumbnail,true);
			files->set_item_metadata(files->get_item_count()-1,fp);
			files->set_item_tag_icon(files->get_item_count()-1,type_icon);
			Array udata;
			udata.resize(2);
			udata[0]=files->get_item_count()-1;
			udata[1]=fname;
			EditorResourcePreview::get_singleton()->queue_resource_preview(fp,this,"_thumbnail_done",udata);
		} else {
			files->add_item(fname,type_icon,true);
			files->set_item_metadata(files->get_item_count()-1,fp);

		}

		if (cselection.has(fname))
			files->select(files->get_item_count()-1,false);

	}


}
Esempio n. 30
0
void ScenesDock::_update_files(bool p_keep_selection) {

	Set<String> cselection;

	if (p_keep_selection) {

		for(int i=0;i<files->get_item_count();i++) {

			if (files->is_selected(i))
				cselection.insert(files->get_item_text(i));
		}
	}

	files->clear();

	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

	int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
	Ref<Texture> folder_thumbnail;
	Ref<Texture> file_thumbnail;

	bool use_thumbnails=!display_mode->is_pressed();

	if (use_thumbnails) { //thumbnails

		files->set_max_columns(0);
		files->set_icon_mode(ItemList::ICON_MODE_TOP);
		files->set_fixed_column_width(thumbnail_size*3/2);
		files->set_max_text_lines(2);
		files->set_min_icon_size(Size2(thumbnail_size,thumbnail_size));

		if (!has_icon("ResizedFolder","EditorIcons")) {
			Ref<ImageTexture> folder = get_icon("FolderBig","EditorIcons");
			Image img = folder->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_folder = Ref<ImageTexture>( memnew( ImageTexture));
			resized_folder->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		folder_thumbnail = get_icon("ResizedFolder","EditorIcons");

		if (!has_icon("ResizedFile","EditorIcons")) {
			Ref<ImageTexture> file = get_icon("FileBig","EditorIcons");
			Image img = file->get_data();
			img.resize(thumbnail_size,thumbnail_size);
			Ref<ImageTexture> resized_file = Ref<ImageTexture>( memnew( ImageTexture));
			resized_file->create_from_image(img,0);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

		file_thumbnail = get_icon("ResizedFile","EditorIcons");

	} else {

		files->set_icon_mode(ItemList::ICON_MODE_LEFT);
		files->set_max_columns(1);
		files->set_max_text_lines(1);
		files->set_fixed_column_width(0);
		files->set_min_icon_size(Size2());

	}


	if (path!="res://") {

		if (use_thumbnails) {
			files->add_item("..",folder_thumbnail,true);
		} else {
			files->add_item("..",get_icon("folder","FileDialog"),true);
		}

		String bd = path.get_base_dir();
		if (bd!="res://" && !bd.ends_with("/"))
			bd+="/";

		files->set_item_metadata(files->get_item_count()-1,bd);
	}

	for(int i=0;i<efd->get_subdir_count();i++) {

		String dname=efd->get_subdir(i)->get_name();


		if (use_thumbnails) {
			files->add_item(dname,folder_thumbnail,true);
		} else {
			files->add_item(dname,get_icon("folder","FileDialog"),true);
		}

		files->set_item_metadata(files->get_item_count()-1,path.plus_file(dname)+"/");

		if (cselection.has(dname))
			files->select(files->get_item_count()-1,false);
	}

	for(int i=0;i<efd->get_file_count();i++) {

		String fname=efd->get_file(i);
		String fp = path.plus_file(fname);


		String type = efd->get_file_type(i);
		Ref<Texture> type_icon;

		if (has_icon(type,"EditorIcons")) {
			type_icon=get_icon(type,"EditorIcons");
		} else {
			type_icon=get_icon("Object","EditorIcons");
		}

		if (use_thumbnails) {
			files->add_item(fname,file_thumbnail,true);
			files->set_item_metadata(files->get_item_count()-1,fp);
			files->set_item_tag_icon(files->get_item_count()-1,type_icon);
			EditorResourcePreview::get_singleton()->queue_resource_preview(fp,this,"_thumbnail_done",files->get_item_count()-1);
		} else {
			files->add_item(fname,type_icon,true);
			files->set_item_metadata(files->get_item_count()-1,fp);

		}

		if (cselection.has(fname))
			files->select(files->get_item_count()-1,false);

	}


}