fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosBugfixes + Dark Mode skina8034e9

master
1.5 KiB68 linesraw
1local PANEL = class.create("CheckPanel", "Label")
2
3PANEL:ACCESSOR("Value", "m_iValue", 0)
4
5function PANEL:CheckPanel()
6	self:super() -- Initialize our baseclass
7	self:SetFocusable(true)
8	self:SetDrawPanel(true)
9	self:SetBGColor(color(215, 215, 215))
10
11	self:TextMargin(0, 4, 0, 0)
12	self:SetTextAlignmentX("center")
13	self:SetTextAlignmentY("top")
14	self:SetTextColor(color_darkgrey)
15	self:DockPadding(2, 18, 2, 2)
16
17	self.OPTIONS = {}
18end
19
20function PANEL:Skin()
21	self:super("Skin")
22	gui.skinHook("Init", "SubPanel", self)
23end
24
25function PANEL:AddOption(id, label, toggled)
26	local option = self:Add("CheckBox")
27	option:SetText(label)
28	option:Dock(DOCK_TOP)
29	option:SetToggled(toggled)
30	option.OnToggle = function()
31		if self.m_iValue ~= self:GetValue() then
32			self:OnValueChanged(self.m_iValue)
33		end
34	end
35
36	self.OPTIONS[id] = option
37	return option
38end
39
40function PANEL:PerformLayout()
41	self:SizeToChildren(false, true)
42end
43
44function PANEL:GetValue()
45	self.m_iValue = 0
46	for id, option in pairs(self.OPTIONS) do
47		if option:IsToggled() then
48			self.m_iValue = bit.bor(self.m_iValue, id)
49		end
50	end
51	return self.m_iValue
52end
53
54function PANEL:SetValue(value)
55	if self.m_iValue ~= value then
56		self.m_iValue = value
57		for id, option in pairs(self.OPTIONS) do
58			-- DON'T use SetToggled, since it would call OnValueChanged
59			-- We call OnValueChanged manually to reduce calls
60			option.m_bToggled = bit.band(value, id) == id
61		end
62		self:OnValueChanged(value) -- Manual call
63	end
64end
65
66function PANEL:OnValueChanged(value)
67	-- OVERRIDE
68end