Pixel-Composer/scripts/matrixGrid/matrixGrid.gml

122 lines
3.1 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
function matrixGrid(_type, _onModify, _unit = noone) : widget() constructor {
2023-01-04 02:30:04 +01:00
size = 9;
onModify = _onModify;
unit = _unit;
linked = false;
b_link = button(function() { linked = !linked; });
b_link.icon = THEME.value_link;
onModifyIndex = function(index, val) {
2023-02-14 05:32:32 +01:00
var modi = false;
2023-01-04 02:30:04 +01:00
if(linked) {
for( var i = 0; i < size; i++ )
2023-02-14 05:32:32 +01:00
modi |= onModify(i, toNumber(val));
return modi;
2023-01-04 02:30:04 +01:00
}
2023-02-14 05:32:32 +01:00
return onModify(index, toNumber(val));
2023-01-04 02:30:04 +01:00
}
2023-02-14 05:32:32 +01:00
onModifySingle[0] = function(val) { return onModifyIndex(0, val); }
onModifySingle[1] = function(val) { return onModifyIndex(1, val); }
onModifySingle[2] = function(val) { return onModifyIndex(2, val); }
2023-01-04 02:30:04 +01:00
2023-02-14 05:32:32 +01:00
onModifySingle[3] = function(val) { return onModifyIndex(3, val); }
onModifySingle[4] = function(val) { return onModifyIndex(4, val); }
onModifySingle[5] = function(val) { return onModifyIndex(5, val); }
2023-01-04 02:30:04 +01:00
2023-02-14 05:32:32 +01:00
onModifySingle[6] = function(val) { return onModifyIndex(6, val); }
onModifySingle[7] = function(val) { return onModifyIndex(7, val); }
onModifySingle[8] = function(val) { return onModifyIndex(8, val); }
2023-01-04 02:30:04 +01:00
extras = -1;
2023-01-25 06:49:00 +01:00
static setInteract = function(interactable = noone) {
self.interactable = interactable;
b_link.interactable = interactable;
for( var i = 0; i < size; i++ )
tb[i].interactable = interactable;
if(extras)
extras.interactable = interactable;
}
2023-01-17 08:11:55 +01:00
static register = function(parent = noone) {
b_link.register(parent);
for( var i = 0; i < size; i++ )
tb[i].register(parent);
if(extras)
extras.register(parent);
if(unit != noone && unit.reference != noone)
unit.triggerButton.register(parent);
}
2023-01-04 02:30:04 +01:00
for(var i = 0; i < size; i++) {
tb[i] = new textBox(_type, onModifySingle[i]);
tb[i].slidable = true;
}
2023-02-14 05:32:32 +01:00
static setSlideSpeed = function(speed) {
for(var i = 0; i < size; i++)
tb[i].slide_speed = speed;
}
2023-01-04 02:30:04 +01:00
static draw = function(_x, _y, _w, _h, _data, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-01-04 02:30:04 +01:00
if(extras && instanceof(extras) == "buttonClass") {
2023-03-25 12:27:04 +01:00
extras.setActiveFocus(hover, active);
2023-01-04 02:30:04 +01:00
extras.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide);
_w -= ui(40);
}
if(unit != noone && unit.reference != noone) {
_w += ui(4);
2023-03-25 12:27:04 +01:00
unit.triggerButton.setActiveFocus(ihover, iactive);
2023-01-04 02:30:04 +01:00
unit.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m);
_w -= ui(40);
}
2023-03-25 12:27:04 +01:00
b_link.setActiveFocus(hover, active);
2023-01-04 02:30:04 +01:00
b_link.icon_index = linked;
b_link.icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
b_link.tooltip = linked? "Unlink values" : "Link values";
var hh = TEXTBOX_HEIGHT + ui(8);
var th = hh * 3 - ui(8);
var bx = _x;
var by = _y + th / 2 - ui(32 / 2);
b_link.draw(bx + ui(4), by + ui(4), ui(24), ui(24), _m, THEME.button_hide);
_x += ui(28);
_w -= ui(28);
var ww = _w / 3;
for(var i = 0; i < 3; i++)
for(var j = 0; j < 3; j++) {
var ind = i * 3 + j;
2023-03-25 12:27:04 +01:00
tb[ind].setActiveFocus(hover, active);
2023-01-04 02:30:04 +01:00
var bx = _x + ww * j;
var by = _y + hh * i;
tb[ind].draw(bx + ui(8), by, ww - ui(8), TEXTBOX_HEIGHT, _data[ind], _m);
}
2023-01-17 08:11:55 +01:00
resetFocus();
2023-01-04 02:30:04 +01:00
return th;
}
}