Exemplo n.º 1
0
        public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, IElement element)
        {
            if (ShouldGenerate)
            {
                bool wasAnythingMovedToALayer = false;
                // todo:  Need to register the layer here
                foreach (var item in element.AllNamedObjects.Where(item =>
                                                                   GumPluginCodeGenerator.IsGue(item) &&
                                                                   !string.IsNullOrEmpty(item.LayerOn) &&
                                                                   NamedObjectSaveCodeGenerator.GetFieldCodeGenerationType(item) == CodeGenerationType.Full))
                {
                    string frbLayerName = item.LayerOn;
                    string gumLayerName = $"{item.LayerOn}Gum";

                    if (item.LayerOn == AvailableLayersTypeConverter.UnderEverythingLayerName)
                    {
                        frbLayerName = AvailableLayersTypeConverter.UnderEverythingLayerCode;
                        gumLayerName = UnderEverythingLayerGumName;
                    }

                    if (item.LayerOn == AvailableLayersTypeConverter.TopLayerName)
                    {
                        frbLayerName = AvailableLayersTypeConverter.TopLayerName;
                        gumLayerName = TopLayerGumName;
                    }

                    codeBlock.Line($"{item.FieldName}.MoveToFrbLayer({frbLayerName}, {gumLayerName});");
                    wasAnythingMovedToALayer = true;
                }

                if (wasAnythingMovedToALayer && element is FlatRedBall.Glue.SaveClasses.ScreenSave)
                {
                    codeBlock.Line("FlatRedBall.Gui.GuiManager.SortZAndLayerBased();");
                }
            }
            return(base.GenerateAddToManagers(codeBlock, element));
        }
 IEnumerable <NamedObjectSave> GetObjectsForGumLayers(IElement element)
 {
     return(element.AllNamedObjects.Where(item => item.IsLayer &&
                                          NamedObjectSaveCodeGenerator.GetFieldCodeGenerationType(item) == CodeGenerationType.Full));
 }