Pixel-Composer/objects/o_dialog_menubox/Draw_64.gml

271 lines
8.4 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
2023-03-28 06:58:28 +02:00
if(!ready) exit;
2022-01-13 05:24:03 +01:00
#region draw
2022-11-03 11:44:49 +01:00
var yy = dialog_y;
2024-08-09 13:30:09 +02:00
var _lclick = sFOCUS && (!mouse_init_inside && mouse_release(mb_left)) || (keyboard_check_pressed(vk_enter) && hk_editing == noone);
2024-08-10 15:32:50 +02:00
var _rclick = sFOCUS && !mouse_init_inside && !mouse_init_r_pressed && mouse_release(mb_right);
2024-08-10 07:30:41 +02:00
if(!mouse_init_inside && mouse_press(mb_right) && item_selecting) {
instance_destroy(item_selecting);
item_selecting = noone;
}
2022-01-13 05:24:03 +01:00
draw_sprite_stretched(THEME.s_box_r2_clr, 0, dialog_x, dialog_y, dialog_w, dialog_h);
2022-01-13 05:24:03 +01:00
for(var i = 0; i < array_length(menu); i++) {
2023-01-25 06:49:00 +01:00
var _menuItem = menu[i];
2024-08-09 13:30:09 +02:00
if(is_string(_menuItem)) {
draw_set_text(f_p3, fa_left, fa_top, COLORS._main_text_sub);
draw_text(dialog_x + ui(8), yy + ui(4), _menuItem);
yy += string_height(_menuItem) + ui(8);
continue;
}
2023-11-01 08:10:25 +01:00
if(is_instanceof(_menuItem, MenuItem) && _menuItem.shiftMenu != noone && key_mod_press(SHIFT))
_menuItem = _menuItem.shiftMenu;
2024-08-09 13:30:09 +02:00
if(_menuItem == -1) {
2024-08-10 07:30:41 +02:00
var bx = dialog_x + ui(16);
var bw = dialog_w - ui(32);
draw_set_color(CDEF.main_mdblack);
draw_line_width(bx, yy + ui(3), bx + bw, yy + ui(3), 2);
2022-11-03 11:44:49 +01:00
yy += ui(8);
2022-01-13 05:24:03 +01:00
continue;
2024-08-09 13:30:09 +02:00
}
2023-02-19 02:13:19 +01:00
var label = _menuItem.name;
2024-04-08 07:13:46 +02:00
var _h = is_instanceof(_menuItem, MenuItemGroup)? hght * 2 : hght;
var cc = struct_try_get(_menuItem, "color", c_white);
2024-08-09 13:30:09 +02:00
var _key = _menuItem.hotkey != noone? find_hotkey(_menuItem.hotkey[0], _menuItem.hotkey[1]) : noone;
_menuItem.hoykeyObject = _key;
2023-11-20 05:10:55 +01:00
if(sHOVER && point_in_rectangle(mouse_mx, mouse_my, dialog_x, yy + 1, dialog_x + dialog_w, yy + _h - 1)) {
2023-01-25 06:49:00 +01:00
selecting = i;
2024-04-08 07:13:46 +02:00
var tips = array_safe_get_fast(tooltips, i, noone);
2023-03-05 07:16:44 +01:00
if(tips != noone) TOOLTIP = tips;
}
2023-05-03 21:42:17 +02:00
2023-01-25 06:49:00 +01:00
if(selecting == i) {
2024-04-08 07:13:46 +02:00
var _hc = cc == c_white? COLORS.dialog_menubox_highlight : cc;
var _ha = cc == c_white? 0.75 : 0.8;
draw_sprite_stretched_ext(THEME.textbox, 3, dialog_x, yy, dialog_w, _h, _hc, _ha);
2024-08-10 15:32:50 +02:00
if(_hovering_ch && is_instanceof(_menuItem, MenuItem)) {
2024-08-10 07:30:41 +02:00
if(_menuItem.active && _lclick) {
2024-08-09 13:30:09 +02:00
2024-08-18 13:13:40 +02:00
var _par = _menuItem.params;
var _dat = {
_x: dialog_x,
x: dialog_x + dialog_w,
y: yy,
name: _menuItem.name,
index: i,
depth: depth,
context: context,
params: _menuItem.params,
};
2024-08-16 13:55:58 +02:00
if(_menuItem.isShelf) {
var _res = _menuItem.func(_dat);
array_push(children, _res.id); // open child
} else if(remove_parents) {
2024-08-18 13:13:40 +02:00
if(_par == noone) _menuItem.func();
else _menuItem.func(_par);
2024-08-16 13:55:58 +02:00
instance_destroy(o_dialog_menubox); // close all
} else {
2024-08-18 13:13:40 +02:00
if(_par == noone) _menuItem.func();
else _menuItem.func(_par);
2024-08-16 13:55:58 +02:00
instance_destroy(); // close self
}
2024-08-09 13:30:09 +02:00
}
2024-08-10 15:32:50 +02:00
}
if(_hovering_ch && (is_instanceof(_menuItem, MenuItem) || is_instanceof(_menuItem, MenuItemGroup))) {
2024-08-09 13:30:09 +02:00
if(_key && _rclick) {
var _dat = {
2024-08-10 07:30:41 +02:00
_x: mouse_mx + ui(4),
2024-08-09 13:30:09 +02:00
x: mouse_mx + ui(4),
y: mouse_my + ui(4),
depth: depth,
name: _menuItem.name,
index: i,
context: context,
params: _menuItem.params,
};
selecting_menu = _menuItem;
2024-08-10 15:32:50 +02:00
2024-08-13 13:17:45 +02:00
with(o_dialog_menubox) { if(!remove_parents) instance_destroy(); }
2024-08-09 13:30:09 +02:00
var context_menu_settings = [
2024-08-13 13:17:45 +02:00
_key.full_name(),
menuItem(__txt("Edit hotkey"), function() /*=>*/ { hk_editing = selecting_menu; keyboard_lastchar = hk_editing.hoykeyObject.key; }),
2024-08-09 13:30:09 +02:00
];
2024-08-10 07:30:41 +02:00
item_selecting = submenuCall(_dat, context_menu_settings);
item_selecting.remove_parents = false;
array_push(children, item_selecting.id);
2024-08-09 13:30:09 +02:00
}
2022-01-13 05:24:03 +01:00
}
2024-08-10 15:32:50 +02:00
2023-05-03 21:42:17 +02:00
} else if(cc != c_white)
draw_sprite_stretched_ext(THEME.textbox, 3, dialog_x, yy, dialog_w, _h, cc, 0.5);
2022-01-13 05:24:03 +01:00
2024-08-10 15:32:50 +02:00
var _hx = dialog_x + dialog_w - ui(16);
var _hy = yy + hght / 2 + ui(2);
2023-11-01 08:10:25 +01:00
if(is_instanceof(_menuItem, MenuItemGroup)) {
2023-02-19 02:13:19 +01:00
var _submenus = _menuItem.group;
2024-08-10 07:30:41 +02:00
draw_set_text(font, fa_center, fa_center, COLORS._main_text_sub);
2023-03-02 07:59:14 +01:00
draw_set_alpha(_menuItem.active * 0.75 + 0.25);
2022-11-22 14:25:39 +01:00
draw_text(dialog_x + dialog_w / 2, yy + hght / 2, label);
draw_set_alpha(1);
2022-01-13 05:24:03 +01:00
2023-01-25 06:49:00 +01:00
var amo = array_length(_submenus);
2023-10-14 08:00:35 +02:00
var _w = (amo - 1) / 2 * (_menuItem.spacing + ui(4));
2022-01-13 05:24:03 +01:00
var _sx = dialog_x + dialog_w / 2 - _w;
for(var j = 0; j < amo; j++) {
2023-01-25 06:49:00 +01:00
var _submenu = _submenus[j];
2023-10-14 08:00:35 +02:00
var _bx = _sx + j * (_menuItem.spacing + ui(4));
var _by = yy + hght + hght / 2 - ui(4);
var _spr = noone, _ind = 0;
var _sprs = _submenu[0];
2024-03-31 05:36:11 +02:00
var _tlp = array_safe_get_fast(_submenu, 2, "");
var _dat = array_safe_get_fast(_submenu, 3, {});
2023-10-14 08:00:35 +02:00
var _clr = c_white;
var _str = "";
2022-01-13 05:24:03 +01:00
2023-10-14 08:00:35 +02:00
var _sw = _menuItem.spacing;
var _sh = _menuItem.spacing;
2023-10-07 09:09:18 +02:00
if(is_string(_sprs)) {
_str = _sprs;
draw_set_text(f_p2, fa_center, fa_center, COLORS._main_text);
_sw = string_width(_str) + ui(12);
_sh = string_height(_str) + ui(8);
2024-08-09 13:30:09 +02:00
2022-09-23 13:28:42 +02:00
} else {
2023-10-07 09:09:18 +02:00
if(is_array(_sprs)) {
_spr = _sprs[0];
_ind = _sprs[1];
2024-03-31 05:36:11 +02:00
_clr = array_safe_get_fast(_sprs, 2, c_white);
2023-10-07 09:09:18 +02:00
} else _spr = _sprs;
2023-10-14 08:00:35 +02:00
_sw = sprite_get_width(_spr) + ui(8);
_sh = sprite_get_height(_spr) + ui(8);
2022-09-23 13:28:42 +02:00
}
2022-01-13 05:24:03 +01:00
2024-04-08 07:13:46 +02:00
if(_hovering_ch && point_in_rectangle(mouse_mx, mouse_my, _bx - _sw / 2, _by - _sh / 2, _bx + _sw / 2, _by + _sh / 2)) {
2023-01-25 06:49:00 +01:00
if(_tlp != "") TOOLTIP = _tlp;
2023-10-07 09:09:18 +02:00
draw_sprite_stretched_ext(THEME.textbox, 3, _bx - _sw / 2, _by - _sh / 2, _sw, _sh, COLORS.dialog_menubox_highlight, 1);
draw_sprite_stretched_ext(THEME.textbox, 1, _bx - _sw / 2, _by - _sh / 2, _sw, _sh, COLORS.dialog_menubox_highlight, 1);
2022-01-13 05:24:03 +01:00
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, sFOCUS)) {
2023-10-14 08:00:35 +02:00
_submenu[1](_dat);
2022-11-01 03:06:03 +01:00
instance_destroy(o_dialog_menubox);
2022-01-13 05:24:03 +01:00
}
}
2023-10-07 09:09:18 +02:00
if(_spr != noone)
2023-10-14 08:00:35 +02:00
draw_sprite_ui_uniform(_spr, _ind, _bx, _by,, _clr);
2023-10-07 09:09:18 +02:00
if(_str != "")
draw_text(_bx, _by, _str);
2022-01-13 05:24:03 +01:00
}
2024-08-09 13:30:09 +02:00
2022-01-13 05:24:03 +01:00
} else {
2023-02-19 02:13:19 +01:00
if(_menuItem.spr != noone) {
var spr = is_array(_menuItem.spr)? _menuItem.spr[0] : _menuItem.spr;
var ind = is_array(_menuItem.spr)? _menuItem.spr[1] : 0;
2024-08-10 07:30:41 +02:00
draw_sprite_ui(spr, ind, dialog_x + ui(24), yy + hght / 2, .8, .8, 0, COLORS._main_icon, _menuItem.active * 0.5 + 0.25);
2023-02-19 02:13:19 +01:00
}
2023-03-12 02:28:21 +01:00
if(_menuItem.toggle != noone) {
2023-03-13 10:45:56 +01:00
var tog = _menuItem.toggle(_menuItem);
2023-03-12 02:28:21 +01:00
if(tog) draw_sprite_ui(THEME.icon_toggle, 0, dialog_x + ui(24), yy + hght / 2,,,, COLORS._main_icon);
}
2023-12-20 14:02:49 +01:00
var tx = dialog_x + show_icon * ui(32) + ui(16);
2024-08-10 07:30:41 +02:00
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
2023-03-02 07:59:14 +01:00
draw_set_alpha(_menuItem.active * 0.75 + 0.25);
2023-02-19 02:13:19 +01:00
draw_text(tx, yy + hght / 2, label);
2022-11-22 14:25:39 +01:00
draw_set_alpha(1);
2023-02-19 02:13:19 +01:00
if(_menuItem.isShelf) {
2022-11-18 03:20:31 +01:00
draw_sprite_ui_uniform(THEME.arrow, 0, dialog_x + dialog_w - ui(20), yy + hght / 2, 1, COLORS._main_icon);
2024-08-10 07:30:41 +02:00
_hx -= ui(24);
}
2024-08-10 15:32:50 +02:00
}
if(_key) {
draw_set_font(font);
2024-08-10 07:30:41 +02:00
2024-08-10 15:32:50 +02:00
var _ktxt = key_get_name(_key.key, _key.modi);
var _tw = string_width(_ktxt);
var _th = line_get_height();
var _bx = _hx - _tw - ui(4);
var _by = _hy - _th / 2 - ui(3);
var _bw = _tw + ui(8);
var _bh = _th + ui(3);
if(hk_editing == _menuItem) {
draw_set_text(font, fa_right, fa_center, COLORS._main_accent);
draw_sprite_stretched_ext(THEME.ui_panel, 1, _bx, _by, _bw, _bh, COLORS._main_text_accent);
2024-08-09 13:30:09 +02:00
2024-08-10 15:32:50 +02:00
} else if(_ktxt != "") {
draw_set_text(font, fa_right, fa_center, COLORS._main_text_sub);
draw_sprite_stretched_ext(THEME.ui_panel, 1, _bx, _by, _bw, _bh, CDEF.main_dkgrey);
2022-01-13 05:24:03 +01:00
}
2024-08-10 15:32:50 +02:00
draw_text(_hx, _hy, _ktxt);
2022-01-13 05:24:03 +01:00
}
yy += _h;
}
2023-01-04 02:30:04 +01:00
2024-08-09 13:30:09 +02:00
if(hk_editing != noone) {
if(keyboard_check_pressed(vk_enter))
hk_editing = noone;
else
hotkey_editing(hk_editing.hoykeyObject);
2024-08-10 07:30:41 +02:00
if(keyboard_check_pressed(vk_escape))
hk_editing = noone;
2024-08-09 13:30:09 +02:00
} else if(sFOCUS) {
2023-01-25 06:49:00 +01:00
if(keyboard_check_pressed(vk_up)) {
selecting--;
if(selecting < 0) selecting = array_length(menu) - 1;
}
if(keyboard_check_pressed(vk_down))
2023-02-20 10:16:31 +01:00
selecting = safe_mod(selecting + 1, array_length(menu));
2024-08-09 13:30:09 +02:00
2023-01-25 06:49:00 +01:00
if(keyboard_check_pressed(vk_escape))
instance_destroy();
}
draw_sprite_stretched(THEME.s_box_r2_clr, 1, dialog_x, dialog_y, dialog_w, dialog_h);
2024-03-23 07:26:11 +01:00
2024-08-09 13:30:09 +02:00
if(mouse_init_inside && (mouse_release(mb_left) || mouse_release(mb_right))) mouse_init_inside = false;
2024-08-10 15:32:50 +02:00
if(mouse_release(mb_right)) mouse_init_r_pressed = false;
2023-05-08 19:14:30 +02:00
#endregion
#region debug
2023-05-22 20:31:55 +02:00
if(global.FLAG[$ "context_menu_id"]) {
2023-05-08 19:14:30 +02:00
draw_set_color(c_white);
draw_rectangle_border(dialog_x, dialog_y, dialog_x + dialog_w, dialog_y + dialog_h, 2);
draw_set_text(f_p0, fa_left, fa_bottom);
draw_text(dialog_x, dialog_y - ui(2), menu_id);
}
2022-01-13 05:24:03 +01:00
#endregion