Pixel-Composer/objects/o_dialog_menubox/Create_0.gml

83 lines
1.8 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
event_inherited();
#region data
draggable = false;
2022-11-01 03:06:03 +01:00
destroy_on_click_out = false;
2023-01-25 06:49:00 +01:00
selecting = -1;
2022-01-13 05:24:03 +01:00
alarm[0] = -1;
menu = 1;
2022-11-03 11:44:49 +01:00
hght = ui(36);
2022-11-01 03:06:03 +01:00
children = ds_list_create();
ds_list_add(children, self);
2022-01-13 05:24:03 +01:00
2023-03-05 07:16:44 +01:00
tooltips = [];
2023-02-19 02:13:19 +01:00
show_icon = false;
2023-02-23 07:02:19 +01:00
function setMenu(_menu, align = fa_left) {
2022-01-13 05:24:03 +01:00
menu = _menu;
dialog_x = x;
dialog_y = y;
2023-02-19 02:13:19 +01:00
show_icon = false;
2022-01-13 05:24:03 +01:00
dialog_w = 0;
dialog_h = 0;
2022-11-01 03:06:03 +01:00
while(ds_list_size(children) > 1) {
var ch = children[| 1];
instance_destroy(children[| 1]);
ds_list_delete(children, 1);
}
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
2022-01-13 05:24:03 +01:00
for(var i = 0; i < array_length(menu); i++) {
2023-02-19 02:13:19 +01:00
var _menuItem = menu[i];
if(_menuItem == -1) {
2022-11-03 11:44:49 +01:00
dialog_h += ui(8);
2022-01-13 05:24:03 +01:00
continue;
}
2023-02-19 02:13:19 +01:00
2022-01-13 05:24:03 +01:00
draw_set_font(f_p0);
2023-02-19 02:13:19 +01:00
var ww = string_width(_menuItem.name) + ui(64);
if(instanceof(_menuItem) == "MenuItemGroup") {
var amo = array_length(_menuItem.group);
ww = max(ww, ui(16) + amo * (hght + ui(4)));
dialog_h += hght;
}
2023-01-25 06:49:00 +01:00
2023-02-19 02:13:19 +01:00
if(instanceof(_menuItem) == "MenuItem") {
if(_menuItem.hotkey != noone) {
var _key = find_hotkey(_menuItem.hotkey[0], _menuItem.hotkey[1]);
2022-11-01 03:06:03 +01:00
if(_key) {
draw_set_font(f_p1);
var ss = key_get_name(_key.key, _key.modi);
2022-11-03 11:44:49 +01:00
ww += string_width(ss) + ui(16);
2022-11-01 03:06:03 +01:00
}
2023-02-19 02:13:19 +01:00
}
if(_menuItem.spr != noone)
show_icon = true;
2023-03-12 02:28:21 +01:00
if(_menuItem.toggle != noone)
show_icon = true;
2022-01-13 05:24:03 +01:00
}
2023-02-19 02:13:19 +01:00
dialog_w = max(dialog_w, ww);
2022-01-13 05:24:03 +01:00
dialog_h += hght;
}
2023-02-19 02:13:19 +01:00
if(show_icon)
dialog_w += ui(32);
2023-02-23 07:02:19 +01:00
dialog_y = min(dialog_y, WIN_H - dialog_h);
switch(align) {
case fa_left: dialog_x = round(min(dialog_x, WIN_W - dialog_w)); break;
case fa_center: dialog_x = round(min(dialog_x - dialog_w / 2, WIN_W - dialog_w)); break;
2023-02-28 09:43:01 +01:00
case fa_right: dialog_x = round(max(dialog_x - dialog_w, 0)); break;
2023-02-23 07:02:19 +01:00
}
2022-01-13 05:24:03 +01:00
ready = true;
}
#endregion