【发布时间】:2021-04-23 18:34:49
【问题描述】:
我在使用 Derma SpawnIcon 时遇到了一些问题。当我用函数绘制 1 个 SpawnIcon 时它可以正常工作,但是当我尝试使用相同的函数并绘制第二个 SpawnIcon DoClick 函数时,它仅适用于最后一个 SpawnIcon。我不知道为什么会发生这种情况,以及如何解决这个问题,请帮助我:(
cl_hud.lua(在自动机中)
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(在我的实体中)
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)
【问题讨论】:
-
DButton 和 DButtonImage 也会发生很少的 UPD:(
标签: lua garrys-mod