fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
e9088ad
settings-overhaul
1local graphics =love . graphics 2local newImage =graphics . newImage 3local newFont =graphics . newFont 4local timer =love . timer 5 6local log =require ( "log" ) 7 8local notification ={ 9messages ={} , 10font =newFont ( "fonts/melee-bold.otf" , 12 ), 11padding =8 , 12} 13 14local dummy =function ( height , fade ) end 15 16function notification . add ( height , length , fade , draw ) 17height =height or 16 18length =length or 3 19fade =fade or 0.75 20 21local now =timer . getTime () 22 23table . insert ( notification . messages , { 24time =now , 25length =length , 26fade =fade , 27finish =now + length + fade , 28 29height =height , 30 31draw =draw or dummy , 32 33lerp ={} , 34} ) 35end 36 37function notification . update ( x , y ) 38local now =timer . getTime () 39 40local prevh =0 41 42for k , message in pairs ( notification . messages ) do 43if ( message . finish >= now ) then 44x =x * 0.5 + ( message . lerp . x or x ) * 0.5 45y =y * 0.5 + ( message . lerp . y or y ) * 0.5 46y =y + prevh / 2 + notification . padding / 2 47 48message . lerp . x =x 49message . lerp . y =y 50 51prevh =message . height 52end 53end 54 55for k , message in pairs ( notification . messages ) do 56if ( message . finish >= now ) then 57return 58end 59end 60 61notification . messages ={} 62end 63 64function notification . draw () 65local now =timer . getTime () 66for k , message in pairs ( notification . messages ) do 67 68local fade =1 69 70if now >= message . time + message . length then 71fade =1 - (( now - message . time - message . length ) / message . fade ) 72end 73 74local x , y =message . lerp . x , message . lerp . y 75 76if x and y then 77graphics . push ( "transform" ) 78graphics . translate ( x , y ) 79graphics . setFont ( notification . font ) 80graphics . setColor ( 255 , 255 , 255 , 255 * fade ) 81local succ , ret =xpcall ( message . draw , debug . traceback , message . height , fade ) 82if not succ then 83log . error ( "notification error: %s" , ret ) 84end 85graphics . pop () 86end 87end 88end 89 90function notification . error ( text ) 91love . window . requestAttention () 92notification . add ( 14 , 10 , 0.75 , function ( height , fade ) 93graphics . setColor ( 0 , 0 , 0 , 255 * fade ) 94graphics . textOutline ( text , 1 , 1 , 1 ) 95graphics . setColor ( 241 , 73 , 82 , 255 * fade ) 96graphics . ( text , 0 , 0 ) 97end ) 98end 99 100function notification . warning ( text ) 101notification . add ( 14 , 5 , 0.75 , function ( height , fade ) 102graphics . setColor ( 0 , 0 , 0 , 255 * fade ) 103graphics . textOutline ( text , 1 , 1 , 1 ) 104graphics . setColor ( 255 , 242 , 0 , 255 * fade ) 105graphics . ( text , 0 , 0 ) 106end ) 107end 108 109function notification . info ( text ) 110notification . add ( 14 , 5 , 0.75 , function ( height , fade ) 111graphics . setColor ( 0 , 0 , 0 , 255 * fade ) 112graphics . textOutline ( text , 1 , 1 , 1 ) 113graphics . setColor ( 79 , 202 , 255 , 255 * fade ) 114graphics . ( text , 0 , 0 ) 115end ) 116end 117 118function notification . coloredMessage ( ... ) 119local args ={ ... } 120notification . add ( 14 , 5 , 0.75 , function ( height , fade ) 121graphics . setColor ( 0 , 0 , 0 , 255 * fade ) 122graphics . textOutline ( args , 1 , 1 , 1 ) 123graphics . setColor ( 255 , 255 , 255 , 255 * fade ) 124graphics . ( args , 0 , 0 ) 125end ) 126end 127 128return notification