Pixel-Composer/objects/o_dialog_preference/Create_0.gml

449 lines
12 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
/// @description init
event_inherited();
#region data
2022-11-03 11:44:49 +01:00
dialog_w = ui(640);
dialog_h = ui(480);
2022-01-13 05:24:03 +01:00
destroy_on_click_out = true;
destroy_on_escape = false;
#endregion
#region resize
dialog_resizable = true;
2022-11-03 11:44:49 +01:00
dialog_w_min = ui(640);
dialog_h_min = ui(480);
2022-01-13 05:24:03 +01:00
onResize = function() {
2022-11-18 03:20:31 +01:00
sp_pref.resize(dialog_w - ui(192), dialog_h - ui(88));
sp_hotkey.resize(dialog_w - ui(192), dialog_h - ui(88));
sp_colors.resize(dialog_w - ui(192), dialog_h - ui(128));
2022-01-13 05:24:03 +01:00
}
#endregion
#region pages
page_current = 0;
2022-09-21 06:09:40 +02:00
page[0] = "General";
page[1] = "Node settings";
2022-11-18 03:20:31 +01:00
page[2] = "Appearances";
page[3] = "Hotkeys";
2022-01-13 05:24:03 +01:00
pref_global = ds_list_create();
pref_node = ds_list_create();
2022-01-13 05:24:03 +01:00
ds_list_add(pref_global, [
"Show welcome screen",
"show_splash",
new checkBox(function() {
PREF_MAP[? "show_splash"] = !PREF_MAP[? "show_splash"];
PREF_SAVE();
})
]);
2022-01-13 05:24:03 +01:00
2022-11-03 11:44:49 +01:00
PREF_MAP[? "_display_scaling"] = PREF_MAP[? "display_scaling"];
ds_list_add(pref_global, [
2022-11-01 03:06:03 +01:00
"GUI scaling",
2022-11-03 11:44:49 +01:00
"_display_scaling",
2022-11-01 03:06:03 +01:00
new slider(0.5, 2, 0.01, function(val) {
2022-11-03 11:44:49 +01:00
PREF_MAP[? "_display_scaling"] = val;
PREF_SAVE();
2022-11-01 03:06:03 +01:00
}, function() {
2022-11-03 11:44:49 +01:00
PREF_MAP[? "_display_scaling"] = clamp(PREF_MAP[? "_display_scaling"], 0.5, 2);
if(PREF_MAP[? "display_scaling"] == PREF_MAP[? "_display_scaling"])
return;
PREF_MAP[? "display_scaling"] = PREF_MAP[? "_display_scaling"];
2022-11-01 03:06:03 +01:00
setPanel();
loadFonts();
2022-11-03 11:44:49 +01:00
time_source_start(time_source_create(time_source_global, 1, time_source_units_frames, onResize));
})
]);
2022-01-13 05:24:03 +01:00
ds_list_add(pref_global, [
"Double click delay",
"double_click_delay",
2022-09-21 06:09:40 +02:00
new slider(0, 100, 1, function(val) {
PREF_MAP[? "double_click_delay"] = val;
PREF_SAVE();
})
]);
2022-01-13 05:24:03 +01:00
2022-11-21 06:38:44 +01:00
ds_list_add(pref_global, [
"UI frame rate",
"ui_framerate",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "ui_framerate"] = max(15, round(real(str)));
PREF_SAVE();
})
]);
ds_list_add(pref_global, [
"Default surface size",
"default_surface_side",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "default_surface_side"] = max(1, round(real(str)));
PREF_SAVE();
})
]);
2022-01-13 05:24:03 +01:00
ds_list_add(pref_global, [
"Show node render time",
"node_show_time",
new checkBox(function() {
PREF_MAP[? "node_show_time"] = !PREF_MAP[? "node_show_time"];
PREF_SAVE();
})
]);
2022-01-25 10:58:11 +01:00
ds_list_add(pref_global, [
"Collection preview speed",
"collection_preview_speed",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "collection_preview_speed"] = max(1, round(real(str)));
PREF_SAVE();
})
]);
2022-09-21 06:09:40 +02:00
ds_list_add(pref_global, [
"Inspector line break width",
"inspector_line_break_width",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "inspector_line_break_width"] = max(1, round(real(str)));
PREF_SAVE();
})
]);
2022-11-14 03:16:15 +01:00
ds_list_add(pref_global, [
"Expand hovering panel",
"expand_hover",
new checkBox(function() {
PREF_MAP[? "expand_hover"] = !PREF_MAP[? "expand_hover"];
PREF_SAVE();
})
]);
//NODE
2022-09-21 06:09:40 +02:00
ds_list_add(pref_node, "Particle");
ds_list_add(pref_node, [
2022-09-21 06:09:40 +02:00
"Max particles",
"part_max_amount",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "part_max_amount"] = real(str);
PREF_SAVE();
})
]);
2022-09-21 06:09:40 +02:00
ds_list_add(pref_node, "Separate shape");
ds_list_add(pref_node, [
2022-09-21 06:09:40 +02:00
"Max shapes",
"shape_separation_max",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "shape_separation_max"] = real(str);
PREF_SAVE();
})
]);
2022-09-23 13:28:42 +02:00
ds_list_add(pref_node, "Levels");
ds_list_add(pref_node, [
"Histogram resolution",
"level_resolution",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "level_resolution"] = real(str);
PREF_SAVE();
})
]);
ds_list_add(pref_node, [
"Maximum sampling",
"level_max_sampling",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "level_max_sampling"] = real(str);
PREF_SAVE();
})
]);
ds_list_add(pref_node, "Physic");
ds_list_add(pref_node, [
"Verlet iteration",
"verlet_iteration",
new textBox(TEXTBOX_INPUT.number, function(str) {
PREF_MAP[? "verlet_iteration"] = real(str);
PREF_SAVE();
})
]);
2022-11-18 03:20:31 +01:00
#endregion
#region theme
themes = [];
var f = file_find_first("data/themes/*", fa_directory);
while(f != "") {
array_push(themes, f);
f = file_find_next();
}
file_find_close();
sb_theme = new scrollBox(themes, function(index) {
var thm = themes[index]
if(PREF_MAP[? "theme"] == thm) return;
PREF_MAP[? "theme"] = thm;
PREF_SAVE();
loadFonts();
loadGraphic(thm);
loadColor(thm);
});
sb_theme.align = fa_left;
sp_colors = new scrollPane(dialog_w - ui(192), dialog_h - ui(128), function(_y, _m, _r) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hh = 0;
var th = ui(28);
var x1 = dialog_w - ui(208);
var yy = _y + ui(8);
var padd = ui(6);
var ind = 0;
var cw = ui(100);
var ch = th - ui(4);
var cx = x1 - cw;
var category = "";
for( var i = 0; i < array_length(COLOR_KEYS); i++ ) {
var key = COLOR_KEYS[i];
var val = variable_struct_get(COLORS, key);
if(search_text != "" && string_pos(string_lower(search_text), string_lower(key)) == 0)
continue;
if(is_array(val)) continue;
var spl = string_splice(key, "_");
var cat = spl[0] == ""? spl[1] : spl[0];
if(cat != category) {
category = cat;
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub);
draw_text(ui(16), yy, string_title(category));
yy += string_height(category) + ui(8);
hh += string_height(category) + ui(8);
ind = 0;
}
if(ind % 2 == 0)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, yy - padd, sp_colors.w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
var keyStr = string_replace_all(key, "_", " ");
keyStr = string_replace(keyStr, cat + " ", "");
keyStr = string_title(keyStr);
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text(ui(8), yy + th / 2, keyStr);
var b = buttonInstant(THEME.button, cx, yy + ui(2), cw, ch, _m, sFOCUS, sHOVER);
draw_sprite_stretched_ext(THEME.color_picker_sample, 0, cx + ui(2), yy + ui(2 + 2), cw - ui(4), ch - ui(4), val, 1);
if(b == 2) {
var dialog = dialogCall(o_dialog_color_selector, WIN_W / 2, WIN_H / 2);
dialog.selector.setColor(val);
self.key = key;
dialog.onApply = function(color) {
variable_struct_set(COLORS, self.key, color);
overrideColor();
};
dialog.selector.onApply = dialog.onApply;
}
yy += th + padd + ui(8);
hh += th + padd + ui(8);
ind++;
}
return hh;
});
2022-09-23 13:28:42 +02:00
2022-11-18 03:20:31 +01:00
function overrideColor() {
var path = "data/themes/" + PREF_MAP[? "theme"] + "/override.json";
var f = file_text_open_write(path);
file_text_write_string(f, json_stringify(COLORS));
file_text_close(f);
}
#endregion
#region draw
current_list = pref_global;
2022-01-13 05:24:03 +01:00
2022-11-18 03:20:31 +01:00
sp_pref = new scrollPane(dialog_w - ui(192), dialog_h - ui(88), function(_y, _m, _r) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2022-01-13 05:24:03 +01:00
var hh = 0;
2022-11-03 11:44:49 +01:00
var th = TEXTBOX_HEIGHT;
var x1 = dialog_w - ui(200);
var yy = _y + ui(8);
var padd = ui(6);
2022-09-21 06:09:40 +02:00
var ind = 0;
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(current_list); i++) {
var _pref = current_list[| i];
2022-09-21 06:09:40 +02:00
if(is_string(_pref)) {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub);
2022-11-03 11:44:49 +01:00
draw_text(ui(16), yy, _pref);
yy += string_height(_pref) + ui(8);
hh += string_height(_pref) + ui(8);
2022-09-21 06:09:40 +02:00
ind = 0;
continue;
}
var name = _pref[0];
2022-11-18 03:20:31 +01:00
if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0)
continue;
if(ind % 2 == 0)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, yy - padd, sp_pref.w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
2022-01-13 05:24:03 +01:00
2022-11-18 03:20:31 +01:00
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text(ui(8), yy + th / 2, _pref[0]);
_pref[2].active = sFOCUS;
_pref[2].hover = sHOVER;
2022-01-13 05:24:03 +01:00
2022-11-18 03:20:31 +01:00
switch(instanceof(_pref[2])) {
case "textBox" :
_pref[2].draw(x1 - ui(4), yy + th / 2, ui(88), th, PREF_MAP[? _pref[1]], _m,, fa_right, fa_center);
break;
case "checkBox" :
_pref[2].draw(x1 - ui(48), yy + th / 2, PREF_MAP[? _pref[1]], _m,, fa_center, fa_center);
break;
case "slider" :
_pref[2].draw(x1 - ui(4), yy + th / 2, ui(200), th, PREF_MAP[? _pref[1]], _m, ui(88), fa_right, fa_center);
break;
case "scrollBox" :
var _w = ui(200);
var _h = th;
_pref[2].align = fa_left;
_pref[2].draw(x1 - ui(4) - _w, yy + th / 2 - _h / 2, _w, _h, PREF_MAP[? _pref[1]], _m, _r[0], _r[1]);
break;
2022-01-13 05:24:03 +01:00
}
2022-11-18 03:20:31 +01:00
yy += th + padd + ui(8);
hh += th + padd + ui(8);
ind++;
2022-01-13 05:24:03 +01:00
}
return hh;
});
#endregion
#region search
tb_search = new textBox(TEXTBOX_INPUT.text, function(str) {
search_text = str;
});
search_text = "";
#endregion
#region hotkey
2022-09-21 06:09:40 +02:00
vk_list = [
vk_left, vk_right, vk_up, vk_down, vk_space, vk_backspace, vk_tab, vk_home, vk_end, vk_delete, vk_insert,
2022-01-13 05:24:03 +01:00
vk_pageup, vk_pagedown, vk_pause, vk_printscreen,
vk_f1, vk_f2, vk_f3, vk_f4, vk_f5, vk_f6, vk_f7, vk_f8, vk_f9, vk_f10, vk_f11, vk_f12,
2022-09-21 06:09:40 +02:00
];
2022-01-13 05:24:03 +01:00
hk_editing = noone;
2022-11-03 11:44:49 +01:00
sp_hotkey = new scrollPane(dialog_w - ui(192), dialog_h - ui(88), function(_y, _m) {
2022-11-18 03:20:31 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
2022-11-03 11:44:49 +01:00
var padd = ui(8);
2022-01-13 05:24:03 +01:00
var hh = 0;
var currGroup = -1;
2022-11-03 11:44:49 +01:00
var x1 = dialog_w - ui(192);
2022-01-13 05:24:03 +01:00
for(var j = 0; j < ds_list_size(HOTKEY_CONTEXT); j++) {
var ll = HOTKEYS[? HOTKEY_CONTEXT[| j]];
for(var i = 0; i < ds_list_size(ll); i++) {
var key = ll[| i];
var group = key.context;
var name = key.name;
var pkey = key.key;
//var modi = key.modi;
if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0)
continue;
if(group != currGroup) {
2022-11-03 11:44:49 +01:00
if(group != "") hh += ui(12);
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub);
2022-11-03 11:44:49 +01:00
draw_text(ui(16), _y + hh, group == ""? "Global" : group);
2022-01-13 05:24:03 +01:00
2022-11-03 11:44:49 +01:00
hh += string_height("l") + ui(16);
2022-01-13 05:24:03 +01:00
currGroup = group;
}
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_top);
2022-01-13 05:24:03 +01:00
var th = string_height("l");
if(i % 2 == 0) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y + hh - padd,
sp_hotkey.w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
2022-01-13 05:24:03 +01:00
}
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(ui(16), _y + hh, name);
2022-01-13 05:24:03 +01:00
var dk = key_get_name(key.key, key.modi);
var kw = string_width(dk);
if(hk_editing == key) {
var _mod_prs = 0;
if(keyboard_check(vk_control)) _mod_prs |= MOD_KEY.ctrl;
if(keyboard_check(vk_shift)) _mod_prs |= MOD_KEY.shift;
if(keyboard_check(vk_alt)) _mod_prs |= MOD_KEY.alt;
if(keyboard_check_pressed(vk_escape)) {
key.key = "";
key.modi = 0;
PREF_SAVE();
} else if(keyboard_check_pressed(vk_anykey)) {
var press = false;
for(var a = 32; a <= 126; a++) {
if(keyboard_check_pressed(a)) {
key.key = ord(string_upper(ansi_char(a)));
press = true;
break;
}
}
if(!press) {
for(var a = 0; a < array_length(vk_list); a++) {
if(keyboard_check_pressed(vk_list[a])) {
key.key = vk_list[a];
press = true;
break;
}
}
}
if(press) key.modi = _mod_prs;
PREF_SAVE();
}
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.button_hide, 2, x1 - ui(40) - kw, _y + hh - ui(6), kw + ui(32), th + ui(12));
2022-01-13 05:24:03 +01:00
} else {
2022-11-18 03:20:31 +01:00
if(buttonInstant(THEME.button_hide, x1 - ui(40) - kw, _y + hh - ui(6), kw + ui(32), th + ui(12), _m, sFOCUS, sHOVER) == 2) {
2022-01-13 05:24:03 +01:00
hk_editing = key;
keyboard_lastchar = pkey;
}
}
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_right, fa_top, hk_editing == key? COLORS._main_text_accent : COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(x1 - ui(24), _y + hh, dk);
2022-01-13 05:24:03 +01:00
hh += th + padd * 2;
}
}
return hh;
})
2022-11-18 03:20:31 +01:00
#endregion