Pixel-Composer/objects/o_dialog_scrollbox/Create_0.gml

83 lines
1.9 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
event_inherited();
#region
2022-12-16 09:18:09 +01:00
max_h = 640;
align = fa_center;
2022-01-13 05:24:03 +01:00
draggable = false;
destroy_on_click_out = true;
2023-01-25 06:49:00 +01:00
selecting = -1;
2022-01-13 05:24:03 +01:00
scrollbox = noone;
2023-02-17 11:31:33 +01:00
initVal = 0;
2023-02-19 13:49:20 +01:00
update_hover = true;
2022-01-13 05:24:03 +01:00
anchor = ANCHOR.top | ANCHOR.left;
2022-12-16 09:18:09 +01:00
sc_content = new scrollPane(0, 0, function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hght = line_height(f_p0, 8);
var data = scrollbox.data;
var _dw = sc_content.surface_w;
2023-02-17 11:31:33 +01:00
var _h = 0;
var _ly = _y;
var hovering = -1;
2022-12-16 09:18:09 +01:00
for(var i = 0; i < array_length(data); i++) {
2023-02-17 11:31:33 +01:00
if(data[i] == -1) {
draw_sprite_stretched(THEME.menu_separator, 0, ui(8), _ly, _dw - ui(16), ui(6));
_ly += ui(8);
_h += ui(8);
continue;
}
2022-12-16 09:18:09 +01:00
2022-12-19 13:35:30 +01:00
if(sHOVER && sc_content.hover && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
2023-01-25 06:49:00 +01:00
selecting = i;
2023-02-17 11:31:33 +01:00
hovering = i;
2023-01-25 06:49:00 +01:00
}
if(selecting == i) {
2022-12-16 09:18:09 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
2023-01-25 06:49:00 +01:00
if(sFOCUS && (mouse_press(mb_left) || keyboard_check_pressed(vk_enter))) {
2023-02-17 11:31:33 +01:00
initVal = i;
2022-12-16 09:18:09 +01:00
instance_destroy();
}
}
draw_set_text(f_p0, align, fa_center, COLORS._main_text);
if(align == fa_center)
draw_text_cut(_dw / 2, _ly + hght / 2, data[i], _dw);
else if(align == fa_left)
draw_text_cut(ui(8), _ly + hght / 2, data[i], _dw);
2023-02-17 11:31:33 +01:00
_ly += hght;
_h += hght;
2022-12-16 09:18:09 +01:00
}
2023-02-19 13:49:20 +01:00
if(update_hover) {
UNDO_HOLDING = true;
if(hovering > -1) scrollbox.onModify(hovering);
else scrollbox.onModify(initVal);
UNDO_HOLDING = false;
}
2023-02-17 11:31:33 +01:00
2023-01-25 06:49:00 +01:00
if(sFOCUS) {
if(keyboard_check_pressed(vk_up)) {
selecting--;
if(selecting < 0) selecting = array_length(data) - 1;
}
if(keyboard_check_pressed(vk_down))
2023-02-20 10:16:31 +01:00
selecting = safe_mod(selecting + 1, array_length(data));
2023-01-25 06:49:00 +01:00
if(keyboard_check_pressed(vk_escape))
instance_destroy();
}
2022-12-16 09:18:09 +01:00
return _h;
});
2022-01-13 05:24:03 +01:00
#endregion