fork/m-overlay

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

Julia RyanChange button colors0747cf1

main
12.3 KiB446 linesraw
1local SKIN = {}
2
3local ANALOG = graphics.newImage("textures/buttons/analog-outline.png")
4local ANALOG_FILLED = graphics.newImage("textures/buttons/analog-filled.png")
5
6local BUTTON_TEXTURES = {
7	DPAD = {
8		GATE = graphics.newImage("textures/buttons/d-pad-gate.png"),
9		GATE_FILLED = graphics.newImage("textures/buttons/d-pad-gate-filled.png"),
10		POSITION = {
11			x = 100,
12			y = 128,
13		},
14	},
15
16	DPAD_LEFT = {
17		PRESSED = graphics.newImage("textures/buttons/d-pad-pressed-left.png"),
18
19		POSITION = {
20			x = 108,
21			y = 144,
22		},
23	},
24
25	DPAD_RIGHT = {
26		PRESSED = graphics.newImage("textures/buttons/d-pad-pressed-right.png"),
27
28		POSITION = {
29			x = 108,
30			y = 144,
31		},
32	},
33
34	DPAD_UP = {
35		PRESSED = graphics.newImage("textures/buttons/d-pad-pressed-up.png"),
36
37		POSITION = {
38			x = 108,
39			y = 144,
40		},
41	},
42
43	DPAD_DOWN = {
44		PRESSED = graphics.newImage("textures/buttons/d-pad-pressed-down.png"),
45
46		POSITION = {
47			x = 108,
48			y = 144,
49		},
50	},
51
52	JOYSTICK = {
53		GATE = graphics.newImage("textures/buttons/joystick-gate.png"),
54		GATE_FILLED = graphics.newImage("textures/buttons/joystick-gate-filled.png"),
55		MASK = graphics.newImage("textures/buttons/joystick-mask.png"),
56		STICK = graphics.newImage("textures/buttons/joystick.png"),
57		FILLED = graphics.newImage("textures/buttons/joystick-filled.png"),
58	},
59	CSTICK = {
60		GATE = graphics.newImage("textures/buttons/c-stick-gate.png"),
61		GATE_FILLED = graphics.newImage("textures/buttons/c-stick-gate-filled.png"),
62		MASK = graphics.newImage("textures/buttons/c-stick-mask.png"),
63		STICK = graphics.newImage("textures/buttons/c-stick.png"),
64		FILLED = graphics.newImage("textures/buttons/c-stick-filled.png"),
65	},
66	A = {
67		OUTLINE = graphics.newImage("textures/buttons/a-outline.png"),
68		FILLED = graphics.newImage("textures/buttons/a-filled.png"),
69		PRESSED = graphics.newImage("textures/buttons/a-pressed.png"),
70		COLOR = color_blue,
71		POSITION = {
72			x = 12 + 64 + 256,
73			y = 48
74		}
75	},
76	B = {
77		OUTLINE = graphics.newImage("textures/buttons/b-outline.png"),
78		FILLED = graphics.newImage("textures/buttons/b-filled.png"),
79		PRESSED = graphics.newImage("textures/buttons/b-pressed.png"),
80		COLOR = color_pink,
81		POSITION = {
82			x = 16 + 256,
83			y = 92
84		}
85	},
86	X = {
87		OUTLINE = graphics.newImage("textures/buttons/x-outline.png"),
88		FILLED = graphics.newImage("textures/buttons/x-filled.png"),
89		PRESSED = graphics.newImage("textures/buttons/x-pressed.png"),
90		COLOR = color_pink,
91		POSITION = {
92			x = 138 + 256,
93			y = 32
94		}
95	},
96	Y = {
97		OUTLINE = graphics.newImage("textures/buttons/y-outline.png"),
98		FILLED = graphics.newImage("textures/buttons/y-filled.png"),
99		PRESSED = graphics.newImage("textures/buttons/y-pressed.png"),
100		COLOR = color_white,
101		POSITION = {
102			x = 60 + 256,
103			y = -16
104		}
105	},
106	Z = {
107		OUTLINE = graphics.newImage("textures/buttons/z-outline.png"),
108		FILLED = graphics.newImage("textures/buttons/z-filled.png"),
109		PRESSED = graphics.newImage("textures/buttons/z-pressed.png"),
110		COLOR = color_blue,
111		POSITION = {
112			x = 128 + 256,
113			y = -32
114		}
115	},
116	START = {
117		OUTLINE = graphics.newImage("textures/buttons/start-outline.png"),
118		FILLED = graphics.newImage("textures/buttons/start-filled.png"),
119		PRESSED = graphics.newImage("textures/buttons/start-pressed.png"),
120		COLOR = color(color_blue),
121		POSITION = {
122			x = 256,
123			y = 26
124		}
125	}
126}
127
128local vertices = {
129	{
130		0, 0,
131		0, 0,
132		1, 1, 1,
133	},
134	{
135		128, 0,
136		1, 0,
137		1, 1, 1
138	},
139	{
140		128, 128,
141		1, 1,
142		1, 1, 1
143	},
144	{
145		0, 128,
146		0, 1,
147		1, 1, 1
148	},
149}
150
151local rotated_vertices = {}
152
153local function transformVertices(vertices, x, y, angle, ox, oy)
154	if #vertices ~= #rotated_vertices then
155		rotated_vertices = {}
156	end
157
158	local c = math.cos(angle)
159	local s = math.sin(angle)
160
161	for i=1, #vertices do
162		-- Create or use vertex cache
163		rotated_vertices[i] = rotated_vertices[i] or {}
164
165		-- Copy and rotate X and Y vertex points
166		rotated_vertices[i][1] = x + (vertices[i][1] - ox) * c - (vertices[i][2] - oy) * s
167		rotated_vertices[i][2] = y + (vertices[i][1] - ox) * s + (vertices[i][2] - oy) * c
168
169		-- Copy other vertex settings
170		rotated_vertices[i][3] = vertices[i][3]
171		rotated_vertices[i][4] = vertices[i][4]
172		rotated_vertices[i][5] = vertices[i][5]
173		rotated_vertices[i][6] = vertices[i][6]
174	end
175
176	return rotated_vertices
177end
178
179local function drawButtons(buttons, controller)
180	for button, flag in pairs(buttons) do
181		local texture = BUTTON_TEXTURES[button]
182		if texture then
183			if button ~= "START" or (button == "START" and SETTINGS:IsStartEnabled()) then
184				local pos = texture.POSITION
185				graphics.setColor(texture.COLOR)
186				if texture.PRESSED and bit.band(controller.buttons.pressed, flag) == flag then -- Check if the button is pressed
187					graphics.easyDraw(texture.PRESSED, pos.x, pos.y, 0, 128, 128)
188				else
189					local text = SETTINGS:IsHighContrast() and texture.FILLED or texture.OUTLINE
190					if text then
191						graphics.easyDraw(text, pos.x, pos.y, 0, 128, 128)
192					end
193				end
194			end
195		end
196	end
197end
198
199function SKIN:Paint(controller)
200	local x, y = memory.game.translateJoyStick(controller.joystick.x, controller.joystick.y)
201
202	--[[if SETTINGS:IsDebugging() then
203		local strx = ("JOY_X: % f"):format(x)
204		local stry = ("JOY_Y: % f"):format(y)
205		local btts = ("BUTTONS: %X"):format(controller.buttons.pressed)
206		graphics.setFont(DEBUG_FONT)
207
208		graphics.setColor(0, 0, 0, 255)
209		graphics.textOutline(btts, 2, 96, 256 - 4 - 36)
210		graphics.textOutline(strx, 2, 96, 256 - 4 - 24)
211		graphics.textOutline(stry, 2, 96, 256 - 4 - 12)
212
213		graphics.setColor(255, 255, 255, 255)
214		graphics.print(btts, 96, 256 - 8 - 36 )
215		graphics.print(strx, 96, 256 - 4 - 24)
216		graphics.print(stry, 96, 256 - 4 - 12)
217	end]]
218
219	local vx, vy = x, 1 - y
220
221	local angle = math.atan2(x, y)
222	local mag = math.sqrt(x*x + y*y)
223
224	local far = mag * 12 -- Higher value = headed towards infinity
225	local near = mag * 20 -- Higher value = more rotation into the horizon
226
227	-- Make the rectangle look like its fading into the horizon
228
229	-- Top left
230	vertices[1][1] = far
231	-- Top right
232	vertices[2][1] = 128 - far
233
234	-- Bottom left
235	vertices[1][2] = near
236	-- Bottom right
237	vertices[2][2] = near
238
239	local rotated = transformVertices(vertices, 64 + 22 + (44 * vx), 64 + 8 + (44 * vy), angle, 64, 64)
240
241	graphics.setColor(255, 255, 255, 255)
242
243	if SETTINGS:IsHighContrast() then
244		graphics.easyDraw(BUTTON_TEXTURES.JOYSTICK.GATE_FILLED, 22, 52, 0, 128, 128)
245	else
246		graphics.stencil(function()
247			perspective.on()
248			perspective.quad(BUTTON_TEXTURES.JOYSTICK.MASK, rotated[1], rotated[2], rotated[3], rotated[4])
249			perspective.off()
250		end, "replace", 1)
251		graphics.setStencilTest("equal", 0) -- Mask out the gate behind the joystick
252			graphics.easyDraw(BUTTON_TEXTURES.JOYSTICK.GATE, 22, 52, 0, 128, 128)
253		graphics.setStencilTest()
254	end
255
256	perspective.on()
257	perspective.quad(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.JOYSTICK.FILLED or BUTTON_TEXTURES.JOYSTICK.STICK, rotated[1], rotated[2], rotated[3], rotated[4])
258	perspective.off()
259
260	-- Draw C-Stick
261
262	local x, y = memory.game.translateCStick(controller.cstick.x, controller.cstick.y)
263
264	--[[if SETTINGS:IsDebugging() then
265		local strx = ("C_X: % f"):format(x)
266		local stry = ("C_Y: % f"):format(y)
267		graphics.setFont(DEBUG_FONT)
268
269		graphics.setColor(0, 0, 0, 255)
270		graphics.textOutline(strx, 2, 224, 256 - 4 - 24)
271		graphics.textOutline(stry, 2, 224, 256 - 4 - 12)
272
273		graphics.setColor(255, 255, 255, 255)
274		graphics.print(strx, 224, 256 - 4 - 24)
275		graphics.print(stry, 224, 256 - 4 - 12)
276	end]]
277
278	local vx, vy = x, 1 - y
279
280	local angle = math.atan2(x, y)
281	local mag = math.sqrt(x*x + y*y)
282
283	local far = mag * 12
284	local near = mag * 20
285
286	-- Make the rectangle look like its fading into the horizon
287
288	-- Top left
289	vertices[1][1] = far
290	-- Top right
291	vertices[2][1] = 128 - far
292
293	-- Bottom left
294	vertices[1][2] = near
295	-- Bottom right
296	vertices[2][2] = near
297
298	local rotated = transformVertices(vertices, 64 + 48 + 128 + (32 * vx), 64 + 18 + (32 * vy), angle, 64, 64)
299
300	graphics.setColor(color_blue)
301
302	if SETTINGS:IsHighContrast() then
303		graphics.easyDraw(BUTTON_TEXTURES.CSTICK.GATE_FILLED, 48 + 128, 52, 0, 128, 128)
304	else
305		graphics.stencil(function()
306			perspective.on()
307			perspective.quad(BUTTON_TEXTURES.CSTICK.MASK, rotated[1], rotated[2], rotated[3], rotated[4])
308			perspective.off()
309		end, "replace", 1)
310		graphics.setStencilTest("equal", 0) -- Mask out the gate behind the joystick
311			graphics.easyDraw(BUTTON_TEXTURES.CSTICK.GATE, 48 + 128, 52, 0, 128, 128)
312		graphics.setStencilTest()
313	end
314
315	perspective.on()
316	perspective.quad(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.CSTICK.FILLED or BUTTON_TEXTURES.CSTICK.STICK, rotated[1], rotated[2], rotated[3], rotated[4])
317	perspective.off()
318
319	graphics.setColor(255, 255, 255, 255)
320
321	-- Draw L
322
323	graphics.setColor(color_pink)
324	if SETTINGS:IsSlippiReplay() and melee.isInGame() then
325		graphics.setLineStyle("smooth")
326		graphics.setLineWidth(4)
327
328		-- Draw outline
329		graphics.easyDraw(SETTINGS:IsHighContrast() and ANALOG_FILLED or ANALOG, 108 + 6, 14, 0, 116, 24)
330
331		-- Draw L segment for button press
332		graphics.line(108 + 14 + 88, 20, 108 + 14 + 88, 20 + 12)
333
334		-- Draw R segment for button press
335		graphics.line(108 + 14 + 12, 20, 108 + 14 + 12, 20 + 12)
336
337		graphics.stencil(function()
338			-- Create a rounded rectangle mask
339			graphics.rectangle("fill", 108 + 14, 20, 100, 12, 6, 6)
340		end, "replace", 1)
341		graphics.setStencilTest("greater", 0) -- Only draw within our rounded rectangle mask
342			-- Analog
343
344			local analog = controller.analog and controller.analog.float or 0
345
346			if not melee.isInGame() then
347				local al, ar = memory.game.translateTriggers(controller.analog.l, controller.analog.r)
348				al = math.min(al, 1)
349				ar = math.min(ar, 1)
350				analog = math.max(al, ar)
351			end
352
353	 		-- L Button
354			if bit.band(controller.buttons.pressed, BUTTONS.L) == BUTTONS.L then
355				graphics.rectangle("fill", 108 + 14, 20, 12, 12)
356				analog = 1
357			end
358
359			-- R Button
360			if bit.band(controller.buttons.pressed, BUTTONS.R) == BUTTONS.R then
361				graphics.rectangle("fill", 108 + 14 + 12 + 76, 20, 12, 12)
362				analog = 1
363			end
364
365			local w = 76 * analog
366			graphics.rectangle("fill", 108 + 14 + 12 + 76/2 - (w/2), 20, w, 12)
367		graphics.setStencilTest()
368	else
369		local al, ar = memory.game.translateTriggers(controller.analog.l, controller.analog.r)
370		al = math.min(al, 1)
371		ar = math.min(ar, 1)
372
373		graphics.setLineStyle("smooth")
374		graphics.setLineWidth(4)
375
376		-- Draw L
377
378		-- Draw outline
379		graphics.easyDraw(SETTINGS:IsHighContrast() and ANALOG_FILLED or ANALOG, 24 + 6, 14, 0, 116, 24)
380		-- Draw segment for button press
381		graphics.line(24 + 14 + 88, 20, 24 + 14 + 88, 20 + 12)
382
383		graphics.stencil(function()
384			-- Create a rounded rectangle mask
385			graphics.rectangle("fill", 24 + 14, 20, 100, 12, 6, 6)
386		end, "replace", 1)
387		graphics.setStencilTest("greater", 0) -- Only draw within our rounded rectangle mask
388	 		-- L Button
389			if bit.band(controller.buttons.pressed, BUTTONS.L) == BUTTONS.L then
390				graphics.rectangle("fill", 24 + 14 + 88, 20, 12, 12)
391				al = 1
392			end
393
394			-- L Analog
395			graphics.rectangle("fill", 24 + 14, 20, 88 * al, 12)
396		graphics.setStencilTest()
397
398		-- Draw R
399
400        graphics.setColor(color_white)
401		-- Draw outline
402		graphics.easyDraw(SETTINGS:IsHighContrast() and ANALOG_FILLED or ANALOG, 48 + 128 + 6, 14, 0, 116, 24)
403		-- Draw segment for button press
404		graphics.line(48 + 128 + 14 + 12, 20, 48 + 128 + 14 + 12, 20 + 12)
405
406		graphics.stencil(function()
407			-- Create a rounded rectangle mask
408			graphics.rectangle("fill", 48 + 128 + 14, 20, 100, 12, 6, 6)
409		end, "replace", 1)
410		graphics.setStencilTest("greater", 0) -- Only draw within our rounded rectangle mask
411			-- R Button
412			if bit.band(controller.buttons.pressed, BUTTONS.R) == BUTTONS.R then
413				graphics.rectangle("fill", 48 + 128 + 14, 20, 12, 12)
414				ar = 1
415			end
416
417			-- R Analog
418			graphics.rectangle("fill", 48 + 128 + 14 + 12 + (88 * (1 - ar)), 20, 88 * ar, 12)
419		graphics.setStencilTest()
420
421		--[[if SETTINGS:IsDebugging() then
422			local strl = ("L: %f"):format(al)
423			local strr = ("R: %f"):format(ar)
424			graphics.setFont(DEBUG_FONT)
425
426			graphics.setColor(0, 0, 0, 255)
427			graphics.textOutline(strl, 2, 340, 256 - 4 - 24)
428			graphics.textOutline(strr, 2, 340, 256 - 4 - 12)
429
430			graphics.setColor(255, 255, 255, 255)
431			graphics.print(strl, 340, 256 - 4 - 24)
432			graphics.print(strr, 340, 256 - 4 - 12)
433		end]]
434	end
435
436	-- Draw buttons
437
438	if SETTINGS:IsDPadEnabled() then
439		graphics.easyDraw(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.DPAD.GATE_FILLED or BUTTON_TEXTURES.DPAD.GATE, 108, 144, 0, 128, 128)
440		drawButtons(DPAD, controller)
441	end
442
443	drawButtons(BUTTONS, controller)
444end
445
446overlay.registerSkin("Default", SKIN)