Pixel-Composer/objects/o_dialog_assetbox/Create_0.gml

149 lines
3.8 KiB
Plaintext
Raw Normal View History

2022-09-27 06:37:28 +02:00
/// @description init
event_inherited();
#region display
2023-02-28 09:43:01 +01:00
draggable = true;
2022-09-27 06:37:28 +02:00
destroy_on_click_out = true;
target = noone;
2023-02-15 10:43:24 +01:00
dialog_w = ui(632);
dialog_h = ui(360);
2023-02-28 09:43:01 +01:00
title_height = 48;
2022-09-27 06:37:28 +02:00
anchor = ANCHOR.top | ANCHOR.right;
dialog_resizable = true;
2022-11-03 11:44:49 +01:00
dialog_w_min = ui(200);
dialog_h_min = ui(120);
2023-02-15 10:43:24 +01:00
dialog_w_max = ui(1080);
dialog_h_max = ui(640);
2022-09-27 06:37:28 +02:00
#endregion
#region context
context = global.ASSETS;
function gotoDir(dirName) {
for(var i = 0; i < ds_list_size(global.ASSETS.subDir); i++) {
var d = global.ASSETS.subDir[| i];
if(d.name != dirName) continue;
d.open = true;
setContext(d);
}
}
function setContext(cont) {
context = cont;
contentPane.scroll_y_raw = 0;
contentPane.scroll_y_to = 0;
}
#endregion
#region surface
2023-11-13 15:42:14 +01:00
folderW = ui(200);
2023-02-15 10:43:24 +01:00
folderW_dragging = false;
folderW_drag_mx = 0;
folderW_drag_sx = 0;
2023-11-13 15:42:14 +01:00
content_w = dialog_w - ui(38) - folderW;
2022-11-03 11:44:49 +01:00
content_h = dialog_h - ui(32);
2022-09-27 06:37:28 +02:00
function onResize() {
2023-11-13 15:42:14 +01:00
content_w = dialog_w - ui(38) - folderW;
2022-11-03 11:44:49 +01:00
content_h = dialog_h - ui(32);
2022-09-27 06:37:28 +02:00
contentPane.resize(content_w, content_h);
2023-08-06 16:00:59 +02:00
folderPane.resize(folderW - ui(12), content_h - ui(32));
2022-09-27 06:37:28 +02:00
}
2023-08-06 16:00:59 +02:00
folderPane = new scrollPane(folderW - ui(12), content_h - ui(32), function(_y, _m) {
2023-02-15 10:43:24 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hh = 8;
for(var i = 0; i < ds_list_size(global.ASSETS.subDir); i++) {
var _w = folderPane.surface_w - ui(16);
var _hover = sHOVER && folderPane.hover;
2023-11-13 07:11:52 +01:00
var hg = global.ASSETS.subDir[| i].draw(self, ui(8), _y + 8, _m, _w, _hover, sFOCUS, global.ASSETS);
2023-02-15 10:43:24 +01:00
hh += hg;
_y += hg;
}
return hh + 8;
});
folderPane.always_scroll = true;
2023-02-15 10:43:24 +01:00
2022-09-27 06:37:28 +02:00
contentPane = new scrollPane(content_w, content_h, function(_y, _m) {
draw_clear_alpha(c_white, 0);
var contents = context.content;
var amo = ds_list_size(contents);
2023-10-31 05:30:42 +01:00
var hh = 0;
var frame = current_time * PREFERENCES.collection_preview_speed / 8000;
2022-09-27 06:37:28 +02:00
2022-11-03 11:44:49 +01:00
var grid_size = ui(64);
var img_size = grid_size - ui(16);
var grid_space = ui(12);
2023-02-15 10:43:24 +01:00
var col = max(1, floor(contentPane.surface_w / (grid_size + grid_space)));
2022-09-27 06:37:28 +02:00
var row = ceil(amo / col);
var yy = _y + grid_space;
hh += grid_space;
for(var i = 0; i < row; i++) {
for(var j = 0; j < col; j++) {
var index = i * col + j;
if(index < amo) {
var content = contents[| index];
var xx = grid_space + (grid_size + grid_space) * j;
2022-09-27 06:37:28 +02:00
2023-02-15 10:43:24 +01:00
BLEND_OVERRIDE;
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.node_bg, 0, xx, yy, grid_size, grid_size);
2023-02-15 10:43:24 +01:00
BLEND_NORMAL;
2022-09-27 06:37:28 +02:00
2023-01-17 08:11:55 +01:00
var spr = content.getSpr();
if(sprite_exists(spr)) {
var sw = sprite_get_width(spr);
var sh = sprite_get_height(spr);
2022-09-27 06:37:28 +02:00
var ss = img_size / max(sw, sh);
var sx = xx + (grid_size - sw * ss) / 2;
var sy = yy + (grid_size - sh * ss) / 2;
var sn = sprite_get_number(spr);
2022-09-27 06:37:28 +02:00
2023-01-17 08:11:55 +01:00
draw_sprite_ext(spr, frame, sx, sy, ss, ss, 0, c_white, 1);
2023-02-15 10:43:24 +01:00
var _txt = $"{sw}x{sh}";
if(sn) _txt = $"[{sn}] " + _txt;
draw_set_text(_f_p4, fa_right, fa_bottom, COLORS._main_text_inner);
var _tw = string_width(_txt) + ui(6);
var _th = 14;
var _nx = xx + grid_size - 1 - _tw;
var _ny = yy + grid_size - _th;
draw_sprite_stretched_ext(THEME.timeline_node, 0, _nx, _ny, _tw, _th - 1, COLORS.panel_bg_clear_inner, 0.85);
draw_text_add(xx + grid_size - ui(3), yy + grid_size + ui(1), _txt);
2022-09-27 06:37:28 +02:00
}
if(sHOVER && contentPane.hover && point_in_rectangle(_m[0], _m[1], xx, yy, xx + grid_size, yy + grid_size)) {
TOOLTIP = [ spr, "sprite" ];
draw_sprite_stretched_ext(THEME.node_active, 0, xx, yy, grid_size, grid_size, COLORS._main_accent, 1);
if(mouse_press(mb_left, sFOCUS)) {
target.onModify(content.path);
instance_destroy();
}
}
2022-09-27 06:37:28 +02:00
}
}
2022-09-27 06:37:28 +02:00
var hght = grid_size + grid_space;
hh += hght;
yy += hght;
}
return hh;
});
#endregion