2023-10-03 16:11:25 +00:00
|
|
|
import "pkg:/source/utils/misc.bs"
|
2023-05-03 21:21:04 +00:00
|
|
|
|
2023-02-25 16:43:36 +00:00
|
|
|
sub init()
|
2023-05-09 12:21:20 +00:00
|
|
|
m.contentArea = m.top.findNode("contentArea")
|
|
|
|
m.radioOptions = m.top.findNode("radioOptions")
|
2023-05-11 01:47:54 +00:00
|
|
|
m.scrollBarColumn = []
|
2023-02-25 16:43:36 +00:00
|
|
|
|
2023-05-09 12:21:20 +00:00
|
|
|
m.top.observeField("contentData", "onContentDataChanged")
|
2023-02-25 16:43:36 +00:00
|
|
|
m.top.observeFieldScoped("buttonSelected", "onButtonSelected")
|
|
|
|
|
2023-05-09 12:21:20 +00:00
|
|
|
m.radioOptions.observeField("focusedChild", "onItemFocused")
|
|
|
|
|
2023-02-25 16:43:36 +00:00
|
|
|
m.top.id = "OKDialog"
|
|
|
|
m.top.height = 900
|
|
|
|
end sub
|
|
|
|
|
2023-05-09 12:21:20 +00:00
|
|
|
' Event handler for when user selected a button
|
2023-02-25 16:43:36 +00:00
|
|
|
sub onButtonSelected()
|
|
|
|
if m.top.buttonSelected = 0
|
2023-05-09 12:21:20 +00:00
|
|
|
m.global.sceneManager.returnData = m.top.contentData.data[m.radioOptions.selectedIndex]
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' Event handler for when user's cursor highlights an option in the option list
|
|
|
|
sub onItemFocused()
|
|
|
|
focusedChild = m.radioOptions.focusedChild
|
|
|
|
if not isValid(focusedChild) then return
|
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
moveScrollBar()
|
2023-05-09 12:21:20 +00:00
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
' If the option list is scrollable, move the option list to the user's section
|
|
|
|
if m.scrollBarColumn.count() <> 0
|
2023-05-09 12:21:20 +00:00
|
|
|
hightedButtonTranslation = m.radioOptions.focusedChild.translation
|
|
|
|
m.radioOptions.translation = [m.radioOptions.translation[0], -1 * hightedButtonTranslation[1]]
|
|
|
|
end if
|
|
|
|
|
|
|
|
end sub
|
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
' Move the popup's scroll bar
|
|
|
|
sub moveScrollBar()
|
|
|
|
' If we haven't found the scrollbar column node yet, try to find it now
|
|
|
|
if m.scrollBarColumn.count() = 0
|
|
|
|
scrollBar = findNodeBySubtype(m.contentArea, "StdDlgScrollbar")
|
|
|
|
if scrollBar.count() = 0 or not isValid(scrollBar[0]) or not isValid(scrollBar[0].node)
|
2023-05-09 12:21:20 +00:00
|
|
|
return
|
|
|
|
end if
|
2023-05-11 01:47:54 +00:00
|
|
|
|
|
|
|
m.scrollBarColumn = findNodeBySubtype(scrollBar[0].node, "Poster")
|
|
|
|
if m.scrollBarColumn.count() = 0 or not isValid(m.scrollBarColumn[0]) or not isValid(m.scrollBarColumn[0].node)
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2023-05-11 12:37:07 +00:00
|
|
|
m.scrollBarThumb = findNodeBySubtype(m.scrollBarColumn[0].node, "Poster")
|
|
|
|
if m.scrollBarThumb.count() = 0 or not isValid(m.scrollBarThumb[0]) or not isValid(m.scrollBarThumb[0].node)
|
2023-05-11 01:47:54 +00:00
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2023-05-11 12:37:07 +00:00
|
|
|
m.scrollBarThumb[0].node.blendColor = "#444444"
|
|
|
|
' If the user presses left then right, it's possible for us to lose focus. Ensure focus stays on the option list.
|
|
|
|
scrollBar[0].node.observeField("focusedChild", "onScrollBarFocus")
|
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
' Hide the default scrollbar background
|
|
|
|
m.scrollBarColumn[0].node.uri = ""
|
|
|
|
|
|
|
|
' Create a new scrollbar background so we can move the original nodes freely
|
|
|
|
scrollbarBackground = createObject("roSGNode", "Rectangle")
|
|
|
|
scrollbarBackground.color = "#101010"
|
|
|
|
scrollbarBackground.opacity = "0.3"
|
|
|
|
scrollbarBackground.width = "30"
|
|
|
|
scrollbarBackground.height = m.contentArea.clippingRect.height
|
|
|
|
scrollbarBackground.translation = [0, 0]
|
|
|
|
scrollBar[0].node.insertChild(scrollbarBackground, 0)
|
|
|
|
|
|
|
|
' Determine the proper scroll amount for the scrollbar
|
2023-05-11 12:37:07 +00:00
|
|
|
m.scrollAmount = (m.contentArea.clippingRect.height - int(m.scrollBarThumb[0].node.height)) / m.radioOptions.getChildCount()
|
2023-05-11 01:47:54 +00:00
|
|
|
m.scrollAmount += m.scrollAmount / m.radioOptions.getChildCount()
|
2023-05-09 12:21:20 +00:00
|
|
|
end if
|
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
if not isvalid(m.radioOptions.focusedChild.id) then return
|
2023-05-09 12:21:20 +00:00
|
|
|
|
2023-05-11 01:47:54 +00:00
|
|
|
m.scrollBarColumn[0].node.translation = [0, val(m.radioOptions.focusedChild.id) * m.scrollAmount]
|
2023-05-09 12:21:20 +00:00
|
|
|
end sub
|
|
|
|
|
2023-05-11 12:37:07 +00:00
|
|
|
' If somehow the scrollbar gains focus, set focus back to the option list
|
|
|
|
sub onScrollBarFocus()
|
|
|
|
m.radioOptions.setFocus(true)
|
|
|
|
|
|
|
|
' Ensure scrollbar styles remain in an unfocused state
|
|
|
|
m.scrollBarThumb[0].node.blendColor = "#353535"
|
|
|
|
end sub
|
|
|
|
|
2023-05-09 12:21:20 +00:00
|
|
|
' Once user selected an item, move cursor down to OK button
|
|
|
|
sub onItemSelected()
|
|
|
|
buttonArea = findNodeBySubtype(m.top, "StdDlgButtonArea")
|
|
|
|
|
|
|
|
if buttonArea.count() <> 0 and isValid(buttonArea[0]) and isValid(buttonArea[0].node)
|
|
|
|
buttonArea[0].node.setFocus(true)
|
2023-02-25 16:43:36 +00:00
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub onContentDataChanged()
|
|
|
|
i = 0
|
|
|
|
for each item in m.top.contentData.data
|
2023-05-09 12:21:20 +00:00
|
|
|
cardItem = m.radioOptions.CreateChild("StdDlgActionCardItem")
|
2023-02-25 16:43:36 +00:00
|
|
|
cardItem.iconType = "radiobutton"
|
2023-05-09 12:21:20 +00:00
|
|
|
cardItem.id = i
|
2023-02-25 16:43:36 +00:00
|
|
|
|
|
|
|
if isValid(item.selected)
|
2023-05-09 12:21:20 +00:00
|
|
|
m.radioOptions.selectedIndex = i
|
2023-02-25 16:43:36 +00:00
|
|
|
end if
|
|
|
|
|
2023-11-20 20:55:15 +00:00
|
|
|
textLine = cardItem.CreateChild("ScrollingLabel")
|
|
|
|
textLine.maxWidth = "750"
|
2023-05-07 01:26:02 +00:00
|
|
|
textLine.text = item.track.description
|
2023-05-09 12:21:20 +00:00
|
|
|
cardItem.observeField("selected", "onItemSelected")
|
2023-02-25 16:43:36 +00:00
|
|
|
i++
|
|
|
|
end for
|
|
|
|
end sub
|
2023-05-09 12:21:20 +00:00
|
|
|
|
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
2023-05-11 12:37:07 +00:00
|
|
|
if key = "right"
|
|
|
|
' By default RIGHT from the option list selects the OK button
|
2023-05-11 12:37:56 +00:00
|
|
|
' Instead, keep the user on the option list
|
2023-05-11 12:37:07 +00:00
|
|
|
return true
|
|
|
|
end if
|
|
|
|
|
2023-05-09 12:21:20 +00:00
|
|
|
if not press then return false
|
|
|
|
|
|
|
|
if key = "up"
|
|
|
|
' By default UP from the OK button is the scrollbar
|
|
|
|
' Instead, move the user to the option list
|
|
|
|
if not m.radioOptions.isinFocusChain()
|
|
|
|
m.radioOptions.setFocus(true)
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
return false
|
|
|
|
end function
|