Support multiple bindings per an action
This commit is contained in:
parent
2cda8e6801
commit
6f7e0777b1
3 changed files with 38 additions and 44 deletions
|
@ -36,14 +36,13 @@ function menu_state:enter()
|
||||||
Label(string.format("Player %d", player), midfont, { 255, 255, 255, 255 }, "left", 500, 0, x, y, menu_state)
|
Label(string.format("Player %d", player), midfont, { 255, 255, 255, 255 }, "left", 500, 0, x, y, menu_state)
|
||||||
y = y + 60
|
y = y + 60
|
||||||
for idx, key in ipairs(bindingOrder) do
|
for idx, key in ipairs(bindingOrder) do
|
||||||
local binding = KEYMAP[player][key]
|
Label(bindingName[key], font, { 255, 255, 255, 255 }, "left", 190, 25, x, y, menu_state)
|
||||||
local l1 = Label(bindingName[key], font, { 255, 255, 255, 255 }, "left", 190, 25, x, y, menu_state)
|
for bindingIdx, binding in ipairs(KEYMAP[player][key]) do
|
||||||
local l2 = Label(binding, font, { 255, 255, 255, 255 }, "left", 50, 25, x + 200, y, menu_state)
|
local label = Label(binding, font, { 255, 255, 255, 255 }, "left", 50, 25, x + 200 + 20 * (bindingIdx - 1), y, menu_state)
|
||||||
local adjust = function()
|
label:onClick(function()
|
||||||
menu_state:adjustBindings(l1, l2, player, key)
|
menu_state:adjustBindings(label, bindingIdx, player, key)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
l1:onClick(adjust)
|
|
||||||
l2:onClick(adjust)
|
|
||||||
y = y + 30
|
y = y + 30
|
||||||
end
|
end
|
||||||
x = x + 400
|
x = x + 400
|
||||||
|
@ -55,19 +54,17 @@ local blinkColor = function(t)
|
||||||
return 255 * ((math.sin(math.pow((math.log(subseconds + 1) / math.log(2)), 2) * math.pi * 2) * 0.5 + 0.5));
|
return 255 * ((math.sin(math.pow((math.log(subseconds + 1) / math.log(2)), 2) * math.pi * 2) * 0.5 + 0.5));
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu_state:adjustBindings(name, binding, player, key)
|
function menu_state:adjustBindings(label, bindingIdx, player, key)
|
||||||
if currentlyChosen ~= nil then
|
if currentlyChosen ~= nil then
|
||||||
currentlyChosen:delete()
|
currentlyChosen:delete()
|
||||||
end
|
end
|
||||||
|
|
||||||
currentlyChosen = ValueController(function ()
|
currentlyChosen = ValueController(function ()
|
||||||
name.color[4] = blinkColor();
|
label.color[4] = blinkColor();
|
||||||
binding.color[4] = blinkColor();
|
|
||||||
end, menu_state)
|
end, menu_state)
|
||||||
currentlyChosen.data = { name = name, binding = binding, player = player, key = key, label = binding }
|
currentlyChosen.data = { bindingIdx = bindingIdx, player = player, key = key, label = label }
|
||||||
currentlyChosen.onDelete = function()
|
currentlyChosen.onDelete = function()
|
||||||
name.color[4] = 255;
|
label.color[4] = 255;
|
||||||
binding.color[4] = 255;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -125,7 +122,7 @@ function menu_state:keypressed(key, unicode)
|
||||||
currentlyChosen:delete()
|
currentlyChosen:delete()
|
||||||
currentlyChosen = nil
|
currentlyChosen = nil
|
||||||
else
|
else
|
||||||
KEYMAP[currentlyChosen.data.player][currentlyChosen.data.key] = key
|
KEYMAP[currentlyChosen.data.player][currentlyChosen.data.key][currentlyChosen.data.bindingIdx] = key
|
||||||
currentlyChosen.data.label.label = key
|
currentlyChosen.data.label.label = key
|
||||||
currentlyChosen:delete()
|
currentlyChosen:delete()
|
||||||
currentlyChosen = nil
|
currentlyChosen = nil
|
||||||
|
|
23
player.lua
23
player.lua
|
@ -51,30 +51,27 @@ Player = Class{
|
||||||
update = function(self, dt)
|
update = function(self, dt)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
press = function(self, key)
|
pressDown = function(self, key, down)
|
||||||
local found = false
|
local found = false
|
||||||
for action, keycode in pairs(self.keys) do
|
for action, bindings in pairs(self.keys) do
|
||||||
|
for idx, keycode in pairs(bindings) do
|
||||||
if key == keycode then
|
if key == keycode then
|
||||||
found = true
|
found = true
|
||||||
if self.actions[action] and self.plane then
|
if self.actions[action] and self.plane then
|
||||||
self.actions[action](true)
|
self.actions[action](down)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return found
|
return found
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
press = function(self, key)
|
||||||
|
return self:pressDown(key, true)
|
||||||
|
end;
|
||||||
|
|
||||||
release = function(self, key)
|
release = function(self, key)
|
||||||
local found = false
|
return self:pressDown(key, false)
|
||||||
for action, keycode in pairs(self.keys) do
|
|
||||||
if key == keycode then
|
|
||||||
found = true
|
|
||||||
if self.actions[action] and self.plane then
|
|
||||||
self.actions[action](false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return found
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
joystick = function(self, ...)
|
joystick = function(self, ...)
|
||||||
|
|
24
settings.lua
24
settings.lua
|
@ -13,21 +13,21 @@ HEIGHT = 768
|
||||||
|
|
||||||
KEYMAP = {
|
KEYMAP = {
|
||||||
[1] = {
|
[1] = {
|
||||||
ccw = 'k',
|
ccw = { 'k' },
|
||||||
cw = 'l',
|
cw = { 'l' },
|
||||||
flip = ',',
|
flip = { ',' },
|
||||||
shoot = 'o',
|
shoot = { 'o' },
|
||||||
accelerate = 'j',
|
accelerate = { 'j' },
|
||||||
decelerate = 'm'
|
decelerate = { 'm' }
|
||||||
},
|
},
|
||||||
|
|
||||||
[2] = {
|
[2] = {
|
||||||
ccw = 'a',
|
ccw = { 'a' },
|
||||||
cw = 's',
|
cw = { 's' },
|
||||||
flip = 'a',
|
flip = { 'a' },
|
||||||
shoot = 'w',
|
shoot = { 'w' },
|
||||||
accelerate = 'x',
|
accelerate = { 'x' },
|
||||||
decelerate = 'z'
|
decelerate = { 'z' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue