components_options_OptionsSlider.bs

sub init()
  m.top.visible = false

  m.sliderGroup = m.top.findNode("sliderGroup")
  m.slideInAnim = m.top.findNode("slideInAnim")
  m.slideInInterp = m.top.findNode("slideInInterp")
  m.panelOverlay = m.top.getScene().findNode("optionsPanelOverlay")

  constants = m.global.constants
  m.top.findNode("backdrop").color = constants.colorBlack + constants.alpha90

  m.top.observeField("visible", "onVisibleChanged")
end sub

sub onVisibleChanged()
  if m.top.visible
    ' Reparent to overlay container (after overhang in JRScene) for correct z-order
    m.originalParent = m.top.getParent()
    m.panelOverlay.appendChild(m.top)
    ' Animate slide-in from left
    m.slideInInterp.keyValue = [[-700, 0], [0, 0]]
    m.slideInAnim.control = "start"
  else
    ' Reset position to off-screen for next open
    m.slideInAnim.control = "stop"
    m.sliderGroup.translation = [-700, 0]
    ' Reparent back to original screen
    if m.originalParent <> invalid
      m.originalParent.appendChild(m.top)
      m.originalParent = invalid
    end if
  end if
end sub

sub setFields()
  options = m.top.options
  buttons = m.top.buttons
  row = m.top.findNode("fieldList")
  if row = invalid then return

  row.clear()
  row.appendChildren(options)
  row.appendChildren(buttons)
end sub

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

  if key = "options" or key = "back"
    m.top.visible = false
    m.top.closeSidePanel = true
    return true
  else if key = "OK"
    list = m.top.findNode("panelList")
    data = list.content.getChild(list.itemFocused)
    data.optionSelected = true
    return true
  end if

  return false
end function