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