Skip to content

Commit 5605e26

Browse files
committed
Implement RmlUi GridView support for Objects tab
This implements full dual-mode (Chili + RmlUi) support for GridView, enabling the Objects tab (Units/Features) and other grid-based UIs to work in RmlUi mode. GridView Changes: - Split initialization into _InitRmlUi() and _InitChili() methods - Added wrapper methods to hide layoutPanel access from subclasses: * ClearChildren(), AddChildItem(), GetChildItem(), Invalidate() - Updated all public API methods for dual-mode support: * GetSelectedItems(), SelectItem(), DeselectAll() * StartMultiModify(), EndMultiModify() * GetControl() returns placeholder in RmlUi mode - Created RmlUi-compatible item abstraction in NewItem() and AddItem() * Items are simple tables in RmlUi mode, Chili controls in Chili mode * Added SetImage() wrapper method to items - Implemented _UpdateRmlUiGrid() for DOM rendering - Added _OnRmlUiItemClick() with selection and double-click support - RmlUi grids use HTML/CSS flexbox layout instead of Chili LayoutPanel Subclass Updates: - ObjectDefsPanel: Use wrapper methods instead of direct layoutPanel access * Updated FilterItems(), GetObjectDefID(), AddDrawIcon() * item.SetImage() instead of item.imgCtrl.file assignment - AssetView: Made double-click and showPath UI Chili-only - SavedBrushes: Updated OnBrushImageUpdated() to use item:SetImage() Editor Integration: - _FinalizeRmlUi() and _FinalizeRmlUiNew() generate grid container div - View:OpenEditor() triggers grid update after rendering - ObjectDefsView stores gridView reference for rendering CSS: - Added .grid-container, .grid-item styles with flexbox layout - Grid items show hover, selected states - Proper image and label styling within grid items This maintains full backward compatibility with Chili mode while enabling the critical Objects tab functionality in RmlUi.
1 parent 9f5b9b9 commit 5605e26

File tree

8 files changed

+461
-146
lines changed

8 files changed

+461
-146
lines changed

scen_edit/view/asset_view.lua

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,30 @@ function AssetView:init(tbl)
2525
-- FIXME: Cleanup double click handling hack
2626
self.__previousDoubleClickTime = Spring.GetTimer()
2727

28-
self.layoutPanel.MouseDblClick = function(ctrl, x, y, button, mods)
29-
if button ~= 1 then
30-
return
31-
end
32-
local cx,cy = ctrl:LocalToClient(x,y)
33-
local itemIdx = ctrl:GetItemIndexAt(cx,cy)
28+
if self.layoutPanel then
29+
-- Chili mode
30+
self.layoutPanel.MouseDblClick = function(ctrl, x, y, button, mods)
31+
if button ~= 1 then
32+
return
33+
end
34+
local cx,cy = ctrl:LocalToClient(x,y)
35+
local itemIdx = ctrl:GetItemIndexAt(cx,cy)
3436

35-
if itemIdx < 0 then return end
37+
if itemIdx < 0 then return end
3638

37-
local item = self.items[itemIdx]
38-
if item == nil then
39-
return
40-
end
39+
local item = self.items[itemIdx]
40+
if item == nil then
41+
return
42+
end
4143

42-
self:DoubleClickItem(item)
44+
self:DoubleClickItem(item)
4345

44-
return ctrl
46+
return ctrl
47+
end
4548
end
46-
if self.showPath then
49+
-- RmlUi mode: double-click is handled by GridView:_OnRmlUiItemClick
50+
if self.showPath and self.layoutPanel then
51+
-- Chili mode only
4752
self.scrollPanel:SetPos(nil, 20)
4853
self.lblPath = Label:New {
4954
x = 35,
@@ -113,7 +118,7 @@ function AssetView:DoubleClickItem(item)
113118
end
114119

115120
function AssetView:SetDir(directory)
116-
self.layoutPanel:DeselectAll()
121+
self:DeselectAll()
117122
self.dir = directory
118123
if self.lblPath then
119124
self.lblPath:SetCaption(self.dir)

scen_edit/view/editor.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,14 @@ function Editor:_FinalizeRmlUi(children, opts)
886886
end
887887
end
888888

889-
-- Combine buttons and fields
890-
self.generatedRml = buttonsHtml .. fieldsHtml
889+
-- Generate grid container if editor has a gridView
890+
local gridHtml = ''
891+
if self.gridView then
892+
gridHtml = string.format('<div id="%s" class="grid-container"></div>', self.gridView.gridId)
893+
end
894+
895+
-- Combine buttons, grid, and fields
896+
self.generatedRml = buttonsHtml .. gridHtml .. fieldsHtml
891897

892898
-- Mark as hidden by default
893899
self.hidden = true
@@ -937,8 +943,14 @@ function Editor:_FinalizeRmlUiNew(layout, opts)
937943
end
938944
end
939945

940-
-- Combine buttons and fields
941-
self.generatedRml = buttonsHtml .. fieldsHtml
946+
-- Generate grid container if editor has a gridView
947+
local gridHtml = ''
948+
if self.gridView then
949+
gridHtml = string.format('<div id="%s" class="grid-container"></div>', self.gridView.gridId)
950+
end
951+
952+
-- Combine buttons, grid, and fields
953+
self.generatedRml = buttonsHtml .. gridHtml .. fieldsHtml
942954

943955
-- Mark as hidden by default
944956
self.hidden = true

0 commit comments

Comments
 (0)