fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
27686d7
settings-overhaul
1local memory =require ( "memory" ) 2 3local PANEL =class . create ( "GCBind" , "Button" ) 4 5PANEL . BUTTONS ={ 6Z =0x0010 , 7R =0x0020 , 8L =0x0040 , 9A =0x0100 , 10B =0x0200 , 11X =0x0400 , 12Y =0x0800 , 13D_LEFT =0x0001 , 14D_RIGHT =0x0002 , 15D_DOWN =0x0004 , 16D_UP =0x0008 , 17START =0x1000 , 18UP =0x10000 , 19DOWN =0x20000 , 20LEFT =0x40000 , 21RIGHT =0x80000 , 22C_UP =0x100000 , 23C_DOWN =0x200000 , 24C_LEFT =0x400000 , 25C_RIGHT =0x800000 , 26} 27 28PANEL : ACCESSOR ( "ButtonCombo" , "m_bButtonCombo" , 0x0042 ) 29PANEL : ACCESSOR ( "Binding" , "m_bBinding" , false ) 30 31function PANEL : GCBind () 32self : super () -- Initialize our baseclass 33 34memory . hook ( "controller.*.buttons.pressed" , self , self . OnButtonPressed ) 35end 36 37function PANEL : Think () 38self : SetEnabled ( memory . isInGame ()) 39end 40 41function PANEL : UpdateButtonCombo ( buttons ) 42if buttons == 0x0 then buttons =self . BUTTONS . D_DOWN end 43self . m_bButtonCombo =buttons 44self : UpdateButtonLabel () 45end 46 47function PANEL : UpdateButtonLabel () 48local pressed ={} 49 50for name , mask in pairs ( self . BUTTONS ) do 51if bit . band ( self . m_bButtonCombo , mask ) == mask then 52table . insert ( pressed , name ) 53end 54end 55 56-- Show the current button combination 57self : SetText ( table . concat ( pressed , "+" )) 58end 59 60function PANEL : OnButtonPressed ( port , buttons ) 61-- Stop if not in binding mode 62if self . m_bBinding == false then return end 63 64-- Once they let go of all buttons, end the binding process 65if buttons == 0x0 then 66self . m_bBinding =false 67return 68end 69 70-- Only allow addition of buttons (Once the button is pressed it is locked in for this session) 71if buttons > self . m_bButtonCombo or buttons >= PANEL . BUTTONS . UP then 72self . m_bButtonCombo =buttons 73self : UpdateButtonLabel () 74end 75end 76 77function PANEL : Paint ( w , h ) 78self : super ( "Paint" , w , h ) 79end 80 81function PANEL : PaintOverlay ( w , h ) 82gui . skinHook ( "PaintOverlay" , "Panel" , self , w , h ) 83if self . m_bBinding then 84graphics . setLineStyle ( "rough" ) 85graphics . setLineWidth ( 3 ) 86end 87end 88 89function PANEL : OnClick () 90self : SetText ( "..." ) 91self . m_bBinding =true 92self . m_bButtonCombo =0x0 93end