-1

I have some trouble with Derma SpawnIcon. When i draw 1 SpawnIcon with function it work okay, but when i try to use the same function and draw second SpawnIcon DoClick function work only for last SpawnIcon. I dont have any idea why that happens, and how to fix this, please help me :(

cl_hud.lua (in autroun)

function DrawCrateDERMA( textebat, mdl )

Frame = vgui.Create( "DFrame" ) --Создаёт окно.
    Frame:SetTitle( "Оружейный ящик" )  --Устанавливает название окна.
    Frame:SetSize( ScrW() * 800/1920, ScrH() * 600/1080 )
    Frame:Center()
    Frame:SetDraggable( false )
    Frame:ShowCloseButton( true )
    Frame:MakePopup(true)
    Frame:SetBackgroundBlur(false)
    Frame.Paint = function( self, w, h ) -- 'function Frame:Paint( w, h )' works too
    draw.RoundedBox( 5, 0, 0, w, h, Color( 25, 25, 25, 200 ) ) -- Draw a red box instead of the frame
end

--[[----------------Создаём панельки--------------]]

sheet = vgui.Create( "DPropertySheet", Frame )
sheet:Dock( FILL )

    --[[----------------Панелька 1--------------]]
panel1 = vgui.Create( "DPanel", sheet )

panel1.Paint = function( self, w, h ) draw.RoundedBox( 100, 0, 0, 280, 120, Color( 0, 0, 0, 0) ) end  
sheet:AddSheet( "Основное оружие", panel1, "materials/gunsicon.png" )
sheet.Paint = function( self, w, h ) -- 'function Frame:Paint( w, h )' works too
    draw.RoundedBox( 5, 0, 0, w, h, Color( 50, 50, 50, 150 ) ) -- Draw a red box instead of the frame
end

end



function DrawCratePrimWeapon(textebat, mdl, posx, posy, functonclick)

local DScrollPanel = vgui.Create( "DScrollPanel" , panel1 )
DScrollPanel:Dock( FILL )

DPanel = DScrollPanel:Add( "DPanel")
DPanel:SetPos( ScrW() * posx/1920, ScrH() * posy/1080 )
DPanel:SetSize( ScrW() * 200/1920, ScrH() * 100/1080 ) -- Set the size of the panel
DPanel:SetBackgroundColor(Color(25,25,25,155))

local ImgKnop = DScrollPanel:Add( "SpawnIcon", panel1 )
ImgKnop:SetPos( ScrW() * 0/1920, ScrH() * 0/1080 )              --// Set position
ImgKnop:SetSize( ScrW() * 200/1920, ScrH() * 100/1080  )            --// OPTIONAL: Use instead of SizeToContents() if you know/want to fix the size
ImgKnop:SetModel( mdl ) --// Set the material - relative to /materials/ directory
ImgKnop:SetParent(DPanel)
ImgKnop.DoClick = function()
print("SUKA")
end

local text1 = DScrollPanel:Add("DLabel",panel1)
text1:SetPos(ScrW() * 0/1920, ScrH() * 75/1080)
text1:SetText(textebat)
text1:SizeToContents()
text1:SetParent(DPanel)

end

cl_init.lua (in my entities)

include("shared.lua")
  

function ENT:Draw()
    self:DrawModel()
end

dob = 260

net.Receive("poslat", function()
DrawCrateDERMA("GAVNO","models/props_interiors/Furniture_Couch02a.mdl")
DrawCratePrimWeapon("228/1337","models/props_c17/furnitureStove001a.mdl", 25 , 25 )
DrawCratePrimWeapon("22345528/1337","models/props_c17/oildrum001.mdl", 25+dob , 25 )
DrawCratePrimWeapon("22328/1337","models/props_c17/lampShade001a.mdl", 25+dob+dob , 25 )
end)  

some pic, if my english was too bad, that you understand literally nothing from that text on top last SpawnIcon work ok

second and first SpawnIcon dont work(

DeloreanZ
  • 13
  • 2

1 Answers1

1
function DrawCrateDERMA( textebat, mdl )
    
    local Frame = vgui.Create( "DFrame" ) --Создаёт окно.
    Frame:SetTitle( "Оружейный ящик" )  --Устанавливает название окна.
    Frame:SetSize( ScrW() * 800/1920, ScrH() * 600/1080 )
    Frame:Center()
    Frame:SetDraggable( false )
    Frame:ShowCloseButton( true )
    Frame:MakePopup(true)
    Frame:SetBackgroundBlur(false)
    Frame.Paint = function( self, w, h ) -- 'function Frame:Paint( w, h )' works too
        draw.RoundedBox( 5, 0, 0, w, h, Color( 25, 25, 25, 200 ) ) -- Draw a red box instead of the frame
    end
    
    --[[----------------Создаём панельки--------------]]
    
    local sheet = vgui.Create( "DPropertySheet", Frame )
    sheet:Dock( FILL )
    
    --[[----------------Панелька 1--------------]]
    local panel1 = vgui.Create( "DPanel", sheet )
    panel1.Paint = function( self, w, h ) draw.RoundedBox( 100, 0, 0, 280, 120, Color( 0, 0, 0, 0) ) end  
    sheet:AddSheet( "Основное оружие", panel1, "materials/gunsicon.png" )
    sheet.Paint = function( self, w, h ) -- 'function Frame:Paint( w, h )' works too
        draw.RoundedBox( 5, 0, 0, w, h, Color( 50, 50, 50, 150 ) ) -- Draw a red box instead of the frame
    end
    
    local DScrollPanel = vgui.Create( "DScrollPanel" , panel)
    DScrollPanel:Dock( FILL )

    return DScrollPanel
end
    
function DrawCratePrimWeapon(panel, textebat, mdl, posx, posy, functonclick)
    
    local DPanel = panel:Add( "DPanel")
    DPanel:SetPos( ScrW() * posx/1920, ScrH() * posy/1080 )
    DPanel:SetSize( ScrW() * 200/1920, ScrH() * 100/1080 ) -- Set the size of the panel
    DPanel:SetBackgroundColor(Color(25,25,25,155))
    
    local ImgKnop = DPanel:Add( "SpawnIcon" )
    ImgKnop:SetPos( ScrW() * 0/1920, ScrH() * 0/1080 )              --// Set position
    ImgKnop:SetSize( ScrW() * 200/1920, ScrH() * 100/1080  )            --// OPTIONAL: Use instead of SizeToContents() if you know/want to fix the size
    ImgKnop:SetModel( mdl ) --// Set the material - relative to /materials/ directory
    ImgKnop:SetParent(DPanel)
    ImgKnop.DoClick = function()
        print("SUKA")
    end
    
    local text1 = DScrollPanel:Add("DLabel",panel)
    text1:SetPos(ScrW() * 0/1920, ScrH() * 75/1080)
    text1:SetText(textebat)
    text1:SizeToContents()
    text1:SetParent(DPanel)
    
end
    
local panel = DrawCrateDERMA("GAVNO","models/props_interiors/Furniture_Couch02a.mdl")
DrawCratePrimWeapon(panel,"228/1337","models/props_c17/furnitureStove001a.mdl", 25 , 25 )
DrawCratePrimWeapon(panel,"22345528/1337","models/props_c17/oildrum001.mdl", 25+dob , 25 )
DrawCratePrimWeapon(panel,"22328/1337","models/props_c17/lampShade001a.mdl", 25+dob+dob , 25 )
LiGyH
  • 26
  • 2
  • it is a good practice to advocate your solution with some arguments – zhisme Jan 19 '21 at 13:34
  • Yay, that work! Now i see, that the DScrollPanel was that problem. Thank you! In a raw variable of your code SpawnIcon was draw behind Frame, but when in DScrollPanel i changed panel, to panel1 it start working prorerly! My thanks for the help! – DeloreanZ Jan 19 '21 at 13:56