Pixel-Composer/objects/o_dialog_arrayBox/Create_0.gml

77 lines
2 KiB
Text
Raw Normal View History

2023-02-14 02:48:33 +01:00
/// @description init
event_inherited();
#region
destroy_on_click_out = true;
2024-10-03 12:20:00 +02:00
max_h = 640;
align = fa_left;
draggable = false;
2023-02-14 02:48:33 +01:00
selecting = -1;
2024-10-03 12:20:00 +02:00
font = f_p1;
2023-02-14 02:48:33 +01:00
arrayBox = noone;
anchor = ANCHOR.top | ANCHOR.left;
sc_content = new scrollPane(0, 0, function(_y, _m) {
2024-10-03 12:20:00 +02:00
draw_clear(COLORS.panel_bg_clear);
var hght = line_get_height(font, 8);
var _h = array_length(arrayBox.data) * hght;
var _dw = sc_content.surface_w;
2023-02-15 10:43:24 +01:00
var array = arrayBox.arraySet;
2023-02-14 02:48:33 +01:00
for(var i = 0; i < array_length(arrayBox.data); i++) {
var _ly = _y + i * hght;
var yc = _ly + hght / 2;
var exists = false;
for( var j = 0; j < array_length(array); j++ ) {
if(arrayBox.data[i] == array[j])
exists = true;
}
2023-04-08 20:06:27 +02:00
var ind = 0;
2023-02-14 02:48:33 +01:00
2024-07-28 13:55:57 +02:00
if(sHOVER && sc_content.hover && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
2023-02-14 02:48:33 +01:00
selecting = i;
2024-07-28 13:55:57 +02:00
sc_content.hover_content = true;
}
2023-02-14 02:48:33 +01:00
if(selecting == i) {
draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
2023-04-08 20:06:27 +02:00
ind = 1;
2023-02-14 02:48:33 +01:00
if(sFOCUS && (mouse_press(mb_left) || keyboard_check_pressed(vk_enter))) {
if(exists) array_remove(array, arrayBox.data[i]);
else array_push(array, arrayBox.data[i]);
2023-02-21 04:48:50 +01:00
if(arrayBox.onModify) arrayBox.onModify();
2023-02-14 02:48:33 +01:00
}
}
2024-10-03 12:20:00 +02:00
var bs = hght - ui(8);
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.checkbox_def, ind, ui(20) - bs / 2, yc - bs / 2, bs, bs);
2024-10-03 12:20:00 +02:00
if(exists) draw_sprite_stretched_ext(THEME.checkbox_def, 2, ui(20) - bs / 2, yc - bs / 2, bs, bs, COLORS._main_accent, 1);
2023-02-14 02:48:33 +01:00
2024-10-03 12:20:00 +02:00
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
draw_text(ui(40), yc, arrayBox.data[i]);
2023-02-14 02:48:33 +01:00
}
if(sFOCUS) {
if(keyboard_check_pressed(vk_up)) {
selecting--;
if(selecting < 0) selecting = array_length(arrayBox.data) - 1;
}
if(keyboard_check_pressed(vk_down))
2023-02-20 10:16:31 +01:00
selecting = safe_mod(selecting + 1, array_length(arrayBox.data));
2023-02-14 02:48:33 +01:00
if(keyboard_check_pressed(vk_escape))
instance_destroy();
}
return _h;
});
#endregion