- [Preset] Fix gradient data not loading.

This commit is contained in:
Tanasart 2024-07-29 14:47:23 +07:00
parent be29bfc5ca
commit ee69669e51
12 changed files with 275 additions and 125 deletions

Binary file not shown.

View file

@ -48,11 +48,28 @@ if !ready exit;
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
draw_text_cut(dialog_x + ui(32), dialog_y + ui(8), content.title, dialog_w - ui(32 + 32));
var _bx = dialog_x + dialog_w - ui(28);
var _by = dialog_y + ui(8);
var _bs = ui(20);
if(instanceof(content) != "Panel_Menu")
if(buttonInstant(THEME.button_hide, dialog_x + dialog_w - ui(28), dialog_y + ui(8), ui(20), ui(20), mouse_ui, sFOCUS, sHOVER, "", THEME.window_exit) == 2) {
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, mouse_ui, sFOCUS, sHOVER, "", THEME.window_exit) == 2) {
onDestroy();
instance_destroy();
}
_bx -= ui(8);
// draw_set_color(COLORS.panel_toolbar_separator);
// draw_line_width(_bx + ui(4), _by, _bx + ui(4), _by + _bs, 2);
for (var i = 0, n = array_length(content.title_actions); i < n; i++) {
var _b = content.title_actions[i];
_bx -= _bs;
_b.setFocusHover(sFOCUS, sHOVER);
_b.draw(_bx, _by, _bs, _bs, mouse_ui, THEME.button_hide);
_bs -= ui(4);
}
}
var bx = content.showHeader? dialog_x + ui(8) : dialog_x + ui(24);

View file

@ -4,6 +4,7 @@ function buttonClass(_onClick, _icon = noone) : widget() constructor {
icon = _icon;
icon_blend = c_white;
icon_index = 0;
icon_size = 1;
text = "";
tooltip = "";
@ -19,15 +20,12 @@ function buttonClass(_onClick, _icon = noone) : widget() constructor {
toggled = false;
context = noone;
static setContext = function(struct) {
onClick = method(struct, onClick);
return self;
}
static setContext = function(struct) { onClick = method(struct, onClick); return self; }
static setLua = function(_lua_thread, _lua_key, _lua_func) {
lua_thread = _lua_thread;
lua_thread = _lua_thread;
lua_thread_key = _lua_key;
onClick = method(self, _lua_func);
onClick = method(self, _lua_func);
}
static trigger = function() {
@ -35,6 +33,7 @@ function buttonClass(_onClick, _icon = noone) : widget() constructor {
if(!is_callable(onClick))
return noone;
triggered = true;
onClick();
}
@ -45,22 +44,17 @@ function buttonClass(_onClick, _icon = noone) : widget() constructor {
return t;
}
static setIcon = function(_icon, _index = 0, _blend = c_white) {
static setIcon = function(_icon, _index = 0, _blend = c_white, _size = 1) {
icon = _icon;
icon_index = _index;
icon_blend = _blend;
icon_size = _size;
return self;
}
static setText = function(_text) {
text = _text;
return self;
}
static setTooltip = function(_tip) {
tooltip = _tip;
return self;
}
static setText = function(_text) { text = _text; return self; }
static setTooltip = function(_tip) { tooltip = _tip; return self; }
static drawParam = function(params) {
setParam(params);
@ -103,7 +97,7 @@ function buttonClass(_onClick, _icon = noone) : widget() constructor {
var aa = interactable * 0.25 + 0.75;
if(icon) {
var ind = is_array(icon_index)? icon_index[0]() : icon_index;
draw_sprite_ui_uniform(icon, ind, _x + _w / 2, _y + _h / 2,, icon_blend, aa);
draw_sprite_ui_uniform(icon, ind, _x + _w / 2, _y + _h / 2, icon_size, icon_blend, aa);
}
if(text != "") {

View file

@ -42,6 +42,7 @@ function FileObject(_name, _path) constructor { #region
if(!retrive_data) getMetadata(); // Metadata not loaded
if(thumbnail_data == -1) return noone; // Metadata does not contains thumbnail
if(!is_struct(thumbnail_data)) return noone;
thumbnail = surface_decode(thumbnail_data);
return thumbnail;

View file

@ -314,12 +314,14 @@ function loadGradient(path) {
_col = toNumber(keys[0]);
_pos = toNumber(keys[1]);
} else {
_col = toNumber(key);
if(file_text_eof(_t)) break;
_pos = toNumber(file_text_readln(_t));
}
if(!is_int64(_col)) _col = cola(_col);
array_push(grad.keys, new gradientKey(_pos, _col));
}
file_text_close(_t);

View file

@ -345,8 +345,6 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
return _nodes;
}
static getInput = function(_y = 0, junc = noone) { return dummy_input; }
static preConnect = function() {
sortIO();
deserialize(load_map, load_scale);

View file

@ -474,8 +474,8 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
var _inp = inputs[| i];
if(!_inp.visible) continue;
if(_inp.value_from != noone) continue;
if(junc != noone && (value_bit(junc.type) & value_bit(_inp.type)) == 0) continue;
if(_inp.value_from != noone) continue;
if(junc != noone && (value_bit(junc.type) & value_bit(_inp.type)) == 0) continue;
var _ddy = abs(_inp.y - _y);
@ -756,7 +756,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
var preset = pres[i];
if(preset.name != "_default") continue;
deserialize(preset.content, true, true);
deserialize(loadPreset(preset), true, true);
applyDeserialize(true);
}

View file

@ -906,6 +906,8 @@ function PanelContent() constructor {
dragSurface = surface_create(1, 1);
showHeader = true;
title_actions = [];
function refresh() {
setPanelSize(panel);
onResize();

View file

@ -1,30 +1,27 @@
function Panel_Globalvar() : PanelContent() constructor {
title = __txtx("panel_globalvar", "Global Variables");
context_str = "Globalvar";
showHeader = false;
title_height = 64;
padding = 20;
padding = 8;
w = ui(320);
h = ui(480);
b_edit = button(function() /*=>*/ { var_editing = !var_editing; }).setTooltip("Edit").setIcon(THEME.gear, 0, COLORS._main_icon, .6);
// title_actions = [ b_edit ];
globalvar_viewer_init();
drawWidgetInit();
function onResize() {
PANEL_PADDING
contentPane.resize(w - ui(padding + padding), h - ui(title_height + padding));
}
function onResize() { contentPane.resize(w - ui(padding + padding), h - ui(padding + padding) - ui(28)); }
contentPane = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding), function(_y, _m) {
contentPane = new scrollPane(w - ui(padding + padding), h - ui(padding + padding) - ui(28), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _hover = pHOVER && contentPane.hover;
var hh = 0;
var yy = _y;
var _x = ui(8);
var hh = 0;
var yy = _y;
var _x = ui(8);
var glPar = globalvar_viewer_draw(_x, yy, contentPane.surface_w - _x - ui(8), _m, pFOCUS, _hover, contentPane, x + _x + ui(padding), y + ui(title_height));
var gvh = glPar[0];
@ -38,27 +35,59 @@ function Panel_Globalvar() : PanelContent() constructor {
function drawContent(panel) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
PANEL_PADDING
PANEL_TITLE
var px = ui(padding);
var py = ui(title_height);
var py = ui(padding);
var pw = w - ui(padding + padding);
var ph = h - ui(title_height + padding);
var ph = h - ui(padding + padding) - ui(28);
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
contentPane.setFocusHover(pFOCUS, pHOVER);
contentPane.draw(px, py, mx - px, my - py);
var bx = w - ui(32 + 16);
var by = title_height / 2 - ui(16 + !in_dialog * 2);
var _add_h = ui(24);
var _bx = 0;
var _by = h - _add_h;
var _ww = w;
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_globalvar_add", "Add variable"), THEME.add, 1, COLORS._main_value_positive) == 2)
PROJECT.globalNode.createValue();
if(var_editing) {
var _bw = _ww / 2 - ui(4);
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _bx + _bw, _by + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, _bx, _by, _bw, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, _bx, _by, _bw, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
draw_text_add(_bx + _bw / 2, _by + _add_h / 2, __txt("Add"));
contentPane.hover_content |= _hov;
if(mouse_press(mb_left, _hov && pFOCUS))
PROJECT.globalNode.createValue();
_bx += _bw + ui(8);
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _bx + _bw, _by + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, _bx, _by, _bw, _add_h, _hov? COLORS._main_icon_light : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, _bx, _by, _bw, _add_h, _hov? COLORS._main_icon_light : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_icon_light : COLORS._main_icon);
draw_text_add(_bx + _bw / 2, _by + _add_h / 2, __txt("Exit"));
contentPane.hover_content |= _hov;
if(mouse_press(mb_left, _hov && pFOCUS))
var_editing = false;
} else {
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _ww, _by + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
draw_text_add(_bx + _ww / 2, _by + _add_h / 2, __txt("Edit"));
contentPane.hover_content |= _hov;
if(mouse_press(mb_left, _hov && pFOCUS))
var_editing = true;
}
bx -= ui(32 + 4);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txt("Edit"), var_editing? THEME.accept : THEME.gear) == 2)
var_editing = !var_editing;
}
}

View file

@ -6,97 +6,145 @@ function Panel_Presets(_node) : PanelContent() constructor {
h = ui(400);
anchor = ANCHOR.left | ANCHOR.top;
defPres = noone;
node = _node;
adding = false;
add_txt = "";
tb_add = new textBox(TEXTBOX_INPUT.text, function(txt) /*=>*/ { add_txt = txt; newPresetFromNode(txt); adding = false; });
tb_add = new textBox(TEXTBOX_INPUT.text, function(txt) /*=>*/ {
adding = false;
add_txt = txt;
if(txt == "") return;
newPresetFromNode(txt);
});
selecting_preset = noone;
context_menu_item_add = menuItem(__txt("New preset"), function() { if(!adding) tb_add.activate(); adding = true; });
context_menu_empty = [ context_menu_item_add ];
directory_verify($"{DIRECTORY}Presets/{instanceof(node)}/");
__initPresets();
context_menu = [
context_menu_item_add,
menuItem(__txt("Delete"), function() { file_delete(selecting_preset.path); __initPresets(); }, THEME.cross),
menuItem(__txt("Replace preset"), function() { replacePreset(selecting_preset.path); }),
menuItem(__txt("Delete"), function() { file_delete(selecting_preset.path); __initPresets(); }, THEME.cross),
];
context_def = [
menuItem(__txt("Set to default"), function() { newPresetFromNode("_default"); }),
];
thumbnail_mask = surface_create(1, 1);
function replacePreset(path) {
if(node == noone) return;
file_delete(path);
var map = node.serialize(true, true);
var thm = node.getPreviewValues();
if(is_surface(thm)) map.thumbnail = surface_encode(thm, false);
json_save_struct(path, map);
__initPresets();
}
function newPresetFromNode(name) {
if(node == noone) return;
var dir = $"{DIRECTORY}Presets/{instanceof(node)}/";
directory_verify(dir);
var pth = dir + name + ".json";
var map = node.serialize(true, true);
var thm = node.getPreviewValues();
if(is_surface(thm)) map.thumbnail = surface_encode(thm, false);
json_save_struct(pth, map);
__initPresets();
adding = false;
}
function onResize() {
sc_presets.resize(w - ui(padding + padding), h - ui(padding + padding));
}
function onResize() { sc_presets.resize(w - ui(padding + padding), h - ui(padding + padding) - ui(28)); }
sc_presets = new scrollPane(w - ui(padding + padding), h - ui(padding + padding), function(_y, _m) {
sc_presets = new scrollPane(w - ui(padding + padding), h - ui(padding + padding) - ui(28), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _ww = sc_presets.surface_w;
var _h = 0;
if(node == noone) return _h;
if(adding) {
tb_add.setFocusHover(sc_presets.active, sc_presets.hover);
var _wh = tb_add.draw(0, _y, _ww, TEXTBOX_HEIGHT, add_txt);
_h += _wh + ui(4);
_y += _wh + ui(4);
} else {
var _add_h = ui(24);
var _hov = pHOVER && point_in_rectangle(_m[0], _m[1], 0, _y, _ww, _y + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, 0, _y, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, 0, _y, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
draw_text_add(_ww / 2, _y + _add_h / 2, __txt("New preset"));
if(_hov) {
sc_presets.hover_content = true;
if(mouse_press(mb_left, pFOCUS)) {
if(!adding) tb_add.activate();
adding = true;
}
}
_h += _add_h + ui(4);
_y += _add_h + ui(4);
}
var folder = instanceof(node);
if(!ds_map_exists(global.PRESETS_MAP, folder)) return 0;
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
var _hov = false;
var pres = global.PRESETS_MAP[? folder];
var amo = array_length(pres);
var _hh = line_get_height() + ui(10);
_h += amo * (_hh + ui(4)) + ui(32);
var _yy = _y;
if(defPres != noone) {
var preset = defPres;
if(pHOVER && sc_presets.hover && point_in_rectangle(_m[0], _m[1], 0, _yy, _ww, _yy + _hh)) {
draw_sprite_stretched_ext(THEME.node_active, 1, 0, _yy, _ww, _hh, COLORS._main_icon, 1);
sc_presets.hover_content = true;
if(mouse_press(mb_left, pFOCUS)) {
LOADING_VERSION = SAVE_VERSION;
node.deserialize(loadPreset(preset), true, true);
if(in_dialog && panel.destroy_on_click_out) close();
}
if(mouse_press(mb_right, pFOCUS)) {
selecting_preset = preset;
menuCall("preset_window_menu",,, context_menu);
}
}
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(8), _yy + _hh / 2, "_default");
} else {
var aa = .5;
if(pHOVER && sc_presets.hover && point_in_rectangle(_m[0], _m[1], 0, _yy, _ww, _yy + _hh)) {
aa = .75;
sc_presets.hover_content = true;
if(mouse_press(mb_right, pFOCUS))
menuCall("preset_window_menu",,, context_def);
}
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text, aa);
draw_text_add(ui(8), _yy + _hh / 2, "_default");
draw_set_alpha(1);
}
_yy += _hh + ui(4);
_h += _hh + ui(4);
var _sz = _hh - ui(8);
thumbnail_mask = surface_create(_sz, _sz);
defPres = noone;
for( var i = 0; i < amo; i++ ) {
var preset = pres[i];
var _yy = _y + (_hh + ui(3)) * i;
if(preset.name == "_default") {
defPres = preset;
continue;
}
draw_sprite_stretched(THEME.ui_panel_bg, 3, 0, _yy, _ww, _hh);
if(pHOVER && sc_presets.hover && point_in_rectangle(_m[0], _m[1], 0, _yy, _ww, _yy + _hh)) {
draw_sprite_stretched_ext(THEME.node_active, 1, 0, _yy, _ww, _hh, COLORS._main_accent, 1);
_hov = true;
sc_presets.hover_content = true;
if(mouse_press(mb_left, pFOCUS)) {
node.deserialize(preset.content, true, true);
LOADING_VERSION = SAVE_VERSION;
node.deserialize(loadPreset(preset), true, true);
if(in_dialog && panel.destroy_on_click_out) close();
}
@ -106,12 +154,39 @@ function Panel_Presets(_node) : PanelContent() constructor {
}
}
loadPreset(preset);
var _thm = preset.getThumbnail();
var _xx = ui(8);
if(is_surface(_thm)) {
_xx = 0;
var _sw = surface_get_width(_thm);
var _sh = surface_get_height(_thm);
var _ss = _sz / max(_sw, _sh);
var _sx = _sz / 2 - _sw * _ss / 2;
var _sy = _sz / 2 - _sh * _ss / 2;
surface_set_target(thumbnail_mask);
DRAW_CLEAR
draw_surface_ext(_thm, _sx, _sy, _ss, _ss, 0, c_white, 1);
BLEND_MULTIPLY
draw_sprite_stretched(THEME.palette_mask, 1, _sx, _sy, _sw * _ss, _sh * _ss);
BLEND_NORMAL
surface_reset_target();
draw_surface(thumbnail_mask, _xx + ui(4), _yy + ui(4));
_xx += _sz + ui(12);
}
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(8), _yy + _hh / 2, preset.name);
draw_text_add(_xx, _yy + _hh / 2, preset.name);
_yy += _hh + ui(4);
}
if(pHOVER && !_hov && mouse_press(mb_right)) dia = menuCall("preset_window_menu",,, context_menu_empty);
return _h;
});
@ -121,12 +196,36 @@ function Panel_Presets(_node) : PanelContent() constructor {
var px = ui(padding);
var py = ui(padding);
var pw = w - ui(padding + padding);
var ph = h - ui(padding + padding);
var ph = h - ui(padding + padding) - ui(28);
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
sc_presets.setFocusHover(pFOCUS, pHOVER);
sc_presets.draw(px, py, mx - px, my - py);
var _add_h = ui(24);
var _bx = 0;
var _by = h - _add_h;
var _ww = w;
if(adding) {
tb_add.setFocusHover(sc_presets.active, sc_presets.hover);
tb_add.font = f_p2;
tb_add.draw(_bx, _by, _ww, _add_h, add_txt);
} else {
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _bx + _ww, _by + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
draw_text_add(_ww / 2, _by + _add_h / 2, __txt("New preset"));
if(mouse_press(mb_left, pFOCUS && _hov)) {
if(!adding) tb_add.activate();
adding = true;
}
}
}
}

View file

@ -1,28 +1,36 @@
#region loading
global.PRESETS_MAP = ds_map_create();
global.PRESETS_MAP = ds_map_create();
function __initPresets() {
ds_map_clear(global.PRESETS_MAP);
function __initPresets() {
ds_map_clear(global.PRESETS_MAP);
var _preset_path = "data/Preset.zip";
var root = DIRECTORY + "Presets";
directory_verify(root);
if(check_version($"{root}/version") && file_exists_empty(_preset_path))
zip_unzip(_preset_path, root);
var _preset_path = "data/Preset.zip";
var root = DIRECTORY + "Presets";
directory_verify(root);
if(check_version($"{root}/version") && file_exists_empty(_preset_path))
zip_unzip(_preset_path, root);
global.PRESETS = new DirectoryObject("Presets", root);
global.PRESETS.scan([".json"]);
global.PRESETS = new DirectoryObject("Presets", root);
global.PRESETS.scan([".json"]);
for( var i = 0; i < ds_list_size(global.PRESETS.subDir); i++ ) {
var l = [];
var grp = global.PRESETS.subDir[| i];
global.PRESETS_MAP[? grp.name] = l;
for( var i = 0; i < ds_list_size(global.PRESETS.subDir); i++ ) {
var l = [];
var grp = global.PRESETS.subDir[| i];
for( var j = 0; j < ds_list_size(grp.content); j++ ) {
var pth = grp.content[| j].path;
var f = new FileObject(grp.content[| j].name, pth);
f.content = json_load_struct(pth);
array_push(l, f);
}
global.PRESETS_MAP[? grp.name] = l;
for( var j = 0; j < ds_list_size(grp.content); j++ ) {
var pth = grp.content[| j].path;
var f = new FileObject(grp.content[| j].name, pth);
array_push(l, f);
}
}
#endregion
}
function loadPreset(preset) {
INLINE
if(preset.content == -1) {
preset.content = json_load_struct(preset.path);
preset.thumbnail_data = struct_try_get(preset.content, "thumbnail", -1);
}
return preset.content;
}

View file

@ -84,14 +84,14 @@ function __test_load_current_collections() { #region
break;
}
} else {
for( var j = 0; j < ds_list_size(coll); j++ ) {
coll[| j].x = xx;
coll[| j].y = yy;
for( var j = 0; j < array_length(coll); j++ ) {
coll[j].x = xx;
coll[j].y = yy;
if(outj)
for( var k = 0; k < ds_list_size(coll[| j].inputs); k++ ) {
if(coll[| j].inputs[| k].type != VALUE_TYPE.surface) continue;
coll[| j].inputs[| k].setFrom(outj);
for( var k = 0; k < ds_list_size(coll[j].inputs); k++ ) {
if(coll[j].inputs[| k].type != VALUE_TYPE.surface) continue;
coll[j].inputs[| k].setFrom(outj);
break;
}
}