fork/m-overlay

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

BkacjiosAdded support for Billy Hatcher and the Giant Egg (NTSC-U v1.0) (#121) Renamed translateAxis to translateJoyStick and added a translateCStick59a1193

v2.1.6
3.6 KiB107 linesraw
1local SKIN = {}
2
3local grey = color(100, 100, 100, 225)
4
5local function draw20XXShadow(x, y, w, h, c)
6	graphics.setColor(c.r/4, c.g/4, c.b/4, 75)
7	graphics.rectangle("fill", x, y, w, 8)
8	graphics.rectangle("fill", x, y + 8, 12, h - 8)
9end
10
11local function draw20XXBox(x, y, w, h, c)
12	graphics.setColor(c.r, c.g, c.b, c.a)
13	graphics.rectangle("fill", x, y, w, h)
14
15	draw20XXShadow(x, y, w, h, c)
16end
17
18local function draw20XXButton(x, y, w, h, c, controller, flag)
19	draw20XXBox(x, y, w, h, c)
20	if bit.band(controller.buttons.pressed, flag) == flag then
21		graphics.setColor(255, 255, 255, 255)
22		graphics.rectangle("fill", x, y, w, h)
23	end
24end
25
26local function draw20XXAnalog(x, y, w, h, c, controller, value, flag, flipped)
27	graphics.setColor(c.r, c.g, c.b, c.a)
28	graphics.rectangle("fill", x, y, w, h)
29
30	if bit.band(controller.buttons.pressed, flag) == flag then
31		graphics.setColor(255, 255, 255, 255)
32		graphics.rectangle("fill", x, y, w, h)
33	else
34		graphics.setColor(200, 200, 200, 255)
35		if flipped then
36			graphics.rectangle("fill", w + x, y, w*-value, h)
37		else
38			graphics.rectangle("fill", x, y, w*value, h)
39		end
40		draw20XXShadow(x, y, w, h, c)
41	end
42end
43
44local white = color(255, 255, 255, 225)
45local red = color(200, 0, 0, 225)
46local green = color(0, 200, 0, 225)
47local purple = color(125, 0, 125, 225)
48local dyellow = color(125, 125, 0, 225)
49local yellow = color(255, 255, 0, 225)
50
51local root2 = math.sqrt(2)
52
53function SKIN:Paint(controller)
54	draw20XXBox(56, 56, 96, 96, grey) -- Joystick
55
56	local x, y = memory.game.translateJoyStick(controller.joystick.x, controller.joystick.y)
57
58	-- Map circular coordiantes onto a square
59	-- https://stackoverflow.com/a/32391780
60
61	local sx = 0.5 * math.sqrt(2 + x*x - y*y + 2*x*root2) - 0.5 * math.sqrt(2 + x*x - y*y - 2*x*root2)
62	local sy = 0.5 * math.sqrt(2 - x*x + y*y + 2*y*root2) - 0.5 * math.sqrt(2 - x*x + y*y - 2*y*root2)
63
64	draw20XXBox((56 + 48 - 8) + 40 * sx, (56 + 48 - 8) + 40 * (-sy), 16, 16, white)
65
66	draw20XXButton(256, 56+32, 64, 64, green, controller, BUTTONS.A) -- A
67	draw20XXButton(256-40, 56+64+16, 32, 32, red, controller, BUTTONS.B) -- B
68
69	if SETTINGS:IsStartEnabled() then
70		draw20XXButton(256-64, 56+32, 24, 24, grey, controller, BUTTONS.START) -- Start
71	end
72
73	draw20XXButton(256, 56, 64, 24, grey, controller, BUTTONS.Y) -- Y
74	draw20XXButton(256 + 64 + 8, 56, 24, 24, purple, controller, BUTTONS.Z) -- Z
75	draw20XXButton(256 + 64 + 8, 56 + 32, 24, 64, grey, controller, BUTTONS.X) -- X
76
77	draw20XXBox(256 + 64 + 40, 56, 96, 96, dyellow) -- C-Stick
78
79	if SETTINGS:IsDPadEnabled() then
80		draw20XXButton(128, 168, 24, 24, grey, controller, DPAD.DPAD_UP)
81		draw20XXButton(128 - 28, 168 + 28, 24, 24, grey, controller, DPAD.DPAD_LEFT)
82		draw20XXButton(128 + 28, 168 + 28, 24, 24, grey, controller, DPAD.DPAD_RIGHT)
83		draw20XXButton(128, 168 + 56, 24, 24, grey, controller, DPAD.DPAD_DOWN)
84	end
85
86	local x, y = memory.game.translateCStick(controller.cstick.x, controller.cstick.y)
87
88	local sx = 0.5 * math.sqrt(2 + x*x - y*y + 2*x*root2) - 0.5 * math.sqrt(2 + x*x - y*y - 2*x*root2)
89	local sy = 0.5 * math.sqrt(2 - x*x + y*y + 2*y*root2) - 0.5 * math.sqrt(2 - x*x + y*y - 2*y*root2)
90
91	draw20XXBox((256 + 64 + 80) + 40 * sx, (56 + 48 - 8) + 40 * (-sy), 16, 16, yellow)
92
93	local al, ar = 0, 0
94
95	if SETTINGS:IsSlippiReplay() and melee.isInGame() then
96		local analog = controller.analog and controller.analog.float or 0
97		al = analog
98		ar = analog
99	else
100		al, ar = memory.game.translateTriggers(controller.analog.l, controller.analog.r)
101	end
102
103	draw20XXAnalog(56 + 12, 24, 84, 24, grey, controller, al, BUTTONS.L) -- L
104	draw20XXAnalog(256, 24, 84, 24, grey, controller, ar, BUTTONS.R, true) -- R
105end
106
107overlay.registerSkin("20XX", SKIN)