Pixel-Composer/scripts/node_sequence_anim/node_sequence_anim.gml

130 lines
3.7 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Sequence_Anim(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Array to Anim";
2022-01-13 05:24:03 +01:00
update_on_frame = true;
2023-10-04 09:49:31 +02:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, [])
2023-06-13 14:42:06 +02:00
.setArrayDepth(1);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Speed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.rejectArray();
2023-06-10 13:59:45 +02:00
inputs[| 2] = nodeValue("Sequence", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [])
2023-06-13 14:42:06 +02:00
.setVisible(true, true)
2023-06-10 13:59:45 +02:00
.setArrayDepth(1);
inputs[| 3] = nodeValue("Overflow", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-06-13 14:42:06 +02:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Hold", "Loop", "Ping Pong", "Empty" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-06-10 13:59:45 +02:00
sequence_surface = noone;
sequence_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
var _seq = getInputData(0);
var _ord = getInputData(2);
2023-06-10 13:59:45 +02:00
var _h = ui(64);
2023-10-04 09:49:31 +02:00
if(!is_array(_seq)) return _h;
2023-06-13 14:42:06 +02:00
if(array_length(_ord) == 0) {
_ord = array_create(array_length(_seq));
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_seq); i < n; i++ )
2023-06-13 14:42:06 +02:00
_ord[i] = i;
}
if(_hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h) && inputs[| 2].value_from == noone) {
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.button_def, mouse_click(mb_left, _focus)? 2 : 1, _x, _y, _w, _h);
2023-06-10 13:59:45 +02:00
if(mouse_press(mb_left, _focus))
dialogPanelCall(new Panel_Array_Sequence(self));
} else
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.button_def, 0, _x, _y, _w, _h);
2023-06-10 13:59:45 +02:00
var x0 = _x + ui(4);
var y0 = _y + ui(4);
var x1 = _x + _w - ui(4 + 32);
var y1 = _y + _h - ui(4);
var sw = x1 - x0;
var sh = y1 - y0;
var nn = sh;
draw_sprite_stretched(THEME.ui_panel_bg, 1, x0, y0, sw, sh);
sequence_surface = surface_verify(sequence_surface, sw, sh - ui(8));
surface_set_target(sequence_surface);
DRAW_CLEAR
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_ord); i < n; i++ ) {
2023-06-10 13:59:45 +02:00
var o = _ord[i];
if(o == noone) continue;
2024-03-31 05:36:11 +02:00
var s = array_safe_get_fast(_seq, o);
2023-06-10 13:59:45 +02:00
if(!is_surface(s)) continue;
var xx = nn * i;
2023-09-08 21:37:36 +02:00
var _sw = surface_get_width_safe(s);
var _sh = surface_get_height_safe(s);
2023-06-10 13:59:45 +02:00
var _ss = (nn - ui(4)) / max(_sw, _sh);
var _sx = xx + nn / 2 - _sw * _ss / 2;
var _sy = nn / 2 - _sh * _ss / 2;
draw_surface_ext_safe(s, _sx, _sy, _ss, _ss);
//draw_set_color(COLORS.panel_toolbar_outline);
//draw_rectangle(xx, 0, xx + nn, nn, true);
}
surface_reset_target();
2023-09-08 21:09:09 +02:00
draw_surface_safe(sequence_surface, x0, y0 + ui(4));
2023-06-10 13:59:45 +02:00
draw_sprite_ui(THEME.gear, 0, x1 + ui(16), _y + _h / 2,,,, COLORS._main_icon);
return _h;
});
input_display_list = [ 0,
2023-06-13 14:42:06 +02:00
["Frames", false], sequence_renderer, 2, 3,
2023-06-10 13:59:45 +02:00
["Animation", false], 1,
];
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
var _sur = getInputData(0);
2023-06-13 14:42:06 +02:00
if(!is_array(_sur)) {
outputs[| 0].setValue(_sur);
2023-06-10 13:59:45 +02:00
return;
}
var _spd = getInputData(1);
var _seq = getInputData(2);
var _ovf = getInputData(3);
2023-06-13 14:42:06 +02:00
2023-10-09 16:07:33 +02:00
var frm = floor(CURRENT_FRAME / _spd);
2023-06-10 13:59:45 +02:00
var ind = frm;
2023-06-13 14:42:06 +02:00
if(array_length(_seq) == 0) {
_seq = array_create(array_length(_sur));
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_sur); i < n; i++ )
2023-06-13 14:42:06 +02:00
_seq[i] = i;
}
if(_ovf == 0)
ind = clamp(ind, 0, array_length(_seq) - 1);
else if(_ovf == 2) {
var _slen = array_length(_seq);
var _slpp = _slen * 2 - 2;
ind = abs(ind % _slpp);
if(ind >= _slen)
ind = _slpp - ind;
} else if(_ovf == 3 && ind >= array_length(_seq)) {
outputs[| 0].setValue(noone);
return;
}
2023-06-10 13:59:45 +02:00
2023-06-13 14:42:06 +02:00
ind = array_safe_get(_seq, ind,, ARRAY_OVERFLOW.loop);
2022-01-13 05:24:03 +01:00
2023-06-10 13:59:45 +02:00
if(ind == noone) {
outputs[| 0].setValue(noone);
2022-01-13 05:24:03 +01:00
return;
}
2024-03-31 05:36:11 +02:00
outputs[| 0].setValue(array_safe_get_fast(_sur, ind));
2022-01-13 05:24:03 +01:00
}
}