Pixel-Composer/scripts/node_group_input/node_group_input.gml

425 lines
12 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-19 13:49:20 +01:00
name = "Group Input";
2022-12-10 05:06:01 +01:00
color = COLORS.node_blend_collection;
2023-12-05 13:49:18 +01:00
preview_draw = false;
is_group_io = true;
2022-01-13 05:24:03 +01:00
2023-12-05 13:49:18 +01:00
destroy_when_upgroup = true;
2022-01-18 05:31:19 +01:00
inParent = undefined;
2024-03-28 14:18:02 +01:00
setDimension(96, 32 + 24);
2022-01-13 05:24:03 +01:00
2023-09-11 16:08:58 +02:00
#region data
2023-06-13 14:42:06 +02:00
data_type_list = [ "Integer", "Float", "Boolean", "Color", "Surface",
"File Path", "Curve", "Text", "Object", "Node",
2023-11-27 11:40:28 +01:00
-1, "Any", "Path", "Particle", "Rigidbody Object",
"Domain", "Struct", "Strands", "Mesh", "Trigger",
-1, "3D Mesh", "3D Light", "3D Scene", "3D Material",
-1, "Audio"
2023-06-13 14:42:06 +02:00
];
2023-11-27 11:40:28 +01:00
data_type_map = [ VALUE_TYPE.integer, VALUE_TYPE.float, VALUE_TYPE.boolean, VALUE_TYPE.color, VALUE_TYPE.surface,
VALUE_TYPE.path, VALUE_TYPE.curve, VALUE_TYPE.text, VALUE_TYPE.object, VALUE_TYPE.node,
noone, VALUE_TYPE.any, VALUE_TYPE.pathnode, VALUE_TYPE.particle, VALUE_TYPE.rigid,
2023-12-29 14:30:54 +01:00
VALUE_TYPE.sdomain, VALUE_TYPE.struct, VALUE_TYPE.strands, VALUE_TYPE.mesh, VALUE_TYPE.trigger,
2023-11-27 11:40:28 +01:00
noone, VALUE_TYPE.d3Mesh, VALUE_TYPE.d3Light, VALUE_TYPE.d3Scene, VALUE_TYPE.d3Material,
noone, VALUE_TYPE.audioBit,
2023-06-13 14:42:06 +02:00
];
2022-12-23 04:45:52 +01:00
display_list = [
/*Integer*/ [ "Default", "Range", "Rotation", "Rotation range", "Slider", "Slider range", "Padding", "Vector", "Vector range", "Area", "Enum button", "Menu scroll" ],
/*Float*/ [ "Default", "Range", "Rotation", "Rotation range", "Slider", "Slider range", "Padding", "Vector", "Vector range", "Area" ],
2023-11-27 11:40:28 +01:00
/*Boolean*/ 0,
2022-12-23 04:45:52 +01:00
/*Color*/ [ "Default", "Gradient", "Palette" ],
2023-11-27 11:40:28 +01:00
/*Surface*/ 0,
2023-10-03 11:27:36 +02:00
2023-11-27 11:40:28 +01:00
/*Path*/ 0,
2023-10-07 09:09:18 +02:00
/*Curve*/ [ "Curve", ],
2023-11-27 11:40:28 +01:00
/*Text*/ 0,
/*Object*/ 0,
/*Node*/ 0,
2023-10-03 11:27:36 +02:00
2023-11-27 11:40:28 +01:00
/*3D*/ 0,
/*Any*/ 0,
/*Pathnode*/0,
/*Particle*/0,
/*Rigid*/ 0,
2023-10-03 11:27:36 +02:00
2023-11-27 11:40:28 +01:00
/*Fdomain*/ 0,
/*Struct*/ 0,
/*Strand*/ 0,
/*Mesh*/ 0,
/*Trigger*/ 0,
/*noone*/ 0,
/*3D Mesh*/ 0,
/*3D Light*/ 0,
/*3D Scene*/ 0,
/*3D Material*/ 0,
/*noone*/ 0,
/*Audio*/ 0,
2023-03-19 09:17:39 +01:00
];
2023-09-11 16:08:58 +02:00
#endregion
2022-12-23 04:45:52 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Display type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2024-04-11 15:43:03 +02:00
.setDisplay(VALUE_DISPLAY.enum_scroll, { data: display_list[0], update_hover: false });
2022-01-13 05:24:03 +01:00
2024-04-11 15:43:03 +02:00
inputs[| 1] = nodeValue("Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
.setDisplay(VALUE_DISPLAY.range)
2024-04-11 15:43:03 +02:00
.setVisible(false);
2022-01-13 05:24:03 +01:00
2023-10-07 09:09:18 +02:00
inputs[| 2] = nodeValue("Input type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 11)
2024-04-11 15:43:03 +02:00
.setDisplay(VALUE_DISPLAY.enum_scroll, { data: data_type_list, update_hover: false });
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Enum label", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "")
2024-04-11 15:43:03 +02:00
.setVisible(false);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Vector size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "2", "3", "4" ])
2024-04-11 15:43:03 +02:00
.setVisible(false);
2022-01-18 05:31:19 +01:00
2024-04-11 15:43:03 +02:00
inputs[| 5] = nodeValue("Order", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
2023-01-01 02:06:02 +01:00
2024-04-11 15:43:03 +02:00
inputs[| 6] = nodeValue("Display preview gizmo", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
2023-03-08 07:35:51 +01:00
inputs[| 7] = nodeValue("Step", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.01)
2024-04-11 15:43:03 +02:00
.setVisible(false);
2023-06-13 14:42:06 +02:00
inputs[| 8] = nodeValue("Button Label", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "Trigger")
2024-04-11 15:43:03 +02:00
.setVisible(false);
for( var i = 0, n = ds_list_size(inputs); i < n; i++ )
inputs[| i].uncache().rejectArray();
2023-03-08 07:35:51 +01:00
2022-01-18 05:31:19 +01:00
input_display_list = [
2023-09-11 16:08:58 +02:00
["Display", false], 6,
2023-06-13 14:42:06 +02:00
["Data", false], 2, 0, 4, 1, 7, 3, 8,
2022-01-18 05:31:19 +01:00
];
2022-01-13 05:24:03 +01:00
2023-07-25 20:12:40 +02:00
outputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0)
.uncache();
2022-01-13 05:24:03 +01:00
2023-12-03 05:02:04 +01:00
attributes.inherit_name = true;
attributes.inherit_type = true;
2023-06-13 14:42:06 +02:00
doTrigger = 0;
2023-12-03 05:02:04 +01:00
onSetDisplayName = function() { attributes.inherit_name = false; }
2023-06-13 14:42:06 +02:00
2023-10-07 09:09:18 +02:00
outputs[| 0].onSetTo = function(juncTo) {
2024-04-03 09:40:37 +02:00
if(attributes.inherit_name && !LOADING && !APPENDING)
2023-12-03 05:02:04 +01:00
setDisplayName(juncTo.name);
2023-10-07 09:09:18 +02:00
if(!attributes.inherit_type) return;
attributes.inherit_type = false;
var ind = array_find(data_type_map, juncTo.type);
if(ind == -1) return;
if(ind == inputs[| 2].getValue()) return;
2023-10-07 16:23:40 +02:00
outputs[| 0].setType(juncTo.type);
2023-10-07 09:09:18 +02:00
inputs[| 2].setValue(ind);
}
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
2023-01-25 06:49:00 +01:00
if(inParent.isArray()) return;
2024-03-14 14:35:19 +01:00
return inParent.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2023-09-11 16:08:58 +02:00
} #endregion
2023-01-01 02:06:02 +01:00
2023-09-11 16:08:58 +02:00
static onValueUpdate = function(index = 0) { #region
2022-01-18 05:31:19 +01:00
if(is_undefined(inParent)) return;
var _dtype = getInputData(0);
var _range = getInputData(1);
var _type = getInputData(2);
2024-03-31 05:36:11 +02:00
var _val_type = array_safe_get_fast(data_type_map, _type, VALUE_TYPE.any);
var _enum_label = getInputData(3);
var _vec_size = getInputData(4);
var _step = getInputData(7);
2022-01-13 05:24:03 +01:00
2022-01-17 12:10:30 +01:00
if(index == 2) {
2023-10-07 09:09:18 +02:00
if(outputs[| 0].type != _val_type) {
var _o = outputs[| 0];
2023-12-19 14:30:34 +01:00
for(var j = 0; j < array_length(_o.value_to); j++) {
var _to = _o.value_to[j];
2023-10-07 09:09:18 +02:00
if(_to.value_from == _o)
_to.removeFrom();
}
2022-01-17 12:10:30 +01:00
}
2022-12-23 04:45:52 +01:00
inputs[| 0].setValue(0);
2023-10-07 09:09:18 +02:00
attributes.inherit_type = false;
2022-01-17 12:10:30 +01:00
}
2024-03-31 05:36:11 +02:00
_dtype = array_safe_get_fast(array_safe_get_fast(display_list, _val_type), _dtype);
2022-12-23 04:45:52 +01:00
2023-10-07 16:23:40 +02:00
inParent.setType(_val_type);
outputs[| 0].setType(_val_type);
2022-01-18 05:31:19 +01:00
var _val = inParent.getValue();
2022-01-13 05:24:03 +01:00
switch(_dtype) {
2023-03-08 07:35:51 +01:00
case "Range" :
2023-11-17 06:24:31 +01:00
if(!is_array(_val) || array_length(_val) != 2)
inParent.animator = new valueAnimator([0, 0], inParent);
inParent.def_val = [0, 0];
2023-03-08 07:35:51 +01:00
inParent.setDisplay(VALUE_DISPLAY.range);
break;
2022-12-23 04:45:52 +01:00
2023-03-08 07:35:51 +01:00
case "Slider" :
2023-11-17 06:24:31 +01:00
if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent);
inParent.def_val = 0;
inParent.setDisplay(VALUE_DISPLAY.slider, { range: [_range[0], _range[1], _step] });
2023-03-08 07:35:51 +01:00
break;
case "Slider range" :
if(!is_array(_val) || array_length(_val) != 2)
inParent.animator = new valueAnimator([0, 0], inParent);
inParent.def_val = [0, 0];
inParent.setDisplay(VALUE_DISPLAY.slider_range, { range: [_range[0], _range[1], _step] });
2023-03-08 07:35:51 +01:00
break;
case "Rotation" :
2023-11-17 06:24:31 +01:00
if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent);
inParent.def_val = 0;
2023-03-08 07:35:51 +01:00
inParent.setDisplay(VALUE_DISPLAY.rotation);
break;
2022-12-12 09:08:03 +01:00
2022-12-23 04:45:52 +01:00
case "Rotation range" :
2022-01-13 05:24:03 +01:00
if(!is_array(_val) || array_length(_val) != 2)
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([0, 0], inParent);
inParent.def_val = [0, 0];
2022-12-23 04:45:52 +01:00
inParent.setDisplay(VALUE_DISPLAY.rotation_range);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
case "Padding" :
2022-01-13 05:24:03 +01:00
if(!is_array(_val) || array_length(_val) != 4)
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([0, 0, 0, 0], inParent);
inParent.def_val = [0, 0, 0, 0];
2022-12-23 04:45:52 +01:00
inParent.setDisplay(VALUE_DISPLAY.padding);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
case "Area" :
2022-01-13 05:24:03 +01:00
if(!is_array(_val) || array_length(_val) != 5)
inParent.animator = new valueAnimator(DEF_AREA, inParent);
inParent.def_val = array_clone(DEF_AREA);
2022-12-23 04:45:52 +01:00
inParent.setDisplay(VALUE_DISPLAY.area);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
case "Vector" :
case "Vector range" :
2022-01-13 05:24:03 +01:00
switch(_vec_size) {
case 0 :
if(!is_array(_val) || array_length(_val) != 2)
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([0, 0], inParent);
inParent.def_val = [0, 0];
2022-01-13 05:24:03 +01:00
break;
case 1 :
if(!is_array(_val) || array_length(_val) != 3)
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([0, 0, 0], inParent);
inParent.def_val = [0, 0, 0];
2022-01-13 05:24:03 +01:00
break;
case 2 :
if(!is_array(_val) || array_length(_val) != 4)
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([0, 0, 0, 0], inParent);
inParent.def_val = [0, 0, 0, 0];
2022-01-13 05:24:03 +01:00
break;
}
2022-12-23 04:45:52 +01:00
if(_dtype == "Vector") inParent.setDisplay(VALUE_DISPLAY.vector);
else if(_dtype == "Vector range") inParent.setDisplay(VALUE_DISPLAY.vector_range);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
2023-11-17 06:24:31 +01:00
case "Enum button" :
if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent);
inParent.def_val = 0;
2023-11-17 06:24:31 +01:00
inParent.setDisplay(VALUE_DISPLAY.enum_button, string_splice(_enum_label, ","));
break;
case "Menu scroll" :
if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent);
inParent.def_val = 0;
2023-11-17 06:24:31 +01:00
inParent.setDisplay(VALUE_DISPLAY.enum_scroll, string_splice(_enum_label, ","));
break;
2022-12-23 04:45:52 +01:00
case "Palette" :
2022-01-13 05:24:03 +01:00
if(!is_array(_val))
2022-09-23 13:28:42 +02:00
inParent.animator = new valueAnimator([c_black], inParent);
inParent.def_val = [c_black];
2022-12-23 04:45:52 +01:00
inParent.setDisplay(VALUE_DISPLAY.palette);
2022-01-13 05:24:03 +01:00
break;
2023-06-13 14:42:06 +02:00
case "Gradient":
2023-10-07 16:23:40 +02:00
inParent.setType(VALUE_TYPE.gradient);
outputs[| 0].setType(inParent.type);
2023-05-28 20:00:51 +02:00
2023-03-02 07:59:14 +01:00
inParent.animator = new valueAnimator(new gradientObject(c_white), inParent);
inParent.def_val = new gradientObject(c_white);
2023-05-28 20:00:51 +02:00
inParent.setDisplay(VALUE_DISPLAY._default);
2023-02-14 05:32:32 +01:00
break;
2023-06-13 14:42:06 +02:00
2023-10-07 09:09:18 +02:00
case "Curve":
inParent.animator = new valueAnimator(CURVE_DEF_11, inParent);
inParent.def_val = array_clone(CURVE_DEF_11);
2023-10-07 09:09:18 +02:00
inParent.setDisplay(VALUE_DISPLAY.curve);
break;
2023-06-13 14:42:06 +02:00
default:
2023-11-17 06:24:31 +01:00
if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent);
inParent.def_val = 0;
2023-06-13 14:42:06 +02:00
inParent.setDisplay(VALUE_DISPLAY._default);
break;
}
switch(_val_type) {
case VALUE_TYPE.trigger :
var bname = getInputData(8);
inParent.setDisplay(VALUE_DISPLAY.button, { name: bname, onClick: function() { doTrigger = 1; } });
2023-06-13 14:42:06 +02:00
break;
2022-01-13 05:24:03 +01:00
}
2023-09-11 16:08:58 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-28 04:07:43 +02:00
static createInput = function() { #region
2022-09-27 06:37:28 +02:00
if(group == noone || !is_struct(group)) return noone;
2023-10-28 04:07:43 +02:00
2023-02-14 05:32:32 +01:00
if(!is_undefined(inParent))
ds_list_remove(group.inputs, inParent);
inParent = nodeValue("Value", group, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1)
2023-07-25 20:12:40 +02:00
.uncache()
2022-09-27 06:37:28 +02:00
.setVisible(true, true);
inParent.from = self;
2023-06-01 10:32:21 +02:00
2022-09-27 06:37:28 +02:00
ds_list_add(group.inputs, inParent);
outputs[| 0].setFrom(inParent, false, false);
if(!LOADING && !APPENDING) {
group.refreshNodeDisplay();
group.sortIO();
}
2022-09-27 06:37:28 +02:00
onValueUpdate(0);
return inParent;
2023-09-11 16:08:58 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2022-12-21 02:30:23 +01:00
if(!LOADING && !APPENDING) createInput();
2022-01-13 05:24:03 +01:00
dtype = -1;
range = 0;
2023-09-11 16:08:58 +02:00
static step = function() { #region
2022-01-18 05:31:19 +01:00
if(is_undefined(inParent)) return;
2023-10-03 11:27:36 +02:00
var _type = getInputData(2);
2024-03-31 05:36:11 +02:00
var _val_type = array_safe_get_fast(data_type_map, _type, VALUE_TYPE.any);
var _dsList = array_safe_get_fast(display_list, _val_type);
2023-11-27 11:40:28 +01:00
if(_dsList == 0) _dsList = [ "Default" ];
inputs[| 0].display_data.data = _dsList;
inputs[| 0].editWidget.data_list = _dsList;
2023-10-03 11:27:36 +02:00
2023-04-15 14:48:29 +02:00
if(inParent.name != display_name) {
inParent.name = display_name;
group.inputMap[? string_replace_all(display_name, " ", "_")] = inParent;
}
2023-06-13 14:42:06 +02:00
if(inParent.type == VALUE_TYPE.trigger) {
if(doTrigger == 1) {
outputs[| 0].setValue(true);
doTrigger = -1;
} else if(doTrigger == -1) {
outputs[| 0].setValue(false);
doTrigger = 0;
}
}
2022-01-13 05:24:03 +01:00
var _dstype = getInputData(0);
2023-10-03 11:27:36 +02:00
var _data = getInputData(2);
2024-03-31 05:36:11 +02:00
var _dsList = array_safe_get_fast(display_list, _data);
_dstype = _dsList == 0? "Default" : array_safe_get_fast(_dsList, _dstype);
2023-06-13 14:42:06 +02:00
2024-03-31 05:36:11 +02:00
var _datype = array_safe_get_fast(data_type_map, _data, VALUE_TYPE.any);
2022-01-13 05:24:03 +01:00
2022-01-19 06:11:17 +01:00
inputs[| 1].setVisible(false);
inputs[| 3].setVisible(false);
inputs[| 4].setVisible(false);
2023-03-08 07:35:51 +01:00
inputs[| 7].setVisible(false);
2023-06-13 14:42:06 +02:00
inputs[| 8].setVisible(_datype == VALUE_TYPE.trigger);
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
switch(_dstype) {
2022-12-23 04:45:52 +01:00
case "Slider" :
case "Slider range" :
2023-03-08 07:35:51 +01:00
inputs[| 7].setVisible(true);
case "Range" :
2022-01-19 06:11:17 +01:00
inputs[| 1].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
case "Enum button" :
case "Menu scroll" :
2022-01-19 06:11:17 +01:00
inputs[| 3].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
2022-12-23 04:45:52 +01:00
case "Vector" :
case "Vector range" :
2022-01-19 06:11:17 +01:00
inputs[| 4].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
}
2023-09-11 16:08:58 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
2023-10-03 11:27:36 +02:00
if(is_undefined(inParent)) return;
2023-09-11 16:08:58 +02:00
} #endregion
2022-12-21 02:30:23 +01:00
2024-04-02 14:33:25 +02:00
static getGraphPreviewSurface = function() { #region
return inputs[| 0].getValue();
} #endregion
2023-10-03 11:27:36 +02:00
static postDeserialize = function() { createInput(false); }
2023-10-18 14:58:55 +02:00
static doApplyDeserialize = function() { #region
if(inParent == undefined) return;
if(group == noone) return;
2023-01-17 08:11:55 +01:00
inParent.name = name;
2023-10-03 11:27:36 +02:00
getInputs();
onValueUpdate();
2023-10-20 12:32:43 +02:00
2023-10-03 11:27:36 +02:00
group.sortIO();
2023-10-18 14:58:55 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-09-11 16:08:58 +02:00
static onDestroy = function() { #region
2022-01-18 05:31:19 +01:00
if(is_undefined(inParent)) return;
2022-01-18 05:31:19 +01:00
ds_list_remove(group.inputs, inParent);
group.sortIO();
group.refreshNodes();
2023-09-11 16:08:58 +02:00
} #endregion
2023-02-14 05:32:32 +01:00
2024-05-22 12:13:46 +02:00
static onUngroup = function() { #region
2023-02-14 05:32:32 +01:00
var fr = inParent.value_from;
2023-12-19 14:30:34 +01:00
for( var i = 0; i < array_length(outputs[| 0].value_to); i++ ) {
var to = outputs[| 0].value_to[i];
2023-02-14 05:32:32 +01:00
if(to.value_from != outputs[| 0]) continue;
to.setFrom(fr);
}
2023-09-11 16:08:58 +02:00
} #endregion
2023-10-18 14:58:55 +02:00
static onLoadGroup = function() { #region
2024-04-08 07:13:46 +02:00
if(group == noone) destroy();
2023-10-18 14:58:55 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
}