fork/m-overlay

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

BkacjiosSort skins alphabeticallycb3e486

v2.1.5
8.0 KiB330 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/SS/SS_Gate.png"),
54		GATE_FILLED = graphics.newImage("textures/buttons/SS/SS_Gate.png"),
55		MASK = graphics.newImage("textures/buttons/joystick-mask.png"),
56		STICK = graphics.newImage("textures/buttons/SS/S_Stick.png"),
57		FILLED = graphics.newImage("textures/buttons/SS/S_Stick.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
65	L = {
66		OUTLINE = graphics.newImage("textures/buttons/SS/SS_L.png"),
67		PRESSED = graphics.newImage("textures/buttons/SS/SS_LP.png"),
68		
69		POSITION = {
70			x = 256 - 64 + 40,
71			y = 64 + 10
72		}
73	},	
74	
75	R = {
76		OUTLINE = graphics.newImage("textures/buttons/SS/SS_R.png"),
77		PRESSED = graphics.newImage("textures/buttons/SS/SS_RP.png"),
78		
79		POSITION = {
80			x = 256 + 128 + 40,
81			y = 64
82		}
83	},	
84	
85	C_UP = {
86		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CU.png"),
87		PRESSED = graphics.newImage("textures/buttons/SS/SS_CUP.png"),
88		
89		POSITION = {
90			x = 256 + 40,
91			y = -10
92		}
93	},
94
95	C_DOWN = {
96		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CD.png"),
97		PRESSED = graphics.newImage("textures/buttons/SS/SS_CDP.png"),
98		
99		POSITION = {
100			x = 256 - 64 - 15,
101			y = 128 + 64 - 10
102		}
103	},
104
105	C_LEFT = {
106		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CL.png"),
107		PRESSED = graphics.newImage("textures/buttons/SS/SS_CLP.png"),
108		
109		POSITION = {
110			x = 256 - 64 + 40,
111			y = 10
112		}
113	},
114
115	C_RIGHT = {
116		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CR.png"),
117		PRESSED = graphics.newImage("textures/buttons/SS/SS_CRP.png"),
118		
119		POSITION = {
120			x = 256 + 64 + 40,
121			y = -10
122		}
123	},
124
125	A = {
126		OUTLINE = graphics.newImage("textures/buttons/SS/SS_A.png"),
127		PRESSED = graphics.newImage("textures/buttons/SS/SS_AP.png"),
128		
129		POSITION = {
130			x = 256 - 64 + 35,
131			y = 128 + 10
132		}
133	},
134	B = {
135		OUTLINE = graphics.newImage("textures/buttons/SS/SS_B.png"),
136		PRESSED = graphics.newImage("textures/buttons/SS/SS_BP.png"),
137		
138		POSITION = {
139			x = 256 + 64 + 40,
140			y = 64 - 10
141		}
142	},
143	X = {
144		OUTLINE = graphics.newImage("textures/buttons/SS/SS_X.png"),
145		PRESSED = graphics.newImage("textures/buttons/SS/SS_XP.png"),
146		
147		POSITION = {
148			x = 256 + 128 + 40,
149			y = 0
150		}
151	},
152	Y = {
153		OUTLINE = graphics.newImage("textures/buttons/SS/SS_Y.png"),
154		PRESSED = graphics.newImage("textures/buttons/SS/SS_YP.png"),
155		
156		POSITION = {
157			x = 256 + 40,
158			y = 64 - 10
159		}
160	},
161	Z = {
162		OUTLINE = graphics.newImage("textures/buttons/SS/SS_Z.png"),
163		PRESSED = graphics.newImage("textures/buttons/SS/SS_ZP.png"),
164		
165		POSITION = {
166			x = 256 - 64 - 25,
167			y = 128 - 10
168		}
169	},
170	START = {
171		OUTLINE = graphics.newImage("textures/buttons/start-outline.png"),
172		FILLED = graphics.newImage("textures/buttons/start-filled.png"),
173		PRESSED = graphics.newImage("textures/buttons/start-pressed.png"),
174		
175		POSITION = {
176			x = 256,
177			y = 26
178		}
179	}
180}
181
182local vertices = {
183	{
184		0, 0,
185		0, 0,
186		1, 1, 1,
187	},
188	{
189		128, 0,
190		1, 0,
191		1, 1, 1
192	},
193	{
194		128, 128,
195		1, 1,
196		1, 1, 1
197	},
198	{
199		0, 128,
200		0, 1,
201		1, 1, 1
202	},
203}
204
205local rotated_vertices = {}
206
207local function transformVertices(vertices, x, y, angle, ox, oy)
208	if #vertices ~= #rotated_vertices then
209		rotated_vertices = {}
210	end
211
212	local c = math.cos(angle)
213	local s = math.sin(angle)
214
215	for i=1, #vertices do
216		-- Create or use vertex cache
217		rotated_vertices[i] = rotated_vertices[i] or {}
218
219		-- Copy and rotate X and Y vertex points
220		rotated_vertices[i][1] = x + (vertices[i][1] - ox) * c - (vertices[i][2] - oy) * s
221		rotated_vertices[i][2] = y + (vertices[i][1] - ox) * s + (vertices[i][2] - oy) * c
222
223		-- Copy other vertex settings
224		rotated_vertices[i][3] = vertices[i][3]
225		rotated_vertices[i][4] = vertices[i][4]
226		rotated_vertices[i][5] = vertices[i][5]
227		rotated_vertices[i][6] = vertices[i][6]
228	end
229
230	return rotated_vertices
231end
232
233local function drawButtons(buttons, controller)
234	for button, flag in pairs(buttons) do
235		local texture = BUTTON_TEXTURES[button]
236		if texture then
237			if button ~= "START" or (button == "START" and SETTINGS:IsStartEnabled()) then
238				
239				local pos = texture.POSITION
240				graphics.setColor(texture.COLOR)
241				local analogr = (SETTINGS:IsSlippiReplay() and melee.isInGame() and controller.analog) and controller.analog.float or controller.analog.r
242				
243				if texture.PRESSED and bit.band(controller.buttons.pressed, flag) == flag then -- Check if the button is pressed
244					graphics.easyDraw(texture.PRESSED, pos.x, pos.y, 0, 88, 88)
245				elseif button == "R" and memory.game.translateTriggers(analogr) > 0 and memory.game.translateTriggers(analogr) < 0.5 then
246					graphics.easyDraw(BUTTON_TEXTURES.R.PRESSED, pos.x, pos.y, 0, 88, 88)
247				else
248					local text = SETTINGS:IsHighContrast() and texture.FILLED or texture.OUTLINE
249					if text then
250						graphics.easyDraw(text, pos.x, pos.y, 0, 88, 88)
251					end
252				end
253			end
254		end
255	end
256end
257
258function SKIN:Paint(controller)
259	local x, y = memory.game.translateJoyStick(controller.joystick.x, controller.joystick.y)
260
261	--[[if SETTINGS:IsDebugging() then
262		local strx = ("JOY_X: % f"):format(x)
263		local stry = ("JOY_Y: % f"):format(y)
264		local btts = ("BUTTONS: %X"):format(controller.buttons.pressed)
265		graphics.setFont(DEBUG_FONT)
266
267		graphics.setColor(0, 0, 0, 255)
268		graphics.textOutline(btts, 2, 96, 256 - 4 - 36)
269		graphics.textOutline(strx, 2, 96, 256 - 4 - 24)
270		graphics.textOutline(stry, 2, 96, 256 - 4 - 12)
271
272		graphics.setColor(255, 255, 255, 255)
273		graphics.print(btts, 96, 256 - 8 - 36 )
274		graphics.print(strx, 96, 256 - 4 - 24)
275		graphics.print(stry, 96, 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 * 15 -- Higher value = headed towards infinity
284	local near = mag * 20 -- Higher value = more rotation into the horizon
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 + 22 + (44 * vx), 64 + 8 + (44 * vy), angle, 64, 64)
299
300	graphics.setColor(255, 255, 255, 255)
301
302	if SETTINGS:IsHighContrast() then
303		graphics.easyDraw(BUTTON_TEXTURES.JOYSTICK.GATE_FILLED, 22, 52, 0, 128, 128)
304	else
305		graphics.stencil(function()
306			perspective.on()
307			perspective.quad(BUTTON_TEXTURES.JOYSTICK.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.JOYSTICK.GATE, 22, 52, 0, 128, 128)
312		graphics.setStencilTest()
313	end
314
315	perspective.on()
316	perspective.quad(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.JOYSTICK.FILLED or BUTTON_TEXTURES.JOYSTICK.STICK, rotated[1], rotated[2], rotated[3], rotated[4])
317	perspective.off()
318
319	
320	-- Draw buttons
321
322	if SETTINGS:IsDPadEnabled() then
323		graphics.easyDraw(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.DPAD.GATE_FILLED or BUTTON_TEXTURES.DPAD.GATE, 108, 144, 0, 128, 128)
324		drawButtons(DPAD, controller)
325	end
326
327	drawButtons(BUTTONS, controller)
328end
329
330overlay.registerSkin("S-Stick", SKIN)