Show tooltips even when paused or time_scale is 0

This commit is contained in:
kobewi 2021-11-22 12:54:05 +01:00
parent 451bba967a
commit 5b55599211
4 changed files with 31 additions and 15 deletions

View file

@ -80,6 +80,14 @@ bool SceneTreeTimer::is_pause_mode_process() {
return process_pause;
}
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);
@ -557,8 +565,13 @@ bool SceneTree::idle(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_idle_frame_step();
} else {
time_left -= p_time;
}
E->get()->set_time_left(time_left);
if (time_left < 0) {

View file

@ -50,6 +50,7 @@ class SceneTreeTimer : public Reference {
float time_left;
bool process_pause;
bool ignore_time_scale = false;
protected:
static void _bind_methods();
@ -61,6 +62,9 @@ public:
void set_pause_mode_process(bool p_pause_mode_process);
bool is_pause_mode_process();
void set_ignore_time_scale(bool p_ignore);
bool is_ignore_time_scale();
void release_connections();
SceneTreeTimer();

View file

@ -333,7 +333,6 @@ void Viewport::_notification(int p_what) {
#endif
// Enable processing for tooltips, collision debugging, physics object picking, etc.
set_process_internal(true);
set_physics_process_internal(true);
} break;
@ -361,16 +360,6 @@ void Viewport::_notification(int p_what) {
remove_from_group("_viewports");
VS::get_singleton()->viewport_set_active(viewport, false);
} 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();
}
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
@ -1500,7 +1489,10 @@ void Viewport::_gui_sort_roots() {
void Viewport::_gui_cancel_tooltip() {
gui.tooltip_control = nullptr;
gui.tooltip_timer = -1;
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;
@ -2241,9 +2233,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 = mpos;
gui.tooltip_timer = gui.tooltip_delay;
gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay);
gui.tooltip_timer->set_ignore_time_scale(true);
gui.tooltip_timer->connect("timeout", this, "_gui_show_tooltip");
}
}

View file

@ -49,6 +49,7 @@ class Label;
class Timer;
class Viewport;
class CollisionObject;
class SceneTreeTimer;
class ViewportTexture : public Texture {
GDCLASS(ViewportTexture, Texture);
@ -308,7 +309,7 @@ private:
bool drag_attempted;
Variant drag_data;
ObjectID drag_preview_id;
float tooltip_timer;
Ref<SceneTreeTimer> tooltip_timer;
float tooltip_delay;
List<Control *> modal_stack;
Transform2D focus_inv_xform;