使用函数绘制 Derma 按钮出现问题

我在使用 Derma SpawnIcon 时遇到了一些问题。当我使用函数绘制一个 SpawnIcon 时,它能够正常工作。但是,当我尝试使用相同的函数绘制第二个 SpawnIcon 时,DoClick 函数只对最后一个 SpawnIcon 工作。我不知道为什么会这样,也不知道如何修复,请帮帮我?。

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 ) ) -- 画圆角矩形代替窗口
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 ) ) -- 画圆角矩形代替窗口
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 ) --设置面板大小
DPanel:SetBackgroundColor(Color(25,25,25,155))

local ImgKnop = DScrollPanel:Add( "SpawnIcon", panel1 )
ImgKnop:SetPos( ScrW() * 0/1920, ScrH() * 0/1080 )              -- //设置位置
ImgKnop:SetSize( ScrW() * 200/1920, ScrH() * 100/1080  )            -- //如果需要固定大小,可使用此项而非 SizeToContents()
ImgKnop:SetModel( mdl ) -- //设置材质 - 相对于 /materials/ 目录
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)

一些图片,如果我的英语不好,你可能什么都看不懂 last SpawnIcon work ok

second and first SpawnIcon dont work(

点赞
用户15037302
用户15037302
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 ) ) -- 替换窗口框架。
    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 ) ) -- 替换窗口框架。
    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 ) -- 设置面板的大小。
    DPanel:SetBackgroundColor(Color(25,25,25,155))

    local ImgKnop = DPanel:Add( "SpawnIcon" )
    ImgKnop:SetPos( ScrW() * 0/1920, ScrH() * 0/1080 )              -- 设置位置。
    ImgKnop:SetSize( ScrW() * 200/1920, ScrH() * 100/1080  )            -- 如果你想要固定大小的话,可以使用该函数代替SizeToContents()。
    ImgKnop:SetModel( mdl ) -- 设置元素素材。
    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 )
2021-01-19 13:21:13