Pixel-Composer/objects/o_dialog_preset/Create_0.gml

83 lines
2.2 KiB
Plaintext
Raw Normal View History

2022-12-10 05:06:01 +01:00
/// @description init
event_inherited();
#region data
dialog_w = ui(240);
dialog_h = ui(400);
node = noone;
destroy_on_click_out = true;
anchor = ANCHOR.left | ANCHOR.top;
adding = false;
add_txt = "";
tb_add = new textBox(TEXTBOX_INPUT.text, function(txt) /*=>*/ { add_txt = txt; newPresetFromNode(txt); adding = false; });
2022-12-10 05:06:01 +01:00
#endregion
#region content
2023-02-28 09:43:01 +01:00
sc_presets = new scrollPane(dialog_w - ui(padding + padding), dialog_h - ui(title_height + padding), function(_y, _m) {
2022-12-10 05:06:01 +01:00
draw_clear_alpha(COLORS.panel_bg_clear, 0);
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, sc_presets.surface_w, TEXTBOX_HEIGHT, add_txt);
_h += _wh + ui(4);
_y += _wh + ui(4);
}
2022-12-10 05:06:01 +01:00
var folder = instanceof(node);
if(!ds_map_exists(global.PRESETS_MAP, folder)) return 0;
var pres = global.PRESETS_MAP[? folder];
2023-04-22 16:23:51 +02:00
var amo = array_length(pres);
2023-05-28 20:00:51 +02:00
var hh = line_get_height() + ui(8);
_h += amo * (hh + ui(4)) + ui(32);
2022-12-10 05:06:01 +01:00
for( var i = 0; i < amo; i++ ) {
var preset = pres[i];
2023-04-22 16:23:51 +02:00
var _yy = _y + (hh + ui(4)) * i;
2022-12-10 05:06:01 +01:00
2022-12-19 13:35:30 +01:00
if(sHOVER && sc_presets.hover && point_in_rectangle(_m[0], _m[1], 0, _yy, sc_presets.w, _yy + hh)) {
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _yy, sc_presets.w - ui(12), hh, COLORS._main_icon, 0.85);
2022-12-10 05:06:01 +01:00
if(mouse_click(mb_left, sFOCUS)) {
node.deserialize(preset.content, true, true);
instance_destroy();
}
if(mouse_click(mb_right, sFOCUS)) {
2023-05-03 21:42:17 +02:00
var dia = menuCall("preset_window_menu",,, [
2023-06-05 18:27:53 +02:00
menuItem(__txt("Delete"), function() {
2022-12-10 05:06:01 +01:00
file_delete(o_dialog_menubox.path);
__initPresets();
2023-02-19 02:13:19 +01:00
}),
],, preset);
2023-02-19 02:13:19 +01:00
dia.path = preset.path;
2022-12-10 05:06:01 +01:00
}
}
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(8), _yy + hh / 2, preset.name);
2022-12-10 05:06:01 +01:00
}
return _h;
});
2022-12-10 05:06:01 +01:00
#endregion
#region new preset
function newPresetFromNode(name) {
if(node == noone) return;
2023-08-06 16:00:59 +02:00
var dir = $"{DIRECTORY}Presets/{instanceof(node)}/";
directory_verify(dir);
2022-12-10 05:06:01 +01:00
var pth = dir + name + ".json";
var map = node.serialize(true, true);
2023-08-06 16:00:59 +02:00
json_save_struct(pth, map);
2022-12-10 05:06:01 +01:00
__initPresets();
}
#endregion