Roku:如何在新屏幕上打开 LabelList?

Roku: How do I open a LabelList on a new screen?

BrightScript,如何在新屏幕上打开以下 LabelList(不是 Main screen/scene)?

<?xml version = "1.0" encoding = "utf-8" ?>

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      example = m.top.findNode("exampleLabelList")

      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]

      m.top.setFocus(true)
    end sub

    ]]>

  </script>

  <children >

    <LabelList id = "exampleLabelList" >

      <ContentNode role = "content" >
        <ContentNode title = "Renderable Nodes" />
        <ContentNode title = "Z-Order/Parent-Child" />
        <ContentNode title = "Animations" />
        <ContentNode title = "Events and Observers" />
        <ContentNode title = "On Demand Example" />
      </ContentNode>

    </LabelList>

  </children>

</component>

我认为您需要更好地理解 SceneGraph API 以便理解如何执行此操作。 在你的 main.brs 文件中,Roku Screen 是用 screen = CreateObject("roSGScreen") 创建的,从那个 Screen 一个 Scene 是用 scene = screen.CreateScene("Scene") 创建的。 因此,您所有的自定义组件都需要添加到该场景的 XML 文件中。 在您的组件文件夹中创建两个单独的文件 LabelListExample.brs 和 LabelListExample.xml。 在你的 LabelListExample.brs 添加这个

sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      example = m.top.findNode("exampleLabelList")

      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]

      m.top.setFocus(true) 
end sub

在您的 LabelListExample.xml 中添加:

    <?xml version="1.0" encoding="UTF-8"?>
    <component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >
    <script type="text/brightscript" uri="pkg:/components/LabelListExample.brs" />
    <children >

        <LabelList id = "exampleLabelList" >

          <ContentNode role = "content" >
            <ContentNode title = "Renderable Nodes" />
            <ContentNode title = "Z-Order/Parent-Child" />
            <ContentNode title = "Animations" />
            <ContentNode title = "Events and Observers" />
            <ContentNode title = "On Demand Example" />
          </ContentNode>

        </LabelList>

      </children>
    </component>

现在在您的 Scene.xml 文件中作为 child 您应该添加:

<Poster
     id="justPoster"
     translation="[0, 0]"
     width="1280"
     height="720" 
  />

<Group id="customComponentView" visible="false">
    <exampleLabelList
       id="customComponent"
    />
</Group>

<Group id="defaultView" visible= "true">
  <Label id="justLabel"
        color="0xFFFFFF"
        translation="[50, 300]"
        wrap="true"
        width="1200"
        horizAlign="center"
        text="Hide me if you can"
        opacity="0.5"
        font = "font:MediumBoldSystemFont"
  />      
</Group>

所以最大的问题是:如何从仅包含标签的 defaultView 到将具有此标签列表的 customComponentView?真的很简单,您只需要隐藏一个并显示另一个。您需要做的是在您的 Scene.brs 文件中添加 onKeyEvent() 函数(如果您正在执行 .xml 中的所有操作,则在您的场景脚本中)。同样在 Scene init() 中,首先使用 :

初始化您的视图和组件
m.defaultView = m.top.findNode(defaultView)
m.customComponentView = m.top.findNode(customComponentView)
m.labelList = m.top.findNode(customComponent)
m.label = m.top.findNode(justLabel)

在 onKeyEvent() 函数中,当按下遥控器上的按钮 "Ok" 时,您可以控制哪个视图可见:

m.defaultView.visible = false
m.customComponentView = true

当 customComponentView 变得可见时,您还需要设置焦点:

m.labelList.setFocus(true)

希望你能从这里继续。另请查看 Roku 文档以了解有关 onKeyEvent() 函数的更多信息。