fork/m-overlay

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

BkacjiosAdded labels to port and skin selector to make it more obvious what these panels do.c7c24b0

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