fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
cb3e486
v2.1.1
1local SKIN ={} 2 3local ANALOG =graphics . newImage ( "textures/buttons/analog-outline.png" ) 4local ANALOG_FILLED =graphics . newImage ( "textures/buttons/analog-filled.png" ) 5 6local BUTTON_TEXTURES ={ 7DPAD ={ 8GATE =graphics . newImage ( "textures/buttons/d-pad-gate.png" ), 9GATE_FILLED =graphics . newImage ( "textures/buttons/d-pad-gate-filled.png" ), 10POSITION ={ 11x =100 , 12y =128 , 13} , 14} , 15 16DPAD_LEFT ={ 17PRESSED =graphics . newImage ( "textures/buttons/d-pad-pressed-left.png" ), 18 19POSITION ={ 20x =108 , 21y =144 , 22} , 23} , 24 25DPAD_RIGHT ={ 26PRESSED =graphics . newImage ( "textures/buttons/d-pad-pressed-right.png" ), 27 28POSITION ={ 29x =108 , 30y =144 , 31} , 32} , 33 34DPAD_UP ={ 35PRESSED =graphics . newImage ( "textures/buttons/d-pad-pressed-up.png" ), 36 37POSITION ={ 38x =108 , 39y =144 , 40} , 41} , 42 43DPAD_DOWN ={ 44PRESSED =graphics . newImage ( "textures/buttons/d-pad-pressed-down.png" ), 45 46POSITION ={ 47x =108 , 48y =144 , 49} , 50} , 51 52JOYSTICK ={ 53GATE =graphics . newImage ( "textures/buttons/SS/SS_Gate.png" ), 54GATE_FILLED =graphics . newImage ( "textures/buttons/SS/SS_Gate.png" ), 55MASK =graphics . newImage ( "textures/buttons/joystick-mask.png" ), 56STICK =graphics . newImage ( "textures/buttons/SS/S_Stick.png" ), 57FILLED =graphics . newImage ( "textures/buttons/SS/S_Stick.png" ), 58} , 59CSTICK ={ 60GATE =graphics . newImage ( "textures/buttons/c-stick-gate.png" ), 61GATE_FILLED =graphics . newImage ( "textures/buttons/c-stick-gate-filled.png" ), 62STICK =graphics . newImage ( "textures/buttons/c-stick-solid.png" ), 63} , 64 65L ={ 66OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_L.png" ), 67PRESSED =graphics . newImage ( "textures/buttons/SS/SS_LP.png" ), 68 69POSITION ={ 70x =256 - 64 + 40 , 71y =64 + 10 72} 73} , 74 75R ={ 76OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_R.png" ), 77PRESSED =graphics . newImage ( "textures/buttons/SS/SS_RP.png" ), 78 79POSITION ={ 80x =256 + 128 + 40 , 81y =64 82} 83} , 84 85C_UP ={ 86OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CU.png" ), 87PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CUP.png" ), 88 89POSITION ={ 90x =256 + 40 , 91y =- 10 92} 93} , 94 95C_DOWN ={ 96OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CD.png" ), 97PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CDP.png" ), 98 99POSITION ={ 100x =256 - 64 - 15 , 101y =128 + 64 - 10 102} 103} , 104 105C_LEFT ={ 106OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CL.png" ), 107PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CLP.png" ), 108 109POSITION ={ 110x =256 - 64 + 40 , 111y =10 112} 113} , 114 115C_RIGHT ={ 116OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CR.png" ), 117PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CRP.png" ), 118 119POSITION ={ 120x =256 + 64 + 40 , 121y =- 10 122} 123} , 124 125A ={ 126OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_A.png" ), 127PRESSED =graphics . newImage ( "textures/buttons/SS/SS_AP.png" ), 128 129POSITION ={ 130x =256 - 64 + 35 , 131y =128 + 10 132} 133} , 134B ={ 135OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_B.png" ), 136PRESSED =graphics . newImage ( "textures/buttons/SS/SS_BP.png" ), 137 138POSITION ={ 139x =256 + 64 + 40 , 140y =64 - 10 141} 142} , 143X ={ 144OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_X.png" ), 145PRESSED =graphics . newImage ( "textures/buttons/SS/SS_XP.png" ), 146 147POSITION ={ 148x =256 + 128 + 40 , 149y =0 150} 151} , 152Y ={ 153OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_Y.png" ), 154PRESSED =graphics . newImage ( "textures/buttons/SS/SS_YP.png" ), 155 156POSITION ={ 157x =256 + 40 , 158y =64 - 10 159} 160} , 161Z ={ 162OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_Z.png" ), 163PRESSED =graphics . newImage ( "textures/buttons/SS/SS_ZP.png" ), 164 165POSITION ={ 166x =256 - 64 - 25 , 167y =128 - 10 168} 169} , 170START ={ 171OUTLINE =graphics . newImage ( "textures/buttons/start-outline.png" ), 172FILLED =graphics . newImage ( "textures/buttons/start-filled.png" ), 173PRESSED =graphics . newImage ( "textures/buttons/start-pressed.png" ), 174 175POSITION ={ 176x =256 , 177y =26 178} 179} 180} 181 182local vertices ={ 183{ 1840 , 0 , 1850 , 0 , 1861 , 1 , 1 , 187} , 188{ 189128 , 0 , 1901 , 0 , 1911 , 1 , 1 192} , 193{ 194128 , 128 , 1951 , 1 , 1961 , 1 , 1 197} , 198{ 1990 , 128 , 2000 , 1 , 2011 , 1 , 1 202} , 203} 204 205local rotated_vertices ={} 206 207local function transformVertices ( vertices , x , y , angle , ox , oy ) 208if # vertices ~= # rotated_vertices then 209rotated_vertices ={} 210end 211 212local c =math . cos ( angle ) 213local s =math . sin ( angle ) 214 215for i =1 , # vertices do 216-- Create or use vertex cache 217rotated_vertices [ i ] =rotated_vertices [ i ] or {} 218 219-- Copy and rotate X and Y vertex points 220rotated_vertices [ i ][ 1 ] =x + ( vertices [ i ][ 1 ] - ox ) * c - ( vertices [ i ][ 2 ] - oy ) * s 221rotated_vertices [ i ][ 2 ] =y + ( vertices [ i ][ 1 ] - ox ) * s + ( vertices [ i ][ 2 ] - oy ) * c 222 223-- Copy other vertex settings 224rotated_vertices [ i ][ 3 ] =vertices [ i ][ 3 ] 225rotated_vertices [ i ][ 4 ] =vertices [ i ][ 4 ] 226rotated_vertices [ i ][ 5 ] =vertices [ i ][ 5 ] 227rotated_vertices [ i ][ 6 ] =vertices [ i ][ 6 ] 228end 229 230return rotated_vertices 231end 232 233local function drawButtons ( buttons , controller ) 234for button , flag in pairs ( buttons ) do 235local texture =BUTTON_TEXTURES [ button ] 236if texture then 237if button ~= "START" or ( button == "START" and SETTINGS : IsStartEnabled ()) then 238 239local pos =texture . POSITION 240graphics . setColor ( texture . COLOR ) 241local analogr =( SETTINGS : IsSlippiReplay () and melee . isInGame () and controller . analog ) and controller . analog . float or controller . analog . r 242 243if texture . PRESSED and bit . band ( controller . buttons . pressed , flag ) == flag then -- Check if the button is pressed 244graphics . easyDraw ( texture . PRESSED , pos . x , pos . y , 0 , 88 , 88 ) 245elseif button == "R" and memory . game . translateTriggers ( analogr ) > 0 and memory . game . translateTriggers ( analogr ) < 0.5 then 246graphics . easyDraw ( BUTTON_TEXTURES . R . PRESSED , pos . x , pos . y , 0 , 88 , 88 ) 247else 248local text =SETTINGS : IsHighContrast () and texture . FILLED or texture . OUTLINE 249if text then 250graphics . easyDraw ( text , pos . x , pos . y , 0 , 88 , 88 ) 251end 252end 253end 254end 255end 256end 257 258function SKIN : Paint ( controller ) 259local x , y =memory . game . translateJoyStick ( controller . joystick . x , controller . joystick . y ) 260 261--[[if SETTINGS:IsDebugging() then 262local strx = ("JOY_X: % f"):format(x) 263local stry = ("JOY_Y: % f"):format(y) 264local btts = ("BUTTONS: %X"):format(controller.buttons.pressed) 265graphics.setFont(DEBUG_FONT) 266 267graphics.setColor(0, 0, 0, 255) 268graphics.textOutline(btts, 2, 96, 256 - 4 - 36) 269graphics.textOutline(strx, 2, 96, 256 - 4 - 24) 270graphics.textOutline(stry, 2, 96, 256 - 4 - 12) 271 272graphics.setColor(255, 255, 255, 255) 273graphics.print(btts, 96, 256 - 8 - 36 ) 274graphics.print(strx, 96, 256 - 4 - 24) 275graphics.print(stry, 96, 256 - 4 - 12) 276end]] 277 278local vx , vy =x , 1 - y 279 280local angle =math . atan2 ( x , y ) 281local mag =math . sqrt ( x * x + y * y ) 282 283local far =mag * 15 -- Higher value = headed towards infinity 284local near =mag * 20 -- Higher value = more rotation into the horizon 285 286-- Make the rectangle look like its fading into the horizon 287 288-- Top left 289vertices [ 1 ][ 1 ] =far 290-- Top right 291vertices [ 2 ][ 1 ] =128 - far 292 293-- Bottom left 294vertices [ 1 ][ 2 ] =near 295-- Bottom right 296vertices [ 2 ][ 2 ] =near 297 298local rotated =transformVertices ( vertices , 64 + 22 + ( 44 * vx ), 64 + 8 + ( 44 * vy ), angle , 64 , 64 ) 299 300graphics . setColor ( 255 , 255 , 255 , 255 ) 301 302if SETTINGS : IsHighContrast () then 303graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE_FILLED , 22 , 52 , 0 , 128 , 128 ) 304else 305graphics . stencil ( function () 306perspective . on () 307perspective . quad ( BUTTON_TEXTURES . JOYSTICK . MASK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 308perspective . off () 309end , "replace" , 1 ) 310graphics . setStencilTest ( "equal" , 0 ) -- Mask out the gate behind the joystick 311graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE , 22 , 52 , 0 , 128 , 128 ) 312graphics . setStencilTest () 313end 314 315perspective . on () 316perspective . quad ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . JOYSTICK . FILLED or BUTTON_TEXTURES . JOYSTICK . STICK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 317perspective . off () 318 319 320-- Draw buttons 321 322if SETTINGS : IsDPadEnabled () then 323graphics . easyDraw ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . DPAD . GATE_FILLED or BUTTON_TEXTURES . DPAD . GATE , 108 , 144 , 0 , 128 , 128 ) 324drawButtons ( DPAD , controller ) 325end 326 327drawButtons ( BUTTONS , controller ) 328end 329 330overlay . registerSkin ( "S-Stick" , SKIN )