Exemplo n.º 1
0
        private void CacheTextures()
        {
            if (mTexturesFound == false && GameContentManager.Current.TilesetsLoaded)
            {
                for (var i = 0; i < Options.LayerCount; i++)
                {
                    for (var x = 0; x < Options.MapWidth; x++)
                    {
                        for (var y = 0; y < Options.MapHeight; y++)
                        {
                            var tileset = TilesetBase.Get(Layers[i].Tiles[x, y].TilesetId);
                            if (tileset != null)
                            {
                                var tilesetTex = Globals.ContentManager.GetTexture(
                                    GameContentManager.TextureType.Tileset, tileset.Name
                                    );

                                Layers[i].Tiles[x, y].TilesetTex = tilesetTex;
                            }
                        }
                    }
                }

                mTexturesFound = true;
            }
        }
Exemplo n.º 2
0
        public void SetTileset(string name)
        {
            TilesetBase tSet     = null;
            var         tilesets = TilesetBase.Lookup;
            var         id       = Guid.Empty;

            foreach (var tileset in tilesets.Pairs)
            {
                if (tileset.Value.Name.ToLower() == name.ToLower())
                {
                    id = tileset.Key;

                    break;
                }
            }

            if (id != Guid.Empty)
            {
                tSet = TilesetBase.Get(id);
            }

            if (tSet != null)
            {
                if (File.Exists("resources/tilesets/" + tSet.Name))
                {
                    picTileset.Show();
                    Globals.CurrentTileset = tSet;
                    Globals.CurSelX        = 0;
                    Globals.CurSelY        = 0;
                    var tilesetTex = GameContentManager.GetTexture(GameContentManager.TextureType.Tileset, tSet.Name);
                    if (tilesetTex != null)
                    {
                        picTileset.Width  = tilesetTex.Width;
                        picTileset.Height = tilesetTex.Height;
                    }

                    cmbTilesets.SelectedItem = name;
                    CreateSwapChain();
                }
            }
        }
Exemplo n.º 3
0
        public static void LoadTilesets()
        {
            if (!Directory.Exists("resources/tilesets"))
            {
                Directory.CreateDirectory("resources/tilesets");
            }

            var tilesets               = Directory.GetFiles("resources/tilesets", "*.png");
            var tilesetWarning         = false;
            var suppressTilesetWarning = Preferences.LoadPreference("SuppressTextureWarning");

            if (suppressTilesetWarning != "" && Convert.ToBoolean(suppressTilesetWarning))
            {
                tilesetWarning = true;
            }

            var newTilesets = new List <string>();

            Array.Sort(tilesets, new AlphanumComparatorFast());
            if (tilesets.Length > 0)
            {
                var tilesetBaseList = TilesetBase.Names;
                for (var i = 0; i < tilesets.Length; i++)
                {
                    tilesets[i] = tilesets[i].Replace("resources/tilesets\\", "");
                    if (tilesetBaseList.Length > 0)
                    {
                        for (var x = 0; x < tilesetBaseList.Length; x++)
                        {
                            if (tilesetBaseList[x].ToLower() == tilesets[i].ToLower())
                            {
                                break;
                            }

                            if (x != tilesetBaseList.Length - 1)
                            {
                                continue;
                            }

                            newTilesets.Add(tilesets[i]);
                        }
                    }
                    else
                    {
                        newTilesets.Add(tilesets[i]);
                    }
                }
            }

            sTilesetDict.Clear();
            TilesetTextures.Clear();
            var badTilesets = new List <string>();

            for (var i = 0; i < TilesetBase.Lookup.Count; i++)
            {
                var tileset = TilesetBase.Get(TilesetBase.IdFromList(i));
                if (File.Exists("resources/tilesets/" + tileset.Name))
                {
                    try
                    {
                        sTilesetDict[tileset.Name.ToLower()] = new Texture("resources/tilesets/" + tileset.Name);
                        TilesetTextures.Add(sTilesetDict[tileset.Name.ToLower()]);
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"Fake methods! ({tileset.Name})");
                        if (exception.InnerException != null)
                        {
                            Log.Error(exception.InnerException);
                        }

                        Log.Error(exception);

                        throw;
                    }

                    if (!tilesetWarning)
                    {
                        using (var img = Image.FromFile("resources/tilesets/" + tileset.Name))
                        {
                            if (img.Width > 2048 || img.Height > 2048)
                            {
                                badTilesets.Add(tileset.Name);
                            }
                        }
                    }
                }
            }

            if (badTilesets.Count > 0)
            {
                MessageBox.Show(
                    "One or more tilesets is too large and likely won't load for your players on older machines! We recommmend that no graphic is larger than 2048 pixels in width or height.\n\nFaulting tileset(s): " +
                    string.Join(",", badTilesets.ToArray()), "Large Tileset Warning!", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation
                    );
            }

            if (newTilesets.Count > 0)
            {
                PacketSender.SendNewTilesets(newTilesets.ToArray());
            }
        }