local function isValidPlayer(player)
return player and player.Player
end
function RoomsUI()
local dialog = GUIManager:getWindowByName("GameRoomsDialog")
local currentTab = currentTab or "Item"
if dialog then
dialog:SetVisible(not dialog:IsVisible())
return
end
dialog = GUIManager:createGUIWindow(GUIType.Window, "GameRoomsDialog")
if not dialog then return end
dialog:SetWidth({0, 600})
dialog:SetHeight({0, 500})
dialog:SetBackgroundColor({0.15, 0.15, 0.15, 0.95})
dialog:SetHorizontalAlignment(HorizontalAlignment.Center)
dialog:SetVerticalAlignment(VerticalAlignment.Center)
dialog:SetTouchable(true)
dialog:SetProperty("ClipChild", "true")
local titleBar = GUIManager:createGUIWindow(GUIType.Window, "TitleBar")
if not titleBar then return end
titleBar:SetWidth({1, 0})
titleBar:SetHeight({0, 50})
titleBar:SetBackgroundColor({0.1, 0.1, 0.3, 1})
titleBar:SetTouchable(true)
titleBar:SetProperty("ClipChild", "true")
dialog:AddChildWindow(titleBar)
local title = GUIManager:createGUIWindow(GUIType.StaticText, "Title")
if not title then return end
title:SetText("GAMEROOMS")
title:SetTextColor({0.8, 0.8, 1, 1})
title:SetWidth({1, -20})
title:SetHeight({1, -10})
title:SetTextHorzAlign(HorizontalAlignment.Center)
title:SetBordered(true)
title:SetProperty("Font", "Arial")
titleBar:AddChildWindow(title)
titleBar:registerEvent(GUIEvent.Click, function()
dialog:SetVisible(false)
end)
local tabContainer = GUIManager:createGUIWindow(GUIType.Window, "TabContainer")
if not tabContainer then return end
tabContainer:SetWidth({0, 150})
tabContainer:SetHeight({1, -50})
tabContainer:SetYPosition({0, 50})
tabContainer:SetBackgroundColor({0.2, 0.2, 0.2, 1})
tabContainer:SetProperty("ClipChild", "true")
dialog:AddChildWindow(tabContainer)
local contentContainer = GUIManager:createGUIWindow(GUIType.Window,
"ContentContainer")
if not contentContainer then return end
contentContainer:SetWidth({0, 450})
contentContainer:SetHeight({1, -50})
contentContainer:SetXPosition({0, 150})
contentContainer:SetYPosition({0, 50})
contentContainer:SetBackgroundColor({0.15, 0.15, 0.15, 0.95})
contentContainer:SetProperty("ClipChild", "true")
dialog:AddChildWindow(contentContainer)
local itemTab = GUIManager:createGUIWindow(GUIType.StaticText, "ItemTab")
if not itemTab then return end
itemTab:SetText("ITEM")
itemTab:SetWidth({1, -10})
itemTab:SetHeight({0, 50})
itemTab:SetXPosition({0, 5})
itemTab:SetYPosition({0, 10})
itemTab:SetTextColor({1, 1, 1, 1})
itemTab:SetBackgroundColor(currentTab == "Item" and {0.4, 0.4, 0.4, 1} or {0.3,
0.3, 0.3, 1})
itemTab:SetBordered(true)
itemTab:SetProperty("Font", "Arial")
itemTab:SetTextHorzAlign(HorizontalAlignment.Center)
tabContainer:AddChildWindow(itemTab)
local allItemsTab = GUIManager:createGUIWindow(GUIType.StaticText,
"AllItemsTab")
if not allItemsTab then return end
allItemsTab:SetText("ITEM LIST")
allItemsTab:SetWidth({1, -10})
allItemsTab:SetHeight({0, 50})
allItemsTab:SetXPosition({0, 5})
allItemsTab:SetYPosition({0, 70})
allItemsTab:SetTextColor({1, 1, 1, 1})
allItemsTab:SetBackgroundColor(currentTab == "AllItems" and {0.4, 0.4, 0.4, 1}
or {0.3, 0.3, 0.3, 1})
allItemsTab:SetBordered(true)
allItemsTab:SetProperty("Font", "Arial")
allItemsTab:SetTextHorzAlign(HorizontalAlignment.Center)
tabContainer:AddChildWindow(allItemsTab)
local itemContent = GUIManager:createGUIWindow(GUIType.Window, "ItemContent")
if not itemContent then return end
itemContent:SetWidth({1, 0})
itemContent:SetHeight({1, 0})
itemContent:SetBackgroundColor({0.15, 0.15, 0.15, 0.95})
itemContent:SetVisible(currentTab == "Item")
itemContent:SetProperty("ClipChild", "true")
contentContainer:AddChildWindow(itemContent)
local allItemsContent = GUIManager:createGUIWindow(GUIType.ScrollablePane,
"AllItemsContent")
if not allItemsContent then return end
allItemsContent:SetWidth({1, 0})
allItemsContent:SetHeight({1, 0})
allItemsContent:SetYPosition({0, 0})
allItemsContent:SetBackgroundColor({0.15, 0.15, 0.15, 0.95})
allItemsContent:SetProperty("ClipChild", "true")
allItemsContent:SetProperty("AutoScrollBar", "true")
allItemsContent:SetTouchable(true)
allItemsContent:InitializeContainer()
allItemsContent:SetVisible(currentTab == "AllItems")
contentContainer:AddChildWindow(allItemsContent)
local searchInput = GUIManager:createGUIWindow(GUIType.Edit, "SearchInput")
if not searchInput then return end
searchInput:SetWidth({0, 430})
searchInput:SetHeight({0, 40})
searchInput:SetXPosition({0, 10})
searchInput:SetYPosition({0, 10})
searchInput:SetTextColor({0.9, 0.9, 1, 1})
searchInput:SetBackgroundColor({0.2, 0.2, 0.3, 1})
searchInput:SetBordered(true)
searchInput:SetText("Searchitems")
searchInput:SetMaxLength(100)
searchInput:SetCaratOffset(5)
searchInput:SetProperty("Font", "Arial")
allItemsContent:AddChildWindow(searchInput)
searchInput:registerEvent(GUIEvent.Click, function()
if searchInput:GetText() == "Searchitems" then
searchInput:SetText("")
end
end)
local itemPreview = GUIManager:createGUIWindow(GUIType.Window, "ItemPreview")
if not itemPreview then return end
itemPreview:SetWidth({0, 300})
itemPreview:SetHeight({0, 50})
itemPreview:SetBackgroundColor({0.1, 0.1, 0.2, 0.95})
itemPreview:SetXPosition({0, -310})
itemPreview:SetYPosition({0, 180})
itemPreview:SetTouchable(false)
itemPreview:SetVisible(false)
itemPreview:SetProperty("ClipChild", "true")
GUISystem.Instance():GetRootWindow():AddChildWindow(itemPreview)
local previewText = GUIManager:createGUIWindow(GUIType.StaticText,
"PreviewText")
if not previewText then return end
previewText:SetWidth({1, -10})
previewText:SetHeight({1, -10})
previewText:SetTextColor({0.8, 0.8, 1, 1})
previewText:SetTextHorzAlign(HorizontalAlignment.Center)
previewText:SetBordered(true)
previewText:SetProperty("Font", "Arial")
itemPreview:AddChildWindow(previewText)
local animating = false
local animTimer = nil
local function animatePreview(show)
if animating and animTimer then
LuaTimer:cancel(animTimer)
animTimer = nil
end
animating = true
itemPreview:SetVisible(show)
local startTime = os.clock()
animTimer = LuaTimer:scheduleTimer(function()
local elapsed = os.clock() - startTime
local progress = math.min(elapsed / 0.3, 1)
if show then
itemPreview:SetXPosition({0, -310 + (320 * progress)})
else
itemPreview:SetXPosition({0, -310 + (320 * (1 - progress))})
end
if progress >= 1 then
animating = false
if not show then
itemPreview:SetVisible(false)
end
LuaTimer:cancel(animTimer)
animTimer = nil
end
end, 0.016, -1)
end
local function createInputLabel(text, yPos, parent)
local label = GUIManager:createGUIWindow(GUIType.StaticText, "Label" ..
math.random(1000, 9999))
if not label then return end
label:SetText(text)
label:SetTextColor({0.7, 0.7, 0.9, 1})
label:SetWidth({0, 120})
label:SetHeight({0, 40})
label:SetXPosition({0, 20})
label:SetYPosition({0, yPos})
label:SetBordered(true)
label:SetProperty("Font", "Arial")
label:SetTextHorzAlign(HorizontalAlignment.Left)
parent:AddChildWindow(label)
return label
end
local function giveItem(itemId, count, meta)
local player = PlayerManager:getClientPlayer()
if isValidPlayer(player) then
player:sendPacket({
pid = "CreativeAddItem",
data = { count = count or 64, id = itemId, meta = meta or 0 }
})
HostApi.notifyGetItem(itemId, meta or 0, count or 64)
end
animatePreview(false)
end
local itemData = {}
local function initializeItemButtons()
itemData = {}
local yPos = 60
local batchSize = 100
local currentIndex = 1
local function processBatch()
local endIndex = math.min(currentIndex + batchSize - 1, 6999)
for id = currentIndex, endIndex do
local item = Item.getItemById(id)
if item then
local unlocName = item:getUnlocalizedName()
if unlocName then
local displayName = Lang:getString(unlocName) or unlocName
local fullText = id .. ":" .. displayName
local itemButton =
GUIManager:createGUIWindow(GUIType.StaticText, "ItemBtn" .. id)
if itemButton then
itemButton:SetText(fullText)
itemButton:SetWidth({0, 430})
itemButton:SetHeight({0, 40})
itemButton:SetXPosition({0, 10})
itemButton:SetYPosition({0, yPos})
itemButton:SetTextColor({1, 1, 1, 1})
itemButton:SetBackgroundColor({0.2, 0.2, 0.3, 1})
itemButton:SetBordered(true)
itemButton:SetProperty("Font", "Arial")
itemButton:SetTextHorzAlign(HorizontalAlignment.Left)
itemButton:SetVisible(false)
itemButton:registerEvent(GUIEvent.Click, function()
giveItem(id, 64, 0)
end)
allItemsContent:AddItem(itemButton)
table.insert(itemData, {id = id, text = fullText,
button = itemButton, yPos = yPos})
yPos = yPos + 45
end
end
end
end
currentIndex = endIndex + 1
if currentIndex <= 6999 then
LuaTimer:scheduleTimer(processBatch, 0.016, 1)
end
end
processBatch()
end
local function populateAllItems()
local query = searchInput:GetText():lower()
if query == "Searchitems" then query = "" end
local yPos = 60
for _, data in ipairs(itemData) do
local visible = query == "" or data.text:lower():find(query)
data.button:SetVisible(visible)
data.button:SetYPosition({0, visible and yPos or -1000})
if visible then
yPos = yPos + 45
end
end
allItemsContent:SetVertScrollOffset(0)
end
if #itemData == 0 then
initializeItemButtons()
end
searchInput:registerEvent(GUIEvent.TextChanged, function()
populateAllItems()
end)
local idLabel = createInputLabel("ITEMID:", 20, itemContent)
if not idLabel then return end
local idInput = GUIManager:createGUIWindow(GUIType.Edit, "IDInput")
if not idInput then return end
idInput:SetWidth({0, 280})
idInput:SetHeight({0, 40})
idInput:SetXPosition({0, 150})
idInput:SetYPosition({0, 20})
idInput:SetTextColor({0.9, 0.9, 1, 1})
idInput:SetBackgroundColor({0.2, 0.2, 0.3, 1})
idInput:SetBordered(true)
idInput:SetMaxLength(100)
idInput:SetCaratOffset(5)
idInput:SetProperty("Font", "Arial")
itemContent:AddChildWindow(idInput)
local countLabel = createInputLabel("COUNT:", 70, itemContent)
if not countLabel then return end
local countInput = GUIManager:createGUIWindow(GUIType.Edit, "CountInput")
if not countInput then return end
countInput:SetWidth({0, 280})
countInput:SetHeight({0, 40})
countInput:SetXPosition({0, 150})
countInput:SetYPosition({0, 70})
countInput:SetTextColor({0.9, 0.9, 1, 1})
countInput:SetBackgroundColor({0.2, 0.2, 0.3, 1})
countInput:SetMaxLength(100)
countInput:SetText("64")
countInput:SetBordered(true)
countInput:SetCaratOffset(5)
countInput:SetProperty("Font", "Arial")
itemContent:AddChildWindow(countInput)
local metaLabel = createInputLabel("META:", 120, itemContent)
if not metaLabel then return end
local metaInput = GUIManager:createGUIWindow(GUIType.Edit, "MetaInput")
if not metaInput then return end
metaInput:SetWidth({0, 280})
metaInput:SetHeight({0, 40})
metaInput:SetXPosition({0, 150})
metaInput:SetYPosition({0, 120})
metaInput:SetTextColor({0.9, 0.9, 1, 1})
metaInput:SetMaxLength(100)
metaInput:SetBackgroundColor({0.2, 0.2, 0.3, 1})
metaInput:SetText("0")
metaInput:SetBordered(true)
metaInput:SetCaratOffset(5)
metaInput:SetProperty("Font", "Arial")
itemContent:AddChildWindow(metaInput)
local itemGiveBtn = GUIManager:createGUIWindow(GUIType.StaticText,
"ItemGiveBtn")
if not itemGiveBtn then return end
itemGiveBtn:SetText("GIVEITEM")
itemGiveBtn:SetWidth({0, 135})
itemGiveBtn:SetHeight({0, 40})
itemGiveBtn:SetXPosition({0, 150})
itemGiveBtn:SetYPosition({0, 180})
itemGiveBtn:SetTextColor({1, 1, 1, 1})
itemGiveBtn:SetBackgroundColor({0.2, 0.5, 0.2, 1})
itemGiveBtn:SetBordered(true)
itemGiveBtn:SetProperty("Font", "Arial")
itemGiveBtn:SetTextHorzAlign(HorizontalAlignment.Center)
itemContent:AddChildWindow(itemGiveBtn)
local itemCloseBtn = GUIManager:createGUIWindow(GUIType.StaticText,
"ItemCloseBtn")
if not itemCloseBtn then return end
itemCloseBtn:SetText("CLOSE")
itemCloseBtn:SetWidth({0, 135})
itemCloseBtn:SetHeight({0, 40})
itemCloseBtn:SetXPosition({0, 295})
itemCloseBtn:SetYPosition({0, 180})
itemCloseBtn:SetTextColor({1, 1, 1, 1})
itemCloseBtn:SetBackgroundColor({0.5, 0.2, 0.2, 1})
itemCloseBtn:SetBordered(true)
itemCloseBtn:SetProperty("Font", "Arial")
itemCloseBtn:SetTextHorzAlign(HorizontalAlignment.Center)
itemContent:AddChildWindow(itemCloseBtn)
local function updateItemName()
local itemId = tonumber(idInput:GetText())
if not itemId then
animatePreview(false)
return
end
local item = Item.getItemById(itemId)
if not item then
previewText:SetText("InvalidID:" .. itemId)
animatePreview(true)
return
end
local unlocName = item:getUnlocalizedName()
if not unlocName then return end
local displayName = Lang:getString(unlocName) or unlocName
previewText:SetText(displayName)
local textWidth = previewText:GetTextWidth() + 20
itemPreview:SetWidth({0, math.max(textWidth, 300)})
animatePreview(true)
end
idInput:registerEvent(GUIEvent.TextChanged, updateItemName)
itemGiveBtn:registerEvent(GUIEvent.Click, function()
local itemId = tonumber(idInput:GetText())
if not itemId then
UIHelper.showToast("Enter valid ID")
return
end
local count = tonumber(countInput:GetText()) or 64
local meta = tonumber(metaInput:GetText()) or 0
giveItem(itemId, count, meta)
end)
itemCloseBtn:registerEvent(GUIEvent.Click, function()
dialog:SetVisible(false)
animatePreview(false)
end)
local function switchTab(activeTab, activeContent, inactiveTab,
inactiveContent, tabName)
currentTab = tabName
if activeTab then activeTab:SetBackgroundColor({0.4, 0.4, 0.4, 1}) end
if inactiveTab then inactiveTab:SetBackgroundColor({0.3, 0.3, 0.3, 1}) end
if activeContent then activeContent:SetVisible(true) end
if inactiveContent then inactiveContent:SetVisible(false) end
if activeContent == allItemsContent then
animatePreview(false)
populateAllItems()
end
end
itemTab:registerEvent(GUIEvent.Click, function()
switchTab(itemTab, itemContent, allItemsTab, allItemsContent, "Item")
end)
allItemsTab:registerEvent(GUIEvent.Click, function()
switchTab(allItemsTab, allItemsContent, itemTab, itemContent, "AllItems")
end)
local openBtn = GUIManager:createGUIWindow(GUIType.StaticText, "OpenBtn")
if not openBtn then return end
openBtn:SetText("GAMEROOMS")
openBtn:SetWidth({0, openBtn:GetTextWidth() + 40})
openBtn:SetHeight({0, 45})
openBtn:SetXPosition({0, 20})
openBtn:SetYPosition({0, 80})
openBtn:SetBackgroundColor({0.2, 0.2, 0.4, 1})
openBtn:SetTextColor({1, 1, 1, 1})
openBtn:SetBordered(true)
openBtn:SetProperty("Font", "Arial")
openBtn:SetTextHorzAlign(HorizontalAlignment.Center)
GUISystem.Instance():GetRootWindow():AddChildWindow(openBtn)
openBtn:registerEvent(GUIEvent.Click, function()
dialog:SetVisible(true)
if currentTab == "Item" then
itemContent:SetVisible(true)
allItemsContent:SetVisible(false)
itemTab:SetBackgroundColor({0.4, 0.4, 0.4, 1})
allItemsTab:SetBackgroundColor({0.3, 0.3, 0.3, 1})
elseif currentTab == "AllItems" then
itemContent:SetVisible(false)
allItemsContent:SetVisible(true)
itemTab:SetBackgroundColor({0.3, 0.3, 0.3, 1})
allItemsTab:SetBackgroundColor({0.4, 0.4, 0.4, 1})
populateAllItems()
end
animatePreview(false)
end)
GUISystem.Instance():GetRootWindow():AddChildWindow(dialog)
end
RoomsUI()