Need help with making a panel with a SpawnIcon inside.
3 replies, posted
Hey! I'm currently coding for a costumer (I suck at coding huds). And I'm making a list form of the Jobs SpawnIcons in DarkRP.
How would I make a panel (200, 64) long with a SpawnIcon (64, 64) inside?
Code:
[CODE] local function AddIcon(Model, name, description, Weapons, command, special, specialcommand)
local icon = vgui.Create("SpawnIcon")
local IconModel = Model
if type(Model) == "table" then
IconModel = Model[math.random(#Model)]
end
icon:SetModel(IconModel)
icon:SetSize(64, 64)
icon:SetToolTip()
icon.OnCursorEntered = function()
icon.PaintOverOld = icon.PaintOver
icon.PaintOver = icon.PaintOverHovered
Info[1] = DarkRP.getPhrase("job_name") .. name
Info[2] = DarkRP.getPhrase("job_description") .. description
Info[3] = DarkRP.getPhrase("job_weapons") .. Weapons
model = IconModel
UpdateInfo()
end[/CODE]
There are no errors. Just to be clear
So you are coding for a customer, but you want others to do the work ?
Don't you think that's exactly what your customer is NOT looking for? - a coder that cannot get the job done.
But answering your question:
First make a panel via vgui.Create()
then parent the spawnicon to it via vgui.Create('SpawnIcon', parentsName)
Oh no. I've just been having major problems.
I already tried that, but it turned up in the left top panel.
[QUOTE=jonasrh;41784903]Oh no. I've just been having major problems.
I already tried that, but it turned up in the left top panel.[/QUOTE]
Because you aren't parenting the panel to anything.
If you got some sort of menu, you would have to parent the panel to it the same way you parent spawnicon.
Also using a separate function for icon adding is silly, just use a for loop and a table of contents.
Here, this is from my container mod:
[lua]function cl_CM.OpenMenu()
local Container = net.ReadEntity()
Container.Items = net.ReadTable()
local Menu = vgui.Create( 'DFrame' )
Menu:SetSize( 5+(Container.Space * 52)+3, 80)
Menu:Center()
Menu:MakePopup()
Menu:SetTitle( 'Container ('..#Container.Items..'/'..Container.Space..')' )
Menu.lblTitle:SetColor( Color(142, 235, 0, 255) )
Menu.Paint = function()
draw.RoundedBox( 6, 0, 0, Menu:GetWide(), Menu:GetTall(), Color( 30, 30, 30, 255 ) )
end
--Ready space for items
for i=1, Container.Space do
local ItemPanel = vgui.Create( "DPanel", Menu )
ItemPanel:SetSize( 50, 50 )
ItemPanel:SetPos( 5+((i-1)*52), 25 )
ItemPanel:SetBackgroundColor( Color( 50, 50, 50, 255 ) )
ItemPanel.Paint = function()
surface.SetDrawColor( Color(142, 235, 0, 255) )
surface.DrawOutlinedRect( 0, 0, ItemPanel:GetWide(), ItemPanel:GetTall() )
end
--Add items to list
if Container.Items[i] then
local itemTbl = Container.Items[i]
local ItemIcon = vgui.Create( "SpawnIcon", ItemPanel )
ItemIcon:SetModel(itemTbl.Mdl)
ItemIcon:SetSize( 49, 49 )
ItemIcon:SetPos( 1, 1 )
ItemIcon:SetTooltip('Name: '..itemTbl.Name)
ItemIcon.DoClick = function()
net.Start( 'NET_ContainerDo' )
net.WriteEntity( Container )
net.WriteInt( i, 16 )
net.SendToServer()
ItemIcon:Remove()
end
end
end
end
net.Receive( 'NET_ContainerOpenMenu', cl_CM.OpenMenu )[/lua]
It basically creates panels for each slot in the container, then creates an icon if theres an item in that slot.
Sorry, you need to Log In to post a reply to this thread.