Esempio n. 1
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }
            LoadGeneralSettings(doc);
            LoadGraphicSettings(doc);
            LoadAudioSettings(doc);
            LoadControls(doc);
            LoadContentPackages(doc);

            XElement tutorialsElement = doc.Root.Element("tutorials");

            if (tutorialsElement != null)
            {
                foreach (XElement element in tutorialsElement.Elements())
                {
                    CompletedTutorialNames.Add(element.GetAttributeString("name", ""));
                }
            }

            UnsavedSettings = false;
            return(true);
        }
Esempio n. 2
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }
            LoadGeneralSettings(doc);
            LoadGraphicSettings(doc);
            LoadAudioSettings(doc);
            LoadControls(doc);
            LoadContentPackages(doc);

            //allow overriding the save paths in the config file
            if (doc.Root.Attribute("overridesavefolder") != null)
            {
                overrideSaveFolder            = SaveUtil.SaveFolder = doc.Root.GetAttributeString("overridesavefolder", "");
                overrideMultiplayerSaveFolder = SaveUtil.MultiplayerSaveFolder = Path.Combine(overrideSaveFolder, "Multiplayer");
            }
            if (doc.Root.Attribute("overridemultiplayersavefolder") != null)
            {
                overrideMultiplayerSaveFolder = SaveUtil.MultiplayerSaveFolder = doc.Root.GetAttributeString("overridemultiplayersavefolder", "");
            }

            XElement tutorialsElement = doc.Root.Element("tutorials");

            if (tutorialsElement != null)
            {
                foreach (XElement element in tutorialsElement.Elements())
                {
                    CompletedTutorialNames.Add(element.GetAttributeString("name", ""));
                }
            }

            UnsavedSettings = false;
            return(true);
        }
Esempio n. 3
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }

            Language           = doc.Root.GetAttributeString("language", Language);
            AutoCheckUpdates   = doc.Root.GetAttributeBool("autocheckupdates", AutoCheckUpdates);
            sendUserStatistics = doc.Root.GetAttributeBool("senduserstatistics", true);

            XElement graphicsMode = doc.Root.Element("graphicsmode");

            GraphicsWidth  = graphicsMode.GetAttributeInt("width", GraphicsWidth);
            GraphicsHeight = graphicsMode.GetAttributeInt("height", GraphicsHeight);
            VSyncEnabled   = graphicsMode.GetAttributeBool("vsync", VSyncEnabled);

            XElement graphicsSettings = doc.Root.Element("graphicssettings");

            ParticleLimit              = graphicsSettings.GetAttributeInt("particlelimit", ParticleLimit);
            LightMapScale              = MathHelper.Clamp(graphicsSettings.GetAttributeFloat("lightmapscale", LightMapScale), 0.1f, 1.0f);
            SpecularityEnabled         = graphicsSettings.GetAttributeBool("specularity", SpecularityEnabled);
            ChromaticAberrationEnabled = graphicsSettings.GetAttributeBool("chromaticaberration", ChromaticAberrationEnabled);
            HUDScale       = graphicsSettings.GetAttributeFloat("hudscale", HUDScale);
            InventoryScale = graphicsSettings.GetAttributeFloat("inventoryscale", InventoryScale);
            var losModeStr = graphicsSettings.GetAttributeString("losmode", "Transparent");

            if (!Enum.TryParse(losModeStr, out losMode))
            {
                losMode = LosMode.Transparent;
            }

#if CLIENT
            if (GraphicsWidth == 0 || GraphicsHeight == 0)
            {
                GraphicsWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            }
#endif

            var windowModeStr = graphicsMode.GetAttributeString("displaymode", "Fullscreen");
            if (!Enum.TryParse(windowModeStr, out windowMode))
            {
                windowMode = WindowMode.Fullscreen;
            }

            XElement audioSettings = doc.Root.Element("audio");
            if (audioSettings != null)
            {
                SoundVolume             = audioSettings.GetAttributeFloat("soundvolume", SoundVolume);
                MusicVolume             = audioSettings.GetAttributeFloat("musicvolume", MusicVolume);
                VoiceChatVolume         = audioSettings.GetAttributeFloat("voicechatvolume", VoiceChatVolume);
                MuteOnFocusLost         = audioSettings.GetAttributeBool("muteonfocuslost", false);
                UseDirectionalVoiceChat = audioSettings.GetAttributeBool("usedirectionalvoicechat", true);
                string voiceSettingStr = audioSettings.GetAttributeString("voicesetting", "Disabled");
                VoiceCaptureDevice = audioSettings.GetAttributeString("voicecapturedevice", "");
                NoiseGateThreshold = audioSettings.GetAttributeFloat("noisegatethreshold", -45);
                var voiceSetting = VoiceMode.Disabled;
                if (Enum.TryParse(voiceSettingStr, out voiceSetting))
                {
                    VoiceSetting = voiceSetting;
                }
            }

            useSteamMatchmaking        = doc.Root.GetAttributeBool("usesteammatchmaking", useSteamMatchmaking);
            requireSteamAuthentication = doc.Root.GetAttributeBool("requiresteamauthentication", requireSteamAuthentication);

            EnableSplashScreen = doc.Root.GetAttributeBool("enablesplashscreen", EnableSplashScreen);

            PauseOnFocusLost = doc.Root.GetAttributeBool("pauseonfocuslost", PauseOnFocusLost);
            AimAssistAmount  = doc.Root.GetAttributeFloat("aimassistamount", AimAssistAmount);
            EnableMouseLook  = doc.Root.GetAttributeBool("enablemouselook", EnableMouseLook);

            CrewMenuOpen = doc.Root.GetAttributeBool("crewmenuopen", CrewMenuOpen);
            ChatOpen     = doc.Root.GetAttributeBool("chatopen", ChatOpen);

            CampaignDisclaimerShown = doc.Root.GetAttributeBool("campaigndisclaimershown", false);
            EditorDisclaimerShown   = doc.Root.GetAttributeBool("editordisclaimershown", false);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    LoadKeyBinds(subElement);
                    break;

                case "gameplay":
                    jobPreferences = new List <string>();
                    foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
                    {
                        string jobIdentifier = ele.GetAttributeString("identifier", "");
                        if (string.IsNullOrEmpty(jobIdentifier))
                        {
                            continue;
                        }
                        jobPreferences.Add(jobIdentifier);
                    }
                    break;

                case "player":
                    defaultPlayerName  = subElement.GetAttributeString("name", defaultPlayerName);
                    CharacterHeadIndex = subElement.GetAttributeInt("headindex", CharacterHeadIndex);
                    if (Enum.TryParse(subElement.GetAttributeString("gender", "none"), true, out Gender g))
                    {
                        CharacterGender = g;
                    }
                    if (Enum.TryParse(subElement.GetAttributeString("race", "white"), true, out Race r))
                    {
                        CharacterRace = r;
                    }
                    else
                    {
                        CharacterRace = Race.White;
                    }
                    CharacterHairIndex           = subElement.GetAttributeInt("hairindex", CharacterHairIndex);
                    CharacterBeardIndex          = subElement.GetAttributeInt("beardindex", CharacterBeardIndex);
                    CharacterMoustacheIndex      = subElement.GetAttributeInt("moustacheindex", CharacterMoustacheIndex);
                    CharacterFaceAttachmentIndex = subElement.GetAttributeInt("faceattachmentindex", CharacterFaceAttachmentIndex);
                    break;

                case "tutorials":
                    foreach (XElement tutorialElement in subElement.Elements())
                    {
                        CompletedTutorialNames.Add(tutorialElement.GetAttributeString("name", ""));
                    }
                    break;
                }
            }

            UnsavedSettings = false;

            selectedContentPackagePaths = new HashSet <string>();

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "contentpackage":
                    string path = System.IO.Path.GetFullPath(subElement.GetAttributeString("path", ""));
                    selectedContentPackagePaths.Add(path);
                    break;
                }
            }

            LoadContentPackages(selectedContentPackagePaths);
            return(true);
        }