Skip to content

Commit

Permalink
fixed duration arg of text
Browse files Browse the repository at this point in the history
fixed value color of text
  • Loading branch information
DmitriySalnikov committed Sep 3, 2023
1 parent 49ab1a5 commit 72d114b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var button_presses = {}
var time := 0.0
var time2 := 0.0
var time3 := 0.0
var time_text := 0.0

func _ready() -> void:
_update_keys_just_press()
Expand Down Expand Up @@ -204,6 +205,7 @@ func _process(delta: float) -> void:
DebugDraw2D.config.text_custom_font = custom_font

if test_text:
time_text -= delta
_text_tests()

# Graphs
Expand Down Expand Up @@ -238,6 +240,10 @@ func _process(delta: float) -> void:


func _text_tests():
if time_text < 0:
DebugDraw2D.set_text("Some delayed text", "for 2.5s", -1, Color.BLACK, 2.5) # it's supposed to show text for 2.5 seconds
time_text += 5

DebugDraw2D.set_text("FPS", "%.2f" % Engine.get_frames_per_second(), 0, Color.GOLD)

DebugDraw2D.begin_text_group("-- First Group --", 2, Color.LIME_GREEN, true, text_groups_title_font_size, text_groups_text_font_size)
Expand Down
2 changes: 1 addition & 1 deletion examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ stretch = true
[node name="Viewport" type="SubViewport" parent="Panel/ViewportContainer"]
handle_input_locally = false
size = Vector2i(2, 2)
size = Vector2i(300, 300)
render_target_update_mode = 0
[node name="CameraLayer2_5" type="Camera3D" parent="Panel/ViewportContainer/Viewport"]
Expand Down
14 changes: 6 additions & 8 deletions src/2d/grouped_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ bool TextGroupItem::update(const double &_expiration_time, const String &_key, c
}

bool TextGroupItem::is_expired() {
if (second_chance) {
second_chance = false;
return false;
}
return expiration_time > 0;
return expiration_time > 0 ? false : !second_chance;
}

void TextGroup::set_group_priority(int _val) {
Expand Down Expand Up @@ -109,6 +105,8 @@ void TextGroup::cleanup_texts(const std::function<void()> &_update, const double
k->expiration_time -= _delta;
if (k->is_expired()) {
keysToRemove.insert(k);
} else {
k->second_chance = false;
}
}

Expand All @@ -120,7 +118,7 @@ void TextGroup::cleanup_texts(const std::function<void()> &_update, const double
_update();
}

void GroupedText::_create_new_default_groupd_if_needed() {
void GroupedText::_create_new_default_group_if_needed() {
LOCK_GUARD(datalock);
if (!_current_text_group) {
_current_text_group = std::make_shared<TextGroup>(owner, "", 0, false, owner->get_config()->get_text_foreground_color(), 0, owner->get_config()->get_text_default_size());
Expand Down Expand Up @@ -222,7 +220,7 @@ void GroupedText::set_text(const String &_key, const Variant &_value, const int
{
LOCK_GUARD(datalock);

_create_new_default_groupd_if_needed();
_create_new_default_group_if_needed();

TextGroupItem_ptr item;

Expand Down Expand Up @@ -309,7 +307,7 @@ void GroupedText::draw(CanvasItem *_ci, const Ref<Font> &_font, const Vector2 &_

text_parts.push_back(DrawTextInstance(text.substr(_keyLength, text.length() - _keyLength), draw_font, font_size,
Vector2(pos.x + font_offset.x + size_right_revert + draw_font->get_string_size(textSep, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x, pos.y + font_offset.y).floor(),
g->get_group_color()));
t->value_color));
}
pos.y += size.y + text_padding.y * 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/2d/grouped_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class GroupedText {
class DebugDraw2D *owner = nullptr;
std::recursive_mutex datalock;

void _create_new_default_groupd_if_needed();
void _create_new_default_group_if_needed();

public:
void init_group(class DebugDraw2D *p_owner);
Expand Down
2 changes: 1 addition & 1 deletion src/3d/render_instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void GeometryPool::fill_lines_data(Ref<ArrayMesh> _ig) {

size_t spent_timer = TIME()->get_ticks_usec();

// 1000 frustums. Avoiding a large number of resizes increased the speed from 1.9-2.0ms to 1.4-1.5ms
// Avoiding a large number of resizes increased the speed from 1.9-2.0ms to 1.4-1.5ms
size_t used_vertices = 0;

// pre calculate buffer size
Expand Down

0 comments on commit 72d114b

Please sign in to comment.