From 482878b2457be579b588d5216f41e8f5637bf201 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Fri, 13 Sep 2024 17:29:19 +0700 Subject: [PATCH] Fix crash when canceling open file dialog. --- objects/o_dialog_menubox/Create_0.gml | 1 + objects/o_dialog_menubox/Draw_64.gml | 55 +++++++++--------- objects/o_dialog_menubox/Step_1.gml | 3 + objects/o_dialog_preference/Create_0.gml | 2 +- scripts/file_functions/file_functions.gml | 6 +- scripts/load_function/load_function.gml | 10 ++-- scripts/panel_menu/panel_menu.gml | 68 +++++++++++++++-------- 7 files changed, 89 insertions(+), 56 deletions(-) diff --git a/objects/o_dialog_menubox/Create_0.gml b/objects/o_dialog_menubox/Create_0.gml index de0c8bbf9..579312b5f 100644 --- a/objects/o_dialog_menubox/Create_0.gml +++ b/objects/o_dialog_menubox/Create_0.gml @@ -17,6 +17,7 @@ event_inherited(); show_icon = false; context = noone; submenu = noone; + submenuIt = noone; _hovering_ch = true; init_press_l = MOUSE_POOL.lpress; diff --git a/objects/o_dialog_menubox/Draw_64.gml b/objects/o_dialog_menubox/Draw_64.gml index 856f4c091..6eac21373 100644 --- a/objects/o_dialog_menubox/Draw_64.gml +++ b/objects/o_dialog_menubox/Draw_64.gml @@ -14,6 +14,8 @@ DIALOG_WINCLEAR1 item_sel_submenu = noone; } + var to_del = noone; + draw_sprite_stretched(THEME.s_box_r2_clr, 0, dialog_x, dialog_y, dialog_w, dialog_h); for(var i = 0; i < array_length(menu); i++) { @@ -60,53 +62,50 @@ DIALOG_WINCLEAR1 if(_hovering_ch && is_instanceof(_menuItem, MenuItem)) { if(_menuItem.active && _lclick) { - var _par = _menuItem.params; - var _dat = { - _x: dialog_x, - x: dialog_x + dialog_w, - y: yy, - name: _menuItem.name, - index: i, - depth: depth, - context: context, - params: _menuItem.params, - }; if(_menuItem.isShelf) { FOCUS_CONTENT = context; if(instance_exists(submenu)) { - var _sfr = submenu.itemFrom; instance_destroy(submenu); - - if(_sfr == _menuItem) { - submenu = noone; - continue; - } + submenu = noone; } + + if(submenuIt == _menuItem) { + submenuIt = noone; + } else { + var _dat = { + _x: dialog_x, + x: dialog_x + dialog_w, + y: yy, + name: _menuItem.name, + index: i, + depth: depth, + context: context, + params: _par, + }; - var _res = _menuItem.func(_dat); - submenu = _res; - submenu.itemFrom = _menuItem; + var _res = _menuItem.func(_dat); + submenu = _res; + submenuIt = _menuItem; + } } else if(remove_parents) { - DIALOG_POSTDRAW FOCUS_CONTENT = context; if(_par == noone) _menuItem.func(); else _menuItem.func(_par); - instance_destroy(o_dialog_menubox); // close all - exit; + + to_del = o_dialog_menubox; } else { - DIALOG_POSTDRAW FOCUS_CONTENT = context; if(_par == noone) _menuItem.func(); else _menuItem.func(_par); - instance_destroy(); - exit; + + to_del = self; } } } @@ -300,4 +299,6 @@ DIALOG_WINCLEAR1 } #endregion -DIALOG_POSTDRAW \ No newline at end of file +DIALOG_POSTDRAW + +if(to_del != noone) instance_destroy(to_del); \ No newline at end of file diff --git a/objects/o_dialog_menubox/Step_1.gml b/objects/o_dialog_menubox/Step_1.gml index 6968054f0..77fff0cdb 100644 --- a/objects/o_dialog_menubox/Step_1.gml +++ b/objects/o_dialog_menubox/Step_1.gml @@ -11,6 +11,9 @@ if(init_press_l) { exit; } +if(submenu != noone && !instance_exists(submenu)) + submenu = noone; + var hov = point_in(mouse_raw_x, mouse_raw_y); if(instance_exists(submenu)) hov |= submenu.point_in(mouse_raw_x, mouse_raw_y); diff --git a/objects/o_dialog_preference/Create_0.gml b/objects/o_dialog_preference/Create_0.gml index 5a6c7df6d..694febce1 100644 --- a/objects/o_dialog_preference/Create_0.gml +++ b/objects/o_dialog_preference/Create_0.gml @@ -532,7 +532,7 @@ event_inherited(); #region node pref_node = ds_list_create(); - ds_list_add(pref_node, __txt("Node")); + // ds_list_add(pref_node, __txt("Node")); ds_list_add(pref_node, new __Panel_Linear_Setting_Item_Preference( __txtx("pref_node_param_show", "Show paramater on new node"), diff --git a/scripts/file_functions/file_functions.gml b/scripts/file_functions/file_functions.gml index d8b3c3972..d3816fade 100644 --- a/scripts/file_functions/file_functions.gml +++ b/scripts/file_functions/file_functions.gml @@ -1,4 +1,4 @@ -function file_exists_empty(path) { INLINE return path != "" && file_exists(path); } +function file_exists_empty(path) { INLINE path = string(path); return path != "" && file_exists(path); } function file_copy_override(src, dest) { if(file_exists_empty(dest)) file_delete(dest); @@ -43,6 +43,8 @@ function get_save_filename_pxc(filter, name, caption = "Save as") { INLINE var path = get_save_filename_ext(filter, name, PREFERENCES.dialog_path, caption); + path = string(path); + if(path != "") PREFERENCES.dialog_path = filename_dir(path); return path; } @@ -51,6 +53,8 @@ function get_open_filename_pxc(filter, name, caption = "Open") { INLINE var path = get_open_filename_ext(filter, name, PREFERENCES.dialog_path, caption); + path = string(path); if(path != "") PREFERENCES.dialog_path = filename_dir(path); + return path; } \ No newline at end of file diff --git a/scripts/load_function/load_function.gml b/scripts/load_function/load_function.gml index cdae8736f..b9b691525 100644 --- a/scripts/load_function/load_function.gml +++ b/scripts/load_function/load_function.gml @@ -13,6 +13,7 @@ function LOAD(safe = false) { var path = get_open_filename_pxc("Pixel Composer project (.pxc)|*.pxc;*.cpxc", ""); key_release(); if(path == "") return; + if(!path_is_project(path)) return; gc_collect(); @@ -279,16 +280,17 @@ function LOAD_AT(path, params = new __loadParams()) { function __EXPORT_ZIP() { exportPortable(PROJECT); } function __IMPORT_ZIP() { - var path = get_open_filename_pxc("Pixel Composer portable project (.zip)|*.zip", ""); + var _path = get_open_filename_pxc("Pixel Composer portable project (.zip)|*.zip", ""); + if(!file_exists_empty(_path)) return; - var _fname = filename_name_only(path); - var _fext = filename_ext(path); + var _fname = filename_name_only(_path); + var _fext = filename_ext(_path); if(_fext != ".zip") return false; directory_verify(TEMPDIR + "proj/"); var _dir = TEMPDIR + "proj/" + _fname; directory_create(_dir); - zip_unzip(path, _dir); + zip_unzip(_path, _dir); var _f = file_find_first(_dir + "/*.pxc", fa_none); var _proj = $"{_dir}/{_f}"; diff --git a/scripts/panel_menu/panel_menu.gml b/scripts/panel_menu/panel_menu.gml index a6741a077..4e246a137 100644 --- a/scripts/panel_menu/panel_menu.gml +++ b/scripts/panel_menu/panel_menu.gml @@ -619,27 +619,29 @@ function Panel_Menu() : PanelContent() constructor { var sc = merge_color(c_white, COLORS._main_value_positive, min(1, version_name_copy)); if(hori) { - draw_set_text(f_p0, fa_center, fa_center, tc); - var ww = string_width(txt) + ui(12); - var _x0 = _xx1 - ww; - var _y0 = ui(6); - var _x1 = _xx1; - var _y1 = h - ui(6); - - if(pHOVER && point_in_rectangle(mx, my, _x0, _y0, _x1, _y1)) { - _draggable = false; - draw_sprite_stretched_ext(THEME.button_hide_fill, 1, _x0, _y0, _x1 - _x0, _y1 - _y0, sc, 1); + if(w > 1500) { + draw_set_text(f_p0, fa_center, fa_center, tc); + var ww = string_width(txt) + ui(12); + var _x0 = _xx1 - ww; + var _y0 = ui(6); + var _x1 = _xx1; + var _y1 = h - ui(6); - if(mouse_press(mb_left, pFOCUS)) - dialogCall(o_dialog_release_note); - if(mouse_press(mb_right, pFOCUS)) { - clipboard_set_text(VERSION_STRING); - version_name_copy = 3; + if(pHOVER && point_in_rectangle(mx, my, _x0, _y0, _x1, _y1)) { + _draggable = false; + draw_sprite_stretched_ext(THEME.button_hide_fill, 1, _x0, _y0, _x1 - _x0, _y1 - _y0, sc, 1); + + if(mouse_press(mb_left, pFOCUS)) + dialogCall(o_dialog_release_note); + if(mouse_press(mb_right, pFOCUS)) { + clipboard_set_text(VERSION_STRING); + version_name_copy = 3; + } } + + draw_text(round((_x0 + _x1) / 2), round((_y0 + _y1) / 2), txt); + _xx1 = _x0 - ui(8); } - - draw_text(round((_x0 + _x1) / 2), round((_y0 + _y1) / 2), txt); - _xx1 = _x0 - ui(8); } else { var _xx1 = ui(40); var y1 = h - ui(20); @@ -667,7 +669,7 @@ function Panel_Menu() : PanelContent() constructor { if(PROJECT.safeMode) txt += $"[{__txt("SAFE MODE")}] "; if(PROJECT.readonly) txt += $"[{__txt("READ ONLY")}] "; - txt += PROJECT.path == ""? __txt("Untitled.pxc") : filename_name(PROJECT.path); + txt += PROJECT.path == ""? __txt("Untitled") : filename_name_only(PROJECT.path); if(PROJECT.modified) txt += "*"; var tx0, tx1, tcx; @@ -696,6 +698,7 @@ function Panel_Menu() : PanelContent() constructor { maxW = abs(tx0 - tx1); draw_set_font(f_p0b); + var full_name = string_width(txt + ".pxc") < maxW; var tc = string_cut(txt, maxW); var tw = string_width(tc) + ui(16); var th = ui(28); @@ -730,27 +733,46 @@ function Panel_Menu() : PanelContent() constructor { dia.tooltips = tip; } + + draw_set_font(f_p0b); + var _tcw = string_width(tc); + if(hori) { - draw_set_text(f_p0b, fa_center, fa_center, COLORS._main_text); - draw_text_int(tcx, (ty0 + ty1) / 2, tc); + draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_text); + draw_text_int(tcx - _tcw / 2, (ty0 + ty1) / 2, tc); + + if(full_name) { + draw_set_color(COLORS._main_text_sub); + draw_text_int(tcx + _tcw / 2, (ty0 + ty1) / 2, ".pxc"); + } + } else { draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_text); draw_text_int(tx0 + ui(8), tby0 + th / 2, tc); + + if(full_name) { + draw_set_color(COLORS._main_text_sub); + draw_text_int(tx0 + ui(8) + _tcw, tby0 + th / 2, ".pxc"); + } + } if(IS_PATREON && PREFERENCES.show_supporter_icon) { - var _tw = string_width(tc); - var _th = string_height(tc); + var _tw = string_width(tc); + var _th = string_height(tc); var _cx, _cy; if(hori) { _cx = tcx + _tw / 2; _cy = (ty0 + ty1) / 2 - _th / 2; + } else { _cx = tx0 + ui(8) + _tw; _cy = tby0 + th / 2 - _th / 2; } + if(full_name) _cx += string_width(".pxc"); + _cx += ui(2); _cy += ui(6);