Пример #1
0
        public int saveData()
        {
            DatafileWriter dw = new DatafileWriter("client.config.txt");

            foreach (InterfaceElement element in elements)
            {
                switch (element.text)
                {
                case "Username": dw.Data["handle"] = (element as InterfaceTextInput).value;
                    break;

                case "Scrn  Width":     //dw.Data["width"] = (element as InterfaceTextInput).value;
                    int resolve = 0;
                    if (int.TryParse((element as InterfaceTextInput).value, out resolve))
                    {
                        if (resolve >= 1024)
                        {
                            dw.Data["width"] = (element as InterfaceTextInput).value;
                        }
                    }
                    break;

                case "Scrn Height":     //dw.Data["height"] = (element as InterfaceTextInput).value;
                    int resolve2 = 0;
                    if (int.TryParse((element as InterfaceTextInput).value, out resolve2))
                    {
                        if (resolve2 >= 768)
                        {
                            dw.Data["height"] = (element as InterfaceTextInput).value;
                        }
                    }
                    break;

                case "Screen Mode": dw.Data["fullscreen"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                    break;

                case "Volume": dw.Data["volume"] = ((element as InterfaceSlider).value / 100).ToString();
                    break;

                case "Enable Sound": dw.Data["nosound"] = (!(element as InterfaceButtonToggle).clicked).ToString().ToLower();
                    break;

                case "Invert Mouse": dw.Data["yinvert"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                    break;

                case "Mouse Sensitivity": dw.Data["sensitivity"] = (element as InterfaceSlider).value.ToString();
                    break;

                case "Bloom": dw.Data["pretty"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                    break;

                case "Show FPS": dw.Data["showfps"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                    break;

                default: break;
                }
            }
            return(dw.WriteChanges("client.config.txt"));
        }
Пример #2
0
        public override void OnEnter(string oldState)
        {
            _SM.IsMouseVisible = true;

            //Load the background
            texSettings = _SM.Content.Load <Texture2D>("menus/tex_menu_settings");
            drawRect    = new Rectangle(_SM.GraphicsDevice.Viewport.Width / 2 - 1024 / 2,
                                        _SM.GraphicsDevice.Viewport.Height / 2 - 768 / 2,
                                        1024,
                                        1024);

            //Read the data from file
            DatafileWriter dw = new DatafileWriter("client.config.txt");

            currentPos = new Vector2(200, 100);
            originalY  = (int)currentPos.Y;

            addLabelAutomatic("User Settings");
            addTextInputAutomatic("Username", dw.Data.ContainsKey("handle") ? dw.Data["handle"] : "Player");
            addSpace(16);

            addLabelAutomatic("Screen Settings");
            addTextInputAutomatic("Scrn  Width", dw.Data.ContainsKey("width") ? dw.Data["width"] : "1024");
            addTextInputAutomatic("Scrn Height", dw.Data.ContainsKey("height") ? dw.Data["height"] : "780");
            addButtonAutomatic("Screen Mode", "Fullscreen", "Windowed", dw.Data.ContainsKey("fullscreen") ? bool.Parse(dw.Data["fullscreen"]) : false);
            addSpace(16);

            addLabelAutomatic("Sound Settings");
            addSliderAutomatic("Volume", 1f, 100f, dw.Data.ContainsKey("volume") ? float.Parse(dw.Data["volume"]) * 100 : 100f, true);
            addButtonAutomatic("Enable Sound", "On", "NoSound", dw.Data.ContainsKey("nosound") ? !bool.Parse(dw.Data["nosound"]) : true);
            addSpace(16);

            shiftColumn();

            addLabelAutomatic("Mouse Settings");
            addButtonAutomatic("Invert Mouse", "Yes", "No", dw.Data.ContainsKey("yinvert") ? bool.Parse(dw.Data["yinvert"]) : false);
            addSliderAutomatic("Mouse Sensitivity", 1f, 10f, dw.Data.ContainsKey("sensitivity") ? float.Parse(dw.Data["sensitivity"]) : 5f, true);
            addSpace(16);

            addLabelAutomatic("Misc Settings");
            addButtonAutomatic("Bloom", "Pretty", "Boring", dw.Data.ContainsKey("pretty") ? bool.Parse(dw.Data["pretty"]) : true);
            addButtonAutomatic("Show FPS", "Yes", "No", dw.Data.ContainsKey("showfps") ? bool.Parse(dw.Data["showfps"]) : true);
            addSpace(16);


            //_P.KillPlayer("");
        }
Пример #3
0
 public int saveData()
 {
     DatafileWriter dw = new DatafileWriter("client.config.txt");
     foreach (InterfaceElement element in elements)
     {
         switch (element.text)
         {
             case "Username": dw.Data["handle"] = (element as InterfaceTextInput).value;
                 break;
             case "Scrn  Width": dw.Data["width"] = (element as InterfaceTextInput).value;
                 break;
             case "Scrn Height": dw.Data["height"] = (element as InterfaceTextInput).value;
                 break;
             case "Screen Mode": dw.Data["fullscreen"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                 break;
             case "Volume": dw.Data["volume"] = ((element as InterfaceSlider).value / 100).ToString();
                 break;
             case "Enable Sound": dw.Data["nosound"] = (!(element as InterfaceButtonToggle).clicked).ToString().ToLower();
                 break;
             case "Invert Mouse": dw.Data["yinvert"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                 break;
             case "Mouse Sensitivity": dw.Data["sensitivity"] = (element as InterfaceSlider).value.ToString();
                 break;
             case "Bloom": dw.Data["pretty"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                 break;
             case "Show FPS": dw.Data["showfps"] = (element as InterfaceButtonToggle).clicked.ToString().ToLower();
                 break;
             default: break;
         }
     }
     return dw.WriteChanges("client.config.txt");
 }
Пример #4
0
        public override void OnEnter(string oldState)
        {
            _SM.IsMouseVisible = true;

            //Load the background
            texSettings = _SM.Content.Load<Texture2D>("menus/tex_menu_settings");
            drawRect = new Rectangle(_SM.GraphicsDevice.Viewport.Width / 2 - 1024 / 2,
                                                 _SM.GraphicsDevice.Viewport.Height / 2 - 768 / 2,
                                                 1024,
                                                 1024);

            //Read the data from file
            DatafileWriter dw = new DatafileWriter("client.config.txt");

            currentPos = new Vector2(200, 100);
            originalY = (int)currentPos.Y;

            addLabelAutomatic("User Settings");
                addTextInputAutomatic("Username", dw.Data.ContainsKey("handle") ? dw.Data["handle"] : "Player");
            addSpace(16);

            addLabelAutomatic("Screen Settings");
                addTextInputAutomatic("Scrn  Width", dw.Data.ContainsKey("width") ? dw.Data["width"] : "1024");
                addTextInputAutomatic("Scrn Height", dw.Data.ContainsKey("height") ? dw.Data["height"] : "780");
                addButtonAutomatic("Screen Mode", "Fullscreen", "Windowed", dw.Data.ContainsKey("fullscreen") ? bool.Parse(dw.Data["fullscreen"]) : false);
            addSpace(16);

            addLabelAutomatic("Sound Settings");
                addSliderAutomatic("Volume", 1f, 100f, dw.Data.ContainsKey("volume") ? float.Parse(dw.Data["volume"])*100 : 100f, true);
                addButtonAutomatic("Enable Sound", "On", "NoSound", dw.Data.ContainsKey("nosound") ? !bool.Parse(dw.Data["nosound"]) : true);
            addSpace(16);

            shiftColumn();

            addLabelAutomatic("Mouse Settings");
                addButtonAutomatic("Invert Mouse", "Yes", "No", dw.Data.ContainsKey("yinvert") ? bool.Parse(dw.Data["yinvert"]) : false);
                addSliderAutomatic("Mouse Sensitivity", 1f, 10f, dw.Data.ContainsKey("sensitivity") ? float.Parse(dw.Data["sensitivity"]) : 5f, true);
            addSpace(16);

            addLabelAutomatic("Misc Settings");
                addButtonAutomatic("Bloom", "Pretty", "Boring", dw.Data.ContainsKey("pretty") ? bool.Parse(dw.Data["pretty"]) : true);
                addButtonAutomatic("Show FPS", "Yes", "No", dw.Data.ContainsKey("showfps") ? bool.Parse(dw.Data["showfps"]) : true);
            addSpace(16);

            
            //_P.KillPlayer("");
        }
Пример #5
0
        protected override void Initialize()
        {
            graphicsDeviceManager.IsFullScreen                = false;
            graphicsDeviceManager.PreferredBackBufferWidth    = 1024;
            graphicsDeviceManager.PreferredBackBufferHeight   = 768;
            graphicsDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;

            //Now moving to DatafileWriter only since it can read and write
            DatafileWriter dataFile = new DatafileWriter("client.config.txt");

            if (dataFile.Data.ContainsKey("width"))
            {
                graphicsDeviceManager.PreferredBackBufferWidth = int.Parse(dataFile.Data["width"], System.Globalization.CultureInfo.InvariantCulture);
            }
            if (dataFile.Data.ContainsKey("height"))
            {
                graphicsDeviceManager.PreferredBackBufferHeight = int.Parse(dataFile.Data["height"], System.Globalization.CultureInfo.InvariantCulture);
            }
            if (dataFile.Data.ContainsKey("fullscreen"))
            {
                graphicsDeviceManager.IsFullScreen = bool.Parse(dataFile.Data["fullscreen"]);
            }
            if (dataFile.Data.ContainsKey("handle"))
            {
                playerHandle = dataFile.Data["handle"];
            }
            if (dataFile.Data.ContainsKey("showfps"))
            {
                DrawFrameRate = bool.Parse(dataFile.Data["showfps"]);
            }
            if (dataFile.Data.ContainsKey("yinvert"))
            {
                InvertMouseYAxis = bool.Parse(dataFile.Data["yinvert"]);
            }
            if (dataFile.Data.ContainsKey("nosound"))
            {
                NoSound = bool.Parse(dataFile.Data["nosound"]);
            }
            if (dataFile.Data.ContainsKey("pretty"))
            {
                RenderPretty = bool.Parse(dataFile.Data["pretty"]);
            }
            if (dataFile.Data.ContainsKey("volume"))
            {
                volumeLevel = Math.Max(0, Math.Min(1, float.Parse(dataFile.Data["volume"], System.Globalization.CultureInfo.InvariantCulture)));
            }
            if (dataFile.Data.ContainsKey("sensitivity"))
            {
                mouseSensitivity = Math.Max(0.001f, Math.Min(0.05f, float.Parse(dataFile.Data["sensitivity"], System.Globalization.CultureInfo.InvariantCulture) / 1000f));
            }
            if (dataFile.Data.ContainsKey("red_name"))
            {
                redName = dataFile.Data["red_name"].Trim();
            }
            if (dataFile.Data.ContainsKey("blue_name"))
            {
                blueName = dataFile.Data["blue_name"].Trim();
            }


            if (dataFile.Data.ContainsKey("red"))
            {
                Color    temp = new Color();
                string[] data = dataFile.Data["red"].Split(',');
                try
                {
                    temp.R = byte.Parse(data[0].Trim());
                    temp.G = byte.Parse(data[1].Trim());
                    temp.B = byte.Parse(data[2].Trim());
                    temp.A = (byte)255;
                }
                catch
                {
                    Console.WriteLine("Invalid colour values for red");
                }
                if (temp.A != 0)
                {
                    red           = temp;
                    customColours = true;
                }
            }

            if (dataFile.Data.ContainsKey("blue"))
            {
                Color    temp = new Color();
                string[] data = dataFile.Data["blue"].Split(',');
                try
                {
                    temp.R = byte.Parse(data[0].Trim());
                    temp.G = byte.Parse(data[1].Trim());
                    temp.B = byte.Parse(data[2].Trim());
                    temp.A = (byte)255;
                }
                catch
                {
                    Console.WriteLine("Invalid colour values for blue");
                }
                if (temp.A != 0)
                {
                    blue          = temp;
                    customColours = true;
                }
            }

            //Now to read the key bindings
            if (!File.Exists("keymap.txt"))
            {
                FileStream temp = File.Create("keymap.txt");
                temp.Close();
                Console.WriteLine("Keymap file does not exist, creating.");
            }
            dataFile = new DatafileWriter("keymap.txt");
            bool anyChanged = false;

            foreach (string key in dataFile.Data.Keys)
            {
                try
                {
                    Buttons button = (Buttons)Enum.Parse(typeof(Buttons), dataFile.Data[key], true);
                    if (Enum.IsDefined(typeof(Buttons), button))
                    {
                        if (keyBinds.BindKey(button, key, true))
                        {
                            anyChanged = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Enum not defined for " + dataFile.Data[key] + ".");
                    }
                }
                catch { }
            }

            //If no keys are bound in this manner then create the default set
            if (!anyChanged)
            {
                keyBinds.CreateDefaultSet();
                keyBinds.SaveBinds(dataFile, "keymap.txt");
                Console.WriteLine("Creating default keymap...");
            }
            graphicsDeviceManager.ApplyChanges();
            base.Initialize();
        }