Pixel-Composer/scripts/node_group_input/node_group_input.gml

208 lines
5.7 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
function Node_create_Group_Input(_x, _y) {
if(!LOADING && !APPENDING && PANEL_GRAPH.getCurrentContext() == -1) return;
var node = new Node_Group_Input(_x, _y, PANEL_GRAPH.getCurrentContext());
ds_list_add(PANEL_GRAPH.nodes_list, node);
return node;
}
function Node_Group_Input(_x, _y, _group) : Node(_x, _y) constructor {
name = "Input";
color = c_ui_yellow;
previewable = false;
auto_height = false;
input_index = -1;
2022-01-18 05:31:19 +01:00
group = _group;
inParent = undefined;
2022-01-13 05:24:03 +01:00
w = 96;
h = 32 + 24;
min_h = h;
2022-01-13 05:24:03 +01:00
inputs[| 0] = nodeValue(0, "Display type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Default", "Range", "Enum Scroll", "Enum Button", "Rotation", "Rotation range",
2022-01-19 03:05:13 +01:00
"Slider", "Slider range", "Gradient", "Palette", "Padding", "Vector", "Vector range", "Area", "Curve" ]);
2022-01-13 05:24:03 +01:00
inputs[| 1] = nodeValue(1, "Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 1])
.setDisplay(VALUE_DISPLAY.vector)
2022-01-19 03:05:13 +01:00
.setVisible(false);
2022-01-13 05:24:03 +01:00
inputs[| 2] = nodeValue(2, "Input type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Integer", "Float", "Boolean", "Color", "Surface", "Path", "Curve", "Text", "Object", "Any" ]);
2022-01-13 05:24:03 +01:00
inputs[| 3] = nodeValue(3, "Enum label", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "")
2022-01-19 03:05:13 +01:00
.setVisible(false);
2022-01-13 05:24:03 +01:00
inputs[| 4] = nodeValue(4, "Vector size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "2", "3", "4" ])
2022-01-18 05:31:19 +01:00
.setVisible(false);
2022-01-19 03:05:13 +01:00
inputs[| 5] = nodeValue(5, "Order", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
2022-01-18 05:31:19 +01:00
input_display_list = [
2022-01-19 03:51:53 +01:00
["Display", false], 5,
["Data", false], 2, 0, 4, 1, 3,
2022-01-18 05:31:19 +01:00
];
2022-01-13 05:24:03 +01:00
outputs[| 0] = nodeValue(0, "Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
2022-01-18 05:31:19 +01:00
static onValueUpdate = function(index) {
if(is_undefined(inParent)) return;
2022-01-13 05:24:03 +01:00
var _dtype = inputs[| 0].getValue();
var _range = inputs[| 1].getValue();
var _val_type = inputs[| 2].getValue();
var _enum_label = inputs[| 3].getValue();
var _vec_size = inputs[| 4].getValue();
2022-01-17 12:10:30 +01:00
if(index == 2) {
var _o = outputs[| 0];
for(var j = 0; j < ds_list_size(_o.value_to); j++) {
var _to = _o.value_to[| j];
if(_to.value_from == _o)
_to.removeFrom();
}
}
2022-01-18 05:31:19 +01:00
inParent.type = _val_type;
2022-01-13 05:24:03 +01:00
outputs[| 0].type = _val_type;
2022-01-18 05:31:19 +01:00
var _val = inParent.getValue();
2022-01-13 05:24:03 +01:00
switch(_dtype) {
case VALUE_DISPLAY.range :
case VALUE_DISPLAY.slider :
2022-01-18 05:31:19 +01:00
inParent.setDisplay(_dtype, [_range[0], _range[1], 0.01]);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.slider_range :
2022-01-18 05:31:19 +01:00
inParent.setDisplay(_dtype, [_range[0], _range[1], 0.01]);
2022-01-13 05:24:03 +01:00
case VALUE_DISPLAY.rotation_range :
if(!is_array(_val) || array_length(_val) != 2)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0], inParent);
2022-01-19 06:11:17 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.enum_button :
case VALUE_DISPLAY.enum_scroll :
2022-01-18 05:31:19 +01:00
inParent.setDisplay(_dtype, string_splice(_enum_label, ","));
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.padding :
if(!is_array(_val) || array_length(_val) != 4)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0, 0, 0], inParent);
2022-01-19 06:11:17 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.area :
if(!is_array(_val) || array_length(_val) != 5)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0, 0, 0, 5], inParent);
2022-01-19 06:11:17 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.vector :
case VALUE_DISPLAY.vector_range :
switch(_vec_size) {
case 0 :
if(!is_array(_val) || array_length(_val) != 2)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0], inParent);
2022-01-13 05:24:03 +01:00
break;
case 1 :
if(!is_array(_val) || array_length(_val) != 3)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0, 0], inParent);
2022-01-13 05:24:03 +01:00
break;
case 2 :
if(!is_array(_val) || array_length(_val) != 4)
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([0, 0, 0, 0], inParent);
2022-01-13 05:24:03 +01:00
break;
}
2022-01-18 05:31:19 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.palette :
if(!is_array(_val))
2022-01-18 05:31:19 +01:00
inParent.value = new animValue([c_black], inParent);
2022-01-19 03:51:53 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
default :
2022-01-18 05:31:19 +01:00
inParent.setDisplay(_dtype);
2022-01-13 05:24:03 +01:00
break;
}
2022-01-18 05:31:19 +01:00
2022-01-19 06:11:17 +01:00
if(index == 5) {
group.sortIO();
}
2022-01-13 05:24:03 +01:00
}
static createInput = function(override_order = true) {
2022-01-18 05:31:19 +01:00
if(group && is_struct(group)) {
if(override_order) {
input_index = ds_list_size(group.inputs);
inputs[| 5].setValue(input_index);
} else {
input_index = inputs[| 5].getValue();
}
2022-01-18 05:31:19 +01:00
2022-01-19 03:05:13 +01:00
inParent = nodeValue(ds_list_size(group.inputs), "Value", group, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1)
.setVisible(true, true);
2022-01-18 05:31:19 +01:00
inParent.from = self;
ds_list_add(group.inputs, inParent);
outputs[| 0].setFrom(inParent, false, false);
group.setHeight();
group.sortIO();
onValueUpdate(0);
}
2022-01-13 05:24:03 +01:00
}
if(!LOADING && !APPENDING)
createInput();
dtype = -1;
range = 0;
2022-01-18 05:31:19 +01:00
static step = function() {
if(is_undefined(inParent)) return;
inParent.name = name;
}
static update = function() {
if(is_undefined(inParent)) return;
2022-01-13 05:24:03 +01:00
var _dtype = inputs[| 0].getValue();
2022-01-19 06:11:17 +01:00
inputs[| 1].setVisible(false);
inputs[| 3].setVisible(false);
inputs[| 4].setVisible(false);
2022-01-13 05:24:03 +01:00
switch(_dtype) {
case VALUE_DISPLAY.range :
case VALUE_DISPLAY.slider :
case VALUE_DISPLAY.slider_range :
2022-01-19 06:11:17 +01:00
inputs[| 1].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.enum_button :
case VALUE_DISPLAY.enum_scroll :
2022-01-19 06:11:17 +01:00
inputs[| 3].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.vector :
case VALUE_DISPLAY.vector_range :
2022-01-19 06:11:17 +01:00
inputs[| 4].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
}
}
2022-01-18 05:31:19 +01:00
static postDeserialize = function() {
createInput(false);
2022-01-13 05:24:03 +01:00
onValueUpdate(0);
}
2022-01-19 03:05:13 +01:00
static onDestroy = function() {
2022-01-18 05:31:19 +01:00
if(is_undefined(inParent)) return;
ds_list_remove(group.inputs, inParent);
2022-01-13 05:24:03 +01:00
}
}