Overriding Panel methods locally ?

Hello guys,
I have a question again!

How can I override methods of a panel locally, so that the method isnt overrided globally.

Im having a addon that uses Derma Panels. I wanna redesign them, but I dont want
that every Panel looks like mine.

So how can I override the Paint Method of the DButton Class for instance without setting it individually or globally.
**
I dont want to set it always to the specific button, because thats not the solution I can use in this case.**

I wanna redesign the combobox options that were used by a DMenu, so I need to override the DMenu method for
this case.

Please correct me if I’m wrong, but you want to have a global panel that can be called any time. You then want to call that panel but edit it local so it doesn’t over ride said global panel.

If this is the case you can just call the panel locally:


local hnaknaw = vgui.Create("MyCustomFrame")

and then remove all the elements you don’t want in it with :Remove()



local hnaknaw = vgui.Create("MyCustomFrame")
hnaknaw.Button1:Remove()
hnaknaw.ButtonClose:Remove()


So on so forth…

Then you just repopulate the menu with new buttons, info, panels, etc



local hnaknaw = vgui.Create("MyCustomFrame")
hnaknaw.Button1:Remove()

local hnaknaw.element1 = vgui.Create("DButton", hnaknaw)
hnaknaw.element1:SetSize(1,1)
hnaknaw.element1:SetPos(5,5)


So on so forth…

[editline]27th October 2017[/editline]

Going a step backward you could just call the panel locally and then repaint said button/combo box:



local hnaknaw = vgui.Create("MyCustomFrame")
local hnaknaw.DComboBox = vgui.Create("DComboBox", hnaknaw)
hnaknaw.DComboBox.Paint = function(self,w,h)
--painty stuff
end


I really hate Facepunch post editing, always screws with [“lua”] tags…

Um… that has actually nothing to do with my problem.
I said panel methods. I gonna explain it towards my example.

So… basically I wanna redesign the combobox choices / options.
The thing is the combobox option uses DMenu as options, so I need to redesign the dmenu. But If i override the default paint method of DMenu, all DMenus would look like that so I just want to override it locally.

DermaMenu returns the panel it creates so you could use that with

Panel:GetChildren, loop through the table, and override the child’s paint function.

[editline]28th October 2017[/editline]


function DComboBox:DoClick()
	if (self:IsMenuOpen()) then
		return self:CloseMenu()
	end
	
	self:OpenMenu()

	local menu = self.Menu:GetCanvas():GetChildren()

	for i, option in ipairs(menu) do
		function option:Paint(w, h)
			-- paint it here
		end
	end
end

Thank you! Works perfectly :slight_smile: