Pixel-Composer/scripts/panel_notification/panel_notification.gml

185 lines
6.9 KiB
Text
Raw Normal View History

2024-08-10 07:30:41 +02:00
#region funtion calls
function __fnInit_Notification() {
registerFunction("Notifications", "Clear log messages", "", MOD_KEY.none, notification_clear_all ).setMenu("noti_clear_all");
registerFunction("Notifications", "Clear warning messages", "", MOD_KEY.none, notification_clear_log ).setMenu("noti_clear_log");
registerFunction("Notifications", "Clear all notifications", "", MOD_KEY.none, notification_clear_warning ).setMenu("noti_clear_warning");
registerFunction("Notifications", "Open log file", "", MOD_KEY.none, notification_open_log ).setMenu("noti_open_log");
}
function notification_clear_all() { CALL("notification_clear_all"); ds_list_clear(STATUSES); }
function notification_clear_log() { CALL("notification_clear_log"); for( var i = ds_list_size(STATUSES) - 1; i >= 0; i-- ) if(STATUSES[| i].type == NOTI_TYPE.log) ds_list_delete(STATUSES, i); }
function notification_clear_warning() { CALL("notification_clear_warning"); for( var i = ds_list_size(STATUSES) - 1; i >= 0; i-- ) if(STATUSES[| i].type == NOTI_TYPE.warning) ds_list_delete(STATUSES, i); }
function notification_open_log() { CALL("notification_open_log"); shellOpenExplorer(DIRECTORY + "log/log.txt"); }
#endregion
2023-03-12 02:28:21 +01:00
function Panel_Notification() : PanelContent() constructor {
2023-06-04 18:28:29 +02:00
title = __txt("Notifications");
2023-03-12 02:28:21 +01:00
w = ui(720);
h = ui(480);
title_height = 64;
2024-08-10 07:30:41 +02:00
padding = 20;
2023-03-12 02:28:21 +01:00
2024-08-10 07:30:41 +02:00
current_page = 0;
filter = NOTI_TYPE.log | NOTI_TYPE.warning | NOTI_TYPE.error;
showHeader = false;
noti_selecting = noone;
2023-03-12 02:28:21 +01:00
rightClickMenu = [
2024-08-10 07:30:41 +02:00
MENU_ITEMS.noti_clear_all,
MENU_ITEMS.noti_clear_log,
MENU_ITEMS.noti_clear_warning,
2023-03-12 02:28:21 +01:00
-1,
2024-08-10 07:30:41 +02:00
MENU_ITEMS.noti_open_log,
2023-03-12 02:28:21 +01:00
];
function onResize() {
PANEL_PADDING
sp_noti.resize(w - ui(padding + padding), h - ui(title_height + padding));
}
sp_noti = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2023-06-10 13:59:45 +02:00
var hh = 32;
var yy = _y;
2023-03-12 02:28:21 +01:00
var txw = sp_noti.surface_w - ui(48 + 48 + 20);
var amo = ds_list_size(STATUSES);
2023-06-10 13:59:45 +02:00
var pad = THEME_VALUE.panel_notification_padding;
2023-03-12 02:28:21 +01:00
draw_set_font(f_p3);
var timeW = string_width("00:00:00");
2024-04-13 07:32:04 +02:00
for( var i = 0; i < amo; i++ ) {
2023-03-12 02:28:21 +01:00
var index = amo - 1 - i;
var noti = STATUSES[| index];
2024-04-13 07:32:04 +02:00
if(is_undefined(noti)) continue;
2023-03-12 02:28:21 +01:00
if(noti.type & filter == 0) continue;
draw_set_font(f_p2);
var _w = sp_noti.surface_w;
2023-06-10 13:59:45 +02:00
var _h = ui(12) + string_height_ext(noti.txt, -1, txw);
_h += pad * 2;
2023-03-12 02:28:21 +01:00
if(yy >= -_h && yy <= sp_noti.h) {
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, 0, yy, _w, _h, COLORS.dialog_notification_bg, 1);
2023-03-12 02:28:21 +01:00
2023-06-10 13:59:45 +02:00
if(pHOVER && pHOVER && point_in_rectangle(_m[0], _m[1], 0, yy, _w, yy + _h)) {
2024-07-28 13:55:57 +02:00
sp_noti.hover_content = true;
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, 0, yy, _w, _h, COLORS.dialog_notification_bg_hover, 1);
2023-03-12 02:28:21 +01:00
if(noti.tooltip != "")
TOOLTIP = noti.tooltip;
if(noti.onClick != noone && mouse_press(mb_left, pFOCUS))
noti.onClick();
if(mouse_press(mb_right, pFOCUS)) {
2024-08-10 07:30:41 +02:00
noti_selecting = noti;
2024-08-10 11:04:14 +02:00
var dia = menuCall("notification_menu", [
2024-08-10 07:30:41 +02:00
menuItem(__txtx("noti_copy_message", "Copy notification message"), function() { clipboard_set_text(noti_selecting.txt); }),
menuItem(__txtx("noti_delete_message", "Delete notification"), function() { ds_list_remove(STATUSES, noti_selecting); }),
]);
2024-04-13 07:32:04 +02:00
2023-03-12 02:28:21 +01:00
}
}
2024-04-13 07:32:04 +02:00
2023-03-12 02:28:21 +01:00
if(noti.life_max > 0) {
var _nwx = sp_noti.w - ui(12) - ui(40);
var _nw = _nwx * noti.life / noti.life_max;
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, ui(40), yy, _nw, _h, COLORS.dialog_notification_icon_bg, 1);
2023-03-12 02:28:21 +01:00
}
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, 0, yy, ui(48), _h, noti.color, 1);
2023-03-12 02:28:21 +01:00
if(noti.icon_end != noone)
draw_sprite_ui(noti.icon_end, 1, _w - ui(24), yy + _h / 2,,,, COLORS._main_icon);
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;
}
}
draw_sprite_ui(ic, 1, ui(24), yy + _h / 2);
var tx = ui(48) + timeW + ui(12);
2023-06-10 13:59:45 +02:00
draw_set_text(f_p3, fa_right, fa_center, COLORS._main_text_sub_inner);
2023-06-05 19:41:01 +02:00
draw_text_line(tx - ui(4), yy + _h / 2, noti.time, -1, txw);
2023-06-10 13:59:45 +02:00
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text_inner);
2023-06-05 19:41:01 +02:00
draw_text_line(tx + ui(4), yy + _h / 2, noti.txt, -1, txw);
2023-03-12 02:28:21 +01:00
if(noti.amount > 1) {
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text);
var bw = max( ui(32), string_width(noti.amount) + ui(10) );
var bh = ui(28);
var bx = _w - ui(0) - bw;
2024-04-11 05:51:13 +02:00
var by = yy + ui(0) + ui(1);
2023-03-12 02:28:21 +01:00
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, bx, by, bw, bh, COLORS._main_icon_dark, 0.75);
2023-03-12 02:28:21 +01:00
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_accent);
draw_text(bx + bw / 2, by + bh / 2, noti.amount);
}
}
2023-06-10 13:59:45 +02:00
yy += _h + ui(4);
hh += _h + ui(4);
2023-03-12 02:28:21 +01:00
}
return hh;
});
function drawContent(panel) {
2023-06-10 13:59:45 +02:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2023-03-12 02:28:21 +01:00
PANEL_PADDING
2023-03-28 06:58:28 +02:00
PANEL_TITLE
2023-03-12 02:28:21 +01:00
var ww = ui(28);
var hh = ui(28);
var bx = w - ui(in_dialog? padding - 8 : padding) - ww;
2023-03-28 06:58:28 +02:00
var by = title_height / 2 - ui(16 + !in_dialog * 2);
2023-03-12 02:28:21 +01:00
var error = !!(filter & NOTI_TYPE.error);
2023-06-04 18:28:29 +02:00
var toolt = error? __txtx("noti_hide_error", "Hide error") : __txtx("noti_show_error", "Show error");
2023-03-12 02:28:21 +01:00
var b = buttonInstant(THEME.button_hide, bx, by, ww, hh, [mx, my], pFOCUS, pHOVER, toolt, THEME.noti_icon_error, error, c_white, 0.75 + error * 0.25);
if(b == 2) filter = filter ^ NOTI_TYPE.error;
2024-08-10 11:04:14 +02:00
if(b == 3) menuCall("notification_error_menu", rightClickMenu);
2023-03-12 02:28:21 +01:00
bx -= ui(36);
var warn = !!(filter & NOTI_TYPE.warning);
2023-06-04 18:28:29 +02:00
var toolt = warn? __txtx("noti_hide_warning", "Hide warning") : __txtx("noti_show_warning", "Show warning");
2023-03-12 02:28:21 +01:00
var b = buttonInstant(THEME.button_hide, bx, by, ww, hh, [mx, my], pFOCUS, pHOVER, toolt, THEME.noti_icon_warning, warn, c_white, 0.75 + warn * 0.25);
if(b == 2) filter = filter ^ NOTI_TYPE.warning;
2024-08-10 11:04:14 +02:00
if(b == 3) menuCall("notification_warning_menu", rightClickMenu);
2023-03-12 02:28:21 +01:00
bx -= ui(36);
var log = !!(filter & NOTI_TYPE.log);
2023-06-04 18:28:29 +02:00
var toolt = log? __txtx("noti_hide_log", "Hide log") : __txtx("noti_show_log", "Show log");
2023-03-12 02:28:21 +01:00
var b = buttonInstant(THEME.button_hide, bx, by, ww, hh, [mx, my], pFOCUS, pHOVER, toolt, THEME.noti_icon_log, log, c_white, 0.75 + log * 0.25);
if(b == 2) filter = filter ^ NOTI_TYPE.log;
2024-08-10 11:04:14 +02:00
if(b == 3) menuCall("notification_log_menu", rightClickMenu);
2023-03-12 02:28:21 +01:00
var px = ui(padding);
var py = ui(title_height);
var pw = w - ui(padding + padding);
var ph = h - ui(title_height + padding);
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
2023-06-21 20:36:53 +02:00
sp_noti.setFocusHover(pHOVER, pHOVER);
2023-03-12 02:28:21 +01:00
sp_noti.draw(px, py, mx - px, my - py);
}
}