Pixel-Composer/scripts/nodeValue_drawer/nodeValue_drawer.gml

258 lines
9.2 KiB
Text
Raw Normal View History

2023-03-19 09:17:39 +01:00
function drawWidgetInit() {
anim_toggling = false;
anim_hold = noone;
visi_hold = noone;
min_w = ui(160);
lineBreak = true;
}
2023-05-16 21:28:16 +02:00
function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover = false, _focus = false, _scrollPane = noone, rx = 0, ry = 0) {
2023-03-19 09:17:39 +01:00
var con_w = ww - ui(4);
var xc = xx + ww / 2;
2023-05-28 20:00:51 +02:00
var lb_h = line_get_height(f_p0) + ui(8);
2023-03-19 09:17:39 +01:00
var lb_y = yy + lb_h / 2;
var butx = xx;
2023-05-03 21:42:17 +02:00
if(jun.connect_type == JUNCTION_CONNECT.input && jun.isAnimable() && !jun.expUse) {
2023-03-21 03:01:53 +01:00
var index = jun.value_from == noone? jun.is_anim : 2;
2023-04-08 20:06:27 +02:00
draw_sprite_ui_uniform(THEME.animate_clock, index, butx, lb_y, 1, index == 2? COLORS._main_accent : c_white, 0.8);
2023-03-19 09:17:39 +01:00
if(_hover && point_in_circle(_m[0], _m[1], butx, lb_y, ui(10))) {
if(anim_hold != noone)
2023-03-21 03:01:53 +01:00
jun.setAnim(anim_hold);
2023-03-19 09:17:39 +01:00
2023-04-08 20:06:27 +02:00
draw_sprite_ui_uniform(THEME.animate_clock, index, butx, lb_y, 1, index == 2? COLORS._main_accent : c_white, 1);
2023-06-04 18:28:29 +02:00
TOOLTIP = jun.value_from == noone? __txtx("panel_inspector_toggle_anim", "Toggle animation") : __txtx("panel_inspector_remove_link", "Remove link");
2023-03-19 09:17:39 +01:00
if(mouse_press(mb_left, _focus)) {
if(jun.value_from != noone)
jun.removeFrom();
else {
2023-03-21 03:01:53 +01:00
recordAction(ACTION_TYPE.var_modify, jun.animator, [ jun.is_anim, "is_anim", jun.name + " animation" ]);
jun.setAnim(!jun.is_anim);
anim_hold = jun.is_anim;
2023-03-19 09:17:39 +01:00
}
PANEL_ANIMATION.updatePropertyList();
}
}
}
if(anim_hold != noone && mouse_release(mb_left))
anim_hold = noone;
butx += ui(20);
if(!global_var) {
2023-06-17 14:30:49 +02:00
index = jun.visible;
draw_sprite_ui_uniform(THEME.junc_visible, index, butx, lb_y, 1,, 0.8);
if(_hover && point_in_circle(_m[0], _m[1], butx, lb_y, ui(10))) {
if(visi_hold != noone)
jun.visible = visi_hold;
2023-03-19 09:17:39 +01:00
2023-06-17 14:30:49 +02:00
draw_sprite_ui_uniform(THEME.junc_visible, index, butx, lb_y, 1,, 1);
TOOLTIP = __txt("Visibility");
2023-03-19 09:17:39 +01:00
2023-06-17 14:30:49 +02:00
if(mouse_press(mb_left, _focus)) {
jun.visible = !jun.visible;
visi_hold = jun.visible;
2023-03-19 09:17:39 +01:00
}
}
} else
2023-04-15 14:48:29 +02:00
draw_sprite_ui_uniform(THEME.node_use_expression, 0, butx, lb_y, 1,, 0.8);
2023-03-19 09:17:39 +01:00
if(visi_hold != noone && mouse_release(mb_left))
visi_hold = noone;
2023-06-10 13:59:45 +02:00
var cc = COLORS._main_text_inner;
2023-04-15 14:48:29 +02:00
if(jun.expUse) {
var expValid = jun.expTree != noone && jun.expTree.validate();
cc = expValid? COLORS._main_value_positive : COLORS._main_value_negative;
}
2023-06-10 13:59:45 +02:00
if(global_var)
2023-04-21 19:08:10 +02:00
if(string_pos(" ", jun.name)) cc = COLORS._main_value_negative;
2023-07-30 19:56:53 +02:00
draw_set_text(lineBreak? f_p0 : f_p1, fa_left, fa_center, cc);
2023-03-26 07:13:36 +02:00
draw_text_add(xx + ui(40), lb_y - ui(2), jun.name);
var lb_w = string_width(jun.name) + ui(48);
2023-03-19 09:17:39 +01:00
#region tooltip
if(jun.tooltip != "") {
var tx = xx + ui(40) + string_width(jun.name) + ui(16);
var ty = lb_y - ui(1);
if(point_in_circle(_m[0], _m[1], tx, ty, ui(10))) {
if(is_string(jun.tooltip))
TOOLTIP = jun.tooltip;
else if(mouse_click(mb_left, _focus))
dialogCall(jun.tooltip);
draw_sprite_ui(THEME.info, 0, tx, ty,,,, COLORS._main_icon_light, 1);
} else
draw_sprite_ui(THEME.info, 0, tx, ty,,,, COLORS._main_icon_light, 0.75);
2023-07-30 19:56:53 +02:00
lb_w += ui(56);
2023-03-19 09:17:39 +01:00
}
#endregion
#region anim
2023-05-03 21:42:17 +02:00
if(jun.connect_type == JUNCTION_CONNECT.input && lineBreak && jun.is_anim) {
2023-03-19 09:17:39 +01:00
var bx = xx + ww - ui(12);
var by = lb_y;
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "", THEME.prop_keyframe, 2) == 2) {
for(var j = 0; j < ds_list_size(jun.animator.values); j++) {
var _key = jun.animator.values[| j];
2023-07-06 19:49:16 +02:00
if(_key.time > PROJECT.animator.current_frame) {
PROJECT.animator.setFrame(_key.time);
2023-03-19 09:17:39 +01:00
break;
}
}
}
bx -= ui(26);
var cc = COLORS.panel_animation_keyframe_unselected;
var kfFocus = false;
for(var j = 0; j < ds_list_size(jun.animator.values); j++) {
2023-07-06 19:49:16 +02:00
if(jun.animator.values[| j].time == PROJECT.animator.current_frame) {
2023-03-19 09:17:39 +01:00
cc = COLORS.panel_animation_keyframe_selected;
kfFocus = true;
break;
}
}
2023-06-04 18:28:29 +02:00
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, kfFocus? __txtx("panel_inspector_remove_key", "Remove keyframe") :
__txtx("panel_inspector_add_key", "Add keyframe"), THEME.prop_keyframe, 1, cc) == 2) {
2023-03-19 09:17:39 +01:00
var _add = false;
for(var j = 0; j < ds_list_size(jun.animator.values); j++) {
var _key = jun.animator.values[| j];
2023-07-06 19:49:16 +02:00
if(_key.time == PROJECT.animator.current_frame) {
2023-03-19 09:17:39 +01:00
if(ds_list_size(jun.animator.values) > 1)
ds_list_delete(jun.animator.values, j);
_add = true;
break;
2023-07-06 19:49:16 +02:00
} else if(_key.time > PROJECT.animator.current_frame) {
ds_list_insert(jun.animator.values, j, new valueKey(PROJECT.animator.current_frame, jun.showValue(), jun.animator));
2023-03-19 09:17:39 +01:00
_add = true;
break;
}
}
2023-07-06 19:49:16 +02:00
if(!_add) ds_list_add(jun.animator.values, new valueKey(PROJECT.animator.current_frame, jun.showValue(), jun.animator));
2023-03-19 09:17:39 +01:00
}
bx -= ui(26);
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "", THEME.prop_keyframe, 0) == 2) {
var _t = -1;
for(var j = 0; j < ds_list_size(jun.animator.values); j++) {
var _key = jun.animator.values[| j];
2023-07-06 19:49:16 +02:00
if(_key.time < PROJECT.animator.current_frame)
2023-03-19 09:17:39 +01:00
_t = _key.time;
}
2023-07-06 19:49:16 +02:00
if(_t > -1) PROJECT.animator.setFrame(_t);
2023-03-19 09:17:39 +01:00
}
var lhf = lb_h / 2 - 4;
draw_set_color(COLORS.panel_inspector_key_separator);
draw_line(bx - ui(20), by - lhf, bx - ui(20), by + lhf);
draw_set_color(COLORS.panel_inspector_key_separator);
draw_line(bx - ui(20), by - lhf, bx - ui(20), by + lhf);
bx -= ui(26 + 12);
2023-06-04 18:28:29 +02:00
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, __txtx("panel_animation_looping_mode", "Looping mode") + " " + ON_END_NAME[jun.on_end], THEME.prop_on_end, jun.on_end) == 2)
2023-03-19 09:17:39 +01:00
jun.on_end = safe_mod(jun.on_end + 1, sprite_get_number(THEME.prop_on_end));
}
#endregion
2023-05-03 21:42:17 +02:00
#region use expression
2023-03-21 03:01:53 +01:00
if(jun.connect_type == JUNCTION_CONNECT.input && lineBreak && !jun.is_anim && !global_var) {
2023-03-19 09:17:39 +01:00
var bx = xx + ww - ui(12);
var by = lb_y;
2023-04-15 14:48:29 +02:00
var ic_b = jun.expUse? c_white : COLORS._main_icon;
2023-06-04 18:28:29 +02:00
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, __txtx("panel_inspector_use_expression", "Use expression"), THEME.node_use_expression, jun.expUse, ic_b) == 2)
2023-04-15 14:48:29 +02:00
jun.expUse = !jun.expUse;
2023-06-17 14:30:49 +02:00
if(jun.expUse) {
bx -= ui(28);
var cc = NODE_DROPPER_TARGET == jun? COLORS._main_value_positive : COLORS._main_icon;
if(buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, __txtx("panel_inspector_dropper", "Node dropper"), THEME.node_dropper, 0, cc) == 2)
NODE_DROPPER_TARGET = NODE_DROPPER_TARGET == jun? noone : jun;
}
2023-03-19 09:17:39 +01:00
}
#endregion
2023-05-16 21:28:16 +02:00
2023-03-19 09:17:39 +01:00
var _hsy = yy + lb_h;
var padd = ui(8);
var labelWidth = max(lb_w, min(ui(80) + ww * 0.2, ui(200)));
var editBoxX = xx + !lineBreak * labelWidth;
var editBoxY = lineBreak? _hsy : yy;
var editBoxW = (xx + ww) - editBoxX;
var editBoxH = lineBreak? TEXTBOX_HEIGHT : lb_h;
var widH = lineBreak? editBoxH : 0;
var mbRight = true;
2023-04-15 14:48:29 +02:00
if(jun.expUse) {
var expValid = jun.expTree != noone && jun.expTree.validate();
2023-04-16 11:53:46 +02:00
jun.express_edit.boxColor = expValid? COLORS._main_value_positive : COLORS._main_value_negative;
2023-07-12 16:28:32 +02:00
jun.express_edit.rx = rx;
jun.express_edit.ry = ry;
2023-04-15 14:48:29 +02:00
2023-06-21 20:36:53 +02:00
jun.express_edit.setFocusHover(_focus, _hover);
2023-04-16 11:53:46 +02:00
if(_focus) jun.express_edit.register(_scrollPane);
2023-03-19 09:17:39 +01:00
2023-04-16 11:53:46 +02:00
var wd_h = jun.express_edit.draw(editBoxX, editBoxY, editBoxW, editBoxH, jun.expression, _m);
2023-07-28 19:41:57 +02:00
widH = wd_h - (TEXTBOX_HEIGHT * !lineBreak);
2023-03-19 09:17:39 +01:00
} else if(jun.editWidget) {
2023-06-21 20:36:53 +02:00
jun.editWidget.setFocusHover(_focus, _hover);
2023-03-19 09:17:39 +01:00
if(jun.connect_type == JUNCTION_CONNECT.input) {
jun.editWidget.setInteract(jun.value_from == noone);
if(_focus) jun.editWidget.register(_scrollPane);
} else {
jun.editWidget.setInteract(false);
}
2023-05-16 21:28:16 +02:00
2023-08-01 11:16:23 +02:00
//if(jun.display_type == VALUE_DISPLAY.area) {
// print("======= Show value widget =====");
// print(jun.animator.values[| 0].value);
// print(jun.showValue());
//}
2023-07-30 19:56:53 +02:00
var param = new widgetParam(editBoxX, editBoxY, editBoxW, editBoxH, jun.showValue(), jun.extra_data, _m, rx, ry);
2023-06-21 20:36:53 +02:00
2023-07-30 19:56:53 +02:00
switch(jun.type) {
case VALUE_TYPE.integer :
case VALUE_TYPE.float :
switch(jun.display_type) {
case VALUE_DISPLAY.padding : param.h = ui(192); break;
case VALUE_DISPLAY.corner : param.h = ui(192); break;
2023-08-01 11:16:23 +02:00
case VALUE_DISPLAY.area :
param.h = ui(204);
break;
2023-03-19 09:17:39 +01:00
}
2023-07-30 19:56:53 +02:00
break;
case VALUE_TYPE.boolean : param.halign = lineBreak? fa_left : fa_center;
case VALUE_TYPE.surface : param.h = ui(96); break;
case VALUE_TYPE.curve : param.h = ui(160);
if(point_in_rectangle(_m[0], _m[1], ui(32), _hsy, ui(32) + ww - ui(16), _hsy + editBoxH))
mbRight = false;
break;
2023-03-19 09:17:39 +01:00
}
2023-07-30 19:56:53 +02:00
widH = jun.editWidget.drawParam(param) - (TEXTBOX_HEIGHT * !lineBreak);
2023-03-19 09:17:39 +01:00
} else if(jun.display_type == VALUE_DISPLAY.label) {
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text_sub);
2023-06-10 13:59:45 +02:00
draw_text_add(xx + ui(16), _hsy, jun.display_data);
2023-03-19 09:17:39 +01:00
widH = string_height(jun.display_data);
} else
widH = 0;
//draw_set_color(c_white);
//draw_rectangle(xx, yy, xx + ww, yy + widH, true);
//draw_set_color(c_red);
//draw_line(xx + ww / 2, yy, xx + ww / 2, yy + widH);
return [ widH, mbRight ];
}