Pixel-Composer/scripts/timeline_data/timeline_data.gml

233 lines
6.6 KiB
Plaintext
Raw Normal View History

2023-10-14 08:00:35 +02:00
function timelineItem() constructor {
show = true;
2023-10-14 13:51:34 +02:00
color = -1;
color_cur = -1;
color_dsp = -1;
2023-10-12 07:07:24 +02:00
parent = noone;
2023-10-14 13:51:34 +02:00
static setColor = function(color) { self.color = color; }
2023-10-14 08:00:35 +02:00
static drawLabel = function(_x, _y, _w, _msx, _msy) {}
static removeSelf = function() { #region
2023-10-12 07:07:24 +02:00
if(parent == noone) return;
array_remove(parent.contents, self);
return self;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
static serialize = function() {}
2023-10-14 08:00:35 +02:00
static deserialize = function(_map) { #region
2023-10-12 07:07:24 +02:00
switch(_map.type) {
case "Node" : return new timelineItemNode(noone).deserialize(_map);
case "Folder" : return new timelineItemGroup(noone).deserialize(_map);
}
return self;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
}
function timelineItemNode(node) : timelineItem() constructor {
self.node = node;
2023-10-14 13:51:34 +02:00
static drawLabel = function(_item, _x, _y, _w, _msx, _msy, hover, focus, itHover, fdHover, nameType, alpha = 1) { #region
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;
2023-10-14 13:51:34 +02:00
var col = color;
var cxt = _item.contexts;
if(col == -1)
for( var i = array_length(cxt) - 1; i >= 0; i-- ) {
var _context = cxt[i];
if(_context.item.color == -1) continue;
col = _context.item.color;
break;
}
color_cur = col;
if(col == -1) col = CDEF.main_grey;
var cc = colorMultiply(col, COLORS.panel_animation_dope_bg);
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)) {
cc = colorMultiply(col, COLORS.panel_animation_dope_bg_hover);
2023-10-14 08:00:35 +02:00
res = 1;
}
2023-10-14 13:51:34 +02:00
color_dsp = cc;
draw_sprite_stretched_ext(THEME.timeline_folder, 0, _x, _y, _w, lh, cc, alpha);
//draw_sprite_stretched_ext(THEME.timeline_node, 1, _x, _y, _w, lh, COLORS.panel_animation_node_outline, 1);
2023-10-14 08:00:35 +02:00
2023-10-14 13:51:34 +02:00
var tx = lx + lw - ui(7);
if(buttonInstant(THEME.button_hide, tx - ui(9), _y + ui(1), ui(18), ui(18), [ _msx, _msy ], focus, hover,
__txtx("panel_animation_goto", "Go to node"), THEME.animate_node_go, 0, col == -1? CDEF.main_grey : col) == 2)
2023-10-14 08:00:35 +02:00
graphFocusNode(node);
2023-10-14 13:51:34 +02:00
if(_sel)
draw_sprite_stretched_ext(THEME.timeline_node, 1, _x, _y + 1, _w, lh - 2, COLORS._main_accent, 1);
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
}
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.display_name == "") {
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
2023-10-14 08:00:35 +02:00
draw_set_font(f_p2);
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;
} #endregion
static serialize = function() { #region
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-10-12 07:07:24 +02:00
_map.color = color;
_map.node_id = node.node_id;
return _map;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
2023-10-14 08:00:35 +02:00
static deserialize = function(_map) { #region
2023-10-12 07:07:24 +02:00
color = _map.color;
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;
2023-10-12 07:07:24 +02:00
node = PROJECT.nodeMap[? _node_id];
node.timeline_item = self;
return self;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
}
function timelineItemGroup() : timelineItem() constructor {
2023-10-14 08:00:35 +02:00
name = "";
renaming = false;
tb_name = new textBox(TEXTBOX_INPUT.text, function(val) { name = val; renaming = false; });
2023-10-12 07:07:24 +02:00
contents = [];
2023-10-14 08:00:35 +02:00
static rename = function() {
renaming = true;
tb_name.setFocusHover(true, true);
run_in(1, function() { tb_name.activate(); });
}
2023-10-14 13:51:34 +02:00
static drawLabel = function(_item, _x, _y, _w, _msx, _msy, hover, focus, itHover, fdHover, nameType, alpha = 1) { #region
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 = color;
var cxt = _item.contexts;
if(col == -1)
for( var i = array_length(cxt) - 1; i >= 0; i-- ) {
var _context = cxt[i];
if(_context.item.color == -1) continue;
col = _context.item.color;
hig = false;
break;
}
color_cur = col;
if(col == -1) col = CDEF.main_grey;
var bnd = hig? merge_color(c_white, COLORS.panel_animation_dope_bg, 0.8) : COLORS.panel_animation_dope_bg;
var cc = colorMultiply(col, bnd);
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)) {
bnd = hig? merge_color(c_white, COLORS.panel_animation_dope_bg_hover, 0.8) : COLORS.panel_animation_dope_bg_hover;
cc = colorMultiply(col, bnd);
2023-10-14 08:00:35 +02:00
res = 1;
}
2023-10-14 13:51:34 +02:00
color_dsp = cc;
2023-10-14 08:00:35 +02:00
draw_sprite_stretched_ext(THEME.timeline_folder, 0, _x, _y, _w, lh, cc, alpha);
2023-10-14 13:51:34 +02:00
if(fdHover == self)
draw_sprite_stretched_ext(THEME.timeline_folder, 1, _x, _y, _w, lh, col == -1? COLORS._main_accent : col, 1);
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
2023-10-14 13:51:34 +02:00
draw_set_text(f_p2, fa_left, fa_center);
2023-10-14 08:00:35 +02:00
if(renaming) {
var _param = new widgetParam(lx + ui(20), _y + ui(2), _w - ui(24), lh - ui(4), name,, [ _msx, _msy ]);
2023-10-14 13:51:34 +02:00
tb_name.setFont(f_p2);
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);
2023-10-14 13:51:34 +02:00
draw_text_add(lx + ui(24), _y + lh / 2 - ui(2), name);
2023-10-14 08:00:35 +02:00
}
return res;
} #endregion
2023-10-14 13:51:34 +02:00
static setColor = function(color) {
self.color = color;
}
2023-10-14 08:00:35 +02:00
static addItem = function(_item) { #region
2023-10-12 07:07:24 +02:00
array_push(contents, _item);
_item.parent = self;
return self;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
2023-10-14 08:00:35 +02:00
static serialize = function() { #region
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;
return _map;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
2023-10-14 08:00:35 +02:00
static deserialize = function(_map) { #region
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;
}
return self;
2023-10-14 08:00:35 +02:00
} #endregion
2023-10-12 07:07:24 +02:00
}