jf-roku/components/settings/settings.brs

201 lines
6.2 KiB
Plaintext
Raw Normal View History

2022-05-01 10:51:28 +00:00
sub init()
m.top.overhangTitle = tr("Settings")
m.top.optionsAvailable = false
m.userLocation = []
m.settingsMenu = m.top.findNode("settingsMenu")
m.settingDetail = m.top.findNode("settingDetail")
m.settingDesc = m.top.findNode("settingDesc")
m.settingTitle = m.top.findNode("settingTitle")
m.path = m.top.findNode("path")
m.boolSetting = m.top.findNode("boolSetting")
2022-09-04 11:22:08 +00:00
m.integerSetting = m.top.findNode("integerSetting")
2022-12-20 02:03:35 +00:00
m.radioSetting = m.top.findNode("radioSetting")
2022-09-04 11:22:08 +00:00
m.integerSetting.observeField("submit", "onKeyGridSubmit")
m.integerSetting.observeField("escape", "onKeyGridEscape")
2022-05-01 10:51:28 +00:00
m.settingsMenu.setFocus(true)
m.settingsMenu.observeField("itemFocused", "settingFocused")
m.settingsMenu.observeField("itemSelected", "settingSelected")
m.boolSetting.observeField("checkedItem", "boolSettingChanged")
2022-12-20 02:03:35 +00:00
m.radioSetting.observeField("checkedItem", "radioSettingChanged")
2022-05-01 10:51:28 +00:00
' Load Configuration Tree
m.configTree = GetConfigTree()
LoadMenu({ children: m.configTree })
end sub
2022-09-04 11:22:08 +00:00
sub onKeyGridSubmit()
selectedSetting = m.userLocation.peek().children[m.settingsMenu.itemFocused]
set_user_setting(selectedSetting.settingName, m.integerSetting.text)
m.settingsMenu.setFocus(true)
end sub
sub onKeyGridEscape()
if m.integerSetting.escape = "left" or m.integerSetting.escape = "back"
m.settingsMenu.setFocus(true)
end if
end sub
2022-05-01 10:51:28 +00:00
sub LoadMenu(configSection)
if configSection.children = invalid
' Load parent menu
m.userLocation.pop()
configSection = m.userLocation.peek()
else
if m.userLocation.Count() > 0 then m.userLocation.peek().selectedIndex = m.settingsMenu.itemFocused
m.userLocation.push(configSection)
end if
result = CreateObject("roSGNode", "ContentNode")
for each item in configSection.children
listItem = result.CreateChild("ContentNode")
listItem.title = tr(item.title)
listItem.Description = tr(item.description)
listItem.id = item.id
end for
m.settingsMenu.content = result
if configSection.selectedIndex <> invalid and configSection.selectedIndex > -1
m.settingsMenu.jumpToItem = configSection.selectedIndex
end if
' Set Path display
m.path.text = ""
for each level in m.userLocation
if level.title <> invalid then m.path.text += " / " + tr(level.title)
end for
end sub
sub settingFocused()
selectedSetting = m.userLocation.peek().children[m.settingsMenu.itemFocused]
m.settingDesc.text = tr(selectedSetting.Description)
m.settingTitle.text = tr(selectedSetting.Title)
' Hide Settings
m.boolSetting.visible = false
2022-09-04 11:22:08 +00:00
m.integerSetting.visible = false
2022-12-20 02:03:35 +00:00
m.radioSetting.visible = false
2022-05-01 10:51:28 +00:00
if selectedSetting.type = invalid
return
else if selectedSetting.type = "bool"
m.boolSetting.visible = true
if get_user_setting(selectedSetting.settingName) = "true"
m.boolSetting.checkedItem = 1
else
m.boolSetting.checkedItem = 0
end if
2022-09-04 11:22:08 +00:00
else if selectedSetting.type = "integer"
integerValue = get_user_setting(selectedSetting.settingName, selectedSetting.default)
if isValid(integerValue)
m.integerSetting.text = integerValue
end if
m.integerSetting.visible = true
2022-12-20 02:03:35 +00:00
else if LCase(selectedSetting.type) = "radio"
selectedValue = get_user_setting(selectedSetting.settingName, selectedSetting.default)
radioContent = CreateObject("roSGNode", "ContentNode")
itemIndex = 0
for each item in m.userLocation.peek().children[m.settingsMenu.itemFocused].options
listItem = radioContent.CreateChild("ContentNode")
listItem.title = tr(item.title)
listItem.id = item.id
if selectedValue = item.id
m.radioSetting.checkedItem = itemIndex
end if
itemIndex++
end for
m.radioSetting.content = radioContent
m.radioSetting.visible = true
2022-05-01 10:51:28 +00:00
else
print "Unknown setting type " + selectedSetting.type
end if
end sub
sub settingSelected()
selectedItem = m.userLocation.peek().children[m.settingsMenu.itemFocused]
if selectedItem.type <> invalid ' Show setting
if selectedItem.type = "bool"
m.boolSetting.setFocus(true)
end if
2022-09-04 11:22:08 +00:00
if selectedItem.type = "integer"
m.integerSetting.setFocus(true)
end if
2022-12-20 02:03:35 +00:00
if (selectedItem.type) = "radio"
m.radioSetting.setFocus(true)
end if
2022-05-01 10:51:28 +00:00
else if selectedItem.children <> invalid and selectedItem.children.Count() > 0 ' Show sub menu
LoadMenu(selectedItem)
m.settingsMenu.setFocus(true)
else
return
end if
m.settingDesc.text = m.settingsMenu.content.GetChild(m.settingsMenu.itemFocused).Description
end sub
sub boolSettingChanged()
if m.boolSetting.focusedChild = invalid then return
selectedSetting = m.userLocation.peek().children[m.settingsMenu.itemFocused]
if m.boolSetting.checkedItem
set_user_setting(selectedSetting.settingName, "true")
else
set_user_setting(selectedSetting.settingName, "false")
end if
end sub
2022-12-20 02:03:35 +00:00
sub radioSettingChanged()
if m.radioSetting.focusedChild = invalid then return
selectedSetting = m.userLocation.peek().children[m.settingsMenu.itemFocused]
set_user_setting(selectedSetting.settingName, m.radioSetting.content.getChild(m.radioSetting.checkedItem).id)
end sub
2022-05-01 10:51:28 +00:00
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
if (key = "back" or key = "left") and m.settingsMenu.focusedChild <> invalid and m.userLocation.Count() > 1
LoadMenu({})
return true
else if (key = "back" or key = "left") and m.settingDetail.focusedChild <> invalid
m.settingsMenu.setFocus(true)
return true
2022-12-20 02:03:35 +00:00
else if (key = "back" or key = "left") and m.radioSetting.hasFocus()
m.settingsMenu.setFocus(true)
return true
2022-05-01 10:51:28 +00:00
end if
if key = "options"
m.global.sceneManager.callFunc("popScene")
2023-02-02 00:03:12 +00:00
return true
end if
2022-05-01 10:51:28 +00:00
if key = "right"
settingSelected()
end if
return false
2022-05-30 12:57:40 +00:00
end function