Esempio n. 1
0
        private UIStyleGroupContainer CompileStyleGroup(StyleRootNode styleRoot, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            UIStyleGroup defaultGroup = new UIStyleGroup();

            defaultGroup.normal = UIStyleRunCommand.CreateInstance();
            defaultGroup.name   = styleRoot.identifier ?? styleRoot.tagName;
            StyleType styleType = styleRoot.tagName != null ? StyleType.Implicit : StyleType.Shared;

            scratchGroupList.size = 0;

            scratchGroupList.Add(defaultGroup);

            CompileStyleGroups(styleRoot, styleType, scratchGroupList, defaultGroup, styleSheetAnimations, uiSoundData);

            return(new UIStyleGroupContainer(styleSheetImporter.NextStyleGroupId, defaultGroup.name, styleType, scratchGroupList.ToArray()));
        }
Esempio n. 2
0
 private void MapSoundCommand(UISoundData[] soundData, UIStyleRunCommand cmd, SoundCommandNode soundCommandNode)
 {
     cmd.runCommands.Add(MapSoundRunCommand(soundData, soundCommandNode));
 }
Esempio n. 3
0
 private void MapAnimationCommand(AnimationData[] styleSheetAnimations, UIStyleRunCommand cmd, AnimationCommandNode animationCommandNode)
 {
     cmd.runCommands.Add(MapAnimationRunCommand(styleSheetAnimations, animationCommandNode));
 }
Esempio n. 4
0
        private void CompileStyleGroups(StyleNodeContainer root, StyleType styleType, LightList <UIStyleGroup> groups, UIStyleGroup targetGroup, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            for (int index = 0; index < root.children.Count; index++)
            {
                StyleASTNode node = root.children[index];
                switch (node)
                {
                case SelectNode selectNode:
                    break;

                case PropertyNode propertyNode:
                    // add to normal ui style set
                    StylePropertyMappers.MapProperty(targetGroup.normal.style, propertyNode, context);
                    break;

                case AttributeNodeContainer attribute:
                    if (root is AttributeNodeContainer)
                    {
                        throw new CompileException(attribute, "You cannot nest attribute group definitions.");
                    }

                    UIStyleGroup attributeGroup = new UIStyleGroup();
                    attributeGroup.normal    = UIStyleRunCommand.CreateInstance();
                    attributeGroup.name      = root.identifier;
                    attributeGroup.rule      = MapAttributeContainerToRule(attribute);
                    attributeGroup.styleType = styleType;
                    groups.Add(attributeGroup);
                    CompileStyleGroups(attribute, styleType, groups, attributeGroup, styleSheetAnimations, uiSoundData);

                    break;

                case RunNode runNode:
                    UIStyleRunCommand cmd = new UIStyleRunCommand()
                    {
                        style       = targetGroup.normal.style,
                        runCommands = targetGroup.normal.runCommands ?? new LightList <IRunCommand>(4)
                    };

                    if (runNode.command is AnimationCommandNode animationCommandNode)
                    {
                        MapAnimationCommand(styleSheetAnimations, cmd, animationCommandNode);
                    }
                    else if (runNode.command is SoundCommandNode soundCommandNode)
                    {
                        MapSoundCommand(uiSoundData, cmd, soundCommandNode);
                    }

                    targetGroup.normal = cmd;
                    break;

                case StyleStateContainer styleContainer:
                    if (styleContainer.identifier == "hover")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.hover;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.hover = uiStyleRunCommand;
                    }
                    else if (styleContainer.identifier == "focus")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.focused;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.focused = uiStyleRunCommand;
                    }
                    else if (styleContainer.identifier == "active")
                    {
                        UIStyleRunCommand uiStyleRunCommand = targetGroup.active;
                        uiStyleRunCommand.style = uiStyleRunCommand.style ?? new UIStyle();
                        MapProperties(styleSheetAnimations, uiSoundData, ref uiStyleRunCommand, styleContainer.children);
                        targetGroup.active = uiStyleRunCommand;
                    }
                    else
                    {
                        throw new CompileException(styleContainer, $"Unknown style state '{styleContainer.identifier}'. Please use [hover], [focus] or [active] instead.");
                    }

                    break;

                default:
                    throw new CompileException(node, $"You cannot have a {node} at this level.");
                }
            }
        }