Pixel-Composer/scripts/panel_function/panel_function.gml

360 lines
11 KiB
Plaintext
Raw Normal View History

2022-01-19 04:16:28 +01:00
#region data
globalvar PANEL_MAIN, PANEL_MENU, PANEL_PREVIEW, PANEL_INSPECTOR, PANEL_GRAPH, PANEL_ANIMATION, PANEL_COLLECTION;
2022-11-14 03:16:15 +01:00
globalvar FULL_SCREEN_CONTENT;
2022-01-19 04:16:28 +01:00
PANEL_MAIN = 0;
2022-11-14 03:16:15 +01:00
FULL_SCREEN_CONTENT = noone;
2022-01-19 04:16:28 +01:00
#endregion
2022-09-21 06:09:40 +02:00
#region panel class
enum PANEL_CONTENT {
empty,
splith,
splitv,
menu,
inspector,
animation,
preview,
graph,
collection
}
2023-03-12 02:28:21 +01:00
#macro PANEL_PADDING padding = in_dialog? ui(24) : ui(16); \
title_height = in_dialog? ui(64) : ui(56);
2023-03-19 09:17:39 +01:00
#macro PANEL_TITLE draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_title); \
draw_text_over(in_dialog? ui(56) : ui(24), title_height / 2 - (!in_dialog) * ui(4), title);
2022-09-21 06:09:40 +02:00
#endregion
2022-01-19 04:16:28 +01:00
#region functions
function clearPanel() {
delete PANEL_MAIN;
delete PANEL_MENU;
delete PANEL_INSPECTOR;
delete PANEL_PREVIEW;
delete PANEL_GRAPH;
2022-12-10 05:06:01 +01:00
delete PANEL_COLLECTION;
2022-01-19 04:16:28 +01:00
PANEL_MAIN = 0;
PANEL_MENU = 0;
PANEL_INSPECTOR = 0;
PANEL_PREVIEW = 0;
PANEL_GRAPH = 0;
2022-12-10 05:06:01 +01:00
PANEL_COLLECTION = 0;
2022-01-19 04:16:28 +01:00
}
2023-03-13 10:45:56 +01:00
function getPanelFromName(name, create = false) {
2023-03-11 01:40:17 +01:00
switch(name) {
2023-03-13 10:45:56 +01:00
case "Panel_Menu" : return (create || findPanel(name))? new Panel_Menu() : PANEL_MENU;
case "Panel_Inspector" : return (create || findPanel(name))? new Panel_Inspector() : PANEL_INSPECTOR;
case "Panel_Animation" : return (create || findPanel(name))? new Panel_Animation() : PANEL_ANIMATION;
case "Panel_Preview" : return (create || findPanel(name))? new Panel_Preview() : PANEL_PREVIEW;
case "Panel_Graph" : return (create || findPanel(name))? new Panel_Graph() : PANEL_GRAPH;
2023-03-12 02:28:21 +01:00
2023-03-13 10:45:56 +01:00
case "Panel_Collection" : return new Panel_Collection();
case "Panel_Workspace" : return new Panel_Workspace();
case "Panel_Tunnels" : return new Panel_Tunnels();
case "Panel_History" : return new Panel_History();
case "Panel_Notification" : return new Panel_Notification();
case "Panel_Nodes" : return new Panel_Nodes();
2023-03-19 09:17:39 +01:00
case "Panel_Globalvar" : return new Panel_Globalvar();
2023-03-25 12:27:04 +01:00
case "Panel_Color" : return new Panel_Color();
2023-03-28 06:58:28 +02:00
case "Panel_Palette" : return new Panel_Palette();
case "Panel_Gradient" : return new Panel_Gradient();
2023-03-11 01:40:17 +01:00
}
return noone;
}
2023-03-19 09:17:39 +01:00
function loadPanelStruct(panel, str) {
var cont = str.content;
if(variable_struct_exists(str, "split")) {
var pan = panel;
if(str.split == "v")
pan = panel.split_v(ui(str.width));
else if(str.split == "h")
pan = panel.split_h(ui(str.width));
if(pan != noone) {
loadPanelStruct(pan[0], cont[0]);
loadPanelStruct(pan[1], cont[1]);
}
} else {
if(!is_array(cont)) cont = [ cont ];
for( var i = 0; i < array_length(cont); i++ ) {
var _cont = getPanelFromName(cont[i])
if(_cont != noone) panel.setContent(_cont);
}
}
}
2023-03-11 01:40:17 +01:00
function loadPanel(path, panel) {
2023-03-11 06:40:34 +01:00
CURRENT_PANEL = json_load_struct(path);
loadPanelStruct(panel, CURRENT_PANEL.panel);
}
2023-03-13 10:45:56 +01:00
function panelAdd(panel, create = false) {
var pan = getPanelFromName(panel, create);
2023-03-21 03:01:53 +01:00
if(pan == noone) return noone;
return dialogPanelCall(pan);
2023-03-11 01:40:17 +01:00
}
2023-03-11 06:40:34 +01:00
function panelObjectInit() {
PANEL_MAIN = new Panel(noone, ui(2), ui(2), WIN_SW - ui(4), WIN_SH - ui(4));
PANEL_MENU = new Panel_Menu();
PANEL_INSPECTOR = new Panel_Inspector();
PANEL_ANIMATION = new Panel_Animation();
PANEL_PREVIEW = new Panel_Preview();
PANEL_GRAPH = new Panel_Graph();
2022-11-14 03:16:15 +01:00
PANEL_COLLECTION = new Panel_Collection();
2023-03-11 06:40:34 +01:00
}
function resetPanel() {
clearPanel();
panelObjectInit();
loadPanelStruct(PANEL_MAIN, CURRENT_PANEL.panel);
PANEL_MAIN.refresh();
}
function setPanel() {
globalvar CURRENT_PANEL;
panelObjectInit();
2023-03-13 10:45:56 +01:00
if(!directory_exists(DIRECTORY + "layouts"))
zip_unzip("data/layouts.zip", DIRECTORY);
2023-03-11 06:40:34 +01:00
var file = DIRECTORY + "layouts/" + PREF_MAP[? "panel_layout_file"] + ".json";
if(!file_exists(file))
file = DIRECTORY + "layouts/Horizontal.json";
loadPanel(file, PANEL_MAIN);
2022-01-19 04:16:28 +01:00
PANEL_ANIMATION.updatePropertyList();
PANEL_MAIN.refresh();
2023-03-23 13:38:50 +01:00
PANEL_MAIN.refreshSize();
2022-01-19 04:16:28 +01:00
}
2023-03-12 02:28:21 +01:00
function findPanel(_type, _pane = PANEL_MAIN) {
var pan = _findPanel(_type, _pane);
if(pan) return pan;
with(o_dialog_panel) {
2023-03-24 09:32:08 +01:00
if(instanceof(content) == _type)
return content;
2023-03-12 02:28:21 +01:00
}
return noone;
}
function _findPanel(_type, _pane, _res = noone) {
2023-02-14 02:51:14 +01:00
if(instanceof(_pane) != "Panel")
2022-01-19 04:16:28 +01:00
return _res;
if(!ds_exists(_pane.childs, ds_type_list))
return _res;
2023-03-19 09:17:39 +01:00
if(ds_list_size(_pane.childs) == 0) {
for( var i = 0; i < array_length(_pane.content); i++ )
if(instanceof(_pane.content[i]) == _type)
return _pane.content[i];
}
2022-01-19 04:16:28 +01:00
for(var i = 0; i < ds_list_size(_pane.childs); i++) {
2023-03-12 02:28:21 +01:00
var _re = _findPanel(_type, _pane.childs[| i], _res);
if(_re != noone) _res = _re;
2022-01-19 04:16:28 +01:00
}
return _res;
}
2023-03-11 01:40:17 +01:00
function panelInit() {
panel_dragging = noone;
panel_hovering = noone;
panel_split = 0;
2023-03-12 02:28:21 +01:00
panel_mouse = 0;
panel_draw_x0 = noone; panel_draw_x0_to = noone;
panel_draw_y0 = noone; panel_draw_y0_to = noone;
panel_draw_x1 = noone; panel_draw_x1_to = noone;
panel_draw_y1 = noone; panel_draw_y1_to = noone;
panel_draw_depth = 0;
2023-03-11 01:40:17 +01:00
}
function panelDraw() {
2023-03-12 02:28:21 +01:00
panel_draw_x0 = panel_draw_x0 == noone? panel_draw_x0_to : lerp_float(panel_draw_x0, panel_draw_x0_to, 3);
panel_draw_y0 = panel_draw_y0 == noone? panel_draw_y0_to : lerp_float(panel_draw_y0, panel_draw_y0_to, 3);
panel_draw_x1 = panel_draw_x1 == noone? panel_draw_x1_to : lerp_float(panel_draw_x1, panel_draw_x1_to, 3);
panel_draw_y1 = panel_draw_y1 == noone? panel_draw_y1_to : lerp_float(panel_draw_y1, panel_draw_y1_to, 3);
panel_draw_depth = lerp_float(panel_draw_depth, panel_split == 4, 3);
if(panel_draw_x0_to != noone) {
draw_set_color(COLORS._main_accent);
if(panel_split == 4) {
var dist = ui(8) * panel_draw_depth;
draw_set_alpha(.2);
draw_roundrect_ext(panel_draw_x0 - dist, panel_draw_y0 - dist, panel_draw_x1 - dist, panel_draw_y1 - dist, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(panel_draw_x0 - dist, panel_draw_y0 - dist, panel_draw_x1 - dist, panel_draw_y1 - dist, 8, 8, true);
draw_set_alpha(.2);
draw_roundrect_ext(panel_draw_x0 + dist, panel_draw_y0 + dist, panel_draw_x1 + dist, panel_draw_y1 + dist, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(panel_draw_x0 + dist, panel_draw_y0 + dist, panel_draw_x1 + dist, panel_draw_y1 + dist, 8, 8, true);
} else {
draw_set_alpha(.4);
draw_roundrect_ext(panel_draw_x0, panel_draw_y0, panel_draw_x1, panel_draw_y1, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(panel_draw_x0, panel_draw_y0, panel_draw_x1, panel_draw_y1, 8, 8, true);
}
}
2023-03-11 01:40:17 +01:00
if(panel_dragging) {
draw_surface_ext(panel_dragging.dragSurface, mouse_mx + 8, mouse_my + 8, 0.5, 0.5, 0, c_white, 0.5);
2023-03-12 02:28:21 +01:00
if((panel_mouse == 0 && mouse_release(mb_left)) || (panel_mouse == 1 && mouse_press(mb_left))) {
2023-03-11 01:40:17 +01:00
var p = [];
2023-03-19 09:17:39 +01:00
if(panel_split == 4) {
if(panel_hovering == PANEL_MAIN) { //pop out
var panel = instanceof(panel_dragging) == "Panel"? panel_dragging.content : panel_dragging;
dialogPanelCall(panel);
} else
panel_hovering.setContent(panel_dragging, true);
2023-03-12 02:28:21 +01:00
} else if(panel_hovering == PANEL_MAIN) { //split main panel
2023-03-11 06:40:34 +01:00
var panel = new Panel(noone, ui(2), ui(2), WIN_SW - ui(4), WIN_SH - ui(4));
var main = PANEL_MAIN;
switch(panel_split) {
case 0 : p = panel.split_v( panel.h / 2); break;
case 1 : p = panel.split_h( panel.w / 2); break;
case 2 : p = panel.split_h( panel.w / 2); break;
case 3 : p = panel.split_v( panel.h / 2); break;
}
panel.parent.childs[| (panel_split + 1) % 2] = main;
main.parent = panel.parent;
2023-03-19 09:17:39 +01:00
panel.parent.childs[| (panel_split + 0) % 2].setContent(panel_dragging);
2023-03-11 06:40:34 +01:00
PANEL_MAIN.refreshSize();
} else {
var c = panel_hovering.content;
2023-03-19 09:17:39 +01:00
panel_hovering.content = [];
2023-03-11 06:40:34 +01:00
switch(panel_split) {
case 0 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
case 1 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 2 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 3 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
}
2023-03-11 01:40:17 +01:00
2023-03-19 09:17:39 +01:00
p[(panel_split + 1) % 2].setContent(c);
p[(panel_split + 0) % 2].setContent(panel_dragging);
2023-03-11 06:40:34 +01:00
panel_hovering.refreshSize();
}
2023-03-11 01:40:17 +01:00
panel_hovering = noone;
panel_dragging = noone;
2023-03-12 02:28:21 +01:00
panel_draw_x0 = noone; panel_draw_x0_to = noone;
panel_draw_y0 = noone; panel_draw_y0_to = noone;
panel_draw_x1 = noone; panel_draw_x1_to = noone;
panel_draw_y1 = noone; panel_draw_y1_to = noone;
panel_draw_depth = 0;
2023-03-11 01:40:17 +01:00
}
}
}
function panelSerialize() {
2023-03-11 06:40:34 +01:00
var cont = {};
cont.panel = _panelSerialize(PANEL_MAIN);
return cont;
2023-03-11 01:40:17 +01:00
}
function _panelSerialize(panel) {
var cont = {};
2023-03-11 06:40:34 +01:00
var ind = 0;
2023-03-11 01:40:17 +01:00
2023-03-19 09:17:39 +01:00
cont.content = [];
2023-03-11 06:40:34 +01:00
if(panel.split != "" && ds_list_size(panel.childs) == 2) {
cont.split = panel.split;
if(panel.split == "h") {
ind = panel.childs[| 1].w < panel.childs[| 0].w;
cont.width = panel.childs[| ind].w * (panel.childs[| ind].x == panel.x? 1 : -1);
} else {
ind = panel.childs[| 1].h < panel.childs[| 0].h;
cont.width = panel.childs[| ind].h * (panel.childs[| ind].y == panel.y? 1 : -1);
}
ind = panel.childs[| 1].x == panel.x && panel.childs[| 1].y == panel.y;
for( var i = 0; i < ds_list_size(panel.childs); i++ )
cont.content[i] = _panelSerialize(panel.childs[| (ind + i) % 2]);
2023-03-19 09:17:39 +01:00
} else {
for( var i = 0; i < array_length(panel.content); i++ )
cont.content[i] = instanceof(panel.content[i]);
}
2023-03-11 06:40:34 +01:00
return cont;
}
function panelSerializeArray() {
return _panelSerializeArray(PANEL_MAIN);
}
function _panelSerializeArray(panel) {
var cont = [];
2023-03-11 01:40:17 +01:00
2023-03-19 09:17:39 +01:00
if(!ds_list_empty(panel.childs)) {
2023-03-11 06:40:34 +01:00
for( var i = 0; i < ds_list_size(panel.childs); i++ )
cont[i] = _panelSerializeArray(panel.childs[| i]);
2023-03-19 09:17:39 +01:00
} else {
for( var i = 0; i < array_length(panel.content); i++ )
cont[i] = instanceof(panel.content[i]);
}
2023-03-11 01:40:17 +01:00
return cont;
}
2022-11-14 03:16:15 +01:00
#endregion
#region fullscreen
function set_focus_fullscreen() {
if(FULL_SCREEN_CONTENT != noone) {
2023-03-19 09:17:39 +01:00
PANEL_MAIN.childs[| 1].content = [];
2022-11-14 03:16:15 +01:00
FULL_SCREEN_CONTENT = noone;
2022-12-27 04:00:50 +01:00
PANEL_MAIN.refreshSize();
2022-11-14 03:16:15 +01:00
return;
}
var panel = PREF_MAP[? "expand_hover"]? HOVER : FOCUS;
if(panel == noone) return;
if(!is_struct(panel)) return;
if(instanceof(panel) != "Panel") return;
2023-03-19 09:17:39 +01:00
if(array_length(panel.content) == 0) return;
2022-11-14 03:16:15 +01:00
if(!panel.content.expandable) return;
2023-03-19 09:17:39 +01:00
PANEL_MAIN.childs[| 1].setContent(panel.content);
2022-11-14 03:16:15 +01:00
FULL_SCREEN_CONTENT = panel;
}
#endregion
#region function
function panelHover(content) {
2023-03-19 09:17:39 +01:00
if(!HOVER) return false;
if(instanceof(HOVER) != "Panel") return false;
return instanceof(HOVER.getContent()) == instanceof(content);
2022-11-14 03:16:15 +01:00
}
function panelFocus(content) {
2023-03-19 09:17:39 +01:00
if(!FOCUS) return false;
if(instanceof(FOCUS) != "Panel") return false;
return instanceof(FOCUS.getContent()) == instanceof(content);
2022-11-14 03:16:15 +01:00
}
2022-01-19 04:16:28 +01:00
#endregion