Removed stupid right arrow to edit resource. Now simply click it..

This commit is contained in:
Juan Linietsky 2017-06-04 20:35:08 -03:00
parent 5aa66d03d8
commit 01198cb896
5 changed files with 108 additions and 11 deletions

View File

@ -247,6 +247,10 @@ Ref<Theme> create_editor_theme() {
theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("TreeArrowRight", "EditorIcons")); theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("TreeArrowRight", "EditorIcons"));
theme->set_icon("select_arrow", "Tree", theme->get_icon("Dropdown", "EditorIcons")); theme->set_icon("select_arrow", "Tree", theme->get_icon("Dropdown", "EditorIcons"));
theme->set_stylebox("bg_focus", "Tree", focus_sbt); theme->set_stylebox("bg_focus", "Tree", focus_sbt);
theme->set_stylebox("custom_button", "Tree", style_button);
theme->set_stylebox("custom_button_pressed", "Tree", style_button);
theme->set_stylebox("custom_button_hover", "Tree", style_button);
theme->set_color("custom_button_font_highlight", "Tree", HIGHLIGHT_COLOR_LIGHT);
Ref<StyleBox> style_tree_btn = make_flat_stylebox(light_color_1, 2, 4, 2, 4); Ref<StyleBox> style_tree_btn = make_flat_stylebox(light_color_1, 2, 4, 2, 4);
theme->set_stylebox("button_pressed", "Tree", style_tree_btn); theme->set_stylebox("button_pressed", "Tree", style_tree_btn);

View File

@ -2310,6 +2310,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p
if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) { if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) {
p_item->set_text(1, "<null>"); p_item->set_text(1, "<null>");
p_item->set_icon(1, Ref<Texture>()); p_item->set_icon(1, Ref<Texture>());
p_item->set_custom_as_button(1, false);
Dictionary d = p_item->get_metadata(0); Dictionary d = p_item->get_metadata(0);
int hint = d.has("hint") ? d["hint"].operator int() : -1; int hint = d.has("hint") ? d["hint"].operator int() : -1;
@ -2319,6 +2320,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p
} }
} else { } else {
p_item->set_custom_as_button(1, true);
RES res = obj->get(p_name).operator RefPtr(); RES res = obj->get(p_name).operator RefPtr();
if (res->is_class("Texture")) { if (res->is_class("Texture")) {
int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width");
@ -3540,17 +3542,21 @@ void PropertyEditor::update_tree() {
item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM);
item->set_editable(1, !read_only); item->set_editable(1, !read_only);
item->add_button(1, get_icon("EditResource", "EditorIcons")); //item->add_button(1, get_icon("EditResource", "EditorIcons"));
String type; String type;
if (p.hint == PROPERTY_HINT_RESOURCE_TYPE) if (p.hint == PROPERTY_HINT_RESOURCE_TYPE)
type = p.hint_string; type = p.hint_string;
if (obj->get(p.name).get_type() == Variant::NIL || obj->get(p.name).operator RefPtr().is_null()) { RES res = obj->get(p.name).operator RefPtr();
if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) {
item->set_text(1, "<null>"); item->set_text(1, "<null>");
item->set_icon(1, Ref<Texture>()); item->set_icon(1, Ref<Texture>());
item->set_custom_as_button(1, false);
} else { } else if (res.is_valid()) {
RES res = obj->get(p.name).operator RefPtr();
item->set_custom_as_button(1, true);
if (res->is_class("Texture")) { if (res->is_class("Texture")) {
int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width");
@ -3853,6 +3859,16 @@ void PropertyEditor::_item_edited() {
case Variant::NODE_PATH: { case Variant::NODE_PATH: {
_edit_set(name, NodePath(item->get_text(1)), refresh_all); _edit_set(name, NodePath(item->get_text(1)), refresh_all);
} break;
case Variant::OBJECT: {
if (!item->is_custom_set_as_button(1))
break;
RES res = obj->get(name);
if (res.is_valid()) {
emit_signal("resource_selected", res.get_ref_ptr(), name);
}
} break; } break;
case Variant::DICTIONARY: { case Variant::DICTIONARY: {

View File

@ -610,6 +610,18 @@ Color TreeItem::get_custom_bg_color(int p_column) const {
return cells[p_column].bg_color; return cells[p_column].bg_color;
} }
void TreeItem::set_custom_as_button(int p_column, bool p_button) {
ERR_FAIL_INDEX(p_column, cells.size());
cells[p_column].custom_button = p_button;
}
bool TreeItem::is_custom_set_as_button(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].custom_button;
}
void TreeItem::_bind_methods() { void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode); ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
@ -670,6 +682,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color); ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color);
ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color); ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color);
ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button);
ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button);
ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL("")); ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count); ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count);
ClassDB::bind_method(D_METHOD("get_button:Texture", "column", "button_idx"), &TreeItem::get_button); ClassDB::bind_method(D_METHOD("get_button:Texture", "column", "button_idx"), &TreeItem::get_button);
@ -732,6 +747,10 @@ TreeItem::~TreeItem() {
tree->pressing_for_editor = false; tree->pressing_for_editor = false;
} }
if (tree && tree->cache.hover_item == this) {
tree->cache.hover_item = NULL;
}
if (tree && tree->selected_item == this) if (tree && tree->selected_item == this)
tree->selected_item = NULL; tree->selected_item = NULL;
@ -772,6 +791,11 @@ void Tree::update_cache() {
cache.select_arrow = get_icon("select_arrow"); cache.select_arrow = get_icon("select_arrow");
cache.updown = get_icon("updown"); cache.updown = get_icon("updown");
cache.custom_button = get_stylebox("custom_button");
cache.custom_button_hover = get_stylebox("custom_button_hover");
cache.custom_button_pressed = get_stylebox("custom_button_pressed");
cache.custom_button_font_highlight = get_color("custom_button_font_highlight");
cache.font_color = get_color("font_color"); cache.font_color = get_color("font_color");
cache.font_color_selected = get_color("font_color_selected"); cache.font_color_selected = get_color("font_color_selected");
cache.guide_color = get_color("guide_color"); cache.guide_color = get_color("guide_color");
@ -833,6 +857,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
if (s.height > height) if (s.height > height)
height = s.height; height = s.height;
} }
if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
height += cache.custom_button->get_minimum_size().height;
}
} break; } break;
default: {} default: {}
@ -1202,12 +1229,28 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Ref<Texture> downarrow = cache.select_arrow; Ref<Texture> downarrow = cache.select_arrow;
Rect2i ir = item_rect; Rect2i ir = item_rect;
ir.size.width -= downarrow->get_width();
draw_item_rect(p_item->cells[i], ir, col);
Point2i arrow_pos = item_rect.pos; Point2i arrow_pos = item_rect.pos;
arrow_pos.x += item_rect.size.x - downarrow->get_width(); arrow_pos.x += item_rect.size.x - downarrow->get_width();
arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0); arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0);
ir.size.width -= downarrow->get_width();
if (p_item->cells[i].custom_button) {
if (cache.hover_item == p_item && cache.hover_cell == i) {
if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
draw_style_box(cache.custom_button_pressed, ir);
} else {
draw_style_box(cache.custom_button_hover, ir);
col = cache.custom_button_font_highlight;
}
} else {
draw_style_box(cache.custom_button, ir);
}
ir.size -= cache.custom_button->get_minimum_size();
ir.pos += cache.custom_button->get_offset();
}
draw_item_rect(p_item->cells[i], ir, col);
downarrow->draw(ci, arrow_pos); downarrow->draw(ci, arrow_pos);
@ -1697,11 +1740,18 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
case TreeItem::CELL_MODE_CUSTOM: { case TreeItem::CELL_MODE_CUSTOM: {
edited_item = p_item; edited_item = p_item;
edited_col = col; edited_col = col;
custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); bool on_arrow = x > col_width - cache.select_arrow->get_width();
emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
bring_up_editor = false; bring_up_editor = false;
item_edited(col, p_item);
if (on_arrow || !p_item->cells[col].custom_button) {
custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
}
if (!p_item->cells[col].custom_button || !on_arrow) {
item_edited(col, p_item);
}
click_handled = true; click_handled = true;
return -1; return -1;
} break; } break;
@ -2148,7 +2198,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} }
} }
if (drop_mode_flags && root) { if (root) {
Point2 mpos = mm->get_position(); Point2 mpos = mm->get_position();
mpos -= cache.bg->get_offset(); mpos -= cache.bg->get_offset();
@ -2163,11 +2213,17 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
int col, h, section; int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
if (it != drop_mode_over || section != drop_mode_section) { if (drop_mode_flags && it != drop_mode_over || section != drop_mode_section) {
drop_mode_over = it; drop_mode_over = it;
drop_mode_section = section; drop_mode_section = section;
update(); update();
} }
if (it != cache.hover_item || col != cache.hover_cell) {
cache.hover_item = it;
cache.hover_cell = col;
update();
}
} }
} }
@ -3469,6 +3525,7 @@ void Tree::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos"))); ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos"))); ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("item_edited")); ADD_SIGNAL(MethodInfo("item_edited"));
ADD_SIGNAL(MethodInfo("item_custom_button_pressed"));
ADD_SIGNAL(MethodInfo("item_double_clicked")); ADD_SIGNAL(MethodInfo("item_double_clicked"));
ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item"))); ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item")));
//ADD_SIGNAL( MethodInfo("item_doubleclicked" ) ); //ADD_SIGNAL( MethodInfo("item_doubleclicked" ) );
@ -3575,6 +3632,9 @@ Tree::Tree() {
force_edit_checkbox_only_on_checkbox = false; force_edit_checkbox_only_on_checkbox = false;
set_clip_contents(true); set_clip_contents(true);
cache.hover_item = NULL;
cache.hover_cell = -1;
} }
Tree::~Tree() { Tree::~Tree() {

View File

@ -81,6 +81,7 @@ private:
bool custom_bg_color; bool custom_bg_color;
bool custom_bg_outline; bool custom_bg_outline;
Color bg_color; Color bg_color;
bool custom_button;
Variant meta; Variant meta;
String tooltip; String tooltip;
@ -107,6 +108,7 @@ private:
Cell() { Cell() {
custom_draw_obj = 0; custom_draw_obj = 0;
custom_button = false;
mode = TreeItem::CELL_MODE_STRING; mode = TreeItem::CELL_MODE_STRING;
min = 0; min = 0;
max = 100; max = 100;
@ -238,6 +240,9 @@ public:
void clear_custom_bg_color(int p_column); void clear_custom_bg_color(int p_column);
Color get_custom_bg_color(int p_column) const; Color get_custom_bg_color(int p_column) const;
void set_custom_as_button(int p_column, bool p_button);
bool is_custom_set_as_button(int p_column) const;
void set_tooltip(int p_column, const String &p_tooltip); void set_tooltip(int p_column, const String &p_tooltip);
String get_tooltip(int p_column) const; String get_tooltip(int p_column) const;
@ -369,6 +374,10 @@ private:
Ref<StyleBox> title_button; Ref<StyleBox> title_button;
Ref<StyleBox> title_button_hover; Ref<StyleBox> title_button_hover;
Ref<StyleBox> title_button_pressed; Ref<StyleBox> title_button_pressed;
Ref<StyleBox> custom_button;
Ref<StyleBox> custom_button_hover;
Ref<StyleBox> custom_button_pressed;
Color title_button_color; Color title_button_color;
Ref<Texture> checked; Ref<Texture> checked;
@ -383,6 +392,7 @@ private:
Color guide_color; Color guide_color;
Color drop_position_color; Color drop_position_color;
Color relationship_line_color; Color relationship_line_color;
Color custom_button_font_highlight;
int hseparation; int hseparation;
int vseparation; int vseparation;
@ -410,6 +420,9 @@ private:
int hover_index; int hover_index;
Point2 click_pos; Point2 click_pos;
TreeItem *hover_item;
int hover_cell;
} cache; } cache;
int _get_title_button_height() const; int _get_title_button_height() const;

View File

@ -626,6 +626,9 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
t->set_stylebox("title_button_normal", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4)); t->set_stylebox("title_button_normal", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4));
t->set_stylebox("title_button_pressed", "Tree", make_stylebox(tree_title_pressed_png, 4, 4, 4, 4)); t->set_stylebox("title_button_pressed", "Tree", make_stylebox(tree_title_pressed_png, 4, 4, 4, 4));
t->set_stylebox("title_button_hover", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4)); t->set_stylebox("title_button_hover", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4));
t->set_stylebox("custom_button", "Tree", sb_button_normal);
t->set_stylebox("custom_button_pressed", "Tree", sb_button_pressed);
t->set_stylebox("custom_button_hover", "Tree", sb_button_hover);
t->set_icon("checked", "Tree", make_icon(checked_png)); t->set_icon("checked", "Tree", make_icon(checked_png));
t->set_icon("unchecked", "Tree", make_icon(unchecked_png)); t->set_icon("unchecked", "Tree", make_icon(unchecked_png));
@ -645,6 +648,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
t->set_color("guide_color", "Tree", Color(0, 0, 0, 0.1)); t->set_color("guide_color", "Tree", Color(0, 0, 0, 0.1));
t->set_color("drop_position_color", "Tree", Color(1, 0.3, 0.2)); t->set_color("drop_position_color", "Tree", Color(1, 0.3, 0.2));
t->set_color("relationship_line_color", "Tree", Color::html("464646")); t->set_color("relationship_line_color", "Tree", Color::html("464646"));
t->set_color("custom_button_font_highlight", "Tree", control_font_color_hover);
t->set_constant("hseparation", "Tree", 4 * scale); t->set_constant("hseparation", "Tree", 4 * scale);
t->set_constant("vseparation", "Tree", 4 * scale); t->set_constant("vseparation", "Tree", 4 * scale);