Skip to content

Commit 68d803b

Browse files
committed
Add RmlUi polish features for GridView-based components
- Implement AssetView path navigation with up button and path display - Add SavedBrushes add/remove button support with visual styling - Temporarily disable smoke test GitHub action
1 parent ec27029 commit 68d803b

File tree

8 files changed

+367
-88
lines changed

8 files changed

+367
-88
lines changed
File renamed without changes.

scen_edit/view/asset_view.lua

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,70 @@ function AssetView:init(tbl)
4747
end
4848
end
4949
-- RmlUi mode: double-click is handled by GridView:_OnRmlUiItemClick
50-
if self.showPath and self.layoutPanel then
51-
-- Chili mode only
52-
self.scrollPanel:SetPos(nil, 20)
53-
self.lblPath = Label:New {
54-
x = 35,
55-
y = 3,
56-
width = 100,
57-
height = 20,
58-
caption = "",
59-
parent = self.holderControl,
60-
font = {
61-
color = {0.7, 0.7, 0.7, 1.0},
62-
},
63-
}
64-
self.btnUp = Button:New {
65-
x = 5,
66-
y = 2,
67-
width = 18,
68-
height = 18,
69-
caption = "",
70-
parent = self.holderControl,
71-
padding = {0, 0, 0, 0},
72-
children = {
73-
Image:New {
74-
x = 0,
75-
y = 0,
76-
width = "100%",
77-
height = "100%",
78-
margin = {0, 0, 0, 0},
79-
file = self.imageFolderUp,
80-
}
81-
},
82-
OnClick = {
83-
function()
84-
self:SetDir(Path.GetParentDir(self.dir))
85-
end
86-
},
87-
}
88-
if self.rootDir then
89-
self.lblRootDir = Label:New {
90-
right = 5,
50+
if self.showPath then
51+
if self.layoutPanel then
52+
-- Chili mode
53+
self.scrollPanel:SetPos(nil, 20)
54+
self.lblPath = Label:New {
55+
x = 35,
9156
y = 3,
9257
width = 100,
9358
height = 20,
94-
caption = "Root: " .. tostring(self.rootDir),
59+
caption = "",
9560
parent = self.holderControl,
9661
font = {
9762
color = {0.7, 0.7, 0.7, 1.0},
9863
},
9964
}
65+
self.btnUp = Button:New {
66+
x = 5,
67+
y = 2,
68+
width = 18,
69+
height = 18,
70+
caption = "",
71+
parent = self.holderControl,
72+
padding = {0, 0, 0, 0},
73+
children = {
74+
Image:New {
75+
x = 0,
76+
y = 0,
77+
width = "100%",
78+
height = "100%",
79+
margin = {0, 0, 0, 0},
80+
file = self.imageFolderUp,
81+
}
82+
},
83+
OnClick = {
84+
function()
85+
self:SetDir(Path.GetParentDir(self.dir))
86+
end
87+
},
88+
}
89+
if self.rootDir then
90+
self.lblRootDir = Label:New {
91+
right = 5,
92+
y = 3,
93+
width = 100,
94+
height = 20,
95+
caption = "Root: " .. tostring(self.rootDir),
96+
parent = self.holderControl,
97+
font = {
98+
color = {0.7, 0.7, 0.7, 1.0},
99+
},
100+
}
101+
end
102+
else
103+
-- RmlUi mode - create path navigation control
104+
self.pathNav = RmlUiPathNav({
105+
currentPath = tbl.dir or '',
106+
rootDir = self.rootDir,
107+
imageFolderUp = self.imageFolderUp,
108+
OnUpClick = {
109+
function()
110+
self:SetDir(Path.GetParentDir(self.dir))
111+
end
112+
}
113+
})
100114
end
101115
end
102116
self:SetDir(tbl.dir or '')
@@ -122,6 +136,9 @@ function AssetView:SetDir(directory)
122136
self.dir = directory
123137
if self.lblPath then
124138
self.lblPath:SetCaption(self.dir)
139+
elseif self.pathNav then
140+
-- RmlUi mode
141+
self.pathNav:SetPath(self.dir)
125142
end
126143
-- MaterialBrowser.lastDir = self.dir
127144
self:ScanDir()

scen_edit/view/editor.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,14 +913,20 @@ function Editor:_FinalizeRmlUi(children, opts)
913913
end
914914
end
915915

916+
-- Generate path navigation if gridView has it (AssetView)
917+
local pathNavHtml = ''
918+
if self.gridView and self.gridView.pathNav then
919+
pathNavHtml = self.gridView.pathNav:GenerateRml()
920+
end
921+
916922
-- Generate grid container if editor has a gridView
917923
local gridHtml = ''
918924
if self.gridView then
919925
gridHtml = string.format('<div id="%s" class="grid-container"></div>', self.gridView.gridId)
920926
end
921927

922-
-- Combine buttons, filters, grid, and fields
923-
self.generatedRml = buttonsHtml .. filtersHtml .. gridHtml .. fieldsHtml
928+
-- Combine buttons, filters, path nav, grid, and fields
929+
self.generatedRml = buttonsHtml .. filtersHtml .. pathNavHtml .. gridHtml .. fieldsHtml
924930

925931
-- Mark as hidden by default
926932
self.hidden = true
@@ -983,14 +989,20 @@ function Editor:_FinalizeRmlUiNew(layout, opts)
983989
end
984990
end
985991

992+
-- Generate path navigation if gridView has it (AssetView)
993+
local pathNavHtml = ''
994+
if self.gridView and self.gridView.pathNav then
995+
pathNavHtml = self.gridView.pathNav:GenerateRml()
996+
end
997+
986998
-- Generate grid container if editor has a gridView
987999
local gridHtml = ''
9881000
if self.gridView then
9891001
gridHtml = string.format('<div id="%s" class="grid-container"></div>', self.gridView.gridId)
9901002
end
9911003

992-
-- Combine buttons, filters, grid, and fields
993-
self.generatedRml = buttonsHtml .. filtersHtml .. gridHtml .. fieldsHtml
1004+
-- Combine buttons, filters, path nav, grid, and fields
1005+
self.generatedRml = buttonsHtml .. filtersHtml .. pathNavHtml .. gridHtml .. fieldsHtml
9941006

9951007
-- Mark as hidden by default
9961008
self.hidden = true

scen_edit/view/grid_view.lua

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,26 @@ function GridView:_UpdateRmlUiGrid()
449449
local itemId = self.gridId .. "_item_" .. idx
450450
local selectedClass = self.selectedIndices[idx] and " selected" or ""
451451

452+
-- Check if this is a special "Add" button item (SavedBrushes)
453+
local noBackground = item.__no_background and " no-background" or ""
452454
html = html .. string.format([[
453-
<div id="%s" class="grid-item%s" style="width: %ddp; height: %ddp;">
454-
]], itemId, selectedClass, self.itemWidth, self.itemHeight)
455-
456-
-- Add image if present
457-
if item.image then
455+
<div id="%s" class="grid-item%s%s" style="width: %ddp; height: %ddp;">
456+
]], itemId, selectedClass, noBackground, self.itemWidth, self.itemHeight)
457+
458+
-- Handle special "Add brush" item
459+
if item.__add_brush and item.OnAddClick then
460+
local addIconPath = item.addIcon or "LuaUI/images/scenedit/plus.png"
461+
if addIconPath:sub(1, 6) == "LuaUI/" then
462+
addIconPath = "../../../" .. addIconPath
463+
end
464+
html = html .. string.format([[
465+
<button id="%s-add-btn" class="add-brush-button">
466+
<img src="%s" class="add-brush-icon"/>
467+
<span class="add-brush-label">Add</span>
468+
</button>
469+
]], itemId, addIconPath)
470+
-- Normal grid item
471+
elseif item.image then
458472
local imagePath = item.image
459473
-- Handle both file paths (strings) and texture IDs (numbers/tables)
460474
if type(imagePath) == "string" then
@@ -485,19 +499,59 @@ function GridView:_UpdateRmlUiGrid()
485499
html = html .. string.format('<div class="grid-item-label">%s</div>', item.caption)
486500
end
487501

502+
-- Add remove button if item has one (SavedBrushes)
503+
if item.OnRemoveClick then
504+
local removeIconPath = item.removeIcon or "LuaUI/images/scenedit/cancel.png"
505+
if removeIconPath:sub(1, 6) == "LuaUI/" then
506+
removeIconPath = "../../../" .. removeIconPath
507+
end
508+
html = html .. string.format([[
509+
<button id="%s-remove-btn" class="remove-brush-button" title="Remove brush">
510+
<img src="%s"/>
511+
</button>
512+
]], itemId, removeIconPath)
513+
end
514+
488515
html = html .. '</div>'
489516
end
490517

491518
gridContainer.inner_rml = html
492519

493-
-- Bind click events for selection
520+
-- Bind click events for selection and special buttons
521+
local callListeners = CallListeners -- Capture for closures
494522
for idx, item in ipairs(self.childItems) do
495523
local itemId = self.gridId .. "_item_" .. idx
496-
local itemElement = SB.view.mainDocument:GetElementById(itemId)
497-
if itemElement then
498-
itemElement:AddEventListener("click", function()
499-
self:_OnRmlUiItemClick(idx)
500-
end)
524+
525+
-- Bind "Add" button click
526+
if item.__add_brush and item.OnAddClick then
527+
local addBtn = SB.view.mainDocument:GetElementById(itemId .. "-add-btn")
528+
if addBtn then
529+
addBtn:AddEventListener("click", function(event)
530+
callListeners(item.OnAddClick)
531+
event:StopPropagation() -- Don't trigger item selection
532+
end)
533+
end
534+
end
535+
536+
-- Bind "Remove" button click
537+
if item.OnRemoveClick then
538+
local removeBtn = SB.view.mainDocument:GetElementById(itemId .. "-remove-btn")
539+
if removeBtn then
540+
removeBtn:AddEventListener("click", function(event)
541+
callListeners(item.OnRemoveClick)
542+
event:StopPropagation() -- Don't trigger item selection
543+
end)
544+
end
545+
end
546+
547+
-- Bind item selection click (if not an add button)
548+
if not item.__add_brush then
549+
local itemElement = SB.view.mainDocument:GetElementById(itemId)
550+
if itemElement then
551+
itemElement:AddEventListener("click", function()
552+
self:_OnRmlUiItemClick(idx)
553+
end)
554+
end
501555
end
502556
end
503557
end

scen_edit/view/map/saved_brushes.lua

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,52 @@ function SavedBrushes:RemoveBrush(brushID)
110110
end
111111

112112
function SavedBrushes:_AddAddBrush()
113-
local addBrush = self:NewItem({
114-
tooltip = "Add new brush",
115-
children = {
116-
Button:New {
117-
x = 0, y = 0, right = 0, bottom = 0,
118-
caption = "",
119-
padding = {5, 5, 5, 5},
120-
children = {
121-
Image:New {
122-
x = 0, y = 0, right = 0, bottom = 15,
123-
file = Path.Join(SB.DIRS.IMG, "plus.png"),
113+
local addBrush
114+
if self.layoutPanel then
115+
-- Chili mode
116+
addBrush = self:NewItem({
117+
tooltip = "Add new brush",
118+
children = {
119+
Button:New {
120+
x = 0, y = 0, right = 0, bottom = 0,
121+
caption = "",
122+
padding = {5, 5, 5, 5},
123+
children = {
124+
Image:New {
125+
x = 0, y = 0, right = 0, bottom = 15,
126+
file = Path.Join(SB.DIRS.IMG, "plus.png"),
127+
},
128+
Label:New {
129+
x = 0, height = 10, right = 0, bottom = 0,
130+
align = 'center',
131+
autosize = false,
132+
caption = "Add",
133+
}
124134
},
125-
Label:New {
126-
x = 0, height = 10, right = 0, bottom = 0,
127-
align = 'center',
128-
autosize = false,
129-
caption = "Add",
135+
OnClick = {
136+
function()
137+
local brush = self.GetNewBrush()
138+
local brushID = self:AddBrush(brush)
139+
self:SelectBrush(brushID)
140+
end
130141
}
131142
},
132-
OnClick = {
133-
function()
134-
local brush = self.GetNewBrush()
135-
local brushID = self:AddBrush(brush)
136-
self:SelectBrush(brushID)
137-
end
138-
}
139-
},
143+
}
144+
})
145+
else
146+
-- RmlUi mode
147+
addBrush = self:NewItem({
148+
tooltip = "Add new brush",
149+
})
150+
addBrush.addIcon = Path.Join(SB.DIRS.IMG, "plus.png")
151+
addBrush.OnAddClick = {
152+
function()
153+
local brush = self.GetNewBrush()
154+
local brushID = self:AddBrush(brush)
155+
self:SelectBrush(brushID)
156+
end
140157
}
141-
})
158+
end
142159
--local addBrush = self:AddItem("Add", Path.Join(SB.DIRS.IMG, "add-plus-button.png"), "Add new brush")
143160
addBrush.__add_brush = true
144161
addBrush.__no_background = true
@@ -181,12 +198,24 @@ function SavedBrushes:PopulateItems()
181198
item.brushID = brush.brushID
182199

183200
if not self.disableRemove then
184-
local btnClose = self:_MakeCloseButton(brushID)
185-
item:AddChild(btnClose)
186-
item.btnClose = btnClose
187-
188-
item:SetChildLayer(item.imgCtrl, 2)
189-
item:SetChildLayer(item.btnClose, 1)
201+
if self.layoutPanel then
202+
-- Chili mode
203+
local btnClose = self:_MakeCloseButton(brushID)
204+
item:AddChild(btnClose)
205+
item.btnClose = btnClose
206+
207+
item:SetChildLayer(item.imgCtrl, 2)
208+
item:SetChildLayer(item.btnClose, 1)
209+
else
210+
-- RmlUi mode
211+
item.OnRemoveClick = {
212+
function()
213+
self:RemoveBrush(brushID)
214+
self:_UpdateBrushes()
215+
end
216+
}
217+
item.removeIcon = Path.Join(SB.DIRS.IMG, 'cancel.png')
218+
end
190219
end
191220
item:Invalidate()
192221
end

0 commit comments

Comments
 (0)