Pixel-Composer/scripts/textArrayBox/textArrayBox.gml

86 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-21 04:48:50 +01:00
function textArrayBox(arraySet, data, onModify = noone) : widget() constructor {
2023-02-15 10:43:24 +01:00
self.getArray = arraySet;
self.arraySet = noone;
2024-03-31 11:10:14 +02:00
self.data = data;
2023-02-21 04:48:50 +01:00
self.onModify = onModify;
2023-02-14 02:48:33 +01:00
2023-02-15 10:43:24 +01:00
hide = false;
2023-02-14 02:48:33 +01:00
open = false;
static drawParam = function(params) {
2024-03-27 11:51:14 +01:00
setParam(params);
2024-03-26 04:03:45 +01:00
2023-09-28 13:15:29 +02:00
return draw(params.x, params.y, params.w, params.h, params.m, params.rx, params.ry);
}
2023-07-30 19:56:53 +02:00
static draw = function(_x, _y, _w, _h, _m, _rx = 0, _ry = 0) {
2023-02-14 02:48:33 +01:00
x = _x;
y = _y;
w = _w;
2023-02-15 10:43:24 +01:00
if(getArray != noone)
arraySet = getArray();
2023-02-14 02:48:33 +01:00
var tx = _x + ui(4);
var ty = _y + ui(4);
2024-03-26 04:03:45 +01:00
var hh = line_get_height(font, ui(4));
2023-02-14 02:48:33 +01:00
var th = hh + ui(8);
2024-03-26 04:03:45 +01:00
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arraySet); i < n; i++ ) {
2023-02-15 10:43:24 +01:00
var ww = string_width(arraySet[i]) + ui(16);
2023-02-14 02:48:33 +01:00
if(tx + ww + ui(2) > _x + _w - ui(8)) {
tx = _x + ui(4);
ty += hh + ui(2);
th += hh + ui(2);
}
tx += ww + ui(2);
}
h = th;
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, th, boxColor);
2023-02-14 02:48:33 +01:00
if(open) {
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, th, COLORS._main_accent, 1);
2023-02-14 02:48:33 +01:00
} else {
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + th)) {
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, th, boxColor, 0.5 + !hide * 0.5);
2023-02-14 02:48:33 +01:00
if(mouse_press(mb_left, active)) {
2023-02-15 10:43:24 +01:00
with(dialogCall(o_dialog_arrayBox, _rx + _x, _ry + _y + th)) {
2023-02-14 02:48:33 +01:00
arrayBox = other;
dialog_w = other.w;
}
}
2023-02-15 10:43:24 +01:00
} else if(!hide)
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, th, boxColor, 0.5 + 0.5 * interactable);
2023-02-14 02:48:33 +01:00
}
var tx = _x + ui(4);
var ty = _y + ui(4);
2024-03-26 04:03:45 +01:00
var hh = line_get_height(font, ui(4));
2023-02-14 02:48:33 +01:00
2024-03-26 04:03:45 +01:00
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arraySet); i < n; i++ ) {
2023-02-15 10:43:24 +01:00
var ww = string_width(arraySet[i]) + ui(16);
2023-02-14 02:48:33 +01:00
if(tx + ww + ui(2) > _x + _w - ui(8)) {
tx = _x + ui(4);
ty += hh + ui(2);
}
draw_sprite_stretched_ext(THEME.group_label, 0, tx, ty, ww, hh, COLORS._main_icon, 1);
2023-02-15 10:43:24 +01:00
draw_text(tx + ui(8), ty + hh / 2, arraySet[i]);
2023-02-14 02:48:33 +01:00
tx += ww + ui(2);
}
resetFocus();
return th;
}
2024-03-31 11:10:14 +02:00
static clone = function() {
2024-03-31 11:10:14 +02:00
var cln = new textArrayBox(getArray, data, onModify);
return cln;
}
2023-02-14 02:48:33 +01:00
}