Pixel-Composer/scripts/rangeBox/rangeBox.gml

102 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-01-17 08:11:55 +01:00
function rangeBox(_type, _onModify) : widget() constructor {
onModify = _onModify;
extra_data = { linked : false };
2022-01-13 05:24:03 +01:00
tooltip = new tooltipSelector("Value Type", [
__txt("Random Range"),
__txt("Constant"),
]);
2023-01-17 08:11:55 +01:00
onModifyIndex = function(index, val) {
2023-02-14 05:32:32 +01:00
var modi = false;
if(extra_data.linked) {
2023-01-17 08:11:55 +01:00
for( var i = 0; i < 2; i++ )
2023-02-14 05:32:32 +01:00
modi |= onModify(i, toNumber(val));
return modi;
2023-01-17 08:11:55 +01:00
}
2023-02-14 05:32:32 +01:00
return onModify(index, toNumber(val));
2023-01-17 08:11:55 +01:00
}
2022-01-13 05:24:03 +01:00
label = [ "min", "max" ];
2023-02-14 05:32:32 +01:00
onModifySingle[0] = function(val) { return onModifyIndex(0, toNumber(val)); }
onModifySingle[1] = function(val) { return onModifyIndex(1, toNumber(val)); }
2022-01-13 05:24:03 +01:00
extras = -1;
for(var i = 0; i < 2; i++) {
tb[i] = new textBox(_type, onModifySingle[i]);
tb[i].slidable = true;
}
2023-02-14 05:32:32 +01:00
static setSlideSpeed = function(speed) {
tb[0].slide_speed = speed;
tb[1].slide_speed = speed;
2023-02-14 05:32:32 +01:00
}
2023-01-25 06:49:00 +01:00
static setInteract = function(interactable = noone) {
self.interactable = interactable;
tb[0].interactable = interactable;
if(!extra_data.linked)
tb[1].interactable = interactable;
2023-01-25 06:49:00 +01:00
}
2023-01-17 08:11:55 +01:00
static register = function(parent = noone) {
tb[0].register(parent);
if(!extra_data.linked)
tb[1].register(parent);
2023-01-17 08:11:55 +01:00
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
return draw(params.x, params.y, params.w, params.h, params.data, params.extra_data, params.m);
2023-07-30 19:56:53 +02:00
}
static draw = function(_x, _y, _w, _h, _data, _extra_data, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
if(struct_has(_extra_data, "linked")) extra_data.linked = _extra_data.linked;
tooltip.index = extra_data.linked;
2023-01-17 08:11:55 +01:00
var _icon_blend = extra_data.linked? COLORS._main_accent : COLORS._main_icon;
2023-01-17 08:11:55 +01:00
var bx = _x;
var by = _y + _h / 2 - ui(32 / 2);
if(buttonInstant(THEME.button_hide, bx + ui(4), by + ui(4), ui(24), ui(24), _m, active, hover, tooltip, THEME.value_link, extra_data.linked, _icon_blend) == 2) {
extra_data.linked = !extra_data.linked;
_extra_data.linked = extra_data.linked;
if(extra_data.linked) {
onModify(0, _data[0]);
onModify(1, _data[0]);
}
}
2023-01-17 08:11:55 +01:00
_x += ui(28);
_w -= ui(28);
if(extra_data.linked) {
tb[0].setFocusHover(active, hover);
tb[0].draw(_x + ui(8), _y, _w - ui(8), _h, _data[0], _m);
} else {
if(is_array(_data) && array_length(_data) >= 2) {
var ww = _w / 2;
for(var i = 0; i < 2; i++) {
tb[i].setFocusHover(active, hover);
2023-02-14 05:32:32 +01:00
var bx = _x + ww * i;
tb[i].draw(bx + ui(44), _y, ww - ui(44), _h, _data[i], _m);
2023-02-14 05:32:32 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
draw_text(bx + ui(8), _y + _h / 2, label[i]);
}
2022-01-13 05:24:03 +01:00
}
}
2023-01-17 08:11:55 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2022-01-13 05:24:03 +01:00
}
}