fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
e093899
GUI
1local memory =require ( "memory.watcher" ) 2 3function PANEL : Initialize () 4self : super () 5 6self : SetSize ( 200 , 200 ) 7 8self . m_pFontPercent =graphics . newFont ( "fonts/ultimate-bold.otf" , 64 ) 9self . m_pFontDecimal =graphics . newFont ( "fonts/ultimate-bold.otf" , 24 ) 10 11self . m_tPercents ={ entity =0 , partner =0 } 12self . m_tDecimals ={ entity =0 , partner =0 } 13self . m_tLastUpdate ={} 14 15memory . hook ( "player.*.*.percent" , self , self . UpdatePercent ) 16 17self : MakeAccessor ( "Port" , "m_iPort" ) 18end 19 20function PANEL : UpdatePercent ( port , entity , percent ) 21if self : GetPort () == port then 22self . m_tPercents [ entity ] =math . floor ( percent ) 23self . m_tDecimals [ entity ] =math . floor ( percent % 1 * 10 ) 24if self . m_tPercents [ entity ] < percent then 25self . m_tLastUpdate [ entity ] =timer . getTime () 26end 27end 28end 29 30function PANEL : GetEntityUpdateTime ( entity ) 31return self . m_tLastUpdate [ entity ] or 0 32end 33 34function PANEL : GetPlayer () 35return memory . player [ self : GetPort ()] 36end 37 38function PANEL : GetEntity () 39return melee . getPlayerEntity ( self : GetPort ()) 40end 41 42do 43local lerp =math . lerp 44 45function PANEL : GetPercentColor ( percent ) 46if percent <= 10 then 47return color_white 48elseif percent <= 35 then 49local fade =( percent - 10 ) / 25 50return hsl ( lerp ( 60 , 50 , fade ), 1 , lerp ( 1 , 0.5 , fade )) 51elseif percent <= 100 then 52local fade =( percent - 35 ) / 65 53return hsl ( lerp ( 50 , 0 , fade ), 1 , 0.5 ) 54elseif percent <= 200 then 55local fade =( percent - 100 ) / 100 56return hsl ( lerp ( 360 , 344 , fade ), 1 , lerp ( 0.5 , 0.33 , fade )) 57end 58local fade =( percent - 200 ) / 799 59return hsl ( 344 , 1 , lerp ( 0.33 , 0.24 , fade )) 60end 61end 62 63function PANEL : Paint ( w , h ) 64local t =timer . getTime () 65 66local player =self : GetPlayer () 67 68if not melee . isEntityAlive ( melee . getEntity ( player )) then return end 69 70local active =melee . getActiveEntityName ( player ) 71 72local percent =self . m_tPercents [ active ] 73local decimal =string . format ( ".%i%%" , self . m_tDecimals [ active ]) 74 75local percentW =self . m_pFontPercent : getWidth ( percent ) 76local percentH =self . m_pFontPercent : getHeight () / 2 77 78local decimalW =self . m_pFontDecimal : getWidth ( decimal ) 79local decimalH =self . m_pFontDecimal : getWidth ( decimal ) / 2 80 81local x =w - decimalW - percentW + 6 82local y =h / 2 - percentH / 2 83 84local sx , sy =0 , 0 85if self : GetEntityUpdateTime ( active ) + 0.25 >= t then 86sx =math . random ( - 8 , 8 ) 87sy =math . random ( - 8 , 8 ) 88end 89 90local pX , pY =x + sx , y + sy 91 92graphics . setFont ( self . m_pFontPercent ) 93graphics . setColor ( 0 , 0 , 0 , 255 ) 94graphics . textOutline ( percent , 4 , pX + 2 , pY + 2 , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 95graphics . setColor ( self : GetPercentColor ( percent )) 96graphics . ( percent , pX , pY , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 97 98local dX , dY =sx + w - decimalW , h / 2 + sy 99 100graphics . setFont ( self . m_pFontDecimal ) 101graphics . setColor ( 0 , 0 , 0 , 255 ) 102graphics . textOutline ( decimal , 2 , dX + 1 , dY + 1 , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 103graphics . setColor ( self : GetPercentColor ( percent )) 104graphics . ( decimal , dX , dY , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 105 106if player . character == CHARACTER . CLIMBERS and melee . isEntityAlive ( player . partner ) then 107percent =player . partner . percent 108local display =( "%.1f%%" ): format ( percent ) 109 110local sx , sy =0 , 0 111if self : GetEntityUpdateTime ( "partner" ) + 0.25 >= t then 112sx =math . random ( - 8 , 8 ) 113sy =math . random ( - 8 , 8 ) 114end 115 116graphics . setColor ( color_black ) 117graphics . textOutlinef ( display , 2 , sx , y + percentH + sy , w , "right" , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 118graphics . setColor ( self : GetPercentColor ( percent )) 119graphics . printf ( display , sx , y + percentH + sy , w , "right" , 0 , 1 , 1 , 0 , 0 , - 0.15 , 0 ) 120 121--graphics.setColor(color_white) 122--overlay.drawStockIcon(character, overlay.nana_skins[player.skin] or 0, percentH + 64, 112) 123end 124end 125 126gui . register ( "PlayerPercent" , PANEL , "Base" )