Pixel-Composer/scripts/notification_system/notification_system.gml

118 lines
3.0 KiB
Plaintext
Raw Normal View History

2022-11-03 11:44:49 +01:00
#region notification
globalvar STATUSES, WARNING, ERRORS;
STATUSES = ds_list_create();
WARNING = ds_list_create();
ERRORS = ds_list_create();
#endregion
#region classes
enum NOTI_TYPE {
2023-02-14 07:37:13 +01:00
log = 1 << 0,
warning = 1 << 1,
error = 1 << 2,
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 {
2022-11-03 11:44:49 +01:00
self.type = type;
self.txt = str;
self.icon = icon;
self.color = color;
self.life_max = life;
self.life = life;
self.onClick = noone;
2023-01-17 08:11:55 +01:00
self.tooltip = "";
self.icon_end = noone;
2022-11-14 03:16:15 +01:00
2023-02-21 07:38:25 +01:00
self.amount = 1;
2022-12-19 13:35:30 +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) {
2022-12-22 03:09:55 +01:00
self.onClick = method(self, onClick);
2023-01-17 08:11:55 +01:00
self.tooltip = tooltip;
self.icon_end = icon_end;
2022-12-22 03:09:55 +01:00
return 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) {
2023-06-17 18:59:20 +02:00
if(TEST_ERROR) return;
str = string(str);
2023-03-22 08:47:19 +01:00
show_debug_message("STATUS: " + str);
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-06-17 18:59:20 +02:00
if(TEST_ERROR) return;
2023-03-22 08:47:19 +01:00
show_debug_message("WARNING: " + str);
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) {
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.warning, str, icon, c_ui_orange, PREF_MAP[? "notification_time"]);
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
2023-08-02 19:11:57 +02:00
if(!instance_exists(o_dialog_warning))
2023-02-15 10:43:24 +01:00
dialogCall(o_dialog_warning, mouse_mx + ui(16), mouse_my + ui(16)).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-06-17 18:59:20 +02:00
if(TEST_ERROR) return;
2023-03-22 08:47:19 +01:00
show_debug_message("ERROR: " + str);
2022-11-03 11:44:49 +01:00
var noti = new notification(NOTI_TYPE.error, str, icon, c_ui_red);
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