Character head & gender settings are saved. Closes #474

This commit is contained in:
Joonas Rikkonen
2018-07-17 13:38:21 +03:00
parent 88abbe28e3
commit 23e0a76f37
2 changed files with 60 additions and 24 deletions
@@ -25,7 +25,7 @@ namespace Barotrauma
public bool EnableSplashScreen { get; set; }
//public bool FullScreenEnabled { get; set; }
private KeyOrMouse[] keyMapping;
private WindowMode windowMode;
@@ -51,8 +51,37 @@ namespace Barotrauma
}
}
private bool unsavedSettings;
private int characterHeadIndex;
public int CharacterHeadIndex
{
get { return characterHeadIndex; }
set
{
if (value == characterHeadIndex) return;
// Begin saving coroutine. Remove any existing save coroutines if one is running.
if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); }
CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine");
characterHeadIndex = value;
}
}
private Gender characterGender;
public Gender CharacterGender
{
get { return characterGender; }
set
{
if (value == characterGender) return;
// Begin saving coroutine. Remove any existing save coroutines if one is running.
if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); }
CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine");
characterGender = value;
}
}
private bool unsavedSettings;
public bool UnsavedSettings
{
get
@@ -230,18 +259,15 @@ namespace Barotrauma
case "keymapping":
foreach (XAttribute attribute in subElement.Attributes())
{
InputType inputType;
if (Enum.TryParse(attribute.Name.ToString(), true, out inputType))
if (Enum.TryParse(attribute.Name.ToString(), true, out InputType inputType))
{
int mouseButton;
if (int.TryParse(attribute.Value.ToString(), out mouseButton))
if (int.TryParse(attribute.Value.ToString(), out int mouseButton))
{
keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
}
else
{
Keys key;
if (Enum.TryParse(attribute.Value.ToString(), true, out key))
if (Enum.TryParse(attribute.Value.ToString(), true, out Keys key))
{
keyMapping[(int)inputType] = new KeyOrMouse(key);
}
@@ -258,6 +284,9 @@ namespace Barotrauma
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;
}
}
@@ -363,8 +392,10 @@ namespace Barotrauma
gameplay.Add(jobPreferences);
doc.Root.Add(gameplay);
var playerElement = new XElement("player");
playerElement.Add(new XAttribute("name", defaultPlayerName ?? ""));
var playerElement = new XElement("player",
new XAttribute("name", defaultPlayerName ?? ""),
new XAttribute("headindex", characterHeadIndex),
new XAttribute("gender", characterGender));
doc.Root.Add(playerElement);
doc.Save(filePath);