fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
e093899
GUI
1local PANEL ={} 2 3local watcher =require ( "memory.watcher" ) 4local perspective =require ( "perspective" ) 5local state =require ( "smash.states" ) 6 7require ( "extensions.math" ) 8 9local BUTTONS ={ 10NONE =0x0000 , 11DPAD_LEFT =0x0001 , 12DPAD_RIGHT =0x0002 , 13DPAD_DOWN =0x0004 , 14DPAD_UP =0x0008 , 15Z =0x0010 , 16R =0x0020 , 17L =0x0040 , 18A =0x0100 , 19B =0x0200 , 20X =0x0400 , 21Y =0x0800 , 22START =0x1000 , 23} 24 25local timer =love . timer 26local graphics =love . graphics 27local newImage =graphics . newImage 28local newFont =graphics . newFont 29local format =string . format 30 31local DISCONNECTED =newImage ( "textures/buttons/disconnected.png" ) 32 33local BUTTON_TEXTURES ={ 34DPAD ={ 35BACKGROUND =newImage ( "textures/buttons/d-pad-gate.png" ), 36POSITION ={ 37x =100 , 38y =128 , 39} , 40} , 41 42DPAD_LEFT ={ 43PRESSED =newImage ( "textures/buttons/d-pad-pressed-left.png" ), 44POSITION ={ 45x =108 , 46y =144 , 47} , 48} , 49 50DPAD_RIGHT ={ 51PRESSED =newImage ( "textures/buttons/d-pad-pressed-right.png" ), 52POSITION ={ 53x =108 , 54y =144 , 55} , 56} , 57 58DPAD_UP ={ 59PRESSED =newImage ( "textures/buttons/d-pad-pressed-up.png" ), 60POSITION ={ 61x =108 , 62y =144 , 63} , 64} , 65 66DPAD_DOWN ={ 67PRESSED =newImage ( "textures/buttons/d-pad-pressed-down.png" ), 68POSITION ={ 69x =108 , 70y =144 , 71} , 72} , 73 74JOYSTICK ={ 75BACKGROUND =newImage ( "textures/buttons/joystick-gate.png" ), 76MASK =newImage ( "textures/buttons/joystick-mask.png" ), 77STICK =newImage ( "textures/buttons/joystick-outline.png" ), 78} , 79CSTICK ={ 80BACKGROUND =newImage ( "textures/buttons/c-stick-gate.png" ), 81STICK =newImage ( "textures/buttons/c-stick.png" ), 82} , 83A ={ 84OUTLINE =newImage ( "textures/buttons/a-outline.png" ), 85PRESSED =newImage ( "textures/buttons/a-pressed.png" ), 86COLOR =color ( 0 , 225 , 150 , 255 ), 87POSITION ={ 88x =12 + 64 + 256 , 89y =64 90} 91} , 92B ={ 93OUTLINE =newImage ( "textures/buttons/b-outline.png" ), 94PRESSED =newImage ( "textures/buttons/b-pressed.png" ), 95COLOR =color ( 230 , 0 , 0 , 255 ), 96POSITION ={ 97x =16 + 256 , 98y =108 99} 100} , 101X ={ 102OUTLINE =newImage ( "textures/buttons/x-outline.png" ), 103PRESSED =newImage ( "textures/buttons/x-pressed.png" ), 104COLOR =color ( 255 , 255 , 255 , 255 ), 105POSITION ={ 106x =138 + 256 , 107y =48 108} 109} , 110Y ={ 111OUTLINE =newImage ( "textures/buttons/y-outline.png" ), 112PRESSED =newImage ( "textures/buttons/y-pressed.png" ), 113COLOR =color ( 255 , 255 , 255 , 255 ), 114POSITION ={ 115x =60 + 256 , 116y =0 117} 118} , 119Z ={ 120OUTLINE =newImage ( "textures/buttons/z-outline.png" ), 121PRESSED =newImage ( "textures/buttons/z-pressed.png" ), 122COLOR =color ( 165 , 75 , 165 , 255 ), 123POSITION ={ 124x =128 + 256 , 125y =- 16 126} 127} , 128START ={ 129OUTLINE =newImage ( "textures/buttons/start-outline.png" ), 130PRESSED =newImage ( "textures/buttons/start-pressed.png" ), 131COLOR =color ( 255 , 255 , 255 , 255 ), 132POSITION ={ 133x =256 , 134y =42 135} 136} 137} 138 139local MAX_PORTS =4 140 141function PANEL : Initialize () 142self : super () 143 144self : SetSize ( 512 , 256 ) 145 146self : DockPadding ( 0 , 0 , 0 , 0 ) 147self : DockMargin ( 0 , 0 , 0 , 0 ) 148 149self . m_pFont =newFont ( "fonts/ultimate-bold.otf" , 16 ) 150 151self . m_bEnabled =false 152self . m_iPort =- 1 153self . m_iActions =0 154 155watcher . hook ( "match.finished" , self , self . ResetAPM ) 156watcher . hook ( "player.*.*.action_state" , self , self . UpdateAPM ) 157end 158 159function PANEL : SetPort ( port ) 160self . m_iPort =port 161end 162 163function PANEL : GetPort () 164return self . m_iPort 165end 166 167function PANEL : ResetAPM ( finished ) 168if finished == 0 then 169self . m_iActions =0 170self . m_bEnabled =true 171else 172self . m_bEnabled =false 173end 174end 175 176function PANEL : UpdateAPM ( port , entityType , state_id ) 177local player =watcher . player [ port ][ entityType ] 178 179if player and port == self : GetPort () and ( state . isAction ( state_id ) or state . isCharacterAction ( player . character , state_id )) then 180--print(string.format("[%04X] %s", state_id, state.translateChar(player.character, state_id))) 181if not self . m_bEnabled then return end 182self . m_iActions =self . m_iActions + 1 183end 184end 185 186 187function PANEL : Paint ( w , h ) 188graphics . setColor ( 255 , 255 , 255 , 255 ) 189 190local time =watcher . match . frame / 60 191 192graphics . setFont ( self . m_pFont ) 193graphics . ( format ( "APM: %d" , self . m_iActions / time * 60 ), 8 , h - 24 ) 194end 195 196gui . register ( "APMDisplay" , PANEL , "Base" )