Surface layer (Overlay) script

Source: Internet
Author: User

The surface script provides you with the ability to define layers in a script to make it easy to reuse. At the same time, you can use the Scenemanager,overlay and Overlayelement classes to create all the layers in your code for a scene, although it's a bit less useful in use. Instead, you can store the layer definition as a text file and call it when needed.

Load Script

The surface script is loaded by the system at initialization: By default, it searches all common resource locations (see Root::addresourcelocation) to find files with the '. Overlay ' extension and parses it. If you want to parse a file with a different extension, use the Overlaymanager::getsingleton (). Parseallsources method, or if you want to parse a separate file, use the Overlaymanager: : Getsingleton (). Parsescript.

Format

Multiple layers can be defined in a single script. The script format is pseudo C + +, using parentheses ({}) to split the sections, with a line starting with '//' to represent comments (note that nested annotations are not allowed), and inherit by using templates. The general format of the typical example is as follows:

The name of the overlay comes first
myoverlays/anewoverlay
{
    zorder

    container Panel ( Myoverlayelements/testpanel)
    {
        //Center It horzontally, put it at the top left
        0.25
        top 0
        width 0.5< C9/>height 0.1
        Material mymaterials/apanelmaterial

        //Another panel nested in this one
        container panel ( Myoverlayelements/anotherpanel)
        {left
             0
             top 0
             width 0.1
             height 0.1
             Material Mymaterials/nestedpanel
        }}}

The example above defines a layer called ' Myoverlays/anewoverlay ', which has 2 panels and one nested on the other. It uses the correlation matrix (if the Metrics_mode option is not found).

Each layer in the script must be given a name, before the first curly brace ' {'. This name must be globally unique. You can include a path character (as shown in the previous example) to logically differentiate your layer, and to avoid duplicating the layer name, the engine does not think there is any structural relationship here, but just treats it as a string. Both the properties of the layer and the nested elements are inside the parentheses. The layer itself has only one property ' ZOrder ', which, when displayed in more than one layer, determines how much ' high ' the layer is placed in this heap. The higher the ' zorder ' value of the layer, the closer the surface is displayed.

Adding elements to a layer

In a layer, you can include any 2D or 3D element. To do this, rely on defining a nested block of code that starts as follows: element If you want to define a child-free 2D element container If you want to define a 2D container object (that is, you can have a container or an element nested inside yourself)

In addition to the ability to store nested blocks, elements and container blocks are extremely similar.
Container/Element block

Both of these are separated by curly braces. The header format before the first curly brace is:

[container | element] <type_name> (<instance_name>) [: <template_name>]
{...
type_nameThe name of the Overlayelement type that has been registered with Overlaymanager must be given. The plugin registers in Overlaymanager to declare its ability to create elements while declaring the type name. The ogre has been pre-defined PanelBorderpanelTextAreathree different types. instance_nameMust be a unique name in all other elements/containers to be able to identify this element. Note that you can get a pointer to any of the named elements by calling Overlaymanager::getsingleton (). Getoverlayelement (name). Template_nameAn optional template that is based on this item. See below for more information Templates

The properties that can be enclosed in parentheses depend on the user-defined type. However, the following properties are always available: Metrics_mode horz_align vert_align left top width Height material caption

Template

You can use templates to create various elements that have the same attributes. A template is an abstract element, and it is not added to a layer. It acts as a base class in which elements can inherit and get default properties. To create a template, the keyword template must be the first word defined by the element (before container or element). The template element is created at the outermost level-it is not specified in a certain layer. It is recommended that you define templates in a separate layer, although this is not necessary. Defining templates in a separate file allows for a different look and a convenient alternative.

Elements can inherit a template in a way similar to C + + inheritance-by using the: operator on the element definition. : The operator is placed after the right parenthesis of the name (separated by a space). The template name to inherit is placed after the: operator (also separated by a space).

A template can contain sub-templates that are created when the template is instantiated. Although using the template keyword is optional for a child template, it is recommended for clarity because the child template itself is a template.

Template container Borderpanel (mytemplates/basicborderpanel) {left 0 top 0 width 1 height 1//setup The Texture UVs for a borderpanel//does this in a template so it doesn ' t need to be redone everywhere material core/stat Sblockcenter border_size 0.05 0.05 0.06665 0.06665 border_material core/statsblockborder border_topleft_uv 0.0
    1.0000 0.1914 0.7969 border_top_uv 0.1914 1.0000 0.8086 0.7969 border_topright_uv 0.8086 1.0000 1.0000 0.7969 Border_left_uv 0.0000 0.7969 0.1914 0.2148 border_right_uv 0.8086 0.7969 1.0000 0.2148 border_bottomleft_uv 0. 0000 0.2148 0.1914 0.0000 border_bottom_uv 0.1914 0.2148 0.8086 0.0000 border_bottomright_uv 0.8086 0.2148 1.0000 0.0000} template Container Button (Mytemplates/basicbutton)  : mytemplates/basicborderpanel {left 0.82 top 0. Width 0.16 height 0.13 material core/statsblockcenter border_up_material core/statsblockborder/up b Order_down_material Core/statsblockborder/down} template Element TextArea (mytemplates/basictext) {font_name Ogre char_height 0.08 Co Lour_top 1 1 0 colour_bottom 1 0.2 0.2 left 0.03 top 0.02 width 0.12 height 0.09} myoverlays/another
        Overlay {ZOrder 490 container Borderpanel (Myelements/backpanel)  : mytemplates/basicborderpanel { Left 0 Top 0 width 1 height 1 container Button (Myelements/hostbutton)  : mytemplates 

        /basicbutton {left 0.82 top 0.45 caption Mytemplates/basictext HOST}
            Container Button (Myelements/joinbutton)  : Mytemplates/basicbutton {left 0.82 Top 0.60 caption Mytemplates/basictext JOIN}}}

The example above uses a template to define a button. Note that the button template inherits from the Borderpanel template. This reduces the number of properties required to initialize a button.

Also note that instantiating a button requires a template name as the Caption property. So templates can also be used by elements that need to dynamically create child elements (in this case, the button creates a textareaelement as its caption).

Original address: http://www.beyondc.cn/surface-overlay-script.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.