Skip to content

Commit 3574790

Browse files
committed
Add button compatibility layer for RmlUi editors
Buttons (TabbedPanelButton and Button:New) now work automagically in both Chili and RmlUi modes through the compatibility layer. Changes: - Add button compatibility layer in rmlui_field_compat.lua - RmlUiTabbedPanelButton: Action buttons (Add, Set, Smooth, etc.) - RmlUiButton: Regular buttons added via AddControl() - Override TabbedPanelButton(), Button.New() to create RmlUi buttons - Buttons store OnClick handlers, captions, images, tooltips - SetPressedState() updates button CSS class when pressed - Update Editor:_FinalizeRmlUi() to process buttons from children - Extract action buttons and regular buttons from children array - Generate HTML for action buttons panel at top of editor - Generate HTML for regular buttons within fields section - Store buttons for event binding - Update View:BindFieldEvents() to bind button click events - Bind action button clicks to their OnClick handlers - Bind regular button clicks to their OnClick handlers - Use CallListeners() to invoke handlers - Add CSS styling for action buttons - .action-buttons-panel: Horizontal button strip at editor top - .action-button: 70x70dp buttons with icon + label - .action-button.pressed: Green highlight when active - .action-button-icon and .action-button-label styling - Delete unused RmlUi editor files - rmlui_editor_base.lua: Separate editor approach not used - rmlui_components.lua: Empty editor stubs not used - Keep rmlui_component.lua (used by picker windows) All existing editors (heightmap, metal, grass, texture, etc.) now have their action buttons working in RmlUi mode without any code changes.
1 parent 330afc3 commit 3574790

File tree

6 files changed

+253
-402
lines changed

6 files changed

+253
-402
lines changed

scen_edit/view/editor.lua

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function Editor:Finalize(children, opts)
118118

119119
-- In RmlUi mode, generate RML from fields instead of creating Chili controls
120120
if SB.view and SB.view.useRmlUi then
121-
self:_FinalizeRmlUi(opts)
121+
self:_FinalizeRmlUi(children, opts)
122122
self.__initializing = false
123123
return
124124
end
@@ -725,25 +725,59 @@ end
725725
SB.IncludeDir(Path.Join(SB.DIRS.SRC, 'view/fields'))
726726

727727
-- RmlUi-specific finalization
728-
function Editor:_FinalizeRmlUi(opts)
729-
-- Generate RML for all fields
730-
local html = ''
728+
function Editor:_FinalizeRmlUi(children, opts)
729+
children = children or {}
730+
opts = opts or {}
731+
732+
-- Extract action buttons from children (TabbedPanelButton instances)
733+
self.actionButtons = {}
734+
self.regularButtons = {}
735+
736+
for _, child in ipairs(children) do
737+
if child and type(child) == "table" then
738+
-- Check if it's an RmlUi button
739+
if child.GenerateRml and child.OnClick then
740+
if child.id and child.id:match("^action%-btn%-") then
741+
table.insert(self.actionButtons, child)
742+
elseif child.id and child.id:match("^btn%-") then
743+
table.insert(self.regularButtons, child)
744+
end
745+
end
746+
end
747+
end
731748

749+
-- Generate RML for action buttons (placed at top)
750+
local buttonsHtml = ''
751+
if #self.actionButtons > 0 then
752+
buttonsHtml = '<div class="action-buttons-panel">'
753+
for _, button in ipairs(self.actionButtons) do
754+
buttonsHtml = buttonsHtml .. button:GenerateRml()
755+
end
756+
buttonsHtml = buttonsHtml .. '</div>'
757+
end
758+
759+
-- Generate RML for all fields
760+
local fieldsHtml = ''
732761
for _, fieldName in ipairs(self.fieldOrder) do
733762
local field = self.fields[fieldName]
734763
-- Skip fields that are children of GroupFields (they're rendered by the group)
735764
if field and not field._isGroupChild then
736765
if field.GenerateRml then
737-
html = html .. field:GenerateRml()
766+
fieldsHtml = fieldsHtml .. field:GenerateRml()
738767
else
739-
-- Fallback for fields without GenerateRml (like separators/controls)
740-
html = html .. '<div class="field-separator"></div>'
768+
-- Check if it's a control with a button
769+
if field.ctrl and field.ctrl.GenerateRml then
770+
fieldsHtml = fieldsHtml .. field.ctrl:GenerateRml()
771+
else
772+
-- Fallback for other controls
773+
fieldsHtml = fieldsHtml .. '<div class="field-separator"></div>'
774+
end
741775
end
742776
end
743777
end
744778

745-
-- Store the generated RML for later use
746-
self.generatedRml = html
779+
-- Combine buttons and fields
780+
self.generatedRml = buttonsHtml .. fieldsHtml
747781

748782
-- Mark as hidden by default
749783
self.hidden = true

scen_edit/view/rcss/springboard.rcss

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,69 @@ body#springboard {
202202
border: 1dp #2a5f8f;
203203
padding: 5dp 10dp;
204204
cursor: pointer;
205+
margin-bottom: 10dp;
205206
}
206207

207208
.field-button:hover {
208209
background-color: #4a8ecf;
209210
}
210211

212+
/* Action buttons panel at top of editor */
213+
.action-buttons-panel {
214+
display: flex;
215+
flex-direction: row;
216+
gap: 0dp;
217+
margin-bottom: 15dp;
218+
padding: 5dp;
219+
background-color: #2a2a2a;
220+
border-bottom: 1dp #555555;
221+
}
222+
223+
.action-button {
224+
display: flex;
225+
flex-direction: column;
226+
align-items: center;
227+
justify-content: center;
228+
width: 70dp;
229+
height: 70dp;
230+
background-color: #3a3a3a;
231+
border: 1dp #555555;
232+
padding: 5dp;
233+
cursor: pointer;
234+
margin-right: 0dp;
235+
}
236+
237+
.action-button:hover {
238+
background-color: #4a4a4a;
239+
border-color: #777777;
240+
}
241+
242+
.action-button.pressed {
243+
background-color: #2a5f2a;
244+
border-color: #3a7f3a;
245+
}
246+
247+
.action-button-icon {
248+
width: 35dp;
249+
height: 35dp;
250+
margin-bottom: 3dp;
251+
}
252+
253+
.action-button.pressed .action-button-icon {
254+
decorator: image;
255+
image-color: #00ff00;
256+
}
257+
258+
.action-button-label {
259+
font-size: 11dp;
260+
color: #ffffff;
261+
text-align: center;
262+
}
263+
264+
.action-button.pressed .action-button-label {
265+
color: #00ff00;
266+
}
267+
211268
.field-separator {
212269
height: 1dp;
213270
background-color: #555555;

scen_edit/view/rmlui_components.lua

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)