Beispiel #1
0
        void LoadGuiOptions()
        {
            ChatLines      = Options.GetInt(OptionsKey.ChatLines, 0, 30, 12);
            ClickableChat  = Options.GetBool(OptionsKey.ClickableChat, false);
            InventoryScale = Options.GetFloat(OptionsKey.InventoryScale, 0.25f, 5f, 1f);
            HotbarScale    = Options.GetFloat(OptionsKey.HotbarScale, 0.25f, 5f, 1f);
            ChatScale      = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f);
            ShowFPS        = Options.GetBool(OptionsKey.ShowFPS, true);

            UseClassicGui     = Options.GetBool(OptionsKey.ClassicGui, true) || ClassicMode;
            UseClassicTabList = Options.GetBool(OptionsKey.ClassicTabList, false) || ClassicMode;
            UseClassicOptions = Options.GetBool(OptionsKey.ClassicOptions, false) || ClassicMode;

            TabAutocomplete = Options.GetBool(OptionsKey.TabAutocomplete, false);
            FontName        = Options.Get(OptionsKey.FontName, "Arial");
            if (ClassicMode)
            {
                FontName = "Arial";
            }

            try {
                using (Font f = new Font(FontName, 16)) { }
            } catch (Exception) {
                FontName = "Arial";
                Options.Set(OptionsKey.FontName, "Arial");
            }
        }
Beispiel #2
0
        void LoadOptions()
        {
            ClassicMode       = Options.GetBool("mode-classic", false);
            ClassicHacks      = Options.GetBool(OptionsKey.AllowClassicHacks, false);
            AllowCustomBlocks = Options.GetBool(OptionsKey.AllowCustomBlocks, true);
            UseCPE            = Options.GetBool(OptionsKey.UseCPE, true);
            SimpleArmsAnim    = Options.GetBool(OptionsKey.SimpleArmsAnim, false);

            ViewBobbing = Options.GetBool(OptionsKey.ViewBobbing, true);
            FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync);

            SetFpsLimitMethod(method);
            ViewDistance     = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512);
            UserViewDistance = ViewDistance;
            SmoothLighting   = Options.GetBool(OptionsKey.SmoothLighting, false);

            DefaultFov        = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70);
            Fov               = DefaultFov;
            ZoomFov           = DefaultFov;
            ModifiableLiquids = !ClassicMode && Options.GetBool(OptionsKey.ModifiableLiquids, false);
            CameraClipping    = Options.GetBool(OptionsKey.CameraClipping, true);

            AllowServerTextures = Options.GetBool(OptionsKey.AllowServerTextures, true);
            MouseSensitivity    = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30);
            ShowBlockInHand     = Options.GetBool(OptionsKey.ShowBlockInHand, true);
            InvertMouse         = Options.GetBool(OptionsKey.InvertMouse, false);

            bool skipSsl = Options.GetBool("skip-ssl-check", false);

            if (skipSsl)
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                Options.Set("skip-ssl-check", false);
            }
        }
        public override void Init()
        {
            base.Init();
            INetworkProcessor network = game.Network;

            widgets = new Widget[] {
                // Column 1
                !network.IsSinglePlayer ? null :
                Make(-140, -100, "Click distance", OnWidgetClick,
                     g => g.LocalPlayer.ReachDistance.ToString(),
                     (g, v) => g.LocalPlayer.ReachDistance = Single.Parse(v)),

                Make(-140, -50, "Music", OnWidgetClick,
                     g => g.UseMusic ? "yes" : "no",
                     (g, v) => { g.UseMusic = v == "yes";
                                 g.AudioPlayer.SetMusic(g.UseMusic);
                                 Options.Set(OptionsKey.UseMusic, v == "yes"); }),

                Make(-140, 0, "Sound", OnWidgetClick,
                     g => g.UseSound ? "yes" : "no",
                     (g, v) => { g.UseSound = v == "yes";
                                 g.AudioPlayer.SetSound(g.UseSound);
                                 Options.Set(OptionsKey.UseSound, v == "yes"); }),

                Make(-140, 50, "View bobbing", OnWidgetClick,
                     g => g.ViewBobbing ? "yes" : "no",
                     (g, v) => { g.ViewBobbing = v == "yes";
                                 Options.Set(OptionsKey.ViewBobbing, v == "yes"); }),

                // Column 2
                !network.IsSinglePlayer ? null :
                Make(140, -100, "Block physics", OnWidgetClick,
                     g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no",
                     (g, v) => {
                    ((SinglePlayerServer)network).physics.Enabled = v == "yes";
                    Options.Set(OptionsKey.SingleplayerPhysics, v == "yes");
                }),

                Make(140, -50, "Auto close launcher", OnWidgetClick,
                     g => Options.GetBool(OptionsKey.AutoCloseLauncher, false) ? "yes" : "no",
                     (g, v) => Options.Set(OptionsKey.AutoCloseLauncher, v == "yes")),

                Make(140, 0, "Invert mouse", OnWidgetClick,
                     g => g.InvertMouse ? "yes" : "no",
                     (g, v) => { g.InvertMouse = v == "yes";
                                 Options.Set(OptionsKey.InvertMouse, v == "yes"); }),

                Make(140, 50, "Mouse sensitivity", OnWidgetClick,
                     g => g.MouseSensitivity.ToString(),
                     (g, v) => { g.MouseSensitivity = Int32.Parse(v);
                                 Options.Set(OptionsKey.Sensitivity, v); }),

                MakeBack(false, titleFont,
                         (g, w) => g.SetNewScreen(new OptionsGroupScreen(g))),
                null, null,
            };
            MakeValidators();
            MakeDescriptions();
        }
Beispiel #4
0
        public LocalPlayer(Game game) : base(game)
        {
            DisplayName    = game.Username;
            SkinName       = game.Username;
            SkinIdentifier = "skin_255";

            SpeedMultiplier = Options.GetFloat(OptionsKey.Speed, 0.1f, 50, 7);
            PushbackPlacing = Options.GetBool(OptionsKey.PushbackPlacing, false);
            NoclipSlide     = Options.GetBool(OptionsKey.NoclipSlide, false);
            InitRenderingData();
        }
Beispiel #5
0
        public LocalPlayer(Game game) : base(game)
        {
            DisplayName    = game.Username;
            SkinName       = game.Username;
            SkinIdentifier = "skin_255";
            physics        = new PhysicsComponent(game, this);
            Hacks          = new HacksComponent(game, this);

            Hacks.SpeedMultiplier = Options.GetFloat(OptionsKey.Speed, 0.1f, 50, 10);
            Hacks.PushbackPlacing = Options.GetBool(OptionsKey.PushbackPlacing, false);
            Hacks.NoclipSlide     = Options.GetBool(OptionsKey.NoclipSlide, false);
            Hacks.DoubleJump      = Options.GetBool(OptionsKey.DoubleJump, false);
            Hacks.Enabled         = Options.GetBool(OptionsKey.HacksEnabled, true);
            InitRenderingData();
        }
Beispiel #6
0
        void LoadGui()
        {
            Chat           = new Chat(this);
            InventoryScale = Options.GetFloat(OptionsKey.InventoryScale, 0.25f, 5f, 1f);
            HotbarScale    = Options.GetFloat(OptionsKey.HotbarScale, 0.25f, 5f, 1f);
            ChatScale      = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f);
            ShowFPS        = Options.GetBool(OptionsKey.ShowFPS, true);

            TabAutocomplete = Options.GetBool(OptionsKey.TabAutocomplete, false);
            FontName        = Options.Get(OptionsKey.FontName) ?? "Arial";
            try {
                using (Font f = new Font(FontName, 16)) { }
            } catch (Exception) {
                FontName = "Arial";
                Options.Set(OptionsKey.FontName, "Arial");
            }
        }
Beispiel #7
0
        internal void OnLoad()
        {
                        #if ANDROID
            Graphics = new OpenGLESApi();
                        #elif !USE_DX
            Graphics = new OpenGLApi(window);
                        #else
            Graphics = new Direct3D9Api(window);
                        #endif
            Graphics.MakeApiInfo();
            ErrorHandler.ExtraInfo = Graphics.ApiInfo;

                        #if ANDROID
            Drawer2D = new CanvasDrawer2D(Graphics);
                        #else
            Drawer2D = new GdiPlusDrawer2D(Graphics);
                        #endif
            UpdateClientSize();

            Entities = new EntityList(this);
            TextureCache.Init();

                        #if SURVIVAL_TEST
            if (Options.GetBool(OptionsKey.SurvivalMode, false))
            {
                Mode = new SurvivalGameMode();
            }
            else
            {
                Mode = new CreativeGameMode();
            }
                        #endif

            Input           = new InputHandler(this);
            ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
            TabList         = new TabList(); Components.Add(TabList);
            LoadOptions();
            LoadGuiOptions();
            Chat = new Chat(); Components.Add(Chat);

            Events.OnNewMap        += OnNewMapCore;
            Events.OnNewMapLoaded  += OnNewMapLoadedCore;
            Events.TextureChanged  += TextureChangedCore;
            Events.LowVRAMDetected += OnLowVRAMDetected;

            BlockInfo.Allocate(256);
            BlockInfo.Init();

            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            Downloader = new AsyncDownloader(Drawer2D); Components.Add(Downloader);
            Lighting   = new BasicLighting(); Components.Add(Lighting);

            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.UseChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackText, false);
            Graphics.Mipmaps          = Options.GetBool(OptionsKey.Mipmaps, false);

            Atlas1D.game  = this;
            Atlas2D.game  = this;
            Animations    = new Animations(); Components.Add(Animations);
            Inventory     = new Inventory(); Components.Add(Inventory);
            Inventory.Map = new BlockID[BlockInfo.Count];

            BlockInfo.SetDefaultPerms();
            World       = new World(this);
            LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
            Entities.List[EntityList.SelfID] = LocalPlayer;

            MapRenderer        = new MapRenderer(this);
            ChunkUpdater       = new ChunkUpdater(this);
            EnvRenderer        = new EnvRenderer(); Components.Add(EnvRenderer);
            MapBordersRenderer = new MapBordersRenderer(); Components.Add(MapBordersRenderer);

            string renType = Options.Get(OptionsKey.RenderType, "normal");
            int    flags   = CalcRenderType(renType);
            if (flags == -1)
            {
                flags = 0;
            }

            MapBordersRenderer.legacy = (flags & 1) != 0;
            EnvRenderer.legacy        = (flags & 1) != 0;
            EnvRenderer.minimal       = (flags & 2) != 0;

            if (IPAddress == null)
            {
                Server = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Server = new Network.NetworkProcessor(this);
            }
            Components.Add(Server);
            Graphics.LostContextFunction = Server.Tick;

            Cameras.Add(new FirstPersonCamera(this));
            Cameras.Add(new ThirdPersonCamera(this, false));
            Cameras.Add(new ThirdPersonCamera(this, true));
            Camera = Cameras[0];
            UpdateProjection();

            Gui               = new GuiInterface(this); Components.Add(Gui);
            CommandList       = new CommandList(); Components.Add(CommandList);
            SelectionManager  = new SelectionManager(); Components.Add(SelectionManager);
            WeatherRenderer   = new WeatherRenderer(); Components.Add(WeatherRenderer);
            HeldBlockRenderer = new HeldBlockRenderer(); Components.Add(HeldBlockRenderer);

            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            Culling           = new FrustumCulling();
            Picking           = new PickedPosRenderer(); Components.Add(Picking);
            AudioPlayer       = new AudioPlayer(); Components.Add(AudioPlayer);
            AxisLinesRenderer = new AxisLinesRenderer(); Components.Add(AxisLinesRenderer);
            SkyboxRenderer    = new SkyboxRenderer(); Components.Add(SkyboxRenderer);

            List <string> nonLoaded = PluginLoader.LoadAll(this);

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Init(this);
            }
            ExtractInitialTexturePack();
            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Ready(this);
            }
            InitScheduledTasks();

            if (nonLoaded != null)
            {
                for (int i = 0; i < nonLoaded.Count; i++)
                {
                    Overlay warning = new PluginOverlay(this, nonLoaded[i]);
                    Gui.ShowOverlay(warning, false);
                }
            }

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingScreen(this, connectString, ""));
            Server.BeginConnect();
        }
Beispiel #8
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);
        }
Beispiel #9
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;

                        #if ANDROID
            Graphics = new OpenGLESApi();
                        #elif !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeApiInfo();
            ErrorHandler.AdditionalInfo = Graphics.ApiInfo;

                        #if ANDROID
            Drawer2D = new CanvasDrawer2D(Graphics);
                        #else
            Drawer2D = new GdiPlusDrawer2D(Graphics);
                        #endif

            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.Load();
            LastModified.Load();

            if (Options.GetBool(OptionsKey.SurvivalMode, false))
            {
                Mode = new SurvivalGameMode();
            }
            else
            {
                Mode = new CreativeGameMode();
            }
            Components.Add(Mode);

            Input           = new InputHandler(this);
            defaultIb       = Graphics.MakeDefaultIb();
            ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
            TabList         = new TabList(); Components.Add(TabList);
            LoadOptions();
            LoadGuiOptions();
            Chat = new Chat(); Components.Add(Chat);

            WorldEvents.OnNewMap       += OnNewMapCore;
            WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore;
            Events.TextureChanged      += TextureChangedCore;

            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader(Drawer2D); Components.Add(AsyncDownloader);
            Lighting        = new BasicLighting(); Components.Add(Lighting);

            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.UseChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackText, false);
            Graphics.Mipmaps          = Options.GetBool(OptionsKey.Mipmaps, false);

            TerrainAtlas1D = new TerrainAtlas1D(this);
            TerrainAtlas   = new TerrainAtlas2D(this);
            Animations     = new Animations(); Components.Add(Animations);
            Inventory      = new Inventory(); Components.Add(Inventory);

            BlockInfo.SetDefaultPerms();
            World       = new World(this);
            LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
            Entities.List[EntityList.SelfID] = LocalPlayer;
            Width = window.Width; Height = window.Height;

            MapRenderer = new MapRenderer(this);
            string renType = Options.Get(OptionsKey.RenderType) ?? "normal";
            if (!SetRenderType(renType))
            {
                SetRenderType("normal");
            }

            if (IPAddress == null)
            {
                Server = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Server = new Network.NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Server.Tick;

            Cameras.Add(new FirstPersonCamera(this));
            Cameras.Add(new ThirdPersonCamera(this, false));
            Cameras.Add(new ThirdPersonCamera(this, true));
            Camera = Cameras[0];
            UpdateProjection();

            Gui               = new GuiInterface(this); Components.Add(Gui);
            CommandList       = new CommandList(); Components.Add(CommandList);
            SelectionManager  = new SelectionManager(); Components.Add(SelectionManager);
            WeatherRenderer   = new WeatherRenderer(); Components.Add(WeatherRenderer);
            HeldBlockRenderer = new HeldBlockRenderer(); Components.Add(HeldBlockRenderer);

            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            Culling           = new FrustumCulling();
            Picking           = new PickedPosRenderer(); Components.Add(Picking);
            AudioPlayer       = new AudioPlayer(); Components.Add(AudioPlayer);
            AxisLinesRenderer = new AxisLinesRenderer(); Components.Add(AxisLinesRenderer);
            SkyboxRenderer    = new SkyboxRenderer(); Components.Add(SkyboxRenderer);

            plugins = new PluginLoader(this);
            List <string> nonLoaded = plugins.LoadAll();

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Init(this);
            }
            ExtractInitialTexturePack();
            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Ready(this);
            }
            InitScheduledTasks();

            if (nonLoaded != null)
            {
                for (int i = 0; i < nonLoaded.Count; i++)
                {
                    plugins.MakeWarning(this, nonLoaded[i]);
                }
            }

            window.LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingMapScreen(this, connectString, ""));
            Server.Connect(IPAddress, Port);
        }
        public override void Init()
        {
            base.Init();
            INetworkProcessor network = game.Network;

            buttons = new ButtonWidget[] {
                // Column 1
                !network.IsSinglePlayer ? null :
                Make(-140, -200, "Click distance", OnWidgetClick,
                     g => g.LocalPlayer.ReachDistance.ToString(),
                     (g, v) => g.LocalPlayer.ReachDistance = Single.Parse(v)),

                Make(-140, -150, "Use sound", OnWidgetClick,
                     g => g.UseSound ? "yes" : "no",
                     (g, v) => { g.UseSound = v == "yes";
                                 g.AudioPlayer.SetSound(g.UseSound);
                                 Options.Set(OptionsKey.UseSound, v == "yes"); }),

                Make(-140, -100, "Simple arms anim", OnWidgetClick,
                     g => g.SimpleArmsAnim? "yes" : "no",
                     (g, v) => { g.SimpleArmsAnim = v == "yes";
                                 Options.Set(OptionsKey.SimpleArmsAnim, v == "yes"); }),

                Make(-140, -50, "Names mode", OnWidgetClick,
                     g => g.Players.NamesMode.ToString(),
                     (g, v) => { object raw          = Enum.Parse(typeof(NameMode), v);
                                 g.Players.NamesMode = (NameMode)raw;
                                 Options.Set(OptionsKey.NamesMode, v); }),

                Make(-140, 0, "FPS limit", OnWidgetClick,
                     g => g.FpsLimit.ToString(),
                     (g, v) => { object raw = Enum.Parse(typeof(FpsLimitMethod), v);
                                 g.SetFpsLimitMethod((FpsLimitMethod)raw);
                                 Options.Set(OptionsKey.FpsLimit, v); }),

                Make(-140, 50, "View distance", OnWidgetClick,
                     g => g.ViewDistance.ToString(),
                     (g, v) => g.SetViewDistance(Int32.Parse(v), true)),

                // Column 2
                !network.IsSinglePlayer ? null :
                Make(140, -200, "Block physics", OnWidgetClick,
                     g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no",
                     (g, v) => {
                    ((SinglePlayerServer)network).physics.Enabled = v == "yes";
                    Options.Set(OptionsKey.SingleplayerPhysics, v == "yes");
                }),

                Make(140, -150, "Use music", OnWidgetClick,
                     g => g.UseMusic ? "yes" : "no",
                     (g, v) => { g.UseMusic = v == "yes";
                                 g.AudioPlayer.SetMusic(g.UseMusic);
                                 Options.Set(OptionsKey.UseMusic, v == "yes"); }),

                Make(140, -100, "View bobbing", OnWidgetClick,
                     g => g.ViewBobbing ? "yes" : "no",
                     (g, v) => { g.ViewBobbing = v == "yes";
                                 Options.Set(OptionsKey.ViewBobbing, v == "yes"); }),

                Make(140, -50, "Auto close launcher", OnWidgetClick,
                     g => Options.GetBool(OptionsKey.AutoCloseLauncher, false) ? "yes" : "no",
                     (g, v) => Options.Set(OptionsKey.AutoCloseLauncher, v == "yes")),

                Make(140, 0, "Invert mouse", OnWidgetClick,
                     g => g.InvertMouse ? "yes" : "no",
                     (g, v) => { g.InvertMouse = v == "yes";
                                 Options.Set(OptionsKey.InvertMouse, v == "yes"); }),

                Make(140, 50, "Mouse sensitivity", OnWidgetClick,
                     g => g.MouseSensitivity.ToString(),
                     (g, v) => { g.MouseSensitivity = Int32.Parse(v);
                                 Options.Set(OptionsKey.Sensitivity, v); }),

                MakeBack(false, titleFont,
                         (g, w) => g.SetNewScreen(new PauseScreen(g))),
                null,
            };
            buttons[3].Metadata = typeof(NameMode);
            buttons[4].Metadata = typeof(FpsLimitMethod);

            validators = new MenuInputValidator[] {
                network.IsSinglePlayer ? new RealValidator(1, 1024) : null,
                new BooleanValidator(),
                new BooleanValidator(),
                new EnumValidator(),
                new EnumValidator(),
                new IntegerValidator(16, 4096),

                network.IsSinglePlayer ? new BooleanValidator() : null,
                new BooleanValidator(),
                new BooleanValidator(),
                new BooleanValidator(),
                new BooleanValidator(),
                new IntegerValidator(1, 100),
            };
            okayIndex = buttons.Length - 1;
        }
Beispiel #11
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.Load();
            InputHandler    = new InputHandler(this);
            defaultIb       = Graphics.MakeDefaultIb();
            ParticleManager = AddComponent(new ParticleManager());
            TabList         = AddComponent(new TabList());
            LoadOptions();
            LoadGuiOptions();
            Chat = AddComponent(new Chat());
            WorldEvents.OnNewMap       += OnNewMapCore;
            WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore;

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = AddComponent(new AsyncDownloader());
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.ArialChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackTextShadows, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = AddComponent(new Animations());
            Inventory      = AddComponent(new Inventory());

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

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera = firstPersonCam;
            UpdateProjection();
            CommandManager    = AddComponent(new CommandManager());
            SelectionManager  = AddComponent(new SelectionManager());
            WeatherRenderer   = AddComponent(new WeatherRenderer());
            BlockHandRenderer = AddComponent(new BlockHandRenderer());

            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            fpsScreen         = AddComponent(new FpsScreen(this));
            hudScreen         = AddComponent(new HudScreen(this));
            Culling           = new FrustumCulling();
            Picking           = AddComponent(new PickedPosRenderer());
            AudioPlayer       = AddComponent(new AudioPlayer());
            AxisLinesRenderer = AddComponent(new AxisLinesRenderer());
            SkyboxRenderer    = AddComponent(new SkyboxRenderer());

            foreach (IGameComponent comp in Components)
            {
                comp.Init(this);
            }
            ExtractInitialTexturePack();
            foreach (IGameComponent comp in Components)
            {
                comp.Ready(this);
            }

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