view controller

This commit is contained in:
Tanasart 2024-06-03 14:34:59 +07:00
parent ddddb5d18d
commit 633cd9d7aa
18 changed files with 172 additions and 95 deletions

View file

@ -188,6 +188,15 @@ event_inherited();
})
));
ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference(
__txtx("pref_save_backups", "Backup saves"),
"save_backup",
new textBox(TEXTBOX_INPUT.number, function(val) {
PREFERENCES.save_backup = max(0, val);
PREF_SAVE();
})
));
ds_list_add(pref_global, __txt("Crash"));
ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference(

View file

@ -169,53 +169,53 @@
var node = noone;
for( var i = 0, n = array_length(path); i < n; i++ ) {
var p = path[i];
var ext = string_lower(filename_ext(p));
var ext = filename_ext_raw(p);
switch(ext) {
case ".txt" :
case "txt" :
node = Node_create_Text_File_Read_path(_x, _y, p);
break;
case ".csv" :
case "csv" :
node = Node_create_CSV_File_Read_path(_x, _y, p);
break;
case ".json" :
case "json" :
node = Node_create_Json_File_Read_path(_x, _y, p);
break;
case ".ase" :
case ".aseprite" :
case "ase" :
case "aseprite" :
node = Node_create_ASE_File_Read_path(_x, _y, p);
break;
case ".png" :
case ".jpg" :
case ".jpeg" :
case "png" :
case "jpg" :
case "jpeg" :
if(key_mod_press(SHIFT))
node = Node_create_Image_path(_x, _y, p);
else
node = Node_create_Image_path(_x, _y, p);
break;
case ".gif" :
case "gif" :
node = Node_create_Image_gif_path(_x, _y, p);
break;
case ".obj" :
case "obj" :
node = Node_create_3D_Obj_path(_x, _y, p);
break;
case ".wav" :
case "wav" :
node = Node_create_WAV_File_Read_path(_x, _y, p);
break;
case ".pxc" :
case ".cpxc" :
case "pxc" :
case "cpxc" :
LOAD_PATH(p);
break;
case ".pxcc" :
case "pxcc" :
APPEND(p);
break;
}
@ -419,7 +419,7 @@
path = string_replace_all(path, "\n", "");
path = string_replace_all(path, "\"", "");
if(file_exists_empty(path) && (filename_ext(path) == ".pxc" || filename_ext(path) == ".cpxc"))
if(path_is_project(path))
PROGRAM_ARGUMENTS._path = path;
} else

View file

@ -15,14 +15,15 @@ function FileObject(_name, _path) constructor { #region
meta = noone;
type = FILE_TYPE.collection;
switch(string_lower(filename_ext(path))) { #region
case ".png" :
case ".jpg" :
case ".gif" :
switch(filename_ext_raw(path)) { #region
case "png" :
case "jpg" :
case "gif" :
type = FILE_TYPE.assets;
break;
case ".pxc" :
case ".cpxc" :
case "pxc" :
case "cpxc" :
type = FILE_TYPE.project;
break;
} #endregion
@ -107,9 +108,10 @@ function FileObject(_name, _path) constructor { #region
meta.name = name;
switch(filename_ext(path)) {
case ".pxc" : meta.type = FILE_TYPE.project; break;
case ".pxcc" : meta.type = FILE_TYPE.collection; break;
switch(filename_ext_raw(path)) {
case "pxc" :
case "cpxc" : meta.type = FILE_TYPE.project; break;
case "pxcc" : meta.type = FILE_TYPE.collection; break;
default : meta.type = FILE_TYPE.assets; break;
}

View file

@ -1,6 +1,6 @@
function draw_text_line(_x, _y, _text, _sep, _w) { #region
function draw_text_line(_x, _y, _text, _sep, _w, forceCut = false) { #region
INLINE
__draw_text_ext_transformed(_x, _y, _text, _sep, _w, 1, 1, 0);
__draw_text_ext_transformed(_x, _y, _text, _sep, _w, 1, 1, 0, forceCut);
} #endregion
function draw_text_add(_x, _y, _text, scale = 1) { #region
@ -114,12 +114,12 @@ function draw_text_highlight() { #region
} #endregion
function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation, forceCut = false) { #region
function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation, _break = LOCALE.config.per_character_line_break) { #region
INLINE
_x = round(_x);
_y = round(_y);
if(!LOCALE.config.per_character_line_break && !forceCut) {
if(!_break) {
BLEND_ALPHA_MULP;
draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation);
BLEND_NORMAL;
@ -156,7 +156,8 @@ function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation,
var ha = draw_get_halign();
var va = draw_get_valign();
var xx = _x, yy = _y;
var hh = string_height("M") * array_length(lines) * sy;
var lh = line_get_height();
var hh = lh * array_length(lines) * sy;
draw_set_halign(fa_left);
draw_set_valign(fa_top);
@ -178,7 +179,7 @@ function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation,
}
draw_text_transformed(xx, yy, lines[i], sx, sy, rotation);
yy += string_height("M") * sy;
yy += lh * sy;
}
BLEND_NORMAL;
@ -220,21 +221,21 @@ function __string_width_ext(text, sep, w) { #region
function __string_height_ext(text, sep, w, _break = LOCALE.config.per_character_line_break) { #region
INLINE
if(!_break)
return _string_height_ext(text, sep, w);
if(!_break) return _string_height_ext(text, sep, w);
var lw = 0;
var amo = string_length(text);
if(amo == 0) return 0;
var hh = string_height("M");
var lh = line_get_height();
var hh = lh;
for( var i = 1; i <= amo; i++ ) {
var ch = string_char_at(text, i);
var ww = string_width(ch);
if(lw + ww > w) {
hh += string_height("M");
hh += lh;
lw = ww;
} else
lw += ww;

View file

@ -1,10 +1,12 @@
function draw_tooltip_text(txt) { #region
txt = array_to_string(txt);
if(string_length(txt) > 1024)
txt = string_copy(txt, 1, 1024) + "...";
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
var tw = min(WIN_W - ui(32), string_width(txt));
var tw = min(max(320, WIN_W * 0.4), string_width(txt));
var th = string_height_ext(txt, -1, tw);
var mx = min(mouse_mx + ui(16), WIN_W - (tw + ui(16)));

View file

@ -4,7 +4,7 @@ function LOAD(safe = false) { #region
var path = get_open_filename_pxc("Pixel Composer project (.pxc)|*.pxc;*.cpxc", "");
key_release();
if(path == "") return;
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return;
if(!path_is_project(path)) return;
gc_collect();
var proj = LOAD_PATH(path, false, safe);
@ -71,7 +71,7 @@ function LOAD_AT(path, readonly = false, override = false) { #region
return false;
}
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc" && filename_ext(path) != ".cpxc") {
if(!path_is_project(path)) {
log_warning("LOAD", "File not a valid PROJECT");
return false;
}
@ -102,15 +102,15 @@ function LOAD_AT(path, readonly = false, override = false) { #region
printIf(log, $" > Create temp : {(get_timer() - t1) / 1000} ms"); t1 = get_timer();
var _load_content;
var _ext = filename_ext(path);
var _ext = filename_ext_raw(path);
var s;
if(_ext == ".pxc") {
if(_ext == "pxc") {
var f = file_text_open_read(path);
s = file_text_read_all(f);
file_text_close(f);
} else if(_ext == ".cpxc") {
} else if(_ext == "cpxc") {
var b = buffer_decompress(buffer_load(path));
s = buffer_read(b, buffer_string);
}

View file

@ -23,7 +23,7 @@ function ExpCreateFile(path) {
function ExpFile(path) constructor {
self.path = string_trim(path, [ "/", "\\" ]);
name = filename_name_only(path);
ext = string_lower(filename_ext(path));
ext = filename_ext_raw(path);
parent = noone;
load_thumb = false;
@ -39,8 +39,8 @@ function ExpFile(path) constructor {
thumbnail = -1;
switch(ext) {
case ".png" :
case ".jpg" :
case "png" :
case "jpg" :
thumbnail = sprite_add(path, 0, 0, 0, 0, 0);
if(thumbnail) {
load_thumb = true;
@ -50,8 +50,9 @@ function ExpFile(path) constructor {
}
break;
case ".pxc":
case ".pxcc":
case "cpxc":
case "pxc":
case "pxcc":
thumbnail = THEME.icon_64;
th_w = 64;
th_h = 64;

View file

@ -178,7 +178,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
connection_param = new connectionParameter();
bg_color = c_black;
show_view_control = true;
show_view_control = 1;
#endregion
#region ---- position ----
@ -933,11 +934,15 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
view_hovering = false;
if(!show_view_control) return;
var _side = show_view_control == 1? 1 : -1;
var _hab = pHOVER && !view_pan_tool && !view_zoom_tool;
var d3_view_wz = ui(16);
var _d3x = ui(8) + d3_view_wz;
var _d3x = show_view_control == 1?
ui(8) + d3_view_wz :
w - ui(8) - d3_view_wz;
var _d3y = ui(8) + d3_view_wz;
var _hv = false;
@ -963,7 +968,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
draw_circle_ui(_d3x, _d3y, d3_view_wz, _hv? 0 : 0.04, COLORS._main_icon, 0.3);
draw_sprite_ext(THEME.view_pan, 0, _d3x, _d3y, 1, 1, 0, view_pan_tool? COLORS._main_accent : COLORS._main_icon, 1);
_d3x += d3_view_wz + ui(4) + d3_view_wz;
_d3x += (d3_view_wz + ui(4) + d3_view_wz) * _side;
_hv = false;
if(_hab && point_in_circle(mx, my, _d3x, _d3y, d3_view_wz)) {
@ -2004,8 +2009,11 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
drawGrid();
drawViewControl();
var ovy = ui(8);
if(show_view_control == 2)
ovy += ui(36);
draw_set_text(f_p0, fa_right, fa_top, COLORS._main_text_sub);
draw_text(w - ui(8), ui(8), $"x{graph_s_to}");
draw_text(w - ui(8), ovy, $"x{graph_s_to}");
drawNodes();
drawJunctionConnect();
@ -2230,11 +2238,15 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
return;
}
if(filename_ext(txt) == ".pxc")
var _ext = filename_ext_raw(txt);
if(_ext == "pxc")
APPEND(txt);
else if(filename_ext(txt) == ".pxcc")
else if(_ext == "pxcc")
APPEND(txt);
else if(filename_ext(txt) == ".png") {
else if(_ext == "png") {
if(file_exists_empty(txt)) {
Node_create_Image_path(0, 0, txt);
return;

View file

@ -44,10 +44,10 @@ function Panel_Graph_View_Setting(graphPanel, display) : Panel_Linear_Setting()
),
new __Panel_Linear_Setting_Item(
__txt("View Control"),
new checkBox(function() { graphPanel.show_view_control = !graphPanel.show_view_control; }),
new buttonGroup([ "None", "Left", "Right" ], function(val) { graphPanel.show_view_control = val; }),
function() { return graphPanel.show_view_control },
function(val) { graphPanel.show_view_control = val; },
true,
1,
),
];

View file

@ -115,7 +115,7 @@ function Panel_Preview() : PanelContent() constructor {
mouse_pos_string = "";
show_info = true;
show_view_control = true;
show_view_control = 1;
#endregion
#region ---- tool ----
@ -352,7 +352,7 @@ function Panel_Preview() : PanelContent() constructor {
],
[
THEME.icon_visibility,
function() { return __txtx("graph_visibility_title", "Visibility settings"); },
__txtx("graph_visibility_title", "Visibility settings"),
function(param) {
dialogPanelCall(new Panel_Preview_View_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left });
},
@ -1138,7 +1138,10 @@ function Panel_Preview() : PanelContent() constructor {
#region view controller
if(show_view_control) {
var _view_x = tool_side_draw_l * toolbar_width + ui(8);
var _side = show_view_control == 1? 1 : -1;
var _view_x = show_view_control == 1?
tool_side_draw_l * toolbar_width + ui(8) :
w - tool_side_draw_r * toolbar_width - ui(8);
var _view_y = topbar_height + ui(8);
var _hab = pHOVER && tool_hovering == noone && !view_pan_tool && !view_zoom_tool;
view_hovering = false;
@ -1146,7 +1149,7 @@ function Panel_Preview() : PanelContent() constructor {
if(d3_active) {
var d3_view_wr = ui(32);
var _d3x = _view_x + d3_view_wr;
var _d3x = _view_x + d3_view_wr * _side;
var _d3y = _view_y + d3_view_wr;
var _hv = false;
@ -1184,7 +1187,7 @@ function Panel_Preview() : PanelContent() constructor {
}
var d3_view_wz = ui(16);
var _d3x = _view_x + d3_view_wr * 2 + ui(20);
var _d3x = _view_x + (d3_view_wr * 2 + ui(20)) * _side;
var _d3y = _view_y + d3_view_wz;
var _hv = false;
@ -1209,7 +1212,7 @@ function Panel_Preview() : PanelContent() constructor {
} else {
var d3_view_wz = ui(16);
var _d3x = _view_x + d3_view_wz;
var _d3x = _view_x + d3_view_wz * _side;
var _d3y = _view_y + d3_view_wz;
var _hv = false;
@ -1235,7 +1238,7 @@ function Panel_Preview() : PanelContent() constructor {
draw_circle_ui(_d3x, _d3y, d3_view_wz, _hv? 0 : 0.04, COLORS._main_icon, 0.3);
draw_sprite_ext(THEME.view_pan, 0, _d3x, _d3y, 1, 1, 0, view_pan_tool? COLORS._main_accent : COLORS._main_icon, 1);
_d3x += d3_view_wz + ui(4) + d3_view_wz;
_d3x += (d3_view_wz + ui(4) + d3_view_wz) * _side;
_d3y = _view_y + d3_view_wz;
_hv = false;
@ -1265,6 +1268,11 @@ function Panel_Preview() : PanelContent() constructor {
#endregion
right_menu_y = toolbar_height - ui(4);
if(show_view_control == 2) {
if(d3_active) right_menu_y += ui(72);
else right_menu_y += ui(40);
}
toolbar_draw = false;
var _node = getNodePreview();

View file

@ -15,10 +15,10 @@ function Panel_Preview_View_Setting(previewPanel) : Panel_Linear_Setting() const
),
new __Panel_Linear_Setting_Item(
__txt("View Control"),
new checkBox(function() { previewPanel.show_view_control = !previewPanel.show_view_control; }),
new buttonGroup([ "None", "Left", "Right" ], function(val) { previewPanel.show_view_control = val; }),
function() { return previewPanel.show_view_control },
function(val) { previewPanel.show_view_control = val; },
true,
1,
),
];

View file

@ -20,7 +20,7 @@ function Panel_Test() : PanelContent() constructor {
var f = file_find_first(dir + "\\*", fa_none);
while(f != "") {
var path = dir + "\\" + f;
if(filename_ext(path) == ".pxc")
if(filename_ext_raw(path) == "pxc")
array_push(test_files, path);
f = file_find_next();
}

View file

@ -67,14 +67,27 @@ function path_is_image(path) {
return false;
}
function path_is_project(path) {
if(!file_exists_empty(path)) return false;
function path_is_project(path, checkExist = true) {
if(checkExist && !file_exists_empty(path)) return false;
var ext = filename_ext(path);
ext = string_lower(string_letters(ext));
switch(ext) {
case ".pxc":
case ".pxcc":
case "pxc":
case "cpxc":
return true;
}
return false;
}
function path_is_backup(path) {
if(!path_is_project(path)) return false;
var ext = string_lower(filename_ext(path));
ext = string_replace(ext, ".", "");
return string_letters(ext) != ext;
}
function filename_ext_raw(path) { return string_lower(string_letters(filename_ext(path))); }

View file

@ -127,6 +127,8 @@
#region //////////////////////////////////////////////////////////////////////// MISC //////////////////////////////////////////////////////////////////////////
PREFERENCES.save_file_minify = true;
PREFERENCES.save_backup = 1;
PREFERENCES.render_all_export = true;
PREFERENCES.clear_temp_on_close = true;

View file

@ -8,9 +8,13 @@ function LOAD_FOLDER(list, folder) { #region
var file = file_find_first(path + "/*", fa_directory);
while(file != "") {
if(filename_ext(file) == ".pxc") {
var f = file;
var full_path = path + "/" + file;
var f = new FileObject(filename_name_only(file), full_path);
file = file_find_next();
if(!path_is_project(full_path)) continue;
var f = new FileObject(filename_name_only(f), full_path);
var icon_path = string_replace(full_path, filename_ext(full_path), ".png");
if(file_exists_empty(icon_path)) {
@ -22,8 +26,6 @@ function LOAD_FOLDER(list, folder) { #region
ds_list_add(list, f);
}
file = file_find_next();
}
file_find_close();
} #endregion

View file

@ -87,8 +87,9 @@ function SAVE_ALL() { #region
function SAVE(project = PROJECT) { #region
if(DEMO) return false;
if(project.path == "" || project.readonly)
if(project.path == "" || project.readonly || path_is_backup(project.path))
return SAVE_AS(project);
return SAVE_AT(project, project.path);
} #endregion
@ -99,8 +100,8 @@ function SAVE_AS(project = PROJECT) { #region
key_release();
if(path == "") return false;
if(filename_ext(path) != ".pxc" && filename_ext(path) != ".cpxc")
path += ".pxc";
if(!path_is_project(path, false))
path = filename_name_only(path) + ".pxc";
if(file_exists_empty(path))
log_warning("SAVE", "Overrided file : " + path);
@ -120,10 +121,21 @@ function SAVE_AT(project = PROJECT, path = "", log = "save at ") { #region
//if(TESTING && string_char_at(filename_name(path), 1) != "[")
// path = $"{filename_dir(path)}/[{VERSION_STRING}] {filename_name(path)}";
if(PREFERENCES.save_backup) {
for(var i = PREFERENCES.save_backup - 1; i >= 0; i--) {
var _p = path;
if(i) _p = $"{path}{string(i)}"
if(file_exists(_p))
file_rename(_p, $"{path}{string(i + 1)}");
}
}
if(file_exists_empty(path)) file_delete(path);
var _ext = filename_ext(path);
if(_ext == ".pxc") file_text_write_all(path, save_serialize(project));
else if(_ext == ".cpxc") buffer_save(buffer_compress_string(save_serialize(project)), path);
var _ext = filename_ext_raw(path);
if(_ext == "pxc") file_text_write_all(path, save_serialize(project));
else if(_ext == "cpxc") buffer_save(buffer_compress_string(save_serialize(project)), path);
SAVING = false;
project.readonly = false;

View file

@ -56,7 +56,7 @@ function __loadSteamUGC(file_id, item_map) { #region
} #endregion
function __loadSteamUGCCollection(file_id, f, path) { #region
if(filename_ext(f) != ".pxcc") return;
if(filename_ext_raw(f) != "pxcc") return;
var fullPath = $"{path}/{f}";
var name = filename_name_only(f);
@ -81,7 +81,7 @@ function __loadSteamUGCCollection(file_id, f, path) { #region
} #endregion
function __loadSteamUGCProject(file_id, f, path) { #region
if(filename_ext(f) != ".pxc") return;
if(!path_is_project(f, false)) return;
var fullPath = $"{path}/{f}";
var name = filename_name_only(f);

View file

@ -67,3 +67,16 @@ function filename_name_only(name) { #region
function string_to_var(str) { INLINE return string_replace_all(string_lower(str), " ", "_"); }
function string_quote(str) { INLINE return $"\"{str}\""; }
function array_to_string(arr) {
if(!is_array(arr)) return string(arr);
if(array_empty(arr)) return "[]";
var s = "[";
for (var i = 0, n = array_length(arr); i < n - 1; i++)
s += array_to_string(arr[i]) + ", ";
s += array_to_string(arr[i])
return s + "]";
}