Skip to content

Commit f8ffc59

Browse files
committed
feat(node editor): Enhance Node Editor Functionality and Localization
1. Update button label in init.lua to use localized title. This commit improves the user experience by updating the button label in the main menu of the node editor to use a localized title. 2. Add functionality to create and rename contexts in draw.lua. - Introduce functionality to create a new context in the left pane of the node editor. - Implement a feature to open a popup for renaming contexts in the node editor. 3. Update type annotations for LDNodeEditorLink fields in link.lua. This commit enhances consistency by updating type annotations for LDNodeEditorLink fields to use 'integer' instead of 'number' for improved clarity and consistency.
1 parent 16af56f commit f8ffc59

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

LDYOM/Scripts/scripts/Core/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function init(scriptData)
170170

171171
ld.window.setMainMenuRender("node_editor_button", function()
172172
local scaleFont = ImGui.GetFontSize() / 16;
173-
if ImGui.Button(fa.ICON_FA_PROJECT_DIAGRAM .. " Node Editor (Lua)", ImVec2.new(scaleFont * 200, 0)) then
173+
if ImGui.Button(fa.ICON_FA_PROJECT_DIAGRAM .. " " .. ld.loc.get("nodes.node_editor.title"), ImVec2.new(scaleFont * 200, 0)) then
174174
ld.window.replaceWindow(function()
175175
ld.window.closeMainMenu();
176176
ld.window.openLuaWindow(bind(drawNodeEditor, editor));

LDYOM/Scripts/scripts/Core/ld/draw.lua

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ local lastFrameWindowSize = 0.0;
2626

2727
local showRightMenu = false;
2828
local searchBuffer = "";
29+
---@type integer | nil
30+
local selectedContext = nil;
2931

3032
local openPopupPosition = ImVec2.new();
3133

@@ -89,7 +91,13 @@ function ShowLeftPane(paneWidth, ed)
8991
ImGui.GetContentRegionAvail(contentRegionAvail);
9092
paneWidth = contentRegionAvail.x;
9193

92-
ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##context", ImVec2.new(21 * fontScale, 0));
94+
local openRenamePopupContext = false;
95+
if ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##context", ImVec2.new(21 * fontScale, 0)) then
96+
LDNodeEditor.addNewContext(ed);
97+
selectedContext = #ed.contexts;
98+
ed.currentIndexContext = selectedContext;
99+
openRenameVariablePopup = true;
100+
end
93101
ImGui.SameLine(0, -1);
94102
local isOpenListContexts = ImGui.CollapsingHeader(ld.loc.get("nodes.node_editor.contexts"), 0);
95103
if isOpenListContexts then
@@ -100,12 +108,12 @@ function ShowLeftPane(paneWidth, ed)
100108
if ImGui.Selectable(context.name, isSelected, 0, ImVec2.new(0, 0)) then
101109
ed.currentIndexContext = i;
102110
end
103-
local openRenamePopup = false;
104111
if ImGui.BeginPopupContextItem("##edContextContextMenu" .. i, ImGuiPopupFlags.MouseButtonRight) then
105112
ImGui.TextUnformatted(context.name);
106113
ImGui.Separator();
107114
if ImGui.MenuItem(ld.loc.get("nodes.node_editor.rename"), "", false, true) then
108-
openRenamePopup = true;
115+
selectedContext = i;
116+
openRenamePopupContext = true;
109117
end
110118
if ImGui.MenuItem(ld.loc.get("nodes.node_editor.delete"), "", false, #ed.contexts > 1) then
111119
table.remove(ed.contexts, i);
@@ -115,26 +123,27 @@ function ShowLeftPane(paneWidth, ed)
115123
end
116124
ImGui.EndPopup();
117125
end
118-
119-
if openRenamePopup then
120-
ImGui.OpenPopup("renameContextPopup", 0);
121-
end
122-
123-
if ImGui.BeginPopup("renameContextPopup", 0) then
124-
local newName = context.name;
125-
_, newName = ImGui.InputText("##inputNameRename", newName, ImGuiInputTextFlags.EnterReturnsTrue, nil, nil);
126-
if ImGui.IsItemDeactivatedAfterEdit() then
127-
context.name = newName;
128-
ImGui.CloseCurrentPopup();
129-
end
130-
ImGui.EndPopup();
131-
end
132126
end
133127

134128
ImGui.EndListBox();
135129
end
136130
end
137131

132+
if openRenamePopupContext then
133+
ImGui.OpenPopup("renameContextPopup", 0);
134+
end
135+
136+
if ImGui.BeginPopup("renameContextPopup", 0) then
137+
local context = ed.contexts[selectedContext];
138+
local newName = context.name;
139+
_, newName = ImGui.InputText("##inputNameRename", newName, ImGuiInputTextFlags.EnterReturnsTrue, nil, nil);
140+
if ImGui.IsItemDeactivatedAfterEdit() then
141+
context.name = newName;
142+
ImGui.CloseCurrentPopup();
143+
end
144+
ImGui.EndPopup();
145+
end
146+
138147
local openRenameVariablePopup = false;
139148
if ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##var", ImVec2.new(21 * fontScale, 0)) then
140149
local newVarUUID = LDNodeEditor.addNewVariable(ed, "core.number");
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---@class LDNodeEditorLink
2-
---@field id number
3-
---@field inputId number
4-
---@field outputId number
2+
---@field id integer
3+
---@field inputId integer
4+
---@field outputId integer

0 commit comments

Comments
 (0)