Пример #1
0
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            if (!UIServerBrowser._clientMap.ContainsKey(sender))
            {
                return;
            }
            ulong client = UIServerBrowser._clientMap[sender];

            UIServerBrowser._clientMap.Remove(sender);
            if (!UIServerBrowser._previewMap.ContainsKey(client))
            {
                return;
            }
            Texture2D texture2D = ContentPack.LoadTexture2D(this.PreviewPathForWorkshopItem(client), false);

            if (texture2D == null)
            {
                return;
            }
            Tex2D tex2D = (Tex2D)texture2D;

            if (tex2D == null)
            {
                return;
            }
            UIServerBrowser._previewMap[client] = tex2D;
        }
 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;
                 }
             }
         }
     }
 }
Пример #3
0
 public static T Load <T>(string name)
 {
     if (typeof(T) == typeof(Tex2D))
     {
         Tex2D tex2D = (Tex2D)null;
         lock (DuckGame.Content._textures)
             DuckGame.Content._textures.TryGetValue(name, out tex2D);
         if (tex2D == null)
         {
             Texture2D tex  = (Texture2D)null;
             bool      flag = false;
             if (MonoMain.moddingEnabled && ModLoader.modsEnabled && (name.Length > 1 && name[1] == ':'))
             {
                 flag = true;
             }
             if (!flag)
             {
                 lock (DuckGame.Content._loadLock)
                 {
                     try
                     {
                         tex = DuckGame.Content._base.Load <Texture2D>(name);
                     }
                     catch
                     {
                         flag = MonoMain.moddingEnabled && ModLoader.modsEnabled;
                     }
                 }
             }
             if (flag)
             {
                 foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
                 {
                     if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
                     {
                         tex = accessibleMod.configuration.content.Load <Texture2D>(name);
                     }
                     if (tex != null)
                     {
                         break;
                     }
                 }
             }
             else if (tex == null)
             {
                 try
                 {
                     tex = ContentPack.LoadTexture2D(name);
                 }
                 catch (Exception ex)
                 {
                 }
             }
             if (tex == null)
             {
                 tex = (Texture2D)DuckGame.Content.invalidTexture;
                 Main.SpecialCode = "Couldn't load texture " + name;
             }
             lock (DuckGame.Content._loadLock)
             {
                 tex2D = new Tex2D(tex, name, DuckGame.Content._currentTextureIndex);
                 ++DuckGame.Content._currentTextureIndex;
                 DuckGame.Content._textureList.Add(tex2D);
                 DuckGame.Content._textures[name]            = tex2D;
                 DuckGame.Content._texture2DMap[(object)tex] = tex2D;
             }
         }
         return((T)(Object)tex2D);
     }
     if (typeof(T) == typeof(MTEffect))
     {
         MTEffect mtEffect = (MTEffect)null;
         lock (DuckGame.Content._effects)
             DuckGame.Content._effects.TryGetValue(name, out mtEffect);
         if (mtEffect == null)
         {
             Effect effect = (Effect)null;
             lock (DuckGame.Content._loadLock)
                 effect = DuckGame.Content._base.Load <Effect>(name);
             lock (DuckGame.Content._loadLock)
             {
                 mtEffect = new MTEffect(effect, name, DuckGame.Content._currentEffectIndex);
                 ++DuckGame.Content._currentEffectIndex;
                 DuckGame.Content._effectList.Add(mtEffect);
                 DuckGame.Content._effects[name]     = mtEffect;
                 DuckGame.Content._effectMap[effect] = mtEffect;
             }
         }
         return((T)(Object)mtEffect);
     }
     if (typeof(T) == typeof(SoundEffect))
     {
         SoundEffect soundEffect = (SoundEffect)null;
         lock (DuckGame.Content._loadLock)
         {
             try
             {
                 soundEffect = DuckGame.Content._base.Load <SoundEffect>(name);
             }
             catch
             {
             }
         }
         if (MonoMain.moddingEnabled && ModLoader.modsEnabled && soundEffect == null)
         {
             foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
             {
                 if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
                 {
                     soundEffect = accessibleMod.configuration.content.Load <SoundEffect>(name);
                 }
                 if (soundEffect != null)
                 {
                     break;
                 }
             }
         }
         return((T)(Object)soundEffect);
     }
     if (!(typeof(T) == typeof(Song)))
     {
         return(DuckGame.Content._base.Load <T>(name));
     }
     if (MonoMain.moddingEnabled && ModLoader.modsEnabled)
     {
         foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
         {
             if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
             {
                 Song song = accessibleMod.configuration.content.Load <Song>(name);
                 if (song != null)
                 {
                     return((T)(Object)song);
                 }
             }
         }
     }
     return(default(T));
 }
 public override void Update()
 {
     if (this._testMode)
     {
         this._wait += Maths.IncFrameTimer();
         if (Keyboard.Pressed(Keys.F5) || (double)this._wait > 0.1)
         {
             this._wait = 0.0f;
             try
             {
                 this._tie        = new SpriteMap((Tex2D)ContentPack.LoadTexture2D("tieTest.png"), 64, 64);
                 this._tie.center = new Vec2(26f, 27f);
             }
             catch (Exception ex)
             {
             }
         }
     }
     DuckGame.Graphics.fadeAdd = Lerp.Float(DuckGame.Graphics.fadeAdd, 0.0f, 0.01f);
     if (Main.isDemo && this._skip && !this._firedSkipLogic)
     {
         this._firedSkipLogic = true;
         Vote.CloseVoting();
         HUD.CloseAllCorners();
         this.DoSkip();
     }
     if ((double)DuckGame.Graphics.fade > 0.990000009536743 && !this._skip && Vote.Passed(VoteType.Skip))
     {
         this._skip = true;
     }
     if (this._talker.finished || !HighlightLevel._cancelSkip && this._skip && !Main.isDemo)
     {
         this._done -= 0.04f;
     }
     DuckGame.Graphics.fade = Lerp.Float(DuckGame.Graphics.fade, (double)this._done < 0.0 ? 0.0f : 1f, 0.02f);
     if ((double)DuckGame.Graphics.fade < 0.00999999977648258 && (this._talker.finished || this._skip))
     {
         if (this._endOfHighlights || this._skip)
         {
             Vote.CloseVoting();
             Level.current = (Level) new RockScoreboard(RockScoreboard.returnLevel, ScoreBoardMode.ShowWinner, true);
         }
         else
         {
             Level.current = (Level) new HighlightPlayback(4);
         }
     }
     if (this._state == TVState.ShowPedestals)
     {
         this._waitZoom -= 0.008f;
         if ((double)this._waitZoom < 0.00999999977648258)
         {
             this._waitZoom     = 0.0f;
             this._desiredState = TVState.ShowNewscaster;
         }
     }
     if (this._state == TVState.ShowHotness && this._hotness.ready)
     {
         this._talker.Resume();
     }
     if (this._state == TVState.ShowInterview)
     {
         this._interviewWait -= 0.02f;
         if ((double)this._interviewWait < 0.0 && !this._askedQuestion)
         {
             this._talker.InsertLine(Script.winner() + "! To what do you attribute your success?", this._interviewIndex);
             this._talker.Resume();
             this._askedQuestion = true;
         }
     }
     this._cameraOffset.x = Lerp.Float(this._cameraOffset.x, HighlightLevel._image != null ? 20f : 0.0f, 2f);
     this._talker.active  = this._talker.visible = this._state != TVState.ShowPedestals;
     if (this._state == this._desiredState)
     {
         return;
     }
     this._talker.active = false;
     this._transition.PlaySwipe();
     if (!this._transition.doTransition)
     {
         return;
     }
     this._state = this._desiredState;
 }
Пример #5
0
        public static CustomTileData LoadTileData(string path, CustomType type)
        {
            CustomTileData customTileData = new CustomTileData();

            if (path == "" || path == null)
            {
                return(customTileData);
            }
            Texture2D texture2D = ContentPack.LoadTexture2D(DuckFile.GetCustomDirectory(type) + path + ".png");

            if (texture2D != null)
            {
                try
                {
                    Color[] data = new Color[texture2D.Width * texture2D.Height];
                    texture2D.GetData <Color>(data);
                    for (int index1 = 0; index1 < 5; ++index1)
                    {
                        int num1 = 112;
                        int num2 = 64 + index1 * 16;
                        if (index1 == 1)
                        {
                            int num3 = num2;
                            num2 = num1;
                            num1 = num3;
                        }
                        if (index1 == 3)
                        {
                            num1 = 96;
                            num2 = 112;
                        }
                        else if (index1 == 4)
                        {
                            num1 = 112;
                            num2 = 112;
                        }
                        int num4 = -1;
                        int num5 = 0;
                        for (int index2 = 0; index2 < 16; ++index2)
                        {
                            bool flag = false;
                            for (int index3 = 0; index3 < 16; ++index3)
                            {
                                int index4 = index1 != 1 ? num1 + index3 + (num2 + index2) * texture2D.Width : num2 + index2 + (num1 + index3) * texture2D.Width;
                                if (index1 == 3 || index1 == 4 ? data[index4].a != (byte)0 : data[index4].r == (byte)0 && data[index4].g == byte.MaxValue && data[index4].b == (byte)0 && data[index4].a == byte.MaxValue)
                                {
                                    if (num4 == -1)
                                    {
                                        num4 = index3;
                                    }
                                }
                                else if (num4 != -1)
                                {
                                    num5 = index3 - num4;
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                        switch (index1)
                        {
                        case 0:
                            customTileData.verticalWidth = num5;
                            break;

                        case 1:
                            customTileData.horizontalHeight = num5;
                            break;

                        case 2:
                            customTileData.verticalWidthThick = num5;
                            break;

                        case 3:
                            customTileData.leftNubber = num5 != 0;
                            break;

                        case 4:
                            customTileData.rightNubber = num5 != 0;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    texture2D = (Texture2D)null;
                }
                customTileData.texture = texture2D;
                customTileData.path    = path;
                Custom._customTilesetData[type][path] = customTileData;
            }
            return(customTileData);
        }
Пример #6
0
        void LoadTextures(string folder, string prefix)
        {
            var rootFolder = folder.Remove(0, prefix.Length);

            DirectoryInfo dir = new DirectoryInfo(folder);

            foreach (FileInfo file in dir.GetFiles("*.png"))
            {
                Textures.Add(rootFolder.TrimStart('\\') + file.Name.Substring(0, file.Name.Length - 4), TextureHelper.getTex2D(ContentPack.LoadTexture2D(file.FullName)));
            }

            foreach (var d in dir.GetDirectories())
            {
                LoadTextures(folder + '\\' + d.Name + '\\', prefix);
            }
        }