fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
d9a59ed
v2.1.5
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 ( 0 , 225 , 150 , 255 ), 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 ( 230 , 0 , 0 , 255 ), 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 ( 255 , 255 , 255 , 255 ), 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 ( 255 , 255 , 255 , 255 ), 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 ( 165 , 75 , 165 , 255 ), 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 ( 255 , 255 , 255 , 255 ), 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 ( 255 , 235 , 0 , 255 ) 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 323if SETTINGS : IsSlippiReplay () and melee . isInGame () then 324graphics . setLineStyle ( "smooth" ) 325graphics . setLineWidth ( 4 ) 326 327-- Draw outline 328graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 108 + 6 , 14 , 0 , 116 , 24 ) 329 330-- Draw L segment for button press 331graphics . line ( 108 + 14 + 88 , 20 , 108 + 14 + 88 , 20 + 12 ) 332 333-- Draw R segment for button press 334graphics . line ( 108 + 14 + 12 , 20 , 108 + 14 + 12 , 20 + 12 ) 335 336graphics . stencil ( function () 337-- Create a rounded rectangle mask 338graphics . rectangle ( "fill" , 108 + 14 , 20 , 100 , 12 , 6 , 6 ) 339end , "replace" , 1 ) 340graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 341-- Analog 342 343local analog =controller . analog and controller . analog . float or 0 344 345if not melee . isInGame () then 346local al , ar =memory . game . translateTriggers ( controller . analog . l , controller . analog . r ) 347al =math . min ( al , 1 ) 348ar =math . min ( ar , 1 ) 349analog =math . max ( al , ar ) 350end 351 352-- L Button 353if bit . band ( controller . buttons . pressed , BUTTONS . L ) == BUTTONS . L then 354graphics . rectangle ( "fill" , 108 + 14 , 20 , 12 , 12 ) 355analog =1 356end 357 358-- R Button 359if bit . band ( controller . buttons . pressed , BUTTONS . R ) == BUTTONS . R then 360graphics . rectangle ( "fill" , 108 + 14 + 12 + 76 , 20 , 12 , 12 ) 361analog =1 362end 363 364local w =76 * analog 365graphics . rectangle ( "fill" , 108 + 14 + 12 + 76 / 2 - ( w / 2 ), 20 , w , 12 ) 366graphics . setStencilTest () 367else 368local al , ar =memory . game . translateTriggers ( controller . analog . l , controller . analog . r ) 369al =math . min ( al , 1 ) 370ar =math . min ( ar , 1 ) 371 372graphics . setLineStyle ( "smooth" ) 373graphics . setLineWidth ( 4 ) 374 375-- Draw L 376 377-- Draw outline 378graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 24 + 6 , 14 , 0 , 116 , 24 ) 379-- Draw segment for button press 380graphics . line ( 24 + 14 + 88 , 20 , 24 + 14 + 88 , 20 + 12 ) 381 382graphics . stencil ( function () 383-- Create a rounded rectangle mask 384graphics . rectangle ( "fill" , 24 + 14 , 20 , 100 , 12 , 6 , 6 ) 385end , "replace" , 1 ) 386graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 387-- L Button 388if bit . band ( controller . buttons . pressed , BUTTONS . L ) == BUTTONS . L then 389graphics . rectangle ( "fill" , 24 + 14 + 88 , 20 , 12 , 12 ) 390al =1 391end 392 393-- L Analog 394graphics . rectangle ( "fill" , 24 + 14 , 20 , 88 * al , 12 ) 395graphics . setStencilTest () 396 397-- Draw R 398 399-- Draw outline 400graphics . easyDraw ( SETTINGS : IsHighContrast () and ANALOG_FILLED or ANALOG , 48 + 128 + 6 , 14 , 0 , 116 , 24 ) 401-- Draw segment for button press 402graphics . line ( 48 + 128 + 14 + 12 , 20 , 48 + 128 + 14 + 12 , 20 + 12 ) 403 404graphics . stencil ( function () 405-- Create a rounded rectangle mask 406graphics . rectangle ( "fill" , 48 + 128 + 14 , 20 , 100 , 12 , 6 , 6 ) 407end , "replace" , 1 ) 408graphics . setStencilTest ( "greater" , 0 ) -- Only draw within our rounded rectangle mask 409-- R Button 410if bit . band ( controller . buttons . pressed , BUTTONS . R ) == BUTTONS . R then 411graphics . rectangle ( "fill" , 48 + 128 + 14 , 20 , 12 , 12 ) 412ar =1 413end 414 415-- R Analog 416graphics . rectangle ( "fill" , 48 + 128 + 14 + 12 + ( 88 * ( 1 - ar )), 20 , 88 * ar , 12 ) 417graphics . setStencilTest () 418 419--[[if SETTINGS:IsDebugging() then 420local strl = ("L: %f"):format(al) 421local strr = ("R: %f"):format(ar) 422graphics.setFont(DEBUG_FONT) 423 424graphics.setColor(0, 0, 0, 255) 425graphics.textOutline(strl, 2, 340, 256 - 4 - 24) 426graphics.textOutline(strr, 2, 340, 256 - 4 - 12) 427 428graphics.setColor(255, 255, 255, 255) 429graphics.print(strl, 340, 256 - 4 - 24) 430graphics.print(strr, 340, 256 - 4 - 12) 431end]] 432end 433 434-- Draw buttons 435 436if SETTINGS : IsDPadEnabled () then 437graphics . easyDraw ( SETTINGS : IsHighContrast () and BUTTON_TEXTURES . DPAD . GATE_FILLED or BUTTON_TEXTURES . DPAD . GATE , 108 , 144 , 0 , 128 , 128 ) 438drawButtons ( DPAD , controller ) 439end 440 441drawButtons ( BUTTONS , controller ) 442end 443 444overlay . registerSkin ( "Default" , SKIN )