示例#1
0
 public static void DeleteAllSaveData()
 {
     foreach (string allPath in DuckFile._allPaths)
     {
         foreach (string file in DuckFile.GetFiles(DuckFile.saveDirectory + allPath))
         {
             DuckFile.Delete(file);
         }
     }
 }
示例#2
0
 public static void DeleteFolder(string folder)
 {
     if (!Directory.Exists(folder))
     {
         return;
     }
     foreach (string directory in DuckFile.GetDirectories(folder))
     {
         DuckFile.DeleteFolder(directory);
     }
     foreach (string file in DuckFile.GetFiles(folder))
     {
         DuckFile.Delete(file);
     }
     Directory.Delete(folder);
 }
示例#3
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();
             }
         }
     }
 }
示例#4
0
        public override void Draw()
        {
            if (this._downloadModsMenu.open)
            {
                this._downloadModsMenu.DoDraw();
            }
            if (this.open)
            {
                this.scrollBarTop              = (int)((double)this._box.y - (double)this._box.halfHeight + 1.0 + 16.0);
                this.scrollBarBottom           = (int)((double)this._box.y + (double)this._box.halfHeight - 1.0 - 16.0);
                this.scrollBarScrollableHeight = this.scrollBarBottom - this.scrollBarTop;
                if (this.fixView)
                {
                    Layer.HUD.camera.width  *= 2f;
                    Layer.HUD.camera.height *= 2f;
                    this.fixView             = false;
                }
                DuckGame.Graphics.DrawRect(new Vec2(this._box.x - this._box.halfWidth, this._box.y - this._box.halfHeight), new Vec2((float)((double)this._box.x + (double)this._box.halfWidth - 12.0 - 2.0), this._box.y + this._box.halfHeight), Color.Black, new Depth(0.4f));
                DuckGame.Graphics.DrawRect(new Vec2((float)((double)this._box.x + (double)this._box.halfWidth - 12.0), this._box.y - this._box.halfHeight), new Vec2(this._box.x + this._box.halfWidth, this._box.y + this._box.halfHeight), Color.Black, new Depth(0.4f));
                Rectangle r = this.ScrollBarBox();
                DuckGame.Graphics.DrawRect(r, this._draggingScrollbar || r.Contains(Mouse.position) ? Color.LightGray : Color.Gray, new Depth(0.5f));
                if (this._lobbies.Count == 0)
                {
                    this._fancyFont.Draw("No games found!", new Vec2(this._box.x - this._box.halfWidth + 10f, (float)((double)this._box.y - (double)this._box.halfHeight + 0.0) + 2f), Color.Yellow, new Depth(0.5f));
                }
                this._lobbies = this._lobbies.OrderByDescending <UIServerBrowser.LobbyData, bool>((Func <UIServerBrowser.LobbyData, bool>)(x => x.canJoin)).ToList <UIServerBrowser.LobbyData>();
                for (int index1 = 0; index1 < this._maxLobbiesToShow; ++index1)
                {
                    int index2 = this._scrollItemOffset + index1;
                    if (index2 < this._lobbies.Count)
                    {
                        float x1 = this._box.x - this._box.halfWidth;
                        float y  = this._box.y - this._box.halfHeight + (float)(36 * index1);
                        if (this._hoverIndex == index2)
                        {
                            DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.White * 0.6f, new Depth(0.4f));
                        }
                        else if ((index2 & 1) != 0)
                        {
                            DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.White * 0.1f, new Depth(0.4f));
                        }
                        UIServerBrowser.LobbyData lobby = this._lobbies[index2];
                        if (lobby != null)
                        {
                            this._noImage.texture = this.defaultImage;
                            this._noImage.scale   = new Vec2(1f, 1f);
                            List <Tex2D> tex2DList = new List <Tex2D>();
                            string       name      = lobby.name;
                            string       text1     = "|WHITE||GRAY|\n";
                            if (lobby.workshopItems.Count > 0)
                            {
                                WorkshopItem workshopItem1 = lobby.workshopItems[0];
                                if (workshopItem1.data != null)
                                {
                                    lobby.workshopItems = lobby.workshopItems.OrderByDescending <WorkshopItem, int>((Func <WorkshopItem, int>)(x => x.data == null ? 0 : x.data.votesUp)).ToList <WorkshopItem>();
                                    if (!lobby.downloadedWorkshopItems)
                                    {
                                        lobby.hasFirstMod   = true;
                                        lobby.hasRestOfMods = true;
                                        bool flag = true;
                                        foreach (WorkshopItem workshopItem2 in lobby.workshopItems)
                                        {
                                            ulong id = workshopItem2.id;
                                            if (ModLoader.accessibleMods.FirstOrDefault <Mod>((Func <Mod, bool>)(x => (long)x.configuration.workshopID == (long)id)) == null)
                                            {
                                                if (flag)
                                                {
                                                    lobby.hasFirstMod = false;
                                                }
                                                else
                                                {
                                                    lobby.hasRestOfMods = false;
                                                }
                                            }
                                            flag = false;
                                        }
                                        lobby.downloadedWorkshopItems = true;
                                    }
                                    string str1 = !lobby.hasFirstMod ? "|RED|Requires " + workshopItem1.name : "|DGGREEN|Requires " + workshopItem1.name;
                                    string str2 = lobby.hasRestOfMods ? "|DGGREEN|" : "|RED|";
                                    if (lobby.workshopItems.Count == 2)
                                    {
                                        str1 = str1 + str2 + " +" + (lobby.workshopItems.Count - 1).ToString() + " other mod.";
                                    }
                                    else if (lobby.workshopItems.Count > 2)
                                    {
                                        str1 = str1 + str2 + " +" + (lobby.workshopItems.Count - 1).ToString() + " other mods.";
                                    }
                                    text1 = str1 + "\n|GRAY|";
                                    if (!UIServerBrowser._previewMap.ContainsKey(workshopItem1.id))
                                    {
                                        if (workshopItem1.data.previewPath != null)
                                        {
                                            if (workshopItem1.data.previewPath != "")
                                            {
                                                try
                                                {
                                                    WebClient webClient = new WebClient();
                                                    string    str3      = this.PreviewPathForWorkshopItem(workshopItem1.id);
                                                    DuckFile.CreatePath(str3);
                                                    if (System.IO.File.Exists(str3))
                                                    {
                                                        DuckFile.Delete(str3);
                                                    }
                                                    webClient.DownloadFileAsync(new Uri(workshopItem1.data.previewPath), str3);
                                                    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.Completed);
                                                    UIServerBrowser._clientMap[(object)webClient] = workshopItem1.id;
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                        }
                                        UIServerBrowser._previewMap[workshopItem1.id] = (Tex2D)null;
                                    }
                                    else
                                    {
                                        Tex2D preview = UIServerBrowser._previewMap[workshopItem1.id];
                                        if (preview != null)
                                        {
                                            tex2DList.Add(preview);
                                        }
                                    }
                                }
                            }
                            if (lobby.wallMode == "1")
                            {
                                text1 += "Wall Mode. ";
                            }
                            if (lobby.requiredWins != "")
                            {
                                text1 = text1 + "First to " + lobby.requiredWins.ToString() + " ";
                            }
                            if (lobby.restsEvery != "")
                            {
                                text1 = text1 + "rests every " + lobby.restsEvery.ToString() + ". ";
                            }
                            if (lobby.customLevels != "" && lobby.customLevels != "0")
                            {
                                text1 = text1 + lobby.customLevels.ToString() + " Custom Levels. ";
                            }
                            DuckGame.Graphics.DrawRect(new Vec2(x1 + 2f, y + 2f), new Vec2((float)((double)x1 + 36.0 - 2.0), (float)((double)y + 36.0 - 2.0)), Color.Gray, new Depth(0.5f), false, 2f);
                            if (tex2DList.Count > 0)
                            {
                                Vec2 zero = Vec2.Zero;
                                for (int index3 = 0; index3 < 4; ++index3)
                                {
                                    if (index3 < tex2DList.Count)
                                    {
                                        this._noImage.texture = tex2DList[index3];
                                        if (tex2DList.Count > 1)
                                        {
                                            this._noImage.scale = new Vec2(16f / (float)this._noImage.texture.width);
                                        }
                                        else
                                        {
                                            this._noImage.scale = new Vec2(32f / (float)this._noImage.texture.width);
                                        }
                                        if (this._noImage.texture.width != this._noImage.texture.height)
                                        {
                                            if (this._noImage.texture.width > this._noImage.texture.height)
                                            {
                                                this._noImage.scale = new Vec2(32f / (float)this._noImage.texture.height);
                                                DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Rectangle((float)(this._noImage.texture.width / 2 - this._noImage.texture.height / 2), 0.0f, (float)this._noImage.texture.height, (float)this._noImage.texture.height), new Depth(0.5f));
                                            }
                                            else
                                            {
                                                DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Rectangle(0.0f, 0.0f, (float)this._noImage.texture.width, (float)this._noImage.texture.width), new Depth(0.5f));
                                            }
                                        }
                                        else
                                        {
                                            DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Depth(0.5f));
                                        }
                                        zero.x += 16f;
                                        if ((double)zero.x >= 32.0)
                                        {
                                            zero.x  = 0.0f;
                                            zero.y += 16f;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                DuckGame.Graphics.Draw(this._noImage, x1 + 2f, y + 2f, new Depth(0.5f));
                            }
                            string text2 = name;
                            if (lobby.maxPlayers != "")
                            {
                                text2 = text2 + " (" + lobby.lobby.users.Count.ToString() + "/" + lobby.numSlots.ToString() + ")";
                            }
                            if (!lobby.canJoin)
                            {
                                string str = text2 + " |DGRED|(";
                                if (lobby.version != DG.version)
                                {
                                    switch (DuckNetwork.CheckVersion(lobby.version))
                                    {
                                    case NMVersionMismatch.Type.Older:
                                        str += "They have an older version.";
                                        break;

                                    case NMVersionMismatch.Type.Newer:
                                        str += "They have a newer version.";
                                        break;

                                    default:
                                        str += "They have a different version.";
                                        break;
                                    }
                                }
                                else if (lobby.started == "true")
                                {
                                    str += "This game is in progress.";
                                }
                                else if (lobby.numSlots != "" && lobby.lobby.users.Count >= Convert.ToInt32(lobby.numSlots))
                                {
                                    str += "Lobby is full.";
                                }
                                else if (lobby.type != "2")
                                {
                                    str += "This game is not public.";
                                }
                                else if (lobby.hasLocalMods)
                                {
                                    str += "This game is using non-workshop mods.";
                                }
                                text2 = str + ")";
                                DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.Black * 0.5f, new Depth(0.99f));
                            }
                            this._fancyFont.maxWidth = 1000;
                            this._fancyFont.Draw(text2, new Vec2((float)((double)x1 + 36.0 + 10.0), y + 2f), Color.Yellow, new Depth(0.5f));
                            if (lobby.version == DG.version)
                            {
                                this._fancyFont.Draw(lobby.version, new Vec2((float)((double)x1 + 430.0 + 10.0), y + 2f), Colors.DGGreen * 0.35f, new Depth(0.5f));
                            }
                            else
                            {
                                this._fancyFont.Draw(lobby.version, new Vec2((float)((double)x1 + 430.0 + 10.0), y + 2f), Colors.DGRed * 0.35f, new Depth(0.5f));
                            }
                            DuckGame.Graphics.Draw(this._steamIcon, x1 + 36f, y + 2.5f, new Depth(0.5f));
                            this._fancyFont.Draw(text1, new Vec2(x1 + 36f, y + 6f + (float)this._fancyFont.characterHeight), Color.LightGray, new Depth(0.5f));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (Mouse.available && !this._gamepadMode)
                {
                    this._cursor.depth    = new Depth(1f);
                    this._cursor.scale    = new Vec2(1f, 1f);
                    this._cursor.position = Mouse.position;
                    this._cursor.frame    = 0;
                    if (Editor.hoverTextBox)
                    {
                        this._cursor.frame       = 5;
                        this._cursor.position.y -= 4f;
                        this._cursor.scale       = new Vec2(0.5f, 1f);
                    }
                    this._cursor.Draw();
                }
            }
            base.Draw();
        }