fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
be5d99b
settings-overhaul
1local PANEL =class . create ( "HorizontalSelect" , "Label" ) 2 3PANEL : ACCESSOR ( "Selection" , "m_iSelection" , 1 ) 4 5function PANEL : HorizontalSelect () 6self : super () -- Initialize our baseclass 7 8self : SetDrawPanel ( true ) 9self : SetFocusable ( true ) 10self : DockPadding ( 0 , 0 , 0 , 0 ) 11self : SetBGColor ( color_blank ) 12self : SetBorderColor ( color_blank ) 13self : SetTextAlignment ( "center" ) 14 15self . m_tOptions ={} 16 17self . m_pButLeft =self : Add ( "Button" ) 18--self.m_pButLeft:SetDrawLabel(false) 19self . m_pButLeft : SetText ( "<" ) 20self . m_pButLeft : Dock ( DOCK_LEFT ) 21self . m_pButLeft : SetWidth ( 20 ) 22function self . m_pButLeft : OnClick () 23self : GetParent (): SelectLeft () 24end 25 26self . m_pButRight =self : Add ( "Button" ) 27--self.m_pButRight:SetDrawLabel(false) 28self . m_pButRight : SetText ( ">" ) 29self . m_pButRight : Dock ( DOCK_RIGHT ) 30self . m_pButRight : SetWidth ( 20 ) 31function self . m_pButRight : OnClick () 32self : GetParent (): SelectRight () 33end 34 35gui . skinHook ( "Init" , "HorizontalSelect" , self ) 36end 37 38-- Override base class SetEnabled with our own 39-- Toggle the left/right buttons at the same time 40function PANEL : SetEnabled ( b ) 41self . m_bEnabled =b 42self . m_pButLeft : SetEnabled ( b ) 43self . m_pButRight : SetEnabled ( b ) 44end 45 46function PANEL : Paint ( w , h ) 47self : super ( "Paint" , w , h ) -- Paint our label 48end 49 50function PANEL : PaintOverlay ( w , h ) 51gui . skinHook ( "PaintOverlay" , "FocusPanel" , self , w , h ) 52end 53 54function PANEL : AddOption ( str , default ) 55table . insert ( self . m_tOptions , str ) 56if default then 57self : SelectOption ( # self . m_tOptions ) 58end 59self : UpdateSelection () 60return # self . m_tOptions 61end 62 63function PANEL : SelectOption ( num , force ) 64if self . m_iSelection == num and not force then return end 65self . m_iSelection =num 66self : UpdateSelection () 67self : OnSelectOption ( self . m_iSelection ) 68end 69 70function PANEL : OnSelectOption ( num ) 71-- Override 72end 73 74function PANEL : OnMousePressed ( x , y , but ) 75end 76 77function PANEL : UpdateSelection () 78self : SetText ( self . m_tOptions [ self . m_iSelection ]) 79self . m_pButLeft : SetEnabled ( self . m_iSelection > 1 ) 80self . m_pButRight : SetEnabled ( self . m_iSelection < # self . m_tOptions ) 81end 82 83function PANEL : SelectLeft () 84self : SelectOption ( math . max ( 1 , self . m_iSelection - 1 )) 85end 86 87function PANEL : SelectRight () 88self : SelectOption ( math . min ( # self . m_tOptions , self . m_iSelection + 1 )) 89end 90 91function PANEL : OnMouseWheeled ( x , y ) 92if not self : HasFocus () or not self : IsEnabled () then return end 93if y > 0 then 94self : SelectLeft () 95else 96self : SelectRight () 97end 98return true 99end