components_JRScene.bs

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

sub init()
  m.top.backgroundColor = m.global.constants.colors.background_primary
  m.top.backgroundURI = ""
  m.spinner = m.top.findNode("spinner")
end sub

' Triggered when the isLoading boolean component field is changed
sub isLoadingChanged()
  ' toggle visibility of active view/group
  group = m.global.sceneManager.callFunc("getActiveScene")
  if isValid(group)
    group.visible = not m.top.isLoading
  end if

  ' toggle visibility of loading spinner
  m.spinner.visible = m.top.isLoading
end sub

function onKeyEvent(key as string, press as boolean) as boolean
  if not press then return false
  if m.top.disableRemote then return true

  if key = "back"
    m.global.sceneManager.callFunc("popScene")
    return true
  else if key = "options"
    group = m.global.sceneManager.callFunc("getActiveScene")
    if isValid(group) and isValid(group.optionsAvailable) and group.optionsAvailable
      group.lastFocus = group.focusedChild
      panel = group.findNode("options")
      panel.visible = true
      panel.findNode("panelList").setFocus(true)
    end if
    return true
  end if

  return false
end function