Pixel-Composer/scripts/timeline_data/timeline_data.gml

301 lines
8.8 KiB
Plaintext
Raw Normal View History

2023-10-14 08:00:35 +02:00
function timelineItem() constructor {
h = ui(20);
2024-02-12 10:25:23 +01:00
show = true;
active = true;
2023-10-14 08:00:35 +02:00
2024-02-12 10:25:23 +01:00
color = -1;
2023-10-15 15:04:42 +02:00
color_cur = CDEF.main_grey;
2023-10-14 13:51:34 +02:00
color_dsp = -1;
2024-02-12 10:25:23 +01:00
parent = noone;
2023-10-12 07:07:24 +02:00
2023-10-14 13:51:34 +02:00
static setColor = function(color) { self.color = color; }
static getColor = function() { return color; }
2023-10-14 13:51:34 +02:00
static drawLabel = function(_x, _y, _w, _msx, _msy) {}
static drawDopesheet = function(_x, _y, _s, _msx, _msy) {}
2024-06-29 12:31:24 +02:00
static drawDopesheetOver = function(_x, _y, _s, _msx, _msy, _hover, _focus) {}
2023-10-14 08:00:35 +02:00
static removeSelf = function() {
2023-10-12 07:07:24 +02:00
if(parent == noone) return;
array_remove(parent.contents, self);
return self;
}
2023-10-12 07:07:24 +02:00
2024-06-29 12:31:24 +02:00
static onSerialize = function(_map) {}
2023-10-12 07:07:24 +02:00
static serialize = function() {}
2024-06-29 12:31:24 +02:00
static onDeserialize = function(_map) {}
static deserialize = function(_map) {
2023-10-12 07:07:24 +02:00
switch(_map.type) {
case "Folder" : return new timelineItemGroup().deserialize(_map);
2023-10-12 07:07:24 +02:00
case "Node" : return new timelineItemNode(noone).deserialize(_map);
2024-06-29 12:31:24 +02:00
case "timelineItemGroup_Canvas" : return new timelineItemGroup_Canvas().deserialize(_map);
case "timelineItemNode_Canvas" : return new timelineItemNode_Canvas(noone).deserialize(_map);
case "timelineItemNode_Image_Animated" : return new timelineItemNode_Image_Animated(noone).deserialize(_map);
case "timelineItemNode_Sequence_Anim" : return new timelineItemNode_Sequence_Anim(noone).deserialize(_map);
case "timelineItemNode_Image_gif" : return new timelineItemNode_Image_gif(noone).deserialize(_map);
2023-10-12 07:07:24 +02:00
}
return self;
}
2023-10-12 07:07:24 +02:00
}
function timelineItemNode(node) : timelineItem() constructor {
self.node = node;
static drawLabel = function(_item, _x, _y, _w, _msx, _msy, hover, focus, itHover, fdHover, nameType, alpha = 1) {
2023-10-14 13:51:34 +02:00
var _sel = node == PANEL_INSPECTOR.getInspecting();
var lx = _x + _item.depth * ui(12) + ui(2);
var lw = _w - _item.depth * ui(12) - ui(4);
2023-10-14 08:00:35 +02:00
var lh = ui(20);
var res = 0;
var col = getColor();
2023-10-14 13:51:34 +02:00
var cxt = _item.contexts;
if(col == -1)
for( var i = array_length(cxt) - 1; i >= 0; i-- ) {
var _context = cxt[i];
2024-06-29 12:31:24 +02:00
var _c = _context.item.getColor();
if(_c == -1) continue;
col = _c;
2023-10-14 13:51:34 +02:00
break;
}
2024-07-06 10:31:26 +02:00
2024-06-29 12:31:24 +02:00
if(col == -1) col = merge_color(CDEF.main_ltgrey, CDEF.main_white, 0.3);
2023-10-15 15:04:42 +02:00
color_cur = col;
2023-10-14 13:51:34 +02:00
2024-06-29 12:31:24 +02:00
var cc = colorMultiply(col, COLORS.panel_animation_dope_bg);
2024-07-04 03:11:32 +02:00
color_dsp = cc;
draw_sprite_stretched_ext(THEME.s_box_r2, 0, _x, _y, _w, lh, cc, alpha);
2023-10-14 08:00:35 +02:00
2023-10-14 13:51:34 +02:00
if(hover && point_in_rectangle(_msx, _msy, _x + ui(20), _y, _x + _w, _y + lh - 1)) {
draw_sprite_stretched_add(THEME.s_box_r2, 0, _x, _y, _w, lh, col, 0.05);
2023-10-14 08:00:35 +02:00
res = 1;
}
// draw_sprite_stretched_add(THEME.s_box_r2, 1, _x, _y, _w, lh, c_white, 0.15);
2024-06-29 12:31:24 +02:00
2023-10-14 13:51:34 +02:00
var tx = lx + lw - ui(7);
2024-07-04 03:11:32 +02:00
var tt = __txtx("panel_animation_goto", "Go to node");
var _m = [ _msx, _msy ];
if(buttonInstant(noone, tx - ui(9), _y + ui(1), ui(18), ui(18), _m, focus, hover, tt, THEME.animate_node_go, 0, col == -1? COLORS._main_icon_light : col, 0.4) == 2)
graphFocusNode(node);
2023-10-14 08:00:35 +02:00
if(_sel) draw_sprite_stretched_ext(THEME.s_box_r2, 1, _x, _y, _w, lh, COLORS._main_accent, 1);
2023-10-14 13:51:34 +02:00
var aa = 0.75;
if(hover && point_in_rectangle(_msx, _msy, lx, _y, lx + ui(20), _y + lh)) {
aa = 1;
2023-10-14 08:00:35 +02:00
if(mouse_press(mb_left, focus)) show = !show;
2023-10-14 13:51:34 +02:00
}
2024-08-12 13:42:05 +02:00
if(node.isActiveDynamic())
draw_sprite_ui_uniform(THEME.arrow, show? 3 : 0, lx + ui(10), _y + lh / 2, 1, col == -1? CDEF.main_grey : col, aa);
2023-10-14 08:00:35 +02:00
draw_set_text(f_p3, fa_left, fa_center);
var nodeName = $"[{node.name}] ";
var tw = string_width(nodeName);
draw_set_color(itHover == self? COLORS._main_text_accent : COLORS._main_text);
2023-10-14 13:51:34 +02:00
var txx = lx + ui(24);
2023-10-14 08:00:35 +02:00
if(nameType == 0 || nameType == 1 || !node.renamed) {
2023-10-14 13:51:34 +02:00
draw_set_alpha(0.6);
2023-10-14 08:00:35 +02:00
draw_text_add(txx, _y + lh / 2 - ui(2), nodeName);
txx += tw;
}
2023-10-14 13:51:34 +02:00
2024-07-04 03:11:32 +02:00
draw_set_font(f_p3);
2023-10-14 08:00:35 +02:00
draw_set_alpha(1);
2023-10-14 13:51:34 +02:00
if(nameType == 0 || nameType == 2)
draw_text_add(txx, _y + lh / 2 - ui(2), node.display_name);
2023-10-14 08:00:35 +02:00
return res;
}
2024-06-29 12:31:24 +02:00
static drawDopesheetOutput = function(_x, _y, _s, _msx, _msy) { return;
2024-08-08 06:57:51 +02:00
var _surf = node.outputs[0].getValue();
if(!is_surface(_surf)) return;
var _h = h - 2;
var _rx = _x + (CURRENT_FRAME + 1) * _s;
var _ry = h / 2 + _y;
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
var _ss = _h / max(_sw, _sh);
// draw_sprite_stretched_ext(THEME.s_box_r2, 0, _rx - h / 2, _ry - h / 2, h, h, CDEF.main_dkblack);
draw_surface_ext(_surf, _rx - _sw * _ss / 2, _ry - _sh * _ss / 2, _ss, _ss, 0, c_white, 1);
// draw_sprite_stretched_ext(THEME.s_box_r2, 1, _rx - h / 2, _ry - h / 2, h, h, CDEF.main_dkgrey);
}
2023-10-14 08:00:35 +02:00
static setColor = function(color) { node.attributes.color = color; }
static getColor = function() { return node.attributes.color; }
static serialize = function() {
2023-10-12 07:07:24 +02:00
var _map = {};
_map.type = "Node";
2023-10-14 08:00:35 +02:00
_map.show = show;
2023-11-17 06:24:31 +01:00
_map.node_id = is_struct(node)? node.node_id : -4;
onSerialize(_map);
2023-10-12 07:07:24 +02:00
return _map;
}
2023-10-12 07:07:24 +02:00
static deserialize = function(_map) {
2023-10-14 08:00:35 +02:00
show = struct_try_get(_map, "show", true);
2023-10-12 07:07:24 +02:00
2023-10-14 08:00:35 +02:00
var _node_id = _map.node_id;
2024-06-29 12:31:24 +02:00
if(_node_id == 0) {
node = PROJECT.globalNode;
node.timeline_item = self;
} else if(ds_map_exists(PROJECT.nodeMap, _node_id)) {
2023-11-09 07:59:03 +01:00
node = PROJECT.nodeMap[? _node_id];
node.timeline_item = self;
}
2023-10-12 07:07:24 +02:00
onDeserialize(_map);
2024-06-29 12:31:24 +02:00
2023-10-12 07:07:24 +02:00
return self;
}
2023-10-12 07:07:24 +02:00
}
function timelineItemGroup() : timelineItem() constructor {
2024-06-29 12:31:24 +02:00
name = "";
2023-10-14 08:00:35 +02:00
renaming = false;
2024-06-30 08:52:55 +02:00
2023-10-14 08:00:35 +02:00
tb_name = new textBox(TEXTBOX_INPUT.text, function(val) { name = val; renaming = false; });
2024-06-30 08:52:55 +02:00
tb_name.padding = ui(4);
tb_name.hide = 2;
2023-10-12 07:07:24 +02:00
contents = [];
static rename = function() { #region
2023-10-14 08:00:35 +02:00
renaming = true;
tb_name.setFocusHover(true, true);
2023-10-15 15:04:42 +02:00
run_in(1, function() {
tb_name._current_text = name;
tb_name.activate();
});
} #endregion
2023-10-14 08:00:35 +02:00
static drawLabel = function(_item, _x, _y, _w, _msx, _msy, hover, focus, itHover, fdHover, nameType, alpha = 1) {
2023-10-14 13:51:34 +02:00
var lx = _x + _item.depth * ui(12) + ui(2);
var lw = _w - _item.depth * ui(12) - ui(4);
2023-10-14 08:00:35 +02:00
var lh = ui(20);
var res = 0;
2023-10-14 13:51:34 +02:00
var hig = true;
var col = getColor();
2023-10-14 13:51:34 +02:00
var cxt = _item.contexts;
if(col == -1)
for( var i = array_length(cxt) - 1; i >= 0; i-- ) {
var _context = cxt[i];
if(_context.item.getColor() == -1) continue;
col = _context.item.getColor();
2023-10-14 13:51:34 +02:00
hig = false;
break;
}
if(col == -1) col = CDEF.main_grey;
2023-10-15 15:04:42 +02:00
color_cur = col;
2023-10-14 13:51:34 +02:00
2024-06-30 08:52:55 +02:00
var bnd = hig? merge_color(c_white, COLORS.panel_animation_dope_bg, .9) : COLORS.panel_animation_dope_bg_hover;
2023-10-14 13:51:34 +02:00
var cc = colorMultiply(col, bnd);
2024-06-30 08:52:55 +02:00
color_dsp = cc;
draw_sprite_stretched_ext(THEME.s_box_r2, 0, _x, _y, _w, lh, cc, alpha);
2023-10-14 08:00:35 +02:00
2023-10-14 13:51:34 +02:00
if(hover && point_in_rectangle(_msx, _msy, _x + ui(20), _y, _x + _w, _y + lh - 1)) {
draw_sprite_stretched_add(THEME.s_box_r2, 0, _x, _y, _w, lh, col, 0.05);
2023-10-14 08:00:35 +02:00
res = 1;
}
draw_sprite_stretched_add(THEME.s_box_r2, 1, _x, _y, _w, lh, c_white, 0.15);
2023-10-14 13:51:34 +02:00
if(fdHover == self)
draw_sprite_stretched_ext(THEME.s_box_r2, 1, _x, _y + 1, _w, lh - 2, col == -1? COLORS._main_accent : col, 1);
2023-10-14 13:51:34 +02:00
var aa = 0.75;
2023-10-14 08:00:35 +02:00
if(hover && point_in_rectangle(_msx, _msy, lx, _y, lx + ui(20), _y + lh)) {
2023-10-14 13:51:34 +02:00
aa = 1;
2023-10-14 08:00:35 +02:00
if(mouse_press(mb_left, focus)) show = !show;
2023-10-14 13:51:34 +02:00
}
draw_sprite_ui_uniform(THEME.folder_16, show, lx + ui(10), _y + lh / 2, 1, col == -1? CDEF.main_grey : col, aa);
2023-10-14 08:00:35 +02:00
2024-07-04 03:11:32 +02:00
draw_set_text(f_p3, fa_left, fa_center);
2023-10-14 08:00:35 +02:00
if(renaming) {
2024-06-30 08:52:55 +02:00
var _param = new widgetParam(lx + ui(20), _y + 1, _w - ui(24), lh - ui(4), name,, [ _msx, _msy ]);
2024-07-04 03:11:32 +02:00
_param.font = f_p3;
2024-06-30 08:52:55 +02:00
tb_name.highlight_color = cc;
tb_name.highlight_alpha = .5;
2023-10-14 08:00:35 +02:00
tb_name.setFocusHover(focus, hover);
tb_name.drawParam(_param);
} else {
draw_set_color(itHover == self? COLORS._main_text_accent : COLORS._main_text);
2024-06-30 08:52:55 +02:00
draw_text_add(lx + ui(24), _y + lh / 2, name);
2023-10-14 08:00:35 +02:00
}
return res;
}
2023-10-14 08:00:35 +02:00
static addItem = function(_item) {
2023-10-12 07:07:24 +02:00
array_push(contents, _item);
_item.parent = self;
return self;
}
2023-10-12 07:07:24 +02:00
static destroy = function() {
2023-10-15 15:04:42 +02:00
var ind = array_find(parent.contents, self);
array_delete(parent.contents, ind, 1);
for( var i = 0, n = array_length(contents); i < n; i++ ) {
array_insert(parent.contents, ind++, contents[i]);
contents[i].parent = parent;
}
}
2023-10-15 15:04:42 +02:00
static serialize = function() {
2023-10-12 07:07:24 +02:00
var _map = {};
2023-10-14 08:00:35 +02:00
_map.type = "Folder";
_map.name = name;
_map.show = show;
_map.color = color;
2023-10-12 07:07:24 +02:00
var _content = array_create(array_length(contents));
for( var i = 0, n = array_length(contents); i < n; i++ )
_content[i] = contents[i].serialize();
_map.contents = _content;
2024-06-29 12:31:24 +02:00
onSerialize(_map);
2023-10-12 07:07:24 +02:00
return _map;
}
2023-10-12 07:07:24 +02:00
static deserialize = function(_map) {
2023-10-12 07:07:24 +02:00
color = _map.color;
2023-10-14 08:00:35 +02:00
name = struct_try_get(_map, "name", "");
show = struct_try_get(_map, "show", true);
2023-10-12 07:07:24 +02:00
contents = array_create(array_length(_map.contents));
for( var i = 0, n = array_length(_map.contents); i < n; i++ ) {
contents[i] = new timelineItem().deserialize(_map.contents[i]);
contents[i].parent = self;
}
2024-06-29 12:31:24 +02:00
onDeserialize(_map);
2023-10-12 07:07:24 +02:00
return self;
}
2023-10-12 07:07:24 +02:00
}