Pixel-Composer/scripts/notification_system/notification_system.gml

134 lines
3.3 KiB
Text
Raw Normal View History

2022-11-03 11:44:49 +01:00
#region notification
globalvar STATUSES, WARNING, ERRORS;
STATUSES = ds_list_create();
2024-02-04 07:33:42 +01:00
WARNING = ds_list_create();
ERRORS = ds_list_create();
2022-11-03 11:44:49 +01:00
#endregion
#region classes
enum NOTI_TYPE {
2024-11-20 09:05:51 +01:00
log = 1 << 0,
warning = 1 << 1,
error = 1 << 2,
internal = 1 << 3,
2022-11-03 11:44:49 +01:00
}
2022-11-18 03:20:31 +01:00
function notification(type, str, icon = noone, color = c_ui_blue_dkgrey, life = -1) constructor {
2024-02-04 07:33:42 +01:00
self.type = type;
self.txt = str;
self.txtclr = COLORS._main_text_sub;
self.icon = icon;
self.color = color;
2022-11-03 11:44:49 +01:00
self.life_max = life;
2023-12-10 02:48:10 +01:00
self.life = life;
2022-11-03 11:44:49 +01:00
2024-02-04 07:33:42 +01:00
self.onClick = noone;
self.tooltip = "";
2023-01-17 08:11:55 +01:00
self.icon_end = noone;
2022-11-14 03:16:15 +01:00
2023-02-21 07:38:25 +01:00
self.amount = 1;
2024-11-20 09:05:51 +01:00
self.time = $"{string_lead_zero(current_hour, 2)}:{string_lead_zero(current_minute, 2)}.{string_lead_zero(current_second, 2)}";
2022-12-22 03:09:55 +01:00
2023-01-17 08:11:55 +01:00
static setOnClick = function(onClick, tooltip = "", icon_end = noone) {
2024-02-04 07:33:42 +01:00
self.onClick = method(self, onClick);
self.tooltip = tooltip;
2023-01-17 08:11:55 +01:00
self.icon_end = icon_end;
2022-12-22 03:09:55 +01:00
return self;
}
2024-02-04 07:33:42 +01:00
2024-11-20 09:05:51 +01:00
if(type != NOTI_TYPE.internal) array_push(CMD, self);
2022-11-03 11:44:49 +01:00
}
2023-01-25 06:49:00 +01:00
function noti_status(str, icon = noone, flash = false, ref = noone) {
str = string(str);
2023-03-22 08:47:19 +01:00
show_debug_message("STATUS: " + str);
2024-04-08 07:13:46 +02:00
if(TEST_ERROR) return {};
2023-10-27 13:55:31 +02:00
if(PANEL_MAIN == 0) return;
2023-03-22 08:47:19 +01:00
2023-02-28 09:43:01 +01:00
if(flash && PANEL_MENU) {
PANEL_MENU.noti_flash = 1;
PANEL_MENU.noti_flash_color = flash;
}
2023-02-21 07:38:25 +01:00
if(!ds_list_empty(STATUSES) && STATUSES[| ds_list_size(STATUSES) - 1].txt == str) {
STATUSES[| ds_list_size(STATUSES) - 1].amount++;
2023-02-28 09:43:01 +01:00
return STATUSES[| ds_list_size(STATUSES) - 1];
2023-02-21 07:38:25 +01:00
}
2022-12-22 03:09:55 +01:00
var noti = new notification(NOTI_TYPE.log, str, icon);
ds_list_add(STATUSES, noti);
2023-01-17 08:11:55 +01:00
2023-01-25 06:49:00 +01:00
if(ref) {
var onClick = function() { PANEL_GRAPH.focusNode(self.ref); };
noti.ref = ref;
noti.onClick = method(noti, onClick);
}
2022-12-22 03:09:55 +01:00
return noti;
2022-11-03 11:44:49 +01:00
}
2023-01-25 06:49:00 +01:00
function noti_warning(str, icon = noone, ref = noone) {
2023-10-18 14:58:55 +02:00
if(TEST_ERROR) return {};
2023-10-27 13:55:31 +02:00
if(PANEL_MAIN == 0) return;
2023-03-22 08:47:19 +01:00
2023-02-21 07:38:25 +01:00
if(PANEL_MENU) {
PANEL_MENU.noti_flash = 1;
PANEL_MENU.noti_flash_color = COLORS._main_accent;
}
if(!ds_list_empty(STATUSES) && STATUSES[| ds_list_size(STATUSES) - 1].txt == str) {
2023-12-10 02:48:10 +01:00
var noti = STATUSES[| ds_list_size(STATUSES) - 1];
noti.amount++;
noti.life = noti.life_max;
return noti;
2023-02-21 07:38:25 +01:00
}
2023-12-10 02:48:10 +01:00
show_debug_message("WARNING: " + str);
2023-10-31 05:30:42 +01:00
var noti = new notification(NOTI_TYPE.warning, str, icon, c_ui_orange, PREFERENCES.notification_time);
2024-02-04 07:33:42 +01:00
noti.txtclr = c_ui_orange;
2022-11-03 11:44:49 +01:00
ds_list_add(STATUSES, noti);
ds_list_add(WARNING, noti);
2023-02-14 07:37:13 +01:00
2024-04-08 07:13:46 +02:00
if(!instance_exists(o_dialog_warning)) {
var dia = dialogCall(o_dialog_warning, mouse_mx + ui(16), mouse_my + ui(16));
if(dia) dia.warning_text = str;
}
2022-11-03 11:44:49 +01:00
2023-01-25 06:49:00 +01:00
if(ref) {
var onClick = function() { PANEL_GRAPH.focusNode(self.ref); };
noti.ref = ref;
noti.onClick = method(noti, onClick);
}
2022-11-03 11:44:49 +01:00
return noti;
}
2023-02-14 07:37:13 +01:00
function noti_error(str, icon = noone, ref = noone) {
2023-10-18 14:58:55 +02:00
if(TEST_ERROR) return {};
2023-03-22 08:47:19 +01:00
show_debug_message("ERROR: " + str);
2023-10-27 13:55:31 +02:00
if(PANEL_MAIN == 0) print(str);
2023-03-22 08:47:19 +01:00
2022-11-03 11:44:49 +01:00
var noti = new notification(NOTI_TYPE.error, str, icon, c_ui_red);
2024-02-04 07:33:42 +01:00
noti.txtclr = c_ui_red;
2022-11-03 11:44:49 +01:00
ds_list_add(STATUSES, noti);
ds_list_add(ERRORS, noti);
2023-02-14 07:37:13 +01:00
if(ref) {
var onClick = function() { PANEL_GRAPH.focusNode(self.ref); };
noti.ref = ref;
noti.onClick = method(noti, onClick);
}
2022-11-03 11:44:49 +01:00
return noti;
}
function noti_remove(noti) {
ds_list_remove(STATUSES, noti);
ds_list_remove(ERRORS, noti);
}
#endregion