diff --git a/objects/_p_dialog/Create_0.gml b/objects/_p_dialog/Create_0.gml index f272c474a..30045b720 100644 --- a/objects/_p_dialog/Create_0.gml +++ b/objects/_p_dialog/Create_0.gml @@ -30,6 +30,8 @@ destroy_on_escape = true; destroy_on_click_out = false; anchor = ANCHOR.none; + + init_pressing = mouse_click(mb_left); #endregion #region windows @@ -194,7 +196,7 @@ if(!active) return; if(!DIALOG_CLICK) return; - if(mouse_press(mb_any)) { + if(!init_pressing && mouse_press(mb_any)) { if(!isTop()) return; for( var i = 0, n = array_length(children); i < n; i++ ) diff --git a/objects/_p_dialog/Step_1.gml b/objects/_p_dialog/Step_1.gml index 80d10ac68..efa0c16c1 100644 --- a/objects/_p_dialog/Step_1.gml +++ b/objects/_p_dialog/Step_1.gml @@ -1,4 +1,7 @@ /// @description init +if(init_pressing && mouse_release(mb_left)) + init_pressing = false; + if !ready exit; if !active exit; diff --git a/objects/o_dialog_color_selector/Create_0.gml b/objects/o_dialog_color_selector/Create_0.gml index 38a4807a0..7e03f9703 100644 --- a/objects/o_dialog_color_selector/Create_0.gml +++ b/objects/o_dialog_color_selector/Create_0.gml @@ -76,22 +76,16 @@ event_inherited(); draw_circle_prec(ui(16) + ui(4), yy + ui(16), ui(4), false); } - if(preset_selecting == i) drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs, selector.current_color); - else drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(20)); + if(preset_selecting == i) + var _palRes = drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs, selector.current_color); + else + drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(20)); if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) { - if(preset_selecting == i && _hover && point_in_rectangle(_m[0], _m[1], ui(16), yy + ui(28), ui(16) + ww, yy + ui(28) + _height)) { - var m_ax = _m[0] - ui(16); - var m_ay = _m[1] - (yy + ui(28)); + if(preset_selecting == i && _hover && _palRes.hoverIndex > noone) { + selector.setColor(_palRes.hoverColor); + selector.setHSV(); - var m_gx = floor(m_ax / _gs); - var m_gy = floor(m_ay / _gs); - - var _index = m_gy * col + m_gx; - if(_index < pre_amo && _index >= 0) { - selector.setColor(pal.palette[_index]); - selector.setHSV(); - } } else if(isHover) { preset_selecting = i; click_block = true; diff --git a/objects/o_dialog_file_name/Create_0.gml b/objects/o_dialog_file_name/Create_0.gml index c6cdcae64..d7757de97 100644 --- a/objects/o_dialog_file_name/Create_0.gml +++ b/objects/o_dialog_file_name/Create_0.gml @@ -22,6 +22,11 @@ event_inherited(); instance_destroy(); }); + function setName(_name) { + self.name = _name; + return self; + } + WIDGET_CURRENT = tb_name; KEYBOARD_STRING = ""; #endregion \ No newline at end of file diff --git a/objects/o_dialog_file_name/Draw_64.gml b/objects/o_dialog_file_name/Draw_64.gml index b296d78a5..fef21ecb0 100644 --- a/objects/o_dialog_file_name/Draw_64.gml +++ b/objects/o_dialog_file_name/Draw_64.gml @@ -9,6 +9,5 @@ draw_text(dialog_x + ui(8), dialog_y + dialog_h / 2, __txt("Name")); tb_name.setFocusHover(sFOCUS, sHOVER); - tb_name.draw(dialog_x + ui(64), dialog_y + ui(8), dialog_w - ui(72), dialog_h - ui(16), - name, mouse_ui); + tb_name.draw(dialog_x + ui(64), dialog_y + ui(8), dialog_w - ui(72), dialog_h - ui(16), name, mouse_ui); #endregion \ No newline at end of file diff --git a/objects/o_dialog_gradient/Create_0.gml b/objects/o_dialog_gradient/Create_0.gml index e74faa394..18d278b80 100644 --- a/objects/o_dialog_gradient/Create_0.gml +++ b/objects/o_dialog_gradient/Create_0.gml @@ -190,27 +190,18 @@ event_inherited(); } if(palette_selecting == i) - drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs); + var _palRes = drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs); else drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(20)); if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) { - if(palette_selecting == i && _hover && point_in_rectangle(_m[0], _m[1], ui(16), yy + ui(28), ui(16) + ww, yy + ui(28) + _height)) { - var m_ax = _m[0] - ui(16); - var m_ay = _m[1] - (yy + ui(28)); + if(palette_selecting == i && _hover && _palRes.hoverIndex > noone) { + var c = _palRes.hoverColor; + if(is_real(c)) c = cola(c); + + selector.setColor(c); + selector.setHSV(); - var m_gx = floor(m_ax / _gs); - var m_gy = floor(m_ay / _gs); - - var _index = m_gy * col + m_gx; - if(_index < pre_amo && _index >= 0) { - var c = pal.palette[_index]; - - if(is_real(c)) c = cola(c); - - selector.setColor(c); - selector.setHSV(); - } } else if(isHover) { palette_selecting = i; click_block = true; diff --git a/objects/o_main/Other_62.gml b/objects/o_main/Other_62.gml index ed240039a..262a15f00 100644 --- a/objects/o_main/Other_62.gml +++ b/objects/o_main/Other_62.gml @@ -1,4 +1,6 @@ /// @description network +var _id = async_load[? "id"]; + if(ds_map_exists(global.FILE_LOAD_ASYNC, async_load[? "id"])) { var cb = global.FILE_LOAD_ASYNC[? async_load[? "id"]]; var callback = cb[0]; @@ -7,4 +9,33 @@ if(ds_map_exists(global.FILE_LOAD_ASYNC, async_load[? "id"])) { callback(arguments); } +if(PALETTE_LOSPEC && _id == PALETTE_LOSPEC) { + PALETTE_LOSPEC = 0; + if (async_load[? "status"] != 0) exit; + + var res = ds_map_find_value(async_load, "result"); + var resJson = json_try_parse(res, -1); + + if(resJson == -1) exit; + if(!is_struct(resJson)) exit; + if(!struct_has(resJson, "colors")) exit; + + var _name = resJson.name; + var _auth = resJson.author; + var _colr = resJson.colors; + + if(!is_array(_colr)) exit; + + _name = string_replace_all(_name, "-", " "); + + var _path = $"{DIRECTORY}Palettes/{_name}.hex" + var _f = file_text_open_write(_path); + for (var i = 0, n = array_length(_colr); i < n; i++) + file_text_write_string(_f, $"{_colr[i]}\n"); + file_text_close(_f); + __initPalette(); + + noti_status($"Loaded palette: {_name} by {_auth} completed.", noone, true); +} + asyncLoad(async_load); \ No newline at end of file diff --git a/objects/o_main/o_main.yy b/objects/o_main/o_main.yy index aa3956e2b..5031680f0 100644 --- a/objects/o_main/o_main.yy +++ b/objects/o_main/o_main.yy @@ -3,22 +3,22 @@ "%Name":"o_main", "eventList":[ {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":2,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":62,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":2,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":4,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":3,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":5,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":69,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":68,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":60,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":20,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":68,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":69,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":75,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":10,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, ], diff --git a/scripts/buttonPalette/buttonPalette.gml b/scripts/buttonPalette/buttonPalette.gml index 52bb74dcc..2e0152b26 100644 --- a/scripts/buttonPalette/buttonPalette.gml +++ b/scripts/buttonPalette/buttonPalette.gml @@ -225,17 +225,26 @@ function drawPalette(_pal, _x, _y, _w, _h, _a = 1) { #region } } #endregion -function drawPaletteGrid(_pal, _x, _y, _w, _gs = 24, c_color = -1) { #region +function drawPaletteGrid(_pal, _x, _y, _w, _gs = 24, params = {}) { #region + var c_color = struct_try_get(params, "color", -1); + var _stretch = struct_try_get(params, "stretch", false); + var _mx = struct_try_get(params, "mx", -1); + var _my = struct_try_get(params, "my", -1); + var amo = array_length(_pal); var col = floor(_w / _gs); var row = ceil(amo / col); var cx = -1, cy = -1; var _h = row * _gs; + var _gw = _stretch? _w / (min(col, amo)) : _gs; + var _hov = noone; + var _hcc = noone; + for(var i = 0; i < amo; i++) { var _cc = safe_mod(i, col); var _rr = floor(i / col); - var _x0 = _x + _cc * _gs; + var _x0 = _x + _cc * _gw; var _y0 = _y + _rr * _gs; var _i = 0; @@ -258,7 +267,11 @@ function drawPaletteGrid(_pal, _x, _y, _w, _gs = 24, c_color = -1) { #region } } - draw_sprite_stretched_ext(THEME.palette_mask, _i, _x0, _y0 + 1, _gs, _gs, _pal[i], 1); + draw_sprite_stretched_ext(THEME.palette_mask, _i, _x0, _y0 + 1, _cc == col - 1? _gw : ceil(_gw), _gs, _pal[i], 1); + if(point_in_rectangle(_mx, _my, _x0, _y0, _x0 + _gw, _y0 + _gs)) { + _hov = i; + _hcc = _pal[i]; + } var _same = (c_color & 0x00FFFFFF) == (_pal[i] & 0x00FFFFFF); if(c_color >= 0 && _same) { @@ -269,8 +282,12 @@ function drawPaletteGrid(_pal, _x, _y, _w, _gs = 24, c_color = -1) { #region if(cx != -1) { var _pd = ui(5); - draw_sprite_stretched_ext(THEME.palette_selecting, 0, cx - _pd, cy + 1 - _pd, _gs + _pd * 2, _gs + _pd * 2); + draw_sprite_stretched_ext(THEME.palette_selecting, 0, cx - _pd, cy + 1 - _pd, _gw + _pd * 2, _gs + _pd * 2); } - return _h; + return { + height: _h, + hoverIndex: _hov, + hoverColor: _hcc, + }; } #endregion \ No newline at end of file diff --git a/scripts/palette_functions/palette_functions.gml b/scripts/palette_functions/palette_functions.gml index 593f8e057..b78574d6a 100644 --- a/scripts/palette_functions/palette_functions.gml +++ b/scripts/palette_functions/palette_functions.gml @@ -79,8 +79,10 @@ function loadPalette(path) { #region return pal; } #endregion -globalvar PALETTES; +globalvar PALETTES, PALETTE_LOSPEC; + PALETTES = []; +PALETTE_LOSPEC = 0; function __initPalette() { PALETTES = []; diff --git a/scripts/panel_palette/panel_palette.gml b/scripts/panel_palette/panel_palette.gml index c4112fc20..ca2b91261 100644 --- a/scripts/panel_palette/panel_palette.gml +++ b/scripts/panel_palette/panel_palette.gml @@ -13,6 +13,31 @@ function Panel_Palette() : PanelContent() constructor { __save_palette_data = []; + menu_refresh = menuItem(__txt("Refresh"), function() { __initPalette(); }); + menu_add = menuItem(__txt("Add"), function(_dat) { + return submenuCall(_dat, [ + menuItem(__txt("File..."), function() { + var _p = get_open_filename("hex|*.hex|gpl|*.gpl|Image|.png", "palette"); + if(!file_exists_empty(_p)) return; + + file_copy(_p, $"{DIRECTORY}Palettes/{filename_name(_p)}"); + __initPalette(); + }), + menuItem(__txt("Lospec..."), function() { + fileNameCall("", function(txt) { + if(txt == "") return; + txt = string_lower(txt); + txt = string_replace_all(txt, " ", "-"); + + var _url = $"https://Lospec.com/palette-list{txt}.json"; + PALETTE_LOSPEC = http_get(_url); + }).setName("Palette") + }), + ]); + }).setIsShelf(); + + menu_stretch = menuItem(__txt("Stretch"), function() { PREFERENCES.palette_stretch = !PREFERENCES.palette_stretch; }, noone, noone, function() /*=>*/ {return PREFERENCES.palette_stretch}); + function onResize() { sp_palettes.resize(w - ui(padding + padding), h - ui(padding + padding)); } @@ -22,9 +47,9 @@ function Panel_Palette() : PanelContent() constructor { var ww = sp_palettes.surface_w; var hh = ui(28); var _gs = grid_size; - var _height; var yy = _y; var cur = CURRENT_COLOR; + var _height; if(pHOVER && key_mod_press(CTRL)) { if(mouse_wheel_down()) grid_size_to = clamp(grid_size_to - ui(4), ui(8), ui(32)); @@ -57,15 +82,34 @@ function Panel_Palette() : PanelContent() constructor { hh += _add_h + ui(8); } + if(PALETTE_LOSPEC) { + var _add_h = ui(28); + var _add_w = ui(64); + var _add_x = ww / 2 + sin(current_time / 400) * (ww - _add_w) / 2 - _add_w / 2; + + draw_sprite_stretched_ext(THEME.timeline_node, 0, 0, yy, ww, _add_h, COLORS._main_value_positive, .4); + draw_sprite_stretched_ext(THEME.timeline_node, 0, _add_x, yy, _add_w, _add_h, COLORS._main_value_positive, .3); + draw_sprite_stretched_ext(THEME.timeline_node, 1, 0, yy, ww, _add_h, COLORS._main_value_positive, .7); + draw_set_text(f_p2, fa_center, fa_center, COLORS._main_value_positive); + draw_text_add(ww / 2, yy + _add_h / 2, __txt("Loading Lospec Palette...")); + + yy += _add_h + ui(8); + hh += _add_h + ui(8); + } + if(mouse_release(mb_left)) drag_from_self = false; + var right_clicked = false; + var pd = lerp(ui(4), ui(10), (grid_size - ui(8)) / (ui(32) - ui(8))); + var param = { color: cur, stretch : PREFERENCES.palette_stretch, mx : _m[0], my : _m[1] }; + for(var i = 0; i < array_length(PALETTES); i++) { var preset = PALETTES[i]; var pre_amo = array_length(preset.palette); - var col = floor((ww - ui(20)) / _gs); + var col = floor((ww - pd * 2) / _gs); var row = ceil(pre_amo / col); - _height = ui(34) + row * _gs; + _height = ui(21) + row * _gs + pd; var isHover = pHOVER && point_in_rectangle(_m[0], _m[1], 0, max(0, yy), ww, min(sp_palettes.h, yy + _height)); @@ -74,29 +118,21 @@ function Panel_Palette() : PanelContent() constructor { draw_sprite_stretched_ext(THEME.node_active, 1, 0, yy, ww, _height, COLORS._main_accent, 1); draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub); - draw_text(ui(10), yy + ui(2), preset.name); - drawPaletteGrid(preset.palette, ui(10), yy + ui(24), ww - ui(20), _gs, cur); + draw_text(pd, yy + ui(2), preset.name); + var _palRes = drawPaletteGrid(preset.palette, pd, yy + ui(20), ww - pd * 2, _gs, param); if(isHover) { if(mouse_press(mb_left, pFOCUS)) { - if(point_in_rectangle(_m[0], _m[1], ui(10), yy + ui(24), ww - ui(10), yy + ui(24) + _height)) { - var m_ax = _m[0] - ui(10); - var m_ay = _m[1] - (yy + ui(24)); + if(_palRes.hoverIndex > noone) { + CURRENT_COLOR = _palRes.hoverColor; - var m_gx = floor(m_ax / _gs); - var m_gy = floor(m_ay / _gs); + DRAGGING = { + type: "Color", + data: _palRes.hoverColor + } + MESSAGE = DRAGGING; - var _index = m_gy * col + m_gx; - if(_index < pre_amo && _index >= 0) { - CURRENT_COLOR = array_safe_get_fast(preset.palette, _index); - - DRAGGING = { - type: "Color", - data: array_safe_get_fast(preset.palette, _index) - } - MESSAGE = DRAGGING; - } - } else if(point_in_rectangle(_m[0], _m[1], ui(10), yy, ww - ui(10), yy + ui(24))) { + } else if(point_in_rectangle(_m[0], _m[1], pd, yy, ww - pd, yy + ui(20))) { DRAGGING = { type: "Palette", data: preset.palette @@ -108,11 +144,11 @@ function Panel_Palette() : PanelContent() constructor { if(mouse_press(mb_right, pFOCUS)) { hovering = preset; + right_clicked = true; menuCall("palette_window_preset_menu",,, [ - menuItem(__txt("Refresh"), function() { - __initPalette(); - }), + menu_add, + menu_refresh, -1, menuItem(__txtx("palette_editor_set_default", "Set as default"), function() { PROJECT.setPalette(array_clone(hovering.palette)); @@ -121,12 +157,23 @@ function Panel_Palette() : PanelContent() constructor { file_delete(hovering.path); __initPalette(); }), + -1, + menu_stretch, ]); } } - yy += _height + ui(8); - hh += _height + ui(8); + yy += _height + ui(4); + hh += _height + ui(4); + } + + if(!right_clicked && mouse_press(mb_right, pFOCUS)) { + menuCall("palette_window_preset_menu_empty",,, [ + menu_add, + menu_refresh, + -1, + menu_stretch, + ]); } return hh; diff --git a/scripts/preferences/preferences.gml b/scripts/preferences/preferences.gml index f312be4ca..e47c07850 100644 --- a/scripts/preferences/preferences.gml +++ b/scripts/preferences/preferences.gml @@ -104,6 +104,8 @@ PREFERENCES.collection_preview_speed = 60; PREFERENCES.collection_scale = 1; + PREFERENCES.palette_stretch = false; + PREFERENCES.pan_mouse_key = mb_middle; #endregion