2023-01-17 08:11:55 +01:00
|
|
|
function vectorRangeBox(_size, _type, _onModify, _unit = noone) : widget() constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
size = _size;
|
|
|
|
onModify = _onModify;
|
2022-12-27 04:00:50 +01:00
|
|
|
unit = _unit;
|
2023-10-02 08:57:44 +02:00
|
|
|
linked = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
disp_h = 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
|
|
|
|
|
|
|
onModifyIndex = function(index, val) {
|
2023-10-02 08:57:44 +02:00
|
|
|
if(linked) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var modi = false;
|
|
|
|
modi |= onModify(floor(index / 2) * 2 + 0, toNumber(val));
|
|
|
|
modi |= onModify(floor(index / 2) * 2 + 1, 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
|
|
|
|
|
|
|
axis = [ "x", "y", "z", "w"];
|
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)); }
|
|
|
|
onModifySingle[2] = function(val) { return onModifyIndex(2, toNumber(val)); }
|
|
|
|
onModifySingle[3] = function(val) { return onModifyIndex(3, toNumber(val)); }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
extras = -1;
|
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
for(var i = 0; i < size; i++) { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
tb[i] = new textBox(_type, onModifySingle[i]);
|
|
|
|
tb[i].slidable = true;
|
2024-03-24 06:44:34 +01:00
|
|
|
tb[i].hide = true;
|
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
static setSlideSpeed = function(speed) { #region
|
2023-02-14 05:32:32 +01:00
|
|
|
for(var i = 0; i < size; i++)
|
2023-11-15 14:42:53 +01:00
|
|
|
tb[i].setSlidable(speed);
|
2024-03-24 06:44:34 +01:00
|
|
|
} #endregion
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
static setInteract = function(interactable = noone) { #region
|
2023-01-25 06:49:00 +01:00
|
|
|
self.interactable = interactable;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _step = linked? 2 : 1;
|
2023-09-27 14:55:21 +02:00
|
|
|
for( var i = 0; i < size; i += _step )
|
2023-01-25 06:49:00 +01:00
|
|
|
tb[i].interactable = interactable;
|
2024-03-24 06:44:34 +01:00
|
|
|
} #endregion
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
static register = function(parent = noone) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _step = linked? 2 : 1;
|
2023-09-27 14:55:21 +02:00
|
|
|
for( var i = 0; i < size; i += _step )
|
2023-01-17 08:11:55 +01:00
|
|
|
tb[i].register(parent);
|
2024-03-24 06:44:34 +01:00
|
|
|
} #endregion
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
static drawParam = function(params) { #region
|
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-03-24 06:44:34 +01:00
|
|
|
} #endregion
|
2023-07-30 19:56:53 +02:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
static draw = function(_x, _y, _w, _h, _data, _display_data, _m) { #region
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(struct_has(_display_data, "linked")) linked = _display_data.linked;
|
2024-03-24 08:01:24 +01:00
|
|
|
var _hh = linked? _h : _h * 2 + ui(4);
|
|
|
|
h = h == 0? _hh : lerp_float(h, _hh, 5);
|
2023-10-02 08:57:44 +02:00
|
|
|
tooltip.index = linked;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
var _bs = min(_h, ui(32));
|
|
|
|
var bx = _x;
|
|
|
|
var by = _y + _h / 2 - _bs / 2;
|
|
|
|
|
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, _bs, _bs, _m, active, hover, tooltip, THEME.value_link, linked, _icon_blend) == 2) {
|
2023-10-02 08:57:44 +02:00
|
|
|
linked = !linked;
|
2024-03-24 06:44:34 +01:00
|
|
|
_display_data.linked = linked;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(linked) {
|
2023-09-27 14:55:21 +02:00
|
|
|
for(var i = 0; i < size; i += 2) {
|
|
|
|
onModify(i + 0, _data[i]);
|
|
|
|
onModify(i + 1, _data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
_x += _bs + ui(4);
|
|
|
|
_w -= _bs + ui(4);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
var ww = _w / 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
if(linked) {
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, c_white, 1);
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, c_white, 0.5 + 0.5 * interactable);
|
|
|
|
|
|
|
|
for( var i = 0; i < 2; i++ ) {
|
|
|
|
var bx = _x + ww * i;
|
|
|
|
var by = _y;
|
|
|
|
|
|
|
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
|
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_text_add(bx + ui(8), by + _h / 2, axis[i]);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
|
|
|
|
tb[i * 2].setFocusHover(active, hover);
|
|
|
|
tb[i * 2].draw(bx, by, ww, _h, _data[i * 2], _m);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for( var j = 0; j < 2; j++ ) {
|
|
|
|
var by = _y + (_h + ui(4)) * j;
|
|
|
|
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, _x, by, _w, _h, c_white, 1);
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 0, _x, by, _w, _h, c_white, 0.5 + 0.5 * interactable);
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-03-24 06:44:34 +01:00
|
|
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
|
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_text_add(_x + ui(8), by + _h / 2, axis[j]);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
|
|
|
|
for( var i = 0; i < 2; i++ ) {
|
|
|
|
var bx = _x + ww * i;
|
|
|
|
|
|
|
|
tb[j * 2 + i].setFocusHover(active, hover);
|
|
|
|
tb[j * 2 + i].draw(bx, by, ww, _h, _data[j * 2 + i], _m);
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
resetFocus();
|
2022-11-21 06:38:44 +01:00
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
return h;
|
2024-03-24 06:44:34 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|