Pixel-Composer/scripts/node_global/node_global.gml

287 lines
8.1 KiB
Plaintext
Raw Normal View History

2024-03-14 14:35:19 +01:00
function variable_editor(nodeVal) constructor {
2023-02-14 05:32:32 +01:00
value = nodeVal;
2023-05-28 20:00:51 +02:00
val_type = [ VALUE_TYPE.integer, VALUE_TYPE.float, VALUE_TYPE.boolean, VALUE_TYPE.color, VALUE_TYPE.gradient, VALUE_TYPE.path, VALUE_TYPE.curve, VALUE_TYPE.text ];
val_type_name = [ "Integer", "Float", "Boolean", "Color", "Gradient", "Path", "Curve", "Text" ];
2023-03-07 14:29:47 +01:00
display_list = [
/*Integer*/ [ "Default", "Range", "Rotation", "Rotation range", "Slider", "Slider range", "Padding", "Vector2", "Vector3", "Vector4", "Vector range", "Vector2 range", "Area" ],
/*Float*/ [ "Default", "Range", "Rotation", "Rotation range", "Slider", "Slider range", "Padding", "Vector2", "Vector3", "Vector4", "Vector range", "Vector2 range", "Area" ],
2023-02-14 05:32:32 +01:00
/*Boolean*/ [ "Default" ],
/*Color*/ [ "Default", "Palette" ],
/*Gradient*/[ "Default" ],
2023-03-07 14:29:47 +01:00
/*Path*/ [ "Import", "Export", "Font" ],
2023-02-14 05:32:32 +01:00
/*Curve*/ [ "Default", ],
/*Text*/ [ "Default", ],
]
2023-07-12 21:00:05 +02:00
tb_name = new textBox(TEXTBOX_INPUT.text, function(str) {
2023-03-08 07:35:51 +01:00
value_name = str;
value.name = str;
2023-04-21 19:08:10 +02:00
if(string_pos(" ", value.name))
noti_warning("Global variable name can't have space.");
2023-10-02 10:45:30 +02:00
RENDER_ALL
2023-03-08 07:35:51 +01:00
});
vb_range = new vectorBox(2, function(value, index) {
slider_range[index] = value;
2023-09-26 14:35:25 +02:00
refreshInput();
2023-03-08 07:35:51 +01:00
});
tb_step = new textBox(TEXTBOX_INPUT.number, function(value) {
slider_step = value;
2023-09-26 14:35:25 +02:00
refreshInput();
2023-03-08 07:35:51 +01:00
});
2023-02-14 05:32:32 +01:00
sc_type = new scrollBox(val_type_name, function(value) {
type_index = value;
sc_disp.data_list = display_list[value];
2023-03-07 14:29:47 +01:00
disp_index = 0;
refreshInput();
2023-03-08 07:35:51 +01:00
2023-10-02 10:45:30 +02:00
RENDER_ALL
2023-02-14 05:32:32 +01:00
} );
2023-03-07 14:29:47 +01:00
sc_type.update_hover = false;
2023-02-14 05:32:32 +01:00
sc_disp = new scrollBox(display_list[0], function(value) {
disp_index = value;
2023-03-07 14:29:47 +01:00
refreshInput();
2023-03-08 07:35:51 +01:00
2023-10-02 10:45:30 +02:00
RENDER_ALL
2023-03-07 14:29:47 +01:00
} );
sc_disp.update_hover = false;
2023-04-15 14:48:29 +02:00
value_name = "NewValue";
2023-03-07 14:29:47 +01:00
type_index = 0;
_type_index = 0;
disp_index = 0;
_disp_index = 0;
2023-03-08 07:35:51 +01:00
slider_range = [ 0, 1 ];
slider_step = 0.01;
2024-03-14 14:35:19 +01:00
static refreshInput = function() { #region
2023-10-07 16:23:40 +02:00
value.setType(val_type[type_index]);
2023-03-07 14:29:47 +01:00
value.name = value_name;
if(_type_index != type_index || _disp_index != disp_index) {
switch(value.type) {
case VALUE_TYPE.integer :
case VALUE_TYPE.float :
switch(sc_disp.data_list[disp_index]) {
case "Vector2" :
2024-03-14 14:35:19 +01:00
case "Range" :
2023-03-07 14:29:47 +01:00
case "Vector range" :
case "Slider range" :
case "Rotation range" :
value.setValue([0, 0]);
break;
case "Vector3" :
value.setValue([0, 0, 0]);
break;
case "Vector4" :
2023-09-26 14:35:25 +02:00
case "Vector2 range" :
2023-03-07 14:29:47 +01:00
case "Padding" :
value.setValue([0, 0, 0, 0]);
break;
case "Area" :
value.setValue([0, 0, 0, 0, 0]);
break;
default :
value.setValue(0);
break;
}
break;
case VALUE_TYPE.color :
switch(sc_disp.data_list[disp_index]) {
case "Palette" :
value.setValue([0]);
break;
default :
value.setValue(0);
break;
}
break;
2023-05-28 20:00:51 +02:00
case VALUE_TYPE.gradient :
value.setValue(new gradientObject(c_black));
break;
2023-03-07 14:29:47 +01:00
case VALUE_TYPE.boolean :
value.setValue(false);
break;
case VALUE_TYPE.text :
case VALUE_TYPE.path :
value.setValue("");
break;
case VALUE_TYPE.curve :
value.setValue(CURVE_DEF_01);
break;
}
}
2024-03-14 14:35:19 +01:00
_type_index = type_index;
_disp_index = disp_index;
2023-03-07 14:29:47 +01:00
switch(sc_disp.data_list[disp_index]) {
2023-02-14 05:32:32 +01:00
case "Default" : value.setDisplay(VALUE_DISPLAY._default); break;
case "Range" : value.setDisplay(VALUE_DISPLAY.range); break;
case "Rotation" : value.setDisplay(VALUE_DISPLAY.rotation); break;
case "Rotation range" : value.setDisplay(VALUE_DISPLAY.rotation_range); break;
case "Slider" :
value.setDisplay(VALUE_DISPLAY.slider, { range: [slider_range[0], slider_range[1], slider_step] });
2023-02-14 05:32:32 +01:00
break;
case "Slider range" :
value.setDisplay(VALUE_DISPLAY.slider_range, { range: [slider_range[0], slider_range[1], slider_step] });
2023-02-14 05:32:32 +01:00
break;
case "Padding" : value.setDisplay(VALUE_DISPLAY.padding); break;
2023-09-26 14:35:25 +02:00
case "Vector2" :
case "Vector3" :
2023-03-07 14:29:47 +01:00
case "Vector4" : value.setDisplay(VALUE_DISPLAY.vector); break;
2023-09-26 14:35:25 +02:00
case "Vector range" :
2023-03-07 14:29:47 +01:00
case "Vector2 range" : value.setDisplay(VALUE_DISPLAY.vector_range); break;
2023-02-14 05:32:32 +01:00
case "Area" : value.setDisplay(VALUE_DISPLAY.area); break;
case "Palette" : value.setDisplay(VALUE_DISPLAY.palette); break;
2023-03-07 14:29:47 +01:00
case "Import" : value.setDisplay(VALUE_DISPLAY.path_load, { filter: "" }); break;
case "Export" : value.setDisplay(VALUE_DISPLAY.path_save, { filter: "" }); break;
case "Font" : value.setDisplay(VALUE_DISPLAY.path_font); break;
2023-02-14 05:32:32 +01:00
}
2024-03-14 14:35:19 +01:00
} #endregion
2023-03-08 07:35:51 +01:00
2024-03-14 14:35:19 +01:00
static draw = function(_x, _y, _w, _m, _focus, _hover) { #region
2023-03-08 07:35:51 +01:00
var _h = 0;
switch(sc_disp.data_list[disp_index]) {
case "Slider" :
case "Slider range" :
var wd_h = ui(32);
var lb_w = ui(72);
2023-06-21 20:36:53 +02:00
vb_range.setFocusHover(_focus, _hover);
tb_step.setFocusHover(_focus, _hover);
2023-03-08 07:35:51 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
draw_text(_x + ui(8), _y + wd_h / 2, __txt("Range"));
2023-03-08 07:35:51 +01:00
vb_range.draw(_x + lb_w, _y, _w - lb_w, wd_h, slider_range, noone, _m);
2023-03-08 07:35:51 +01:00
_h += wd_h + ui(4);
_y += wd_h + ui(4);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
draw_text(_x + ui(8), _y + wd_h / 2, __txt("Step"));
2023-03-08 07:35:51 +01:00
tb_step.draw(_x + lb_w, _y, _w - lb_w, wd_h, slider_step , _m);
_h += wd_h + ui(8);
_y += wd_h + ui(8);
break;
}
return _h;
2024-03-14 14:35:19 +01:00
} #endregion
}
2023-02-14 05:32:32 +01:00
2023-03-07 14:29:47 +01:00
function Node_Global(_x = 0, _y = 0) : __Node_Base(_x, _y) constructor {
2023-07-06 19:49:16 +02:00
name = "GLOBAL";
2023-05-03 21:42:17 +02:00
display_name = "";
2022-01-13 05:24:03 +01:00
node_id = 0;
group = noone;
2023-10-02 14:41:44 +02:00
use_cache = CACHE_USE.none;
value = ds_map_create();
2022-01-13 05:24:03 +01:00
input_display_list = -1;
2023-05-03 21:42:17 +02:00
anim_priority = -999;
2022-01-13 05:24:03 +01:00
2024-02-12 10:25:23 +01:00
static valueUpdate = function(index) { RENDER_ALL }
2023-03-08 07:35:51 +01:00
static createValue = function() { #region
2023-05-03 21:42:17 +02:00
var _in = nodeValue("NewValue", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
_in.editor = new variable_editor(_in);
2023-03-07 14:29:47 +01:00
ds_list_add(inputs, _in);
return _in;
} #endregion
2023-03-07 14:29:47 +01:00
static inputExist = function(key) { #region
2023-03-08 07:35:51 +01:00
return ds_map_exists(value, key);
} #endregion
2023-03-08 07:35:51 +01:00
static inputGetable = function(from, key) { #region
2023-03-08 07:35:51 +01:00
if(!inputExist(key)) return false;
var to = value[? key];
if(!typeCompatible(from.type, to.type))
return false;
if(typeIncompatible(from, to))
return false;
return true;
} #endregion
2023-03-08 07:35:51 +01:00
static getInput = function(key, def = noone) { #region
2023-03-07 14:29:47 +01:00
if(!ds_map_exists(value, key)) return def;
return value[? key];
} #endregion
2023-02-14 05:32:32 +01:00
static step = function() { #region
2023-02-14 05:32:32 +01:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
2023-04-21 19:08:10 +02:00
var _inp = inputs[| i];
value[? _inp.name] = _inp;
var val = true;
if(string_pos(" ", _inp.name)) val = false;
_inp.editor.tb_name.boxColor = val? c_white : COLORS._main_value_negative;
2023-02-14 05:32:32 +01:00
}
} #endregion
2022-01-13 05:24:03 +01:00
static serialize = function() { #region
2023-06-13 14:42:06 +02:00
var _map = {};
2023-03-07 14:29:47 +01:00
2023-06-13 14:42:06 +02:00
var _inputs = [];
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(inputs); i++) {
2023-03-07 14:29:47 +01:00
var _ser = inputs[| i].serialize();
2023-06-13 14:42:06 +02:00
_ser.global_type = inputs[| i].editor.type_index;
_ser.global_disp = inputs[| i].editor.disp_index;
_ser.global_name = inputs[| i].editor.value_name;
_ser.global_s_range = inputs[| i].editor.slider_range;
_ser.global_s_step = inputs[| i].editor.slider_step;
2023-03-07 14:29:47 +01:00
2023-06-13 14:42:06 +02:00
array_push(_inputs, _ser);
2022-01-13 05:24:03 +01:00
}
2023-03-07 14:29:47 +01:00
2023-06-13 14:42:06 +02:00
_map.inputs = _inputs;
_map.attri = attributes;
2022-01-13 05:24:03 +01:00
return _map;
} #endregion
2022-01-13 05:24:03 +01:00
static deserialize = function(_map) { #region
2023-06-13 14:42:06 +02:00
var _inputs = _map.inputs;
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
for(var i = 0; i < array_length(_inputs); i++) {
2024-02-12 10:25:23 +01:00
var _des = _inputs[i];
var _in = createValue();
var _name = struct_try_get(_des, "global_name", "");
2023-03-08 07:35:51 +01:00
2023-06-13 14:42:06 +02:00
_in.editor.type_index = struct_try_get(_des, "global_type", 0);
_in.editor.disp_index = struct_try_get(_des, "global_disp", 0);
_in.editor.disp_index = struct_try_get(_des, "global_disp", 0);
2024-02-12 10:25:23 +01:00
_in.editor.value_name = _name;
2023-03-08 07:35:51 +01:00
2023-06-13 14:42:06 +02:00
_in.editor.slider_range = _des.global_s_range;
_in.editor.slider_step = struct_try_get(_des, "global_s_step", 0.01);
2023-03-08 07:35:51 +01:00
_in.editor.refreshInput();
_in.applyDeserialize(_des);
2024-02-12 10:25:23 +01:00
if(struct_has(PROGRAM_ARGUMENTS, _name)) _in.setValue(PROGRAM_ARGUMENTS[$ _name]);
2022-01-13 05:24:03 +01:00
}
2023-03-08 07:35:51 +01:00
if(struct_has(_map, "attr")) struct_override(attributes, _map.attr);
2023-03-08 07:35:51 +01:00
step();
} #endregion
2022-01-13 05:24:03 +01:00
}