Show tooltips even when paused or time_scale is 0

This commit is contained in:
kobewi 2021-02-27 00:37:20 +01:00
parent 8cddd3b2c0
commit 8793ec4564
4 changed files with 31 additions and 17 deletions

View File

@ -82,6 +82,14 @@ bool SceneTreeTimer::is_process_always() {
return process_always;
}
void SceneTreeTimer::set_ignore_time_scale(bool p_ignore) {
ignore_time_scale = p_ignore;
}
bool SceneTreeTimer::is_ignore_time_scale() {
return ignore_time_scale;
}
void SceneTreeTimer::release_connections() {
List<Connection> connections;
get_all_signal_connections(&connections);
@ -466,8 +474,13 @@ bool SceneTree::process(float p_time) {
E = N;
continue;
}
float time_left = E->get()->get_time_left();
time_left -= p_time;
if (E->get()->is_ignore_time_scale()) {
time_left -= Engine::get_singleton()->get_process_step();
} else {
time_left -= p_time;
}
E->get()->set_time_left(time_left);
if (time_left < 0) {

View File

@ -54,6 +54,7 @@ class SceneTreeTimer : public RefCounted {
float time_left = 0.0;
bool process_always = true;
bool ignore_time_scale = false;
protected:
static void _bind_methods();
@ -65,6 +66,9 @@ public:
void set_process_always(bool p_process_always);
bool is_process_always();
void set_ignore_time_scale(bool p_ignore);
bool is_ignore_time_scale();
void release_connections();
SceneTreeTimer();

View File

@ -502,17 +502,6 @@ void Viewport::_notification(int p_what) {
RS::get_singleton()->viewport_set_active(viewport, false);
RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
if (gui.tooltip_timer >= 0) {
gui.tooltip_timer -= get_process_delta_time();
if (gui.tooltip_timer < 0) {
_gui_show_tooltip();
set_process_internal(false);
}
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
@ -1489,8 +1478,10 @@ void Viewport::_gui_sort_roots() {
void Viewport::_gui_cancel_tooltip() {
gui.tooltip_control = nullptr;
gui.tooltip_timer = -1;
set_process_internal(false);
if (gui.tooltip_timer.is_valid()) {
gui.tooltip_timer->release_connections();
gui.tooltip_timer = Ref<SceneTreeTimer>();
}
if (gui.tooltip_popup) {
gui.tooltip_popup->queue_delete();
gui.tooltip_popup = nullptr;
@ -2139,10 +2130,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
if (can_tooltip && !is_tooltip_shown) {
if (gui.tooltip_timer.is_valid()) {
gui.tooltip_timer->release_connections();
gui.tooltip_timer = Ref<SceneTreeTimer>();
}
gui.tooltip_control = over;
gui.tooltip_pos = over->get_screen_transform().xform(pos);
gui.tooltip_timer = gui.tooltip_delay;
set_process_internal(true);
gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay);
gui.tooltip_timer->set_ignore_time_scale(true);
gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip));
}
}

View File

@ -50,6 +50,7 @@ class Label;
class Timer;
class Viewport;
class CollisionObject3D;
class SceneTreeTimer;
class ViewportTexture : public Texture2D {
GDCLASS(ViewportTexture, Texture2D);
@ -373,7 +374,7 @@ private:
bool drag_attempted = false;
Variant drag_data;
ObjectID drag_preview_id;
float tooltip_timer = -1.0;
Ref<SceneTreeTimer> tooltip_timer;
float tooltip_delay = 0.0;
Transform2D focus_inv_xform;
bool roots_order_dirty = false;