Pixel-Composer/objects/o_dialog_assetbox/Create_0.gml

121 lines
3.0 KiB
Plaintext
Raw Normal View History

2022-09-27 06:37:28 +02:00
/// @description init
event_inherited();
#region display
draggable = false;
destroy_on_click_out = true;
target = noone;
2022-11-03 11:44:49 +01:00
dialog_w = ui(608);
dialog_h = ui(320);
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);
dialog_w_max = ui(640);
dialog_h_max = ui(480);
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
2022-11-03 11:44:49 +01:00
folderW = ui(180);
content_w = dialog_w - ui(32) - folderW;
content_h = dialog_h - ui(32);
2022-09-27 06:37:28 +02:00
function onResize() {
2022-11-03 11:44:49 +01:00
content_w = dialog_w - ui(32) - folderW;
content_h = dialog_h - ui(32);
2022-09-27 06:37:28 +02:00
contentPane.resize(content_w, content_h);
2022-11-03 11:44:49 +01:00
folderPane.resize(folderW - ui(16), content_h - ui(32));
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);
var hh = 0;
var frame = current_time * PREF_MAP[? "collection_preview_speed"] / 8000;
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);
2022-09-27 06:37:28 +02:00
var col = max(1, floor(content_w / (grid_size + grid_space)));
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;
BLEND_ADD
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.node_bg, 0, xx, yy, grid_size, grid_size);
2022-09-27 06:37:28 +02:00
BLEND_NORMAL
2022-12-10 05:06:01 +01:00
if(sHOVER && point_in_rectangle(_m[0], _m[1], xx, yy, xx + grid_size, yy + grid_size)) {
2022-11-21 06:38:44 +01:00
draw_sprite_stretched_ext(THEME.node_active, 0, xx, yy, grid_size, grid_size, COLORS._main_accent, 1);
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, sFOCUS)) {
2022-09-27 06:37:28 +02:00
target.onModify(content.path);
instance_destroy();
}
}
if(sprite_exists(content.spr)) {
var sw = sprite_get_width(content.spr);
var sh = sprite_get_height(content.spr);
var ss = img_size / max(sw, sh);
var sx = xx + (grid_size - sw * ss) / 2;
var sy = yy + (grid_size - sh * ss) / 2;
draw_sprite_ext(content.spr, frame, sx, sy, ss, ss, 0, c_white, 1);
}
}
}
var hght = grid_size + grid_space;
hh += hght;
yy += hght;
}
return hh;
});
2022-11-03 11:44:49 +01:00
folderPane = new scrollPane(folderW - ui(16), content_h - ui(32), function(_y, _m) {
2022-11-18 03:20:31 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2022-09-27 06:37:28 +02:00
var hh = 8;
for(var i = 0; i < ds_list_size(global.ASSETS.subDir); i++) {
2022-11-03 11:44:49 +01:00
var hg = global.ASSETS.subDir[| i].draw(self, ui(8), _y + 8, _m, folderPane.w - ui(16), sHOVER, sFOCUS, global.ASSETS);
2022-09-27 06:37:28 +02:00
hh += hg;
_y += hg;
}
2022-11-03 11:44:49 +01:00
return hh + 8;
2022-09-27 06:37:28 +02:00
});
#endregion