| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
#include "scene/gui/button.h" |
| 35 |
#include "scene/gui/center_container.h" |
| 36 |
#include "scene/gui/label.h" |
| 37 |
#include "scene/gui/progress_bar.h" |
| 38 |
|
| 39 |
class BackgroundProgress : public HBoxContainer { |
| 40 |
GDCLASS(BackgroundProgress, HBoxContainer); |
| 41 |
|
| 42 |
_THREAD_SAFE_CLASS_ |
| 43 |
|
| 44 |
struct Task { |
| 45 |
HBoxContainer *hb = nullptr; |
| 46 |
ProgressBar *progress = nullptr; |
| 47 |
}; |
| 48 |
|
| 49 |
HashMap<String, Task> tasks; |
| 50 |
HashMap<String, int> updates; |
| 51 |
void _update(); |
| 52 |
|
| 53 |
protected: |
| 54 |
void _add_task(const String &p_task, const String &p_label, int p_steps); |
| 55 |
void _task_step(const String &p_task, int p_step = -1); |
| 56 |
void _end_task(const String &p_task); |
| 57 |
|
| 58 |
public: |
| 59 |
void add_task(const String &p_task, const String &p_label, int p_steps); |
| 60 |
void task_step(const String &p_task, int p_step = -1); |
| 61 |
void end_task(const String &p_task); |
| 62 |
}; |
| 63 |
|
| 64 |
class PanelContainer; |
| 65 |
|
| 66 |
class ProgressDialog : public CenterContainer { |
| 67 |
GDCLASS(ProgressDialog, CenterContainer); |
| 68 |
struct Task { |
| 69 |
String task; |
| 70 |
VBoxContainer *vb = nullptr; |
| 71 |
ProgressBar *progress = nullptr; |
| 72 |
Label *state = nullptr; |
| 73 |
uint64_t last_progress_tick = 0; |
| 74 |
}; |
| 75 |
HBoxContainer *cancel_hb = nullptr; |
| 76 |
Button *cancel = nullptr; |
| 77 |
|
| 78 |
HashMap<String, Task> tasks; |
| 79 |
PanelContainer *center_panel = nullptr; |
| 80 |
VBoxContainer *main = nullptr; |
| 81 |
|
| 82 |
LocalVector<ObjectID> host_windows; |
| 83 |
|
| 84 |
Size2 main_border_size; |
| 85 |
|
| 86 |
static ProgressDialog *singleton; |
| 87 |
void _popup(); |
| 88 |
|
| 89 |
void _cancel_pressed(); |
| 90 |
|
| 91 |
void _update_ui(); |
| 92 |
void _reparent_and_show(); |
| 93 |
bool canceled = false; |
| 94 |
|
| 95 |
protected: |
| 96 |
void _notification(int p_what); |
| 97 |
|
| 98 |
public: |
| 99 |
static ProgressDialog *get_singleton() { return singleton; } |
| 100 |
void add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false); |
| 101 |
bool task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_redraw = true); |
| 102 |
void end_task(const String &p_task); |
| 103 |
|
| 104 |
void add_host_window(ObjectID p_window); |
| 105 |
void remove_host_window(ObjectID p_window); |
| 106 |
|
| 107 |
ProgressDialog(); |
| 108 |
~ProgressDialog(); |
| 109 |
}; |