From 7497fec62a13b5726f67b0302293b453b904888e Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 18 May 2019 17:18:10 +0300 Subject: [PATCH] (558678b4c) SerializableProperty names can be translated (the tags are "ClassName.PropertyName", e.g. "LightComponent.LightColor") --- .../Serialization/SerializableEntityEditor.cs | 3 +- .../BarotraumaShared/Source/GameSettings.cs | 73 +++++++++++++------ .../Serialization/SerializableProperty.cs | 5 ++ 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs index 112b57b61..2ce6ff0d7 100644 --- a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs +++ b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs @@ -294,7 +294,8 @@ namespace Barotrauma { value = ""; } - string displayName = property.GetAttribute().DisplayName; + string propertyName = (entity.GetType().Name + "." + property.PropertyInfo.Name).ToLowerInvariant(); + string displayName = TextManager.Get(propertyName, returnNull: true) ?? property.GetAttribute().DisplayName; if (displayName == null) { displayName = property.Name.FormatCamelCaseWithSpaces(); diff --git a/Barotrauma/BarotraumaShared/Source/GameSettings.cs b/Barotrauma/BarotraumaShared/Source/GameSettings.cs index 4446b688a..50f93fe2f 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSettings.cs @@ -341,33 +341,15 @@ namespace Barotrauma { foreach (XElement subElement in doc.Root.Elements()) { - switch (subElement.Name.ToString().ToLowerInvariant()) + if (subElement.Name.ToString().ToLowerInvariant() == "keymapping") { - 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; + LoadKeyBinds(subElement); } } } } - private void CheckBindings(bool useDefaults) + public void CheckBindings(bool useDefaults) { foreach (InputType inputType in Enum.GetValues(typeof(InputType))) { @@ -981,6 +963,55 @@ namespace Barotrauma selectedContentPackagePaths = new HashSet(); + foreach (XElement subElement in doc.Root.Elements()) + { + switch (subElement.Name.ToString().ToLowerInvariant()) + { + case "keymapping": + LoadKeyBinds(subElement); + break; + case "gameplay": + jobPreferences = new List(); + 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(); + foreach (XElement subElement in doc.Root.Elements()) { gSettings = new XElement("graphicssettings"); diff --git a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs index 1ae108e35..ed281d0bf 100644 --- a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs +++ b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs @@ -98,6 +98,11 @@ namespace Barotrauma public readonly AttributeCollection Attributes; public readonly Type PropertyType; + public PropertyInfo PropertyInfo + { + get { return propertyInfo; } + } + public SerializableProperty(PropertyDescriptor property, object obj) { Name = property.Name;