File: keyboard.lua

package info (click to toggle)
mrrescue 1.02e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,228 kB
  • sloc: makefile: 9; sh: 1
file content (109 lines) | stat: -rw-r--r-- 2,577 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
keyboard = {}

local lg = love.graphics

function keyboard.enter()
	state = STATE_KEYBOARD
	keyboard.selection = 1
	keyboard.waiting = false
end

function keyboard.update(dt)
	updateKeys()
end

function keyboard.draw()
	lg.push()
	lg.scale(config.scale)
	lg.setFont(font.bold)

	drawBox(40, 41, 176, 134)

	lg.printf("SET KEYBOARD", 0, 26, WIDTH, "center")
	for i,v in ipairs(keynames) do
		if keyboard.waiting == true and i == keyboard.selection then
			lg.setColor(195,52,41)
		end
		lg.print(string.upper(v), 65, 40+i*13)
		if config.keys[v] == " " then
			lg.print("SPACE", 154, 40+i*13)
		elseif config.keys[v] == "none" then
			lg.setColor(118,31,25)
			lg.print("NONE", 154, 40+i*13)
			lg.setColor(255,255,255)
		else
			lg.print(string.upper(config.keys[v]:sub(1,7)), 154, 40+i*13)
		end
		lg.setColor(255,255,255)
	end
	lg.print("DEFAULT", 65, 144)
	lg.print("BACK", 65, 157)

	lg.print(">", 52, 40+keyboard.selection*13)

	lg.pop()
end

function keyboard.keypressed(k, uni)
	if keyboard.waiting == false then
		if k == "down" then
			keyboard.selection = wrap(keyboard.selection + 1, 1, 9)
			playSound("blip")
		elseif k == "up" then
			keyboard.selection = wrap(keyboard.selection - 1, 1, 9)
			playSound("blip")
		
		elseif k == "return" then
			if keyboard.selection >= 1 and keyboard.selection <= 7 then
				playSound("blip")
				keyboard.waiting = true
			elseif keyboard.selection == 8 then -- DEFAULT
				playSound("confirm")
				defaultKeys()
			elseif keyboard.selection == 9 then -- BACK
				playSound("confirm")
				options.enter()
			end
		elseif k == "escape" then
			playSound("confirm")
			options.enter()
		end
	else
		if k ~= "escape" then
			for i,v in ipairs(keynames) do
				if config.keys[v] == k then
					config.keys[v] = "none"
				end
			end
			config.keys[keynames[keyboard.selection]] = k
		end
		playSound("blip")
		keyboard.waiting = false
	end
end

function keyboard.action(k)
	if keyboard.waiting == false then
		if k == "down" then
			keyboard.selection = wrap(keyboard.selection + 1, 1, 9)
			playSound("blip")
		elseif k == "up" then
			keyboard.selection = wrap(keyboard.selection - 1, 1, 9)
			playSound("blip")
		elseif k == "jump" then
			if keyboard.selection >= 1 and keyboard.selection <= 7 then
				playSound("blip")
				keyboard.waiting = true
			elseif keyboard.selection == 8 then -- DEFAULT
				playSound("confirm")
				defaultKeys()
			elseif keyboard.selection == 9 then -- BACK
				playSound("confirm")
				options.enter()
			end
		elseif k == "action" then
			playSound("confirm")
			options.enter()
		end
	end
end