Improve string printing in the tiledata editor
(cherry picked from commit 1649dcad0b
)
This commit is contained in:
parent
ab14aa9f16
commit
8cefce591a
|
@ -1185,19 +1185,18 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2
|
||||||
Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
|
Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
|
||||||
int font_size = TileSetEditor::get_singleton()->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
|
int font_size = TileSetEditor::get_singleton()->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
|
||||||
String text;
|
String text;
|
||||||
|
// Round floating point precision to 2 digits, as tiles don't have that much space.
|
||||||
switch (value.get_type()) {
|
switch (value.get_type()) {
|
||||||
case Variant::INT:
|
|
||||||
text = vformat("%d", value);
|
|
||||||
break;
|
|
||||||
case Variant::FLOAT:
|
case Variant::FLOAT:
|
||||||
text = vformat("%.2f", value);
|
text = vformat("%.2f", value);
|
||||||
break;
|
break;
|
||||||
case Variant::STRING:
|
case Variant::VECTOR2:
|
||||||
case Variant::STRING_NAME:
|
case Variant::VECTOR3:
|
||||||
text = value;
|
case Variant::VECTOR4:
|
||||||
|
text = vformat("%.2v", value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
text = value.stringify();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1216,8 +1215,8 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size);
|
Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size);
|
||||||
p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1));
|
p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 3, Color(0, 0, 0));
|
||||||
p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color);
|
p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue