2023-11-18 03:47:11 +01:00
|
|
|
function Node_create_Image_gif(_x, _y, _group = noone) { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = "";
|
2024-05-03 13:40:46 +02:00
|
|
|
if(NODE_NEW_MANUAL) {
|
2024-05-16 15:28:45 +02:00
|
|
|
path = get_open_filename_pxc("animated gif|*.gif", "");
|
2023-02-28 09:43:01 +01:00
|
|
|
key_release();
|
2022-01-13 05:24:03 +01:00
|
|
|
if(path == "") return noone;
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
var node = new Node_Image_gif(_x, _y, _group);
|
2022-01-13 05:24:03 +01:00
|
|
|
node.inputs[| 0].setValue(path);
|
2024-05-03 13:40:46 +02:00
|
|
|
if(NODE_NEW_MANUAL) node.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
return node;
|
2023-11-18 03:47:11 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-18 03:47:11 +01:00
|
|
|
function Node_create_Image_gif_path(_x, _y, path) { #region
|
2023-12-08 03:50:09 +01:00
|
|
|
if(!file_exists_empty(path)) return noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
var node = new Node_Image_gif(_x, _y, PANEL_GRAPH.getCurrentContext());
|
2022-01-13 05:24:03 +01:00
|
|
|
node.inputs[| 0].setValue(path);
|
2022-01-16 14:28:57 +01:00
|
|
|
node.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
return node;
|
2023-11-18 03:47:11 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Image_gif(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-03-19 09:17:39 +01:00
|
|
|
name = "Image GIF";
|
2022-11-18 03:20:31 +01:00
|
|
|
color = COLORS.node_blend_input;
|
2022-01-13 05:24:03 +01:00
|
|
|
update_on_frame = true;
|
2024-06-29 08:52:59 +02:00
|
|
|
setAlwaysTimeline(new timelineItemNode_Image_gif(self));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-01 14:57:57 +02:00
|
|
|
inputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, "")
|
2023-12-07 15:08:09 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.path_load, { filter: "Animated gif|*.gif" });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-04-08 07:13:46 +02:00
|
|
|
inputs[| 1] = nodeValue("Set animation length to gif", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, false )
|
|
|
|
.setDisplay(VALUE_DISPLAY.button, { name: "Match length", UI : true, onClick: function() {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(!spr) return;
|
|
|
|
if(!sprite_exists(spr)) return;
|
2023-10-09 16:07:33 +02:00
|
|
|
TOTAL_FRAMES = sprite_get_number(spr);
|
2023-07-06 19:49:16 +02:00
|
|
|
PROJECT.animator.framerate = 12;
|
2023-10-02 08:57:44 +02:00
|
|
|
} });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
inputs[| 2] = nodeValue("Output as array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
|
|
|
|
2023-10-01 14:57:57 +02:00
|
|
|
inputs[| 3] = nodeValue("Loop modes", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Loop", "Ping pong", "Hold last frame", "Hide"])
|
|
|
|
.rejectArray();
|
|
|
|
|
|
|
|
inputs[| 4] = nodeValue("Start frame", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
|
|
|
|
|
|
|
|
inputs[| 5] = nodeValue("Custom frame order", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
|
|
|
|
|
|
|
inputs[| 6] = nodeValue("Frame", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
|
|
|
|
|
|
|
|
inputs[| 7] = nodeValue("Animation speed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
|
|
|
outputs[| 1] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.path, "")
|
2022-01-19 14:48:30 +01:00
|
|
|
.setVisible(true, true);
|
2023-10-01 14:57:57 +02:00
|
|
|
|
|
|
|
input_display_list = [
|
|
|
|
["Image", false], 0,
|
|
|
|
["Output", false], 2,
|
2024-01-09 03:39:40 +01:00
|
|
|
["Animation", false], 1, 3, 4, 7,
|
|
|
|
["Custom Frame Order", false, 5], 6,
|
2023-10-01 14:57:57 +02:00
|
|
|
];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-10-01 14:57:57 +02:00
|
|
|
spr = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
path_current = "";
|
2023-10-01 14:57:57 +02:00
|
|
|
loading = 0;
|
|
|
|
spr_builder = noone;
|
|
|
|
surfaces = [];
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
edit_time = 0;
|
|
|
|
attributes.file_checker = true;
|
|
|
|
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
|
|
|
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
|
|
|
|
|
|
|
on_drop_file = function(path) { #region
|
2023-09-28 13:15:29 +02:00
|
|
|
inputs[| 0].setValue(path);
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
if(updatePaths(path)) {
|
2022-01-16 14:28:57 +01:00
|
|
|
doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2024-03-14 14:35:19 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
insp1UpdateTooltip = __txt("Refresh");
|
2024-03-31 05:36:11 +02:00
|
|
|
insp1UpdateIcon = [ THEME.refresh_icon, 1, COLORS._main_value_positive ];
|
2023-04-07 21:25:27 +02:00
|
|
|
|
2023-10-01 14:57:57 +02:00
|
|
|
static onInspector1Update = function() { #region
|
2024-03-14 14:35:19 +01:00
|
|
|
updatePaths(path_get(getInputData(0)));
|
2023-10-01 14:57:57 +02:00
|
|
|
} #endregion
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
function updatePaths(path = path_current) { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
if(path == -1) return false;
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var ext = string_lower(filename_ext(path));
|
2022-01-13 05:24:03 +01:00
|
|
|
var _name = string_replace(filename_name(path), filename_ext(path), "");
|
|
|
|
|
2023-07-05 15:09:52 +02:00
|
|
|
if(ext != ".gif")
|
|
|
|
return false;
|
2023-11-23 13:39:35 +01:00
|
|
|
|
|
|
|
setDisplayName(_name);
|
2023-07-05 15:09:52 +02:00
|
|
|
outputs[| 1].setValue(path);
|
2023-11-23 13:39:35 +01:00
|
|
|
|
2023-07-05 15:09:52 +02:00
|
|
|
if(spr) sprite_delete(spr);
|
|
|
|
sprite_add_gif(path, function(_spr) {
|
|
|
|
spr_builder = _spr;
|
|
|
|
loading = 2;
|
|
|
|
});
|
|
|
|
loading = 1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-05 15:09:52 +02:00
|
|
|
if(path_current == "")
|
|
|
|
first_update = true;
|
2024-03-14 14:35:19 +01:00
|
|
|
path_current = path;
|
|
|
|
edit_time = max(edit_time, file_get_modify_s(path_current));
|
|
|
|
|
2023-07-05 15:09:52 +02:00
|
|
|
return true;
|
2023-10-01 14:57:57 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-01 14:57:57 +02:00
|
|
|
static step = function() { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _arr = getInputData(2);
|
|
|
|
var _lop = getInputData(3);
|
|
|
|
var _cus = getInputData(5);
|
2023-10-01 14:57:57 +02:00
|
|
|
|
|
|
|
inputs[| 3].setVisible(!_arr);
|
|
|
|
inputs[| 4].setVisible(!_cus);
|
|
|
|
inputs[| 6].setVisible( _cus);
|
|
|
|
inputs[| 7].setVisible(!_cus);
|
|
|
|
|
2023-05-23 14:02:38 +02:00
|
|
|
if(loading == 2 && spr_builder != noone && spr_builder.building()) {
|
2023-09-27 14:55:21 +02:00
|
|
|
surfaces = [];
|
2023-05-23 14:02:38 +02:00
|
|
|
spr = spr_builder._spr;
|
2024-03-14 14:35:19 +01:00
|
|
|
//print($"{spr}: {sprite_get_width(spr)}, {sprite_get_height(spr)}");
|
2023-11-18 03:47:11 +01:00
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
triggerRender();
|
2023-05-23 14:02:38 +02:00
|
|
|
loading = 0;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2023-05-23 14:02:38 +02:00
|
|
|
gc_collect();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2024-03-14 14:35:19 +01:00
|
|
|
|
2024-06-03 05:44:08 +02:00
|
|
|
if(attributes.file_checker && file_exists_empty(path_current)) {
|
2024-06-03 05:48:18 +02:00
|
|
|
var _modi = file_get_modify_s(path_current);
|
|
|
|
|
|
|
|
if(_modi > edit_time) {
|
|
|
|
edit_time = _modi;
|
|
|
|
|
|
|
|
run_in(2, function() { updatePaths(); triggerRender(); });
|
2024-03-14 14:35:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-10-01 14:57:57 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static update = function(frame = CURRENT_FRAME) { #region
|
2024-03-14 14:35:19 +01:00
|
|
|
var path = path_get(getInputData(0));
|
2023-01-17 08:11:55 +01:00
|
|
|
if(path_current != path) updatePaths(path);
|
2024-03-14 14:35:19 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
if(!spr || !sprite_exists(spr)) return;
|
|
|
|
|
|
|
|
var ww = sprite_get_width(spr);
|
|
|
|
var hh = sprite_get_height(spr);
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var _outsurf = outputs[| 0].getValue();
|
2023-10-02 08:57:44 +02:00
|
|
|
var array = getInputData(2);
|
2023-09-27 14:55:21 +02:00
|
|
|
|
|
|
|
if(array) {
|
|
|
|
var amo = sprite_get_number(spr);
|
|
|
|
if(array_length(surfaces) == amo && is_surface(surfaces[0])) {
|
|
|
|
outputs[| 0].setValue(surfaces);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_array_free(_outsurf);
|
|
|
|
surfaces = array_create(amo);
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
|
|
|
surfaces[i] = surface_create_valid(ww, hh, attrDepth());
|
|
|
|
|
|
|
|
surface_set_shader(surfaces[i]);
|
|
|
|
draw_sprite(spr, i, 0, 0);
|
|
|
|
surface_reset_shader();
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs[| 0].setValue(surfaces);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _loop = getInputData(3);
|
|
|
|
var _strt = getInputData(4);
|
|
|
|
var _cust = getInputData(5);
|
|
|
|
var _spd = getInputData(7);
|
2023-10-09 16:07:33 +02:00
|
|
|
var _frm = _cust? getInputData(6) : CURRENT_FRAME * _spd - _strt;
|
2023-10-01 14:57:57 +02:00
|
|
|
|
|
|
|
var _len = sprite_get_number(spr);
|
|
|
|
var _drw = true;
|
|
|
|
|
|
|
|
switch(_loop) {
|
|
|
|
case ANIMATION_END.loop :
|
|
|
|
_frm = safe_mod(_frm, _len);
|
|
|
|
break;
|
|
|
|
case ANIMATION_END.ping :
|
|
|
|
_frm = safe_mod(_frm, _len * 2 - 2);
|
|
|
|
if(_frm >= _len)
|
|
|
|
_frm = _len * 2 - 2 - _frm;
|
|
|
|
break;
|
|
|
|
case ANIMATION_END.hold :
|
|
|
|
_frm = clamp(_frm, -_len, _len - 1);
|
|
|
|
break;
|
|
|
|
case ANIMATION_END.hide :
|
|
|
|
if(_frm < 0 || _frm >= _len)
|
|
|
|
_drw = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
_outsurf = surface_verify(_outsurf, ww, hh, attrDepth());
|
2022-12-27 04:00:50 +01:00
|
|
|
outputs[| 0].setValue(_outsurf);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
surface_set_shader(_outsurf);
|
2023-10-01 14:57:57 +02:00
|
|
|
if(_drw) draw_sprite(spr, _frm, 0, 0);
|
2023-09-27 14:55:21 +02:00
|
|
|
surface_reset_shader();
|
2023-10-01 14:57:57 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-18 03:47:11 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
2023-09-27 14:55:21 +02:00
|
|
|
if(loading) draw_sprite_ui(THEME.loading, 0, xx + w * _s / 2, yy + h * _s / 2, _s, _s, current_time / 2, COLORS._main_icon, 1);
|
2023-11-18 03:47:11 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-18 03:47:11 +01:00
|
|
|
static onDestroy = function() { #region
|
|
|
|
if(sprite_exists(spr)) sprite_flush(spr);
|
|
|
|
} #endregion
|
2024-07-03 05:16:46 +02:00
|
|
|
|
|
|
|
static dropPath = function(path) {
|
|
|
|
inputs[| 0].setValue(path);
|
|
|
|
}
|
2024-06-29 08:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function timelineItemNode_Image_gif(node) : timelineItemNode(node) constructor {
|
|
|
|
|
|
|
|
static drawDopesheet = function(_x, _y, _s, _msx, _msy) {
|
|
|
|
if(!is_instanceof(node, Node_Image_gif)) return;
|
|
|
|
if(!node.attributes.show_timeline) return;
|
|
|
|
|
|
|
|
var _spr = node.spr;
|
|
|
|
if(!sprite_exists(_spr)) return;
|
|
|
|
|
|
|
|
var _rx, _ry;
|
|
|
|
var _sw = sprite_get_width(_spr);
|
|
|
|
var _sh = sprite_get_height(_spr);
|
|
|
|
var _ss = h / max(_sw, _sh);
|
|
|
|
|
|
|
|
for (var i = 0, n = sprite_get_number(_spr); i < n; i++) {
|
|
|
|
_rx = _x + (i + 1) * _s;
|
|
|
|
_ry = h / 2 + _y;
|
|
|
|
|
|
|
|
draw_sprite_ext(_spr, i, _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_Image_gif)) return;
|
|
|
|
if(!node.attributes.show_timeline) return;
|
|
|
|
|
|
|
|
drawDopesheetOutput(_x, _y, _s, _msx, _msy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static onSerialize = function(_map) {
|
|
|
|
_map.type = "timelineItemNode_Image_gif";
|
|
|
|
}
|
2024-07-03 05:16:46 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|