Godot Engine – Multi-platform 2D and 3D game engine
Tree: Fix range cell tooltip displaying full option list
Amen Hanyf89f1cad4342
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cppindex 2fc50f8a079..53be0b47bef 100644--- a/scene/gui/tree.cpp+++ b/scene/gui/tree.cpp@@ -2236,28 +2236,12 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) const {p_item->cells.write[p_col].text_buf->clear();if (p_item->cells[p_col].mode == TreeItem::CELL_MODE_RANGE) {+ if (!p_item->cells[p_col].text.is_empty() && !p_item->cells[p_col].editable) {+ return;+ }+ valtext = _get_range_cell_text(p_item->cells[p_col]);if (!p_item->cells[p_col].text.is_empty()) {- if (!p_item->cells[p_col].editable) {- return;- }-- int option = (int)p_item->cells[p_col].val;-- valtext = p_item->atr(p_col, ETR("(Other)"));- Vector<String> strings = p_item->cells[p_col].text.split(",");- for (int j = 0; j < strings.size(); j++) {- int value = j;- if (!strings[j].get_slicec(':', 1).is_empty()) {- value = strings[j].get_slicec(':', 1).to_int();- }- if (option == value) {- valtext = p_item->atr(p_col, strings[j].get_slicec(':', 0));- break;- }- }-- } else {- valtext = String::num(p_item->cells[p_col].val, Math::range_step_decimals(p_item->cells[p_col].step));+ valtext = p_item->atr(p_col, valtext);}} else {// Don't auto translate if it's in string mode and editable, as the text can be changed to anything by the user.@@ -3644,6 +3628,28 @@ void Tree::_update_value_editor(const TreeItem::Cell &p_cell) {updating_value_editor = false;}+String Tree::_get_range_cell_text(const TreeItem::Cell &p_cell) const {+ if (p_cell.text.is_empty()) {+ return String::num(p_cell.val, Math::range_step_decimals(p_cell.step));+ }++ int option = (int)p_cell.val;+ String valtext = ETR("(Other)");+ Vector<String> strings = p_cell.text.split(",");++ for (int j = 0; j < strings.size(); j++) {+ int value = j;+ if (!strings[j].get_slicec(':', 1).is_empty()) {+ value = strings[j].get_slicec(':', 1).to_int();+ }+ if (option == value) {+ valtext = strings[j].get_slicec(':', 0);+ break;+ }+ }+ return valtext;+}+void Tree::popup_select(int p_option) {if (!popup_edited_item) {return;@@ -7277,6 +7283,9 @@ String Tree::get_tooltip(const Point2 &p_pos) const {if (it) {const String item_tooltip = it->get_tooltip_text(col);if (enable_auto_tooltip && item_tooltip.is_empty()) {+ if (it->cells[col].mode == TreeItem::CELL_MODE_RANGE) {+ return _get_range_cell_text(it->cells[col]);+ }return it->get_text(col);}return item_tooltip;diff --git a/scene/gui/tree.h b/scene/gui/tree.hindex 8094117b6fd..2ad7d402338 100644--- a/scene/gui/tree.h+++ b/scene/gui/tree.h@@ -610,6 +610,7 @@ private:void value_editor_changed(double p_value);void _update_popup_menu(const TreeItem::Cell &p_cell);void _update_value_editor(const TreeItem::Cell &p_cell);+ String _get_range_cell_text(const TreeItem::Cell &p_cell) const;void popup_select(int p_option);