Pixel-Composer/scripts/panel_nodes/panel_nodes.gml

119 lines
3.6 KiB
Plaintext
Raw Normal View History

2023-03-13 10:45:56 +01:00
function Panel_Nodes() : PanelContent() constructor {
#region data
2023-06-04 18:28:29 +02:00
title = __txt("Nodes");
2023-03-19 09:17:39 +01:00
showHeader = false;
2023-03-13 10:45:56 +01:00
w = ui(320);
h = ui(480);
2023-03-19 09:17:39 +01:00
title_height = 64;
padding = 24;
2023-03-13 10:45:56 +01:00
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();
#endregion
function onResize() {
2023-03-19 09:17:39 +01:00
sc_nodes.resize(w - ui(padding + padding), h - ui(padding + title_height + 40));
2023-03-13 10:45:56 +01:00
}
function drawNodeList(_list, _x0, _x1, _y, _m) {
var ww = sc_nodes.surface_w;
var hg = ui(28);
var _h = 0;
for( var i = 0; i < ds_list_size(_list); i++ ) {
var node = _list[| i];
var name = node.display_name == ""? node.name : node.display_name;
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)) {
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);
2023-03-13 10:45:56 +01:00
ds_list_clear(PANEL_GRAPH.nodes_select_list);
PANEL_GRAPH.node_focus = node;
}
}
} else
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _x0, _y, _x1 - _x0, hg, COLORS._main_icon_light, 1);
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.5, 0.5, 0, c_white, 0.75);
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);
_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;
}
#region content
2023-03-19 09:17:39 +01:00
sc_nodes = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding + 40), function(_y, _m) {
2023-03-13 10:45:56 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _h = drawNodeList(NODES, 0, sc_nodes.surface_w, _y, _m);
return _h;
})
#endregion
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
PANEL_PADDING
PANEL_TITLE
2023-03-13 10:45:56 +01:00
var px = ui(padding);
2023-03-19 09:17:39 +01:00
var py = ui(title_height);
2023-03-13 10:45:56 +01:00
var pw = w - ui(padding + padding);
2023-03-19 09:17:39 +01:00
var ph = h - ui(title_height + padding);
2023-03-13 10:45:56 +01:00
draw_sprite_stretched(THEME.ui_panel_bg, !in_dialog, 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)));
}
}