2022-01-13 05:24:03 +01:00
|
|
|
function buttonGroup(_data, _onClick) {
|
|
|
|
return new buttonGroupClass(_data, _onClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buttonGroupClass(_data, _onClick) constructor {
|
|
|
|
data = _data;
|
|
|
|
onClick = _onClick;
|
|
|
|
|
|
|
|
hover = false;
|
|
|
|
active = false;
|
|
|
|
|
|
|
|
for(var i = 0; i < array_length(data); i++) {
|
|
|
|
buttons[i] = button(-1);
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
sb_small = new scrollBox(data, _onClick);
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
static draw = function(_x, _y, _w, _h, _selecting, _m, _rx = 0, _ry = 0) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var amo = array_length(data);
|
|
|
|
var ww = _w / amo;
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
var total_width = 0;
|
|
|
|
draw_set_font(f_p0);
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < amo; i++) {
|
2022-12-10 05:06:01 +01:00
|
|
|
if(is_string(data[i]))
|
|
|
|
total_width += string_width(data[i]) + ui(32);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(total_width < _w) {
|
|
|
|
for(var i = 0; i < amo; i++) {
|
|
|
|
buttons[i].hover = hover;
|
|
|
|
buttons[i].active = active;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
var bx = _x + ww * i;
|
|
|
|
var spr = i == 0 ? THEME.button_left : (i == amo - 1? THEME.button_right : THEME.button_middle);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(_selecting == i) {
|
2022-12-10 05:06:01 +01:00
|
|
|
draw_sprite_stretched(spr, 2, bx, _y, ww, _h);
|
|
|
|
} else if(buttons[i].draw(bx, _y, ww, _h, _m, spr)) {
|
|
|
|
onClick(i);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(is_string(data[i])) {
|
|
|
|
draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
|
|
|
|
draw_text(bx + ww / 2, _y + _h / 2, data[i]);
|
|
|
|
} else if(sprite_exists(data[i])) {
|
|
|
|
draw_sprite_ui_uniform(data[i], i, bx + ww / 2, _y + _h / 2);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-12-10 05:06:01 +01:00
|
|
|
} else {
|
|
|
|
sb_small.hover = hover;
|
|
|
|
sb_small.active = active;
|
2022-12-12 09:08:03 +01:00
|
|
|
sb_small.draw(_x, _y, _w, _h, data[_selecting], _m, _rx, _ry);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-12-10 05:06:01 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
hover = false;
|
|
|
|
active = false;
|
|
|
|
}
|
|
|
|
}
|