Pixel-Composer/scripts/node_array_pin/node_array_pin.gml

113 lines
2.8 KiB
Text
Raw Normal View History

2024-07-07 12:55:27 +02:00
function Node_Array_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Array Pin";
setDimension(32, 32);
auto_height = false;
junction_shift_y = 16;
isHovering = false;
hover_scale = 0;
hover_scale_to = 0;
hover_alpha = 0;
bg_spr_add = 0;
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Array", self, VALUE_TYPE.any, []));
2024-07-07 12:55:27 +02:00
static createNewInput = function() {
2024-08-08 06:57:51 +02:00
var index = array_length(inputs);
2024-07-07 12:55:27 +02:00
2024-08-20 10:15:53 +02:00
newInput(index, nodeValue("Input", self, CONNECT_TYPE.input, VALUE_TYPE.any, -1 ))
2024-07-07 12:55:27 +02:00
.setVisible(true, true);
2024-08-08 06:57:51 +02:00
return inputs[index];
2024-07-07 12:55:27 +02:00
} setDynamicInput(1);
static update = function(frame = CURRENT_FRAME) {
var res = [];
var ind = 0;
2024-08-08 06:57:51 +02:00
for( var i = input_fix_len; i < array_length(inputs); i++ ) {
if(!inputs[i].value_from) continue;
2024-07-07 12:55:27 +02:00
var val = getInputData(i);
array_push(res, val);
2024-08-08 06:57:51 +02:00
inputs[ i].setType(inputs[i].value_from.type);
outputs[0].setType(inputs[i].value_from.type);
2024-07-07 12:55:27 +02:00
}
2024-08-08 06:57:51 +02:00
outputs[0].setValue(res);
2024-07-07 12:55:27 +02:00
}
static pointIn = function(_x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
return point_in_circle(_mx, _my, xx, yy, _s * 24);
}
static preDraw = function(_x, _y, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
2024-08-08 06:57:51 +02:00
for( var i = input_fix_len; i < array_length(inputs); i++ ) {
inputs[i].x = xx;
inputs[i].y = yy;
2024-07-07 12:55:27 +02:00
}
dummy_input.x = xx;
dummy_input.y = yy;
2024-08-08 06:57:51 +02:00
outputs[0].x = xx;
outputs[0].y = yy;
2024-07-07 12:55:27 +02:00
}
static drawBadge = function(_x, _y, _s) {}
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
2024-11-24 06:07:17 +01:00
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
2024-07-07 12:55:27 +02:00
var _dval = PANEL_GRAPH.value_dragging;
2024-08-20 10:15:53 +02:00
var hover = _dval == noone || _dval.connect_type == CONNECT_TYPE.input? outputs[0] : dummy_input;
2024-07-07 12:55:27 +02:00
var xx = x * _s + _x;
var yy = y * _s + _y;
isHovering = point_in_circle(_mx, _my, xx, yy, _s * 24);
2024-11-24 06:07:17 +01:00
var jhov = hover.drawJunction(_draw, _s, _mx, _my);
2024-07-07 12:55:27 +02:00
if(!isHovering) return noone;
hover_scale_to = 1;
return jhov? hover : noone;
}
2024-11-24 06:07:17 +01:00
static drawNode = function(_draw, _x, _y, _mx, _my, _s) {
2024-07-07 12:55:27 +02:00
var xx = x * _s + _x;
var yy = y * _s + _y;
hover_alpha = 0.5;
if(active_draw_index > -1) {
hover_alpha = 1;
hover_scale_to = 1;
active_draw_index = -1;
}
if(hover_scale > 0) {
var _r = hover_scale * _s * 16;
shader_set(sh_node_circle);
shader_set_color("color", COLORS._main_accent, hover_alpha);
draw_sprite_stretched(s_fx_pixel, 0, xx - _r, yy - _r, _r * 2, _r * 2);
shader_reset();
}
hover_scale = lerp_float(hover_scale, hover_scale_to, 3);
hover_scale_to = 0;
if(renamed && display_name != "" && display_name != "Array Pin") {
draw_set_text(f_sdf, fa_center, fa_bottom, COLORS._main_text);
draw_text_transformed(xx, yy - 12 * _s, display_name, _s * 0.4, _s * 0.4, 0);
}
2024-11-24 06:07:17 +01:00
return drawJunctions(_draw, _x, _y, _mx, _my, _s);
2024-07-07 12:55:27 +02:00
}
}