- [Group] Fix node height not updating after duplicated.

This commit is contained in:
Tanasart 2024-07-17 08:48:04 +07:00
parent 268e26012a
commit 530c942ae0
3 changed files with 118 additions and 161 deletions

View File

@ -199,7 +199,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
input_dummy = nodeValue("Add to group", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0);
draw_dummy = false;
input_dummy.onSetFrom = function(juncFrom) { #region
input_dummy.onSetFrom = function(juncFrom) {
array_remove(juncFrom.value_to, input_dummy);
input_dummy.value_from = noone;
@ -214,18 +214,15 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
input.inParent.setFrom(juncFrom);
if(onNewInputFromGraph != noone) onNewInputFromGraph(juncFrom);
} #endregion
}
onNewInputFromGraph = noone;
tool_node = noone;
draw_input_overlay = true;
array_push(attributeEditors, ["Edit Input Display", function() { return 0; },
button(function() { dialogCall(o_dialog_group_input_order).setNode(self, JUNCTION_CONNECT.input); }) ]);
array_push(attributeEditors, ["Edit Output Display", function() { return 0; },
button(function() { dialogCall(o_dialog_group_input_order).setNode(self, JUNCTION_CONNECT.output); }) ]);
array_push(attributeEditors, ["Edit Input Display", function() /*=>*/ {return 0}, button(function() { dialogCall(o_dialog_group_input_order).setNode(self, JUNCTION_CONNECT.input); }) ]);
array_push(attributeEditors, ["Edit Output Display", function() /*=>*/ {return 0}, button(function() { dialogCall(o_dialog_group_input_order).setNode(self, JUNCTION_CONNECT.output); }) ]);
/////========== INSPECTOR ===========
@ -248,7 +245,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
/////============ GROUP =============
will_refresh = false;
static refreshNodes = function() { #region
static refreshNodes = function() {
will_refresh = false;
hasInsp1 = false;
@ -264,18 +261,10 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
i++;
}
} #endregion
}
static getNodeBase = function() { #region
if(instanceBase == noone) return self;
return instanceBase.getNodeBase();
} #endregion
static getNodeList = function() { #region
INLINE
if(instanceBase == noone) return nodes;
return instanceBase.getNodeList();
} #endregion
static getNodeBase = function() { return instanceBase == noone? self : instanceBase.getNodeBase(); }
static getNodeList = function() { return instanceBase == noone? nodes : instanceBase.getNodeList(); }
static exitGroup = function() {}
@ -321,25 +310,25 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
/////============= STEP ==============
static stepBegin = function() { #region
static stepBegin = function() {
if(will_refresh) refreshNodes();
doStepBegin();
} #endregion
}
static step = function() { #region
static step = function() {
if(combine_render_time) {
render_time = 0;
array_foreach(getNodeList(), function(node) { render_time += node.render_time; });
}
onStep();
} #endregion
}
static onStep = function() {}
/////========== JUNCTIONS ==========
static getOutputNodes = function() { #region
static getOutputNodes = function() {
var _nodes = [];
for( var i = custom_output_index; i < ds_list_size(outputs); i++ ) {
var _junc = outputs[| i];
@ -351,18 +340,16 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
}
return _nodes;
} #endregion
}
static getInput = function(_y = 0, junc = noone) { #region
return input_dummy;
} #endregion
static getInput = function(_y = 0, junc = noone) { return input_dummy; }
static preConnect = function() { #region
static preConnect = function() {
sortIO();
deserialize(load_map, load_scale);
} #endregion
}
static sortIO = function() { #region
static sortIO = function() {
var _ilen = ds_list_size(inputs);
var _iarr = attributes.input_display_list;
@ -393,20 +380,20 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
///////////////////////////////////////////////////////////////////
refreshNodeDisplay();
} #endregion
}
static preConnect = function() { #region
static preConnect = function() {
instanceBase = GetAppendID(struct_try_get(load_map, "instance_base", noone));
sortIO();
applyDeserialize();
} #endregion
}
/////========== RENDERING ===========
static getNextNodes = function() { return getNextNodesInternal(); }
static getNextNodesInternal = function() { #region //get node inside the group
static getNextNodesInternal = function() { //get node inside the group
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"→→→→→ Call get next node from group: {INAME}");
@ -429,9 +416,9 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
LOG_BLOCK_END();
return _nodes;
} #endregion
}
static getNextNodesExternal = function() { #region //get node connected to the parent object
static getNextNodesExternal = function() { //get node connected to the parent object
LOG_IF(global.FLAG.render == 1, $"Checking next node external for {INAME}");
LOG_BLOCK_START();
@ -455,11 +442,11 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
LOG_BLOCK_END();
return nextNodes;
} #endregion
}
static clearTopoSorted = function() { INLINE topoSorted = false; for( var i = 0, n = array_length(nodes); i < n; i++ ) { nodes[i].clearTopoSorted(); } }
static setRenderStatus = function(result) { #region
static setRenderStatus = function(result) {
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
rendered = result;
@ -483,9 +470,9 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
if(!result && group != noone)
group.setRenderStatus(result);
LOG_BLOCK_END();
} #endregion
}
static isActiveDynamic = function(frame = CURRENT_FRAME) { #region
static isActiveDynamic = function(frame = CURRENT_FRAME) {
if(update_on_frame) return true;
if(!rendered) return true;
@ -493,9 +480,9 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
if(inputs[| i].isActiveDynamic(frame) || !inputs[| i].from.rendered) return true;
return false;
} #endregion
}
static resetRender = function(_clearCache = false) { #region
static resetRender = function(_clearCache = false) {
LOG_LINE_IF(global.FLAG.render == 1, $"Reset Render for group {INAME}");
setRenderStatus(false);
@ -504,11 +491,11 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
if(reset_all_child)
for(var i = 0, n = array_length(nodes); i < n; i++)
nodes[i].resetRender(_clearCache);
} #endregion
}
/////============= DRAW =============
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(!draw_input_overlay) return;
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
@ -519,7 +506,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
var _hov = _in.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_hov != undefined) active &= !_hov;
}
} #endregion
}
static onPreDraw = function(_x, _y, _s, _iny, _outy) {
var xx = x * _s + _x;
@ -554,7 +541,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
panelSetContext(PANEL_GRAPH);
}
static onDrawJunctions = function(_x, _y, _mx, _my, _s) { #region
static onDrawJunctions = function(_x, _y, _mx, _my, _s) {
input_dummy.visible = false;
if(draw_dummy) {
@ -563,9 +550,9 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
draw_dummy = false;
} #endregion
}
static getTool = function() { #region
static getTool = function() {
for(var i = 0, n = array_length(nodes); i < n; i++) {
var _node = nodes[i];
if(!_node.active) continue;
@ -573,11 +560,11 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return self;
} #endregion
}
/////============ PREVIEW ============
static getGraphPreviewSurface = function() { #region
static getGraphPreviewSurface = function() {
var _output_junc = outputs[| preview_channel];
for( var i = 0, n = array_length(nodes); i < n; i++ ) {
@ -595,27 +582,27 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return noone;
} #endregion
}
/////============= CACHE =============
static clearCache = function() { #region
static clearCache = function() {
array_foreach(getNodeList(), function(node) { node.clearCache(); });
} #endregion
}
/////========== INSTANCING ===========
static setInstance = function(node) { #region
static setInstance = function(node) {
instanceBase = node;
} #endregion
}
static resetInstance = function() { #region
static resetInstance = function() {
instanceBase = noone;
} #endregion
}
/////========= SERIALIZATION =========
static attributeSerialize = function() { #region
static attributeSerialize = function() {
sortIO();
var _attr = variable_clone(attributes);
@ -633,12 +620,12 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return _attr;
} #endregion
}
static preApplyDeserialize = function() { #region
static preApplyDeserialize = function() {
var attr = attributes;
if(LOADING_VERSION < 11690) { #region
if(LOADING_VERSION < 11690) {
var pr = ds_priority_create();
for( var i = ds_list_size(inputs) - 1; i >= custom_input_index; i-- ) {
@ -663,7 +650,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
ds_priority_destroy(pr);
return;
} #endregion
}
if(struct_has(attr, "custom_input_list")) {
var _ilist = attr.custom_input_list;
@ -718,15 +705,15 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
} #endregion
}
static processSerialize = function(_map) { #region
static processSerialize = function(_map) {
_map.instance_base = instanceBase? instanceBase.node_id : noone;
} #endregion
}
/////============ ACTION ============
static onClone = function(_newNode, target = PANEL_GRAPH.getCurrentContext()) { #region
static onClone = function(_newNode, target = PANEL_GRAPH.getCurrentContext()) {
if(instanceBase != noone) {
_newNode.instanceBase = instanceBase;
return;
@ -750,19 +737,19 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
APPENDING = false;
ds_list_destroy(dups);
} #endregion
}
static enable = function() { #region
static enable = function() {
active = true;
array_foreach(getNodeList(), function(node) { node.enable(); });
} #endregion
}
static disable = function() { #region
static disable = function() {
active = false;
array_foreach(getNodeList(), function(node) { node.disable(); });
} #endregion
}
function onDoubleClick(panel) { #region
function onDoubleClick(panel) {
if(PREFERENCES.panel_graph_group_require_shift && !key_mod_press(SHIFT)) return false;
panelSetContext(panel);
@ -771,7 +758,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
ononDoubleClick(panel);
return true;
} #endregion
}
static panelSetContext = function(panel) {
__temp_panel = panel;
@ -784,14 +771,14 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
static ononDoubleClick = noone;
static enable = function() { #region
static enable = function() {
active = true; timeline_item.active = true;
for( var i = 0, n = array_length(nodes); i < n; i++ ) nodes[i].enable();
} #endregion
}
static disable = function() { #region
static disable = function() {
active = false; timeline_item.active = false;
for( var i = 0, n = array_length(nodes); i < n; i++ ) nodes[i].disable();
} #endregion
}
}

View File

@ -1,59 +1,43 @@
function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Group Output";
color = COLORS.node_blend_collection;
is_group_io = true;
name = "Group Output";
color = COLORS.node_blend_collection;
is_group_io = true;
destroy_when_upgroup = true;
setDimension(96, 32 + 24);
inputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1)
.uncache()
.setVisible(true, true);
inputs[| 0].onSetFrom = function(juncFrom) /*=>*/ { if(attributes.inherit_name && !LOADING && !APPENDING) setDisplayName(juncFrom.name); }
attributes.inherit_name = true;
outParent = undefined;
output_index = -1;
outParent = undefined;
output_index = -1;
onSetDisplayName = function() { attributes.inherit_name = false; }
onSetDisplayName = function() /*=>*/ { attributes.inherit_name = false; }
inputs[| 0].onSetFrom = function(juncFrom) {
if(attributes.inherit_name && !LOADING && !APPENDING)
setDisplayName(juncFrom.name);
}
static setRenderStatus = function(result) { #region
static setRenderStatus = function(result) {
if(rendered == result) return;
LOG_LINE_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
rendered = result;
if(group) group.setRenderStatus(result);
} #endregion
}
static onValueUpdate = function(index = 0) { #region
if(is_undefined(outParent)) return;
} #endregion
static onValueUpdate = function(index = 0) { if(is_undefined(outParent)) return; }
static getNextNodes = function() { #region
static getNextNodes = function() {
if(is_undefined(outParent)) return [];
LOG_BLOCK_START();
var nodes = [];
for(var j = 0; j < array_length(outParent.value_to); j++) {
var _to = outParent.value_to[j];
if(!_to.node.isRenderActive()) continue;
//printIf(global.FLAG.render, "Value to " + _to.name);
if(!_to.node.active || _to.value_from == noone) {
//printIf(global.FLAG.render, "no value from");
continue;
}
if(_to.value_from.node != group) {
//printIf(global.FLAG.render, "value from not equal group");
continue;
}
//printIf(global.FLAG.render, "Group output ready " + string(_to.node.isRenderable()));
if(!_to.node.isRenderActive()) continue;
if(!_to.node.active || _to.value_from == noone) continue;
if(_to.value_from.node != group) continue;
array_push(nodes, _to.node);
LOG_IF(global.FLAG.render == 1, $"Check complete, push {_to.node.internalName} to queue.");
@ -61,60 +45,55 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr
LOG_BLOCK_END();
return nodes;
} #endregion
}
static createOutput = function() { #region
static createOutput = function() {
if(group == noone) return;
if(!is_struct(group)) return;
if(!is_undefined(outParent))
ds_list_remove(group.outputs, outParent);
if(!is_undefined(outParent)) ds_list_remove(group.outputs, outParent);
outParent = nodeValue("Value", group, JUNCTION_CONNECT.output, VALUE_TYPE.any, -1)
.uncache()
.setVisible(true, true);
outParent.from = self;
ds_list_add(group.outputs, outParent);
if(!LOADING && !APPENDING) {
group.refreshNodeDisplay();
group.sortIO();
group.setHeight();
}
outParent.setFrom(inputs[| 0]);
} if(!LOADING && !APPENDING) createOutput(); #endregion
} if(!LOADING && !APPENDING) createOutput();
static step = function() { #region
static step = function() {
if(is_undefined(outParent)) return;
outParent.name = display_name;
inputs[| 0].setType(VALUE_TYPE.any);
if(inputs[| 0].value_from != noone) {
inputs[| 0].setType(inputs[| 0].value_from.type);
inputs[| 0].display_type = inputs[| 0].value_from.display_type;
}
var _in0 = inputs[| 0];
var _pty = _in0.type;
var _typ = _in0.value_from == noone? VALUE_TYPE.any : _in0.value_from.type;
var _dis = _in0.value_from == noone? VALUE_DISPLAY._default : _in0.value_from.display_type;
outParent.setType(inputs[| 0].type);
outParent.display_type = inputs[| 0].display_type;
} #endregion
static getGraphPreviewSurface = function() { #region
return inputs[| 0].getValue();
} #endregion
static postDeserialize = function() { #region
if(group == noone) return;
_in0.setType(_typ);
_in0.display_type = _dis;
createOutput(false);
} #endregion
static doApplyDeserialize = function() { #region
outParent.setType(_in0.type);
outParent.display_type = _in0.display_type;
} #endregion
if(group && _pty != _typ) group.setHeight();
}
static onDestroy = function() { #region
static getGraphPreviewSurface = function() { return inputs[| 0].getValue(); }
static postDeserialize = function() { if(group == noone) return; createOutput(false); }
static doApplyDeserialize = function() {}
static onDestroy = function() {
if(is_undefined(outParent)) return;
ds_list_remove(group.outputs, outParent);
@ -126,9 +105,9 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr
for (var i = 0, n = array_length(_tos); i < n; i++)
_tos[i].removeFrom();
} #endregion
}
static onUngroup = function() { #region
static onUngroup = function() {
var fr = inputs[| 0].value_from;
for( var i = 0; i < array_length(outParent.value_to); i++ ) {
@ -137,9 +116,7 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr
to.setFrom(fr);
}
} #endregion
}
static onLoadGroup = function() { #region
if(group == noone) destroy();
} #endregion
static onLoadGroup = function() { if(group == noone) destroy(); }
}

View File

@ -237,7 +237,7 @@ function NodeObject(_name, _spr, _node, _create, tooltip = "", tags = []) constr
#macro NODE_ADD_CAT if(!IS_CMD) addNodeCatagory
#endregion
function nodeBuild(_name, _x, _y, _group = PANEL_GRAPH.getCurrentContext()) { #region
function nodeBuild(_name, _x, _y, _group = PANEL_GRAPH.getCurrentContext()) {
INLINE
if(!ds_map_exists(ALL_NODES, _name)) {
@ -245,11 +245,13 @@ function nodeBuild(_name, _x, _y, _group = PANEL_GRAPH.getCurrentContext()) { #r
return noone;
}
var _node = ALL_NODES[? _name];
return _node.build(_x, _y, _group);
} #endregion
var _node = ALL_NODES[? _name];
var _bnode = _node.build(_x, _y, _group);
function addNodeObject(_list, _name, _spr, _node, _fun, _tag = [], tooltip = "") { #region
return _bnode;
}
function addNodeObject(_list, _name, _spr, _node, _fun, _tag = [], tooltip = "") {
if(ds_map_exists(ALL_NODES, _node)) {
var _n = ALL_NODES[? _node];
ds_list_add(_list, _n);
@ -261,20 +263,11 @@ function addNodeObject(_list, _name, _spr, _node, _fun, _tag = [], tooltip = "")
ds_list_add(_list, _n);
return _n;
} #endregion
}
function addNodeCatagory(name, list, filter = [], color = noone) { #region
global.__currPage = name;
ds_list_add(NODE_CATEGORY, { name, list, filter, color });
} #endregion
function addNodePBCatagory(name, list, filter = []) { #region
ds_list_add(NODE_PB_CATEGORY, { name: name, list: list, filter: filter });
} #endregion
function addNodePCXCatagory(name, list, filter = []) { #region
ds_list_add(NODE_PCX_CATEGORY, { name: name, list: list, filter: filter });
} #endregion
function addNodeCatagory( name, list, filter = [], color = noone) { global.__currPage = name; ds_list_add(NODE_CATEGORY, { name, list, filter, color }); }
function addNodePBCatagory( name, list, filter = []) { ds_list_add(NODE_PB_CATEGORY, { name, list, filter }); }
function addNodePCXCatagory( name, list, filter = []) { ds_list_add(NODE_PCX_CATEGORY, { name, list, filter }); }
function __initNodes() {
global.__currPage = "";