From 5533c53932e12e6e6a947f006cccd3d77a90bbdf Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 26 Aug 2024 22:14:53 +0200 Subject: [PATCH] alang fixes --- armorpaint/sources/nodes_brush.ts | 37 ++++----- base/sources/nodes_material.ts | 16 ++-- base/sources/parser_material.ts | 2 +- base/sources/tab_materials.ts | 13 ++-- base/sources/ui_nodes.ts | 124 ++++++++++++++++-------------- 5 files changed, 102 insertions(+), 90 deletions(-) diff --git a/armorpaint/sources/nodes_brush.ts b/armorpaint/sources/nodes_brush.ts index 639e397c..57dba265 100644 --- a/armorpaint/sources/nodes_brush.ts +++ b/armorpaint/sources/nodes_brush.ts @@ -1,24 +1,10 @@ -/// -/// -/// -let nodes_brush_categories: string[] = [_tr("Nodes")]; - -let nodes_brush_category0: zui_node_t[] = [ - tex_image_node_def, - input_node_def, - math_node_def, - random_node_def, - separate_vector_node_def, - time_node_def, - float_node_def, - vector_node_def, - vector_math_node_def +let nodes_brush_categories: string[] = [ + _tr("Nodes") ]; -let nodes_brush_list: node_list_t[] = [ - nodes_brush_category0 -]; +let nodes_brush_category0: zui_node_t[]; +let nodes_brush_list: node_list_t[]; let nodes_brush_creates: map_tlogic_node_ext_t>; @@ -34,6 +20,21 @@ function nodes_brush_init() { map_set(nodes_brush_creates, "float_node", float_node_create); map_set(nodes_brush_creates, "vector_node", vector_node_create); map_set(nodes_brush_creates, "vector_math_node", vector_math_node_create); + + nodes_brush_category0 = [ + tex_image_node_def, + input_node_def, + math_node_def, + random_node_def, + separate_vector_node_def, + time_node_def, + float_node_def, + vector_node_def, + vector_math_node_def + ]; + nodes_brush_list = [ + nodes_brush_category0 + ]; } function nodes_brush_create_node(node_type: string): zui_node_t { diff --git a/base/sources/nodes_material.ts b/base/sources/nodes_material.ts index 59f6df23..b5a59fc3 100644 --- a/base/sources/nodes_material.ts +++ b/base/sources/nodes_material.ts @@ -1656,7 +1656,7 @@ let nodes_material_texture: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Linear") + "\0" + _tr("Diagonal") + "\0" + _tr("Radial") + "\0" + _tr("Spherical")), + data: u8_array_create_from_string(_tr("Linear") + "\n" + _tr("Diagonal") + "\n" + _tr("Radial") + "\n" + _tr("Spherical")), min: 0.0, max: 1.0, precision: 100, @@ -1729,7 +1729,7 @@ let nodes_material_texture: zui_node_t[] = [ type: "ENUM", output: -1, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Auto") + "\0" + _tr("Linear") + "\0" + _tr("sRGB") + "\0" + _tr("DirectX Normal Map")), + data: u8_array_create_from_string(_tr("Auto") + "\n" + _tr("Linear") + "\n" + _tr("sRGB") + "\n" + _tr("DirectX Normal Map")), min: 0.0, max: 1.0, precision: 100, @@ -1977,7 +1977,7 @@ let nodes_material_texture: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Intensity") + "\0" + _tr("Cells")), + data: u8_array_create_from_string(_tr("Intensity") + "\n" + _tr("Cells")), min: 0.0, max: 1.0, precision: 100, @@ -2414,7 +2414,7 @@ let nodes_material_color: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Mix") + "\0" + _tr("Darken") + "\0" + _tr("Multiply") + "\0" + _tr("Burn") + "\0" + _tr("Lighten") + "\0" + _tr("Screen") + "\0" + _tr("Dodge") + "\0" + _tr("Add") + "\0" + _tr("Overlay") + "\0" + _tr("Soft Light") + "\0" + _tr("Linear Light") + "\0" + _tr("Difference") + "\0" + _tr("Subtract") + "\0" + _tr("Divide") + "\0" + _tr("Hue") + "\0" + _tr("Saturation") + "\0" + _tr("Color") + "\0" + _tr("Value")), + data: u8_array_create_from_string(_tr("Mix") + "\n" + _tr("Darken") + "\n" + _tr("Multiply") + "\n" + _tr("Burn") + "\n" + _tr("Lighten") + "\n" + _tr("Screen") + "\n" + _tr("Dodge") + "\n" + _tr("Add") + "\n" + _tr("Overlay") + "\n" + _tr("Soft Light") + "\n" + _tr("Linear Light") + "\n" + _tr("Difference") + "\n" + _tr("Subtract") + "\n" + _tr("Divide") + "\n" + _tr("Hue") + "\n" + _tr("Saturation") + "\n" + _tr("Color") + "\n" + _tr("Value")), min: 0.0, max: 1.0, precision: 100, @@ -2750,7 +2750,7 @@ let nodes_material_vector: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Partial Derivative") + "\0" + _tr("Whiteout") + "\0" + _tr("Reoriented")), + data: u8_array_create_from_string(_tr("Partial Derivative") + "\n" + _tr("Whiteout") + "\n" + _tr("Reoriented")), min: 0.0, max: 1.0, precision: 100, @@ -3002,7 +3002,7 @@ let nodes_material_converter: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Min Max") + "\0" + _tr("Range")), + data: u8_array_create_from_string(_tr("Min Max") + "\n" + _tr("Range")), min: 0.0, max: 1.0, precision: 100, @@ -3485,7 +3485,7 @@ let nodes_material_converter: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Add") + "\0" + _tr("Subtract") + "\0" + _tr("Multiply") + "\0" + _tr("Divide") + "\0" + _tr("Power") + "\0" + _tr("Logarithm") + "\0" + _tr("Square Root") + "\0" + _tr("Inverse Square Root") + "\0" + _tr("Absolute") + "\0" + _tr("Exponent") + "\0" + _tr("Minimum") + "\0" + _tr("Maximum") + "\0" + _tr("Less Than") + "\0" + _tr("Greater Than") + "\0" + _tr("Sign") + "\0" + _tr("Round") + "\0" + _tr("Floor") + "\0" + _tr("Ceil") + "\0" + _tr("Truncate") + "\0" + _tr("Fraction") + "\0" + _tr("Modulo") + "\0" + _tr("Snap") + "\0" + _tr("Ping-Pong") + "\0" + _tr("Sine") + "\0" + _tr("Cosine") + "\0" + _tr("Tangent") + "\0" + _tr("Arcsine") + "\0" + _tr("Arccosine") + "\0" + _tr("Arctangent") + "\0" + _tr("Arctan2") + "\0" + _tr("Hyperbolic Sine") + "\0" + _tr("Hyperbolic Cosine") + "\0" + _tr("Hyperbolic Tangent") + "\0" + _tr("To Radians") + "\0" + _tr("To Degrees")), + data: u8_array_create_from_string(_tr("Add") + "\n" + _tr("Subtract") + "\n" + _tr("Multiply") + "\n" + _tr("Divide") + "\n" + _tr("Power") + "\n" + _tr("Logarithm") + "\n" + _tr("Square Root") + "\n" + _tr("Inverse Square Root") + "\n" + _tr("Absolute") + "\n" + _tr("Exponent") + "\n" + _tr("Minimum") + "\n" + _tr("Maximum") + "\n" + _tr("Less Than") + "\n" + _tr("Greater Than") + "\n" + _tr("Sign") + "\n" + _tr("Round") + "\n" + _tr("Floor") + "\n" + _tr("Ceil") + "\n" + _tr("Truncate") + "\n" + _tr("Fraction") + "\n" + _tr("Modulo") + "\n" + _tr("Snap") + "\n" + _tr("Ping-Pong") + "\n" + _tr("Sine") + "\n" + _tr("Cosine") + "\n" + _tr("Tangent") + "\n" + _tr("Arcsine") + "\n" + _tr("Arccosine") + "\n" + _tr("Arctangent") + "\n" + _tr("Arctan2") + "\n" + _tr("Hyperbolic Sine") + "\n" + _tr("Hyperbolic Cosine") + "\n" + _tr("Hyperbolic Tangent") + "\n" + _tr("To Radians") + "\n" + _tr("To Degrees")), min: 0.0, max: 1.0, precision: 100, @@ -3794,7 +3794,7 @@ let nodes_material_converter: zui_node_t[] = [ type: "ENUM", output: 0, default_value: f32_array_create_x(0), - data: u8_array_create_from_string(_tr("Add") + "\0" + _tr("Subtract") + "\0" + _tr("Multiply") + "\0" + _tr("Divide") + "\0" + _tr("Average") + "\0" + _tr("Cross Product") + "\0" + _tr("Project") + "\0" + _tr("Reflect") + "\0" + _tr("Dot Product") + "\0" + _tr("Distance") + "\0" + _tr("Length") + "\0" + _tr("Scale") + "\0" + _tr("Normalize") + "\0" + _tr("Absolute") + "\0" + _tr("Minimum") + "\0" + _tr("Maximum") + "\0" + _tr("Floor") + "\0" + _tr("Ceil") + "\0" + _tr("Fraction") + "\0" + _tr("Modulo") + "\0" + _tr("Snap") + "\0" + _tr("Sine") + "\0" + _tr("Cosine") + "\0" + _tr("Tangent")), + data: u8_array_create_from_string(_tr("Add") + "\n" + _tr("Subtract") + "\n" + _tr("Multiply") + "\n" + _tr("Divide") + "\n" + _tr("Average") + "\n" + _tr("Cross Product") + "\n" + _tr("Project") + "\n" + _tr("Reflect") + "\n" + _tr("Dot Product") + "\n" + _tr("Distance") + "\n" + _tr("Length") + "\n" + _tr("Scale") + "\n" + _tr("Normalize") + "\n" + _tr("Absolute") + "\n" + _tr("Minimum") + "\n" + _tr("Maximum") + "\n" + _tr("Floor") + "\n" + _tr("Ceil") + "\n" + _tr("Fraction") + "\n" + _tr("Modulo") + "\n" + _tr("Snap") + "\n" + _tr("Sine") + "\n" + _tr("Cosine") + "\n" + _tr("Tangent")), min: 0.0, max: 1.0, precision: 100, diff --git a/base/sources/parser_material.ts b/base/sources/parser_material.ts index a23d82ba..cfa8a84b 100644 --- a/base/sources/parser_material.ts +++ b/base/sources/parser_material.ts @@ -2007,7 +2007,7 @@ function parser_material_safestr(s: string): string { function u8_array_string_at(a: u8_array_t, i: i32): string { let s: string = u8_array_to_string(a); - let ss: string[] = string_split(s, "\0"); + let ss: string[] = string_split(s, "\n"); return ss[i]; } diff --git a/base/sources/tab_materials.ts b/base/sources/tab_materials.ts index 96b9d50e..94601eb0 100644 --- a/base/sources/tab_materials.ts +++ b/base/sources/tab_materials.ts @@ -319,13 +319,12 @@ function tab_materials_draw_slots(mini: bool) { function tab_materials_button_new(text: string) { if (zui_button(text)) { - let current: image_t = _g2_current; - g2_end(); - context_raw.material = slot_material_create(project_materials[0].data); - array_push(project_materials, context_raw.material); - tab_materials_update_material(); - g2_begin(current); - history_new_material(); + app_notify_on_init(function() { + context_raw.material = slot_material_create(project_materials[0].data); + array_push(project_materials, context_raw.material); + tab_materials_update_material(); + history_new_material(); + }); } } diff --git a/base/sources/ui_nodes.ts b/base/sources/ui_nodes.ts index 13c15da5..b1c4f4c9 100644 --- a/base/sources/ui_nodes.ts +++ b/base/sources/ui_nodes.ts @@ -57,64 +57,74 @@ let _ui_nodes_on_link_drag_link_drag: zui_node_link_t; let _ui_nodes_on_link_drag_node: zui_node_t; function ui_nodes_on_link_drag(link_drag_id: i32, is_new_link: bool) { - if (is_new_link) { - let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); - let links: zui_node_link_t[] = ui_nodes_get_canvas(true).links; - let link_drag: zui_node_link_t = zui_get_link(links, link_drag_id); - let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; - let node: zui_node_t = zui_get_node(nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); - let link_x: i32 = ui_nodes_ui._window_x + zui_nodes_NODE_X(node); - let link_y: i32 = ui_nodes_ui._window_y + zui_nodes_NODE_Y(node); - if (link_drag.from_id > -1) { - link_x += zui_nodes_NODE_W(node); - link_y += zui_nodes_OUTPUT_Y(node.outputs.length, link_drag.from_socket); - } - else { - link_y += zui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node.inputs, link_drag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs.length) + zui_nodes_BUTTONS_H(node); - } - if (math_abs(mouse_x - link_x) > 5 || math_abs(mouse_y - link_y) > 5) { // Link length + if (!is_new_link) { + return; + } - _ui_nodes_on_link_drag_link_drag = link_drag; - _ui_nodes_on_link_drag_node = node; + let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); + let links: zui_node_link_t[] = ui_nodes_get_canvas(true).links; + let link_drag: zui_node_link_t = zui_get_link(links, link_drag_id); + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + let node: zui_node_t = zui_get_node(nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); + let link_x: i32 = ui_nodes_ui._window_x + zui_nodes_NODE_X(node); + let link_y: i32 = ui_nodes_ui._window_y + zui_nodes_NODE_Y(node); + if (link_drag.from_id > -1) { + link_x += zui_nodes_NODE_W(node); + link_y += zui_nodes_OUTPUT_Y(node.outputs.length, link_drag.from_socket); + } + else { + link_y += zui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node.inputs, link_drag.to_socket) + + zui_nodes_OUTPUTS_H(node.outputs.length) + zui_nodes_BUTTONS_H(node); + } - ui_nodes_node_search(-1, -1, function () { - let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); - let link_drag: zui_node_link_t = _ui_nodes_on_link_drag_link_drag; - let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; - let n: zui_node_t = zui_get_node(nodes, ui_nodes.nodes_selected_id[0]); - if (link_drag.to_id == -1 && n.inputs.length > 0) { - link_drag.to_id = n.id; - let from_type: string = _ui_nodes_on_link_drag_node.outputs[link_drag.from_socket].type; - // Connect to the first socket - link_drag.to_socket = 0; - // Try to find the first type-matching socket and use it if present - for (let i: i32 = 0; i < n.inputs.length; ++i) { - let socket: zui_node_socket_t = n.inputs[i]; - if (socket.type == from_type) { - link_drag.to_socket = array_index_of(n.inputs, socket); - break; - } + if (math_abs(mouse_x - link_x) > 5 || math_abs(mouse_y - link_y) > 5) { // Link length + + _ui_nodes_on_link_drag_link_drag = link_drag; + _ui_nodes_on_link_drag_node = node; + + ui_nodes_node_search(-1, -1, function () { + let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); + + let node_selected_id: i32 = _ui_nodes_on_link_drag_node.id; + if (ui_nodes.nodes_selected_id.length > 0) { + node_selected_id = ui_nodes.nodes_selected_id[0]; + } + + let link_drag: zui_node_link_t = _ui_nodes_on_link_drag_link_drag; + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + let n: zui_node_t = zui_get_node(nodes, node_selected_id); + if (link_drag.to_id == -1 && n.inputs.length > 0) { + link_drag.to_id = n.id; + let from_type: string = _ui_nodes_on_link_drag_node.outputs[link_drag.from_socket].type; + // Connect to the first socket + link_drag.to_socket = 0; + // Try to find the first type-matching socket and use it if present + for (let i: i32 = 0; i < n.inputs.length; ++i) { + let socket: zui_node_socket_t = n.inputs[i]; + if (socket.type == from_type) { + link_drag.to_socket = array_index_of(n.inputs, socket); + break; } - array_push(ui_nodes_get_canvas(true).links, link_drag); } - else if (link_drag.from_id == -1 && n.outputs.length > 0) { - link_drag.from_id = n.id; - link_drag.from_socket = 0; - array_push(ui_nodes_get_canvas(true).links, link_drag); - } - ///if is_lab - parser_logic_parse(ui_nodes_get_canvas(true)); - context_raw.rdirty = 5; - ///end - }); - } - // Selecting which node socket to preview - else if (node.id == ui_nodes.nodes_selected_id[0]) { - context_raw.node_preview_socket = link_drag.from_id > -1 ? link_drag.from_socket : 0; - ///if (is_paint || is_sculpt) - context_raw.node_preview_dirty = true; + array_push(ui_nodes_get_canvas(true).links, link_drag); + } + else if (link_drag.from_id == -1 && n.outputs.length > 0) { + link_drag.from_id = n.id; + link_drag.from_socket = 0; + array_push(ui_nodes_get_canvas(true).links, link_drag); + } + ///if is_lab + parser_logic_parse(ui_nodes_get_canvas(true)); + context_raw.rdirty = 5; ///end - } + }); + } + // Selecting which node socket to preview + else if (node.id == ui_nodes.nodes_selected_id[0]) { + context_raw.node_preview_socket = link_drag.from_id > -1 ? link_drag.from_socket : 0; + ///if (is_paint || is_sculpt) + context_raw.node_preview_dirty = true; + ///end } } @@ -189,7 +199,8 @@ function ui_nodes_on_socket_released(socket_id: i32) { zui_float_input(_ui_nodes_hval1, tr("G")); zui_float_input(_ui_nodes_hval2, tr("B")); zui_float_input(_ui_nodes_hval3, tr("A")); - default_value = f32_array_create_xyzw(_ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value, _ui_nodes_hval3.value); + default_value = f32_array_create_xyzw( + _ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value, _ui_nodes_hval3.value); } else if (type == 1) { let row: f32[] = [1 / 3, 1 / 3, 1 / 3]; @@ -197,7 +208,8 @@ function ui_nodes_on_socket_released(socket_id: i32) { _ui_nodes_hval0.value = zui_float_input(_ui_nodes_hval0, tr("X")); _ui_nodes_hval1.value = zui_float_input(_ui_nodes_hval1, tr("Y")); _ui_nodes_hval2.value = zui_float_input(_ui_nodes_hval2, tr("Z")); - default_value = f32_array_create_xyz(_ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value); + default_value = f32_array_create_xyz( + _ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value); } else { let f: f32 = zui_float_input(_ui_nodes_hval0, tr("default_value")); @@ -243,7 +255,7 @@ function ui_nodes_on_socket_released(socket_id: i32) { else ui_nodes_on_canvas_released(); } // Selecting which node socket to preview - else if (node.id == nodes.nodes_selected_id[0]) { + else if (nodes.nodes_selected_id.length > 0 && node.id == nodes.nodes_selected_id[0]) { let i: i32 = array_index_of(node.outputs, socket); if (i > -1) { context_raw.node_preview_socket = i;