2023-02-28 09:43:01 +01:00
|
|
|
function Node_Stack(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2022-12-27 04:00:50 +01:00
|
|
|
name = "Stack";
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Horizontal", "Vertical", "On top" ])
|
|
|
|
.rejectArray();
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Align", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_button, [ "Start", "Middle", "End"])
|
|
|
|
.rejectArray();
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Spacing", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.rejectArray();
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
setIsDynamicInput(1);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static createNewInput = function() { #region
|
2022-12-27 04:00:50 +01:00
|
|
|
var index = ds_list_size(inputs);
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index] = nodeValue("Input", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, -1 )
|
2022-12-27 04:00:50 +01:00
|
|
|
.setVisible(true, true);
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2022-12-27 04:00:50 +01:00
|
|
|
if(!LOADING && !APPENDING) createNewInput();
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
|
2023-04-16 15:26:52 +02:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static refreshDynamicInput = function() { #region
|
2022-12-27 04:00:50 +01:00
|
|
|
var _l = ds_list_create();
|
|
|
|
for( var i = 0; i < ds_list_size(inputs); i++ ) {
|
|
|
|
if(i < input_fix_len || inputs[| i].value_from)
|
|
|
|
ds_list_add(_l, inputs[| i]);
|
|
|
|
else
|
|
|
|
delete inputs[| i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(_l); i++ )
|
|
|
|
_l[| i].index = i;
|
|
|
|
|
|
|
|
ds_list_destroy(inputs);
|
|
|
|
inputs = _l;
|
|
|
|
|
|
|
|
createNewInput();
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static onValueFromUpdate = function(index) { #region
|
2023-01-09 03:14:20 +01:00
|
|
|
if(index < input_fix_len) return;
|
|
|
|
if(LOADING || APPENDING) return;
|
|
|
|
|
|
|
|
refreshDynamicInput();
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static step = function() { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _axis = getInputData(0);
|
2023-01-01 02:06:02 +01:00
|
|
|
|
|
|
|
inputs[| 1].setVisible(_axis != 2);
|
|
|
|
inputs[| 2].setVisible(_axis != 2);
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static update = function(frame = PROJECT.animator.current_frame) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _axis = getInputData(0);
|
|
|
|
var _alig = getInputData(1);
|
|
|
|
var _spac = getInputData(2);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
|
|
|
var ww = 0;
|
|
|
|
var hh = 0;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _surf = getInputData(i);
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(_surf)) _surf = [ _surf ];
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
for( var j = 0; j < array_length(_surf); j++ ) {
|
|
|
|
if(!is_surface(_surf[j])) continue;
|
2023-09-08 21:37:36 +02:00
|
|
|
var sw = surface_get_width_safe(_surf[j]);
|
|
|
|
var sh = surface_get_height_safe(_surf[j]);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
if(_axis == 0) {
|
|
|
|
ww += sw + (i > input_fix_len && j == array_length(_surf) - 1) * _spac;
|
|
|
|
hh = max(hh, sh);
|
|
|
|
} else if(_axis == 1) {
|
|
|
|
ww = max(ww, sw);
|
|
|
|
hh += sh + (i > input_fix_len && j == array_length(_surf) - 1) * _spac;
|
|
|
|
} else if(_axis == 2) {
|
|
|
|
ww = max(ww, sw);
|
|
|
|
hh = max(hh, sh);
|
|
|
|
}
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var _outSurf = outputs[| 0].getValue();
|
2023-03-19 09:17:39 +01:00
|
|
|
_outSurf = surface_verify(_outSurf, ww, hh, attrDepth());
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0].setValue(_outSurf);
|
|
|
|
|
2023-04-16 15:26:52 +02:00
|
|
|
var atlas = [];
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
surface_set_target(_outSurf);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-19 13:49:20 +01:00
|
|
|
BLEND_ALPHA;
|
2022-12-27 04:00:50 +01:00
|
|
|
|
|
|
|
var sx = 0, sy = 0;
|
2023-02-14 05:32:32 +01:00
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _surf = getInputData(i);
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(_surf)) _surf = [ _surf ];
|
|
|
|
|
|
|
|
for( var j = 0; j < array_length(_surf); j++ ) {
|
|
|
|
if(!is_surface(_surf[j])) continue;
|
2023-09-08 21:37:36 +02:00
|
|
|
var sw = surface_get_width_safe(_surf[j]);
|
|
|
|
var sh = surface_get_height_safe(_surf[j]);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
if(_axis == 0) {
|
|
|
|
switch(_alig) {
|
|
|
|
case fa_left: sy = 0; break;
|
|
|
|
case fa_center: sy = hh / 2 - sh / 2; break;
|
|
|
|
case fa_right: sy = hh - sh; break;
|
|
|
|
}
|
|
|
|
} else if(_axis == 1) {
|
|
|
|
switch(_alig) {
|
|
|
|
case fa_left: sx = 0; break;
|
|
|
|
case fa_center: sx = ww / 2 - sw / 2; break;
|
|
|
|
case fa_right: sx = ww - sw; break;
|
|
|
|
}
|
|
|
|
} else if(_axis == 2) {
|
|
|
|
sx = ww / 2 - sw / 2;
|
|
|
|
sy = hh / 2 - sh / 2;
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
2023-04-16 15:26:52 +02:00
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
array_push(atlas, new SurfaceAtlas(_surf[j], sx, sy));
|
2023-02-14 05:32:32 +01:00
|
|
|
draw_surface_safe(_surf[j], sx, sy);
|
2023-04-16 15:26:52 +02:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(_axis == 0)
|
|
|
|
sx += sw + _spac;
|
|
|
|
else if(_axis == 1)
|
|
|
|
sy += sh + _spac;
|
|
|
|
}
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-12-27 04:00:50 +01:00
|
|
|
surface_reset_target();
|
2023-04-16 15:26:52 +02:00
|
|
|
|
|
|
|
outputs[| 1].setValue(atlas);
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
|
|
|
|