fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a3968ab
v2.1.2
1local memory =require ( "memory" ) 2 3local PANEL =class . create ( "GCBinder" , "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" , 0x0 ) 29PANEL : ACCESSOR ( "BindingCombo" , "m_bBindingCombo" , 0x0 ) 30PANEL : ACCESSOR ( "Binding" , "m_bBinding" , false ) 31 32function PANEL : GCBinder () 33self : super () -- Initialize our baseclass 34memory . hook ( "controller.*.buttons.pressed" , self , self . OnButtonPressed ) 35self : UpdateButtonLabel () 36end 37 38function PANEL : Think () 39self : SetEnabled ( memory . isInGame ()) 40end 41 42function PANEL : SetButtonCombo ( buttons ) 43if buttons then 44self . m_bButtonCombo =buttons 45self : UpdateButtonLabel () 46end 47end 48 49function PANEL : UpdateButtonLabel () 50local pressed ={} 51 52for name , mask in pairs ( self . BUTTONS ) do 53if bit . band ( self . m_bBinding and self . m_bBindingCombo or self . m_bButtonCombo , mask ) == mask then 54table . insert ( pressed , name ) 55end 56end 57 58-- Show the current button combination 59self : SetText ( table . concat ( pressed , "+" )) 60end 61 62function PANEL : OnButtonPressed ( port , buttons ) 63-- Stop if not in binding mode 64if self . m_bBinding == false then return end 65 66-- Once they let go of all buttons, end the binding process 67if buttons == 0x0 then 68self . m_bBinding =false 69self . m_bButtonCombo =self . m_bBindingCombo 70self : UpdateButtonLabel () 71return 72end 73 74-- Only allow addition of buttons (Once the button is pressed it is locked in for this session) 75if buttons > self . m_bBindingCombo or buttons >= PANEL . BUTTONS . UP then 76self . m_bBindingCombo =buttons 77self : UpdateButtonLabel () 78end 79end 80 81function PANEL : OnKeyPressed ( key , isrepeat ) 82if self . m_bBinding and key == "backspace" or key == "escape" then 83self . m_bBinding =false 84self : UpdateButtonLabel () 85return true 86end 87end 88 89function PANEL : Paint ( w , h ) 90self : super ( "Paint" , w , h ) 91end 92 93function PANEL : PaintOverlay ( w , h ) 94gui . skinHook ( "PaintOverlay" , "Panel" , self , w , h ) 95if self . m_bBinding then 96graphics . setColor ( color_blue ) 97graphics . setLineStyle ( "rough" ) 98graphics . setLineWidth ( 3 ) 99graphics . innerRectangle ( 0 , 0 , w , h ) 100end 101end 102 103function PANEL : OnClick () 104self : SetText ( "..." ) 105self . m_bBinding =true 106self . m_bBindingCombo =0x0 107end