Pixel-Composer/scripts/panel_nodes/panel_nodes.gml

107 lines
3.5 KiB
Plaintext
Raw Normal View History

2023-03-13 10:45:56 +01:00
function Panel_Nodes() : PanelContent() constructor {
title = __txt("Nodes");
padding = 8;
w = ui(320);
h = ui(480);
search_string = "";
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) /*=>*/ { search_string = string(str); });
tb_search.align = fa_left;
tb_search.auto_update = true;
tb_search.boxColor = COLORS._main_icon_light;
node_collapse = ds_map_create();
2023-03-13 10:45:56 +01:00
function onResize() { sc_nodes.resize(w - ui(padding + padding), h - ui(padding + padding + 40)); }
2023-03-13 10:45:56 +01:00
function drawNodeList(_arr, _x0, _x1, _y, _m) {
2023-03-13 10:45:56 +01:00
var ww = sc_nodes.surface_w;
var hg = ui(28);
var _h = 0;
for( var i = 0; i < array_length(_arr); i++ ) {
var node = _arr[i];
var name = node.renamed? node.display_name : node.name;
2023-03-13 10:45:56 +01:00
if(string_lower(search_string) != "" && string_lower(string_pos(search_string, name)) == 0)
continue;
var isGroup = struct_has(node, "nodes");
if(isGroup && !ds_map_exists(node_collapse, node.node_id))
node_collapse[? node.node_id] = false;
if(pHOVER && point_in_rectangle(_m[0], _m[1], _x0, _y, _x1 - _x0 - ui(32), _y + hg)) {
2024-07-28 13:55:57 +02:00
sc_nodes.hover_content = true;
2023-03-13 10:45:56 +01:00
var cc = merge_color(COLORS._main_icon_light, COLORS._main_icon, 0.25);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _x0, _y, _x1 - _x0, hg, cc, 1);
if(sc_nodes.active) {
if(DOUBLE_CLICK)
PANEL_PREVIEW.setNodePreview(node);
else if(mouse_press(mb_left)) {
if(isGroup)
node_collapse[? node.node_id] = !node_collapse[? node.node_id];
2023-06-19 20:28:30 +02:00
PANEL_INSPECTOR.setInspecting(node);
PANEL_GRAPH.nodes_selecting = [ node ];
2023-03-13 10:45:56 +01:00
}
}
} else
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _x0, _y, _x1 - _x0, hg, COLORS._main_icon_light, 1);
draw_sprite_stretched_add(THEME.ui_panel, 1, _x0, _y, _x1 - _x0, hg, c_white, .3);
2023-03-13 10:45:56 +01:00
var bw = ui(24);
var bh = ui(24);
var bx = _x1 - ui(4) - bw;
var by = _y + (hg - bh) / 2;
2023-06-04 18:28:29 +02:00
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_nodes.active, sc_nodes.hover, __txtx("panel_node_goto", "Go to node"), THEME.node_goto,, COLORS._main_icon, 0.75, 0.75) == 2)
2023-03-13 10:45:56 +01:00
graphFocusNode(node);
bx -= ui(32);
var _n = ALL_NODES[? instanceof(node)];
var spr = _n.spr;
draw_sprite_ui(spr, 1, _x0 + ui(4 + 16), _y + hg / 2, 0.25, 0.25, 0, c_white, 1);
2023-03-13 10:45:56 +01:00
var cc = COLORS._main_text;
draw_set_text(f_p1, fa_left, fa_center, cc);
draw_text(_x0 + hg + ui(8) + (isGroup * ui(20)), _y + hg / 2, name);
if(isGroup) draw_sprite_ui(THEME.arrow, (!node_collapse[? node.node_id]) * 3, _x0 + hg + ui(16), _y + hg / 2,,,,, 0.75);
2023-03-13 10:45:56 +01:00
_y += hg + ui(4);
_h += hg + ui(4);
if(isGroup && !node_collapse[? node.node_id]) {
var hh = drawNodeList(node.nodes, _x0 + ui(16), _x1, _y, _m);
_y += hh + ui(4);
_h += hh + ui(4);
}
}
return _h;
}
sc_nodes = new scrollPane(w - ui(padding + padding), h - ui(padding + padding + 40), function(_y, _m) {
2024-07-28 13:55:57 +02:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _h = drawNodeList(PROJECT.nodes, 0, sc_nodes.surface_w, _y, _m);
return _h;
});
2023-03-13 10:45:56 +01:00
function drawContent(panel) {
2023-06-10 13:59:45 +02:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2023-03-19 09:17:39 +01:00
2023-03-13 10:45:56 +01:00
var px = ui(padding);
var py = ui(padding);
2023-03-13 10:45:56 +01:00
var pw = w - ui(padding + padding);
var ph = h - ui(padding + padding);
2023-03-13 10:45:56 +01:00
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
2023-06-21 20:36:53 +02:00
tb_search.setFocusHover(pFOCUS, pHOVER);
2023-03-13 10:45:56 +01:00
tb_search.draw(px, py, pw, ui(32), search_string, [mx, my]);
2023-06-21 20:36:53 +02:00
sc_nodes.setFocusHover(pFOCUS, pHOVER);
2023-03-13 10:45:56 +01:00
sc_nodes.draw(px, py + ui(40), mx - px, my - (py + ui(40)));
}
}