From df84505d510c4390a3d54fe06dba177d8ee91898 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 10 Jul 2024 14:17:14 +0700 Subject: [PATCH] - [L-system] Fix UI overlapping. --- scripts/node_line/node_line.gml | 14 ++++----- scripts/node_path_bake/node_path_bake.gml | 12 +++---- .../node_path_l_system/node_path_l_system.gml | 31 +++++++++++++------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/scripts/node_line/node_line.gml b/scripts/node_line/node_line.gml index 813d3709b..81967d472 100644 --- a/scripts/node_line/node_line.gml +++ b/scripts/node_line/node_line.gml @@ -223,17 +223,17 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _pathStr = _rtStr; var _pathEnd = _rtMax; - var _stepLen = min(_pathEnd, 1 / _seg); //Distance to move per step + var _stepLen = min(_pathEnd, 1 / _seg); // Distance to move per step if(_stepLen <= 0.00001) continue; - var _total = _pathEnd; //Length remaining - var _total_prev = _total; //Use to prevent infinite loop - var _freeze = 0; //Use to prevent infinite loop + var _total = _pathEnd; // Length remaining + var _total_prev = _total; // Use to prevent infinite loop + var _freeze = 0; // Use to prevent infinite loop - var _prog_curr = _clamp? _shift : frac(_shift); //Pointer to the current position + var _prog_curr = _clamp? _shift : frac(_shift); // Pointer to the current position var _prog_next = 0; - var _prog = _prog_curr + 1; //Record previous position to delete from _total - var _prog_total = 0; //Record the distance the pointer has moved so far + var _prog = _prog_curr + 1; // Record previous position to delete from _total + var _prog_total = 0; // Record the distance the pointer has moved so far var points = []; var pointAmo = 0; var wght; diff --git a/scripts/node_path_bake/node_path_bake.gml b/scripts/node_path_bake/node_path_bake.gml index 8afe617b0..3028b3b27 100644 --- a/scripts/node_path_bake/node_path_bake.gml +++ b/scripts/node_path_bake/node_path_bake.gml @@ -13,7 +13,7 @@ function Node_Path_Bake(_x, _y, _group = noone) : Node(_x, _y, _group) construct path_amount = 1; - 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) { var _path = getInputData(0); if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); @@ -36,9 +36,9 @@ function Node_Path_Bake(_x, _y, _group = noone) : Node(_x, _y, _group) construct oy = ny; } } - } #endregion + } - static update = function() { #region + static update = function() { var _path = getInputData(0); var _dist = getInputData(1); @@ -66,10 +66,10 @@ function Node_Path_Bake(_x, _y, _group = noone) : Node(_x, _y, _group) construct if(_amo == 1) _segs = _segs[0]; outputs[| 0].setValue(_segs); - } #endregion + } - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { var bbox = drawGetBbox(xx, yy, _s); draw_sprite_fit(THEME.node_draw_path, 0, bbox.xc, bbox.yc, bbox.w, bbox.h); - } #endregion + } } \ No newline at end of file diff --git a/scripts/node_path_l_system/node_path_l_system.gml b/scripts/node_path_l_system/node_path_l_system.gml index de1ccf2ad..df09db15a 100644 --- a/scripts/node_path_l_system/node_path_l_system.gml +++ b/scripts/node_path_l_system/node_path_l_system.gml @@ -1,11 +1,13 @@ -function L_Turtle(x = 0, y = 0, ang = 90, w = 1, color = c_white) constructor { +function L_Turtle(x = 0, y = 0, ang = 90, w = 1, color = c_white, itr = 0) constructor { self.x = x; self.y = y; self.ang = ang; self.w = w; self.color = color; - static clone = function() { return new L_Turtle(x, y, ang, w, color); } + self.itr = itr; + + static clone = function() { return new L_Turtle(x, y, ang, w, color, itr); } } function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { @@ -70,14 +72,15 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const draw_sprite_ui(THEME.arrow, 0, tx + _tw + ui(16), ty + _th / 2,,,, COLORS._main_icon); _rule.editWidget.setFocusHover(_focus, _hover); - _rule.editWidget.draw(tx + _tw + ui(32), ty, _w - (_tw + ui(8 + 24 + 32)), _th, _rule.showValue(), _m, _rule.display_type); + var wh = max(_th, _rule.editWidget.draw(tx + _tw + ui(32), ty, _w - (_tw + ui(8 + 24 + 32)), _th, _rule.showValue(), _m, _rule.display_type)); - ty += _th + ui(6); - hh += _th + ui(6); + ty += wh + ui(6); + hh += wh + ui(6); } return hh; - }, function(parent = noone) { + }, + function(parent = noone) { for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) { var _name = inputs[| i + 0]; var _rule = inputs[| i + 1]; @@ -292,6 +295,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const len = _len; st = ds_stack_create(); t = new L_Turtle(_pos[0], _pos[1], _san); + maxItr = 0; string_foreach(cache_data.result, function(_ch, _) { switch(_ch) { @@ -299,10 +303,13 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const var nx = t.x + lengthdir_x(len, t.ang); var ny = t.y + lengthdir_y(len, t.ang); - ds_queue_enqueue(lineq, [ [t.x, t.y, t.w], [nx, ny, t.w] ]); + ds_queue_enqueue(lineq, [ [ t.x, t.y, t.w, t.itr ], [ nx, ny, t.w, t.itr + 1 ] ]); t.x = nx; t.y = ny; + t.itr++; + maxItr = max(maxItr, t.itr); + break; case "G": @@ -314,10 +321,12 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const var nx = t.x + lengthdir_x(len * frac(itr), t.ang); var ny = t.y + lengthdir_y(len * frac(itr), t.ang); - ds_queue_enqueue(lineq, [ [t.x, t.y, t.w], [nx, ny, t.w] ]); + ds_queue_enqueue(lineq, [ [ t.x, t.y, t.w, t.itr ], [ nx, ny, t.w, t.itr + 1 ] ]); t.x = nx; t.y = ny; + t.itr++; + maxItr = max(maxItr, t.itr); break; case "+": t.ang += ang; break; @@ -333,7 +342,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const case ">": t.w += 0.1; break; case "<": t.w -= 0.1; break; - default : noti_warning($"L-system: Invalid rule '{_ch}'"); + // default : noti_warning($"L-system: Invalid rule '{_ch}'"); } }); @@ -343,9 +352,11 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const lines = array_create(ds_queue_size(lineq)); var i = 0; + var a = ds_queue_size(lineq); - while(!ds_queue_empty(lineq)) { + repeat(a) { var _l = ds_queue_dequeue(lineq); + lines[i++] = _l; boundary.addPoint(_l[0][0], _l[0][1], _l[1][0], _l[1][1]); }