Skip to content

Commit 3fe7832

Browse files
committed
Implement tab switching and editor button population
Fixed widget errors and implemented core tabbed interface logic: RML Changes: - Removed team selector (will use Chili floating widget like original) - Removed onclick handlers causing widget errors - Simplified tab buttons (Objects, Map, Env, Misc) - Tab IDs match tab names (tab-Objects, tab-Map, etc.) RCSS Changes: - Adjusted layout: tabs at 10dp, editor buttons at 40dp, content at 125dp - Added flex-shrink: 0 to editor buttons for proper scrolling - Reduced sizes to match tighter layout View.lua Changes: - Added BindTabEvents() - binds click events to tab buttons - Added SwitchTab() - switches active tab and updates styling - Added PopulateEditorButtons() - reads SB.editorRegistry and creates buttons - Added OpenEditor() - placeholder for opening editors - Added UpdateEditorButtonStates() - highlights pressed editor button - Initializes with Objects tab by default Next: Implement field rendering system to show actual editor content
1 parent ec7db08 commit 3fe7832

File tree

3 files changed

+155
-52
lines changed

3 files changed

+155
-52
lines changed

scen_edit/view/rcss/springboard.rcss

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,28 @@ body#springboard {
1010
background-color: #1a1a1a;
1111
}
1212

13-
/* Team selector (top right corner) */
14-
.team-selector {
15-
position: absolute;
16-
top: 10dp;
17-
right: 10dp;
18-
padding: 5dp;
19-
background-color: #2a2a2a;
20-
border: 1dp #555555;
21-
border-radius: 3dp;
22-
display: flex;
23-
flex-direction: row;
24-
gap: 5dp;
25-
align-items: center;
26-
}
27-
28-
.team-selector label {
29-
color: #cccccc;
30-
}
31-
32-
.team-selector select {
33-
background-color: #3a3a3a;
34-
color: #cccccc;
35-
border: 1dp #555555;
36-
padding: 3dp;
37-
}
38-
39-
/* Tab bar */
13+
/* Tab bar at top */
4014
.tab-bar {
4115
position: absolute;
42-
top: 50dp;
16+
top: 10dp;
4317
left: 0dp;
4418
right: 0dp;
45-
height: 30dp;
46-
background-color: #2a2a2a;
19+
height: 25dp;
20+
background-color: #222222;
4721
display: flex;
4822
flex-direction: row;
49-
gap: 2dp;
50-
padding: 2dp;
23+
gap: 1dp;
24+
padding: 1dp;
5125
}
5226

5327
.tab-button {
5428
flex: 1;
5529
background-color: #3a3a3a;
5630
color: #999999;
5731
border: 1dp #555555;
58-
padding: 5dp 10dp;
32+
padding: 3dp 8dp;
5933
text-align: center;
34+
font-size: 12dp;
6035
cursor: pointer;
6136
}
6237

@@ -71,10 +46,10 @@ body#springboard {
7146
border-bottom: 2dp #3a7ebf;
7247
}
7348

74-
/* Editor button panel (scrollable horizontal) */
49+
/* Editor button panel (scrollable horizontal) - matches TOOLBOX_ITEM_HEIGHT (70dp) + padding */
7550
.editor-panel-wrapper {
7651
position: absolute;
77-
top: 85dp;
52+
top: 40dp;
7853
left: 0dp;
7954
right: 0dp;
8055
height: 80dp;
@@ -104,6 +79,7 @@ body#springboard {
10479
align-items: center;
10580
justify-content: center;
10681
padding: 5dp;
82+
flex-shrink: 0;
10783
}
10884

10985
.editor-button:hover {
@@ -119,23 +95,24 @@ body#springboard {
11995
.editor-button img {
12096
width: 35dp;
12197
height: 35dp;
122-
margin-bottom: 5dp;
98+
margin-bottom: 3dp;
12399
}
124100

125101
.editor-button-label {
126-
font-size: 10dp;
102+
font-size: 9dp;
127103
color: #cccccc;
128104
text-align: center;
105+
word-wrap: break-word;
129106
}
130107

131108
.editor-button.pressed .editor-button-label {
132109
color: #00ff00;
133110
}
134111

135-
/* Main content area */
112+
/* Main content area - starts after editor panel (40 + 80 = 120dp) */
136113
.main-content {
137114
position: absolute;
138-
top: 170dp;
115+
top: 125dp;
139116
left: 0dp;
140117
right: 0dp;
141118
bottom: 0dp;

scen_edit/view/rml/springboard_main.rml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@
55
<link type="text/rcss" href="../rcss/springboard.rcss"/>
66
</head>
77
<body id="springboard">
8-
<!-- Team selector (top right) -->
9-
<div id="team-selector-container" class="team-selector">
10-
<label>Team:</label>
11-
<select id="team-selector">
12-
<option value="0">Team 0</option>
13-
<option value="1">Team 1</option>
14-
</select>
15-
</div>
16-
178
<!-- Tab bar -->
189
<div id="tab-bar" class="tab-bar">
19-
<button id="tab-objects" class="tab-button active" data-tab="Objects" onclick="widget:OnTabClick(event)">Objects</button>
20-
<button id="tab-map" class="tab-button" data-tab="Map" onclick="widget:OnTabClick(event)">Map</button>
21-
<button id="tab-env" class="tab-button" data-tab="Env" onclick="widget:OnTabClick(event)">Env</button>
22-
<button id="tab-misc" class="tab-button" data-tab="Misc" onclick="widget:OnTabClick(event)">Misc</button>
10+
<button id="tab-Objects" class="tab-button active">Objects</button>
11+
<button id="tab-Map" class="tab-button">Map</button>
12+
<button id="tab-Env" class="tab-button">Env</button>
13+
<button id="tab-Misc" class="tab-button">Misc</button>
2314
</div>
2415

2516
<!-- Editor button panel (scrollable horizontal) -->

scen_edit/view/view.lua

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

86+
-- Initialize tab system
87+
self.currentTab = "Objects"
88+
self:BindTabEvents()
89+
self:PopulateEditorButtons(self.currentTab)
90+
8691
-- Initialize floating windows (hidden by default)
8792
self.commandWindow = RmlUiCommandWindow()
8893
self.commandWindow:Initialize()
@@ -323,3 +328,133 @@ function View:DrawWorldPreUnit()
323328
end
324329
self.selectionManager:DrawWorldPreUnit()
325330
end
331+
332+
-- RmlUi tab and editor button management
333+
function View:BindTabEvents()
334+
if not self.mainDocument then return end
335+
336+
-- Bind click events to all tab buttons
337+
local tabs = {"Objects", "Map", "Env", "Misc"}
338+
for _, tabName in ipairs(tabs) do
339+
local tabButton = self.mainDocument:GetElementById("tab-" .. tabName)
340+
if tabButton then
341+
tabButton:AddEventListener("click", function()
342+
self:SwitchTab(tabName)
343+
end)
344+
end
345+
end
346+
end
347+
348+
function View:SwitchTab(tabName)
349+
if self.currentTab == tabName then return end
350+
351+
-- Update tab button styles
352+
local tabs = {"Objects", "Map", "Env", "Misc"}
353+
for _, name in ipairs(tabs) do
354+
local tabButton = self.mainDocument:GetElementById("tab-" .. name)
355+
if tabButton then
356+
if name == tabName then
357+
tabButton:SetClass("active", true)
358+
else
359+
tabButton:SetClass("active", false)
360+
end
361+
end
362+
end
363+
364+
self.currentTab = tabName
365+
self:PopulateEditorButtons(tabName)
366+
367+
-- Clear main content area
368+
local mainContent = self.mainDocument:GetElementById("main-content")
369+
if mainContent then
370+
mainContent.inner_rml = "<p>Select an editor from the buttons above</p>"
371+
end
372+
end
373+
374+
function View:PopulateEditorButtons(tabName)
375+
local editorPanel = self.mainDocument:GetElementById("editor-button-panel")
376+
if not editorPanel then return end
377+
378+
-- Clear existing buttons
379+
editorPanel.inner_rml = ""
380+
381+
-- Get all editors for this tab from editorRegistry
382+
local editors = {}
383+
for name, editorCfg in pairs(SB.editorRegistry) do
384+
if editorCfg.tab == tabName then
385+
table.insert(editors, editorCfg)
386+
end
387+
end
388+
389+
-- Sort by order
390+
table.sort(editors, function(a, b)
391+
if a.order ~= b.order then
392+
return a.order < b.order
393+
end
394+
return a.caption < b.caption
395+
end)
396+
397+
-- Create button HTML for each editor
398+
local buttonsHTML = ""
399+
for _, editorCfg in ipairs(editors) do
400+
local btnId = "editor-btn-" .. editorCfg.name
401+
buttonsHTML = buttonsHTML .. string.format([[
402+
<div id="%s" class="editor-button">
403+
<div class="editor-button-label">%s</div>
404+
</div>
405+
]], btnId, editorCfg.caption)
406+
end
407+
408+
editorPanel.inner_rml = buttonsHTML
409+
410+
-- Bind click events to editor buttons
411+
for _, editorCfg in ipairs(editors) do
412+
local btnId = "editor-btn-" .. editorCfg.name
413+
local btn = self.mainDocument:GetElementById(btnId)
414+
if btn then
415+
btn:AddEventListener("click", function()
416+
self:OpenEditor(editorCfg.name)
417+
end)
418+
end
419+
end
420+
end
421+
422+
function View:OpenEditor(editorName)
423+
Log.Notice("Opening editor: " .. editorName)
424+
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
438+
end
439+
440+
local editor = SB.editors[editorName]
441+
local mainContent = self.mainDocument:GetElementById("main-content")
442+
if mainContent and editor then
443+
-- For now, just show a placeholder
444+
-- TODO: Implement full editor rendering with fields
445+
mainContent.inner_rml = "<h3>Editor: " .. editorName .. "</h3><p>Fields will be rendered here</p>"
446+
end
447+
448+
-- Highlight pressed button
449+
self:UpdateEditorButtonStates(editorName)
450+
end
451+
452+
function View:UpdateEditorButtonStates(activeEditorName)
453+
-- Remove pressed state from all buttons
454+
for name, _ in pairs(SB.editorRegistry) do
455+
local btn = self.mainDocument:GetElementById("editor-btn-" .. name)
456+
if btn then
457+
btn:SetClass("pressed", name == activeEditorName)
458+
end
459+
end
460+
end

0 commit comments

Comments
 (0)