public override void Update()
 {
     if (!this.opened || this._dialog.opened || (this._deleteDialog.opened || this._overwriteDialog.opened) || this._opening)
     {
         this._opening = false;
         foreach (ContextMenu contextMenu in this._items)
         {
             contextMenu.disabled = true;
         }
     }
     else
     {
         bool flag = false;
         foreach (ContextMenu contextMenu in this._items)
         {
             contextMenu.disabled = false;
             if (!flag && contextMenu.hover)
             {
                 flag = true;
                 string str        = "";
                 int    startIndex = this._currentDirectory.IndexOf(this._rootFolder);
                 if (startIndex != -1)
                 {
                     str = this._currentDirectory.Remove(startIndex, this._rootFolder.Length);
                 }
                 if (str != "" && !str.EndsWith("/"))
                 {
                     str += "/";
                 }
                 if (str.StartsWith("/"))
                 {
                     str = str.Substring(1, str.Length - 1);
                 }
                 string path = str + contextMenu.data;
                 if (this._prevPreviewPath != path)
                 {
                     if (path.EndsWith(".lev"))
                     {
                         if (this._preview == null || !(this._preview is RenderTarget2D))
                         {
                             this._preview = (Tex2D) new RenderTarget2D(320, 200);
                         }
                         this._preview = (Tex2D)Content.GeneratePreview(path.Substring(0, path.Length - 4), this._preview as RenderTarget2D);
                     }
                     else if (path.EndsWith(".png"))
                     {
                         Texture2D texture2D = ContentPack.LoadTexture2D(this._currentDirectory + "/" + Path.GetFileName(path));
                         this._preview = texture2D == null ? Content.invalidTexture : (this._type != ContextFileType.Block && this._type != ContextFileType.Background && this._type != ContextFileType.Platform || texture2D.Width == 128 && texture2D.Height == 128 ? (this._type != ContextFileType.Parallax || texture2D.Width == 320 && texture2D.Height == 240 ? (this._type != ContextFileType.ArcadeStyle || texture2D.Width == 27 && texture2D.Height == 34 || texture2D.Width == 54 && texture2D.Height == 68 ? (Tex2D)texture2D : this._badArcade.texture) : this._badParallax.texture) : this._badTileset.texture);
                     }
                     else
                     {
                         this._previewSprite   = (Sprite)null;
                         this._prevPreviewPath = (string)null;
                     }
                     this._previewSprite = new Sprite(this._preview);
                     if (this._type == ContextFileType.Block || this._type == ContextFileType.Background || (this._type == ContextFileType.Platform || this._type == ContextFileType.Parallax))
                     {
                         this._previewSprite.scale = new Vec2(2f, 2f);
                     }
                     this._prevPreviewPath = path;
                 }
             }
         }
         if (!flag && this._type == ContextFileType.ArcadeStyle)
         {
             this._preview         = this._badArcade.texture;
             this._previewSprite   = new Sprite(this._preview);
             this._prevPreviewPath = (string)null;
         }
         Editor.lockInput = (ContextMenu)this;
         base.Update();
         this._scrollWait = Lerp.Float(this._scrollWait, 0.0f, 0.2f);
         if (this._dialog.result != null && this._dialog.result != "")
         {
             Editor current = Level.current as Editor;
             current._guid = Guid.NewGuid().ToString();
             Editor.ResetWorkshopData();
             current.DoSave(this._currentDirectory + "/" + this._dialog.result);
             this._dialog.result = "";
             this.Close();
         }
         if (!this._overwriteDialog.opened && this._doOverwriteDialog)
         {
             this._doOverwriteDialog = false;
             if (this._overwriteDialog.result)
             {
                 (Level.current as Editor).DoSave(this._currentDirectory + "/" + this._overwriteName);
                 this._overwriteDialog.result = false;
                 this._overwriteName          = "";
                 this.Close();
             }
         }
         if (!this._deleteDialog.opened && this._doDeleteDialog)
         {
             this._doDeleteDialog = false;
             if (this._deleteDialog.result)
             {
                 foreach (ContextMenu contextMenu in this._items)
                 {
                     if (contextMenu.hover)
                     {
                         Editor.Delete(this._currentDirectory + "/" + contextMenu.text);
                         break;
                     }
                 }
                 this.ClearItems();
                 this.SetDirectory(this._currentDirectory);
             }
         }
         if (Keyboard.Pressed(Keys.Escape) || Mouse.right == InputState.Pressed || Input.Pressed("QUACK"))
         {
             this.Close();
         }
         if (!this._selectLevels && Input.Pressed("GRAB"))
         {
             this._deleteDialog.Open("CONFIRM DELETE");
             Editor.lockInput          = (ContextMenu)this._deleteDialog;
             this._doDeleteDialog      = true;
             this._deleteDialog.result = false;
         }
         else
         {
             if (Input.Pressed("LEFT"))
             {
                 this._selectedIndex -= this._maxItems;
             }
             else if (Input.Pressed("RIGHT"))
             {
                 this._selectedIndex += this._maxItems;
             }
             this._selectedIndex = Maths.Clamp(this._selectedIndex, 0, this._items.Count - 1);
             if (this._items.Count <= this._maxItems)
             {
                 return;
             }
             float num1 = 1f / (float)(this._items.Count - this._maxItems);
             if ((double)Mouse.scroll != 0.0)
             {
                 this._scrollPosition += (float)Math.Sign(Mouse.scroll) * num1;
                 if ((double)this._scrollPosition > 1.0)
                 {
                     this._scrollPosition = 1f;
                 }
                 if ((double)this._scrollPosition < 0.0)
                 {
                     this._scrollPosition = 0.0f;
                 }
             }
             int num2 = (int)Math.Round(((double)(this._items.Count - this._maxItems) - 1.0) * (double)this._scrollPosition);
             int num3 = 0;
             int num4 = 0;
             for (int index = 0; index < this._items.Count; ++index)
             {
                 if (this._items[index].hover)
                 {
                     num4 = index;
                     break;
                 }
             }
             if (Editor.gamepadMode)
             {
                 if (num4 > num2 + this._maxItems)
                 {
                     this._scrollPosition += (float)(num4 - (num2 + this._maxItems)) * num1;
                 }
                 else if (num4 < num2)
                 {
                     this._scrollPosition -= (float)(num2 - num4) * num1;
                 }
             }
             for (int index = 0; index < this._items.Count; ++index)
             {
                 this._items[index].disabled = false;
                 if (index < num2 || index > num2 + this._maxItems)
                 {
                     this._items[index].visible = false;
                     this._items[index].hover   = false;
                 }
                 else
                 {
                     ContextMenu contextMenu = this._items[index];
                     this._items[index].visible  = true;
                     this._items[index].position = new Vec2(this._items[index].position.x, (float)((double)this.y + 3.0 + (double)num3 * (double)this._items[index].itemSize.y));
                     ++num3;
                 }
             }
         }
     }
 }
Example #2
0
 public override void Update()
 {
     HUD.CloseCorner(HUDCorner.TopLeft);
     this._dialog.DoUpdate();
     if (this._dialog.opened)
     {
         return;
     }
     Editor.lockInput = (ContextMenu)null;
     if (this._dialog.result != null && this._dialog.result != "")
     {
         string        result        = this._dialog.result;
         LevelPlaylist levelPlaylist = new LevelPlaylist();
         levelPlaylist.levels.AddRange((IEnumerable <string>)Editor.activatedLevels);
         XDocument doc = new XDocument();
         doc.Add((object)levelPlaylist.Serialize());
         DuckFile.SaveXDocument(doc, DuckFile.levelDirectory + result + ".play");
         this.SetCurrentFolder(this._rootDirectory);
         this._dialog.result = (string)null;
     }
     else
     {
         if (this._selectedLevel == null)
         {
             this._exiting = true;
         }
         if (Editor.activatedLevels.Count > 0)
         {
             if (!this.showPlaylistOption)
             {
                 this.showPlaylistOption = true;
                 HUD.AddCornerControl(HUDCorner.BottomLeft, "@RAGDOLL@NEW PLAYLIST");
             }
         }
         else if (this.showPlaylistOption)
         {
             this.showPlaylistOption = false;
             HUD.CloseCorner(HUDCorner.BottomLeft);
         }
         if (this._deleteFile.value)
         {
             foreach (string str in this._selectedLevel.levelsInside)
             {
                 Editor.activatedLevels.Remove(str);
             }
             Editor.activatedLevels.Remove(this._selectedLevel.path);
             if (this._selectedLevel.itemType == LSItemType.Folder)
             {
                 DuckFile.DeleteFolder(DuckFile.levelDirectory + this._selectedLevel.path);
             }
             else if (this._selectedLevel.itemType == LSItemType.Playlist)
             {
                 DuckFile.Delete(DuckFile.levelDirectory + this._selectedLevel.path);
             }
             else
             {
                 DuckFile.Delete(DuckFile.levelDirectory + this._selectedLevel.path + ".lev");
             }
             Thread.Sleep(100);
             this.SetCurrentFolder(this._currentDirectory);
             this._deleteFile.value = false;
         }
         if (this._exiting)
         {
             HUD.CloseAllCorners();
             Graphics.fade = Lerp.Float(Graphics.fade, 0.0f, 0.04f);
             if ((double)Graphics.fade >= 0.00999999977648258)
             {
                 return;
             }
             this.isClosed = true;
         }
         else
         {
             Graphics.fade = Lerp.Float(Graphics.fade, 1f, 0.04f);
             if (Input.Pressed("UP"))
             {
                 if (this._selectedItem > 0)
                 {
                     --this._selectedItem;
                 }
                 if (this._selectedItem < this._topIndex)
                 {
                     this._topIndex = this._selectedItem;
                 }
             }
             else if (Input.Pressed("DOWN"))
             {
                 if (this._selectedItem < this._items.Count <LSItem>() - 1)
                 {
                     ++this._selectedItem;
                 }
                 if (this._selectedItem >= this._topIndex + this._maxItems)
                 {
                     this._topIndex = this._selectedItem + 1 - this._maxItems;
                 }
             }
             else if (Input.Pressed("LEFT"))
             {
                 this._selectedItem -= this._maxItems - 1;
                 if (this._selectedItem < 0)
                 {
                     this._selectedItem = 0;
                 }
                 if (this._selectedItem < this._topIndex)
                 {
                     this._topIndex = this._selectedItem;
                 }
             }
             else if (Input.Pressed("RIGHT"))
             {
                 this._selectedItem += this._maxItems - 1;
                 if (this._selectedItem > this._items.Count <LSItem>() - 1)
                 {
                     this._selectedItem = this._items.Count <LSItem>() - 1;
                 }
                 if (this._selectedItem >= this._topIndex + this._maxItems)
                 {
                     this._topIndex = this._selectedItem + 1 - this._maxItems;
                 }
             }
             else if (Input.Pressed("SHOOT"))
             {
                 if (this._selectedLevel.itemType != LSItemType.UpFolder)
                 {
                     if (this._selectedLevel.itemType == LSItemType.Folder || this._selectedLevel.itemType == LSItemType.Playlist || this._selectedLevel.itemType == LSItemType.Workshop)
                     {
                         if (!this._selectedLevel.enabled)
                         {
                             this._selectedLevel.enabled          = true;
                             this._selectedLevel.partiallyEnabled = false;
                             Editor.activatedLevels.AddRange((IEnumerable <string>) this._selectedLevel.levelsInside);
                         }
                         else
                         {
                             this._selectedLevel.enabled          = false;
                             this._selectedLevel.partiallyEnabled = false;
                             foreach (string str in this._selectedLevel.levelsInside)
                             {
                                 Editor.activatedLevels.Remove(str);
                             }
                         }
                     }
                     else if (Editor.activatedLevels.Contains(this._selectedLevel.path))
                     {
                         Editor.activatedLevels.Remove(this._selectedLevel.path);
                     }
                     else
                     {
                         Editor.activatedLevels.Add(this._selectedLevel.path);
                     }
                 }
             }
             else if (Input.Pressed("SELECT"))
             {
                 if (this._selectedLevel.itemType == LSItemType.Workshop)
                 {
                     this.SetCurrentFolder(this._selectedLevel.path);
                 }
                 else if (this._selectedLevel.itemType == LSItemType.Folder || this._selectedLevel.itemType == LSItemType.Playlist)
                 {
                     this.SetCurrentFolder(this._rootDirectory + this._selectedLevel.path);
                 }
                 else if (this._selectedLevel.itemType == LSItemType.UpFolder)
                 {
                     this.FolderUp();
                 }
             }
             else if (Input.Pressed("QUACK"))
             {
                 if (this._currentDirectory != this._rootDirectory)
                 {
                     this.FolderUp();
                 }
             }
             else if (Input.Pressed("START"))
             {
                 this._exiting = true;
             }
             else if (Input.Pressed("RAGDOLL"))
             {
                 this._dialog.Open("New Playlist...");
                 Editor.lockInput = (ContextMenu)this._dialog;
             }
             else if (Input.Pressed("GRAB") && MonoMain.pauseMenu != this._confirmMenu && (this._selectedLevel.itemType != LSItemType.UpFolder && this._selectedLevel.itemType != LSItemType.Workshop))
             {
                 LevelSelect._skipCompanionOpening = true;
                 MonoMain.pauseMenu = (UIComponent)this._confirmMenu;
                 this._confirmMenu.Open();
                 SFX.Play("pause", 0.6f);
             }
             this.PositionItems();
             if (this._selectedLevel != this._lastSelection)
             {
                 if (this._lastSelection == null || this._selectedLevel.itemType != this._lastSelection.itemType)
                 {
                     HUD.CloseCorner(HUDCorner.BottomRight);
                     if (this._selectedLevel.itemType == LSItemType.UpFolder)
                     {
                         HUD.AddCornerControl(HUDCorner.BottomRight, "@SELECT@Return");
                     }
                     else if (this._selectedLevel.itemType == LSItemType.Folder || this._selectedLevel.itemType == LSItemType.Playlist || this._selectedLevel.itemType == LSItemType.Workshop)
                     {
                         HUD.AddCornerControl(HUDCorner.BottomRight, "@SHOOT@Toggle");
                         HUD.AddCornerControl(HUDCorner.BottomRight, "@SELECT@Open");
                     }
                     else
                     {
                         HUD.AddCornerControl(HUDCorner.BottomRight, "@SHOOT@Toggle");
                     }
                 }
                 this._lastSelection = this._selectedLevel;
             }
             if (this._selectedLevel != this._previewItem)
             {
                 if (this._selectedLevel.itemType == LSItemType.Level)
                 {
                     this._preview       = Content.GeneratePreview(this._selectedLevel.path);
                     this._previewSprite = this._preview == null ? (Sprite)null : new Sprite(this._preview, 0.0f, 0.0f);
                 }
                 else
                 {
                     this._previewSprite = (Sprite)null;
                 }
                 this._previewItem = this._selectedLevel;
             }
             foreach (Thing thing in this._items)
             {
                 thing.Update();
             }
         }
     }
 }