public void SetDirectory(string dir) { dir = Path.GetFullPath(dir); dir = dir.Replace('\\', '/'); while (dir.StartsWith("/")) { dir = dir.Substring(1); } if (dir.EndsWith("/")) { dir = dir.Substring(0, dir.Length - 1); } if (dir.Length < this._rootFolder.Length) { dir = this._rootFolder; } int num1 = 0; this._currentDirectory = dir; if (this._currentDirectory != this._rootFolder) { ++num1; } if (this._save) { ++num1; } string[] directories = DuckFile.GetDirectories(this._currentDirectory); string[] files = DuckFile.GetFiles(this._currentDirectory); int num2 = num1 + (directories.Length + files.Length); float x = 338f; this._scrollBar = false; this._scrollPosition = 0.0f; if (num2 > this._maxItems) { x = 326f; this._scrollBar = true; } if (this._save) { this.AddItem(new ContextMenu((IContextListener)this) { text = "@NEWICONTINY@New File...", data = "New File...", itemSize = new Vec2(x, 16f) }); } if (this._currentDirectory != this._rootFolder) { this.AddItem(new ContextMenu((IContextListener)this) { text = "@LOADICONTINY@../", data = "../", itemSize = new Vec2(x, 16f) }); } foreach (string path in directories) { string fileName = Path.GetFileName(path); this.AddItem(new ContextMenu((IContextListener)this) { fancy = true, text = "@LOADICONTINY@" + fileName, data = fileName, itemSize = new Vec2(x, 16f) }); } foreach (string path in files) { string fileName = Path.GetFileName(path); if (!this._selectLevels) { if (fileName.EndsWith(this.TypeExtension())) { ContextMenu contextMenu = new ContextMenu((IContextListener)this) { fancy = true, text = fileName }; contextMenu.text = fileName.Substring(0, fileName.Length - 4); contextMenu.data = fileName; contextMenu.itemSize = new Vec2(x, 16f); this.AddItem(contextMenu); } } else { string str1 = path.Replace('\\', '/'); string str2 = str1.Substring(0, str1.Length - 4); string str3 = str2.Substring(str2.IndexOf("/levels/", StringComparison.InvariantCultureIgnoreCase) + 8); ContextCheckBox contextCheckBox = new ContextCheckBox(fileName, (IContextListener)this); contextCheckBox.fancy = true; contextCheckBox.path = str3; contextCheckBox.isChecked = Editor.activatedLevels.Contains(str3); contextCheckBox.itemSize = new Vec2(x, 16f); this.AddItem((ContextMenu)contextCheckBox); } } int num3 = (int)Math.Round((double)(this._items.Count - 1 - this._maxItems) * (double)this._scrollPosition); int num4 = 0; for (int index = 0; index < this._items.Count; ++index) { if (index < num3 || index > num3 + this._maxItems) { this._items[index].visible = false; } else { this._items[index].visible = true; this._items[index].position = new Vec2(this._items[index].position.x, (float)((double)this.y + 3.0 + (double)num4 * ((double)this._items[index].itemSize.y + 1.0))); ++num4; } } this.menuSize.y = this._fdHeight; }
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(); }