Exemple #1
0
        static void SetMipmaps(Game g, string v)
        {
            g.Graphics.Mipmaps = SetBool(v, OptionsKey.Mipmaps);

            string url = g.World.TextureUrl;

            if (url == null)
            {
                TexturePack.ExtractDefault(g); return;
            }

            using (Stream data = TextureCache.GetStream(url)) {
                if (data == null)
                {
                    TexturePack.ExtractDefault(g); return;
                }

                if (url.Contains(".zip"))
                {
                    TexturePack extractor = new TexturePack();
                    extractor.Extract(data, g);
                }
                else
                {
                    TexturePack.ExtractTerrainPng(g, data, url);
                }
            }
        }
Exemple #2
0
        void LoadMap(string path)
        {
            IMapFormatImporter importer = null;

            if (path.EndsWith(".dat"))
            {
                importer = new MapDatImporter();
            }
            else if (path.EndsWith(".fcm"))
            {
                importer = new MapFcm3Importer();
            }
            else if (path.EndsWith(".cw"))
            {
                importer = new MapCwImporter();
            }
            else if (path.EndsWith(".lvl"))
            {
                importer = new MapLvlImporter();
            }

            try {
                using (FileStream fs = File.OpenRead(path)) {
                    int width, height, length;
                    game.World.Reset();
                    game.WorldEvents.RaiseOnNewMap();

                    if (game.World.TextureUrl != null)
                    {
                        TexturePack.ExtractDefault(game);
                        game.World.TextureUrl = null;
                    }
                    BlockInfo.Reset(game);
                    game.Inventory.SetDefaultMapping();

                    byte[] blocks = importer.Load(fs, game, out width, out height, out length);
                                        #if USE16_BIT
                    game.World.SetNewMap(Utils.UInt8sToUInt16s(blocks), width, height, length);
                                        #else
                    game.World.SetNewMap(blocks, width, height, length);
                                        #endif

                    game.WorldEvents.RaiseOnNewMapLoaded();
                    if (game.UseServerTextures && game.World.TextureUrl != null)
                    {
                        game.Server.RetrieveTexturePack(game.World.TextureUrl);
                    }

                    LocalPlayer    p      = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false);
                    p.SetLocation(update, false);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                string file = Path.GetFileName(path);
                game.Chat.Add("&eFailed to load map \"" + file + "\"");
            }
        }
Exemple #3
0
		void HandleSetMapEnvUrl() {
			string url = reader.ReadString();
			if (!game.UseServerTextures) return;
			
			if (url == "") {
				if (game.World.TextureUrl != null) TexturePack.ExtractDefault(game);
			} else if (Utils.IsUrlPrefix(url, 0)) {
				net.RetrieveTexturePack(url);
			}
			Utils.LogDebug("Image url: " + url);
		}
        public void Disconnect(string title, string reason)
        {
            Events.RaiseDisconnected(title, reason);

            Gui.Reset(this);
            World.Reset();
            World.blocks = null;
            Drawer2D.InitColours();
            BlockInfo.Reset(this);
            TexturePack.ExtractDefault(this);
            Gui.SetNewScreen(new ErrorScreen(this, title, reason));
            GC.Collect();
        }
        internal static void LoadMap(Game game, string path)
        {
            game.World.Reset();
            Events.RaiseOnNewMap();

            if (game.World.TextureUrl != null)
            {
                TexturePack.ExtractDefault(game);
                game.World.TextureUrl = null;
            }
            BlockInfo.Reset();
            game.Inventory.SetDefaultMapping();

            int width, height, length;

            byte[] blocks;
            try {
                using (Stream fs = Platform.FileOpen(path)) {
                    IMapFormatImporter importer = null;
                    if (path.EndsWith(".dat"))
                    {
                        importer = new MapDatImporter();
                    }
                    else if (path.EndsWith(".fcm"))
                    {
                        importer = new MapFcm3Importer();
                    }
                    else if (path.EndsWith(".cw"))
                    {
                        importer = new MapCwImporter();
                    }
                    else if (path.EndsWith(".lvl"))
                    {
                        importer = new MapLvlImporter();
                    }
                    blocks = importer.Load(fs, game, out width, out height, out length);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                game.Chat.Add("&eFailed to load map \"" + path + "\"");
                return;
            }

            game.World.SetNewMap(blocks, width, height, length);
            Events.RaiseOnNewMapLoaded();

            LocalPlayer    p      = game.LocalPlayer;
            LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false);

            p.SetLocation(update, false);
        }
        public void Disconnect(string title, string reason)
        {
            Events.RaiseDisconnected(title, reason);

            Gui.Reset(this);
            World.Reset();
            WorldEvents.RaiseOnNewMap();

            IDrawer2D.InitCols();
            BlockInfo.Reset();
            TexturePack.ExtractDefault(this);
            Gui.SetNewScreen(new DisconnectScreen(this, title, reason));
            GC.Collect();
        }
Exemple #7
0
        public void Disconnect(string title, string reason)
        {
            World.Reset();
            WorldEvents.RaiseOnNewMap();
            Gui.SetNewScreen(new DisconnectScreen(this, title, reason));

            IDrawer2D.InitCols();
            BlockInfo.Reset();
            TexturePack.ExtractDefault(this);

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Reset(this);
            }
            GC.Collect();
        }
Exemple #8
0
        protected override void EntryClick(Game game, Widget widget)
        {
            string file = GetCur(widget);
            string path = Path.Combine("texpacks", file);

            if (!Platform.FileExists(path))
            {
                return;
            }

            int cur = currentIndex;

            game.DefaultTexturePack = file;
            TexturePack.ExtractDefault(game);
            Recreate();
            SetCurrentIndex(cur);
        }
Exemple #9
0
        protected override void TextButtonClick(Game game, Widget widget)
        {
            string file = ((ButtonWidget)widget).Text;
            string dir  = Path.Combine(Program.AppDirectory, "texpacks");
            string path = Path.Combine(dir, file);

            if (!File.Exists(path))
            {
                return;
            }

            int index = currentIndex;

            game.DefaultTexturePack = file;
            TexturePack.ExtractDefault(game);
            Recreate();
            SetCurrentIndex(index);
        }