Pixel-Composer/objects/o_dialog_palette/Create_0.gml

161 lines
4.0 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
event_inherited();
#region data
dialog_w = ui(812);
dialog_h = ui(440);
2023-02-28 09:43:01 +01:00
title_height = 52;
2022-01-13 05:24:03 +01:00
destroy_on_click_out = true;
name = __txtx("palette_editor_title", "Palette editor");
2022-01-13 05:24:03 +01:00
palette = 0;
2024-07-30 13:02:53 +02:00
index_sel_start = 0;
index_selecting = [ 0, 0 ];
index_dragging = noone;
interactable = true;
2024-05-25 10:07:11 +02:00
drop_target = noone;
2022-01-13 05:24:03 +01:00
2024-07-31 06:56:49 +02:00
mouse_interact = false;
colors_selecting = [];
2024-01-09 03:39:40 +01:00
index_drag_x = 0; index_drag_x_to = 0;
index_drag_y = 0; index_drag_y_to = 0;
index_drag_w = 0; index_drag_w_to = 0;
index_drag_h = 0; index_drag_h_to = 0;
2024-07-30 13:02:53 +02:00
palette_positions = {}
2022-11-18 03:20:31 +01:00
setColor = function(color) {
2024-07-31 06:56:49 +02:00
if(index_selecting[1] != 1 || palette == 0) return;
2024-07-30 13:02:53 +02:00
palette[index_selecting[0]] = color;
2023-01-01 02:06:02 +01:00
2023-01-04 02:30:04 +01:00
if(onApply == noone) return;
onApply(palette);
2022-01-13 05:24:03 +01:00
}
2022-11-18 03:20:31 +01:00
onApply = noone;
2022-11-18 03:20:31 +01:00
selector = new colorSelector(setColor);
selector.dropper_close = false;
2023-07-23 20:21:35 +02:00
selector.discretize_pal = false;
2022-11-18 03:20:31 +01:00
2023-02-14 13:44:46 +01:00
previous_palette = c_black;
2024-07-30 13:02:53 +02:00
selection_surface = surface_create(1, 1);
2023-02-14 13:44:46 +01:00
function setDefault(pal) {
setPalette(pal);
previous_palette = array_clone(pal);
}
b_cancel = button(function() {
onApply(previous_palette);
instance_destroy();
2023-06-10 13:59:45 +02:00
}).setIcon(THEME.undo, 0, COLORS._main_icon)
2023-06-05 18:27:53 +02:00
.setTooltip(__txtx("dialog_revert_and_exit", "Revert and exit"));
2023-02-14 13:44:46 +01:00
2023-01-25 06:49:00 +01:00
b_apply = button(function() {
onApply(palette);
instance_destroy();
}).setIcon(THEME.accept, 0, COLORS._main_icon_dark);
2022-01-13 05:24:03 +01:00
function setPalette(pal) {
palette = pal;
2024-07-30 13:02:53 +02:00
index_selecting = [ 0, 0 ];
if(!array_empty(palette))
2022-11-18 03:20:31 +01:00
selector.setColor(palette[0]);
2024-07-30 13:02:53 +02:00
palette_positions = {};
2022-01-13 05:24:03 +01:00
}
#endregion
#region presets
2023-03-02 07:59:14 +01:00
hovering_name = "";
2024-07-30 13:02:53 +02:00
pal_padding = ui(9);
sp_preset_w = ui(240) - pal_padding * 2 - ui(8);
sp_presets = new scrollPane(sp_preset_w, dialog_h - ui(48 + 8) - pal_padding, function(_y, _m) {
2022-11-18 03:20:31 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2022-01-13 05:24:03 +01:00
2024-07-30 13:02:53 +02:00
var ww = sp_presets.surface_w;
var _gs = ui(20);
var hh = ui(24);
var nh = ui(20);
var pd = ui(6);
var _ww = ww - pd * 2;
var hg = nh + _gs + pd;
var yy = _y;
for(var i = -1; i < array_length(PALETTES); i++) {
var pal = i == -1? {
2024-07-30 13:02:53 +02:00
name : "project",
palette : PROJECT.attributes.palette,
path : ""
} : PALETTES[i];
2024-07-30 13:02:53 +02:00
var isHover = sHOVER && sp_presets.hover && point_in_rectangle(_m[0], _m[1], 0, yy, ww, yy + hg);
draw_sprite_stretched(THEME.ui_panel_bg, 3, 0, yy, ww, hg);
2024-07-28 13:55:57 +02:00
if(isHover) {
sp_presets.hover_content = true;
draw_sprite_stretched_ext(THEME.node_bg, 1, 0, yy, ww, hg, COLORS._main_accent, 1);
2024-07-28 13:55:57 +02:00
}
2023-02-23 07:02:19 +01:00
2022-11-18 03:20:31 +01:00
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
2024-07-30 13:02:53 +02:00
draw_text_add(pd, yy + ui(2), pal.name);
drawPalette(pal.palette, pd, yy + nh, _ww, _gs);
2022-01-13 05:24:03 +01:00
2023-03-02 07:59:14 +01:00
if(isHover) {
if(mouse_press(mb_left, interactable && sFOCUS)) {
2024-04-20 05:00:28 +02:00
palette = array_clone(pal.palette);
2024-01-09 03:39:40 +01:00
onApply(palette);
2024-07-30 13:02:53 +02:00
index_selecting = [ 0, 0 ];
selector.setColor(palette[0], false);
2023-03-02 07:59:14 +01:00
}
2024-01-08 08:10:50 +01:00
if(i >= 0 && mouse_press(mb_right, interactable && sFOCUS)) {
hovering = pal;
2024-08-10 11:04:14 +02:00
menuCall("palette_window_preset_menu", [
menuItem(__txtx("palette_editor_set_default", "Set as default"), function() { PROJECT.setPalette(array_clone(hovering.palette)); }),
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() { file_delete(hovering.path); __initPalette(); }),
]);
2022-01-13 05:24:03 +01:00
}
}
2022-11-03 11:44:49 +01:00
yy += hg + ui(4);
hh += hg + ui(4);
2022-01-13 05:24:03 +01:00
}
return hh;
2023-12-29 14:30:54 +01:00
});
sp_presets.always_scroll = true;
2022-01-13 05:24:03 +01:00
#endregion
#region tools
2022-12-13 09:20:36 +01:00
function sortPalette(sortFunc) {
if(index_selecting[1] < 2)
array_sort(palette, sortFunc);
else {
var _arr = array_create(index_selecting[1]);
for(var i = 0; i < index_selecting[1]; i++)
_arr[i] = palette[index_selecting[0] + i];
array_sort(_arr, sortFunc);
for(var i = 0; i < index_selecting[1]; i++)
palette[index_selecting[0] + i] = _arr[i];
}
2023-01-09 03:14:20 +01:00
onApply(palette);
2022-01-13 05:24:03 +01:00
}
#endregion
2022-11-18 03:20:31 +01:00
#region action
function onResize() { sp_presets.resize(sp_preset_w, dialog_h - ui(62)); }
2022-11-18 03:20:31 +01:00
function checkMouse() {}
2022-01-13 05:24:03 +01:00
#endregion