From 7291b4e412627ab8ce55332a66332c85ff41683f Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Sat, 8 Aug 2020 21:43:37 +0100 Subject: [PATCH] WIP for Itemgrid Options --- components/ButtonGroupHoriz.brs | 2 +- components/Buttons/JFButtons.brs | 112 ++++++++++++++++++++++++ components/Buttons/JFButtons.xml | 32 +++++++ components/Buttons/TextSizeTask.brs | 21 +++++ components/Buttons/TextSizeTask.xml | 16 ++++ components/ItemGrid2/ItemGrid2.brs | 26 +++++- components/ItemGrid2/ItemGrid2.xml | 2 +- components/ItemGrid2/LoadItemsTask2.brs | 3 +- components/JFScene.brs | 2 +- components/options/OptionsScreen.brs | 87 ++++++++++++++++++ components/options/OptionsScreen.xml | 69 +++++++++++++++ images/backgroundmask.png | Bin 0 -> 829725 bytes images/button_bg_focus.9.png | Bin 0 -> 15881 bytes images/button_bg_focus_t.9.png | Bin 0 -> 20077 bytes images/button_bg_off.9.png | Bin 0 -> 2087 bytes images/dialog.9.png | Bin 329 -> 1946 bytes images/icons/down_black.png | Bin 0 -> 198 bytes images/icons/down_white.png | Bin 0 -> 196 bytes images/icons/up_black.png | Bin 0 -> 212 bytes images/icons/up_white.png | Bin 0 -> 223 bytes images/option-menu-bg.9.png | Bin 0 -> 1957 bytes 21 files changed, 367 insertions(+), 5 deletions(-) create mode 100644 components/Buttons/JFButtons.brs create mode 100644 components/Buttons/JFButtons.xml create mode 100644 components/Buttons/TextSizeTask.brs create mode 100644 components/Buttons/TextSizeTask.xml create mode 100644 components/options/OptionsScreen.brs create mode 100644 components/options/OptionsScreen.xml create mode 100644 images/backgroundmask.png create mode 100644 images/button_bg_focus.9.png create mode 100644 images/button_bg_focus_t.9.png create mode 100644 images/button_bg_off.9.png create mode 100644 images/icons/down_black.png create mode 100644 images/icons/down_white.png create mode 100644 images/icons/up_black.png create mode 100644 images/icons/up_white.png create mode 100644 images/option-menu-bg.9.png diff --git a/components/ButtonGroupHoriz.brs b/components/ButtonGroupHoriz.brs index 4c4a41b2..65291580 100644 --- a/components/ButtonGroupHoriz.brs +++ b/components/ButtonGroupHoriz.brs @@ -18,7 +18,7 @@ function onKeyEvent(key as string, press as boolean) as boolean return true else if key = "up" or key = "down" m.top.escape = true - return true + return false end if return false diff --git a/components/Buttons/JFButtons.brs b/components/Buttons/JFButtons.brs new file mode 100644 index 00000000..83ff3c1f --- /dev/null +++ b/components/Buttons/JFButtons.brs @@ -0,0 +1,112 @@ +sub init() + + m.top.focusable = true + + + + m.menubg = m.top.findNode("menubg") + + m.focusRing = m.top.findNode("focus") + m.buttonGroup = m.top.findNode("buttonGroup") + m.focusAnim = m.top.findNode("moveFocusAnimation") + m.focusAnimTranslation = m.top.findNode("focusLocation") + m.focusAnimWidth = m.top.findNode("focusWidth") + m.focusAnimHeight = m.top.findNode("focusHeight") + + m.buttonCount = 0 + m.selectedFocusedIndex = 1 + + m.textSizeTask = createObject("roSGNode", "TextSizeTask") + + m.top.observeField("focusedChild", "focusChanged") + m.top.enableRenderTracking = true + m.top.observeField("renderTracking", "renderChanged") + +end sub + +' +' When options are fully displayed, set focus and selected option +sub renderChanged() + if m.top.renderTracking = "full" then + highlightSelected(m.selectedFocusedIndex, false) + m.top.setfocus(true) + end if +end sub + + +sub updateButtons() + m.textSizeTask.fontsize = 40 + m.textSizeTask.text= m.top.buttons + m.textSizeTask.name = m.buttonCount + m.textSizeTask.observeField("width", "showButtons") + m.textSizeTask.control = "RUN" +end sub + +sub showButtons() + + totalWidth = 110 ' track for menu background width - start with side padding + + for i = 0 to m.top.buttons.count() - 1 + m.buttonCount = m.buttonCount + 1 + l = m.buttonGroup.createChild("Label") + l.text = m.top.buttons[i] + l.font.size = 40 + l.translation=[0,10] + l.height = m.textSizeTask.height + l.width = m.textSizeTask.width[i] + 50 + l.horizAlign = "center" + l.vertAlign="center" + totalWidth = totalWidth + l.width + 45 + end for + + m.menubg.width = totalWidth + m.menubg.height = m.textSizeTask.height + 40 + +end sub + +' Highlight selected menu option +sub highlightSelected(index as integer, animate = true) + + val = m.buttonGroup.getChild(index) + rect = val.ancestorBoundingRect(m.top) + + if animate = true then + m.focusAnimTranslation.keyValue = [m.focusRing.translation, [rect.x - 25, rect.y - 30]] + m.focusAnimWidth.keyValue = [m.focusRing.width, val.width + 50] + m.focusAnimHeight.keyValue = [m.focusRing.height, val.height + 60] + m.focusAnim.control = "start" + else + m.focusRing.translation = [rect.x - 25, rect.y - 30] + m.focusRing.width = val.width + 50 + m.focusRing.height = val.height + 60 + end if + +end sub + +' Change opacity of the highlighted menu item based on focus +sub focusChanged() + if m.top.isInFocusChain() then + m.focusRing.opacity = 1 + else + m.focusRing.opacity = 0.6 + end if +end sub + + +function onKeyEvent(key as string, press as boolean) as boolean + + if not press then return false + + if key = "left" + if(m.selectedFocusedIndex > 0) m.selectedFocusedIndex = m.selectedFocusedIndex - 1 + highlightSelected(m.selectedFocusedIndex) + m.top.focusedIndex = m.selectedFocusedIndex + return true + else if key = "right" + if(m.selectedFocusedIndex < m.buttonCount - 1) m.selectedFocusedIndex = m.selectedFocusedIndex + 1 + highlightSelected(m.selectedFocusedIndex) + m.top.focusedIndex = m.selectedFocusedIndex + return true + end if + return false +end function diff --git a/components/Buttons/JFButtons.xml b/components/Buttons/JFButtons.xml new file mode 100644 index 00000000..30b0f36a --- /dev/null +++ b/components/Buttons/JFButtons.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +