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
4.1 KiB196 linesraw
1local PANEL = {}
2
3local watcher = require("memory.watcher")
4local perspective = require("perspective")
5local state = require("smash.states")
6
7require("extensions.math")
8
9local BUTTONS = {
10	NONE		= 0x0000,
11	DPAD_LEFT	= 0x0001,
12	DPAD_RIGHT	= 0x0002,
13	DPAD_DOWN	= 0x0004,
14	DPAD_UP		= 0x0008,
15	Z			= 0x0010,
16	R			= 0x0020,
17	L			= 0x0040,
18	A			= 0x0100,
19	B			= 0x0200,
20	X			= 0x0400,
21	Y			= 0x0800,
22	START		= 0x1000,
23}
24
25local timer = love.timer
26local graphics = love.graphics
27local newImage = graphics.newImage
28local newFont = graphics.newFont
29local format = string.format
30
31local DISCONNECTED = newImage("textures/buttons/disconnected.png")
32
33local BUTTON_TEXTURES = {
34	DPAD = {
35		BACKGROUND = newImage("textures/buttons/d-pad-gate.png"),
36		POSITION = {
37			x = 100,
38			y = 128,
39		},
40	},
41
42	DPAD_LEFT = {
43		PRESSED = newImage("textures/buttons/d-pad-pressed-left.png"),
44		POSITION = {
45			x = 108,
46			y = 144,
47		},
48	},
49
50	DPAD_RIGHT = {
51		PRESSED = newImage("textures/buttons/d-pad-pressed-right.png"),
52		POSITION = {
53			x = 108,
54			y = 144,
55		},
56	},
57
58	DPAD_UP = {
59		PRESSED = newImage("textures/buttons/d-pad-pressed-up.png"),
60		POSITION = {
61			x = 108,
62			y = 144,
63		},
64	},
65
66	DPAD_DOWN = {
67		PRESSED = newImage("textures/buttons/d-pad-pressed-down.png"),
68		POSITION = {
69			x = 108,
70			y = 144,
71		},
72	},
73
74	JOYSTICK = {
75		BACKGROUND = newImage("textures/buttons/joystick-gate.png"),
76		MASK = newImage("textures/buttons/joystick-mask.png"),
77		STICK = newImage("textures/buttons/joystick-outline.png"),
78	},
79	CSTICK = {
80		BACKGROUND = newImage("textures/buttons/c-stick-gate.png"),
81		STICK = newImage("textures/buttons/c-stick.png"),
82	},
83	A = {
84		OUTLINE = newImage("textures/buttons/a-outline.png"),
85		PRESSED = newImage("textures/buttons/a-pressed.png"),
86		COLOR = color(0, 225, 150, 255),
87		POSITION = {
88			x = 12 + 64 + 256,
89			y = 64
90		}
91	},
92	B = {
93		OUTLINE = newImage("textures/buttons/b-outline.png"),
94		PRESSED = newImage("textures/buttons/b-pressed.png"),
95		COLOR = color(230, 0, 0, 255),
96		POSITION = {
97			x = 16 + 256,
98			y = 108
99		}
100	},
101	X = {
102		OUTLINE = newImage("textures/buttons/x-outline.png"),
103		PRESSED = newImage("textures/buttons/x-pressed.png"),
104		COLOR = color(255, 255, 255, 255),
105		POSITION = {
106			x = 138 + 256,
107			y = 48
108		}
109	},
110	Y = {
111		OUTLINE = newImage("textures/buttons/y-outline.png"),
112		PRESSED = newImage("textures/buttons/y-pressed.png"),
113		COLOR = color(255, 255, 255, 255),
114		POSITION = {
115			x = 60 + 256,
116			y = 0
117		}
118	},
119	Z = {
120		OUTLINE = newImage("textures/buttons/z-outline.png"),
121		PRESSED = newImage("textures/buttons/z-pressed.png"),
122		COLOR = color(165, 75, 165, 255),
123		POSITION = {
124			x = 128 + 256,
125			y = -16
126		}
127	},
128	START = {
129		OUTLINE = newImage("textures/buttons/start-outline.png"),
130		PRESSED = newImage("textures/buttons/start-pressed.png"),
131		COLOR = color(255, 255, 255, 255),
132		POSITION = {
133			x = 256,
134			y = 42
135		}
136	}
137}
138
139local MAX_PORTS = 4
140
141function PANEL:Initialize()
142	self:super()
143
144	self:SetSize(512, 256)
145	
146	self:DockPadding(0,0,0,0)
147	self:DockMargin(0,0,0,0)
148
149	self.m_pFont = newFont("fonts/ultimate-bold.otf", 16)
150
151	self.m_bEnabled = false
152	self.m_iPort = -1
153	self.m_iActions = 0
154
155	watcher.hook("match.finished", self, self.ResetAPM)
156	watcher.hook("player.*.*.action_state", self, self.UpdateAPM)
157end
158
159function PANEL:SetPort(port)
160	self.m_iPort = port
161end
162
163function PANEL:GetPort()
164	return self.m_iPort
165end
166
167function PANEL:ResetAPM(finished)
168	if finished == 0 then
169		self.m_iActions = 0
170		self.m_bEnabled = true
171	else
172		self.m_bEnabled = false
173	end
174end
175
176function PANEL:UpdateAPM(port, entityType, state_id)
177	local player = watcher.player[port][entityType]
178
179	if player and port == self:GetPort() and (state.isAction(state_id) or state.isCharacterAction(player.character, state_id)) then
180		--print(string.format("[%04X] %s", state_id, state.translateChar(player.character, state_id)))
181		if not self.m_bEnabled then return end
182		self.m_iActions = self.m_iActions + 1
183	end
184end
185
186
187function PANEL:Paint(w, h)
188	graphics.setColor(255, 255, 255, 255)
189
190	local time = watcher.match.frame / 60
191
192	graphics.setFont(self.m_pFont)
193	graphics.print(format("APM: %d", self.m_iActions / time * 60), 8, h - 24)
194end
195
196gui.register("APMDisplay", PANEL, "Base")