2023-03-12 02:28:21 +01:00
|
|
|
function Panel_Tunnels() : PanelContent() constructor {
|
2024-07-29 11:15:56 +02:00
|
|
|
title = __txt("Tunnels");
|
|
|
|
padding = 8;
|
2024-08-13 13:17:45 +02:00
|
|
|
|
|
|
|
w = ui(320);
|
|
|
|
h = ui(480);
|
|
|
|
|
|
|
|
build_x = 0;
|
|
|
|
build_y = 0;
|
|
|
|
|
|
|
|
tunnel_ins = [];
|
|
|
|
tunnel_select = noone;
|
|
|
|
tunnel_hover = noone;
|
|
|
|
|
|
|
|
function scanNodes() {
|
2023-03-12 02:28:21 +01:00
|
|
|
tunnel_ins = [];
|
|
|
|
|
2024-08-13 13:17:45 +02:00
|
|
|
for (var i = 0, n = array_length(PROJECT.allNodes); i < n; i++) {
|
|
|
|
var node = PROJECT.allNodes[i];
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-08-13 13:17:45 +02:00
|
|
|
if(instanceof(node) == "Node_Tunnel_In")
|
|
|
|
array_push(tunnel_ins, node);
|
2023-03-12 02:28:21 +01:00
|
|
|
}
|
2024-08-13 13:17:45 +02:00
|
|
|
}
|
|
|
|
scanNodes();
|
|
|
|
|
|
|
|
search_string = "";
|
|
|
|
keyboard_lastchar = "";
|
|
|
|
keyboard_lastkey = -1;
|
|
|
|
KEYBOARD_STRING = "";
|
|
|
|
|
|
|
|
search_res = [];
|
|
|
|
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) {
|
|
|
|
search_string = string(str);
|
|
|
|
searchNodes();
|
|
|
|
});
|
|
|
|
|
|
|
|
tb_search.align = fa_left;
|
|
|
|
tb_search.auto_update = true;
|
|
|
|
tb_search.boxColor = COLORS._main_icon_light;
|
|
|
|
WIDGET_CURRENT = tb_search;
|
|
|
|
|
|
|
|
function searchNodes() {
|
|
|
|
search_res = [];
|
|
|
|
for( var i = 0, n = array_length(tunnel_ins); i < n; i++ ) {
|
|
|
|
var node = tunnel_ins[i];
|
|
|
|
var key = node.inputs[0].getValue(0);
|
|
|
|
|
|
|
|
if(string_pos(search_string, key) == 0) continue;
|
|
|
|
array_push(search_res, node);
|
2023-03-12 02:28:21 +01:00
|
|
|
}
|
2024-08-13 13:17:45 +02:00
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-09-13 08:25:00 +02:00
|
|
|
function onResize() { sc_tunnel.resize(w - ui(padding + padding), h - ui(padding + padding) - ui(28 + 40)); }
|
2024-07-29 11:15:56 +02:00
|
|
|
|
2024-09-13 08:25:00 +02:00
|
|
|
sc_tunnel = new scrollPane(w - ui(padding + padding), h - ui(padding + padding) - ui(28 + 40), function(_y, _m) {
|
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear_inner, 1);
|
2024-07-29 11:15:56 +02:00
|
|
|
var _h = 0;
|
|
|
|
var ww = sc_tunnel.surface_w;
|
|
|
|
var hg = ui(36);
|
|
|
|
var i = 0;
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
var arr = search_string == ""? tunnel_ins : search_res;
|
|
|
|
tunnel_hover = noone;
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(arr); i < n; i++ ) {
|
|
|
|
var node = arr[i];
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + hg)) {
|
|
|
|
sc_tunnel.hover_content = true;
|
|
|
|
var cc = merge_color(COLORS._main_icon_light, COLORS._main_icon, 0.25);
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, cc, 1);
|
|
|
|
tunnel_hover = node;
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
if(mouse_press(mb_left, sc_tunnel.active) && _m[0] < ww - ui(32 + 32 * 2))
|
|
|
|
tunnel_select = tunnel_select == node? noone : node;
|
|
|
|
} else
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, COLORS._main_icon_light, 1);
|
2024-09-13 08:25:00 +02:00
|
|
|
draw_sprite_stretched_add(THEME.ui_panel, 1, 0, _y, ww, hg, c_white, .1);
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var key = node.inputs[0].getValue(0);
|
2024-07-29 11:15:56 +02:00
|
|
|
var bw = ui(28);
|
|
|
|
var bh = ui(28);
|
|
|
|
var bx = ww - ui(4) - bw;
|
|
|
|
var by = _y + (hg - bh) / 2;
|
|
|
|
|
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_node_goto", "Go to node"), THEME.node_goto) == 2)
|
|
|
|
graphFocusNode(node);
|
|
|
|
bx -= ui(32);
|
|
|
|
|
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_tunnel_create_tunnel", "Create tunnel out"), THEME.tunnel) == 2) {
|
2024-12-01 12:42:45 +01:00
|
|
|
var _node = nodeBuild("Node_Tunnel_Out", build_x, build_y - 8);
|
2024-08-08 06:57:51 +02:00
|
|
|
_node.inputs[0].setValue(key);
|
2024-07-29 11:15:56 +02:00
|
|
|
|
|
|
|
if(in_dialog) instance_destroy();
|
|
|
|
}
|
|
|
|
bx -= ui(32);
|
|
|
|
|
|
|
|
draw_sprite_ui(THEME.tunnel, 1, ui(4 + 16), _y + hg / 2);
|
2024-09-13 08:25:00 +02:00
|
|
|
draw_set_text(f_p2, fa_left, fa_center, key == ""? COLORS._main_text_sub : COLORS._main_text);
|
|
|
|
draw_text_add(ui(4 + 32 + 4), _y + hg / 2, key == ""? $"[{__txtx("panel_tunnel_no_key", "No key")}]" : key);
|
2024-07-29 11:15:56 +02:00
|
|
|
|
|
|
|
_y += hg + ui(4);
|
|
|
|
_h += hg + ui(4);
|
|
|
|
|
|
|
|
if(tunnel_select == node) {
|
2024-09-13 08:25:00 +02:00
|
|
|
var amo = ds_map_size(PROJECT.tunnels_out);
|
|
|
|
var k = ds_map_find_first(PROJECT.tunnels_out);
|
2024-07-29 11:15:56 +02:00
|
|
|
|
|
|
|
repeat(amo) {
|
|
|
|
var _k = k;
|
2024-09-13 08:25:00 +02:00
|
|
|
k = ds_map_find_next(PROJECT.tunnels_out, k);
|
2024-07-29 11:15:56 +02:00
|
|
|
|
2024-09-13 08:25:00 +02:00
|
|
|
var out = PROJECT.tunnels_out[? _k];
|
2024-07-29 11:15:56 +02:00
|
|
|
if(out != key || !ds_map_exists(PROJECT.nodeMap, _k))
|
|
|
|
continue;
|
2024-09-13 08:25:00 +02:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
var _node = PROJECT.nodeMap[? _k];
|
2024-09-13 08:25:00 +02:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
draw_sprite_ui(THEME.tunnel, 0, ui(32), _y + ui(10), 0.75, 0.75, 0, COLORS._main_icon);
|
2024-09-13 08:25:00 +02:00
|
|
|
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text_sub);
|
|
|
|
draw_text_add(ui(32 + 16), _y + ui(10), _node.renamed? _node.display_name : _node.name);
|
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + ui(20)))
|
|
|
|
tunnel_hover = _node;
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
_y += ui(20);
|
|
|
|
_h += ui(20);
|
2023-03-12 02:28:21 +01:00
|
|
|
}
|
2024-07-29 11:15:56 +02:00
|
|
|
|
|
|
|
_y += ui(8);
|
|
|
|
_h += ui(8);
|
2023-03-12 02:28:21 +01:00
|
|
|
}
|
2024-07-29 11:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return _h;
|
|
|
|
});
|
|
|
|
|
2023-03-12 02:28:21 +01:00
|
|
|
function drawContent(panel) {
|
2023-06-10 13:59:45 +02:00
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
2023-03-12 02:28:21 +01:00
|
|
|
scanNodes();
|
|
|
|
|
|
|
|
var px = ui(padding);
|
2024-07-29 11:15:56 +02:00
|
|
|
var py = ui(padding);
|
2023-03-12 02:28:21 +01:00
|
|
|
var pw = w - ui(padding + padding);
|
2024-07-29 11:15:56 +02:00
|
|
|
var ph = h - ui(padding + padding) - ui(28);
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2023-11-13 05:38:37 +01:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
|
2024-07-29 11:15:56 +02:00
|
|
|
|
2024-09-13 08:25:00 +02:00
|
|
|
tb_search.setFocusHover(pFOCUS, pHOVER);
|
2023-03-12 02:28:21 +01:00
|
|
|
tb_search.draw(px, py, pw, ui(32), search_string, [mx, my]);
|
2024-07-29 11:15:56 +02:00
|
|
|
if(search_string == "") tb_search.sprite_index = 1;
|
2023-03-12 02:28:21 +01:00
|
|
|
|
2023-06-21 20:36:53 +02:00
|
|
|
sc_tunnel.setFocusHover(pFOCUS, pHOVER);
|
2023-03-12 02:28:21 +01:00
|
|
|
sc_tunnel.draw(px, py + ui(40), mx - px, my - (py + ui(40)));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-07-29 11:15:56 +02:00
|
|
|
var _add_h = ui(24);
|
|
|
|
var _bx = 0;
|
|
|
|
var _by = h - _add_h;
|
|
|
|
var _ww = w;
|
|
|
|
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _bx + _ww, _by + _add_h);
|
|
|
|
|
2024-08-06 04:30:00 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel, 0, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel, 1, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
|
2024-07-29 11:15:56 +02:00
|
|
|
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
|
|
|
|
draw_text_add(_ww / 2, _by + _add_h / 2, __txtx("panel_tunnel_create_tunnel", "Create tunnel"));
|
|
|
|
|
|
|
|
if(mouse_press(mb_left, pFOCUS && _hov))
|
2024-12-01 12:42:45 +01:00
|
|
|
nodeBuild("Node_Tunnel_In", build_x, build_y - 8);
|
2023-03-12 02:28:21 +01:00
|
|
|
}
|
|
|
|
}
|