Skip to content

Commit

Permalink
feat(node editor): Enhance Node Editor Functionality and Localization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GeTechG committed Mar 5, 2024
1 parent 16af56f commit f8ffc59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LDYOM/Scripts/scripts/Core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function init(scriptData)

ld.window.setMainMenuRender("node_editor_button", function()
local scaleFont = ImGui.GetFontSize() / 16;
if ImGui.Button(fa.ICON_FA_PROJECT_DIAGRAM .. " Node Editor (Lua)", ImVec2.new(scaleFont * 200, 0)) then
if ImGui.Button(fa.ICON_FA_PROJECT_DIAGRAM .. " " .. ld.loc.get("nodes.node_editor.title"), ImVec2.new(scaleFont * 200, 0)) then
ld.window.replaceWindow(function()
ld.window.closeMainMenu();
ld.window.openLuaWindow(bind(drawNodeEditor, editor));
Expand Down
43 changes: 26 additions & 17 deletions LDYOM/Scripts/scripts/Core/ld/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ local lastFrameWindowSize = 0.0;

local showRightMenu = false;
local searchBuffer = "";
---@type integer | nil
local selectedContext = nil;

local openPopupPosition = ImVec2.new();

Expand Down Expand Up @@ -89,7 +91,13 @@ function ShowLeftPane(paneWidth, ed)
ImGui.GetContentRegionAvail(contentRegionAvail);
paneWidth = contentRegionAvail.x;

ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##context", ImVec2.new(21 * fontScale, 0));
local openRenamePopupContext = false;
if ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##context", ImVec2.new(21 * fontScale, 0)) then
LDNodeEditor.addNewContext(ed);
selectedContext = #ed.contexts;
ed.currentIndexContext = selectedContext;
openRenameVariablePopup = true;
end
ImGui.SameLine(0, -1);
local isOpenListContexts = ImGui.CollapsingHeader(ld.loc.get("nodes.node_editor.contexts"), 0);
if isOpenListContexts then
Expand All @@ -100,12 +108,12 @@ function ShowLeftPane(paneWidth, ed)
if ImGui.Selectable(context.name, isSelected, 0, ImVec2.new(0, 0)) then
ed.currentIndexContext = i;
end
local openRenamePopup = false;
if ImGui.BeginPopupContextItem("##edContextContextMenu" .. i, ImGuiPopupFlags.MouseButtonRight) then
ImGui.TextUnformatted(context.name);
ImGui.Separator();
if ImGui.MenuItem(ld.loc.get("nodes.node_editor.rename"), "", false, true) then
openRenamePopup = true;
selectedContext = i;
openRenamePopupContext = true;
end
if ImGui.MenuItem(ld.loc.get("nodes.node_editor.delete"), "", false, #ed.contexts > 1) then
table.remove(ed.contexts, i);
Expand All @@ -115,26 +123,27 @@ function ShowLeftPane(paneWidth, ed)
end
ImGui.EndPopup();
end

if openRenamePopup then
ImGui.OpenPopup("renameContextPopup", 0);
end

if ImGui.BeginPopup("renameContextPopup", 0) then
local newName = context.name;
_, newName = ImGui.InputText("##inputNameRename", newName, ImGuiInputTextFlags.EnterReturnsTrue, nil, nil);
if ImGui.IsItemDeactivatedAfterEdit() then
context.name = newName;
ImGui.CloseCurrentPopup();
end
ImGui.EndPopup();
end
end

ImGui.EndListBox();
end
end

if openRenamePopupContext then
ImGui.OpenPopup("renameContextPopup", 0);
end

if ImGui.BeginPopup("renameContextPopup", 0) then
local context = ed.contexts[selectedContext];
local newName = context.name;
_, newName = ImGui.InputText("##inputNameRename", newName, ImGuiInputTextFlags.EnterReturnsTrue, nil, nil);
if ImGui.IsItemDeactivatedAfterEdit() then
context.name = newName;
ImGui.CloseCurrentPopup();
end
ImGui.EndPopup();
end

local openRenameVariablePopup = false;
if ImGui.Button(fa.ICON_FA_PLUS_SQUARE .. "##var", ImVec2.new(21 * fontScale, 0)) then
local newVarUUID = LDNodeEditor.addNewVariable(ed, "core.number");
Expand Down
6 changes: 3 additions & 3 deletions LDYOM/Scripts/scripts/Core/ld/link.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@class LDNodeEditorLink
---@field id number
---@field inputId number
---@field outputId number
---@field id integer
---@field inputId integer
---@field outputId integer

0 comments on commit f8ffc59

Please sign in to comment.