Example #1
0
        public static void LoadSetting()
        {
            try
            {
                var mode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
                WindowWidth  = mode.Width;
                WindowHeight = mode.Height;

                var parser  = new FileIniDataParser();
                var data    = parser.ReadFile(GameIniFilePath, LocalEncoding);
                var setting = data[SettingSectionName];
                int value;
                if (int.TryParse(setting["FullScreen"], out value))
                {
                    IsFullScreen = (value != 0);
                }
                if (int.TryParse(setting["Width"], out value))
                {
                    WindowWidth = value;
                }
                if (int.TryParse(setting["Height"], out value))
                {
                    WindowHeight = value;
                }
                if (int.TryParse(setting["SaveLoadSelectionIndex"], out value))
                {
                    SaveLoadSelectionIndex = value;
                }
                if (int.TryParse(setting["IsUseThewWhenNormalRun"], out value))
                {
                    IsUseThewWhenNormalRun = value > 0;
                }
                if (int.TryParse(setting["MaxMagicUnit"], out value))
                {
                    MagicManager.MaxMagicUnit = value;
                }
                if (int.TryParse(setting["RunSpeedFold"], out value))
                {
                    RunSpeedFold = value;
                }

                float fv;
                if (float.TryParse(setting["SoundEffectVolume"], out fv))
                {
                    SoundEffect.MasterVolume = fv;
                }
                if (float.TryParse(setting["MusicVolume"], out fv))
                {
                    BackgroundMusic.SetVolume(fv);
                }
            }
            catch (Exception)
            {
                //no setting file, do nothing
            }
        }
Example #2
0
        /// <summary>
        /// Save game settings to ini file.
        /// Because some settings was not needed to save when playing game.
        /// Set isAll to flase will only save update require settings when playing game.
        /// Set isAll to thre if is in setting game settings.
        /// </summary>
        /// <param name="isAll">Save all settings to file if true.</param>
        private static void SaveSetting(bool isAll)
        {
            try
            {
                IniData data;
                if (!File.Exists(GameIniFilePath))
                {
                    data = new IniData();
                }
                else
                {
                    data = new FileIniDataParser().ReadFile(GameIniFilePath, LocalEncoding);
                }
                var section = data[SettingSectionName];
                if (section == null)
                {
                    data.Sections.AddSection(SettingSectionName);
                    section = data[SettingSectionName];
                }

                section["FullScreen"]             = IsFullScreen ? "1" : "0";
                section["SaveLoadSelectionIndex"] = SaveLoadSelectionIndex.ToString();
                section["IsUseThewWhenNormalRun"] = IsUseThewWhenNormalRun ? "1" : "0";
                if (isAll)
                {
                    section["Width"]  = WindowWidth.ToString();
                    section["Height"] = WindowHeight.ToString();
                    try
                    {
                        section["SoundEffectVolume"] = SoundEffect.MasterVolume.ToString();
                        section["MusicVolume"]       = BackgroundMusic.GetVolume().ToString();
                    }
                    catch (Exception e)
                    {
                    }
                    section["MaxMagicUnit"] = MagicManager.MaxMagicUnit.ToString();
                    section["RunSpeedFold"] = RunSpeedFold.ToString();
                }
                File.WriteAllText(GameIniFilePath, data.ToString(), LocalEncoding);
            }
            catch (Exception exception)
            {
                Log.LogFileSaveError("Game setting file", GameIniFilePath, exception);
            }
        }