fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
4032e64
master
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 ={ 7JOYSTICK ={ 8GATE =graphics . newImage ( "textures/buttons/SS/SS_Gate.png" ), 9GATE_FILLED =graphics . newImage ( "textures/buttons/SS/SS_Gate.png" ), 10MASK =graphics . newImage ( "textures/buttons/joystick-mask.png" ), 11STICK =graphics . newImage ( "textures/buttons/SS/S_Stick.png" ), 12FILLED =graphics . newImage ( "textures/buttons/SS/S_Stick.png" ), 13} , 14CSTICK ={ 15GATE =graphics . newImage ( "textures/buttons/c-stick-gate.png" ), 16GATE_FILLED =graphics . newImage ( "textures/buttons/c-stick-gate-filled.png" ), 17STICK =graphics . newImage ( "textures/buttons/c-stick-solid.png" ), 18} , 19 20L ={ 21OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_L.png" ), 22PRESSED =graphics . newImage ( "textures/buttons/SS/SS_LP.png" ), 23 24POSITION ={ 25x =256 - 64 + 40 , 26y =64 + 10 27} 28} , 29 30R ={ 31OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_R.png" ), 32PRESSED =graphics . newImage ( "textures/buttons/SS/SS_RP.png" ), 33 34POSITION ={ 35x =256 + 128 + 40 , 36y =64 37} 38} , 39 40C_UP ={ 41OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CU.png" ), 42PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CUP.png" ), 43 44POSITION ={ 45x =256 + 40 , 46y =- 10 47} 48} , 49 50C_DOWN ={ 51OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CD.png" ), 52PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CDP.png" ), 53 54POSITION ={ 55x =256 - 64 - 15 , 56y =128 + 64 - 10 57} 58} , 59 60C_LEFT ={ 61OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CL.png" ), 62PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CLP.png" ), 63 64POSITION ={ 65x =256 - 64 + 40 , 66y =10 67} 68} , 69 70C_RIGHT ={ 71OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_CR.png" ), 72PRESSED =graphics . newImage ( "textures/buttons/SS/SS_CRP.png" ), 73 74POSITION ={ 75x =256 + 64 + 40 , 76y =- 10 77} 78} , 79 80A ={ 81OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_A.png" ), 82PRESSED =graphics . newImage ( "textures/buttons/SS/SS_AP.png" ), 83 84POSITION ={ 85x =256 - 64 + 35 , 86y =128 + 10 87} 88} , 89B ={ 90OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_B.png" ), 91PRESSED =graphics . newImage ( "textures/buttons/SS/SS_BP.png" ), 92 93POSITION ={ 94x =256 + 64 + 40 , 95y =64 - 10 96} 97} , 98X ={ 99OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_X.png" ), 100PRESSED =graphics . newImage ( "textures/buttons/SS/SS_XP.png" ), 101 102POSITION ={ 103x =256 + 128 + 40 , 104y =0 105} 106} , 107Y ={ 108OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_Y.png" ), 109PRESSED =graphics . newImage ( "textures/buttons/SS/SS_YP.png" ), 110 111POSITION ={ 112x =256 + 40 , 113y =64 - 10 114} 115} , 116Z ={ 117OUTLINE =graphics . newImage ( "textures/buttons/SS/SS_Z.png" ), 118PRESSED =graphics . newImage ( "textures/buttons/SS/SS_ZP.png" ), 119 120POSITION ={ 121x =256 - 64 - 25 , 122y =128 - 10 123} 124} 125} 126 127local vertices ={ 128{ 1290 , 0 , 1300 , 0 , 1311 , 1 , 1 , 132} , 133{ 134128 , 0 , 1351 , 0 , 1361 , 1 , 1 137} , 138{ 139128 , 128 , 1401 , 1 , 1411 , 1 , 1 142} , 143{ 1440 , 128 , 1450 , 1 , 1461 , 1 , 1 147} , 148} 149 150local rotated_vertices ={} 151 152local function transformVertices ( vertices , x , y , angle , ox , oy ) 153if # vertices ~= # rotated_vertices then 154rotated_vertices ={} 155end 156 157local c =math . cos ( angle ) 158local s =math . sin ( angle ) 159 160for i =1 , # vertices do 161-- Create or use vertex cache 162rotated_vertices [ i ] =rotated_vertices [ i ] or {} 163 164-- Copy and rotate X and Y vertex points 165rotated_vertices [ i ][ 1 ] =x + ( vertices [ i ][ 1 ] - ox ) * c - ( vertices [ i ][ 2 ] - oy ) * s 166rotated_vertices [ i ][ 2 ] =y + ( vertices [ i ][ 1 ] - ox ) * s + ( vertices [ i ][ 2 ] - oy ) * c 167 168-- Copy other vertex settings 169rotated_vertices [ i ][ 3 ] =vertices [ i ][ 3 ] 170rotated_vertices [ i ][ 4 ] =vertices [ i ][ 4 ] 171rotated_vertices [ i ][ 5 ] =vertices [ i ][ 5 ] 172rotated_vertices [ i ][ 6 ] =vertices [ i ][ 6 ] 173end 174 175return rotated_vertices 176end 177 178local function drawButtons ( buttons , controller ) 179for button , flag in pairs ( buttons ) do 180local texture =BUTTON_TEXTURES [ button ] 181if texture then 182local pos =texture . POSITION 183graphics . setColor ( texture . COLOR ) 184local analogr =( SETTINGS : IsSlippiReplay () and melee . isInGame () and controller . analog ) and controller . analog . float or controller . analog 185local tl , tr =memory . game . translateTriggers ( 0 , analogr and analogr . r or 0 ) 186 187if texture . PRESSED and bit . band ( controller . buttons . pressed , flag ) == flag then -- Check if the button is pressed 188graphics . easyDraw ( texture . PRESSED , pos . x , pos . y , 0 , 88 , 88 ) 189elseif button == "R" and tr > 0 and tr < 0.5 then 190graphics . easyDraw ( BUTTON_TEXTURES . R . PRESSED , pos . x , pos . y , 0 , 88 , 88 ) 191else 192local text =SETTINGS : IsHighContrast () and texture . FILLED or texture . OUTLINE 193if text then 194graphics . easyDraw ( text , pos . x , pos . y , 0 , 88 , 88 ) 195end 196end 197end 198end 199end 200 201function SKIN : Paint ( controller ) 202local x , y =memory . game . translateJoyStick ( controller . joystick . x , controller . joystick . y ) 203 204--[[if SETTINGS:IsDebugging() then 205local strx = ("JOY_X: % f"):format(x) 206local stry = ("JOY_Y: % f"):format(y) 207local btts = ("BUTTONS: %X"):format(controller.buttons.pressed) 208graphics.setFont(DEBUG_FONT) 209 210graphics.setColor(0, 0, 0, 255) 211graphics.textOutline(btts, 2, 96, 256 - 4 - 36) 212graphics.textOutline(strx, 2, 96, 256 - 4 - 24) 213graphics.textOutline(stry, 2, 96, 256 - 4 - 12) 214 215graphics.setColor(255, 255, 255, 255) 216graphics.print(btts, 96, 256 - 8 - 36 ) 217graphics.print(strx, 96, 256 - 4 - 24) 218graphics.print(stry, 96, 256 - 4 - 12) 219end]] 220 221local vx , vy =x , 1 - y 222 223local angle =math . atan2 ( x , y ) 224local mag =math . sqrt ( x * x + y * y ) 225 226local far =mag * 15 -- Higher value = headed towards infinity 227local near =mag * 20 -- Higher value = more rotation into the horizon 228 229-- Make the rectangle look like its fading into the horizon 230 231-- Top left 232vertices [ 1 ][ 1 ] =far 233-- Top right 234vertices [ 2 ][ 1 ] =128 - far 235 236-- Bottom left 237vertices [ 1 ][ 2 ] =near 238-- Bottom right 239vertices [ 2 ][ 2 ] =near 240 241local rotated =transformVertices ( vertices , 64 + 22 + ( 44 * vx ), 64 + 8 + ( 44 * vy ), angle , 64 , 64 ) 242 243graphics . setColor ( 255 , 255 , 255 , 255 ) 244 245if SETTINGS : IsHighContrast () then 246graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE_FILLED , 22 , 52 , 0 , 128 , 128 ) 247else 248graphics . stencil ( function () 249perspective . on () 250perspective . quad ( BUTTON_TEXTURES . JOYSTICK . MASK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 251perspective . off () 252end , "replace" , 1 ) 253graphics . setStencilTest ( "equal" , 0 ) -- Mask out the gate behind the joystick 254graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE , 22 , 52 , 0 , 128 , 128 ) 255graphics . setStencilTest () 256end 257 258perspective . on () 259perspective . quad ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . JOYSTICK . FILLED or BUTTON_TEXTURES . JOYSTICK . STICK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 260perspective . off () 261 262-- Draw buttons 263drawButtons ( BUTTONS , controller ) 264end 265 266overlay . registerSkin ( "S-Stick" , SKIN )