Skip to content

Commit 279fd1a

Browse files
committed
Fix field initialization and editor creation
- Add Set() method to RmlUiField (alias for SetValue) for Chili API compatibility - Fix GroupField to auto-generate name like Chili does (_groupField1, etc.) - Register GroupField child fields in Editor:AddField() for RmlUi mode - Initialize ALL editors upfront in View:InitializeAllEditors() * Called during View:InitializeRmlUi() instead of lazy creation * Catches field errors early instead of when users click buttons * Generates RML for all editors during init via Finalize() - Update OpenEditor() to use pre-initialized editors This fixes: - "Attempted to add field without name" errors from GroupField children - "attempt to call method 'Set' (a nil value)" errors - Late error detection when clicking UI buttons
1 parent b091ddb commit 279fd1a

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

scen_edit/view/editor.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ function Editor:AddField(field)
362362
field.ctrl = self:_AddControl(field.name, field.components)
363363
end
364364
self:_AddField(field)
365+
366+
-- In RmlUi mode, register child fields of GroupField
367+
if SB.view and SB.view.useRmlUi and field.fields then
368+
for _, childField in ipairs(field.fields) do
369+
if childField.name then
370+
self:_AddField(childField)
371+
end
372+
end
373+
end
374+
365375
-- Only call Added() if the method exists (Chili fields)
366376
if field.Added then
367377
field:Added()

scen_edit/view/rmlui_field_compat.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ ObjectField = RmlUiObjectField
2323
ObjectTypeField = RmlUiObjectTypeField
2424
TeamField = RmlUiTeamField
2525
ArrayField = RmlUiArrayField
26-
GroupField = RmlUiGroupField
26+
27+
-- GroupField wrapper that matches Chili's constructor pattern
28+
-- Auto-generates name like Chili does
29+
local _GROUP_INDEX = 0
30+
function GroupField(fields)
31+
_GROUP_INDEX = _GROUP_INDEX + 1
32+
local name = "_groupField" .. tostring(_GROUP_INDEX)
33+
return RmlUiGroupField({
34+
name = name,
35+
fields = fields
36+
})
37+
end
2738

2839
-- Picker windows
2940
AssetPickerWindow = RmlUiAssetPickerWindow

scen_edit/view/rmlui_fields.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function RmlUiField:SetValue(value)
4040
end
4141
end
4242

43+
-- Alias for compatibility with Chili field API
44+
function RmlUiField:Set(value)
45+
self:SetValue(value)
46+
end
47+
4348
function RmlUiField:UpdateDisplay()
4449
-- Override in subclass
4550
end

scen_edit/view/view.lua

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ function View:InitializeRmlUi()
8383
return
8484
end
8585

86+
-- Initialize ALL editors upfront from editorRegistry
87+
-- This generates RML during init so we catch errors early
88+
self:InitializeAllEditors()
89+
8690
-- Initialize tab system
8791
self.currentTab = "Objects"
8892
self:BindTabEvents()
@@ -159,6 +163,29 @@ function View:InitializeRmlUi()
159163
Log.Notice("RmlUi UI initialized successfully with all dialogs, editors, and floating windows")
160164
end
161165

166+
function View:InitializeAllEditors()
167+
-- Initialize SB.editors table if it doesn't exist
168+
if not SB.editors then
169+
SB.editors = {}
170+
end
171+
172+
-- Instantiate all editors from editorRegistry
173+
-- This calls their init() which calls Finalize() which generates RML
174+
-- Doing this upfront catches field errors early instead of when users click buttons
175+
Log.Notice("Initializing all editors from editorRegistry...")
176+
local count = 0
177+
for name, editorCfg in pairs(SB.editorRegistry) do
178+
if editorCfg.editor then
179+
Log.Notice(" Creating editor: " .. name)
180+
SB.editors[name] = editorCfg.editor()
181+
count = count + 1
182+
else
183+
Log.Warning(" Editor " .. name .. " has no constructor function")
184+
end
185+
end
186+
Log.Notice("Initialized " .. count .. " editors")
187+
end
188+
162189
function View:SetupRmlUiEvents()
163190
if not self.mainDocument then
164191
return
@@ -422,22 +449,13 @@ end
422449
function View:OpenEditor(editorName)
423450
Log.Notice("Opening editor: " .. editorName)
424451

425-
-- Create editor instance if not exists
426-
if not SB.editors then
427-
SB.editors = {}
428-
end
429-
430-
if not SB.editors[editorName] then
431-
local editorCfg = SB.editorRegistry[editorName]
432-
if editorCfg and editorCfg.editor then
433-
SB.editors[editorName] = editorCfg.editor()
434-
else
435-
Log.Error("Editor not found: " .. editorName)
436-
return
437-
end
452+
-- Editor should already be initialized during View:InitializeAllEditors()
453+
local editor = SB.editors and SB.editors[editorName]
454+
if not editor then
455+
Log.Error("Editor not initialized: " .. editorName)
456+
return
438457
end
439458

440-
local editor = SB.editors[editorName]
441459
local editorCfg = SB.editorRegistry[editorName]
442460
local mainContent = self.mainDocument:GetElementById("main-content")
443461

0 commit comments

Comments
 (0)