-
Notifications
You must be signed in to change notification settings - Fork 33
Description
I am creating a custom GUI based on itemgui.lua from LuaExamples. The purpose of this script is to detect items in specific containers on the submarine, categorize and count them, and then display the statistics on a luadevice menu.
if SERVER then return end
Hook.Patch("Barotrauma.Items.Components.CustomInterface", "CreateGUI", function (instance, ptable)
if not instance.originalElement.GetAttributeString("type", "") == "luacustom" then
return
end
local item = instance.Item
local frame = instance.GuiFrame
local menuList = GUI.ListBox(
GUI.RectTransform(Vector2(0.4, 0.9),
frame.RectTransform, GUI.Anchor.TopLeft,GUI.Pivot.TopLeft)
)
menuList.RectTransform.RelativeOffset=Vector2(0.02,0.05)
GUI.TextBlock(
GUI.RectTransform(Vector2(1.0, 0.1),
menuList.Content.RectTransform, GUI.Anchor.TopLeft,GUI.Pivot.TopLeft),
"Test TextBlock"
)
ListBoxContent = menuList.Content.RectTransform
end)
if Game.IsSingleplayer then
Hook.Add("UpdateCntGUI","CntGUI",function () --This hook will be called outside the file
DT_GUI_UpdateCnt()
end)
end
function DT_GUI_UpdateCnt()
for iden, itemdata in pairs(Digital_Terminal.Data) do
if Digital_Terminal.CntBoxes[iden] then
Digital_Terminal.CntBoxes[iden].Text = itemdata.Name .. ":" .. itemdata.Cnt
else
Digital_Terminal.CntBoxes[iden] = DT_GUI_CntBox(iden)
end
end
end
function DT_GUI_CntBox(iden)
local cntBox = GUI.TextBlock(GUI.RectTransform(Vector2(1, 0.1),
ListBoxContent,GUI.Anchor.TopLeft,GUI.Pivot.TopLeft),
Digital_Terminal.Data[iden].Name .. ":" .. Digital_Terminal.Data[iden].Cnt
, nil, nil, GUI.Alignment.Right)
GUI.Image(
GUI.RectTransform(Vector2(0.1, 1.0),
cntBox.RectTransform, GUI.Anchor.TopLeft,GUI.Pivot.TopLeft),
ItemPrefab.GetItemPrefab(iden).Sprite
)
print("Created GUI box for item: " .. iden)
return cntBox
endThe data source, Digital_Terminal.Data, is a table maintained in a separate file that records item counts by category. I have verified that the content of this table is completely correct. My approach is to populate a menuList (ListBox) by dynamically adding TextBlock and Image components to display the quantity of each item category.
The Issue:
I have encountered a strange problem regarding where the device is placed:
Simple Scene: In a simple custom scene I built, the GUI always renders and updates correctly, regardless of whether there are 11 item types or over 60.
Complex Submarine (e.g., Dugong): When I place the luadevice on a more complex submarine, the TextBlock and Image elements for the item statistics fail to render or update entirely.
The CreateGUI hook is triggered correctly, but the menu stops updating afterwards.
Console Output:
As the logs indicate, 65 item types representatively were detected, and the DT_GUI_CntBox function appears to be executing normally. However, the luadevice simply does not render these TextBlock and Image components on its GUI in the complex environment.No errors are logged in the console at any point during execution.
