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;
|
2024-06-29 08:52:59 +02:00
|
|
|
setAlwaysTimeline(new timelineItemNode_Sequence_Anim(self));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self, []))
|
2023-06-13 14:42:06 +02:00
|
|
|
.setArrayDepth(1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_Float("Speed", self, 1))
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2023-06-10 13:59:45 +02:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Int("Sequence", self, []))
|
2023-06-13 14:42:06 +02:00
|
|
|
.setVisible(true, true)
|
2023-06-10 13:59:45 +02:00
|
|
|
.setArrayDepth(1);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Enum_Scroll("Overflow", self, 0, [ "Hold", "Loop", "Ping Pong", "Empty" ]));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-06-10 13:59:45 +02:00
|
|
|
sequence_surface = noone;
|
|
|
|
sequence_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
2023-10-02 08:57:44 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-06-29 08:52:59 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _h, COLORS.node_composite_bg_blend, 1);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
if(_hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h) && inputs[2].value_from == noone) {
|
2024-08-06 04:30:00 +02:00
|
|
|
draw_sprite_stretched_add(THEME.ui_panel, 1, _x, _y, _w, _h, c_white, 0.2);
|
2024-06-29 08:52:59 +02:00
|
|
|
|
2023-06-10 13:59:45 +02:00
|
|
|
if(mouse_press(mb_left, _focus))
|
|
|
|
dialogPanelCall(new Panel_Array_Sequence(self));
|
2024-06-29 08:52:59 +02:00
|
|
|
}
|
2023-06-10 13:59:45 +02:00
|
|
|
|
2024-06-29 08:52:59 +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;
|
|
|
|
|
2024-06-29 08:52:59 +02:00
|
|
|
// draw_sprite_stretched(THEME.ui_panel_bg, 1, x0, y0, sw, sh);
|
2023-06-10 13:59:45 +02:00
|
|
|
|
2024-06-29 08:52:59 +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);
|
2024-06-29 08:52:59 +02:00
|
|
|
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();
|
|
|
|
|
2024-06-29 08:52:59 +02:00
|
|
|
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) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _sur = getInputData(0);
|
2023-06-13 14:42:06 +02:00
|
|
|
if(!is_array(_sur)) {
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_sur);
|
2023-06-10 13:59:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
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)) {
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(noone);
|
2023-06-13 14:42:06 +02:00
|
|
|
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) {
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(noone);
|
2022-01-13 05:24:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(array_safe_get_fast(_sur, ind));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2024-06-29 08:52:59 +02: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) {
|
2024-06-29 08:52:59 +02:00
|
|
|
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
|
|
|
}
|