From 993463204a491e2b873b94e06c10e70e9f26d0f3 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 3 Jul 2024 10:16:46 +0700 Subject: [PATCH] - [UI] Fix error when closing panel. --- scripts/array_functions/array_functions.gml | 4 +- scripts/node_collection/node_collection.gml | 407 ++++++++++-------- scripts/node_data/node_data.gml | 7 + .../node_group_output/node_group_output.gml | 6 + scripts/node_image/node_image.gml | 4 + scripts/node_image_gif/node_image_gif.gml | 5 + scripts/node_svg/node_svg.gml | 4 + scripts/panel_data/panel_data.gml | 290 +++++++------ scripts/panel_function/panel_function.gml | 47 +- scripts/panel_graph/panel_graph.gml | 2 + scripts/panel_inspector/panel_inspector.gml | 4 + scripts/panel_preview/panel_preview.gml | 6 +- 12 files changed, 433 insertions(+), 353 deletions(-) diff --git a/scripts/array_functions/array_functions.gml b/scripts/array_functions/array_functions.gml index 99567e782..2e1ba1b6d 100644 --- a/scripts/array_functions/array_functions.gml +++ b/scripts/array_functions/array_functions.gml @@ -145,9 +145,7 @@ function array_find(arr, val) { #region self.__temp_val = val; if(!is_array(arr)) return -1; - return array_find_index(arr, function(_val, _ind) { - return isEqual(_val, self.__temp_val); - }); + return array_find_index(arr, function(_val, _ind) { return isEqual(_val, self.__temp_val); }); } #endregion function array_find_string(arr, val) { #region diff --git a/scripts/node_collection/node_collection.gml b/scripts/node_collection/node_collection.gml index 1e5785d90..9371e89f6 100644 --- a/scripts/node_collection/node_collection.gml +++ b/scripts/node_collection/node_collection.gml @@ -225,6 +225,8 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc array_push(attributeEditors, ["Edit Output Display", function() { return 0; }, button(function() { dialogCall(o_dialog_group_input_order).setNode(self, JUNCTION_CONNECT.output); }) ]); + /////========== INSPECTOR =========== + hasInsp1 = false; insp1UpdateTooltip = __txtx("panel_inspector_execute", "Execute node contents"); insp1UpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ]; @@ -241,6 +243,8 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc static onInspector2Update = function() { array_foreach(NodeListSort(nodes), function(n) { if(n.hasInspector2Update()) n.inspector2Update(); }); } static hasInspector2Update = function() { INLINE return hasInsp2; } + /////============ GROUP ============= + will_refresh = false; static refreshNodes = function() { #region will_refresh = false; @@ -271,19 +275,68 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc return instanceBase.getNodeList(); } #endregion - static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region - if(!draw_input_overlay) return; + static exitGroup = function() {} + + static onAdd = function(_node) {} + static add = function(_node) { + array_push(getNodeList(), _node); + var list = _node.group == noone? PANEL_GRAPH.nodes_list : _node.group.getNodeList(); + array_remove(list, _node); - for(var i = custom_input_index; i < ds_list_size(inputs); i++) { - var _in = inputs[| i]; - var _show = _in.from.getInputData(6); + recordAction(ACTION_TYPE.group_added, self, _node); + _node.group = self; + + will_refresh = true; + node_length = array_length(nodes); + + onAdd(_node); + } + + static onRemove = function(_node) {} + static remove = function(_node) { + var _hide = _node.destroy_when_upgroup; + + if(!_hide) { + var node_list = getNodeList(); + var list = group == noone? PANEL_GRAPH.nodes_list : group.getNodeList(); - if(!_show) continue; - var _hov = _in.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); - if(_hov != undefined) active &= !_hov; + array_remove(node_list, _node); + array_push(list, _node); } + + recordAction(ACTION_TYPE.group_removed, self, _node); + + if(struct_has(_node, "onUngroup")) + _node.onUngroup(); + + if(_hide) _node.disable(); + else _node.group = group; + + will_refresh = true; + node_length = array_length(nodes); + onRemove(_node); + } + + /////============= STEP ============== + + static stepBegin = function() { #region + if(will_refresh) refreshNodes(); + doStepBegin(); } #endregion + static step = function() { #region + 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 var _nodes = []; for( var i = custom_output_index; i < ds_list_size(outputs); i++ ) { @@ -302,6 +355,53 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc return input_dummy; } #endregion + static preConnect = function() { #region + sortIO(); + deserialize(load_map, load_scale); + } #endregion + + static sortIO = function() { #region + var _ilen = ds_list_size(inputs); + var _iarr = attributes.input_display_list; + + for( var i = custom_input_index; i < _ilen; i++ ) + array_push_unique(_iarr, i); + + for( var i = array_length(_iarr) - 1; i >= 0; i-- ) { + if(is_array(_iarr[i])) continue; + if(_iarr[i] >= _ilen) array_delete(_iarr, i, 1); + } + + input_display_list = array_merge(group_input_display_list, attributes.input_display_list); + + /////////////////////////////////////////////////////////////////// + + var _olen = ds_list_size(outputs); + var _oarr = attributes.output_display_list; + + for( var i = custom_output_index; i < _olen; i++ ) + array_push_unique(_oarr, i); + for( var i = array_length(_oarr) - 1; i >= 0; i-- ) { + if(is_array(_oarr[i])) continue; + if(_oarr[i] >= _olen) array_delete(_oarr, i, 1); + } + + output_display_list = array_merge(group_output_display_list, attributes.output_display_list); + + /////////////////////////////////////////////////////////////////// + + refreshNodeDisplay(); + } #endregion + + static preConnect = function() { #region + 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 @@ -393,68 +493,32 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc return false; } #endregion - static exitGroup = function() {} + static resetRender = function(_clearCache = false) { #region + LOG_LINE_IF(global.FLAG.render == 1, $"Reset Render for group {INAME}"); + + setRenderStatus(false); + if(_clearCache) clearInputCache(); + + if(reset_all_child) + for(var i = 0, n = array_length(nodes); i < n; i++) + nodes[i].resetRender(_clearCache); + } #endregion - static onAdd = function(_node) {} - static add = function(_node) { - array_push(getNodeList(), _node); - var list = _node.group == noone? PANEL_GRAPH.nodes_list : _node.group.getNodeList(); - array_remove(list, _node); - - recordAction(ACTION_TYPE.group_added, self, _node); - _node.group = self; - - will_refresh = true; - node_length = array_length(nodes); - - onAdd(_node); - } + /////============= DRAW ============= - static onRemove = function(_node) {} - static remove = function(_node) { - var _hide = _node.destroy_when_upgroup; + static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region + if(!draw_input_overlay) return; - if(!_hide) { - var node_list = getNodeList(); - var list = group == noone? PANEL_GRAPH.nodes_list : group.getNodeList(); + for(var i = custom_input_index; i < ds_list_size(inputs); i++) { + var _in = inputs[| i]; + var _show = _in.from.getInputData(6); - array_remove(node_list, _node); - array_push(list, _node); + if(!_show) continue; + var _hov = _in.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); + if(_hov != undefined) active &= !_hov; } - - recordAction(ACTION_TYPE.group_removed, self, _node); - - if(struct_has(_node, "onUngroup")) - _node.onUngroup(); - - if(_hide) _node.disable(); - else _node.group = group; - - will_refresh = true; - node_length = array_length(nodes); - onRemove(_node); - } - - static clearCache = function() { #region - array_foreach(getNodeList(), function(node) { node.clearCache(); }); } #endregion - static stepBegin = function() { #region - if(will_refresh) refreshNodes(); - doStepBegin(); - } #endregion - - static step = function() { #region - if(combine_render_time) { - render_time = 0; - array_foreach(getNodeList(), function(node) { render_time += node.render_time; }); - } - - onStep(); - } #endregion - - static onStep = function() {} - static onPreDraw = function(_x, _y, _s, _iny, _outy) { var xx = x * _s + _x; var yy = y * _s + _y; @@ -473,10 +537,22 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, getColor(), _aa); } - static preConnect = function() { #region - sortIO(); - deserialize(load_map, load_scale); - } #endregion + static drawNodeOverlay = function(xx, yy, _mx, _my, _s) { + if(_s < 0.75) return; + + var _bx = xx + w * _s - 10; + var _by = yy + h * _s - 10; + + var _hv = PANEL_GRAPH.pHOVER && PANEL_GRAPH.node_hovering == self; + _hv &= point_in_circle(_mx, _my, _bx, _by, 8); + + BLEND_ADD + draw_sprite_ext(THEME.animate_node_go, 0, _bx, _by, 1, 1, 0, getColor(), 0.2 + _hv * 0.3); + BLEND_NORMAL + + if(_hv && PANEL_GRAPH.pFOCUS && mouse_press(mb_left)) + panelSetContext(PANEL_GRAPH); + } static onDrawJunctions = function(_x, _y, _mx, _my, _s) { #region input_dummy.visible = false; @@ -489,39 +565,6 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc draw_dummy = false; } #endregion - static sortIO = function() { #region - var _ilen = ds_list_size(inputs); - var _iarr = attributes.input_display_list; - - for( var i = custom_input_index; i < _ilen; i++ ) - array_push_unique(_iarr, i); - - for( var i = array_length(_iarr) - 1; i >= 0; i-- ) { - if(is_array(_iarr[i])) continue; - if(_iarr[i] >= _ilen) array_delete(_iarr, i, 1); - } - - input_display_list = array_merge(group_input_display_list, attributes.input_display_list); - - /////////////////////////////////////////////////////////////////// - - var _olen = ds_list_size(outputs); - var _oarr = attributes.output_display_list; - - for( var i = custom_output_index; i < _olen; i++ ) - array_push_unique(_oarr, i); - for( var i = array_length(_oarr) - 1; i >= 0; i-- ) { - if(is_array(_oarr[i])) continue; - if(_oarr[i] >= _olen) array_delete(_oarr, i, 1); - } - - output_display_list = array_merge(group_output_display_list, attributes.output_display_list); - - /////////////////////////////////////////////////////////////////// - - refreshNodeDisplay(); - } #endregion - static getTool = function() { #region for(var i = 0, n = array_length(nodes); i < n; i++) { var _node = nodes[i]; @@ -532,78 +575,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc return self; } #endregion - static onClone = function(_newNode, target = PANEL_GRAPH.getCurrentContext()) { #region - if(instanceBase != noone) { - _newNode.instanceBase = instanceBase; - return; - } - - var dups = ds_list_create(); - - for(var i = 0, n = array_length(nodes); i < n; i++) { - var _node = nodes[i]; - var _cnode = _node.clone(target); - ds_list_add(dups, _cnode); - - APPEND_MAP[? _node.node_id] = _cnode.node_id; - } - - APPENDING = true; - for(var i = 0; i < ds_list_size(dups); i++) { - var _node = dups[| i]; - _node.connect(); - } - APPENDING = false; - - ds_list_destroy(dups); - } #endregion - - static enable = function() { #region - active = true; - array_foreach(getNodeList(), function(node) { node.enable(); }); - } #endregion - - static disable = function() { #region - active = false; - array_foreach(getNodeList(), function(node) { node.disable(); }); - } #endregion - - static resetRender = function(_clearCache = false) { #region - LOG_LINE_IF(global.FLAG.render == 1, $"Reset Render for group {INAME}"); - - setRenderStatus(false); - if(_clearCache) clearInputCache(); - - if(reset_all_child) - for(var i = 0, n = array_length(nodes); i < n; i++) - nodes[i].resetRender(_clearCache); - } #endregion - - static setInstance = function(node) { #region - instanceBase = node; - } #endregion - - static resetInstance = function() { #region - instanceBase = noone; - } #endregion - - function onDoubleClick(panel) { #region - if(PREFERENCES.panel_graph_group_require_shift && !key_mod_press(SHIFT)) return false; - - __temp_panel = panel; - - if(PREFERENCES.graph_open_group_in_tab) - run_in(1, function() { __temp_panel.openGroupTab(self) }); - else - panel.addContext(self); - - if(ononDoubleClick != noone) - ononDoubleClick(panel); - - return true; - } #endregion - - static ononDoubleClick = noone; + /////============ PREVIEW ============ static getGraphPreviewSurface = function() { #region var _output_junc = outputs[| preview_channel]; @@ -625,16 +597,24 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc return noone; } #endregion - static enable = function() { #region - active = true; timeline_item.active = true; - for( var i = 0, n = array_length(nodes); i < n; i++ ) nodes[i].enable(); + /////============= CACHE ============= + + static clearCache = function() { #region + array_foreach(getNodeList(), function(node) { node.clearCache(); }); } #endregion - static disable = function() { #region - active = false; timeline_item.active = false; - for( var i = 0, n = array_length(nodes); i < n; i++ ) nodes[i].disable(); + /////========== INSTANCING =========== + + static setInstance = function(node) { #region + instanceBase = node; } #endregion + static resetInstance = function() { #region + instanceBase = noone; + } #endregion + + /////========= SERIALIZATION ========= + static attributeSerialize = function() { #region sortIO(); @@ -744,11 +724,74 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc _map.instance_base = instanceBase? instanceBase.node_id : noone; } #endregion - static preConnect = function() { #region - instanceBase = GetAppendID(struct_try_get(load_map, "instance_base", noone)); + /////============ ACTION ============ + + static onClone = function(_newNode, target = PANEL_GRAPH.getCurrentContext()) { #region + if(instanceBase != noone) { + _newNode.instanceBase = instanceBase; + return; + } - sortIO(); - applyDeserialize(); + var dups = ds_list_create(); + + for(var i = 0, n = array_length(nodes); i < n; i++) { + var _node = nodes[i]; + var _cnode = _node.clone(target); + ds_list_add(dups, _cnode); + + APPEND_MAP[? _node.node_id] = _cnode.node_id; + } + + APPENDING = true; + for(var i = 0; i < ds_list_size(dups); i++) { + var _node = dups[| i]; + _node.connect(); + } + APPENDING = false; + + ds_list_destroy(dups); + } #endregion + + static enable = function() { #region + active = true; + array_foreach(getNodeList(), function(node) { node.enable(); }); + } #endregion + + static disable = function() { #region + active = false; + array_foreach(getNodeList(), function(node) { node.disable(); }); + } #endregion + + function onDoubleClick(panel) { #region + if(PREFERENCES.panel_graph_group_require_shift && !key_mod_press(SHIFT)) return false; + + panelSetContext(panel); + + if(ononDoubleClick != noone) + ononDoubleClick(panel); + + return true; + } #endregion + + static panelSetContext = function(panel) { + __temp_panel = panel; + + if(PREFERENCES.graph_open_group_in_tab) + run_in(1, function() { __temp_panel.openGroupTab(self) }); + else + panel.addContext(self); + } + + static ononDoubleClick = noone; + + static enable = function() { #region + 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 + active = false; timeline_item.active = false; + for( var i = 0, n = array_length(nodes); i < n; i++ ) nodes[i].disable(); } #endregion } \ No newline at end of file diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index f3c03bdcb..4eb5f2f78 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -1167,6 +1167,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { static drawNodeBase = function(xx, yy, _s) { INLINE draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, getColor(), (.25 + .5 * renderActive) * (.25 + .75 * isHighlightingInGraph())); } + static drawNodeOverlay = function(xx, yy, _mx, _my, _s) {} + __draw_bbox = BBOX(); static drawGetBbox = function(xx, yy, _s) { #region var pad_label = draw_name && display_parameter.avoid_label; @@ -1699,6 +1701,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { if(bg_spr_add > 0) draw_sprite_stretched_add(bg_spr, 1, xx, yy, w * _s, h * _s, bg_spr_add_clr, bg_spr_add); + drawNodeOverlay(xx, yy, _mx, _my, _s); + return _s > 0.5? drawJunctions(xx, yy, _mx, _my, _s) : drawJunctions_fast(xx, yy, _mx, _my, _s); } #endregion @@ -2219,8 +2223,11 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { /////=========== CLEAN UP =========== static cleanUp = function() { #region + if(ds_exists(inputs, ds_type_list)) for( var i = 0; i < ds_list_size(inputs); i++ ) inputs[| i].cleanUp(); + + if(ds_exists(outputs, ds_type_list)) for( var i = 0; i < ds_list_size(outputs); i++ ) outputs[| i].cleanUp(); diff --git a/scripts/node_group_output/node_group_output.gml b/scripts/node_group_output/node_group_output.gml index ac09f4a77..4b5658bbf 100644 --- a/scripts/node_group_output/node_group_output.gml +++ b/scripts/node_group_output/node_group_output.gml @@ -120,6 +120,12 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr ds_list_remove(group.outputs, outParent); group.sortIO(); group.refreshNodes(); + + var _tos = outParent.getJunctionTo(); + + for (var i = 0, n = array_length(_tos); i < n; i++) + _tos[i].removeFrom(); + } #endregion static onUngroup = function() { #region diff --git a/scripts/node_image/node_image.gml b/scripts/node_image/node_image.gml index 36f2ecf97..6f8ad12dd 100644 --- a/scripts/node_image/node_image.gml +++ b/scripts/node_image/node_image.gml @@ -159,4 +159,8 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { #endregion } #endregion + + static dropPath = function(path) { + inputs[| 0].setValue(path); + } } \ No newline at end of file diff --git a/scripts/node_image_gif/node_image_gif.gml b/scripts/node_image_gif/node_image_gif.gml index cb505ef7a..482dc6d3e 100644 --- a/scripts/node_image_gif/node_image_gif.gml +++ b/scripts/node_image_gif/node_image_gif.gml @@ -232,6 +232,10 @@ function Node_Image_gif(_x, _y, _group = noone) : Node(_x, _y, _group) construct static onDestroy = function() { #region if(sprite_exists(spr)) sprite_flush(spr); } #endregion + + static dropPath = function(path) { + inputs[| 0].setValue(path); + } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -268,4 +272,5 @@ function timelineItemNode_Image_gif(node) : timelineItemNode(node) constructor { static onSerialize = function(_map) { _map.type = "timelineItemNode_Image_gif"; } + } \ No newline at end of file diff --git a/scripts/node_svg/node_svg.gml b/scripts/node_svg/node_svg.gml index cdd7960b3..82944db96 100644 --- a/scripts/node_svg/node_svg.gml +++ b/scripts/node_svg/node_svg.gml @@ -114,4 +114,8 @@ function Node_SVG(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { outputs[| 0].setValue(_outsurf); outputs[| 1].setValue(rawContent); } + + static dropPath = function(path) { + inputs[| 0].setValue(path); + } } \ No newline at end of file diff --git a/scripts/panel_data/panel_data.gml b/scripts/panel_data/panel_data.gml index 7c76253de..afef46019 100644 --- a/scripts/panel_data/panel_data.gml +++ b/scripts/panel_data/panel_data.gml @@ -6,14 +6,14 @@ enum ANCHOR { right = 8 } -function Panel(_parent, _x, _y, _w, _h) constructor { #region +function Panel(_parent, _x, _y, _w, _h) constructor { parent = _parent; - if(parent) ds_list_add(parent.childs, self); + if(parent) array_push(parent.childs, self); padding = THEME_VALUE.panel_margin; content = []; content_index = 0; - childs = ds_list_create(); + childs = []; anchor = ANCHOR.none; x = _x; @@ -53,25 +53,33 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region draw_droppable = false; - border_rb_close = menuItem(__txt("Close"), function() { #region + border_rb_close = menuItem(__txt("Close"), function() { var con = getContent(); if(con == noone) return; con.close(); - }, THEME.cross); #endregion + }, THEME.cross); - border_rb_menu = [ #region + border_rb_menu = [ menuItem(__txt("Move"), function() { extract(); panel_mouse = 1; }), menuItem(__txtx("panel_pop_out", "Pop out"), function() { popWindow(); }, THEME.node_goto), border_rb_close - ]; #endregion + ]; static getContent = function() { return array_safe_get_fast(content, content_index, noone); } static hasContent = function() { return bool(array_length(content)); } - function resetMask() { #region + function replacePanel(panel) { + setContent(panel.content); + childs = panel.childs; + split = panel.split; + + refreshSize(); + } + + function resetMask() { var tab = array_length(content) > 1; tx = x; ty = y + tab * ui(tab_height); tw = w; th = h - tab * ui(tab_height); @@ -84,29 +92,29 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region draw_sprite_stretched(THEME.ui_panel_bg, 0, padding, padding, tw - padding * 2, th - padding * 2); gpu_set_blendmode(bm_normal); surface_reset_target(); - } resetMask(); #endregion + } resetMask(); - function setPadding(padding) { #region + function setPadding(padding) { self.padding = padding; refresh(); - } #endregion + } - function refresh() { #region + function refresh() { resetMask(); for( var i = 0, n = array_length(content); i < n; i++ ) content[i].refresh(); - for( var i = 0; i < ds_list_size(childs); i++ ) - childs[| i].refresh(); - } #endregion + for( var i = 0; i < array_length(childs); i++ ) + childs[i].refresh(); + } - function move(dx, dy) { #region + function move(dx, dy) { x += dx; y += dy; - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; _panel.move(dx, dy); } @@ -114,9 +122,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region content[i].x = x; content[i].y = y; } - } #endregion + } - function resizable(dw, dh, oppose = ANCHOR.left) { #region + function resizable(dw, dh, oppose = ANCHOR.left) { var tab = array_length(content) > 1; tx = x; ty = y + tab * ui(tab_height); tw = w; th = h - tab * ui(tab_height); @@ -130,16 +138,16 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region return res; } - var _c0 = ds_list_get(childs, 0, noone); - var _c1 = ds_list_get(childs, 1, noone); + var _c0 = array_safe_get(childs, 0, noone); + var _c1 = array_safe_get(childs, 1, noone); if(_c0 == noone || _c1 == noone) return false; var ind = hori? _c1.w > _c0.w : _c1.h > _c0.h; - return childs[| ind].resizable(dw, dh, oppose); - } #endregion + return childs[ind].resizable(dw, dh, oppose); + } - function refreshSize(recur = true) { #region //refresh content surface after resize + function refreshSize(recur = true) { //refresh content surface after resize //__debug_counter("refresh size"); var tab = array_length(content) > 1; tx = x; ty = y + tab * ui(tab_height); @@ -151,67 +159,67 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region content[i].onResize(); } - if(ds_list_size(childs) == 2) { + if(array_length(childs) == 2) { //print("=== Refreshing (" + string(w) + ", " + string(h) + ") " + string(split) + " ==="); - var _tw = childs[| 0].w + childs[| 1].w; - var _th = childs[| 0].h + childs[| 1].h; + var _tw = childs[0].w + childs[1].w; + var _th = childs[0].h + childs[1].h; - var fixChild = split == "h"? childs[| 1].x < childs[| 0].x : childs[| 1].y < childs[| 0].y; + var fixChild = split == "h"? childs[1].x < childs[0].x : childs[1].y < childs[0].y; - childs[| fixChild].x = x; - childs[| fixChild].y = y; + childs[fixChild].x = x; + childs[fixChild].y = y; if(split == "h") { - childs[| fixChild].w = round(childs[| fixChild].w / _tw * w); - childs[| fixChild].h = round(h); + childs[ fixChild].w = round(childs[fixChild].w / _tw * w); + childs[ fixChild].h = round(h); - childs[| !fixChild].x = x + childs[| fixChild].w; - childs[| !fixChild].y = y; + childs[!fixChild].x = x + childs[fixChild].w; + childs[!fixChild].y = y; - childs[| !fixChild].w = round(w - childs[| fixChild].w); - childs[| !fixChild].h = round(h); + childs[!fixChild].w = round(w - childs[fixChild].w); + childs[!fixChild].h = round(h); - childs[| fixChild].anchor = ANCHOR.left; - childs[| !fixChild].anchor = ANCHOR.right; + childs[ fixChild].anchor = ANCHOR.left; + childs[!fixChild].anchor = ANCHOR.right; } else if(split == "v") { - childs[| fixChild].w = round(w); - childs[| fixChild].h = round(childs[| fixChild].h / _th * h); + childs[ fixChild].w = round(w); + childs[ fixChild].h = round(childs[fixChild].h / _th * h); - childs[| !fixChild].x = x; - childs[| !fixChild].y = y + childs[| fixChild].h; + childs[!fixChild].x = x; + childs[!fixChild].y = y + childs[fixChild].h; - childs[| !fixChild].w = round(w); - childs[| !fixChild].h = round(h - childs[| fixChild].h); + childs[!fixChild].w = round(w); + childs[!fixChild].h = round(h - childs[fixChild].h); - childs[| fixChild].anchor = ANCHOR.top; - childs[| !fixChild].anchor = ANCHOR.bottom; + childs[ fixChild].anchor = ANCHOR.top; + childs[!fixChild].anchor = ANCHOR.bottom; } if(recur) - for(var i = 0; i < ds_list_size(childs); i++) - childs[| i].refreshSize(); + for(var i = 0; i < array_length(childs); i++) + childs[i].refreshSize(); } refresh(); - } #endregion + } - function resize(dw, dh, oppose = ANCHOR.left) { #region + function resize(dw, dh, oppose = ANCHOR.left) { if(dw == 0 && dh == 0) return; - if(ds_list_size(childs) == 2) { + if(array_length(childs) == 2) { var hori = oppose == ANCHOR.left || oppose == ANCHOR.right; - var ind = hori? childs[| 1].w > childs[| 0].w : childs[| 1].h > childs[| 0].h; - childs[| ind].resize(dw, dh, oppose); + var ind = hori? childs[1].w > childs[0].w : childs[1].h > childs[0].h; + childs[ind].resize(dw, dh, oppose); } w = max(round(w + dw), min_w); h = max(round(h + dh), min_h); refreshSize(false); - } #endregion + } - function setContent(_content = noone, _switch = false) { #region + function setContent(_content = noone, _switch = false) { if(is_array(_content)) content = array_append(content, _content); else @@ -223,15 +231,15 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(_switch) setTab(array_find(content, _content)); refresh(); - } #endregion + } - function switchContent(_content) { #region + function switchContent(_content) { var _ind = array_find(content, _content); if(_ind == -1) return; setTab(_ind); - } #endregion + } - function split_h(_w) { #region + function split_h(_w) { if(abs(_w) > w) { print($"Error: Split panel larger than size w ({_w} > {w})"); return noone; @@ -243,7 +251,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region _panelParent.split = "h"; var _panelL = self; - ds_list_add(_panelParent.childs, _panelL); + array_push(_panelParent.childs, _panelL); var _panelR = new Panel(_panelParent, x + _w, y, w - _w, h); _panelR.anchor = ANCHOR.right; @@ -258,16 +266,16 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(parent == noone) PANEL_MAIN = _panelParent; else - ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self)); + array_remove(parent.childs, self); parent = _panelParent; anchor = ANCHOR.left; content = []; return [ _panelL, _panelR ]; - } #endregion + } - function split_v(_h) { #region + function split_v(_h) { if(abs(_h) > h) { print($"Error: Split panel larger than size h ({_h} > {h})"); return noone; @@ -279,7 +287,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region _panelParent.split = "v"; var _panelT = self; - ds_list_add(_panelParent.childs, _panelT); + array_push(_panelParent.childs, _panelT); var _panelB = new Panel(_panelParent, x, y + _h, w, h - _h); _panelB.anchor = ANCHOR.bottom; @@ -293,16 +301,16 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(parent == noone) PANEL_MAIN = _panelParent; else - ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self)); + array_remove(parent.childs, self); parent = _panelParent; anchor = ANCHOR.top; content = []; return [_panelT, _panelB]; - } #endregion + } - function stepBegin() { #region + function stepBegin() { var con = getContent(); if(FULL_SCREEN_CONTENT != noone && con == FULL_SCREEN_CONTENT && self != FULL_SCREEN_PARENT) return; @@ -316,8 +324,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region var dw = round(_mx - drag_sm); var res = true; - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; switch(_panel.anchor) { case ANCHOR.left: res &= _panel.resizable(dw, 0, ANCHOR.left); @@ -331,8 +339,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(res) { drag_sm = _mx; - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; switch(_panel.anchor) { case ANCHOR.left: _panel.resize(dw, 0, ANCHOR.left); @@ -354,8 +362,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region var dh = round(_my - drag_sm); var res = true; - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; switch(_panel.anchor) { case ANCHOR.top: res &= _panel.resizable(0, dh, ANCHOR.top); @@ -369,8 +377,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(res) { drag_sm = _my; - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; switch(_panel.anchor) { case ANCHOR.top: _panel.resize(0, dh, ANCHOR.top); @@ -398,38 +406,38 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(FOCUS == self && con) FOCUS_STR = con.context_str; } else { - for(var i = 0; i < ds_list_size(childs); i++) - childs[| i].stepBegin(); + for(var i = 0; i < array_length(childs); i++) + childs[i].stepBegin(); } } - } #endregion + } - static step = function() { #region - for(var i = 0; i < ds_list_size(childs); i++) - childs[| i].step(); - } #endregion + static step = function() { + for(var i = 0; i < array_length(childs); i++) + childs[i].step(); + } - static draw = function() { #region + static draw = function() { if(hasContent()) { drawPanel(); return; } - if(ds_list_empty(childs)) + if(array_empty(childs)) return; var min_w = ui(32); var min_h = ui(32); if(split == "h") { - min_w = childs[| 0].min_w + childs[| 1].min_w; - min_h = max(childs[| 0].min_h + childs[| 1].min_h); + min_w = childs[0].min_w + childs[1].min_w; + min_h = max(childs[0].min_h + childs[1].min_h); } else { - min_w = max(childs[| 0].min_w, childs[| 1].min_w); - min_h = childs[| 0].min_h + childs[| 1].min_h; + min_w = max(childs[0].min_w, childs[1].min_w); + min_h = childs[0].min_h + childs[1].min_h; } - for(var i = 0; i < ds_list_size(childs); i++) { - var _panel = childs[| i]; + for(var i = 0; i < array_length(childs); i++) { + var _panel = childs[i]; _panel.draw(); if!(HOVER == noone || is_struct(HOVER)) @@ -464,9 +472,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(self == PANEL_MAIN && o_main.panel_dragging != noone && key_mod_press(CTRL)) checkHover(); - } #endregion + } - function drawTab() { #region + function drawTab() { tab_surface = surface_verify(tab_surface, w - padding * 2 + 1, tab_height + ui(4)); var tsx = x + padding - 1; @@ -623,9 +631,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region surface_reset_target(); draw_surface(tab_surface, tsx, tsy); - } #endregion + } - function setTab(tabIndex, forceFocus = false) { #region + function setTab(tabIndex, forceFocus = false) { if(tabIndex < 0) return; if(tabIndex >= array_length(content)) return; if(content_index == tabIndex) { @@ -640,9 +648,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region var prec = array_safe_get_fast(content, content_index); if(prec) prec.onFocusBegin(); - } #endregion + } - function drawPanel() { #region + function drawPanel() { if(w <= ui(16)) return; var tab = array_length(content) > 1; @@ -726,18 +734,18 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region if(o_main.panel_dragging != noone && m_ot && !key_mod_press(CTRL)) checkHover(); - } #endregion + } - function drawGUI() { #region - for( var i = 0; i < ds_list_size(childs); i++ ) - childs[| i].drawGUI(); + function drawGUI() { + for( var i = 0; i < array_length(childs); i++ ) + childs[i].drawGUI(); var con = getContent(); if(con == noone) return; con.drawGUI(); - } #endregion + } - function extract() { #region + function extract() { var con = getContent(); con.dragSurface = surface_clone(content_surface); o_main.panel_dragging = con; @@ -750,10 +758,10 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region FOCUS = noone; if(hasContent()) return; - var ind = !ds_list_find_index(parent.childs, self); //index of the other child - var sib = parent.childs[| ind]; + var ind = !array_find(parent.childs, self); //index of the other child + var sib = parent.childs[ind]; - if(!sib.hasContent() && ds_list_size(sib.childs) == 2) { //other child is compound panel + if(!sib.hasContent() && array_length(sib.childs) == 2) { //other child is compound panel var gparent = parent.parent; if(gparent == noone) { sib.x = PANEL_MAIN.x; sib.y = PANEL_MAIN.y; @@ -763,27 +771,27 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region sib.parent = noone; PANEL_MAIN.refreshSize(); } else { - var pind = ds_list_find_index(gparent.childs, parent); //index of parent in grandparent object - gparent.childs[| pind] = sib; //replace parent with sibling + var pind = array_find(gparent.childs, parent); //index of parent in grandparent object + gparent.childs[pind] = sib; //replace parent with sibling sib.parent = gparent; gparent.refreshSize(); } } else if(sib.hasContent()) { //other child is content panel, set parent to content panel parent.setContent(sib.content); - ds_list_clear(parent.childs); + parent.childs = []; } - } #endregion + } - function popWindow() { #region + function popWindow() { var con = getContent(); if(con == noone) return; dialogPanelCall(con); extract(); o_main.panel_dragging = noone; - } #endregion + } - function checkHover() { #region + function checkHover() { var dx = (mouse_mx - x) / w; var dy = (mouse_my - y) / h; var p = ui(8); @@ -840,12 +848,12 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region } } } - } #endregion + } function onFocusBegin() { INLINE if(FOCUS.getContent()) FOCUS.getContent().onFocusBegin(); } function onFocusEnd() { INLINE if(FOCUS.getContent()) FOCUS.getContent().onFocusEnd(); } - function remove(con = getContent()) { #region + function remove(con = getContent()) { var curr = getContent(); array_remove(content, con); @@ -854,20 +862,18 @@ function Panel(_parent, _x, _y, _w, _h) constructor { #region else setTab(array_find(content, curr), true); refresh(); - if(hasContent()) return; - if(parent == noone) { - show_message("Can't close main panel."); - return; - } - ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self)); - var otherPanel = parent.childs[| 0]; - parent.setContent(otherPanel.content); - ds_list_clear(parent.childs); - } #endregion -} #endregion + if(hasContent()) return; + if(parent == noone) { show_message("Can't close the main panel."); return; } + + if(array_length(parent.childs) == 2) { + array_remove(parent.childs, self); + parent.replacePanel(parent.childs[0]); + } + } +} -function PanelContent() constructor { #region +function PanelContent() constructor { title = ""; icon = noone; context_str = ""; @@ -899,10 +905,10 @@ function PanelContent() constructor { #region dragSurface = surface_create(1, 1); showHeader = true; - function refresh() { #region + function refresh() { setPanelSize(panel); onResize(); - } #endregion + } function onResize() {} @@ -911,35 +917,35 @@ function PanelContent() constructor { #region static initSize = function() {} - function setPanelSize(panel) { #region + function setPanelSize(panel) { x = panel.tx; y = panel.ty; w = panel.tw; h = panel.th; - } #endregion + } - function onSetPanel(panel) { #region + function onSetPanel(panel) { self.panel = panel; setPanelSize(panel); initSize(); onResize(); - } #endregion + } - function panelStepBegin(panel) { #region + function panelStepBegin(panel) { setPanelSize(panel); onStepBegin(); - } #endregion + } - function onStepBegin() { #region + function onStepBegin() { mx = mouse_mx - x; my = mouse_my - y; stepBegin(); - } #endregion + } function stepBegin() {} - static draw = function(panel) { #region + static draw = function(panel) { self.panel = panel; if(o_main.panel_dragging == noone) { @@ -948,7 +954,7 @@ function PanelContent() constructor { #region } drawContent(panel); - } #endregion + } function drawContent(panel) {} @@ -964,9 +970,9 @@ function PanelContent() constructor { #region static serialize = function() { return { name: instanceof(self) }; } static deserialize = function(data) { return self; } -} #endregion +} -function setFocus(target, fstring = noone) { #region +function setFocus(target, fstring = noone) { if((instance_exists(FOCUS) && variable_instance_exists(FOCUS, "onFocusEnd")) || (is_struct(FOCUS) && struct_has(FOCUS, "onFocusEnd"))) FOCUS.onFocusEnd(); @@ -979,4 +985,4 @@ function setFocus(target, fstring = noone) { #region (is_struct(FOCUS) && struct_has(FOCUS, "onFocusBegin"))) FOCUS.onFocusBegin(); -} #endregion \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/panel_function/panel_function.gml b/scripts/panel_function/panel_function.gml index 4a163d281..f7367e329 100644 --- a/scripts/panel_function/panel_function.gml +++ b/scripts/panel_function/panel_function.gml @@ -206,17 +206,15 @@ function _findPanel(_type, _pane, _res = noone) { #region if(instanceof(_pane) != "Panel") return _res; - if(!ds_exists(_pane.childs, ds_type_list)) - return _res; - if(ds_list_size(_pane.childs) == 0) { + if(array_empty(_pane.childs) == 0) { for( var i = 0, n = array_length(_pane.content); i < n; i++ ) if(instanceof(_pane.content[i]) == _type) return _pane.content[i]; } - for(var i = 0; i < ds_list_size(_pane.childs); i++) { - var _re = _findPanel(_type, _pane.childs[| i], _res); + for(var i = 0; i < array_length(_pane.childs); i++) { + var _re = _findPanel(_type, _pane.childs[i], _res); if(_re != noone) _res = _re; } @@ -230,8 +228,6 @@ function _findPanels(_type, _pane, _arr = []) { #region if(!is_instanceof(_pane, Panel)) return _arr; - if(!ds_exists(_pane.childs, ds_type_list)) - return _arr; for( var i = 0, n = array_length(_pane.content); i < n; i++ ) { var _cnt = instanceof(_pane.content[i]); @@ -240,8 +236,8 @@ array_push(_arr, _pane.content[i]); } - for(var i = 0; i < ds_list_size(_pane.childs); i++) - _arr = _findPanels(_type, _pane.childs[| i], _arr); + for(var i = 0; i < array_length(_pane.childs); i++) + _arr = _findPanels(_type, _pane.childs[i], _arr); return _arr; } #endregion @@ -313,9 +309,9 @@ case 3 : p = panel.split_v( panel.h / 2); break; } - panel.parent.childs[| (panel_split + 1) % 2] = main; + panel.parent.childs[(panel_split + 1) % 2] = main; main.parent = panel.parent; - panel.parent.childs[| (panel_split + 0) % 2].setContent(panel_dragging); + panel.parent.childs[(panel_split + 0) % 2].setContent(panel_dragging); PANEL_MAIN.refreshSize(); } else { @@ -356,20 +352,20 @@ var ind = 0; cont.content = []; - if(_panel.split != "" && ds_list_size(_panel.childs) == 2) { + if(_panel.split != "" && array_length(_panel.childs) == 2) { cont.split = _panel.split; if(_panel.split == "h") { - ind = _panel.childs[| 1].w < _panel.childs[| 0].w; - cont.width = _panel.childs[| ind].w * (_panel.childs[| ind].x == _panel.x? 1 : -1); + ind = _panel.childs[1].w < _panel.childs[0].w; + cont.width = _panel.childs[ind].w * (_panel.childs[ind].x == _panel.x? 1 : -1); } else { - ind = _panel.childs[| 1].h < _panel.childs[| 0].h; - cont.width = _panel.childs[| ind].h * (_panel.childs[| ind].y == _panel.y? 1 : -1); + ind = _panel.childs[1].h < _panel.childs[0].h; + cont.width = _panel.childs[ind].h * (_panel.childs[ind].y == _panel.y? 1 : -1); } - ind = _panel.childs[| 1].x == _panel.x && _panel.childs[| 1].y == _panel.y; - for( var i = 0; i < ds_list_size(_panel.childs); i++ ) - cont.content[i] = _panelSerialize(_panel.childs[| (ind + i) % 2], _content); + ind = _panel.childs[1].x == _panel.x && _panel.childs[1].y == _panel.y; + for( var i = 0; i < array_length(_panel.childs); i++ ) + cont.content[i] = _panelSerialize(_panel.childs[(ind + i) % 2], _content); } else { for( var i = 0, n = array_length(_panel.content); i < n; i++ ) @@ -386,9 +382,10 @@ function _panelSerializeArray(panel) { #region var cont = []; - if(!ds_list_empty(panel.childs)) { - for( var i = 0; i < ds_list_size(panel.childs); i++ ) - cont[i] = _panelSerializeArray(panel.childs[| i] ); + if(!array_empty(panel.childs)) { + for( var i = 0; i < array_length(panel.childs); i++ ) + cont[i] = _panelSerializeArray(panel.childs[i] ); + } else { for( var i = 0, n = array_length(panel.content); i < n; i++ ) cont[i] = instanceof(panel.content[i]); @@ -411,15 +408,15 @@ var content = panel.getContent(); if(!content.expandable) return; - PANEL_MAIN.childs[| 1].setContent(content); + PANEL_MAIN.childs[1].setContent(content); - FULL_SCREEN_PARENT = PANEL_MAIN.childs[| 1]; + FULL_SCREEN_PARENT = PANEL_MAIN.childs[1]; FULL_SCREEN_PANEL = panel; FULL_SCREEN_CONTENT = content; content.onFullScreen(); } else { - PANEL_MAIN.childs[| 1].content = []; + PANEL_MAIN.childs[1].content = []; PANEL_MAIN.refreshSize(); FULL_SCREEN_CONTENT.onFullScreen(); diff --git a/scripts/panel_graph/panel_graph.gml b/scripts/panel_graph/panel_graph.gml index e07e803d6..29df06fd1 100644 --- a/scripts/panel_graph/panel_graph.gml +++ b/scripts/panel_graph/panel_graph.gml @@ -933,6 +933,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { } #endregion function drawViewControl() { #region + if(h < ui(96)) return; + view_hovering = false; if(!show_view_control) return; diff --git a/scripts/panel_inspector/panel_inspector.gml b/scripts/panel_inspector/panel_inspector.gml index 07f4660d9..e0e11134f 100644 --- a/scripts/panel_inspector/panel_inspector.gml +++ b/scripts/panel_inspector/panel_inspector.gml @@ -1127,6 +1127,8 @@ function Panel_Inspector() : PanelContent() constructor { name: instanceof(self), inspecting : node_get_id(inspecting), inspectings : array_map(inspectings, function(n) { return node_get_id(n) }), + + locked, }; } @@ -1134,6 +1136,8 @@ function Panel_Inspector() : PanelContent() constructor { inspecting = node_from_id(data.inspecting); inspectings = array_map(data.inspectings, function(n) { return node_from_id(n); }); + locked = struct_try_get(data, "locked", locked); + return self; } diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 7f9dd688d..40ac0959e 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -42,7 +42,7 @@ function Panel_Preview() : PanelContent() constructor { canvas_y = h / 2; } run_in(1, function() { initSize() }); - + canvas_x = 0; canvas_y = 0; canvas_s = 1; @@ -2177,6 +2177,8 @@ function Panel_Preview() : PanelContent() constructor { canvas_x, canvas_y, canvas_s, + + locked, }; } @@ -2188,6 +2190,8 @@ function Panel_Preview() : PanelContent() constructor { canvas_y = struct_try_get(data, "canvas_y", canvas_y); canvas_s = struct_try_get(data, "canvas_s", canvas_s); + locked = struct_try_get(data, "locked", locked); + run_in(1, fullView) return self; }