fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

blackops7799Started work on context menus Made APMDisplay its own seperate panel Renamed fonts Modified the script loading environement to just be a copy of _Ge093899

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