Skip to content

Commit b091ddb

Browse files
committed
Move RML generation to Editor:Finalize() method
Fixed architecture - RML is now generated when editor initializes, not when opened: editor.lua changes: - Editor:Finalize() now detects RmlUi mode and calls _FinalizeRmlUi() - _FinalizeRmlUi() loops through fields, calls GenerateRml(), stores result - Generated RML stored in editor.generatedRml - Added ShowRmlUi() and HideRmlUi() methods for visibility view.lua changes: - OpenEditor() now uses pre-generated editor.generatedRml - No longer generates RML on-the-fly - Much cleaner - just displays what was already generated This is the correct flow: 1. Editor constructor calls init() 2. Editor adds fields with AddField() 3. Editor calls Finalize() which: - RmlUi mode: generates RML → editor.generatedRml - Chili mode: creates Chili controls → editor.window 4. User clicks button → OpenEditor() displays editor.generatedRml All field generation happens during editor initialization!
1 parent d172d2b commit b091ddb

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

scen_edit/view/editor.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ function Editor:Finalize(children, opts)
115115
end
116116

117117
opts = opts or {}
118+
119+
-- In RmlUi mode, generate RML from fields instead of creating Chili controls
120+
if SB.view and SB.view.useRmlUi then
121+
self:_FinalizeRmlUi(opts)
122+
self.__initializing = false
123+
return
124+
end
125+
126+
-- Chili mode continues below
118127
self:_FinalizeButtons(children, opts)
119128

120129
local OnShow = {function() self:__OnShow() end}
@@ -655,3 +664,44 @@ end
655664

656665
-- We load these fields last as they might be/contain subclasses of editor view
657666
SB.IncludeDir(Path.Join(SB.DIRS.SRC, 'view/fields'))
667+
668+
-- RmlUi-specific finalization
669+
function Editor:_FinalizeRmlUi(opts)
670+
-- Generate RML for all fields
671+
local html = ''
672+
673+
for _, fieldName in ipairs(self.fieldOrder) do
674+
local field = self.fields[fieldName]
675+
if field and field.GenerateRml then
676+
html = html .. field:GenerateRml()
677+
elseif field then
678+
-- Fallback for fields without GenerateRml (like separators/controls)
679+
html = html .. '<div class="field-separator"></div>'
680+
end
681+
end
682+
683+
-- Store the generated RML for later use
684+
self.generatedRml = html
685+
686+
-- Mark as hidden by default
687+
self.hidden = true
688+
end
689+
690+
-- Show the editor in RmlUi mode
691+
function Editor:ShowRmlUi()
692+
self.hidden = false
693+
if SB.view and SB.view.OpenEditor then
694+
-- Trigger view to display this editor
695+
for name, editor in pairs(SB.editors) do
696+
if editor == self then
697+
SB.view:DisplayEditor(name)
698+
break
699+
end
700+
end
701+
end
702+
end
703+
704+
-- Hide the editor in RmlUi mode
705+
function Editor:HideRmlUi()
706+
self.hidden = true
707+
end

scen_edit/view/view.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,26 +440,26 @@ function View:OpenEditor(editorName)
440440
local editor = SB.editors[editorName]
441441
local editorCfg = SB.editorRegistry[editorName]
442442
local mainContent = self.mainDocument:GetElementById("main-content")
443+
443444
if mainContent and editor then
444-
-- Render all fields to RML
445-
local html = '<div class="editor-container"><h3 class="editor-title">' .. (editorCfg and editorCfg.caption or editorName) .. '</h3>'
446-
447-
-- Generate RML for each field in order
448-
for _, fieldName in ipairs(editor.fieldOrder) do
449-
local field = editor.fields[fieldName]
450-
if field and field.GenerateRml then
451-
html = html .. field:GenerateRml()
452-
elseif field then
453-
-- Fallback for fields without GenerateRml (like separators)
454-
html = html .. '<div class="field-separator"></div>'
455-
end
445+
-- Use pre-generated RML from Finalize()
446+
local html = '<div class="editor-container"><h3 class="editor-title">' ..
447+
(editorCfg and editorCfg.caption or editorName) .. '</h3>'
448+
449+
if editor.generatedRml then
450+
html = html .. editor.generatedRml
451+
else
452+
html = html .. '<p>Editor has no fields defined</p>'
456453
end
457454

458455
html = html .. '</div>'
459456
mainContent.inner_rml = html
460457

461458
-- Bind field events
462459
self:BindFieldEvents(editor)
460+
461+
-- Mark editor as visible
462+
editor.hidden = false
463463
end
464464

465465
-- Highlight pressed button

0 commit comments

Comments
 (0)