mirror of
https://gitlab.com/Oreolek/salet-gamepad-module.git
synced 2024-07-02 23:05:03 +03:00
Scroll through all the links with tabindex
This commit is contained in:
parent
fd817756f3
commit
d304c3e96e
|
@ -1,38 +1,76 @@
|
||||||
# Select the previous choice
|
# Select the previous choice
|
||||||
selectUp = (event, button) ->
|
salet.view.selectUp = (event, button, padid) ->
|
||||||
if button != "dpad up" and button != "left stick up"
|
if button != "dpad up" and button != "left stick up"
|
||||||
return
|
return
|
||||||
if $(".options li").length == 0
|
if $(".options li").length == 0
|
||||||
return
|
return selectUpLink(event, button, padid)
|
||||||
$(".options li").removeClass("active")
|
$(".options li").removeClass("active")
|
||||||
count = $(".options li").length
|
count = $(".options li").length
|
||||||
window.selectedoption--
|
window.selectedoption--
|
||||||
if window.selectedoption <= 0
|
if window.selectedoption <= 0
|
||||||
window.selectedoption = count
|
window.selectedoption = count
|
||||||
console.log window.selectedoption
|
|
||||||
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
|
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
|
||||||
|
|
||||||
# Select the next choice
|
# Select the next choice
|
||||||
selectDown = (event, button) ->
|
salet.view.selectDown = (event, button, padid) ->
|
||||||
if button != "dpad down" and button != "left stick down"
|
if button != "dpad down" and button != "left stick down"
|
||||||
return
|
return
|
||||||
if $(".options li").length == 0
|
if $(".options li").length == 0
|
||||||
return
|
return selectDownLink(event, button, padid)
|
||||||
$(".options li").removeClass("active")
|
$(".options li").removeClass("active")
|
||||||
window.selectedoption++
|
window.selectedoption++
|
||||||
count = $(".options li").length
|
count = $(".options li").length
|
||||||
if window.selectedoption > count
|
if window.selectedoption > count
|
||||||
window.selectedoption = 1
|
window.selectedoption = 1
|
||||||
console.log window.selectedoption
|
|
||||||
$(".options li:nth-child(#{window.selectedoption})").addClass("active")
|
$(".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) ->
|
selectOption = (event, button) ->
|
||||||
if button != "a"
|
if button != "a"
|
||||||
return
|
return
|
||||||
$(".options li.active").click()
|
$(".options li.active").click()
|
||||||
|
|
||||||
# enter the options room
|
# enter the options room
|
||||||
enterOptions = (event, button) ->
|
enterOptions = (event, button, padid) ->
|
||||||
if button != "back" and button != "start"
|
if button != "back" and button != "start"
|
||||||
return
|
return
|
||||||
if button == "start"
|
if button == "start"
|
||||||
|
@ -48,7 +86,15 @@ joystick = () ->
|
||||||
temp = new Gamepad(pad)
|
temp = new Gamepad(pad)
|
||||||
if temp.pressed?
|
if temp.pressed?
|
||||||
if salet.view.gamepads[pad.id].pressed != 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
|
salet.view.gamepads[pad.id] = temp
|
||||||
|
|
||||||
$(document).on("viewinit", () ->
|
$(document).on("viewinit", () ->
|
||||||
|
@ -65,7 +111,7 @@ $(document).on("viewinit", () ->
|
||||||
)
|
)
|
||||||
|
|
||||||
window.selectedoption ?= 1
|
window.selectedoption ?= 1
|
||||||
$(document).on("press", selectUp)
|
$(document).on("press", salet.view.selectUp)
|
||||||
$(document).on("press", selectDown)
|
$(document).on("press", salet.view.selectDown)
|
||||||
$(document).on("press", selectOption)
|
$(document).on("press", selectOption)
|
||||||
$(document).on("press", enterOptions)
|
$(document).on("press", enterOptions)
|
||||||
|
|
Loading…
Reference in a new issue