Pixel-Composer/scripts/nodeValue_drawer/nodeValue_drawer.gml

403 lines
12 KiB
Plaintext
Raw Normal View History

2024-03-24 04:58:08 +01:00
enum INSP_VIEW_MODE {
compact,
spacious
}
2023-03-19 09:17:39 +01:00
function drawWidgetInit() {
anim_toggling = false;
anim_hold = noone;
visi_hold = noone;
min_w = ui(160);
2024-03-24 04:58:08 +01:00
viewMode = PREFERENCES.inspector_view_default;
2024-03-02 10:08:44 +01:00
tooltip_loop_type = new tooltipSelector(__txtx("panel_animation_looping_mode", "Looping mode"), global.junctionEndName);
2023-03-19 09:17:39 +01:00
}
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) {
2024-08-14 09:55:53 +02:00
var con_w = ww - ui(4);
var xc = xx + ww / 2;
2024-09-10 11:48:51 +02:00
var _font = viewMode == INSP_VIEW_MODE.spacious? f_p1 : f_p2;
2024-03-26 04:03:45 +01:00
var breakLine = viewMode == INSP_VIEW_MODE.spacious || jun.expUse;
2024-08-14 09:55:53 +02:00
var lb_h = line_get_height(_font) + ui(6);
var lb_y = yy + lb_h / 2;
2023-09-07 20:59:14 +02:00
2024-08-14 09:55:53 +02:00
var _name = jun.getName();
var wid = jun.editWidget;
var cHov = false;
2024-07-28 13:55:57 +02:00
switch(instanceof(wid)) {
case "textArea" :
case "controlPointBox" :
case "transformBox" :
breakLine = true;
2024-07-28 13:55:57 +02:00
}
2023-03-19 09:17:39 +01:00
var butx = xx;
2024-08-20 10:15:53 +02:00
if(jun.connect_type == CONNECT_TYPE.input && jun.isAnimable() && !jun.expUse) { // animation
2023-10-18 14:58:55 +02:00
var index = jun.hasJunctionFrom()? 2 : jun.is_anim;
2023-11-24 10:41:53 +01:00
var cc = c_white;
if(jun.is_anim) cc = COLORS._main_value_positive;
if(index == 2) cc = COLORS._main_accent;
draw_sprite_ui_uniform(THEME.animate_clock, index, butx, lb_y, 1, cc, 0.8);
2023-03-19 09:17:39 +01:00
if(_hover && point_in_circle(_m[0], _m[1], butx, lb_y, ui(10))) {
2024-07-28 13:55:57 +02:00
cHov = true;
2023-03-19 09:17:39 +01:00
if(anim_hold != noone)
2024-09-03 11:49:51 +02:00
jun.setAnim(anim_hold, true);
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-10-18 14:58:55 +02:00
TOOLTIP = jun.hasJunctionFrom()? __txtx("panel_inspector_remove_link", "Remove link") : __txtx("panel_inspector_toggle_anim", "Toggle animation");
2023-03-19 09:17:39 +01:00
if(mouse_press(mb_left, _focus)) {
if(jun.value_from != noone)
jun.removeFrom();
else {
2024-09-03 11:49:51 +02:00
jun.setAnim(!jun.is_anim, true);
2023-03-21 03:01:53 +01:00
anim_hold = jun.is_anim;
2023-03-19 09:17:39 +01:00
}
}
}
2024-07-28 13:55:57 +02:00
}
2023-03-19 09:17:39 +01:00
2024-08-14 09:55:53 +02:00
if(anim_hold != noone && mouse_release(mb_left)) anim_hold = noone;
2023-03-19 09:17:39 +01:00
butx += ui(20);
2024-07-28 13:55:57 +02:00
if(!global_var) { // visibility
var _visi = jun.isVisible();
draw_sprite_ui_uniform(THEME.junc_visible, _visi, butx, lb_y, 1,, 0.8);
2023-06-17 14:30:49 +02:00
if(_hover && point_in_circle(_m[0], _m[1], butx, lb_y, ui(10))) {
2024-07-28 13:55:57 +02:00
cHov = true;
if(visi_hold != noone && jun.visible_manual != visi_hold) {
jun.visible_manual = visi_hold;
2024-03-31 11:10:14 +02:00
jun.node.refreshNodeDisplay();
2023-11-08 08:38:04 +01:00
}
draw_sprite_ui_uniform(THEME.junc_visible, _visi, butx, lb_y, 1,, 1);
2023-06-17 14:30:49 +02:00
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_manual = _visi? -1 : 1;
visi_hold = jun.visible_manual;
2024-03-31 11:10:14 +02:00
jun.node.refreshNodeDisplay();
2023-03-19 09:17:39 +01:00
}
}
2024-07-28 13:55:57 +02:00
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
2024-08-14 09:55:53 +02:00
if(visi_hold != noone && mouse_release(mb_left)) visi_hold = noone;
2023-03-19 09:17:39 +01:00
var cc = COLORS._main_text;
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-11-24 10:41:53 +01:00
if(global_var) {
if(string_pos(" ", _name)) cc = COLORS._main_value_negative;
} else {
if(jun.is_anim) cc = COLORS._main_value_positive;
2023-11-24 14:48:19 +01:00
if(jun.hasJunctionFrom()) cc = COLORS._main_accent;
2023-11-24 10:41:53 +01:00
}
2023-04-21 19:08:10 +02:00
draw_set_text(_font, fa_left, fa_center, cc);
var lb_w = ui(40 + 16) + string_width(_name);
var lb_x = ui(40) + xx;
2023-10-15 15:04:42 +02:00
2024-07-28 13:55:57 +02:00
if(jun.color != -1) {
2023-10-15 15:04:42 +02:00
draw_sprite_ext(THEME.timeline_color, 1, lb_x + ui(8), lb_y, 1, 1, 0, jun.color, 1);
lb_x += ui(24);
lb_w += ui(24);
2024-07-28 13:55:57 +02:00
}
2023-10-15 15:04:42 +02:00
2024-07-28 13:55:57 +02:00
if(!jun.active) {
2023-12-07 15:08:09 +01:00
draw_set_text(_font, fa_left, fa_center, COLORS._main_text_sub_inner);
draw_text_add(lb_x, lb_y - ui(2), _name);
if(jun.active_tooltip != "") {
var tx = xx + ui(40) + string_width(_name) + ui(16);
var ty = lb_y - ui(1);
if(point_in_circle(_m[0], _m[1], tx, ty, ui(10))) {
2024-07-28 13:55:57 +02:00
cHov = true;
2023-12-07 15:08:09 +01:00
TOOLTIP = jun.active_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);
}
2024-07-28 13:55:57 +02:00
return [ 0, true, cHov ];
}
2023-12-07 15:08:09 +01:00
2024-03-24 04:58:08 +01:00
draw_text_over(lb_x, lb_y, _name);
2023-03-19 09:17:39 +01:00
#region tooltip
if(jun.tooltip != "") {
var tx = xx + ui(40) + string_width(_name) + ui(16);
2023-03-19 09:17:39 +01:00
var ty = lb_y - ui(1);
if(point_in_circle(_m[0], _m[1], tx, ty, ui(10))) {
2024-07-28 13:55:57 +02:00
cHov = true;
2023-03-19 09:17:39 +01:00
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(32);
2023-03-19 09:17:39 +01:00
}
#endregion
#region anim
2024-08-20 10:15:53 +02:00
if(jun.connect_type == CONNECT_TYPE.input && breakLine && jun.is_anim) {
var _anim = jun.animator;
2023-03-19 09:17:39 +01:00
var bx = xx + ww - ui(12);
var by = lb_y;
2024-07-28 13:55:57 +02:00
var b = buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "", THEME.prop_keyframe, 2)
if(b) cHov = true;
if(b == 2) {
for(var j = 0; j < array_length(_anim.values); j++) {
var _key = _anim.values[j];
2023-10-09 16:07:33 +02:00
if(_key.time > CURRENT_FRAME) {
2023-07-06 19:49:16 +02:00
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 < array_length(_anim.values); j++) {
if(_anim.values[j].time == CURRENT_FRAME) {
2023-03-19 09:17:39 +01:00
cc = COLORS.panel_animation_keyframe_selected;
kfFocus = true;
break;
}
}
2024-07-28 13:55:57 +02:00
var _tlp = kfFocus? __txtx("panel_inspector_remove_key", "Remove keyframe") : __txtx("panel_inspector_add_key", "Add keyframe");
var b = buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, _tlp, THEME.prop_keyframe, 1, cc)
if(b) cHov = true;
if(b == 2) {
var _remv = false;
for(var j = 0; j < array_length(_anim.values); j++) {
var _key = _anim.values[j];
2023-10-09 16:07:33 +02:00
if(_key.time == CURRENT_FRAME) {
_anim.removeKey(_key);
_remv = true;
2023-03-19 09:17:39 +01:00
break;
}
}
if(!_remv) _anim.setValue(jun.showValue(), true, CURRENT_FRAME);
2023-03-19 09:17:39 +01:00
}
bx -= ui(26);
2024-07-28 13:55:57 +02:00
var b = buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, "", THEME.prop_keyframe, 0)
if(b) cHov = true;
if(b == 2) {
2023-03-19 09:17:39 +01:00
var _t = -1;
for(var j = 0; j < array_length(_anim.values); j++) {
var _key = _anim.values[j];
2023-10-09 16:07:33 +02:00
if(_key.time < 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);
2024-03-02 10:08:44 +01:00
tooltip_loop_type.index = jun.on_end;
2024-07-28 13:55:57 +02:00
var b = buttonInstant(THEME.button_hide, bx - ui(12), by - ui(12), ui(24), ui(24), _m, _focus, _hover, tooltip_loop_type, THEME.prop_on_end, jun.on_end)
if(b) cHov = true;
if(b == 2) jun.on_end = safe_mod(jun.on_end + 1, sprite_get_number(THEME.prop_on_end));
2023-03-19 09:17:39 +01:00
}
#endregion
2024-08-14 09:55:53 +02:00
#region right buttons
2024-08-20 10:15:53 +02:00
if(jun.connect_type == CONNECT_TYPE.input && breakLine && !jun.is_anim && !global_var) {
2024-08-14 09:55:53 +02:00
var bx = xx + ww + ui(16);
var by = lb_y;
var bs = ui(24);
var bsh = bs / 2;
2023-11-24 10:41:53 +01:00
2024-08-14 09:55:53 +02:00
bx -= bs + ui(4);
2023-11-24 14:48:19 +01:00
if(jun.is_modified) {
2024-08-14 09:55:53 +02:00
var b = buttonInstant(THEME.button_hide, bx - bsh, by - bsh, bs, bs, _m, _focus, _hover, __txtx("panel_inspector_reset", "Reset value"), THEME.refresh_16, 0, COLORS._main_icon)
2024-07-28 13:55:57 +02:00
if(b) cHov = true;
if(b == 2) jun.resetValue();
2023-11-24 14:48:19 +01:00
} else
2023-12-29 14:30:54 +01:00
draw_sprite_ui(THEME.refresh_16, 0, bx, by,,,, COLORS._main_icon, 0.5);
2023-11-24 10:41:53 +01:00
2024-08-14 09:55:53 +02:00
bx -= bs + ui(4);
2023-04-15 14:48:29 +02:00
var ic_b = jun.expUse? c_white : COLORS._main_icon;
2024-08-14 09:55:53 +02:00
var b = buttonInstant(THEME.button_hide, bx - bsh, by - bsh, bs, bs, _m, _focus, _hover, __txtx("panel_inspector_use_expression", "Use expression"), THEME.node_use_expression, jun.expUse, ic_b)
2024-07-28 13:55:57 +02:00
if(b) cHov = true;
if(b == 2) {
2024-03-14 14:35:19 +01:00
jun.setUseExpression(!jun.expUse);
2023-11-14 14:29:11 +01:00
if(!jun.expUse) WIDGET_CURRENT = noone;
}
2023-06-17 14:30:49 +02:00
if(jun.expUse) {
2024-08-14 09:55:53 +02:00
bx -= bs + ui(4);
2023-06-17 14:30:49 +02:00
var cc = NODE_DROPPER_TARGET == jun? COLORS._main_value_positive : COLORS._main_icon;
2024-08-14 09:55:53 +02:00
var b = buttonInstant(THEME.button_hide, bx - bsh, by - bsh, bs, bs, _m, _focus, _hover, __txtx("panel_inspector_dropper", "Node Dropper"), THEME.node_dropper, 0, cc)
2024-07-28 13:55:57 +02:00
if(b) cHov = true;
if(b == 2) NODE_DROPPER_TARGET = NODE_DROPPER_TARGET == jun? noone : jun;
2023-06-17 14:30:49 +02:00
}
2023-09-07 20:59:14 +02:00
if(jun.expUse || jun.type == VALUE_TYPE.text) {
2024-08-14 09:55:53 +02:00
bx -= bs + ui(4);
var cc = jun.popup_dialog == noone? COLORS._main_icon : COLORS._main_value_positive;
2024-08-14 09:55:53 +02:00
var b = buttonInstant(THEME.button_hide, bx - bsh, by - bsh, bs, bs, _m, _focus, _hover, __txtx("panel_inspector_pop_text", "Pop up Editor"), THEME.text_popup, 0, cc)
2024-07-28 13:55:57 +02:00
if(b) cHov = true;
if(b == 2) {
if(jun.expUse) jun.popup_dialog = dialogPanelCall(new Panel_Text_Editor(jun.express_edit, function() { return context.expression; }, jun));
else jun.popup_dialog = dialogPanelCall(new Panel_Text_Editor(jun.editWidget, function() { return context.showValue(); }, jun));
jun.popup_dialog.content.title = $"{jun.node.name} - {_name}";
2023-09-07 20:59:14 +02:00
}
}
2024-08-14 09:55:53 +02:00
if(jun.bypass_junc) {
bx -= bs + ui(4);
var ic_b = jun.bypass_junc.visible? COLORS._main_icon_light : COLORS._main_icon;
var b = buttonInstant(THEME.button_hide, bx - bsh, by - bsh, bs, bs, _m, _focus, _hover, __txt("Bypass"), THEME.junction_bypass, jun.bypass_junc.visible, ic_b)
if(b) cHov = true;
if(b == 2) {
jun.bypass_junc.visible = !jun.bypass_junc.visible;
jun.node.setHeight();
}
}
2023-03-19 09:17:39 +01:00
}
#endregion
2023-05-16 21:28:16 +02:00
2024-08-14 09:55:53 +02:00
var _hsy = yy + lb_h;
var padd = ui(8);
var labelWidth = max(lb_w, min(ww * 0.4, ui(200)));
2024-08-14 09:55:53 +02:00
var widExtend = breakLine || jun.type == VALUE_TYPE.curve;
2024-06-01 14:08:24 +02:00
var editBoxX = xx + !widExtend * labelWidth;
var editBoxY = widExtend? _hsy : yy;
2023-03-19 09:17:39 +01:00
var editBoxW = (xx + ww) - editBoxX;
2024-06-01 14:08:24 +02:00
var editBoxH = widExtend? TEXTBOX_HEIGHT : lb_h;
2024-08-14 09:55:53 +02:00
var widH = widExtend? editBoxH : 0;
var mbRight = true;
2024-06-06 09:54:13 +02:00
2024-07-28 13:55:57 +02:00
if(jun.expUse) { // expression editor
2023-04-15 14:48:29 +02:00
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);
2024-07-28 13:55:57 +02:00
widH = wd_h - (TEXTBOX_HEIGHT * !widExtend);
cHov |= jun.express_edit.inBBOX(_m);
2024-06-06 09:54:13 +02:00
var un = jun.unit;
if(un.reference != noone) {
un.triggerButton.icon_index = un.mode;
un.triggerButton.tooltip.index = un.mode;
}
2024-06-01 14:08:24 +02:00
2024-07-28 13:55:57 +02:00
} else if(wid && jun.display_type != VALUE_DISPLAY.none) { // edit widget
wid.setFocusHover(_focus, _hover);
2023-12-22 14:46:54 +01:00
2024-08-20 10:15:53 +02:00
if(jun.connect_type == CONNECT_TYPE.input) {
wid.setInteract(!jun.hasJunctionFrom());
if(_focus) wid.register(_scrollPane);
2024-08-23 06:14:52 +02:00
if(is_instanceof(jun, NodeValue_Dimension)) {
var _proj = jun.node.attributes.use_project_dimension;
wid.side_button.icon_index = _proj;
wid.side_button.icon_blend = _proj? c_white : COLORS._main_icon;
}
2023-03-19 09:17:39 +01:00
} else {
wid.setInteract(false);
2023-03-19 09:17:39 +01:00
}
2023-05-16 21:28:16 +02:00
2023-09-09 13:52:16 +02:00
var _show = jun.showValue();
var param = new widgetParam(editBoxX, editBoxY, editBoxW, editBoxH, _show, jun.display_data, _m, rx, ry);
2024-09-10 11:48:51 +02:00
param.font = viewMode == INSP_VIEW_MODE.spacious? f_p1 : f_p2;
2024-07-03 05:32:12 +02:00
param.sep_axis = jun.sep_axis;
2023-06-21 20:36:53 +02:00
2023-07-30 19:56:53 +02:00
switch(jun.type) {
2024-03-26 04:03:45 +01:00
case VALUE_TYPE.float :
case VALUE_TYPE.integer :
2023-07-30 19:56:53 +02:00
switch(jun.display_type) {
2024-03-26 04:03:45 +01:00
case VALUE_DISPLAY.puppet_control :
case VALUE_DISPLAY.transform :
param.h = viewMode == INSP_VIEW_MODE.spacious? param.h : lb_h;
break;
2023-03-19 09:17:39 +01:00
}
2023-07-30 19:56:53 +02:00
break;
2024-03-26 04:03:45 +01:00
2023-08-24 19:44:12 +02:00
case VALUE_TYPE.boolean :
if(is_instanceof(wid, checkBoxActive)) break;
2024-03-27 14:18:39 +01:00
2024-06-01 14:08:24 +02:00
param.halign = widExtend? fa_left : fa_center;
2024-03-27 14:18:39 +01:00
param.s = editBoxH;
2024-06-01 14:08:24 +02:00
if(!widExtend) {
2024-03-27 14:18:39 +01:00
param.w = ww - min(ui(80) + ww * 0.2, ui(200));
param.x = editBoxX + editBoxW - param.w;
}
2023-08-24 19:44:12 +02:00
break;
case VALUE_TYPE.d3Material :
case VALUE_TYPE.surface :
2024-06-01 14:08:24 +02:00
param.h = widExtend? ui(96) : ui(48);
2023-08-24 19:44:12 +02:00
break;
2024-05-26 04:51:14 +02:00
2023-08-24 19:44:12 +02:00
case VALUE_TYPE.curve :
2024-06-01 14:08:24 +02:00
if(point_in_rectangle(_m[0], _m[1], ui(32), _hsy, ui(32) + ww - ui(16), _hsy + wid.h))
2023-07-30 19:56:53 +02:00
mbRight = false;
break;
2023-03-19 09:17:39 +01:00
}
2023-07-30 19:56:53 +02:00
var _widH = wid.drawParam(param) ?? 0;
2024-07-28 13:55:57 +02:00
widH = _widH - (TEXTBOX_HEIGHT * !widExtend);
cHov |= wid.inBBOX(_m)
2024-05-26 04:51:14 +02:00
mbRight &= wid.right_click_block;
2024-08-14 09:55:53 +02:00
}
2023-03-19 09:17:39 +01:00
2024-07-28 13:55:57 +02:00
return [ widH, mbRight, cHov ];
2023-03-19 09:17:39 +01:00
}