Browse Source

Scroll through all the links with tabindex

master
Alexander Yakovlev 5 years ago
parent
commit
d304c3e96e
  1. 66
      src/init.coffee

66
src/init.coffee

@ -1,38 +1,76 @@
# Select the previous choice
selectUp = (event, button) ->
salet.view.selectUp = (event, button, padid) ->
if button != "dpad up" and button != "left stick up"
return
if $(".options li").length == 0
return
return selectUpLink(event, button, padid)
$(".options li").removeClass("active")
count = $(".options li").length
window.selectedoption--
if window.selectedoption <= 0
window.selectedoption = count
console.log window.selectedoption
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
# Select the next choice
selectDown = (event, button) ->
salet.view.selectDown = (event, button, padid) ->
if button != "dpad down" and button != "left stick down"
return
if $(".options li").length == 0
return
return selectDownLink(event, button, padid)
$(".options li").removeClass("active")
window.selectedoption++
count = $(".options li").length
if window.selectedoption > count
window.selectedoption = 1
console.log window.selectedoption
$(".options li:nth-child(#{window.selectedoption})").addClass("active")
# Select the next link inside room text
selectDownLink = (event, button, padid) ->
tabid = $("#current-room .active").first().attr("tabindex")
$("#current-room .active").removeClass("active")
maxtab = 0
for element in $("#current-room [tabindex]")
if maxtab < $(element).attr("tabindex")
maxtab = $(element).attr("tabindex")
tabid = salet.view.increaseTabindex(tabid, maxtab)
$("#current-room [tabindex='#{tabid}']").addClass("active")
# Select the previous link inside room text
selectUpLink = (event, button, padid) ->
tabid = $("#current-room .active").attr("tabindex")
$("#current-room .active").removeClass("active")
tabid = salet.view.decreaseTabindex(tabid)
$("#current-room [tabindex='#{tabid}']").addClass("active")
salet.view.decreaseTabindex = (tabid) ->
tabid--
if tabid < 0
# tabindex can't be negative, choosing maximum tabindex
maxtab = 0
for element in $("#current-room [tabindex]")
if maxtab < $(element).attr("tabindex")
maxtab = $(element).attr("tabindex")
tabid = maxtab
if $("#current-room [tabindex='#{tabid}']").length == 0
return salet.view.decreaseTabindex(tabid)
return tabid
salet.view.increaseTabindex = (tabid, maxtab) ->
if tabid < maxtab
tabid++
else
tabid = 0
if $("#current-room [tabindex='#{tabid}']").length == 0
return salet.view.increaseTabindex(tabid)
return tabid
selectOption = (event, button) ->
if button != "a"
return
$(".options li.active").click()
# enter the options room
enterOptions = (event, button) ->
enterOptions = (event, button, padid) ->
if button != "back" and button != "start"
return
if button == "start"
@ -48,7 +86,15 @@ joystick = () ->
temp = new Gamepad(pad)
if temp.pressed?
if salet.view.gamepads[pad.id].pressed != temp.pressed
$(document).trigger("press", temp.pressed)
$(document).trigger("press", temp.pressed, pad.id)
if temp.map.axes?
for axis, axisname in temp.map.axes
oldval = salet.view.gamepads[pad.id].gamepad.axes[axis.index]
newval = temp.gamepad.axes[axis.index]
if Math.abs(newval) <= 0.2
newval = 0
if newval != oldval
$(document).trigger("axis", axisname, newval, padid)
salet.view.gamepads[pad.id] = temp
$(document).on("viewinit", () ->
@ -65,7 +111,7 @@ $(document).on("viewinit", () ->
)
window.selectedoption ?= 1
$(document).on("press", selectUp)
$(document).on("press", selectDown)
$(document).on("press", salet.view.selectUp)
$(document).on("press", salet.view.selectDown)
$(document).on("press", selectOption)
$(document).on("press", enterOptions)

Loading…
Cancel
Save