2022-01-13 05:24:03 +01:00
|
|
|
/// @description
|
|
|
|
event_inherited();
|
|
|
|
|
|
|
|
#region data
|
|
|
|
destroy_on_click_out = true;
|
2023-02-28 09:43:01 +01:00
|
|
|
dialog_w = ui(648);
|
2023-01-25 06:49:00 +01:00
|
|
|
dialog_h = ui(640);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-29 15:02:03 +02:00
|
|
|
draggable = false;
|
|
|
|
dialog_resizable = false;
|
2022-11-03 11:44:49 +01:00
|
|
|
dialog_w_min = ui(400);
|
2023-01-25 06:49:00 +01:00
|
|
|
dialog_h_min = ui(400);
|
2022-01-13 05:24:03 +01:00
|
|
|
dialog_w_max = WIN_W;
|
|
|
|
dialog_h_max = WIN_H;
|
|
|
|
|
|
|
|
target = noone;
|
|
|
|
|
|
|
|
function onResize() {
|
2023-02-28 09:43:01 +01:00
|
|
|
sp_content.resize(dialog_w - ui(padding + padding), dialog_h - ui(title_height + padding));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region content
|
2024-03-24 06:44:34 +01:00
|
|
|
menuOn = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = -1;
|
|
|
|
drag_spr = -1;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
sp_content = new scrollPane(dialog_w - ui(padding + padding), dialog_h - ui(title_height + padding), function(_y, _m) {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(!target) return 0;
|
2024-03-24 06:44:34 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_clear_alpha(COLORS.dialog_array_edit_bg, 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var _h = ui(8);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var ww = ui(100);
|
|
|
|
var hh = ui(100);
|
|
|
|
var pad = ui(16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
var arr = target.getValue();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var len = array_length(arr);
|
|
|
|
var col = floor((sp_content.surface_w - pad) / (ww + pad));
|
|
|
|
var row = ceil(len / col);
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var yy = _y + ui(8);
|
2022-01-13 05:24:03 +01:00
|
|
|
var menu = -1;
|
|
|
|
var drag = -1;
|
2022-09-21 06:09:40 +02:00
|
|
|
var inb_hover = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for( var i = 0; i < row; i++ ) {
|
|
|
|
var ch = hh;
|
|
|
|
for( var j = 0; j < col; j++ ) {
|
|
|
|
var index = i * col + j;
|
|
|
|
if(index >= len) break;
|
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
var path = arr[index];
|
|
|
|
var xx = pad + (ww + pad) * j;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 0, xx, yy, ww, hh);
|
2024-06-19 05:41:07 +02:00
|
|
|
draw_sprite_stretched_add(THEME.ui_panel_fg, 0, xx, yy, ww, hh, c_white, 0.3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
if(sHOVER && sp_content.hover && point_in_rectangle(_m[0], _m[1], xx, yy, xx + ww, yy + hh)) {
|
2022-12-12 09:08:03 +01:00
|
|
|
inb_hover = index;
|
2024-06-19 05:41:07 +02:00
|
|
|
if(dragging == -1 || dragging == index)
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, xx, yy, ww, hh, COLORS._main_accent, 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_press(mb_left, sFOCUS))
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = index;
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_press(mb_right, sFOCUS)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
menu = index;
|
|
|
|
menuOn = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
var spr = struct_try_get(SPRITE_PATH_MAP, path, noone);
|
2023-03-29 15:02:03 +02:00
|
|
|
if(spr == noone || !sprite_exists(spr))
|
|
|
|
spr = s_texture_default;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
var spr_w = sprite_get_width(spr);
|
|
|
|
var spr_h = sprite_get_height(spr);
|
2022-11-03 11:44:49 +01:00
|
|
|
var spr_s = min((ww - ui(16)) / spr_w, (hh - ui(16)) / spr_h);
|
2022-01-13 05:24:03 +01:00
|
|
|
var spr_x = xx + ww / 2 - spr_w * spr_s / 2;
|
|
|
|
var spr_y = yy + hh / 2 - spr_h * spr_s / 2;
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var aa = dragging == -1? 1 : (dragging == index? 1 : 0.5);
|
|
|
|
draw_sprite_ext(spr, 0, spr_x, spr_y, spr_s, spr_s, 0, c_white, aa);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p2, fa_center, fa_top, COLORS._main_text);
|
2024-06-19 05:41:07 +02:00
|
|
|
var name = string_cut_line(filename_name_only(path), ww);
|
2022-01-13 05:24:03 +01:00
|
|
|
var txt_h = string_height_ext(name, -1, ww);
|
|
|
|
|
2023-06-05 19:41:01 +02:00
|
|
|
draw_text_line(xx + ww / 2, yy + hh + ui(16), name, -1, ww);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
ch = max(ch, hh + txt_h + ui(32));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
yy += ch;
|
|
|
|
_h += ch;
|
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(dragging != -1) {
|
2022-09-21 06:09:40 +02:00
|
|
|
if(inb_hover != -1) {
|
2022-12-12 09:08:03 +01:00
|
|
|
rearrange(dragging, inb_hover);
|
|
|
|
dragging = inb_hover;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-12-12 09:08:03 +01:00
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
dragging = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(menu > -1) {
|
2023-05-03 21:42:17 +02:00
|
|
|
menuCall("image_array_edit_menu",,, [
|
2023-06-05 18:27:53 +02:00
|
|
|
menuItem(__txt("Remove"), function() {
|
2024-06-19 05:41:07 +02:00
|
|
|
var arr = target.getValue();
|
2022-01-13 05:24:03 +01:00
|
|
|
array_delete(arr, menuOn, 1);
|
2024-04-21 09:36:00 +02:00
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
target.setValue(arr);
|
|
|
|
target.node.triggerRender();
|
2023-02-19 02:13:19 +01:00
|
|
|
})
|
2023-05-04 20:00:56 +02:00
|
|
|
],, target );
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return _h;
|
|
|
|
})
|
2022-12-12 09:08:03 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region function
|
|
|
|
function rearrange(oldindex, newindex) {
|
|
|
|
if(oldindex == newindex) return;
|
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
var arr = target.getValue();
|
2022-12-12 09:08:03 +01:00
|
|
|
var val = arr[oldindex];
|
|
|
|
array_delete(arr, oldindex, 1);
|
|
|
|
array_insert(arr, newindex, val);
|
2024-04-21 09:36:00 +02:00
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
target.setValue(arr);
|
|
|
|
target.node.triggerRender();
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
sortAsc = true;
|
|
|
|
function sortByName() {
|
|
|
|
if(!target) return 0;
|
2024-06-19 05:41:07 +02:00
|
|
|
var arr = target.getValue();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
array_sort(arr, bool(sortAsc));
|
|
|
|
sortAsc = !sortAsc;
|
|
|
|
|
2024-06-19 05:41:07 +02:00
|
|
|
target.setValue(arr);
|
|
|
|
target.node.triggerRender();
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|