Pixel-Composer/scripts/node_sequence_anim/node_sequence_anim.gml

176 lines
4.9 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;
setAlwaysTimeline(new timelineItemNode_Sequence_Anim(self));
2022-01-13 05:24:03 +01:00
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;
}
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _h, COLORS.node_composite_bg_blend, 1);
if(_hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h) && inputs[| 2].value_from == noone) {
draw_sprite_stretched_add(THEME.ui_panel_fg, 1, _x, _y, _w, _h, c_white, 0.2);
2023-06-10 13:59:45 +02:00
if(mouse_press(mb_left, _focus))
dialogPanelCall(new Panel_Array_Sequence(self));
}
2023-06-10 13:59:45 +02:00
var pd = ui(2);
var x0 = _x + pd;
var y0 = _y + pd;
var x1 = _x + _w - pd - ui(32);
var y1 = _y + _h - pd;
2023-06-10 13:59:45 +02:00
var sw = x1 - x0;
var sh = y1 - y0;
var nn = sh;
// draw_sprite_stretched(THEME.ui_panel_bg, 1, x0, y0, sw, sh);
2023-06-10 13:59:45 +02:00
sequence_surface = surface_verify(sequence_surface, sw, sh - pd * 2);
2023-06-10 13:59:45 +02:00
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);
var _ss = nn / max(_sw, _sh);
2023-06-10 13:59:45 +02:00
var _sx = xx + nn / 2 - _sw * _ss / 2;
var _sy = nn / 2 - _sh * _ss / 2;
draw_surface_ext_safe(s, _sx, _sy, _ss, _ss);
}
surface_reset_target();
draw_surface_safe(sequence_surface, x0, y0 + pd);
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
}
}
function timelineItemNode_Sequence_Anim(node) : timelineItemNode(node) constructor {
static drawDopesheet = function(_x, _y, _s, _msx, _msy) {
if(!is_instanceof(node, Node_Sequence_Anim)) return;
if(!node.attributes.show_timeline) return;
var _surfs = node.getInputData(0);
var _seq = node.getInputData(2);
var _useq = !array_empty(_seq);
var _arr = _useq? _seq : _surfs;
var _surf, _rx;
var _h = h - 2;
var _ry = h / 2 + _y;
for (var i = 0, n = array_length(_arr); i < n; i++) {
_surf = _arr[i];
if(_useq) {
if(_surf < 0) continue;
_surf = _surfs[_surf];
}
if(!surface_exists(_surf)) continue;
_rx = _x + (i + 1) * _s;
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
var _ss = _h / max(_sw, _sh);
draw_surface_ext(_surf, _rx - _sw * _ss / 2, _ry - _sh * _ss / 2, _ss, _ss, 0, c_white, .5);
}
}
2024-06-29 12:31:24 +02:00
static drawDopesheetOver = function(_x, _y, _s, _msx, _msy, _hover, _focus) {
if(!is_instanceof(node, Node_Sequence_Anim)) return;
if(!node.attributes.show_timeline) return;
drawDopesheetOutput(_x, _y, _s, _msx, _msy);
}
static onSerialize = function(_map) {
_map.type = "timelineItemNode_Sequence_Anim";
}
2022-01-13 05:24:03 +01:00
}