protected override void TextButtonClick(Game game, Widget widget, MouseButton mouseBtn)
        {
            if (mouseBtn != MouseButton.Left)
            {
                return;
            }
            string file = ((ButtonWidget)widget).Text;
            string dir  = Path.Combine(Program.AppDirectory, TexturePackExtractor.Dir);
            string path = Path.Combine(dir, file);

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

            int index = currentIndex;

            game.DefaultTexturePack = file;
            game.World.TextureUrl   = null;
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract(path, game);
            Recreate();
            SetCurrentIndex(index);
        }
Ejemplo n.º 2
0
        void HandleCpeEnvSetMapApperance()
        {
            string url = reader.ReadAsciiString();

            game.Map.SetSidesBlock((Block)reader.ReadUInt8());
            game.Map.SetEdgeBlock((Block)reader.ReadUInt8());
            game.Map.SetEdgeLevel(reader.ReadInt16());

            if (url == String.Empty)
            {
                TexturePackExtractor extractor = new TexturePackExtractor();
                extractor.Extract(game.DefaultTexturePack, game);
            }
            else if (Utils.IsUrlPrefix(url))
            {
                if (!game.AcceptedUrls.HasUrl(url) && !game.DeniedUrls.HasUrl(url))
                {
                    game.AsyncDownloader.RetrieveContentLength(url, true, "CL_" + url);
                    game.ShowWarning(new WarningScreen(
                                         game, "CL_" + url, "Do you want to download the server's terrain image?",
                                         DownloadTexturePack, null, WarningScreenTick,
                                         "The terrain image is located at:", url,
                                         "Terrain image size: Determining..."));
                }
                else
                {
                    DownloadTexturePack(url);
                }
            }
            Utils.LogDebug("Image url: " + url);
        }
Ejemplo n.º 3
0
        protected void ExtractDefault()
        {
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract(game.DefaultTexturePack, game);
            game.World.TextureUrl = null;
        }
Ejemplo n.º 4
0
        void CheckForNewTerrainAtlas()
        {
            DownloadedItem item;

            if (game.AsyncDownloader.TryGetItem("terrain", out item))
            {
                if (item.Data != null)
                {
                    game.ChangeTerrainAtlas((Bitmap)item.Data);
                    TextureCache.AddToCache(item.Url, (Bitmap)item.Data);
                }
                else if (Is304Status(item.WebEx))
                {
                    Bitmap bmp = TextureCache.GetBitmapFromCache(item.Url);
                    if (bmp == null)                      // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else
                    {
                        game.ChangeTerrainAtlas(bmp);
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }

            if (game.AsyncDownloader.TryGetItem("texturePack", out item))
            {
                if (item.Data != null)
                {
                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract((byte[])item.Data, game);
                    TextureCache.AddToCache(item.Url, (byte[])item.Data);
                }
                else if (Is304Status(item.WebEx))
                {
                    byte[] data = TextureCache.GetDataFromCache(item.Url);
                    if (data == null)                        // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else
                    {
                        TexturePackExtractor extractor = new TexturePackExtractor();
                        extractor.Extract(data, game);
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }
        }
Ejemplo n.º 5
0
        public void Disconnect(string title, string reason)
        {
            Gui.Reset(this);
            World.Reset();
            World.blocks = null;
            Drawer2D.InitColours();
            BlockInfo.Reset(this);

            TexturePackExtractor.ExtractDefault(this);
            Gui.SetNewScreen(new ErrorScreen(this, title, reason));
            GC.Collect();
        }
Ejemplo n.º 6
0
        void ExtractInitialTexturePack()
        {
            defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip";
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract("default.zip", this);
            // in case the user's default texture pack doesn't have all required textures
            if (DefaultTexturePack != "default.zip")
            {
                extractor.Extract(DefaultTexturePack, this);
            }
        }
Ejemplo n.º 7
0
        protected void CheckAsyncResources()
        {
            DownloadedItem item;

            if (game.AsyncDownloader.TryGetItem("terrain", out item))
            {
                TexturePackExtractor.ExtractTerrainPng(game, item);
            }
            if (game.AsyncDownloader.TryGetItem("texturePack", out item))
            {
                TexturePackExtractor.ExtractTexturePack(game, item);
            }
        }
Ejemplo n.º 8
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();
                    if (game.World.TextureUrl != null)
                    {
                        TexturePackExtractor.ExtractDefault(game);
                        game.World.TextureUrl = null;
                    }
                    game.BlockInfo.Reset(game);

                    byte[] blocks = importer.Load(fs, game, out width, out height, out length);
                    game.World.SetNewMap(blocks, width, height, length);
                    game.WorldEvents.RaiseOnNewMapLoaded();
                    if (game.AllowServerTextures && game.World.TextureUrl != null)
                    {
                        game.Server.RetrieveTexturePack(game.World.TextureUrl);
                    }

                    LocalPlayer    p      = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnYaw, p.SpawnPitch, false);
                    p.SetLocation(update, false);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                string file = Path.GetFileName(path);
                game.Chat.Add("&e/client loadmap: Failed to load map \"" + file + "\"");
            }
        }
Ejemplo n.º 9
0
        protected override void TextButtonClick(Game game, Widget widget)
        {
            string file = ((ButtonWidget)widget).Text;
            string dir  = Path.Combine(Program.AppDirectory, TexturePackExtractor.Dir);
            string path = Path.Combine(dir, file);

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

            game.DefaultTexturePack = file;
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract(path, game);
            Recreate();
        }
Ejemplo n.º 10
0
        void HandleSetMapEnvUrl()
        {
            string url = reader.ReadAsciiString();

            if (!game.AllowServerTextures)
            {
                return;
            }

            if (url == "")
            {
                TexturePackExtractor.ExtractDefault(game);
            }
            else if (Utils.IsUrlPrefix(url, 0))
            {
                net.RetrieveTexturePack(url);
            }
            Utils.LogDebug("Image url: " + url);
        }
        void HandleCpeEnvSetMapApperance()
        {
            string url = reader.ReadAsciiString();

            game.Map.SetSidesBlock((Block)reader.ReadUInt8());
            game.Map.SetEdgeBlock((Block)reader.ReadUInt8());
            game.Map.SetEdgeLevel(reader.ReadInt16());
            if (!game.AllowServerTextures)
            {
                return;
            }

            if (url == String.Empty)
            {
                TexturePackExtractor extractor = new TexturePackExtractor();
                extractor.Extract(game.DefaultTexturePack, game);
                game.Map.TextureUrl = null;
            }
            else if (Utils.IsUrlPrefix(url, 0))
            {
                RetrieveTexturePack(url);
            }
            Utils.LogDebug("Image url: " + url);
        }
Ejemplo n.º 12
0
        protected void CheckAsyncResources()
        {
            DownloadedItem item;

            if (game.AsyncDownloader.TryGetItem("terrain", out item))
            {
                if (item.Data != null)
                {
                    Bitmap bmp = (Bitmap)item.Data;
                    game.World.TextureUrl = item.Url;
                    game.Events.RaiseTexturePackChanged();

                    if (!FastBitmap.CheckFormat(bmp.PixelFormat))
                    {
                        Utils.LogDebug("Converting terrain atlas to 32bpp image");
                        game.Drawer2D.ConvertTo32Bpp(ref bmp);
                    }
                    if (!game.ChangeTerrainAtlas(bmp))
                    {
                        bmp.Dispose(); return;
                    }
                    TextureCache.AddToCache(item.Url, bmp);
                    TextureCache.AddETagToCache(item.Url, item.ETag, game.ETags);
                }
                else if (item.ResponseCode == HttpStatusCode.NotModified)
                {
                    Bitmap bmp = TextureCache.GetBitmapFromCache(item.Url);
                    if (bmp == null)                       // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else if (item.Url != game.World.TextureUrl)
                    {
                        game.Events.RaiseTexturePackChanged();
                        if (!game.ChangeTerrainAtlas(bmp))
                        {
                            bmp.Dispose(); return;
                        }
                    }

                    if (bmp != null)
                    {
                        game.World.TextureUrl = item.Url;
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }

            if (game.AsyncDownloader.TryGetItem("texturePack", out item))
            {
                if (item.Data != null)
                {
                    game.World.TextureUrl = item.Url;

                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract((byte[])item.Data, game);
                    TextureCache.AddToCache(item.Url, (byte[])item.Data);
                    TextureCache.AddETagToCache(item.Url, item.ETag, game.ETags);
                }
                else if (item.ResponseCode == HttpStatusCode.NotModified)
                {
                    byte[] data = TextureCache.GetDataFromCache(item.Url);
                    if (data == null)                        // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else if (item.Url != game.World.TextureUrl)
                    {
                        TexturePackExtractor extractor = new TexturePackExtractor();
                        extractor.Extract(data, game);
                    }

                    if (data != null)
                    {
                        game.World.TextureUrl = item.Url;
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }
        }
Ejemplo n.º 13
0
        protected void CheckAsyncResources()
        {
            DownloadedItem item;

            if (game.AsyncDownloader.TryGetItem("terrain", out item))
            {
                if (item.Data != null)
                {
                    Bitmap bmp = (Bitmap)item.Data;
                    if (!FastBitmap.CheckFormat(bmp.PixelFormat))
                    {
                        Utils.LogDebug("Converting terrain atlas to 32bpp image");
                        game.Drawer2D.ConvertTo32Bpp(ref bmp);
                    }
                    game.ChangeTerrainAtlas(bmp);
                    TextureCache.AddToCache(item.Url, bmp);
                    game.Map.TextureUrl = item.Url;
                }
                else if (Is304Status(item.WebEx))
                {
                    Bitmap bmp = TextureCache.GetBitmapFromCache(item.Url);
                    if (bmp == null)                      // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else
                    {
                        game.ChangeTerrainAtlas(bmp);
                    }
                    game.Map.TextureUrl = item.Url;
                }
                else
                {
                    ExtractDefault();
                    game.Map.TextureUrl = null;
                }
            }

            if (game.AsyncDownloader.TryGetItem("texturePack", out item))
            {
                if (item.Data != null)
                {
                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract((byte[])item.Data, game);
                    TextureCache.AddToCache(item.Url, (byte[])item.Data);
                    game.Map.TextureUrl = item.Url;
                }
                else if (Is304Status(item.WebEx))
                {
                    byte[] data = TextureCache.GetDataFromCache(item.Url);
                    if (data == null)                        // Should never happen, but handle anyways.
                    {
                        ExtractDefault();
                    }
                    else
                    {
                        TexturePackExtractor extractor = new TexturePackExtractor();
                        extractor.Extract(data, game);
                    }
                    game.Map.TextureUrl = item.Url;
                }
                else
                {
                    ExtractDefault();
                    game.Map.TextureUrl = null;
                }
            }
        }
Ejemplo n.º 14
0
        protected void ExtractDefault()
        {
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract(game.DefaultTexturePack, game);
        }
Ejemplo n.º 15
0
        protected override void OnLoad(EventArgs e)
        {
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();
            Players = new EntityList(this);

            Options.Load();
            AcceptedUrls.Load(); DeniedUrls.Load();
            ViewDistance     = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512);
            UserViewDistance = ViewDistance;
            CameraClipping   = Options.GetBool(OptionsKey.CameraClipping, true);
            InputHandler     = new InputHandler(this);
            Chat             = new ChatLog(this);
            ParticleManager  = new ParticleManager(this);
            HudScale         = Options.GetFloat(OptionsKey.HudScale, 0.25f, 5f, 1f);
            ChatScale        = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f);
            defaultIb        = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30);
            UseClassicGui    = Options.GetBool(OptionsKey.UseClassicGui, false);
            BlockInfo        = new BlockInfo();
            BlockInfo.Init();
            ChatLines     = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12);
            ClickableChat = Options.GetBool(OptionsKey.ClickableChat, true);
            ModelCache    = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = new AsyncDownloader(skinServer);
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            Drawer2D.UseBitmappedChat = !Options.GetBool(OptionsKey.ArialChatFont, false);
            ViewBobbing               = Options.GetBool(OptionsKey.ViewBobbing, false);
            ShowBlockInHand           = Options.GetBool(OptionsKey.ShowBlockInHand, true);
            InvertMouse               = Options.GetBool(OptionsKey.InvertMouse, false);
            SimpleArmsAnim            = Options.GetBool(OptionsKey.SimpleArmsAnim, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = new Animations(this);
            defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip";
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract("default.zip", this);
            // in case the user's default texture pack doesn't have all required textures
            if (defTexturePack != "default.zip")
            {
                extractor.Extract(DefaultTexturePack, this);
            }
            Inventory = new Inventory(this);

            BlockInfo.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete);
            Map                = new Map(this);
            LocalPlayer        = new LocalPlayer(this);
            Players[255]       = LocalPlayer;
            width              = Width;
            height             = Height;
            MapRenderer        = new MapRenderer(this);
            MapBordersRenderer = new MapBordersRenderer(this);
            EnvRenderer        = new StandardEnvRenderer(this);
            if (IPAddress == null)
            {
                Network = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Network = new NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera          = firstPersonCam;
            FieldOfView     = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70);
            ZoomFieldOfView = FieldOfView;
            UpdateProjection();
            CommandManager = new CommandManager();
            CommandManager.Init(this);
            SelectionManager = new SelectionManager(this);
            WeatherRenderer  = new WeatherRenderer(this);
            WeatherRenderer.Init();
            BlockHandRenderer = new BlockHandRenderer(this);
            BlockHandRenderer.Init();

            FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync);
            SetFpsLimitMethod(method);
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            fpsScreen = new FpsScreen(this);
            fpsScreen.Init();
            hudScreen = new HudScreen(this);
            hudScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapBordersRenderer.Init();
            Picking           = new PickingRenderer(this);
            AudioPlayer       = new AudioPlayer(this);
            LiquidsBreakable  = Options.GetBool(OptionsKey.LiquidsBreakable, false);
            AxisLinesRenderer = new AxisLinesRenderer(this);

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            Graphics.WarnIfNecessary(Chat);
            SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Network.Connect(IPAddress, Port);
        }