I'm making a small GUI to display info about a player and the server, for sandbox. I made a small Derma panel and linked it up with some File.Write to make savable settings for the GUI (for example: Remove X from the GUI but keep Y). Here is my current progress with the GUI: [url]http://i.imgur.com/MUO4qnc.png[/url]
I would like to make it so that, for example, if I disabled the "Total propcount" part via my clientside Derma panel, everything BELOW it would slide up X in the Y direction. I've tried for hours on end and had no luck, every idea I've had becomes far too complicated, perfect example:
[CODE]if CSettings[1] == 1 then
if MyPropCount ~= nil then
draw.SimpleText("Your propcount: "..MyPropCount,"HUDFont", ScrW()/75, (0 + ScrH()/15) , Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end
elseif MyPropCount == nil then
draw.SimpleText("Your propcount: Loading...", "HUDFont", ScrW()/75, (0 + ScrH()/15) , Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)-- Your propcount disabled
end
if CSettings[2] == 1 then
if CSettings[3] == 1 or CSettings[5] == 1 then
RemoveY = (CSettings[4]-1)*RemoveOneY
if CSettings[3] == 1 and CSettings[5] == 1 then
RemoveY = (CSettings[4]-2)*RemoveOneY
end
else
RemoveY = CSettings[4]*RemoveOneY
end
draw.SimpleText("Total propcount: "..CGUI_TotalPropCount,"HUDFont", ScrW()/75, ((0 + ScrH()/20)+RemoveY), Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end
if CSettings[3] == 1 then
draw.SimpleText("Test","HUDFont", ScrW()/75, ((0 + ScrH()/20)+(CSettings[4]*RemoveOneY)), Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end[/CODE]
So does anybody have any ideas to make the text move up automatically when a value is disabled - only the text below it, obviously.
You'd draw the text and increment Y each time a line gets drawn if its disabled don't increment. That way the text will auto adjust.
Sorry not good at doing code on the fly off the top of my head but thats how you'd do it.
Create a table that stores those values. Then, use a DIconLayout. For each entry of the table, add to it and set it equal to the name and such.
[lua]function GM:CreateMainMenu()
-- Used when clicking off the main menu to close it --
local gw_menu_close = vgui.Create("DFrame")
gw_menu_close:SetSize(ScrW(), ScrH())
gw_menu_close:SetTitle("")
gw_menu_close:ShowCloseButton(false)
gw_menu_close:MakePopup(true)
gw_menu_close.Paint = function() end
gw_menu_close.OnMousePressed = function()
gw_menu_close:Close()
end
-- The main menu that players see --
local gw_menu = vgui.Create("DFrame", gw_menu_close)
gw_menu:MakePopup(true)
gw_menu:ShowCloseButton(false)
gw_menu:SetTitle("")
gw_menu:SetSize(gmw, gmh)
gw_menu:SetPos(ScrW() / 2 - gw_menu:GetWide() / 2, ScrH() / 2 - gw_menu:GetTall() / 2)
gw_menu.Paint = function()
draw.RoundedBox(8, 0, 0, gmw, gmh, Color(255, 255, 255, 155))
draw.RoundedBox(8, 2, 2, gmw - 4, gmh - 4, Color(55, 55, 55, 155))
end
-- The layout that allows us to easily add more (and keep things sorted) --
local gw_selection = vgui.Create("DIconLayout", gw_menu)
gw_selection:SetSize(gmw, 50)
gw_selection:SetPos(0, 0)
gw_selection:SetSpaceY(0)
gw_selection:SetSpaceX(0)
-- Selecting the boss category --
local gw_boss_selection = gw_selection:Add("DButton")
gw_boss_selection:SetSize(gmw, 60)
gw_boss_selection:SetText("")
gw_boss_selection.Paint = function()
draw.RoundedBoxEx(8, 2, 2, gmw - 4, 60, Color(178, 34, 34, 225), true, true, false, false)
gw_drawimage(mats[1], Color(255, 255, 255), 15, 10, 48, 48)
gw_drawimage(mats[1], Color(255, 255, 255), gw_boss_selection:GetWide() - 63, 10, 48, 48)
draw.SimpleText("Boss Selection", "HUDText_Rage", gw_boss_selection:GetWide() / 2, 25, Color(255, 255, 255), TEXT_ALIGN_CENTER)
end
gw_boss_selection.OnMousePressed = function()
gw_menu_close:Close()
self:CreateBossSelection()
end
-- Choosing a loadout category --
local gw_loadout_selection = gw_selection:Add("DButton")
gw_loadout_selection:SetSize(gmw, 60)
gw_loadout_selection:SetText("")
gw_loadout_selection.Paint = function()
draw.RoundedBoxEx(8, 2, 2, gmw - 4, 60, Color(205, 201, 201, 75), false, false, false, false)
gw_drawimage(mats[2], Color(255, 255, 255, 75), 15, 10, 48, 48)
gw_drawimage(mats[2], Color(255, 255, 255, 75), gw_loadout_selection:GetWide() - 63, 10, 48, 48)
draw.SimpleText("Loadout", "HUDText_Rage", gw_loadout_selection:GetWide() / 2, 25, Color(255, 255, 255, 75), TEXT_ALIGN_CENTER)
end
-- Selecting a class category --
local gw_class_selection = gw_selection:Add("DButton")
gw_class_selection:SetSize(gmw, 60)
gw_class_selection:SetText("")
gw_class_selection.Paint = function()
draw.RoundedBoxEx(8, 2, 2, gmw - 4, 60, Color(218, 165, 32, 225), false, false, false, false)
gw_drawimage(mats[3], Color(255, 255, 255), 15, 10, 48, 48)
gw_drawimage(mats[3], Color(255, 255, 255), gw_class_selection:GetWide() - 63, 10, 48, 48)
draw.SimpleText("Class Selection", "HUDText_Rage", gw_class_selection:GetWide() / 2, 25, Color(255, 255, 255), TEXT_ALIGN_CENTER)
end
gw_class_selection.OnMousePressed = function()
gw_menu_close:Close()
GAMEMODE:CreateClassSelection()
end
-- Looking in your inventory category --
local gw_inventory_selection = gw_selection:Add("DButton")
gw_inventory_selection:SetSize(gmw, 60)
gw_inventory_selection:SetText("")
gw_inventory_selection.Paint = function()
draw.RoundedBoxEx(8, 2, 2, gmw - 4, 60, Color(160, 82, 45, 255), false, false, true, true)
gw_drawimage(mats[4], Color(255, 255, 255, 255), 15, 10, 48, 48)
gw_drawimage(mats[4], Color(255, 255, 255, 255), gw_inventory_selection:GetWide() - 63, 10, 48, 48)
draw.SimpleText("Inventory Selection", "HUDText_Rage", gw_inventory_selection:GetWide() / 2, 25, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER)
end
gw_inventory_selection.DoClick = function()
gw_menu_close:Close()
GAMEMODE:CreateInventoryMenu()
end
end[/lua]
This is what I use for my main menu in Garry's Warehouse.
Thank you! I fixed it in a similar way to your main menu:
[CODE]local Elements = {}
local Loading = "Loading..."
if CSettings[1] == 1 then
Elements["TotalProps"] = {"Total propcount: ",CGUI_TotalPropCount}
end
if CSettings[2] == 1 and MyPropCount ~= nil then
Elements["YourProps"] = {"My propcount: ",MyPropCount}
elseif CSettings[2] == 1 then
Elements["YourProps"] = {"My propcount: ",Loading}
end
if CSettings[3] == 1 and MyPropCount ~= nil then
Elements["TestOne"] = {"TestOne ",MyPropCount}
end
function Draws(Str,Height)
local Height = (Height * ScrH()/AspectSpacer)
draw.SimpleText(Str,"HUDFont", ScrW()/75, (Height + ScrH()/OptionYPos) , Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end
local Order = 1
for k,v in pairs(Elements) do
Draws(v[1]..v[2],Order)
Order = Order + 1
end
end [/CODE]
Sorry, you need to Log In to post a reply to this thread.