Pixel-Composer/objects/o_dialog_menubox/Draw_64.gml

90 lines
2.8 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
#region draw
2022-11-03 11:44:49 +01:00
var yy = dialog_y;
2022-01-13 05:24:03 +01:00
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.textbox, 1, 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++) {
if(!is_array(menu[i])) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.menu_separator, 0, dialog_x + ui(8), yy, dialog_w - ui(16), ui(6));
2022-11-03 11:44:49 +01:00
yy += ui(8);
2022-01-13 05:24:03 +01:00
continue;
}
var _h = hght;
2022-11-22 14:25:39 +01:00
var label = menu[i][0];
var activated = string_char_at(label, 1) != "-";
if(!activated) label = string_copy(label, 2, string_length(label) - 1);
2022-01-13 05:24:03 +01:00
if(is_array(menu[i][1]))
_h += hght;
2022-11-22 14:25:39 +01:00
if(activated && sHOVER && point_in_rectangle(mouse_mx, mouse_my, dialog_x, yy + 1, dialog_x + dialog_w, yy + _h - 1)) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, dialog_x, yy, dialog_w, _h, COLORS.dialog_menubox_highlight, 1);
2022-01-13 05:24:03 +01:00
2022-12-10 05:06:01 +01:00
if(!is_array(menu[i][1]) && sFOCUS && mouse_release(mb_left)) {
2022-11-18 03:20:31 +01:00
var res = menu[i][1](dialog_x + dialog_w, yy, depth, menu[i][0]);
if(array_safe_get(menu[i], 2, 0) == ">")
ds_list_add(children, res);
else
instance_destroy(o_dialog_menubox);
2022-01-13 05:24:03 +01:00
}
}
if(is_array(menu[i][1])) {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub);
2022-11-22 14:25:39 +01:00
draw_set_alpha(activated * 0.5 + 0.5);
draw_text(dialog_x + dialog_w / 2, yy + hght / 2, label);
draw_set_alpha(1);
2022-01-13 05:24:03 +01:00
var amo = array_length(menu[i][1]);
2022-11-03 11:44:49 +01:00
var _w = (amo - 1) / 2 * (hght + 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++) {
2022-11-03 11:44:49 +01:00
var _bx = _sx + j * (hght + ui(4));
var _by = yy + hght + hght / 2 - ui(4);
2022-09-23 13:28:42 +02:00
var _spr = noone, _ind = 0;
var _ss = menu[i][1][j][0];
2022-01-13 05:24:03 +01:00
2022-09-23 13:28:42 +02:00
if(is_array(_ss)) {
_spr = _ss[0];
_ind = _ss[1];
} else {
_spr = _ss;
_ind = 0;
}
2022-01-13 05:24:03 +01:00
2022-11-03 11:44:49 +01:00
if(sHOVER && point_in_rectangle(mouse_mx, mouse_my, _bx - ui(14), _by - ui(14), _bx + ui(14), _by + ui(14))) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.textbox, 1, _bx - ui(14), _by - ui(14), ui(28), ui(28), 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)) {
2022-01-13 05:24:03 +01:00
menu[i][1][j][1]();
2022-11-01 03:06:03 +01:00
instance_destroy(o_dialog_menubox);
2022-01-13 05:24:03 +01:00
}
}
2022-11-03 11:44:49 +01:00
draw_sprite_ui_uniform(_spr, _ind, _bx, _by);
2022-01-13 05:24:03 +01:00
}
} else {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2022-11-22 14:25:39 +01:00
draw_set_alpha(activated * 0.5 + 0.5);
draw_text(dialog_x + ui(16), yy + hght / 2, label);
draw_set_alpha(1);
2022-01-13 05:24:03 +01:00
}
if(array_length(menu[i]) > 2) {
2022-11-01 03:06:03 +01:00
if(menu[i][2] == ">") {
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);
2022-11-01 03:06:03 +01:00
} else if(is_array(menu[i][2])) {
var _key = find_hotkey(menu[i][2][0], menu[i][2][1]);
if(_key) {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p1, fa_right, fa_center, COLORS._main_text_sub);
2022-11-03 11:44:49 +01:00
draw_text(dialog_x + dialog_w - ui(16), yy + hght / 2, key_get_name(_key.key, _key.modi));
2022-11-01 03:06:03 +01:00
}
2022-01-13 05:24:03 +01:00
}
}
yy += _h;
}
#endregion