[NEW] opcions_input.lua - Pantalla de definició de tecles per a teclat i pad - Modificat el abad per a que use controller
169 lines
4.9 KiB
Lua
169 lines
4.9 KiB
Lua
local input_type=controller.input.kb
|
|
local input_keys={}
|
|
local menu_opt = 0
|
|
|
|
function opcions_teclat_init()
|
|
input_type=controller.input.kb
|
|
-- definició de tecles a configurar en ordre
|
|
input_keys = controller.kb_keys
|
|
opcions_input_init()
|
|
end
|
|
|
|
function opcions_gamepad_init()
|
|
input_type=controller.input.pad
|
|
-- definició de botons a configurar en ordre
|
|
input_keys = controller.pad_keys
|
|
opcions_input_init()
|
|
end
|
|
|
|
function opcions_input_init()
|
|
surf.target(0)
|
|
surf.cls(16)
|
|
menu_opt = 1
|
|
flow:next()
|
|
end
|
|
|
|
function opcions_input_draw()
|
|
surf.target(0)
|
|
surf.cls(16)
|
|
local s=""
|
|
if input_type==controller.input.kb then
|
|
s="PULSA TECLA PER A "
|
|
if menu_opt==1 then
|
|
arc_textB(s.."AMUNT", 40, 48, 13)
|
|
elseif menu_opt==2 then
|
|
arc_textB(s.."AVALL", 40, 48, 13)
|
|
elseif menu_opt==3 then
|
|
arc_textB(s.."ESQUERRA", 28, 48, 13)
|
|
elseif menu_opt==4 then
|
|
arc_textB(s.."DRETA", 40, 48, 13)
|
|
elseif menu_opt==5 then
|
|
arc_textB(s.."BOTAR", 40, 48, 13)
|
|
elseif menu_opt==6 then
|
|
arc_textB(s.."DISPAR", 36, 48, 13)
|
|
end
|
|
elseif input_type==controller.input.pad then
|
|
s="PULSA BOTÓ PER A "
|
|
if menu_opt==1 then
|
|
arc_textB(s.."AMUNT", 44, 48, 13)
|
|
elseif menu_opt==2 then
|
|
arc_textB(s.."AVALL", 44, 48, 13)
|
|
elseif menu_opt==3 then
|
|
arc_textB(s.."ESQUERRA", 32, 48, 13)
|
|
elseif menu_opt==4 then
|
|
arc_textB(s.."DRETA", 44, 48, 13)
|
|
elseif menu_opt==5 then
|
|
arc_textB(s.."BOTAR", 44, 48, 13)
|
|
elseif menu_opt==6 then
|
|
arc_textB(s.."DISPAR", 40, 48, 13)
|
|
elseif menu_opt==7 then
|
|
arc_textB(s.."GPS ARRERE", 28, 48, 13)
|
|
elseif menu_opt==8 then
|
|
arc_textB(s.."GPS AVANT", 28, 48, 13)
|
|
elseif menu_opt==9 then
|
|
arc_textB(s.."PAUSA", 44, 48, 13)
|
|
end
|
|
end
|
|
end
|
|
|
|
function opcions_input_update()
|
|
local curr_key = input_keys[menu_opt]
|
|
|
|
if key.press(key.ESCAPE) then
|
|
flow:next()
|
|
return
|
|
end
|
|
|
|
if input_type==controller.input.kb then
|
|
local k = key.press()
|
|
if k ~= 0 and k~=key.ESCAPE then
|
|
print(k..", "..curr_key.name..", "..curr_key.code)
|
|
config_key(curr_key, k)
|
|
menu_opt = menu_opt+1
|
|
end
|
|
elseif input_type==controller.input.pad then
|
|
local btn = pad.press();
|
|
if btn ~= -1 then
|
|
config_key(curr_key, btn)
|
|
menu_opt = menu_opt+1
|
|
end
|
|
end
|
|
|
|
if menu_opt >#input_keys then menu_opt=1 end
|
|
end
|
|
|
|
function opcions_input_show()
|
|
opcions_input_draw()
|
|
opcions_input_update()
|
|
end
|
|
|
|
function opcions_input_end()
|
|
menu_opt = 0
|
|
-- menu_state = update_options_menu;
|
|
flow:finish()
|
|
end
|
|
|
|
function config_key(def_key, k)
|
|
local end_setup=false
|
|
local valid_key = true
|
|
-- if input_type==controller.input.kb then
|
|
-- if def_key.name=="up" then
|
|
-- keyUp=k
|
|
-- elseif def_key.name=="down" then
|
|
-- keyDown=k
|
|
-- elseif def_key.name=="left" then
|
|
-- keyLeft=k
|
|
-- elseif def_key.name=="right" then
|
|
-- keyRight=k
|
|
-- elseif def_key.name=="jump" then
|
|
-- keyJump=k
|
|
-- elseif def_key.name=="shoot" then
|
|
-- keyShoot=k
|
|
-- end_setup = true
|
|
-- else
|
|
-- valid_key = false
|
|
-- end
|
|
-- elseif input_type==controller.input.pad then
|
|
-- if def_key.name=="up" then
|
|
-- btnUp=k
|
|
-- elseif def_key.name=="down" then
|
|
-- btnDown=k
|
|
-- elseif def_key.name=="left" then
|
|
-- btnLeft=k
|
|
-- elseif def_key.name=="right" then
|
|
-- btnRight=k
|
|
-- elseif def_key.name=="jump" then
|
|
-- btnJump=k
|
|
-- elseif def_key.name=="shoot" then
|
|
-- btnShoot=k
|
|
-- elseif def_key.name=="next" then
|
|
-- btnCycle1=k
|
|
-- elseif def_key.name=="prev" then
|
|
-- btnCycle2=k
|
|
-- elseif def_key.name=="pause" then
|
|
-- btnPause=k
|
|
-- end_setup = true
|
|
-- else
|
|
-- valid_key = false
|
|
-- end
|
|
-- end
|
|
|
|
if (input_type==controller.input.kb and def_key.name=="shoot")
|
|
or (input_type==controller.input.pad and def_key.name=="pause") then
|
|
end_setup = true
|
|
end
|
|
|
|
if not controller:define(def_key.code, k) then valid_key=false end
|
|
|
|
if valid_key then
|
|
print("DEFINED > "..def_key.name..", "..def_key.code.." = "..k)
|
|
config.key(def_key.code, k)
|
|
else
|
|
print("ERROR AL DEFINIR")
|
|
end
|
|
|
|
if end_setup then flow:next() end
|
|
end
|
|
|
|
flow:registrar("opcions_teclat", { opcions_teclat_init, opcions_input_show, opcions_input_end } )
|
|
flow:registrar("opcions_gamepad", { opcions_gamepad_init, opcions_input_show, opcions_input_end } ) |