fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
0747cf1
main
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/joystick-gate.png" ), 54GATE_FILLED =graphics . newImage ( "textures/buttons/joystick-gate-filled.png" ), 55MASK =graphics . newImage ( "textures/buttons/joystick-mask.png" ), 56STICK =graphics . newImage ( "textures/buttons/joystick.png" ), 57FILLED =graphics . newImage ( "textures/buttons/joystick-filled.png" ), 58} , 59CSTICK ={ 60GATE =graphics . newImage ( "textures/buttons/c-stick-gate.png" ), 61GATE_FILLED =graphics . newImage ( "textures/buttons/c-stick-gate-filled.png" ), 62MASK =graphics . newImage ( "textures/buttons/c-stick-mask.png" ), 63STICK =graphics . newImage ( "textures/buttons/c-stick.png" ), 64FILLED =graphics . newImage ( "textures/buttons/c-stick-filled.png" ), 65} , 66A ={ 67OUTLINE =graphics . newImage ( "textures/buttons/a-outline.png" ), 68FILLED =graphics . newImage ( "textures/buttons/a-filled.png" ), 69PRESSED =graphics . newImage ( "textures/buttons/a-pressed.png" ), 70COLOR =color_blue , 71POSITION ={ 72x =12 + 64 + 256 , 73y =48 74} 75} , 76B ={ 77OUTLINE =graphics . newImage ( "textures/buttons/b-outline.png" ), 78FILLED =graphics . newImage ( "textures/buttons/b-filled.png" ), 79PRESSED =graphics . newImage ( "textures/buttons/b-pressed.png" ), 80COLOR =color_pink , 81POSITION ={ 82x =16 + 256 , 83y =92 84} 85} , 86X ={ 87OUTLINE =graphics . newImage ( "textures/buttons/x-outline.png" ), 88FILLED =graphics . newImage ( "textures/buttons/x-filled.png" ), 89PRESSED =graphics . newImage ( "textures/buttons/x-pressed.png" ), 90COLOR =color_pink , 91POSITION ={ 92x =138 + 256 , 93y =32 94} 95} , 96Y ={ 97OUTLINE =graphics . newImage ( "textures/buttons/y-outline.png" ), 98FILLED =graphics . newImage ( "textures/buttons/y-filled.png" ), 99PRESSED =graphics . newImage ( "textures/buttons/y-pressed.png" ), 100COLOR =color_white , 101POSITION ={ 102x =60 + 256 , 103y =- 16 104} 105} , 106Z ={ 107OUTLINE =graphics . newImage ( "textures/buttons/z-outline.png" ), 108FILLED =graphics . newImage ( "textures/buttons/z-filled.png" ), 109PRESSED =graphics . newImage ( "textures/buttons/z-pressed.png" ), 110COLOR =color_blue , 111POSITION ={ 112x =128 + 256 , 113y =- 32 114} 115} , 116START ={ 117OUTLINE =graphics . newImage ( "textures/buttons/start-outline.png" ), 118FILLED =graphics . newImage ( "textures/buttons/start-filled.png" ), 119PRESSED =graphics . newImage ( "textures/buttons/start-pressed.png" ), 120COLOR =color ( color_blue ), 121POSITION ={ 122x =256 , 123y =26 124} 125} 126} 127 128local vertices ={ 129{ 1300 , 0 , 1310 , 0 , 1321 , 1 , 1 , 133} , 134{ 135128 , 0 , 1361 , 0 , 1371 , 1 , 1 138} , 139{ 140128 , 128 , 1411 , 1 , 1421 , 1 , 1 143} , 144{ 1450 , 128 , 1460 , 1 , 1471 , 1 , 1 148} , 149} 150 151local rotated_vertices ={} 152 153local function transformVertices ( vertices , x , y , angle , ox , oy ) 154if # vertices ~= # rotated_vertices then 155rotated_vertices ={} 156end 157 158local c =math . cos ( angle ) 159local s =math . sin ( angle ) 160 161for i =1 , # vertices do 162-- Create or use vertex cache 163rotated_vertices [ i ] =rotated_vertices [ i ] or {} 164 165-- Copy and rotate X and Y vertex points 166rotated_vertices [ i ][ 1 ] =x + ( vertices [ i ][ 1 ] - ox ) * c - ( vertices [ i ][ 2 ] - oy ) * s 167rotated_vertices [ i ][ 2 ] =y + ( vertices [ i ][ 1 ] - ox ) * s + ( vertices [ i ][ 2 ] - oy ) * c 168 169-- Copy other vertex settings 170rotated_vertices [ i ][ 3 ] =vertices [ i ][ 3 ] 171rotated_vertices [ i ][ 4 ] =vertices [ i ][ 4 ] 172rotated_vertices [ i ][ 5 ] =vertices [ i ][ 5 ] 173rotated_vertices [ i ][ 6 ] =vertices [ i ][ 6 ] 174end 175 176return rotated_vertices 177end 178 179local function drawButtons ( buttons , controller ) 180for button , flag in pairs ( buttons ) do 181local texture =BUTTON_TEXTURES [ button ] 182if texture then 183if button ~= "START" or ( button == "START" and SETTINGS : IsStartEnabled ()) then 184local pos =texture . POSITION 185graphics . setColor ( texture . COLOR ) 186if texture . PRESSED and bit . band ( controller . buttons . pressed , flag ) == flag then -- Check if the button is pressed 187graphics . easyDraw ( texture . PRESSED , pos . x , pos . y , 0 , 128 , 128 ) 188else 189local text =SETTINGS : IsHighContrast () and texture . FILLED or texture . OUTLINE 190if text then 191graphics . easyDraw ( text , pos . x , pos . y , 0 , 128 , 128 ) 192end 193end 194end 195end 196end 197end 198 199function SKIN : Paint ( controller ) 200local x , y =memory . game . translateJoyStick ( controller . joystick . x , controller . joystick . y ) 201 202--[[if SETTINGS:IsDebugging() then 203local strx = ("JOY_X: % f"):format(x) 204local stry = ("JOY_Y: % f"):format(y) 205local btts = ("BUTTONS: %X"):format(controller.buttons.pressed) 206graphics.setFont(DEBUG_FONT) 207 208graphics.setColor(0, 0, 0, 255) 209graphics.textOutline(btts, 2, 96, 256 - 4 - 36) 210graphics.textOutline(strx, 2, 96, 256 - 4 - 24) 211graphics.textOutline(stry, 2, 96, 256 - 4 - 12) 212 213graphics.setColor(255, 255, 255, 255) 214graphics.print(btts, 96, 256 - 8 - 36 ) 215graphics.print(strx, 96, 256 - 4 - 24) 216graphics.print(stry, 96, 256 - 4 - 12) 217end]] 218 219local vx , vy =x , 1 - y 220 221local angle =math . atan2 ( x , y ) 222local mag =math . sqrt ( x * x + y * y ) 223 224local far =mag * 12 -- Higher value = headed towards infinity 225local near =mag * 20 -- Higher value = more rotation into the horizon 226 227-- Make the rectangle look like its fading into the horizon 228 229-- Top left 230vertices [ 1 ][ 1 ] =far 231-- Top right 232vertices [ 2 ][ 1 ] =128 - far 233 234-- Bottom left 235vertices [ 1 ][ 2 ] =near 236-- Bottom right 237vertices [ 2 ][ 2 ] =near 238 239local rotated =transformVertices ( vertices , 64 + 22 + ( 44 * vx ), 64 + 8 + ( 44 * vy ), angle , 64 , 64 ) 240 241graphics . setColor ( 255 , 255 , 255 , 255 ) 242 243if SETTINGS : IsHighContrast () then 244graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE_FILLED , 22 , 52 , 0 , 128 , 128 ) 245else 246graphics . stencil ( function () 247perspective . on () 248perspective . quad ( BUTTON_TEXTURES . JOYSTICK . MASK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 249perspective . off () 250end , "replace" , 1 ) 251graphics . setStencilTest ( "equal" , 0 ) -- Mask out the gate behind the joystick 252graphics . easyDraw ( BUTTON_TEXTURES . JOYSTICK . GATE , 22 , 52 , 0 , 128 , 128 ) 253graphics . setStencilTest () 254end 255 256perspective . on () 257perspective . quad ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . JOYSTICK . FILLED or BUTTON_TEXTURES . JOYSTICK . STICK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 258perspective . off () 259 260-- Draw C-Stick 261 262local x , y =memory . game . translateCStick ( controller . cstick . x , controller . cstick . y ) 263 264--[[if SETTINGS:IsDebugging() then 265local strx = ("C_X: % f"):format(x) 266local stry = ("C_Y: % f"):format(y) 267graphics.setFont(DEBUG_FONT) 268 269graphics.setColor(0, 0, 0, 255) 270graphics.textOutline(strx, 2, 224, 256 - 4 - 24) 271graphics.textOutline(stry, 2, 224, 256 - 4 - 12) 272 273graphics.setColor(255, 255, 255, 255) 274graphics.print(strx, 224, 256 - 4 - 24) 275graphics.print(stry, 224, 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 * 12 284local near =mag * 20 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 + 48 + 128 + ( 32 * vx ), 64 + 18 + ( 32 * vy ), angle , 64 , 64 ) 299 300graphics . setColor ( color_blue ) 301 302if SETTINGS : IsHighContrast () then 303graphics . easyDraw ( BUTTON_TEXTURES . CSTICK . GATE_FILLED , 48 + 128 , 52 , 0 , 128 , 128 ) 304else 305graphics . stencil ( function () 306perspective . on () 307perspective . quad ( BUTTON_TEXTURES . CSTICK . 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 . CSTICK . GATE , 48 + 128 , 52 , 0 , 128 , 128 ) 312graphics . setStencilTest () 313end 314 315perspective . on () 316perspective . quad ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . CSTICK . FILLED or BUTTON_TEXTURES . CSTICK . STICK , rotated [ 1 ], rotated [ 2 ], rotated [ 3 ], rotated [ 4 ]) 317perspective . off () 318 319graphics . setColor ( 255 , 255 , 255 , 255 ) 320 321-- Draw L 322 323graphics . setColor ( color_pink ) 324if SETTINGS : IsSlippiReplay () and melee . isInGame () then 325graphics . setLineStyle ( "smooth" ) 326graphics . setLineWidth ( 4 ) 327 328-- Draw outline 329graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 108 + 6 , 14 , 0 , 116 , 24 ) 330 331-- Draw L segment for button press 332graphics . line ( 108 + 14 + 88 , 20 , 108 + 14 + 88 , 20 + 12 ) 333 334-- Draw R segment for button press 335graphics . line ( 108 + 14 + 12 , 20 , 108 + 14 + 12 , 20 + 12 ) 336 337graphics . stencil ( function () 338-- Create a rounded rectangle mask 339graphics . rectangle ( "fill" , 108 + 14 , 20 , 100 , 12 , 6 , 6 ) 340end , "replace" , 1 ) 341graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 342-- Analog 343 344local analog =controller . analog and controller . analog . float or 0 345 346if not melee . isInGame () then 347local al , ar =memory . game . translateTriggers ( controller . analog . l , controller . analog . r ) 348al =math . min ( al , 1 ) 349ar =math . min ( ar , 1 ) 350analog =math . max ( al , ar ) 351end 352 353-- L Button 354if bit . band ( controller . buttons . pressed , BUTTONS . L ) == BUTTONS . L then 355graphics . rectangle ( "fill" , 108 + 14 , 20 , 12 , 12 ) 356analog =1 357end 358 359-- R Button 360if bit . band ( controller . buttons . pressed , BUTTONS . R ) == BUTTONS . R then 361graphics . rectangle ( "fill" , 108 + 14 + 12 + 76 , 20 , 12 , 12 ) 362analog =1 363end 364 365local w =76 * analog 366graphics . rectangle ( "fill" , 108 + 14 + 12 + 76 / 2 - ( w / 2 ), 20 , w , 12 ) 367graphics . setStencilTest () 368else 369local al , ar =memory . game . translateTriggers ( controller . analog . l , controller . analog . r ) 370al =math . min ( al , 1 ) 371ar =math . min ( ar , 1 ) 372 373graphics . setLineStyle ( "smooth" ) 374graphics . setLineWidth ( 4 ) 375 376-- Draw L 377 378-- Draw outline 379graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 24 + 6 , 14 , 0 , 116 , 24 ) 380-- Draw segment for button press 381graphics . line ( 24 + 14 + 88 , 20 , 24 + 14 + 88 , 20 + 12 ) 382 383graphics . stencil ( function () 384-- Create a rounded rectangle mask 385graphics . rectangle ( "fill" , 24 + 14 , 20 , 100 , 12 , 6 , 6 ) 386end , "replace" , 1 ) 387graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 388-- L Button 389if bit . band ( controller . buttons . pressed , BUTTONS . L ) == BUTTONS . L then 390graphics . rectangle ( "fill" , 24 + 14 + 88 , 20 , 12 , 12 ) 391al =1 392end 393 394-- L Analog 395graphics . rectangle ( "fill" , 24 + 14 , 20 , 88 * al , 12 ) 396graphics . setStencilTest () 397 398-- Draw R 399 400graphics . setColor ( color_white ) 401-- Draw outline 402graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 48 + 128 + 6 , 14 , 0 , 116 , 24 ) 403-- Draw segment for button press 404graphics . line ( 48 + 128 + 14 + 12 , 20 , 48 + 128 + 14 + 12 , 20 + 12 ) 405 406graphics . stencil ( function () 407-- Create a rounded rectangle mask 408graphics . rectangle ( "fill" , 48 + 128 + 14 , 20 , 100 , 12 , 6 , 6 ) 409end , "replace" , 1 ) 410graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 411-- R Button 412if bit . band ( controller . buttons . pressed , BUTTONS . R ) == BUTTONS . R then 413graphics . rectangle ( "fill" , 48 + 128 + 14 , 20 , 12 , 12 ) 414ar =1 415end 416 417-- R Analog 418graphics . rectangle ( "fill" , 48 + 128 + 14 + 12 + ( 88 * ( 1 - ar )), 20 , 88 * ar , 12 ) 419graphics . setStencilTest () 420 421--[[if SETTINGS:IsDebugging() then 422local strl = ("L: %f"):format(al) 423local strr = ("R: %f"):format(ar) 424graphics.setFont(DEBUG_FONT) 425 426graphics.setColor(0, 0, 0, 255) 427graphics.textOutline(strl, 2, 340, 256 - 4 - 24) 428graphics.textOutline(strr, 2, 340, 256 - 4 - 12) 429 430graphics.setColor(255, 255, 255, 255) 431graphics.print(strl, 340, 256 - 4 - 24) 432graphics.print(strr, 340, 256 - 4 - 12) 433end]] 434end 435 436-- Draw buttons 437 438if SETTINGS : IsDPadEnabled () then 439graphics . easyDraw ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . DPAD . GATE_FILLED or BUTTON_TEXTURES . DPAD . GATE , 108 , 144 , 0 , 128 , 128 ) 440drawButtons ( DPAD , controller ) 441end 442 443drawButtons ( BUTTONS , controller ) 444end 445 446overlay . registerSkin ( "Default" , SKIN )