Problem with panel (child button not a have reactions on events)
1 replies, posted
Hi, I’m making an addon and experienced one problem: Child panel does not respond on “panel.Hovered” and “panel.DoClick” also doesn’t have any reaction at “self.Hovered” and “self.DoClick”
(child is a exit button on screenshots)
https://u.furhost.pw/cmARCck.png
Here is code fragment
//entity computer
function ENT:Initialize()
if !IsValid(EcoGov.panels.computer) then
EcoGov.panels.computer = vgui.Create("desktop")
EcoGov.panels.computer:Center()
EcoGov.panels.computer:SetPaintedManually(true)
EcoGov.panels.computer:SetMouseInputEnabled(false)
EcoGov.panels.computer:SetKeyboardInputEnabled(false)
end
self.gui = EcoGov.panels.computer
hook.Add("DoLogin",self,self.DoLogin)
hook.Add("DoExitFromComputer",self,self.DoExitFromComputer)
hook.Add("computer_use",self,self.computer_use)
end
function ENT:DoLogin()
local isMayor = LocalPlayer():getChar():getClass() == CLASS_MAYOR
if isMayor then
self.gui:SetPaintedManually(false)
self.gui:MakePopup()
end
return isMayor
end
function ENT:DoExitFromComputer() -- global hook
self.gui:SetPaintedManually(true)
self.gui:SetMouseInputEnabled(false)
self.gui:SetKeyboardInputEnabled(false)
end
function ENT:DrawTranslucent()
if !IsValid(self.gui) or LocalPlayer():GetPos():Distance(self:GetPos()) > nut.config.get("distanceDrawGui",500) then return end
local scale = 0.02
local x,y = self.gui:GetPos()
local pos = self:LocalToWorld(Vector(0.3,-18.85,24.6) + Vector(0, x * scale, y * scale))
local ang = self:LocalToWorldAngles(Angle(0,90,90))
self.dbg = {x,y,pos,ang}
cam.Start3D2D(pos,ang,scale)
self.gui:PaintManual()
cam.End3D2D()
end
function ENT:computer_use(comp, shopList) -- called from server (ENT:Use())
if !IsValid(self) or !IsValid(self.gui) or comp != self then return end
self.gui:setupLinks(shopList)
self.gui:DoLogin()
end
function PANEL:Init()
self:SetSize(1041,791)
self.wallpaper = self:Add("DImage")
self.wallpaper:SetSize(self:GetSize())
self.wallpaper:SetPos(0,0)
self.wallpaper.Paint = function(pnl,w,h)
draw.RoundedBox(0,0,0,w,h,Color(0,0,0,255))
end
self.desktop = self.wallpaper:Add("DPanel")
self.desktop:SetSize(self:GetSize())
self.desktop:SetPos(0,0)
self.desktop:SetVisible(false)
self.desktop.Paint = function() end
self.loginLayout = self.wallpaper:Add("DPanel")
self.loginLayout:SetSize(self:GetSize())
self.loginLayout:SetPos(0,0)
self.loginLayout.Paint = function() end
self.loginForm = self.loginLayout:Add("loginWindow")
self.loginForm:Center()
self.taskbar = self.wallpaper:Add("TaskBar")
self.taskbar:Dock(BOTTOM)
self.taskbar:SetMouseInputEnabled(true)
hook.Add("DoExitFromComputer",self,self.DoExitFromComputer)
end
function PANEL:DoLogin()
if hook.Run("DoLogin") then
self.loginLayout:SetVisible(false)
self.desktop:SetVisible(true)
self.taskbar:ComputerLocked(false)
end
end
function PANEL:DoExitFromComputer() -- global hook
self.desktop:SetVisible(false)
self.loginLayout:SetVisible(true)
self.taskbar:ComputerLocked(true)
gui.EnableScreenClicker(false)
end
derma.DefineControl("desktop", "Assembly all modules in this panel", PANEL, "DPanel")
function PANEL:Init()
self:SetTall(30)
self.tasks = self:Add("DPanel")
self.tasks:Dock(FILL)
self.tasks:DockMargin(0, 0, 2, 0)
self.tasks.Paint = function() end
self.exit = self:Add("DButton") -- not a have reactions on events self.Hovered и self.DoClick
self.exit:Dock(RIGHT)
self.exit:SetWide(50)
self.exit:SetText("")
self.exit.Paint = function(pnl, w, h) -- if this hovered then change color
if pnl.Hovered then
draw.RoundedBox(0, 0, 0, w, h, Color(100, 100, 100, 20))
end
draw.SimpleText("", "nutIconsSmallNew", w / 2, h / 2, pnl.Hovered and Color(255, 0, 0, 255) or Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
self.exit.DoClick = function()
hook.Run("DoExitFromComputer")
end
self.time = self:Add("DLabel")
self.time:Dock(RIGHT)
self.time:SetWide(150)
self.time:SetContentAlignment(5)
self.time:SetFont("Default")
self.time:SetTextColor(Color(255, 255, 255, 255))
self.time:SetText("")
end
function PANEL:Paint(w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(220, 220, 220, 10))
end
function PANEL:ComputerLocked(isLock)
self.tasks:SetVisible(!isLock)
end
derma.DefineControl("TaskBar", "Taskbar located in bottom destop!", PANEL, "DPanel")
Problem solved! I changed parent from DImage (wallpaper) to main panel (desktop), if you have same problem try to avoid setting DImage as parent
Sorry, you need to Log In to post a reply to this thread.