123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- --[========================================================================[--
- Key redefinition screen code for Thrust II Reloaded.
- Copyright © 2015 Pedro Gimeno Fortea
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- --]========================================================================]--
- local redef = {}
- local step
- function redef.activate()
- step = 1
- end
- local function xlate(s)
- return s == " " and "SPACE" or s:upper()
- end
- function redef.draw()
- lg.setColor(192, 192, 192, 255)
- main.centertext("DEFINE KEYS", main.ww/2, 56)
- lg.print("PRESS KEY FOR LEFT.....", 104, 112)
- if step >= 2 then
- lg.print(xlate(main.keys.left), 480, 112)
- lg.print("PRESS KEY FOR RIGHT....", 104, 160)
- end
- if step >= 3 then
- lg.print(xlate(main.keys.right), 480, 160)
- lg.print("PRESS KEY FOR THRUST...", 104, 208)
- end
- if step >= 4 then
- lg.print(xlate(main.keys.thrust), 480, 208)
- lg.print("PRESS KEY FOR PICKUP...", 104, 256)
- end
- if step >= 5 then
- lg.print(xlate(main.keys.pickup), 480, 256)
- lg.print("PRESS KEY FOR FIRE.....", 104, 304)
- end
- if step >= 6 then
- lg.print(xlate(main.keys.fire), 480, 304)
- lg.print("IS THIS CORRECT? (Y/N)", 128, 384)
- end
- lg.setColor(255, 255, 255)
- end
- function redef.keypressed(k, r)
- -- F10 reserved for save game, F3 for restore
- if k == "f10" or k == "f3" then return end
- if step == 1 then
- main.keys.left = k
- elseif step == 2 then
- main.keys.right = k
- elseif step == 3 then
- main.keys.thrust = k
- elseif step == 4 then
- main.keys.pickup = k
- elseif step == 5 then
- main.keys.fire = k
- end
- if step >= 1 and step <= 5 then
- step = step + 1
- end
- end
- function redef.textinput(c)
- if step == 6 then
- if c:lower() == "y" then
- -- save and return
- local s = main.keys.left .. "\n"
- .. main.keys.right .. "\n"
- .. main.keys.thrust .. "\n"
- .. main.keys.pickup .. "\n"
- .. main.keys.fire
- lfs.write("keys.txt", s, #s)
- main.activate(menu)
- elseif c:lower() == "n" then
- -- start again
- step = 1
- end
- end
- end
- return redef
|