2023-01-17 08:11:55 +01:00
|
|
|
function rangeBox(_type, _onModify) : widget() constructor {
|
2024-03-31 11:10:14 +02:00
|
|
|
type = _type;
|
2023-10-02 08:57:44 +02:00
|
|
|
onModify = _onModify;
|
|
|
|
linked = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
disp_w = 0;
|
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
tooltip = new tooltipSelector("Value Type", [
|
2023-09-28 15:10:41 +02:00
|
|
|
__txtx("widget_range_random", "Random Range"),
|
|
|
|
__txtx("widget_range_constant", "Constant"),
|
2023-09-27 14:55:21 +02:00
|
|
|
]);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-06-19 09:04:03 +02:00
|
|
|
onModifyIndex = function(val, index) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var modi = false;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(linked) {
|
2023-01-17 08:11:55 +01:00
|
|
|
for( var i = 0; i < 2; i++ )
|
2024-06-19 09:04:03 +02:00
|
|
|
modi |= onModify(toNumber(val), i);
|
2023-02-14 05:32:32 +01:00
|
|
|
return modi;
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
2024-06-19 09:04:03 +02:00
|
|
|
return onModify(toNumber(val), index);
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
labels = [ "min", "max" ];
|
2024-06-19 09:04:03 +02:00
|
|
|
onModifySingle[0] = function(val) { return onModifyIndex(toNumber(val), 0); }
|
|
|
|
onModifySingle[1] = function(val) { return onModifyIndex(toNumber(val), 1); }
|
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;
|
2024-03-24 08:01:24 +01:00
|
|
|
tb[i].hide = true;
|
2024-03-27 11:51:14 +01:00
|
|
|
tb[i].label = labels[i];
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static setInteract = function(interactable = noone) {
|
2023-01-25 06:49:00 +01:00
|
|
|
self.interactable = interactable;
|
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
tb[0].interactable = interactable;
|
2024-03-24 06:44:34 +01:00
|
|
|
if(!linked)
|
2023-09-27 14:55:21 +02:00
|
|
|
tb[1].interactable = interactable;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static register = function(parent = noone) {
|
2023-09-27 14:55:21 +02:00
|
|
|
tb[0].register(parent);
|
2023-10-02 08:57:44 +02:00
|
|
|
if(!linked)
|
2023-09-27 14:55:21 +02:00
|
|
|
tb[1].register(parent);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static isHovering = function() {
|
2024-03-28 14:18:02 +01:00
|
|
|
for( var i = 0, n = array_length(tb); i < n; i++ ) if(tb[i].isHovering()) return true;
|
|
|
|
return false;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2024-03-28 14:18:02 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static drawParam = function(params) {
|
2024-03-27 11:51:14 +01:00
|
|
|
setParam(params);
|
|
|
|
for(var i = 0; i < 2; i++) tb[i].setParam(params);
|
2024-03-26 04:03:45 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
return draw(params.x, params.y, params.w, params.h, params.data, params.display_data, params.m);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-07-30 19:56:53 +02:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static draw = function(_x, _y, _w, _h, _data, _display_data, _m) {
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
h = _h;
|
2023-10-02 08:57:44 +02:00
|
|
|
if(struct_has(_display_data, "linked")) linked = _display_data.linked;
|
|
|
|
tooltip.index = linked;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
|
2024-03-24 08:01:24 +01:00
|
|
|
var _bs = min(_h, ui(32));
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
if((_w - _bs) / 2 > ui(64)) {
|
|
|
|
if(side_button) {
|
|
|
|
side_button.setFocusHover(active, hover);
|
|
|
|
side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
|
|
|
|
_w -= _bs + ui(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
var bx = _x;
|
|
|
|
var by = _y + _h / 2 - _bs / 2;
|
2024-03-24 08:01:24 +01:00
|
|
|
|
2024-12-16 12:03:02 +01:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, _bs, _bs, _m, hover, active, tooltip, THEME.value_link, linked, _icon_blend) == 2) {
|
2024-03-29 05:20:49 +01:00
|
|
|
linked = !linked;
|
|
|
|
_display_data.linked = linked;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
if(linked) {
|
2024-06-19 09:04:03 +02:00
|
|
|
onModify(_data[0], 0);
|
|
|
|
onModify(_data[0], 1);
|
2024-03-29 05:20:49 +01:00
|
|
|
}
|
2023-09-27 14:55:21 +02:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
_x += _bs + ui(4);
|
|
|
|
_w -= _bs + ui(4);
|
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
var ww = linked? _w : _w / 2;
|
|
|
|
disp_w = disp_w == 0? ww : lerp_float(disp_w, ww, 5);
|
2024-03-24 06:44:34 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, boxColor, 1);
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, boxColor, 0.5 + 0.5 * interactable);
|
2024-03-24 08:01:24 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(linked) {
|
2023-09-27 14:55:21 +02:00
|
|
|
tb[0].setFocusHover(active, hover);
|
2024-03-24 08:01:24 +01:00
|
|
|
tb[0].draw(_x, _y, disp_w, _h, _data[0], _m);
|
2024-03-24 06:44:34 +01:00
|
|
|
|
|
|
|
} else if(is_array(_data) && array_length(_data) >= 2) {
|
|
|
|
for(var i = 0; i < 2; i++) {
|
|
|
|
tb[i].setFocusHover(active, hover);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
var bx = _x + disp_w * i;
|
|
|
|
tb[i].draw(bx, _y, disp_w, _h, _data[i], _m);
|
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;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2024-03-31 11:10:14 +02:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static clone = function() {
|
2024-03-31 11:10:14 +02:00
|
|
|
var cln = new rangeBox(type, onModify);
|
|
|
|
|
|
|
|
return cln;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2024-11-24 11:39:17 +01:00
|
|
|
|
|
|
|
static free = function() {
|
|
|
|
for( var i = 0, n = array_length(tb); i < n; i++ ) tb[i].free();
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|