예제 #1
0
        private IEnumerable <object> WaitForKeyPress(GUITextBox keyBox)
        {
            yield return(CoroutineStatus.Running);

            while (PlayerInput.LeftButtonHeld() || PlayerInput.LeftButtonClicked())
            {
                //wait for the mouse to be released, so that we don't interpret clicking on the textbox as the keybinding
                yield return(CoroutineStatus.Running);
            }
            while (keyBox.Selected && PlayerInput.GetKeyboardState.GetPressedKeys().Length == 0 &&
                   !PlayerInput.LeftButtonClicked() && !PlayerInput.RightButtonClicked() && !PlayerInput.MidButtonClicked())
            {
                if (Screen.Selected != GameMain.MainMenuScreen && !GUI.SettingsMenuOpen)
                {
                    yield return(CoroutineStatus.Success);
                }

                yield return(CoroutineStatus.Running);
            }

            UnsavedSettings = true;

            int keyIndex = (int)keyBox.UserData;

            if (PlayerInput.LeftButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(0);
                keyBox.Text          = "Mouse1";
            }
            else if (PlayerInput.RightButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(1);
                keyBox.Text          = "Mouse2";
            }
            else if (PlayerInput.MidButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(2);
                keyBox.Text          = "Mouse3";
            }
            else if (PlayerInput.GetKeyboardState.GetPressedKeys().Length > 0)
            {
                Keys key = PlayerInput.GetKeyboardState.GetPressedKeys()[0];
                keyMapping[keyIndex] = new KeyOrMouse(key);
                keyBox.Text          = key.ToString("G");
            }
            else
            {
                yield return(CoroutineStatus.Success);
            }

            keyBox.Deselect();

            yield return(CoroutineStatus.Success);
        }
예제 #2
0
        public void CheckBindings(bool useDefaults)
        {
            foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
            {
                var binding = keyMapping[(int)inputType];
                if (binding == null)
                {
                    switch (inputType)
                    {
                    case InputType.Deselect:
                        if (useDefaults)
                        {
                            binding = new KeyOrMouse(1);
                        }
                        else
                        {
                            // Legacy support
                            var selectKey = keyMapping[(int)InputType.Select];
                            if (selectKey != null && selectKey.Key != Keys.None)
                            {
                                binding = new KeyOrMouse(selectKey.Key);
                            }
                        }
                        break;

                    case InputType.Shoot:
                        if (useDefaults)
                        {
                            binding = new KeyOrMouse(0);
                        }
                        else
                        {
                            // Legacy support
                            var useKey = keyMapping[(int)InputType.Use];
                            if (useKey != null && useKey.MouseButton.HasValue)
                            {
                                binding = new KeyOrMouse(useKey.MouseButton.Value);
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    if (binding == null)
                    {
                        DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
                        binding = new KeyOrMouse(Keys.D1);
                    }
                    keyMapping[(int)inputType] = binding;
                }
            }
        }
예제 #3
0
        private void LoadKeyBinds(XElement element)
        {
            foreach (XAttribute attribute in element.Attributes())
            {
                if (!Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
                {
                    continue;
                }

                if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
                {
                    keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                }
                else
                {
                    if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
                    {
                        keyMapping[(int)inputType] = new KeyOrMouse(key);
                    }
                }
            }
        }
예제 #4
0
        //public bool CanBeHeld
        //{
        //    get { return canBeHeld; }
        //}

        public Key(KeyOrMouse binding)
        {
            this.binding = binding;
        }
예제 #5
0
        public void Load(string filePath)
        {
            XDocument doc = XMLExtensions.TryLoadXml(filePath);

            MasterServerUrl = doc.Root.GetAttributeString("masterserverurl", "");

            AutoCheckUpdates = doc.Root.GetAttributeBool("autocheckupdates", true);
            WasGameUpdated   = doc.Root.GetAttributeBool("wasgameupdated", false);

            VerboseLogging       = doc.Root.GetAttributeBool("verboselogging", false);
            SaveDebugConsoleLogs = doc.Root.GetAttributeBool("savedebugconsolelogs", false);
            if (doc.Root.Attribute("senduserstatistics") == null)
            {
                ShowUserStatisticsPrompt = true;
            }
            else
            {
                sendUserStatistics = doc.Root.GetAttributeBool("senduserstatistics", true);
            }

            if (doc == null)
            {
                GraphicsWidth  = 1024;
                GraphicsHeight = 678;

                MasterServerUrl = "";

                SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");

                JobNamePreferences = new List <string>();
                foreach (JobPrefab job in JobPrefab.List)
                {
                    JobNamePreferences.Add(job.Name);
                }
                return;
            }

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

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

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

            //FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true);

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

            SoundVolume = doc.Root.GetAttributeFloat("soundvolume", 1.0f);
            MusicVolume = doc.Root.GetAttributeFloat("musicvolume", 0.3f);

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

            keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
            keyMapping[(int)InputType.Up]    = new KeyOrMouse(Keys.W);
            keyMapping[(int)InputType.Down]  = new KeyOrMouse(Keys.S);
            keyMapping[(int)InputType.Left]  = new KeyOrMouse(Keys.A);
            keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D);
            keyMapping[(int)InputType.Run]   = new KeyOrMouse(Keys.LeftShift);

            keyMapping[(int)InputType.Chat]       = new KeyOrMouse(Keys.Tab);
            keyMapping[(int)InputType.RadioChat]  = new KeyOrMouse(Keys.OemPipe);
            keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);

            keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E);

            keyMapping[(int)InputType.Use] = new KeyOrMouse(0);
            keyMapping[(int)InputType.Aim] = new KeyOrMouse(1);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    foreach (XAttribute attribute in subElement.Attributes())
                    {
                        if (Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
                        {
                            if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
                            {
                                keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                            }
                            else
                            {
                                if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(key);
                                }
                            }
                        }
                    }
                    break;

                case "gameplay":
                    JobNamePreferences = new List <string>();
                    foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
                    {
                        JobNamePreferences.Add(ele.GetAttributeString("name", ""));
                    }
                    break;

                case "player":
                    defaultPlayerName  = subElement.GetAttributeString("name", "");
                    characterHeadIndex = subElement.GetAttributeInt("headindex", Rand.Int(10));
                    characterGender    = subElement.GetAttributeString("gender", Rand.Range(0.0f, 1.0f) < 0.5f ? "male" : "female")
                                         .ToLowerInvariant() == "male" ? Gender.Male : Gender.Female;
                    break;
                }
            }

            foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
            {
                if (keyMapping[(int)inputType] == null)
                {
                    DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
                    keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1);
                }
            }

            UnsavedSettings = false;

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "contentpackage":
                    string path = subElement.GetAttributeString("path", "");

                    SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path);
                    if (SelectedContentPackage == null)
                    {
                        SelectedContentPackage = new ContentPackage(path);
                    }
                    break;
                }
            }
        }
예제 #6
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);
                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);

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

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    foreach (XAttribute attribute in subElement.Attributes())
                    {
                        if (Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
                        {
                            if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
                            {
                                keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                            }
                            else
                            {
                                if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(key);
                                }
                            }
                        }
                    }
                    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);
        }
예제 #7
0
        private void LoadDefaultConfig()
        {
            XDocument doc = XMLExtensions.TryLoadXml(savePath);

            Language = doc.Root.GetAttributeString("language", "English");

            MasterServerUrl = doc.Root.GetAttributeString("masterserverurl", "");

            AutoCheckUpdates = doc.Root.GetAttributeBool("autocheckupdates", true);
            WasGameUpdated   = doc.Root.GetAttributeBool("wasgameupdated", false);

            VerboseLogging       = doc.Root.GetAttributeBool("verboselogging", false);
            SaveDebugConsoleLogs = doc.Root.GetAttributeBool("savedebugconsolelogs", false);

#if DEBUG
            UseSteam = doc.Root.GetAttributeBool("usesteam", true);
#endif
            QuickStartSubmarineName = doc.Root.GetAttributeString("quickstartsub", "");

            if (doc == null)
            {
                GraphicsWidth  = 1024;
                GraphicsHeight = 678;

                MasterServerUrl = "";

                SelectedContentPackages.Add(ContentPackage.List.Any() ? ContentPackage.List[0] : new ContentPackage(""));

                jobPreferences = new List <string>();
                foreach (JobPrefab job in JobPrefab.List)
                {
                    jobPreferences.Add(job.Identifier);
                }
                return;
            }

            XElement graphicsMode = doc.Root.Element("graphicsmode");
            GraphicsWidth  = 0;
            GraphicsHeight = 0;
            VSyncEnabled   = graphicsMode.GetAttributeBool("vsync", true);

            XElement graphicsSettings = doc.Root.Element("graphicssettings");
            ParticleLimit              = graphicsSettings.GetAttributeInt("particlelimit", 1500);
            LightMapScale              = MathHelper.Clamp(graphicsSettings.GetAttributeFloat("lightmapscale", 0.5f), 0.1f, 1.0f);
            SpecularityEnabled         = graphicsSettings.GetAttributeBool("specularity", true);
            ChromaticAberrationEnabled = graphicsSettings.GetAttributeBool("chromaticaberration", true);
            HUDScale       = graphicsSettings.GetAttributeFloat("hudscale", 1.0f);
            InventoryScale = graphicsSettings.GetAttributeFloat("inventoryscale", 1.0f);
            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 wm))
            {
                wm = WindowMode.Fullscreen;
            }
            WindowMode = wm;

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

#if DEBUG
            EnableSplashScreen = false;
#else
            EnableSplashScreen = doc.Root.GetAttributeBool("enablesplashscreen", true);
#endif

            AimAssistAmount = doc.Root.GetAttributeFloat("aimassistamount", 0.5f);

            SetDefaultBindings(doc, legacy: false);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    foreach (XAttribute attribute in subElement.Attributes())
                    {
                        if (Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
                        {
                            if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
                            {
                                keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                            }
                            else
                            {
                                if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(key);
                                }
                            }
                        }
                    }
                    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", "");
                    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", -1);
                    CharacterBeardIndex          = subElement.GetAttributeInt("beardindex", -1);
                    CharacterMoustacheIndex      = subElement.GetAttributeInt("moustacheindex", -1);
                    CharacterFaceAttachmentIndex = subElement.GetAttributeInt("faceattachmentindex", -1);
                    break;
                }
            }

            List <string>         missingPackagePaths  = new List <string>();
            List <ContentPackage> incompatiblePackages = new List <ContentPackage>();
            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "contentpackage":
                    string path = System.IO.Path.GetFullPath(subElement.GetAttributeString("path", ""));
                    var    matchingContentPackage = ContentPackage.List.Find(cp => System.IO.Path.GetFullPath(cp.Path) == path);
                    if (matchingContentPackage == null)
                    {
                        missingPackagePaths.Add(path);
                    }
                    else if (!matchingContentPackage.IsCompatible())
                    {
                        incompatiblePackages.Add(matchingContentPackage);
                    }
                    else
                    {
                        SelectedContentPackages.Add(matchingContentPackage);
                    }
                    break;
                }
            }

            TextManager.LoadTextPacks(SelectedContentPackages);

            //display error messages after all content packages have been loaded
            //to make sure the package that contains text files has been loaded before we attempt to use TextManager
            foreach (string missingPackagePath in missingPackagePaths)
            {
                DebugConsole.ThrowError(TextManager.Get("ContentPackageNotFound").Replace("[packagepath]", missingPackagePath));
            }
            foreach (ContentPackage incompatiblePackage in incompatiblePackages)
            {
                DebugConsole.ThrowError(TextManager.Get(incompatiblePackage.GameVersion <= new Version(0, 0, 0, 0) ? "IncompatibleContentPackageUnknownVersion" : "IncompatibleContentPackage")
                                        .Replace("[packagename]", incompatiblePackage.Name)
                                        .Replace("[packageversion]", incompatiblePackage.GameVersion.ToString())
                                        .Replace("[gameversion]", GameMain.Version.ToString()));
            }
            foreach (ContentPackage contentPackage in SelectedContentPackages)
            {
                foreach (ContentFile file in contentPackage.Files)
                {
                    if (!System.IO.File.Exists(file.Path))
                    {
                        DebugConsole.ThrowError("Error in content package \"" + contentPackage.Name + "\" - file \"" + file.Path + "\" not found.");
                        continue;
                    }
                    ToolBox.IsProperFilenameCase(file.Path);
                }
            }
            if (!SelectedContentPackages.Any())
            {
                var availablePackage = ContentPackage.List.FirstOrDefault(cp => cp.IsCompatible() && cp.CorePackage);
                if (availablePackage != null)
                {
                    SelectedContentPackages.Add(availablePackage);
                }
            }

            //save to get rid of the invalid selected packages in the config file
            if (missingPackagePaths.Count > 0 || incompatiblePackages.Count > 0)
            {
                SaveNewPlayerConfig();
            }
        }
예제 #8
0
        public void SetDefaultBindings(XDocument doc = null, bool legacy = false)
        {
            keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
            keyMapping[(int)InputType.Up]      = new KeyOrMouse(Keys.W);
            keyMapping[(int)InputType.Down]    = new KeyOrMouse(Keys.S);
            keyMapping[(int)InputType.Left]    = new KeyOrMouse(Keys.A);
            keyMapping[(int)InputType.Right]   = new KeyOrMouse(Keys.D);
            keyMapping[(int)InputType.Run]     = new KeyOrMouse(Keys.LeftShift);
            keyMapping[(int)InputType.Attack]  = new KeyOrMouse(2);
            keyMapping[(int)InputType.Crouch]  = new KeyOrMouse(Keys.LeftControl);
            keyMapping[(int)InputType.Grab]    = new KeyOrMouse(Keys.G);
            keyMapping[(int)InputType.Health]  = new KeyOrMouse(Keys.H);
            keyMapping[(int)InputType.Ragdoll] = new KeyOrMouse(Keys.Space);
            keyMapping[(int)InputType.Aim]     = new KeyOrMouse(1);

            keyMapping[(int)InputType.InfoTab]    = new KeyOrMouse(Keys.Tab);
            keyMapping[(int)InputType.Chat]       = new KeyOrMouse(Keys.T);
            keyMapping[(int)InputType.RadioChat]  = new KeyOrMouse(Keys.R);
            keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);

            keyMapping[(int)InputType.SelectNextCharacter]     = new KeyOrMouse(Keys.Z);
            keyMapping[(int)InputType.SelectPreviousCharacter] = new KeyOrMouse(Keys.X);

            keyMapping[(int)InputType.Voice] = new KeyOrMouse(Keys.V);

            if (legacy)
            {
                keyMapping[(int)InputType.Use]      = new KeyOrMouse(0);
                keyMapping[(int)InputType.Shoot]    = new KeyOrMouse(0);
                keyMapping[(int)InputType.Select]   = new KeyOrMouse(Keys.E);
                keyMapping[(int)InputType.Deselect] = new KeyOrMouse(Keys.E);
            }
            else
            {
                keyMapping[(int)InputType.Use]    = new KeyOrMouse(Keys.E);
                keyMapping[(int)InputType.Select] = new KeyOrMouse(0);
                // shoot and deselect are handled in CheckBindings() so that we don't override the legacy settings.
            }
            if (doc != null)
            {
                foreach (XElement subElement in doc.Root.Elements())
                {
                    switch (subElement.Name.ToString().ToLowerInvariant())
                    {
                    case "keymapping":
                        foreach (XAttribute attribute in subElement.Attributes())
                        {
                            if (Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
                            {
                                if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                                }
                                else
                                {
                                    if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
                                    {
                                        keyMapping[(int)inputType] = new KeyOrMouse(key);
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
예제 #9
0
        partial void InitProjSpecific(XDocument doc)
        {
            if (doc == null)
            {
                GraphicsWidth  = 1024;
                GraphicsHeight = 678;

                MasterServerUrl = "";

                SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");

                JobNamePreferences = new List <string>();
                foreach (JobPrefab job in JobPrefab.List)
                {
                    JobNamePreferences.Add(job.Name);
                }
                return;
            }

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

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

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

            //FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true);

            var windowModeStr = graphicsMode.GetAttributeString("displaymode", "Fullscreen");

            if (!Enum.TryParse <WindowMode>(windowModeStr, out windowMode))
            {
                windowMode = WindowMode.Fullscreen;
            }

            SoundVolume = doc.Root.GetAttributeFloat("soundvolume", 1.0f);
            MusicVolume = doc.Root.GetAttributeFloat("musicvolume", 0.3f);

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

            keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
            keyMapping[(int)InputType.Up]    = new KeyOrMouse(Keys.W);
            keyMapping[(int)InputType.Down]  = new KeyOrMouse(Keys.S);
            keyMapping[(int)InputType.Left]  = new KeyOrMouse(Keys.A);
            keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D);
            keyMapping[(int)InputType.Run]   = new KeyOrMouse(Keys.LeftShift);

            keyMapping[(int)InputType.Chat]       = new KeyOrMouse(Keys.Tab);
            keyMapping[(int)InputType.RadioChat]  = new KeyOrMouse(Keys.OemPipe);
            keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);

            keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E);

            keyMapping[(int)InputType.Use] = new KeyOrMouse(0);
            keyMapping[(int)InputType.Aim] = new KeyOrMouse(1);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    foreach (XAttribute attribute in subElement.Attributes())
                    {
                        InputType inputType;
                        if (Enum.TryParse(attribute.Name.ToString(), true, out inputType))
                        {
                            int mouseButton;
                            if (int.TryParse(attribute.Value.ToString(), out mouseButton))
                            {
                                keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                            }
                            else
                            {
                                Keys key;
                                if (Enum.TryParse(attribute.Value.ToString(), true, out key))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(key);
                                }
                            }
                        }
                    }
                    break;

                case "gameplay":
                    JobNamePreferences = new List <string>();
                    foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
                    {
                        JobNamePreferences.Add(ele.GetAttributeString("name", ""));
                    }
                    break;
                }
            }

            foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
            {
                if (keyMapping[(int)inputType] == null)
                {
                    DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
                    keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1);
                }
            }


            UnsavedSettings = false;
        }
예제 #10
0
        public void Load(string filePath)
        {
            XDocument doc = ToolBox.TryLoadXml(filePath);

            if (doc == null)
            {
                DebugConsole.ThrowError("No config file found");

                GraphicsWidth  = 1024;
                GraphicsHeight = 678;

                MasterServerUrl = "";

                SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");

                JobNamePreferences = new List <string>();
                foreach (JobPrefab job in JobPrefab.List)
                {
                    JobNamePreferences.Add(job.Name);
                }

                return;
            }

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

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

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

            //FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true);

            var windowModeStr = ToolBox.GetAttributeString(graphicsMode, "displaymode", "Fullscreen");

            if (!Enum.TryParse <WindowMode>(windowModeStr, out windowMode))
            {
                windowMode = WindowMode.Fullscreen;
            }

            MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", "");

            AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true);
            WasGameUpdated   = ToolBox.GetAttributeBool(doc.Root, "wasgameupdated", false);

            SoundVolume = ToolBox.GetAttributeFloat(doc.Root, "soundvolume", 1.0f);
            MusicVolume = ToolBox.GetAttributeFloat(doc.Root, "musicvolume", 0.3f);

            VerboseLogging = ToolBox.GetAttributeBool(doc.Root, "verboselogging", false);

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

            keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
            keyMapping[(int)InputType.Up]    = new KeyOrMouse(Keys.W);
            keyMapping[(int)InputType.Down]  = new KeyOrMouse(Keys.S);
            keyMapping[(int)InputType.Left]  = new KeyOrMouse(Keys.A);
            keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D);
            keyMapping[(int)InputType.Run]   = new KeyOrMouse(Keys.LeftShift);


            keyMapping[(int)InputType.Chat]       = new KeyOrMouse(Keys.Tab);
            keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);

            keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E);

            keyMapping[(int)InputType.Use] = new KeyOrMouse(0);
            keyMapping[(int)InputType.Aim] = new KeyOrMouse(1);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "contentpackage":
                    string path = ToolBox.GetAttributeString(subElement, "path", "");


                    SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path);

                    if (SelectedContentPackage == null)
                    {
                        SelectedContentPackage = new ContentPackage(path);
                    }
                    break;

                case "keymapping":
                    foreach (XAttribute attribute in subElement.Attributes())
                    {
                        InputType inputType;
                        if (Enum.TryParse(attribute.Name.ToString(), true, out inputType))
                        {
                            int mouseButton;
                            if (int.TryParse(attribute.Value.ToString(), out mouseButton))
                            {
                                keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
                            }
                            else
                            {
                                Keys key;
                                if (Enum.TryParse(attribute.Value.ToString(), true, out key))
                                {
                                    keyMapping[(int)inputType] = new KeyOrMouse(key);
                                }
                            }
                        }
                    }
                    break;

                case "gameplay":
                    JobNamePreferences = new List <string>();
                    foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
                    {
                        JobNamePreferences.Add(ToolBox.GetAttributeString(ele, "name", ""));
                    }
                    break;
                }
            }

            foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
            {
                if (keyMapping[(int)inputType] == null)
                {
                    DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
                    keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1);
                }
            }


            UnsavedSettings = false;
        }