[Collections] Add setting to hide labels.

This commit is contained in:
Tanasart 2024-12-29 11:42:51 +07:00
parent 558249e742
commit 5c46be3fc0
7 changed files with 145 additions and 116 deletions

View file

@ -46,19 +46,19 @@ event_inherited();
folderW_drag_mx = 0; folderW_drag_mx = 0;
folderW_drag_sx = 0; folderW_drag_sx = 0;
content_w = dialog_w - ui(38) - folderW; content_w = dialog_w - ui(26) - folderW;
content_h = dialog_h - ui(32); content_h = dialog_h - ui(24);
function onResize() { function onResize() {
content_w = dialog_w - ui(38) - folderW; content_w = dialog_w - ui(26) - folderW;
content_h = dialog_h - ui(32); content_h = dialog_h - ui(24);
contentPane.resize(content_w, content_h); contentPane.resize(content_w, content_h);
folderPane.resize(folderW - ui(12), content_h - ui(32)); folderPane.resize(folderW - ui(12), content_h - ui(32));
} }
folderPane = new scrollPane(folderW - ui(12), content_h - ui(32), function(_y, _m) { folderPane = new scrollPane(folderW - ui(12), content_h - ui(32), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0); draw_clear_alpha(COLORS.panel_bg_clear, 1);
var hh = 8; var hh = 8;
for(var i = 0; i < ds_list_size(global.ASSETS.subDir); i++) { for(var i = 0; i < ds_list_size(global.ASSETS.subDir); i++) {
@ -74,7 +74,7 @@ event_inherited();
return hh + 8; return hh + 8;
}); });
folderPane.scroll_color_bg = CDEF.main_mdblack;
contentPane = new scrollPane(content_w, content_h, function(_y, _m) { contentPane = new scrollPane(content_w, content_h, function(_y, _m) {
draw_clear_alpha(c_white, 0); draw_clear_alpha(c_white, 0);
@ -82,6 +82,7 @@ event_inherited();
var contents = context.content; var contents = context.content;
var amo = ds_list_size(contents); var amo = ds_list_size(contents);
var hh = 0; var hh = 0;
var surfh = contentPane.surface_h + 4;
var frame = current_time * PREFERENCES.collection_preview_speed / 8000; var frame = current_time * PREFERENCES.collection_preview_speed / 8000;
var grid_size = ui(64); var grid_size = ui(64);
@ -90,13 +91,22 @@ event_inherited();
var col = max(1, floor(contentPane.surface_w / (grid_size + grid_space))); var col = max(1, floor(contentPane.surface_w / (grid_size + grid_space)));
var row = ceil(amo / col); var row = ceil(amo / col);
var yy = _y + grid_space; var yy = _y + grid_space;
var hght = grid_size + grid_space;
hh += grid_space; hh += grid_space + hght * row;
for(var i = 0; i < row; i++) { for(var i = 0; i < row; i++) {
if(yy + grid_size < -4) {
yy += hght;
continue;
}
if(yy > surfh) break;
for(var j = 0; j < col; j++) { for(var j = 0; j < col; j++) {
var index = i * col + j; var index = i * col + j;
if(index < amo) { if(index >= amo) break;
var content = contents[| index]; var content = contents[| index];
var xx = grid_space + (grid_size + grid_space) * j; var xx = grid_space + (grid_size + grid_space) * j;
@ -138,12 +148,8 @@ event_inherited();
instance_destroy(); instance_destroy();
} }
} }
}
} }
var hght = grid_size + grid_space;
hh += hght;
yy += hght; yy += hght;
} }

View file

@ -7,7 +7,7 @@
#region draw #region draw
if(folderW_dragging) { if(folderW_dragging) {
var w = folderW_drag_sx + (mouse_mx - folderW_drag_mx); var w = folderW_drag_sx + (mouse_mx - folderW_drag_mx);
w = clamp(w, ui(200), dialog_w - ui(128)); w = clamp(w, ui(128), dialog_w - ui(128));
folderW = w; folderW = w;
onResize(); onResize();
@ -17,13 +17,15 @@
} }
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text); draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text);
draw_text(dialog_x + ui(16), dialog_y + ui(16), __txt("Assets")); draw_text(dialog_x + ui(24), dialog_y + ui(16), __txt("Assets"));
//draw_sprite_stretched(THEME.ui_panel_bg, 1, dialog_x + ui(16), dialog_y + ui(48), folderW - ui(24), dialog_h - ui(64)); var _fld_x = dialog_x + ui(12);
draw_sprite_stretched(THEME.ui_panel_bg, 1, dialog_x + ui(12 - 4) + folderW, dialog_y + ui(16), dialog_w - ui(28) - folderW, dialog_h - ui(32)); folderPane.setFocusHover(sFOCUS, sHOVER);
folderPane.draw(_fld_x, dialog_y + ui(48));
var dx0 = dialog_x + ui(16) + folderW - ui(8); var _cnt_x = _fld_x + folderW - ui(4);
var dx1 = dialog_x + ui(16) + folderW; var dx0 = _cnt_x - ui(8);
var dx1 = _cnt_x;
var dy0 = dialog_y + ui(48); var dy0 = dialog_y + ui(48);
var dy1 = dialog_y + dialog_h - ui(16); var dy1 = dialog_y + dialog_h - ui(16);
@ -36,9 +38,8 @@
} }
} }
folderPane.setFocusHover(sFOCUS, sHOVER); draw_sprite_stretched(THEME.ui_panel_bg, 1, _cnt_x, dialog_y + ui(12), content_w + ui(6), dialog_h - ui(24));
folderPane.draw(dialog_x + ui(12), dialog_y + ui(48));
contentPane.setFocusHover(sFOCUS, sHOVER); contentPane.setFocusHover(sFOCUS, sHOVER);
contentPane.draw(dialog_x + ui(12 - 4) + folderW, dialog_y + ui(16)); contentPane.draw(_cnt_x, dialog_y + ui(12));
#endregion #endregion

View file

@ -7,6 +7,7 @@ function FileObject(_name, _path) constructor {
spr = -1; spr = -1;
sprFetchID = noone; sprFetchID = noone;
size = file_size(path);
content = -1; content = -1;
var _mdir = filename_dir(path); var _mdir = filename_dir(path);
@ -15,8 +16,7 @@ function FileObject(_name, _path) constructor {
meta = noone; meta = noone;
type = FILE_TYPE.assets; type = FILE_TYPE.assets;
var _ext = filename_ext_raw(path); switch(filename_ext_raw(path)) {
switch(_ext) {
case "png" : case "png" :
case "jpg" : case "jpg" :
case "gif" : case "gif" :
@ -37,7 +37,6 @@ function FileObject(_name, _path) constructor {
retrive_data = false; retrive_data = false;
thumbnail_data = -1; thumbnail_data = -1;
thumbnail = noone; thumbnail = noone;
size = file_size(path);
static getName = function() { return name; } static getName = function() { return name; }
@ -73,20 +72,20 @@ function FileObject(_name, _path) constructor {
return spr; return spr;
} }
var path = array_safe_get_fast(spr_path, 0); var _path = array_safe_get_fast(spr_path, 0);
var amo = array_safe_get_fast(spr_path, 1); var _amo = array_safe_get_fast(spr_path, 1);
if(!file_exists_empty(path)) return -1; if(!file_exists_empty(_path)) return -1;
if(loadThumbnailAsync) { if(loadThumbnailAsync) {
sprFetchID = sprite_add_ext(path, amo, 0, 0, true); sprFetchID = sprite_add_ext(_path, _amo, 0, 0, true);
IMAGE_FETCH_MAP[? sprFetchID] = function(load_result) { IMAGE_FETCH_MAP[? sprFetchID] = function(load_result) {
spr = load_result[? "id"]; spr = load_result[? "id"];
if(spr && array_safe_get_fast(spr_path, 2)) if(spr && array_safe_get_fast(spr_path, 2))
sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2); sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2);
} }
} else { } else {
spr = sprite_add(path, amo, 0, 0, 0, 0); spr = sprite_add(_path, _amo, 0, 0, 0, 0);
if(spr && array_safe_get_fast(spr_path, 2)) if(spr && array_safe_get_fast(spr_path, 2))
sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2); sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2);
} }
@ -197,12 +196,11 @@ function DirectoryObject(name, path) constructor {
} }
static draw = function(parent, _x, _y, _m, _w, _hover, _focus, _homedir, _params = {}) { static draw = function(parent, _x, _y, _m, _w, _hover, _focus, _homedir, _params = {}) {
var hg = ui(28); var font = struct_try_get(_params, "font", f_p1);
var hg = line_get_height(font, 5);
var hh = 0; var hh = 0;
var font = struct_try_get(_params, "font", f_p0); if(!ds_list_empty(subDir) && _hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + ui(32), _y + hg - 1)) {
if(!ds_list_empty(subDir) && _hover && point_in_rectangle(_m[0], _m[1], _x, _y, ui(32), _y + hg - 1)) {
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _x, _y, ui(32), hg, CDEF.main_white, 1); draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _x, _y, ui(32), hg, CDEF.main_white, 1);
if(mouse_press(mb_left, _focus)) { if(mouse_press(mb_left, _focus)) {
open = !open; open = !open;
@ -210,14 +208,14 @@ function DirectoryObject(name, path) constructor {
} }
} }
var _bx = _x + ui(28); var _bx = _x + ui(32);
var _bw = _w - ui(36); var _bw = _w - ui(36);
if(_hover && point_in_rectangle(_m[0], _m[1], _bx, _y, _bx + _bw, _y + hg - 1)) { if(_hover && point_in_rectangle(_m[0], _m[1], _bx, _y, _bx + _bw, _y + hg - 1)) {
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _bx, _y, _bw, hg, CDEF.main_white, 1); draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _bx - ui(4), _y, _bw + ui(4), hg, CDEF.main_white, 1);
if(!triggered && mouse_press(mb_left, _focus)) { if(!triggered && mouse_press(mb_left, _focus)) {
if(!ds_list_empty(subDir)) { if(!ds_list_empty(subDir) && !open) {
open = !open; open = true;
MOUSE_BLOCK = true; MOUSE_BLOCK = true;
} }
@ -230,8 +228,12 @@ function DirectoryObject(name, path) constructor {
if(triggered && mouse_release(mb_left)) if(triggered && mouse_release(mb_left))
triggered = false; triggered = false;
if(ds_list_empty(subDir)) draw_sprite_ui_uniform(THEME.folder_content, parent.context == self, _x + ui(16), _y + hg / 2 - 1, 1, COLORS.collection_folder_empty); gpu_set_texfilter(true);
else draw_sprite_ui_uniform(THEME.folder_content, open, _x + ui(16), _y + hg / 2 - 1, 1, COLORS.collection_folder_nonempty); var _spr_ind = ds_list_empty(subDir)? parent.context == self : open;
var _spr_bld = ds_list_empty(subDir)? COLORS.collection_folder_empty : COLORS.collection_folder_nonempty;
var _spr_sca = (hg - ui(5)) / 24;
draw_sprite_ui_uniform(THEME.folder_content, _spr_ind, _x + ui(16), _y + hg / 2 - 1, _spr_sca, _spr_bld);
gpu_set_texfilter(false);
draw_set_text(font, fa_left, fa_center, path == parent.context.path? COLORS._main_text_accent : COLORS._main_text_inner); draw_set_text(font, fa_left, fa_center, path == parent.context.path? COLORS._main_text_accent : COLORS._main_text_inner);
draw_text_add(_x + ui(32), _y + hg / 2, name); draw_text_add(_x + ui(32), _y + hg / 2, name);
@ -242,8 +244,6 @@ function DirectoryObject(name, path) constructor {
var l_y = _y; var l_y = _y;
for(var i = 0; i < ds_list_size(subDir); i++) { for(var i = 0; i < ds_list_size(subDir); i++) {
var _hg = subDir[| i].draw(parent, _x + ui(16), _y, _m, _w - ui(16), _hover, _focus, _homedir, _params); var _hg = subDir[| i].draw(parent, _x + ui(16), _y, _m, _w - ui(16), _hover, _focus, _homedir, _params);
// draw_set_color(COLORS.collection_tree_line);
// draw_line(_x + ui(12), _y + hg / 2, _x + ui(16), _y + hg / 2);
hh += _hg; hh += _hg;
_y += _hg; _y += _hg;

View file

@ -28,7 +28,7 @@ function Node_Gradient(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
newInput(8, nodeValue_Surface("Mask", self)); newInput(8, nodeValue_Surface("Mask", self));
newInput(9, nodeValue_Float("Scale", self, 1)) newInput(9, nodeValue_Float("Scale", self, 1))
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 2, 0.01] }) .setDisplay(VALUE_DISPLAY.slider, { range: [0, 5, 0.01] })
.setMappable(13); .setMappable(13);
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -322,7 +322,7 @@ function Panel_Collection() : PanelContent() constructor {
var hh = 0; var hh = 0;
if(contentView == 0) { if(contentView == 0) {
var grid_width = round(grid_size * 1.25); var grid_width = PREFERENCES.collection_label? round(grid_size * 1.25) : grid_size;
if(grid_width > ui(80)) grid_width = grid_size; if(grid_width > ui(80)) grid_width = grid_size;
var grid_space = round(grid_size * 0.1875); var grid_space = round(grid_size * 0.1875);
@ -393,18 +393,16 @@ function Panel_Collection() : PanelContent() constructor {
if(sprite_exists(_node.spr)) { if(sprite_exists(_node.spr)) {
var sw = sprite_get_width(_node.spr); var sw = sprite_get_width(_node.spr);
var sh = sprite_get_height(_node.spr); var sh = sprite_get_height(_node.spr);
var ss = (grid_size - ui(12)) * PREFERENCES.collection_scale / max(sw, sh); var ss = (grid_size * .8) * PREFERENCES.collection_scale / max(sw, sh);
var xo = (sprite_get_xoffset(_node.spr) - sw / 2) * ss; var xo = (sprite_get_xoffset(_node.spr) - sw / 2) * ss;
var yo = (sprite_get_yoffset(_node.spr) - sh / 2) * ss; var yo = (sprite_get_yoffset(_node.spr) - sh / 2) * ss;
var sx = _boxx + grid_size / 2 + xo; var sx = _boxx + grid_size / 2 + xo;
var sy = yy + grid_size / 2 + yo; var sy = yy + grid_size / 2 + yo;
gpu_set_texfilter(true);
BLEND_ALPHA_MULP BLEND_ALPHA_MULP
draw_sprite_ext(_node.spr, frame, sx, sy, ss, ss, 0, c_white, 1); draw_sprite_ext(_node.spr, frame, sx, sy, ss, ss, 0, c_white, 1);
BLEND_NORMAL BLEND_NORMAL
gpu_set_texfilter(false);
} else } else
draw_sprite_ui_uniform(THEME.group, 0, _boxx + grid_size / 2, yy + grid_size / 2, 1, c_white); draw_sprite_ui_uniform(THEME.group, 0, _boxx + grid_size / 2, yy + grid_size / 2, 1, c_white);
@ -422,9 +420,12 @@ function Panel_Collection() : PanelContent() constructor {
} }
} }
if(PREFERENCES.collection_label) {
draw_set_text(f_p3, fa_center, fa_top, COLORS._main_text_inner); draw_set_text(f_p3, fa_center, fa_top, COLORS._main_text_inner);
var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width, 1, true); var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width, 1, true);
name_height = max(name_height, _txtH + 8); name_height = max(name_height, _txtH + 8);
} else
name_height = 0;
} }
var hght = grid_size + name_height + ui(8); var hght = grid_size + name_height + ui(8);
@ -517,11 +518,8 @@ function Panel_Collection() : PanelContent() constructor {
draw_set_alpha(1); draw_set_alpha(1);
_y += ui(24); _y += ui(24);
var _font = f_p0;
var _param = { font : _font };
for(var i = 0; i < ds_list_size(root.subDir); i++) { for(var i = 0; i < ds_list_size(root.subDir); i++) {
var hg = root.subDir[| i].draw(self, ui(8 + in_dialog * 8), _y, _m, folderPane.w - ui(20), pHOVER && folderPane.hover, pFOCUS, root, _param); var hg = root.subDir[| i].draw(self, ui(8 + in_dialog * 8), _y, _m, folderPane.w - ui(20), pHOVER && folderPane.hover, pFOCUS, root);
hh += hg; hh += hg;
_y += hg; _y += hg;
} }
@ -619,7 +617,7 @@ function Panel_Collection() : PanelContent() constructor {
_list = node_temp_list; _list = node_temp_list;
} }
var grid_width = max(ui(40), round(grid_size * 1.25)); var grid_width = PREFERENCES.collection_label? max(ui(40), round(grid_size * 1.25)) : grid_size;
var node_count = ds_list_size(_list); var node_count = ds_list_size(_list);
var grid_space = round(grid_size * 0.1875); var grid_space = round(grid_size * 0.1875);
@ -660,6 +658,7 @@ function Panel_Collection() : PanelContent() constructor {
BLEND_NORMAL; BLEND_NORMAL;
if(_hover && point_in_rectangle(_m[0], _m[1], _nx, yy, _nx + grid_width, yy + grid_size)) { if(_hover && point_in_rectangle(_m[0], _m[1], _nx, yy, _nx + grid_width, yy + grid_size)) {
TOOLTIP = _node.name;
nodecontentPane.hover_content = true; nodecontentPane.hover_content = true;
draw_sprite_stretched_ext(THEME.node_bg, 1, _boxx, yy, grid_size, grid_size, COLORS._main_accent, 1); draw_sprite_stretched_ext(THEME.node_bg, 1, _boxx, yy, grid_size, grid_size, COLORS._main_accent, 1);
@ -669,7 +668,7 @@ function Panel_Collection() : PanelContent() constructor {
} }
} }
var ss = (grid_size - ui(16)) / max(sprite_get_width(_node.spr), sprite_get_height(_node.spr)); var ss = (grid_size * .8) / max(sprite_get_width(_node.spr), sprite_get_height(_node.spr));
var sx = _boxx + grid_size / 2; var sx = _boxx + grid_size / 2;
var sy = yy + grid_size / 2; var sy = yy + grid_size / 2;
@ -684,9 +683,12 @@ function Panel_Collection() : PanelContent() constructor {
} }
if(PREFERENCES.collection_label) {
draw_set_text(font, fa_center, fa_top, COLORS._main_text_inner); draw_set_text(font, fa_center, fa_top, COLORS._main_text_inner);
var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width); var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width);
name_height = max(name_height, _txtH + 8); name_height = max(name_height, _txtH + 8);
} else
name_height = 0;
if(j == col - 1) { if(j == col - 1) {
var hght = grid_size + name_height + ui(8); var hght = grid_size + name_height + ui(8);
@ -883,13 +885,28 @@ function Panel_Collection() : PanelContent() constructor {
refreshContext(); refreshContext();
bx -= ui(36); bx -= ui(36);
}
if(bx < rootx) return; if(bx < rootx) return;
var txt = __txt("Settings"); var txt = __txt("Settings");
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, [mx, my], pHOVER, pFOCUS, txt, THEME.gear) == 2) if(buttonInstant(THEME.button_hide, bx, by, bs, bs, [mx, my], pHOVER, pFOCUS, txt, THEME.gear) == 2)
dialogPanelCall(new Panel_Collections_Setting(), x + bx, y + by - 8, { anchor: ANCHOR.bottom | ANCHOR.left }); dialogPanelCall(new Panel_Collections_Setting(), x + bx, y + by - 8, { anchor: ANCHOR.bottom | ANCHOR.left });
bx -= ui(36); bx -= ui(36);
} }
static serialize = function() {
_map = {
page,
};
return _map;
}
static deserialize = function(data) {
var p = struct_try_get(data, "page", 0);
setPage(p);
return self;
} }
} }

View file

@ -1,28 +1,32 @@
function Panel_Collections_Setting() : Panel_Linear_Setting() constructor { function Panel_Collections_Setting() : Panel_Linear_Setting() constructor {
title = __txtx("collection_settings", "Collection Settings"); title = __txtx("collection_settings", "Collection Settings");
w = ui(380); w = ui(380);
properties = [ properties = [
new __Panel_Linear_Setting_Item( new __Panel_Linear_Setting_Item(
__txt("View"), __txt("View"),
new buttonGroup([ "Grid", "List" ], function(i) { PANEL_COLLECTION.contentView = i; }), new buttonGroup([ "Grid", "List" ], function(i) /*=>*/ { PANEL_COLLECTION.contentView = i; }),
function() /*=>*/ {return PANEL_COLLECTION.contentView}, function() /*=>*/ {return PANEL_COLLECTION.contentView},
), ),
new __Panel_Linear_Setting_Item_Preference(
__txt("Show label"),
"collection_label",
new checkBox(function() /*=>*/ { PREFERENCES.collection_label = !PREFERENCES.collection_label; PREF_SAVE(); }),
),
new __Panel_Linear_Setting_Item_Preference( new __Panel_Linear_Setting_Item_Preference(
__txtx("coll_animated", "Animated thumbnail"), __txtx("coll_animated", "Animated thumbnail"),
"collection_animated", "collection_animated",
new checkBox(function() { PREFERENCES.collection_animated = !PREFERENCES.collection_animated; PREF_SAVE(); }), new checkBox(function() /*=>*/ { PREFERENCES.collection_animated = !PREFERENCES.collection_animated; PREF_SAVE(); }),
), ),
new __Panel_Linear_Setting_Item_Preference( new __Panel_Linear_Setting_Item_Preference(
__txtx("coll_animated_speed", "Animation speed"), __txtx("coll_animated_speed", "Animation speed"),
"collection_preview_speed", "collection_preview_speed",
new textBox(TEXTBOX_INPUT.number, function(val) { PREFERENCES.collection_preview_speed = val; PREF_SAVE(); }), new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ { PREFERENCES.collection_preview_speed = val; PREF_SAVE(); }),
), ),
new __Panel_Linear_Setting_Item_Preference( new __Panel_Linear_Setting_Item_Preference(
__txtx("coll_thumbnail_scale", "Thumbnail scale"), __txtx("coll_thumbnail_scale", "Thumbnail scale"),
"collection_scale", "collection_scale",
slider(0, 1, 0.01, function(val) { PREFERENCES.collection_scale = clamp(val, 0.1, 1); PREF_SAVE(); }), slider(0, 1, 0.01, function(val) /*=>*/ { PREFERENCES.collection_scale = clamp(val, 0.1, 1); PREF_SAVE(); }),
), ),
]; ];

View file

@ -113,6 +113,7 @@
PREFERENCES.curve_connection_line = 1; PREFERENCES.curve_connection_line = 1;
PREFERENCES.collection_animated = true; PREFERENCES.collection_animated = true;
PREFERENCES.collection_label = true;
PREFERENCES.collection_preview_speed = 60; PREFERENCES.collection_preview_speed = 60;
PREFERENCES.collection_scale = 1; PREFERENCES.collection_scale = 1;