components_config_LoginScene.bs

import "pkg:/source/utils/misc.bs"

sub init()
  m.top.setFocus(true)
  m.top.optionsAvailable = false

  m.list = m.top.findNode("configOptions")
  m.checkbox = m.top.findNode("onOff")
  m.buttons = m.top.findNode("buttons")
end sub

' JRScreen hook.
sub OnScreenShown()
  ' Clear backdrop on login screens
  m.global.sceneManager.callFunc("setBackgroundImage", "")

  scene = m.top.getScene()
  overhang = scene.findNode("overhang")
  if isValid(overhang)
    overhang.isLogoVisible = true
    overhang.currentUser = ""
  end if
end sub

function onKeyEvent(key as string, press as boolean) as boolean
  if not press then return false

  if key = "back"
    m.top.backPressed = true
  else if key = "down" and not isValid(m.checkbox.focusedChild) and not isValid(m.buttons.focusedChild)
    limit = m.list.content.getChildren(-1, 0).count() - 1

    if limit = m.list.itemFocused
      m.checkbox.setFocus(true)
      return true
    end if
  else if key = "down" and not isValid(m.buttons.focusedChild)
    m.buttons.callFunc("focus")
    return true
  else if key = "up" and isValid(m.buttons.focusedChild)
    m.checkbox.setFocus(true)
    return true
  else if key = "up" and isValid(m.checkbox.focusedChild)
    m.list.setFocus(true)
    return true
  end if

  return false
end function