Exemplo n.º 1
0
 private void AddType(System.Type t, string group)
 {
     if (MonoMain.lockLoading)
     {
         MonoMain.loadingLocked = true;
         while (MonoMain.lockLoading)
         {
             Thread.Sleep(10);
         }
     }
     MonoMain.loadingLocked = false;
     if (group == "survival")
     {
         return;
     }
     if (group == "")
     {
         Main.SpecialCode = "creating " + t.AssemblyQualifiedName;
         Thing typeInstance = Editor.GetOrCreateTypeInstance(t);
         Main.SpecialCode = "accessing " + t.AssemblyQualifiedName;
         IReadOnlyPropertyBag bag = ContentProperties.GetBag(t);
         if (bag.GetOrDefault <bool>("isInDemo", false))
         {
             this._filteredThings.Add(typeInstance);
         }
         if (bag.GetOrDefault <bool>("isOnlineCapable", true))
         {
             this._onlineFilteredThings.Add(typeInstance);
         }
         this._things.Add(typeInstance);
         this._types.Add(t);
         Editor.MapThing(typeInstance);
         ++MonoMain.lazyLoadyBits;
         Main.SpecialCode = "finished " + t.AssemblyQualifiedName;
     }
     else
     {
         string[]    groupName   = group.Split('|');
         EditorGroup editorGroup = this.SubGroups.FirstOrDefault <EditorGroup>((Func <EditorGroup, bool>)(x => x.Name == groupName[0]));
         if (editorGroup == null)
         {
             editorGroup      = new EditorGroup();
             editorGroup.Name = groupName[0];
             this.SubGroups.Add(editorGroup);
         }
         string str    = group;
         string group1 = ((IEnumerable <string>)groupName).Count <string>() <= 1 ? str.Remove(0, groupName[0].Length) : str.Remove(0, groupName[0].Length + 1);
         editorGroup.AddType(t, group1);
     }
 }
        public void InitializeGroups(
            EditorGroup group,
            FieldBinding radioBinding  = null,
            EditorGroup scriptingGroup = null)
        {
            ++EditorGroupMenu.deep;
            this._text      = group.Name;
            this.itemSize.x = (float)(this._text.Length * 8 + 16);
            foreach (EditorGroup subGroup in group.SubGroups)
            {
                EditorGroupMenu editorGroupMenu = new EditorGroupMenu((IContextListener)this);
                editorGroupMenu.fancy = this.fancy;
                editorGroupMenu.InitializeGroups(subGroup, radioBinding);
                if (!editorGroupMenu.greyOut)
                {
                    this.greyOut = false;
                }
                if (!editorGroupMenu.willOnlineGrayout)
                {
                    this.willOnlineGrayout = false;
                }
                this.AddItem((ContextMenu)editorGroupMenu);
            }
            if (scriptingGroup != null)
            {
                EditorGroupMenu editorGroupMenu = new EditorGroupMenu((IContextListener)this);
                editorGroupMenu.InitializeGroups(scriptingGroup, radioBinding);
                if (!editorGroupMenu.greyOut)
                {
                    this.greyOut = false;
                }
                if (!editorGroupMenu.willOnlineGrayout)
                {
                    this.willOnlineGrayout = false;
                }
                this.AddItem((ContextMenu)editorGroupMenu);
            }
            foreach (Thing allThing in group.AllThings)
            {
                IReadOnlyPropertyBag bag = ContentProperties.GetBag(allThing.GetType());
                if (Main.isDemo && bag.GetOrDefault <bool>("isInDemo", false))
                {
                    this.greyOut = false;
                }
                if (bag.GetOrDefault <bool>("isOnlineCapable", true))
                {
                    this.greyOut           = false;
                    this.willOnlineGrayout = false;
                }
                switch (allThing)
                {
                case BackgroundTile _:
                case ForegroundTile _:
                case SubBackgroundTile _:
                    ContextBackgroundTile contextBackgroundTile = new ContextBackgroundTile(allThing, (IContextListener)this);
                    contextBackgroundTile.contextThing = allThing;
                    this.AddItem((ContextMenu)contextBackgroundTile);
                    continue;

                default:
                    if (radioBinding != null)
                    {
                        if (radioBinding.value is IList)
                        {
                            if (radioBinding.value is List <TypeProbPair> )
                            {
                                ContextSlider contextSlider = new ContextSlider(allThing.editorName, (IContextListener)this, radioBinding, 0.05f, myType: allThing.GetType());
                                contextSlider.greyOut      = Main.isDemo && !bag.GetOrDefault <bool>("isInDemo", false);
                                contextSlider.contextThing = allThing;
                                if (!bag.Contains("isOnlineCapable") || bag.Get <bool>("isOnlineCapable"))
                                {
                                    this.willOnlineGrayout = false;
                                }
                                this.AddItem((ContextMenu)contextSlider);
                                continue;
                            }
                            ContextCheckBox contextCheckBox = new ContextCheckBox(allThing.editorName, (IContextListener)this, radioBinding, allThing.GetType());
                            contextCheckBox.greyOut      = Main.isDemo && !bag.GetOrDefault <bool>("isInDemo", false);
                            contextCheckBox.contextThing = allThing;
                            if (!bag.Contains("isOnlineCapable") || bag.Get <bool>("isOnlineCapable"))
                            {
                                this.willOnlineGrayout = false;
                            }
                            this.AddItem((ContextMenu)contextCheckBox);
                            continue;
                        }
                        ContextRadio contextRadio = new ContextRadio(allThing.editorName, false, (object)allThing.GetType(), (IContextListener)this, radioBinding);
                        contextRadio.greyOut      = Main.isDemo && !bag.GetOrDefault <bool>("isInDemo", false);
                        contextRadio.contextThing = allThing;
                        if (!bag.Contains("isOnlineCapable") || bag.Get <bool>("isOnlineCapable"))
                        {
                            this.willOnlineGrayout = false;
                        }
                        this.AddItem((ContextMenu)contextRadio);
                        continue;
                    }
                    ContextObject contextObject = new ContextObject(allThing, (IContextListener)this);
                    contextObject.contextThing = allThing;
                    this.AddItem((ContextMenu)contextObject);
                    continue;
                }
            }
            --EditorGroupMenu.deep;
            if (EditorGroupMenu.deep != 0)
            {
                return;
            }
            this.UpdateGrayout();
        }