fork/m-overlay

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

Bkacjioskill me4032e64

master
6.7 KiB266 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	JOYSTICK = {
8		GATE = graphics.newImage("textures/buttons/SS/SS_Gate.png"),
9		GATE_FILLED = graphics.newImage("textures/buttons/SS/SS_Gate.png"),
10		MASK = graphics.newImage("textures/buttons/joystick-mask.png"),
11		STICK = graphics.newImage("textures/buttons/SS/S_Stick.png"),
12		FILLED = graphics.newImage("textures/buttons/SS/S_Stick.png"),
13	},
14	CSTICK = {
15		GATE = graphics.newImage("textures/buttons/c-stick-gate.png"),
16		GATE_FILLED = graphics.newImage("textures/buttons/c-stick-gate-filled.png"),
17		STICK = graphics.newImage("textures/buttons/c-stick-solid.png"),
18	},
19
20	L = {
21		OUTLINE = graphics.newImage("textures/buttons/SS/SS_L.png"),
22		PRESSED = graphics.newImage("textures/buttons/SS/SS_LP.png"),
23		
24		POSITION = {
25			x = 256 - 64 + 40,
26			y = 64 + 10
27		}
28	},	
29	
30	R = {
31		OUTLINE = graphics.newImage("textures/buttons/SS/SS_R.png"),
32		PRESSED = graphics.newImage("textures/buttons/SS/SS_RP.png"),
33		
34		POSITION = {
35			x = 256 + 128 + 40,
36			y = 64
37		}
38	},	
39	
40	C_UP = {
41		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CU.png"),
42		PRESSED = graphics.newImage("textures/buttons/SS/SS_CUP.png"),
43		
44		POSITION = {
45			x = 256 + 40,
46			y = -10
47		}
48	},
49
50	C_DOWN = {
51		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CD.png"),
52		PRESSED = graphics.newImage("textures/buttons/SS/SS_CDP.png"),
53		
54		POSITION = {
55			x = 256 - 64 - 15,
56			y = 128 + 64 - 10
57		}
58	},
59
60	C_LEFT = {
61		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CL.png"),
62		PRESSED = graphics.newImage("textures/buttons/SS/SS_CLP.png"),
63		
64		POSITION = {
65			x = 256 - 64 + 40,
66			y = 10
67		}
68	},
69
70	C_RIGHT = {
71		OUTLINE = graphics.newImage("textures/buttons/SS/SS_CR.png"),
72		PRESSED = graphics.newImage("textures/buttons/SS/SS_CRP.png"),
73		
74		POSITION = {
75			x = 256 + 64 + 40,
76			y = -10
77		}
78	},
79
80	A = {
81		OUTLINE = graphics.newImage("textures/buttons/SS/SS_A.png"),
82		PRESSED = graphics.newImage("textures/buttons/SS/SS_AP.png"),
83		
84		POSITION = {
85			x = 256 - 64 + 35,
86			y = 128 + 10
87		}
88	},
89	B = {
90		OUTLINE = graphics.newImage("textures/buttons/SS/SS_B.png"),
91		PRESSED = graphics.newImage("textures/buttons/SS/SS_BP.png"),
92		
93		POSITION = {
94			x = 256 + 64 + 40,
95			y = 64 - 10
96		}
97	},
98	X = {
99		OUTLINE = graphics.newImage("textures/buttons/SS/SS_X.png"),
100		PRESSED = graphics.newImage("textures/buttons/SS/SS_XP.png"),
101		
102		POSITION = {
103			x = 256 + 128 + 40,
104			y = 0
105		}
106	},
107	Y = {
108		OUTLINE = graphics.newImage("textures/buttons/SS/SS_Y.png"),
109		PRESSED = graphics.newImage("textures/buttons/SS/SS_YP.png"),
110		
111		POSITION = {
112			x = 256 + 40,
113			y = 64 - 10
114		}
115	},
116	Z = {
117		OUTLINE = graphics.newImage("textures/buttons/SS/SS_Z.png"),
118		PRESSED = graphics.newImage("textures/buttons/SS/SS_ZP.png"),
119		
120		POSITION = {
121			x = 256 - 64 - 25,
122			y = 128 - 10
123		}
124	}
125}
126
127local vertices = {
128	{
129		0, 0,
130		0, 0,
131		1, 1, 1,
132	},
133	{
134		128, 0,
135		1, 0,
136		1, 1, 1
137	},
138	{
139		128, 128,
140		1, 1,
141		1, 1, 1
142	},
143	{
144		0, 128,
145		0, 1,
146		1, 1, 1
147	},
148}
149
150local rotated_vertices = {}
151
152local function transformVertices(vertices, x, y, angle, ox, oy)
153	if #vertices ~= #rotated_vertices then
154		rotated_vertices = {}
155	end
156
157	local c = math.cos(angle)
158	local s = math.sin(angle)
159
160	for i=1, #vertices do
161		-- Create or use vertex cache
162		rotated_vertices[i] = rotated_vertices[i] or {}
163
164		-- Copy and rotate X and Y vertex points
165		rotated_vertices[i][1] = x + (vertices[i][1] - ox) * c - (vertices[i][2] - oy) * s
166		rotated_vertices[i][2] = y + (vertices[i][1] - ox) * s + (vertices[i][2] - oy) * c
167
168		-- Copy other vertex settings
169		rotated_vertices[i][3] = vertices[i][3]
170		rotated_vertices[i][4] = vertices[i][4]
171		rotated_vertices[i][5] = vertices[i][5]
172		rotated_vertices[i][6] = vertices[i][6]
173	end
174
175	return rotated_vertices
176end
177
178local function drawButtons(buttons, controller)
179	for button, flag in pairs(buttons) do
180		local texture = BUTTON_TEXTURES[button]
181		if texture then
182			local pos = texture.POSITION
183			graphics.setColor(texture.COLOR)
184			local analogr = (SETTINGS:IsSlippiReplay() and melee.isInGame() and controller.analog) and controller.analog.float or controller.analog
185			local tl, tr = memory.game.translateTriggers(0, analogr and analogr.r or 0)
186
187			if texture.PRESSED and bit.band(controller.buttons.pressed, flag) == flag then -- Check if the button is pressed
188				graphics.easyDraw(texture.PRESSED, pos.x, pos.y, 0, 88, 88)
189			elseif button == "R" and tr > 0 and tr < 0.5 then
190				graphics.easyDraw(BUTTON_TEXTURES.R.PRESSED, pos.x, pos.y, 0, 88, 88)
191			else
192				local text = SETTINGS:IsHighContrast() and texture.FILLED or texture.OUTLINE
193				if text then
194					graphics.easyDraw(text, pos.x, pos.y, 0, 88, 88)
195				end
196			end
197		end
198	end
199end
200
201function SKIN:Paint(controller)
202	local x, y = memory.game.translateJoyStick(controller.joystick.x, controller.joystick.y)
203
204	--[[if SETTINGS:IsDebugging() then
205		local strx = ("JOY_X: % f"):format(x)
206		local stry = ("JOY_Y: % f"):format(y)
207		local btts = ("BUTTONS: %X"):format(controller.buttons.pressed)
208		graphics.setFont(DEBUG_FONT)
209
210		graphics.setColor(0, 0, 0, 255)
211		graphics.textOutline(btts, 2, 96, 256 - 4 - 36)
212		graphics.textOutline(strx, 2, 96, 256 - 4 - 24)
213		graphics.textOutline(stry, 2, 96, 256 - 4 - 12)
214
215		graphics.setColor(255, 255, 255, 255)
216		graphics.print(btts, 96, 256 - 8 - 36 )
217		graphics.print(strx, 96, 256 - 4 - 24)
218		graphics.print(stry, 96, 256 - 4 - 12)
219	end]]
220
221	local vx, vy = x, 1 - y
222
223	local angle = math.atan2(x, y)
224	local mag = math.sqrt(x*x + y*y)
225
226	local far = mag * 15 -- Higher value = headed towards infinity
227	local near = mag * 20 -- Higher value = more rotation into the horizon
228
229	-- Make the rectangle look like its fading into the horizon
230
231	-- Top left
232	vertices[1][1] = far
233	-- Top right
234	vertices[2][1] = 128 - far
235
236	-- Bottom left
237	vertices[1][2] = near
238	-- Bottom right
239	vertices[2][2] = near
240
241	local rotated = transformVertices(vertices, 64 + 22 + (44 * vx), 64 + 8 + (44 * vy), angle, 64, 64)
242
243	graphics.setColor(255, 255, 255, 255)
244
245	if SETTINGS:IsHighContrast() then
246		graphics.easyDraw(BUTTON_TEXTURES.JOYSTICK.GATE_FILLED, 22, 52, 0, 128, 128)
247	else
248		graphics.stencil(function()
249			perspective.on()
250			perspective.quad(BUTTON_TEXTURES.JOYSTICK.MASK, rotated[1], rotated[2], rotated[3], rotated[4])
251			perspective.off()
252		end, "replace", 1)
253		graphics.setStencilTest("equal", 0) -- Mask out the gate behind the joystick
254			graphics.easyDraw(BUTTON_TEXTURES.JOYSTICK.GATE, 22, 52, 0, 128, 128)
255		graphics.setStencilTest()
256	end
257
258	perspective.on()
259	perspective.quad(SETTINGS:IsHighContrast() and BUTTON_TEXTURES.JOYSTICK.FILLED or BUTTON_TEXTURES.JOYSTICK.STICK, rotated[1], rotated[2], rotated[3], rotated[4])
260	perspective.off()
261
262	-- Draw buttons
263	drawButtons(BUTTONS, controller)
264end
265
266overlay.registerSkin("S-Stick", SKIN)