Example #1
0
        public static void DownloadAllCloudData()
        {
            bool cloudOnly = MonoMain.cloudOnly;
            bool cloud     = Options.Data.cloud;

            MonoMain.cloudOnly = true;
            Options.Data.cloud = true;
            foreach (string file in DuckFile.GetFiles(DuckFile.profileDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            foreach (string file in DuckFile.GetFiles(DuckFile.levelDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            foreach (string file in DuckFile.GetFiles(DuckFile.optionsDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            MonoMain.cloudOnly = cloudOnly;
            Options.Data.cloud = cloud;
        }
Example #2
0
        public static void InitializeMods()
        {
            MonoMain.loadMessage = "Loading Mods";
            Mod mod;

            AppDomain.CurrentDomain.AssemblyResolve += (ResolveEventHandler)((s, resolveArgs) => ModLoader._modAssemblyNames.TryGetValue(resolveArgs.Name, out mod) ? mod.configuration.assembly : (Assembly)null);
            ModLoader.AddMod((Mod)(CoreMod.coreMod = new CoreMod()));
            DuckFile.CreatePath(DuckFile.modsDirectory);
            ModLoader.LoadMods(DuckFile.modsDirectory);
            ManagedContent.InitializeContentSet <Thing>(ManagedContent.Things);
            ManagedContent.InitializeContentSet <AmmoType>(ManagedContent.AmmoTypes);
            ManagedContent.InitializeContentSet <DeathCrateSetting>(ManagedContent.DeathCrateSettings);
            ManagedContent.InitializeContentSet <DestroyType>(ManagedContent.DestroyTypes);
            ContentProperties.InitializeBags(ManagedContent.Things.Types);
            ModLoader.PostLoadMods();
        }
Example #3
0
 public static void Initialize()
 {
     DuckFile._saveRoot       = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/";
     DuckFile._saveRoot       = DuckFile._saveRoot.Replace('\\', '/');
     DuckFile._saveDirectory  = "DuckGame/";
     DuckFile._levelDirectory = "Levels/";
     DuckFile._allPaths.Add(DuckFile._levelDirectory);
     DuckFile._onlineLevelDirectory = "Online/Levels/";
     DuckFile._allPaths.Add(DuckFile._onlineLevelDirectory);
     DuckFile._optionsDirectory = "Options/";
     DuckFile._allPaths.Add(DuckFile._optionsDirectory);
     DuckFile._albumDirectory = "Album/";
     DuckFile._allPaths.Add(DuckFile._albumDirectory);
     DuckFile._profileDirectory = "Profiles/";
     DuckFile._allPaths.Add(DuckFile._profileDirectory);
     DuckFile._challengeDirectory = "ChallengeData/";
     DuckFile._allPaths.Add(DuckFile._challengeDirectory);
     DuckFile._modsDirectory = "Mods/";
     DuckFile._allPaths.Add(DuckFile._modsDirectory);
     DuckFile._scriptsDirectory = "Scripts/";
     DuckFile._allPaths.Add(DuckFile._scriptsDirectory);
     DuckFile._workshopDirectory = "Workshop/";
     DuckFile._allPaths.Add(DuckFile._workshopDirectory);
     DuckFile._customBlockDirectory = "Custom/Blocks/";
     DuckFile._allPaths.Add(DuckFile._customBlockDirectory);
     DuckFile.CreatePath(DuckFile.customBlockDirectory);
     DuckFile._downloadedBlockDirectory = "Custom/Blocks/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedBlockDirectory);
     DuckFile._customBackgroundDirectory = "Custom/Background/";
     DuckFile._allPaths.Add(DuckFile._customBackgroundDirectory);
     DuckFile.CreatePath(DuckFile.customBackgroundDirectory);
     DuckFile._downloadedBackgroundDirectory = "Custom/Background/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedBackgroundDirectory);
     DuckFile._customPlatformDirectory = "Custom/Platform/";
     DuckFile._allPaths.Add(DuckFile._customPlatformDirectory);
     DuckFile.CreatePath(DuckFile.customPlatformDirectory);
     DuckFile._downloadedPlatformDirectory = "Custom/Platform/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedPlatformDirectory);
     DuckFile._customParallaxDirectory = "Custom/Parallax/";
     DuckFile._allPaths.Add(DuckFile._customParallaxDirectory);
     DuckFile.CreatePath(DuckFile.customParallaxDirectory);
     DuckFile._downloadedParallaxDirectory = "Custom/Parallax/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedParallaxDirectory);
     DuckFile._customArcadeDirectory = "Custom/Arcade/";
     DuckFile._allPaths.Add(DuckFile.customArcadeDirectory);
     DuckFile.CreatePath(DuckFile.customArcadeDirectory);
 }
Example #4
0
 public static XDocument LoadXDocument(string path)
 {
     DuckFile.CreatePath(Path.GetDirectoryName(path));
     DuckFile.PrepareToLoadCloudFile(path);
     if (!File.Exists(path))
     {
         return((XDocument)null);
     }
     try
     {
         return(XDocument.Load(path));
     }
     catch
     {
         return((XDocument)null);
     }
 }
Example #5
0
        public static void SaveChunk(BinaryClassChunk doc, string path)
        {
            DuckFile.CreatePath(Path.GetDirectoryName(path));
            try
            {
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
            }
            catch (Exception ex)
            {
            }
            BitBuffer  bitBuffer  = doc.Serialize();
            FileStream fileStream = File.Create(path);

            fileStream.Write(bitBuffer.buffer, 0, bitBuffer.lengthInBytes);
            fileStream.Close();
            DuckFile.SaveCloudFile(path);
        }
Example #6
0
        public static void SaveXDocument(XDocument doc, string path)
        {
            DuckFile.CreatePath(Path.GetDirectoryName(path));
            try
            {
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
            }
            catch (Exception ex)
            {
            }
            string contents = doc.ToString();

            if (string.IsNullOrWhiteSpace(contents))
            {
                throw new Exception("Blank XML (" + path + ")");
            }
            File.WriteAllText(path, contents);
            DuckFile.SaveCloudFile(path);
        }
Example #7
0
        public static string ApplyCustomData(CustomTileData tData, int index, CustomType type)
        {
            string key = tData.path + "@" + (object)tData.checksum + ".png";

            if (tData.texture != null)
            {
                string str = DuckFile.GetCustomDownloadDirectory(type) + key;
                if (!File.Exists(str))
                {
                    DuckFile.CreatePath(str);
                    FileStream fileStream = File.Create(str);
                    tData.texture.SaveAsPng((Stream)fileStream, tData.texture.Width, tData.texture.Height);
                    fileStream.Close();
                }
            }
            else if (tData.path == null)
            {
                return("");
            }
            Custom._customTilesetData[type][key] = tData;
            Custom.data[type][index]             = key;
            return(key);
        }
Example #8
0
 public override void Update()
 {
     if (this._pressWait > 0)
     {
         --this._pressWait;
     }
     if (this._editModMenu.open)
     {
         if (!UIMenu.globalUILock && (Input.Pressed("QUACK") || Keyboard.Pressed(Keys.Escape)))
         {
             this._editModMenu.Close();
             this.Open();
             return;
         }
     }
     else if (this.open)
     {
         if (this._transferItem != null && !this._needsUpdateNotes)
         {
             if (!this._transferring)
             {
                 if (this._transferItem.result == SteamResult.OK)
                 {
                     WorkshopItemData dat = new WorkshopItemData();
                     if (this._selectedMod.configuration.workshopID == 0UL)
                     {
                         this._selectedMod.configuration.SetWorkshopID(this._transferItem.id);
                         dat.name        = this._selectedMod.configuration.displayName;
                         dat.description = this._selectedMod.configuration.description;
                         dat.visibility  = RemoteStoragePublishedFileVisibility.Private;
                         dat.tags        = new List <string>();
                         dat.tags.Add("Mod");
                     }
                     else
                     {
                         dat.changeNotes = this._updateTextBox.text;
                     }
                     string pathString = this._selectedMod.configuration.directory + "/content/";
                     DuckFile.CreatePath(pathString);
                     string path1 = pathString + "screenshot.png";
                     if (!File.Exists(path1))
                     {
                         File.Delete(path1);
                         Tex2D  screenshot = this._selectedMod.screenshot;
                         Stream stream     = (Stream)DuckFile.Create(path1);
                         ((Texture2D)screenshot.nativeObject).SaveAsPng(stream, screenshot.width, screenshot.height);
                         stream.Dispose();
                     }
                     dat.previewPath = path1;
                     string str = DuckFile.workshopDirectory + (object)this._transferItem.id + "/content";
                     if (Directory.Exists(str))
                     {
                         Directory.Delete(str, true);
                     }
                     DuckFile.CreatePath(str);
                     UIModManagement.DirectoryCopy(this._selectedMod.configuration.directory, str + "/" + this._selectedMod.configuration.name, true);
                     if (Directory.Exists(str + this._selectedMod.configuration.name + "/build"))
                     {
                         Directory.Delete(str + this._selectedMod.configuration.name + "/build", true);
                     }
                     if (Directory.Exists(str + this._selectedMod.configuration.name + "/.vs"))
                     {
                         Directory.Delete(str + this._selectedMod.configuration.name + "/.vs", true);
                     }
                     if (File.Exists(str + this._selectedMod.configuration.name + "/" + this._selectedMod.configuration.name + "_compiled.dll"))
                     {
                         string path2 = str + this._selectedMod.configuration.name + "/" + this._selectedMod.configuration.name + "_compiled.dll";
                         File.SetAttributes(path2, FileAttributes.Normal);
                         File.Delete(path2);
                     }
                     if (File.Exists(str + this._selectedMod.configuration.name + "/" + this._selectedMod.configuration.name + "_compiled.hash"))
                     {
                         string path2 = str + this._selectedMod.configuration.name + "/" + this._selectedMod.configuration.name + "_compiled.hash";
                         File.SetAttributes(path2, FileAttributes.Normal);
                         File.Delete(path2);
                     }
                     dat.contentFolder = str;
                     this._transferItem.ApplyWorkshopData(dat);
                     if (this._transferItem.needsLegal)
                     {
                         Steam.ShowWorkshopLegalAgreement("312530");
                     }
                     this._transferring = true;
                     this._transferItem.ResetProcessing();
                 }
             }
             else if (this._transferItem.finishedProcessing)
             {
                 Steam.OverlayOpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=" + (object)this._transferItem.id);
                 Directory.Delete(DuckFile.workshopDirectory + (object)this._transferItem.id + "/", true);
                 this._transferItem.ResetProcessing();
                 this._transferItem = (WorkshopItem)null;
                 this._transferring = false;
             }
             base.Update();
             return;
         }
         if (this._gamepadMode)
         {
             if (this._hoverIndex < 0)
             {
                 this._hoverIndex = 0;
             }
         }
         else
         {
             this._hoverIndex = -1;
             for (int index = 0; index < this._maxModsToShow && this._scrollItemOffset + index < this._mods.Count; ++index)
             {
                 if (new Rectangle((float)(int)(this._box.x - this._box.halfWidth), (float)(int)(this._box.y - this._box.halfHeight + (float)(36 * index)), (float)((int)this._box.width - 14), 36f).Contains(Mouse.position))
                 {
                     this._hoverIndex = this._scrollItemOffset + index;
                     break;
                 }
             }
         }
         if (this._transferItem != null)
         {
             if (this._updateTextBox != null)
             {
                 Editor.hoverTextBox           = false;
                 this._updateTextBox.position  = new Vec2((float)((double)this._box.x - (double)this._box.halfWidth + 16.0), (float)((double)this._box.y - (double)this._box.halfHeight + 48.0));
                 this._updateTextBox.size      = new Vec2(this._box.width - 32f, this._box.height - 80f);
                 this._updateTextBox._maxLines = (int)((double)this._updateTextBox.size.y / (double)this._fancyFont.characterHeight);
                 this._updateTextBox.Update();
                 float stringWidth = DuckGame.Graphics.GetStringWidth(this._updateButtonText, scale: 2f);
                 float height      = DuckGame.Graphics.GetStringHeight(this._updateButtonText) * 2f;
                 this._updateButton = new Rectangle(this._box.x - stringWidth / 2f, (float)((double)this._box.y + (double)this._box.halfHeight - 24.0), stringWidth, height);
                 if (this._updateButton.Contains(Mouse.position) && Mouse.left == InputState.Pressed)
                 {
                     this._needsUpdateNotes = false;
                     this._updateTextBox.LoseFocus();
                 }
                 else if (Keyboard.Pressed(Keys.Escape))
                 {
                     this._needsUpdateNotes = false;
                     this._transferItem     = (WorkshopItem)null;
                     this._updateTextBox.LoseFocus();
                     new UIMenuActionOpenMenu((UIComponent)this, (UIComponent)this._editModMenu).Activate();
                     return;
                 }
             }
         }
         else if (this._hoverIndex != -1)
         {
             this._selectedMod = this._mods[this._hoverIndex];
             if (Input.Pressed("SHOOT"))
             {
                 if (this._selectedMod != null && this._selectedMod.configuration != null)
                 {
                     if (this._selectedMod.configuration.disabled)
                     {
                         this._selectedMod.configuration.Enable();
                     }
                     else
                     {
                         this._selectedMod.configuration.Disable();
                     }
                     this.modsChanged = true;
                     SFX.Play("rockHitGround", 0.8f);
                 }
             }
             else if (Input.Pressed("SELECT") && this._pressWait == 0 && this._gamepadMode || !this._gamepadMode && Mouse.left == InputState.Pressed)
             {
                 if (this._selectedMod != null)
                 {
                     this._editModMenu.title = this._selectedMod.configuration.loaded ? "|YELLOW|" + this._selectedMod.configuration.displayName : "|YELLOW|" + this._selectedMod.configuration.name;
                     this._editModMenu.Remove((UIComponent)this._deleteOrUnsubItem);
                     this._editModMenu.Remove((UIComponent)this._uploadItem);
                     this._editModMenu.Remove((UIComponent)this._visitItem);
                     if (!this._selectedMod.configuration.isWorkshop && this._selectedMod.configuration.loaded)
                     {
                         this._uploadItem.text = this._selectedMod.configuration.workshopID == 0UL ? "UPLOAD" : "UPDATE";
                         this._editModMenu.Insert((UIComponent)this._uploadItem, 1, true);
                     }
                     if (!this._selectedMod.configuration.isWorkshop && !this._selectedMod.configuration.loaded)
                     {
                         this._deleteOrUnsubItem.text = "DELETE";
                         this._editModMenu.Insert((UIComponent)this._deleteOrUnsubItem, 1, true);
                     }
                     else if (this._selectedMod.configuration.isWorkshop)
                     {
                         this._deleteOrUnsubItem.text = "UNSUBSCRIBE";
                         this._editModMenu.Insert((UIComponent)this._deleteOrUnsubItem, 1, true);
                     }
                     if (this._selectedMod.configuration.isWorkshop)
                     {
                         this._editModMenu.Insert((UIComponent)this._visitItem, 1, true);
                     }
                     this._disableOrEnableItem.text = this._selectedMod.configuration.disabled ? "ENABLE" : "DISABLE";
                     this._editModMenu.dirty        = true;
                     SFX.Play("rockHitGround", 0.8f);
                     new UIMenuActionOpenMenu((UIComponent)this, (UIComponent)this._editModMenu).Activate();
                     return;
                 }
                 Steam.OverlayOpenURL("http://steamcommunity.com/workshop/browse/?appid=312530&searchtext=&childpublishedfileid=0&browsesort=trend&section=readytouseitems&requiredtags%5B%5D=Mod");
             }
         }
         else
         {
             this._selectedMod = (Mod)null;
         }
         if (this._gamepadMode)
         {
             this._draggingScrollbar = false;
             if (Input.Pressed("DOWN"))
             {
                 ++this._hoverIndex;
             }
             else if (Input.Pressed("UP"))
             {
                 --this._hoverIndex;
             }
             if (Input.Pressed("STRAFE"))
             {
                 this._hoverIndex -= 10;
             }
             else if (Input.Pressed("RAGDOLL"))
             {
                 this._hoverIndex += 10;
             }
             if (this._hoverIndex < 0)
             {
                 this._hoverIndex = 0;
             }
             if ((double)(this._oldPos - Mouse.positionScreen).lengthSq > 200.0)
             {
                 this._gamepadMode = false;
             }
         }
         else
         {
             if (!this._draggingScrollbar)
             {
                 if (Mouse.left == InputState.Pressed && this.ScrollBarBox().Contains(Mouse.position))
                 {
                     this._draggingScrollbar = true;
                     this._oldPos            = Mouse.position;
                 }
                 if ((double)Mouse.scroll > 0.0)
                 {
                     this._scrollItemOffset += 5;
                     this._hoverIndex       += 5;
                 }
                 else if ((double)Mouse.scroll < 0.0)
                 {
                     this._scrollItemOffset -= 5;
                     this._hoverIndex       -= 5;
                     if (this._hoverIndex < 0)
                     {
                         this._hoverIndex = 0;
                     }
                 }
             }
             else if (Mouse.left != InputState.Down)
             {
                 this._draggingScrollbar = false;
             }
             else
             {
                 Vec2 vec2 = Mouse.position - this._oldPos;
                 this._oldPos          = Mouse.position;
                 this.scrollBarOffset += (int)vec2.y;
                 if (this.scrollBarOffset > this.scrollBarScrollableHeight)
                 {
                     this.scrollBarOffset = this.scrollBarScrollableHeight;
                 }
                 else if (this.scrollBarOffset < 0)
                 {
                     this.scrollBarOffset = 0;
                 }
                 this._scrollItemOffset = (int)((double)(this._mods.Count - this._maxModsToShow) * (double)((float)this.scrollBarOffset / (float)this.scrollBarScrollableHeight));
             }
             if (Input.Pressed("ANY"))
             {
                 this._gamepadMode = true;
                 this._oldPos      = Mouse.positionScreen;
             }
         }
         if (this._scrollItemOffset < 0)
         {
             this._scrollItemOffset = 0;
         }
         else if (this._scrollItemOffset > Math.Max(0, this._mods.Count - this._maxModsToShow))
         {
             this._scrollItemOffset = Math.Max(0, this._mods.Count - this._maxModsToShow);
         }
         if (this._hoverIndex >= this._mods.Count)
         {
             this._hoverIndex = this._mods.Count - 1;
         }
         else if (this._hoverIndex >= this._scrollItemOffset + this._maxModsToShow)
         {
             this._scrollItemOffset += this._hoverIndex - (this._scrollItemOffset + this._maxModsToShow) + 1;
         }
         else if (this._hoverIndex >= 0 && this._hoverIndex < this._scrollItemOffset)
         {
             this._scrollItemOffset -= this._scrollItemOffset - this._hoverIndex;
         }
         this.scrollBarOffset = this._scrollItemOffset == 0 ? 0 : (int)Lerp.FloatSmooth(0.0f, (float)this.scrollBarScrollableHeight, (float)this._scrollItemOffset / (float)(this._mods.Count - this._maxModsToShow));
         if (!Editor.hoverTextBox && !UIMenu.globalUILock && (Input.Pressed("QUACK") || Keyboard.Pressed(Keys.Escape)))
         {
             if (this.modsChanged)
             {
                 this.Close();
                 MonoMain.pauseMenu = DuckNetwork.OpenModsRestartWindow(this._openOnClose);
             }
             else
             {
                 new UIMenuActionOpenMenu((UIComponent)this, (UIComponent)this._openOnClose).Activate();
             }
             this.modsChanged = false;
             return;
         }
     }
     if (this._showingMenu)
     {
         HUD.CloseAllCorners();
         this._showingMenu = false;
     }
     base.Update();
 }
Example #9
0
 public static T LoadChunk <T>(string path) where T : BinaryClassChunk
 {
     DuckFile.CreatePath(Path.GetDirectoryName(path));
     DuckFile.PrepareToLoadCloudFile(path);
     return(!File.Exists(path) ? default(T) : BinaryClassChunk.FromData <T>(new BitBuffer(File.ReadAllBytes(path), 0, false)));
 }
Example #10
0
 public static LevelData LoadLevel(string path)
 {
     DuckFile.CreatePath(Path.GetDirectoryName(path));
     DuckFile.PrepareToLoadCloudFile(path);
     return(!File.Exists(path) ? (LevelData)null : DuckFile.LoadLevel(File.ReadAllBytes(path)));
 }
Example #11
0
 public static FileStream Create(string path)
 {
     DuckFile.CreatePath(path);
     return(File.Create(path));
 }
 public override void Update()
 {
     if (this._doingPublish && this._currentItem != null)
     {
         if (!this._currentItem.finishedProcessing)
         {
             return;
         }
         if (this._uploading)
         {
             this._uploading = false;
             if (this._currentItem.needsLegal)
             {
                 Steam.ShowWorkshopLegalAgreement("312530");
             }
             this._upload.Close();
             if (this._currentItem.result == SteamResult.OK)
             {
                 this._notify.Open("Item published!");
             }
             else
             {
                 this._notify.Open("Failed (" + this._currentItem.result.ToString() + ")");
             }
             this._doingPublish = false;
         }
         else if (this._currentItem.result == SteamResult.OK)
         {
             this._uploading = true;
             WorkshopItemData dat = new WorkshopItemData();
             dat.name        = this._nameBox.text;
             dat.description = this._descriptionBox.text;
             dat.visibility  = RemoteStoragePublishedFileVisibility.Public;
             dat.tags        = new List <string>();
             if (this._levelType == LevelType.ArcadeMachine)
             {
                 dat.tags.Add("Machine");
             }
             else
             {
                 dat.tags.Add("Map");
             }
             dat.tags.Add(this._levelSize.ToString());
             if (this._levelType != LevelType.Deathmatch)
             {
                 dat.tags.Add(this._levelType.ToString());
             }
             Editor.workshopName        = dat.name;
             Editor.workshopDescription = dat.description;
             Editor.workshopAuthor      = Steam.user.name;
             Editor.workshopID          = this._currentItem.id;
             if (this._addDeathmatchTag)
             {
                 dat.tags.Add("Deathmatch");
                 Editor.workshopLevelDeathmatchReady = true;
             }
             else if (this._addMachineTag)
             {
                 dat.tags.Add("Arcade Machine");
                 Editor.workshopLevelDeathmatchReady = true;
             }
             else if (this._levelType == LevelType.Deathmatch)
             {
                 dat.tags.Add("Strange");
             }
             dat.tags.AddRange((IEnumerable <string>)Editor.workshopTags);
             if (this._extraTags != null && ((IEnumerable <string>) this._extraTags).Count <string>() > 0)
             {
                 dat.tags.AddRange((IEnumerable <string>) this._extraTags);
             }
             (Level.current as Editor).Save();
             this._workshopID = this._currentItem.id;
             string pathString1 = DuckFile.workshopDirectory + (object)this._workshopID + "/";
             string pathString2 = DuckFile.workshopDirectory + (object)this._workshopID + "-preview/";
             DuckFile.CreatePath(pathString1);
             DuckFile.CreatePath(pathString2);
             string withoutExtension = Path.GetFileNameWithoutExtension(this._filePath);
             string str = pathString1 + Path.GetFileName(this._filePath);
             if (File.Exists(str))
             {
                 File.Delete(str);
             }
             File.Copy(this._filePath, str);
             File.SetAttributes(this._filePath, FileAttributes.Normal);
             dat.contentFolder = pathString1;
             string path = pathString2 + withoutExtension + ".png";
             if (File.Exists(path))
             {
                 File.Delete(path);
             }
             Stream stream = (Stream)DuckFile.Create(path);
             ((Texture2D)this._previewTarget.texture.nativeObject).SaveAsPng(stream, this._previewTarget.width, this._previewTarget.height);
             stream.Dispose();
             dat.previewPath = path;
             this._currentItem.ApplyWorkshopData(dat);
             if (this._currentItem.needsLegal)
             {
                 Steam.ShowWorkshopLegalAgreement("312530");
             }
             this._upload.Open("Uploading...", this._currentItem);
         }
         else
         {
             this._notify.Open("Failed (" + this._currentItem.result.ToString() + ")");
             this._doingPublish = false;
         }
         this._currentItem.ResetProcessing();
     }
     else if (!this.opened || this._opening || (this._confirm.opened || this._upload.opened) || (this._deathmatchTest.opened || this._arcadeTest.opened || this._testSuccess.opened))
     {
         if (this.opened)
         {
             Keyboard.keyString = "";
         }
         this._opening = false;
         foreach (ContextMenu contextMenu in this._items)
         {
             contextMenu.disabled = true;
         }
     }
     else if (this._confirm.result)
     {
         if (this._levelType == LevelType.ArcadeMachine)
         {
             this._arcadeTest.Open("This machine can automatically show up in generated arcades, if you pass this validity test. You need to get the Developer trophy on all 3 challenges (oh boy)!");
         }
         else
         {
             this._deathmatchTest.Open("In order to upload this map as a deathmatch level, all ducks need to be able to be eliminated. Do you want to launch the map and show that the map is functional? You don't have to do this, but the map won't show up with the DEATHMATCH tag without completing this test. If this is a challenge map, then don't worry about it!");
         }
         this._confirm.result = false;
     }
     else if (this._testing)
     {
         Keyboard.keyString = "";
         if (DeathmatchTestDialogue.success)
         {
             this._testSuccess.Open("Test success! The level can now be published as a deathmatch level!");
             this._addDeathmatchTag = true;
         }
         else if (ArcadeTestDialogue.success)
         {
             if (this._arcadeTestIndex != 2)
             {
                 ++this._arcadeTestIndex;
                 ArcadeTestDialogue.success       = false;
                 ArcadeTestDialogue.currentEditor = Level.current as Editor;
                 Level.current = this._arcadeTestIndex != 0 ? (this._arcadeTestIndex != 1 ? (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge03Data, true) : (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge02Data, true)) : (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge01Data, true);
                 this._testing = true;
                 return;
             }
             this._testSuccess.Open("Test success! The arcade machine can now be published to the workshop!");
             this._addMachineTag = true;
         }
         else if (DeathmatchTestDialogue.tooSlow)
         {
             this._notify.Open("Framerate too low!");
         }
         else
         {
             this._notify.Open("Testing failed.");
             this._arcadeTestIndex = 0;
         }
         DeathmatchTestDialogue.success = false;
         ArcadeTestDialogue.success     = false;
         this._testing = false;
     }
     else if (this._testSuccess.result)
     {
         this._doingPublish = true;
         if (this._currentItem == null)
         {
             this._currentItem = Steam.CreateItem();
         }
         else
         {
             this._currentItem.SkipProcessing();
         }
         this._testSuccess.result = false;
     }
     else if (this._deathmatchTest.result != -1)
     {
         if (this._deathmatchTest.result == 1)
         {
             this._doingPublish = true;
             if (this._currentItem == null)
             {
                 this._currentItem = Steam.CreateItem();
             }
             else
             {
                 this._currentItem.SkipProcessing();
             }
         }
         else if (this._deathmatchTest.result == 0)
         {
             DeathmatchTestDialogue.success       = false;
             DeathmatchTestDialogue.currentEditor = Level.current as Editor;
             Level.current = (Level) new GameLevel(this._filePath, validityTest: true);
             this._testing = true;
         }
         this._deathmatchTest.result = -1;
     }
     else if (this._arcadeTest.result != -1)
     {
         if (this._arcadeTest.result == 1)
         {
             this._doingPublish = true;
             if (this._currentItem == null)
             {
                 this._currentItem = Steam.CreateItem();
             }
             else
             {
                 this._currentItem.SkipProcessing();
             }
         }
         else if (this._arcadeTest.result == 0)
         {
             ArcadeTestDialogue.success       = false;
             ArcadeTestDialogue.currentEditor = Level.current as Editor;
             Level.current = (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge01Data, true);
             this._testing = true;
         }
         this._arcadeTest.result = -1;
     }
     else
     {
         if (this._tagMenu != null)
         {
             return;
         }
         Vec2 vec2 = new Vec2((float)((double)this.layer.width / 2.0 - (double)this.width / 2.0) + this.hOffset, (float)((double)this.layer.height / 2.0 - (double)this.height / 2.0 - 15.0)) + new Vec2(7f, 276f);
         foreach (KeyValuePair <string, Vec2> tagPosition in this.tagPositions)
         {
             if ((double)Mouse.x > (double)tagPosition.Value.x && (double)Mouse.x < (double)tagPosition.Value.x + 8.0 && ((double)Mouse.y > (double)tagPosition.Value.y && (double)Mouse.y < (double)tagPosition.Value.y + 8.0) && Mouse.left == InputState.Pressed)
             {
                 Editor.workshopTags.Remove(tagPosition.Key);
                 return;
             }
         }
         if (this.tagPositions.Count != this._possibleTags.Count)
         {
             bool flag = false;
             if ((double)Mouse.x > (double)this._plusPosition.x && (double)Mouse.x < (double)this._plusPosition.x + 8.0 && ((double)Mouse.y > (double)this._plusPosition.y && (double)Mouse.y < (double)this._plusPosition.y + 8.0))
             {
                 flag = true;
             }
             if (flag && Mouse.left == InputState.Pressed)
             {
                 ContextMenu contextMenu = new ContextMenu((IContextListener)this);
                 contextMenu.x     = this._plusPosition.x;
                 contextMenu.y     = this._plusPosition.y;
                 contextMenu.root  = true;
                 contextMenu.depth = this.depth + 20;
                 int num = 0;
                 foreach (string possibleTag in this._possibleTags)
                 {
                     if (!Editor.workshopTags.Contains(possibleTag))
                     {
                         contextMenu.AddItem(new ContextMenu((IContextListener)this)
                         {
                             itemSize =
                             {
                                 x = 40f
                             },
                             text = possibleTag
                         });
                         ++num;
                     }
                 }
                 contextMenu.y -= (float)(num * 16 + 10);
                 Level.Add((Thing)contextMenu);
                 contextMenu.opened       = true;
                 contextMenu.closeOnRight = true;
                 this._tagMenu            = contextMenu;
                 return;
             }
         }
         Editor.lockInput = (ContextMenu)this;
         this._descriptionBox.Update();
         this._nameBox.Update();
         this._acceptHover = false;
         this._cancelHover = false;
         if ((double)Mouse.x > (double)this._acceptPos.x && (double)Mouse.x < (double)this._acceptPos.x + (double)this._acceptSize.x && ((double)Mouse.y > (double)this._acceptPos.y && (double)Mouse.y < (double)this._acceptPos.y + (double)this._acceptSize.y))
         {
             this._acceptHover = true;
         }
         if ((double)Mouse.x > (double)this._cancelPos.x && (double)Mouse.x < (double)this._cancelPos.x + (double)this._cancelSize.x && ((double)Mouse.y > (double)this._cancelPos.y && (double)Mouse.y < (double)this._cancelPos.y + (double)this._cancelSize.y))
         {
             this._cancelHover = true;
         }
         if (this._acceptHover && Mouse.left == InputState.Pressed)
         {
             if (this._nameBox.text == "")
             {
                 this._notify.Open("Please enter a name :(");
             }
             else
             {
                 this._confirm.Open("Upload to workshop?");
             }
         }
         if (this._cancelHover && Mouse.left == InputState.Pressed)
         {
             this.Close();
         }
         base.Update();
     }
 }
Example #13
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();
        }