Pixel-Composer/objects/o_dialog_notifications/Create_0.gml

125 lines
3.6 KiB
Plaintext
Raw Normal View History

2022-11-03 11:44:49 +01:00
/// @description init
event_inherited();
#region data
2022-11-14 03:16:15 +01:00
dialog_w = ui(720);
2023-01-01 02:06:02 +01:00
dialog_h = ui(480);
2022-11-03 11:44:49 +01:00
dialog_resizable = true;
destroy_on_click_out = true;
onResize = function() {
sp_noti.resize(dialog_w - ui(80), dialog_h - ui(88));
}
current_page = 0;
filter = NOTI_TYPE.log | NOTI_TYPE.warning | NOTI_TYPE.error;
2023-01-17 08:11:55 +01:00
rightClickMenu = [
[ "Clear log messages", function() {
for( var i = ds_list_size(STATUSES) - 1; i >= 0; i-- ) {
if(STATUSES[| i].type == NOTI_TYPE.log)
ds_list_delete(STATUSES, i);
}
} ],
[ "Clear warning messages", function() {
for( var i = ds_list_size(STATUSES) - 1; i >= 0; i-- ) {
if(STATUSES[| i].type == NOTI_TYPE.warning)
ds_list_delete(STATUSES, i);
}
} ],
-1,
[ "Clear all notifications", function() {
ds_list_clear(STATUSES);
} ],
-1,
[ "Open log file", function() {
shellOpenExplorer(DIRECTORY + "log.txt");
} ],
];
2022-11-03 11:44:49 +01:00
sp_noti = new scrollPane(dialog_w - ui(80), dialog_h - ui(88), function(_y, _m) {
2022-11-18 03:20:31 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2022-11-03 11:44:49 +01:00
var hh = 32;
var yy = _y;
2022-12-21 02:30:23 +01:00
var txw = sp_noti.surface_w - ui(48 + 48 + 20);
2022-11-14 03:16:15 +01:00
var amo = ds_list_size(STATUSES);
2022-11-03 11:44:49 +01:00
2022-11-18 03:20:31 +01:00
draw_set_font(f_p3);
2022-12-19 13:35:30 +01:00
var timeW = string_width("00:00:00");
2022-11-18 03:20:31 +01:00
2022-11-03 11:44:49 +01:00
for( var i = 0; i < ds_list_size(STATUSES); i++ ) {
2022-11-14 03:16:15 +01:00
var index = amo - 1 - i;
var noti = STATUSES[| index];
2022-11-03 11:44:49 +01:00
if(noti.type & filter == 0) continue;
2022-12-10 05:06:01 +01:00
draw_set_font(f_p2);
2022-11-03 11:44:49 +01:00
var _w = sp_noti.w - ui(12);
var _h = ui(8) + string_height_ext(noti.txt, -1, txw) + ui(8);
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy + ui(2), _w, _h - ui(4), COLORS.dialog_notification_bg, 1);
2022-11-03 11:44:49 +01:00
2022-12-19 13:35:30 +01:00
if(sHOVER && sp_noti.hover && point_in_rectangle(_m[0], _m[1], 0, yy, _w, yy + _h - ui(4))) {
2023-01-17 08:11:55 +01:00
draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy + ui(2), _w, _h - ui(4), COLORS.dialog_notification_bg_hover, 1);
if(noti.tooltip != "")
TOOLTIP = noti.tooltip;
2022-12-12 09:08:03 +01:00
if(noti.onClick != noone && mouse_press(mb_left, sFOCUS))
noti.onClick();
2023-01-17 08:11:55 +01:00
2022-12-12 09:08:03 +01:00
if(mouse_press(mb_right, sFOCUS)) {
var dia = dialogCall(o_dialog_menubox, mouse_mx + ui(8), mouse_my + ui(8));
dia.noti = noti;
dia.setMenu([
[ "Copy notification message", function() {
clipboard_set_text(o_dialog_menubox.noti.txt);
} ],
2023-01-17 08:11:55 +01:00
[ "Delete notification", function() {
ds_list_remove(STATUSES, o_dialog_menubox.noti);
} ],
2022-12-12 09:08:03 +01:00
]);
}
}
2022-11-03 11:44:49 +01:00
if(noti.life_max > 0) {
2022-11-14 03:16:15 +01:00
var _nwx = sp_noti.w - ui(12) - ui(40);
2022-11-03 11:44:49 +01:00
var _nw = _nwx * noti.life / noti.life_max;
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.group_label, 0, ui(40), yy + ui(2), _nw, _h - ui(4), COLORS.dialog_notification_icon_bg, 1);
2022-11-03 11:44:49 +01:00
}
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy + ui(2), ui(48), _h - ui(4), noti.color, 1);
2023-01-17 08:11:55 +01:00
if(noti.icon_end != noone)
draw_sprite_ui(noti.icon_end, 1, _w - ui(24), yy + _h / 2,,,, COLORS._main_icon);
2022-11-21 06:38:44 +01:00
var ic = noti.icon;
if(noti.icon == noone) {
switch(noti.type) {
case NOTI_TYPE.log : ic = THEME.noti_icon_log; break;
case NOTI_TYPE.warning : ic = THEME.noti_icon_warning; break;
case NOTI_TYPE.error : ic = THEME.noti_icon_error; break;
}
}
2022-11-18 03:20:31 +01:00
draw_sprite_ui(ic, 1, ui(24), yy + _h / 2);
2022-11-03 11:44:49 +01:00
2022-11-18 03:20:31 +01:00
var tx = ui(48) + timeW + ui(12);
2022-11-03 11:44:49 +01:00
2023-01-17 08:11:55 +01:00
if(yy >= -_h && yy <= sp_noti.h) {
draw_set_text(f_p3, fa_right, fa_center, COLORS._main_text_sub);
draw_text_ext(tx - ui(4), yy + _h / 2, noti.time, -1, txw);
2022-11-14 03:16:15 +01:00
2023-01-17 08:11:55 +01:00
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text);
draw_text_ext(tx + ui(4), yy + _h / 2, noti.txt, -1, txw);
}
2022-11-03 11:44:49 +01:00
yy += _h;
hh += _h;
}
return hh;
})
#endregion