fork/m-overlay

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

blackops7799Added nativefiledialog as a submodule Small fixes and stuff29736a3

GUI
2.7 KiB93 linesraw
1local memory = require("memory.watcher")
2
3function PANEL:Initialize()
4	self:super()
5
6	self.m_pCircle = graphics.newImage("textures/circle.png")
7
8	self.m_fFadeTime = 0.5
9	self.m_fFadeEnd = 0
10
11	self:SetSize(192, 256)
12end
13
14function PANEL:GetEntityUpdateTime(entity)
15	return self.m_tLastUpdate[entity] or 0
16end
17
18function PANEL:GetPlayer()
19	return memory.player[self:GetPort()]
20end
21
22function PANEL:Paint(w, h)
23	local t = timer.getTime()
24
25	for i=1,4 do
26		local player = melee.getPlayer(i)
27		if		(melee.isEntityActive(player.entity) and not melee.isEntityRespawning(player.entity) and melee.isEntityOffCamera(player.entity))
28			or	(melee.isEntityActive(player.partner) and not melee.isEntityRespawning(player.partner) and melee.isEntityOffCamera(player.partner)) then
29			self.m_fFadeEnd = t + self.m_fFadeTime
30		end
31	end
32
33	if self.m_fFadeEnd < t then return end
34
35	local fade = math.max(0, self.m_fFadeEnd - t) / self.m_fFadeTime
36
37	local minimapPosx = w
38	local minimapPosY = 0
39
40	local zone = memory.stage.blastzone
41	local stageW = zone.right - zone.left
42	local stageH = zone.top - zone.bottom
43
44	local camera = memory.camera.limit
45	local offset = memory.stage.offset
46
47	local cameraW = camera.right - camera.left
48	local cameraH = camera.top - camera.bottom
49
50	local minimapW = w
51	local minimapH = minimapW*(stageH/stageW)
52
53	local scale = minimapW/stageW
54
55	graphics.setColor(0, 0, 0, 100 * fade)
56	graphics.rectangle("fill", minimapPosx - minimapW, minimapPosY, minimapW, minimapH)
57	graphics.setColor(255, 255, 255, 200 * fade)
58	graphics.innerRectangle(minimapPosx - minimapW, minimapPosY, minimapW, minimapH)
59
60	local top_x = 1 - (camera.left - zone.left) / stageW
61	local top_y = 1 - (camera.top - zone.bottom) / stageH
62
63	graphics.setColor(255, 255, 255, 200 * fade)
64	graphics.rectangle("line", minimapPosx - (top_x*minimapW), minimapPosY + (top_y*minimapH), cameraW * scale, cameraH * scale)
65
66	for i=4,1,-1 do
67		local player = memory.player[i]
68
69		local color = melee.getPlayerEntityColor(player.entity)
70
71		if color then
72			graphics.setColor(color.r, color.g, color.b, 255*fade)
73
74			if melee.isEntityActive(player.entity) then
75				local pos = player.position
76
77				local x = 1 - (pos.x - offset.x - zone.left) / stageW
78				local y = 1 - (pos.y - offset.y - zone.bottom) / stageH
79
80				graphics.easyDraw(self.m_pCircle, minimapPosx - (x*minimapW), minimapPosY + (y*minimapH), 0, 12, 12, 0.5, 0.5)
81			end
82			if melee.isEntityActive(player.partner) then
83				local pos = player.partner_position
84				
85				local x = 1 - (pos.x - offset.x - zone.left) / stageW
86				local y = 1 - (pos.y - offset.y - zone.bottom) / stageH
87				graphics.easyDraw(self.m_pCircle, minimapPosx - (x*minimapW), minimapPosY + (y*minimapH), 0, 12, 12, 0.5, 0.5)
88			end
89		end
90	end
91end
92
93gui.register("MiniMap", PANEL, "Base")