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