fork/m-overlay

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

BkacjiosMake classes a bit easier to understand and setup. Moved GUI related textures to their own folder.7180fb3

v2.1.6
1.2 KiB59 linesraw
1local PANEL = class.create("DropdownSelect", "Panel")
2
3function PANEL:DropdownSelect()
4	self:super() -- Initialize our baseclass
5end
6
7local PANEL = class.create("Dropdown", "Label")
8
9function PANEL:Dropdown()
10	self:super() -- Initialize our baseclass
11
12	self.m_tOptions = {}
13	self.m_iSelection = 1
14	self.m_bFocusable = true
15end
16
17--[[function PANEL:Paint(w, h)
18	gui.skinHook("Paint", "Dropdown", self, w, h)
19end]]
20
21function PANEL:AddOption(str, default)
22	table.insert(self.m_tOptions, str)
23	if default then
24		self.m_iSelection = #self.m_tOptions
25		self:UpdateSelection()
26	end
27end
28
29function PANEL:SelectOption(num)
30	self.m_iSelection = num
31	self:UpdateSelection()
32end
33
34function PANEL:OnSelectOption(num)
35	-- Override
36end
37
38function PANEL:OpenDropdown()
39
40end
41
42function PANEL:OnMousePressed(x, y, but)
43	if but ~= 1 then return end
44	self:OpenDropdown()
45end
46
47function PANEL:UpdateSelection()
48	self:SetText(self.m_tOptions[self.m_iSelection])
49end
50
51function PANEL:OnMouseWheeled(x, y)
52	if y > 0 then
53		self.m_iSelection = math.max(1, self.m_iSelection - 1)
54	else
55		self.m_iSelection = math.min(#self.m_tOptions, self.m_iSelection + 1)
56	end
57	self:OnSelectOption(self.m_iSelection)
58	self:UpdateSelection()
59end