Browse Source

QOL, script buttons in scene tabs

Juan Linietsky 10 years ago
parent
commit
07c99e11f5

+ 111 - 2
scene/gui/tabs.cpp

@@ -56,7 +56,14 @@ Size2 Tabs::get_minimum_size() const {
 		else
 			ms.width+=tab_bg->get_minimum_size().width;
 
+		if (tabs[i].right_button.is_valid()) {
+			Ref<Texture> rb=tabs[i].right_button;
+			Size2 bms = rb->get_size()+get_stylebox("button")->get_minimum_size();
+			bms.width+=get_constant("hseparation");
 
+			ms.width+=bms.width;
+			ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height);
+		}
 	}
 
 	return ms;
@@ -66,6 +73,39 @@ Size2 Tabs::get_minimum_size() const {
 
 void Tabs::_input_event(const InputEvent& p_event) {
 
+	if (p_event.type==InputEvent::MOUSE_MOTION) {
+
+		Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y );
+
+		int hover=-1;
+		for(int i=0;i<tabs.size();i++) {
+
+			if (tabs[i].rb_rect.has_point(pos)) {
+				hover=i;
+				break;
+			}
+		}
+
+		if (hover!=rb_hover) {
+			rb_hover=hover;
+			update();
+		}
+		return;
+	}
+
+	if (rb_pressing && p_event.type==InputEvent::MOUSE_BUTTON &&
+	    !p_event.mouse_button.pressed &&
+	    p_event.mouse_button.button_index==BUTTON_LEFT) {
+
+		if (rb_hover!=-1) {
+			//pressed
+			emit_signal("right_button_pressed",rb_hover);
+		}
+
+		rb_pressing=false;
+		update();
+	}
+
 	if (p_event.type==InputEvent::MOUSE_BUTTON &&
 	    p_event.mouse_button.pressed &&
 	    p_event.mouse_button.button_index==BUTTON_LEFT) {
@@ -76,6 +116,12 @@ void Tabs::_input_event(const InputEvent& p_event) {
 		int found=-1;
 		for(int i=0;i<tabs.size();i++) {
 
+			if (tabs[i].rb_rect.has_point(pos)) {
+				rb_pressing=true;
+				update();
+				return;
+			}
+
 			int ofs=tabs[i].ofs_cache;
 			int size = tabs[i].ofs_cache;
 			if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) {
@@ -100,7 +146,10 @@ void Tabs::_notification(int p_what) {
 
 	switch(p_what) {
 
-
+		case NOTIFICATION_MOUSE_EXIT: {
+			rb_hover=-1;
+			update();
+		} break;
 		case NOTIFICATION_DRAW: {
 
 			RID ci = get_canvas_item();
@@ -151,6 +200,16 @@ void Tabs::_notification(int p_what) {
 					}
 				}
 
+				if (tabs[i].right_button.is_valid()) {
+					Ref<StyleBox> style = get_stylebox("button");
+					Ref<Texture> rb=tabs[i].right_button;
+
+					lsize+=get_constant("hseparation");
+					lsize+=style->get_margin(MARGIN_LEFT);
+					lsize+=rb->get_width();
+					lsize+=style->get_margin(MARGIN_RIGHT);
+
+				}
 
 				Ref<StyleBox> sb;
 				int va;
@@ -184,7 +243,37 @@ void Tabs::_notification(int p_what) {
 
 				font->draw(ci, Point2i( w, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col );
 
-				w+=slen+sb->get_margin(MARGIN_RIGHT);
+				w+=slen;
+
+				if (tabs[i].right_button.is_valid()) {
+					Ref<StyleBox> style = get_stylebox("button");
+					Ref<Texture> rb=tabs[i].right_button;
+
+					w+=get_constant("hseparation");
+
+					Rect2 rb_rect;
+					rb_rect.size=style->get_minimum_size()+rb->get_size();
+					rb_rect.pos.x=w;
+					rb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(rb_rect.size.y))/2;
+
+					if (rb_hover==i) {
+						if (rb_pressing)
+							get_stylebox("button_pressed")->draw(ci,rb_rect);
+						else
+							style->draw(ci,rb_rect);
+					}
+
+					w+=style->get_margin(MARGIN_LEFT);
+
+					rb->draw(ci,Point2i( w,rb_rect.pos.y+style->get_margin(MARGIN_TOP) ));
+					w+=rb->get_width();
+					w+=style->get_margin(MARGIN_RIGHT);
+					tabs[i].rb_rect=rb_rect;
+
+
+				}
+
+				w+=sb->get_margin(MARGIN_RIGHT);
 
 				tabs[i].size_cache=w-tabs[i].ofs_cache;
 
@@ -252,6 +341,23 @@ Ref<Texture> Tabs::get_tab_icon(int p_tab) const{
 
 }
 
+
+
+void Tabs::set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button){
+
+	ERR_FAIL_INDEX(p_tab,tabs.size());
+	tabs[p_tab].right_button=p_right_button;
+	update();
+	minimum_size_changed();
+
+}
+Ref<Texture> Tabs::get_tab_right_button(int p_tab) const{
+
+	ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref<Texture>());
+	return tabs[p_tab].right_button;
+
+}
+
 void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) {
 
 	Tab t;
@@ -316,6 +422,7 @@ void Tabs::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align);
 
 	ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab")));
+	ADD_SIGNAL(MethodInfo("right_button_pressed",PropertyInfo(Variant::INT,"tab")));
 
 	ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") );
 
@@ -328,5 +435,7 @@ Tabs::Tabs() {
 
 	current=0;
 	tab_align=ALIGN_CENTER;
+	rb_hover=-1;
+	rb_pressing=false;
 
 }

+ 7 - 0
scene/gui/tabs.h

@@ -51,6 +51,8 @@ private:
 		Ref<Texture> icon;
 		int ofs_cache;
 		int size_cache;
+		Ref<Texture> right_button;
+		Rect2 rb_rect;
 	};
 
 	Vector<Tab> tabs;
@@ -58,6 +60,8 @@ private:
 	Control *_get_tab(int idx) const;
 	int _get_top_margin() const;
 	TabAlign tab_align;
+	int rb_hover;
+	bool rb_pressing;
 
 protected:
 
@@ -75,6 +79,9 @@ public:
 	void set_tab_icon(int p_tab,const Ref<Texture>& p_icon);
 	Ref<Texture> get_tab_icon(int p_tab) const;
 
+	void set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button);
+	Ref<Texture> get_tab_right_button(int p_tab) const;
+
 	void set_tab_align(TabAlign p_align);
 	TabAlign get_tab_align() const;
 

+ 3 - 1
scene/resources/default_theme/default_theme.cpp

@@ -250,7 +250,6 @@ void make_default_theme() {
 	t->set_stylebox("hover","ToolButton", make_stylebox( button_normal_png,4,4,4,4) );
 	t->set_stylebox("disabled","ToolButton", make_empty_stylebox(4,4,4,4) );
 	t->set_stylebox("focus","ToolButton", focus );
-
 	t->set_font("font","ToolButton", default_font );
 
 	t->set_color("font_color","ToolButton", control_font_color );
@@ -676,6 +675,9 @@ void make_default_theme() {
 	t->set_stylebox("tab_fg","Tabs", make_stylebox( tab_current_png,4,4,4,4,16,4,16,4) );
 	t->set_stylebox("tab_bg","Tabs", make_stylebox( tab_behind_png,4,4,4,4,16,6,16,4) );
 	t->set_stylebox("panel","Tabs", make_stylebox( tab_container_bg_png,4,4,4,4) );
+	t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) );
+	t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) );
+
 
 	t->set_font("font","Tabs", default_font );
 

+ 17 - 0
tools/editor/editor_data.cpp

@@ -515,6 +515,23 @@ String EditorData::get_scene_type(int p_idx) const {
 	return edited_scene[p_idx].root->get_type();
 
 }
+
+Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
+
+	ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),Ref<Script>());
+	if (!edited_scene[p_idx].root)
+		return Ref<Script>();
+	Ref<Script> s=edited_scene[p_idx].root->get_script();
+	if (!s.is_valid()) {
+		Node *n = edited_scene[p_idx].root->get_child(0);
+		while(!s.is_valid() && n && n->get_filename()==String()) {
+			s=n->get_script();
+			n=n->get_parent();
+		}
+	}
+	return s;
+}
+
 String EditorData::get_scene_title(int p_idx) const {
 	ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),String());
 	if (!edited_scene[p_idx].root)

+ 1 - 0
tools/editor/editor_data.h

@@ -178,6 +178,7 @@ public:
 	String get_scene_title(int p_idx) const;
 	String get_scene_path(int p_idx) const;
 	String get_scene_type(int p_idx) const;
+	Ref<Script> get_scene_root_script(int p_idx) const;
 	void set_edited_scene_version(uint64_t version);
 	uint64_t get_edited_scene_version() const;
 	uint64_t get_scene_version(int p_idx) const;

+ 17 - 1
tools/editor/editor_node.cpp

@@ -109,6 +109,7 @@ EditorNode *EditorNode::singleton=NULL;
 void EditorNode::_update_scene_tabs() {
 
 	scene_tabs->clear_tabs();
+	Ref<Texture> script_icon = gui_base->get_icon("Script","EditorIcons");
 	for(int i=0;i<editor_data.get_edited_scene_count();i++) {
 
 		String type=editor_data.get_scene_type(i);
@@ -123,10 +124,16 @@ void EditorNode::_update_scene_tabs() {
 
 		}
 
+
+
 		int current = editor_data.get_edited_scene();
 		bool unsaved = (i==current)?saved_version!=editor_data.get_undo_redo().get_version():editor_data.get_scene_version(i)!=0;
 		scene_tabs->add_tab(editor_data.get_scene_title(i)+(unsaved?"(*)":""),icon);
 
+		if (editor_data.get_scene_root_script(i).is_valid()) {
+			scene_tabs->set_tab_right_button(i,script_icon);
+		}
+
 	}
 
 	scene_tabs->set_current_tab(editor_data.get_edited_scene());
@@ -220,7 +227,7 @@ void EditorNode::_notification(int p_what) {
 				circle_step=0;
 
 			circle_step_msec=tick;
-			circle_step_frame=frame+1;
+		circle_step_frame=frame+1;
 
 			update_menu->set_icon(gui_base->get_icon("Progress"+itos(circle_step+1),"EditorIcons"));
 
@@ -3583,6 +3590,7 @@ void EditorNode::_bind_methods() {
 	ObjectTypeDB::bind_method("set_current_scene",&EditorNode::set_current_scene);
 	ObjectTypeDB::bind_method("set_current_version",&EditorNode::set_current_version);
 	ObjectTypeDB::bind_method("_scene_tab_changed",&EditorNode::_scene_tab_changed);
+	ObjectTypeDB::bind_method("_scene_tab_script_edited",&EditorNode::_scene_tab_script_edited);
 	ObjectTypeDB::bind_method("_set_main_scene_state",&EditorNode::_set_main_scene_state);
 	ObjectTypeDB::bind_method("_update_scene_tabs",&EditorNode::_update_scene_tabs);
 
@@ -4027,6 +4035,13 @@ void EditorNode::_load_docks() {
 }
 
 
+void EditorNode::_scene_tab_script_edited(int p_tab) {
+
+	Ref<Script> script  = editor_data.get_scene_root_script(p_tab);
+	if (script.is_valid())
+		edit_resource(script);
+}
+
 void EditorNode::_scene_tab_changed(int p_tab) {
 
 
@@ -4181,6 +4196,7 @@ EditorNode::EditorNode() {
 	scene_tabs->add_tab("unsaved");
 	scene_tabs->set_tab_align(Tabs::ALIGN_CENTER);
 	scene_tabs->connect("tab_changed",this,"_scene_tab_changed");
+	scene_tabs->connect("right_button_pressed",this,"_scene_tab_script_edited");
 	top_dark_vb->add_child(scene_tabs);
 	//left
 	left_l_hsplit = memnew( HSplitContainer );

+ 1 - 0
tools/editor/editor_node.h

@@ -469,6 +469,7 @@ class EditorNode : public Node {
 	void _dock_split_dragged(int ofs);
 	void _dock_popup_exit();
 	void _scene_tab_changed(int p_tab);
+	void _scene_tab_script_edited(int p_tab);
 
 	Dictionary _get_main_scene_state();
 	void _set_main_scene_state(Dictionary p_state);

+ 1 - 1
tools/editor/project_export.cpp

@@ -1131,7 +1131,7 @@ ProjectExportDialog::ProjectExportDialog(EditorNode *p_editor) {
 	tree->set_column_min_width(1,90);
 
 	filters = memnew( LineEdit );
-	vb->add_margin_child("Filters for Non-Resources (Comma Separated):",filters);
+	vb->add_margin_child("Filters to export non-resource files (Comma Separated, ie: *.json, *.txt):",filters);
 	filters->connect("text_changed",this,"_filters_edited");