Implemented random character creation (#548)
* Implemented random character creation * Pick from a list and apply a bit of randomness instead * Rename SetInitialData, unselect list entries properly
This commit is contained in:
committed by
Pieter-Jan Briers
parent
5af5a02e31
commit
46ce6bf45e
@@ -97,7 +97,7 @@ namespace Content.Client.GameObjects.Components
|
|||||||
|
|
||||||
private Color _lastColor;
|
private Color _lastColor;
|
||||||
|
|
||||||
public void SetInitialData(Color color, string styleName)
|
public void SetData(Color color, string styleName)
|
||||||
{
|
{
|
||||||
_lastColor = color;
|
_lastColor = color;
|
||||||
|
|
||||||
@@ -107,10 +107,7 @@ namespace Content.Client.GameObjects.Components
|
|||||||
|
|
||||||
foreach (var item in Items)
|
foreach (var item in Items)
|
||||||
{
|
{
|
||||||
if (item.Text == styleName)
|
item.Selected = item.Text == styleName;
|
||||||
{
|
|
||||||
item.Selected = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateStylePickerColor();
|
UpdateStylePickerColor();
|
||||||
@@ -301,8 +298,8 @@ namespace Content.Client.GameObjects.Components
|
|||||||
|
|
||||||
public void SetInitialData(MagicMirrorInitialDataMessage initialData)
|
public void SetInitialData(MagicMirrorInitialDataMessage initialData)
|
||||||
{
|
{
|
||||||
_facialHairStylePicker.SetInitialData(initialData.FacialHairColor, initialData.FacialHairName);
|
_facialHairStylePicker.SetData(initialData.FacialHairColor, initialData.FacialHairName);
|
||||||
_hairStylePicker.SetInitialData(initialData.HairColor, initialData.HairName);
|
_hairStylePicker.SetData(initialData.HairColor, initialData.HairName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
Content.Client/UserInterface/HumanoidProfileEditor.Random.cs
Normal file
67
Content.Client/UserInterface/HumanoidProfileEditor.Random.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Content.Shared.Preferences;
|
||||||
|
using Content.Shared.Preferences.Appearance;
|
||||||
|
using Content.Shared.Text;
|
||||||
|
using Robust.Shared.Interfaces.Random;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Client.UserInterface
|
||||||
|
{
|
||||||
|
public partial class HumanoidProfileEditor
|
||||||
|
{
|
||||||
|
private readonly IRobustRandom _random;
|
||||||
|
|
||||||
|
private void RandomizeEverything()
|
||||||
|
{
|
||||||
|
RandomizeSex();
|
||||||
|
RandomizeAge();
|
||||||
|
RandomizeName();
|
||||||
|
RandomizeAppearance();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RandomizeSex()
|
||||||
|
{
|
||||||
|
SetSex(_random.Prob(0.5f) ? Sex.Male : Sex.Female);
|
||||||
|
UpdateSexControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RandomizeAge()
|
||||||
|
{
|
||||||
|
SetAge(_random.Next(HumanoidCharacterProfile.MinimumAge, HumanoidCharacterProfile.MaximumAge));
|
||||||
|
UpdateAgeEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RandomizeName()
|
||||||
|
{
|
||||||
|
var firstName = _random.Pick(Profile.Sex == Sex.Male
|
||||||
|
? Names.MaleFirstNames
|
||||||
|
: Names.FemaleFirstNames);
|
||||||
|
var lastName = _random.Pick(Names.LastNames);
|
||||||
|
SetName($"{firstName} {lastName}");
|
||||||
|
UpdateNameEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RandomizeAppearance()
|
||||||
|
{
|
||||||
|
var newHairStyle = _random.Pick(HairStyles.HairStylesMap.Keys.ToList());
|
||||||
|
|
||||||
|
var newFacialHairStyle = Profile.Sex == Sex.Female
|
||||||
|
? HairStyles.DefaultFacialHairStyle
|
||||||
|
: _random.Pick(HairStyles.FacialHairStylesMap.Keys.ToList());
|
||||||
|
|
||||||
|
var newHairColor = _random.Pick(HairStyles.RealisticHairColors);
|
||||||
|
newHairColor = newHairColor
|
||||||
|
.WithRed(newHairColor.R + _random.Next(-25, 25) / 100f)
|
||||||
|
.WithGreen(newHairColor.G + _random.Next(-25, 25) / 100f)
|
||||||
|
.WithBlue(newHairColor.B + _random.Next(-25, 25) / 100f);
|
||||||
|
|
||||||
|
Profile = Profile.WithCharacterAppearance(
|
||||||
|
Profile.Appearance
|
||||||
|
.WithHairStyleName(newHairStyle)
|
||||||
|
.WithFacialHairStyleName(newFacialHairStyle)
|
||||||
|
.WithHairColor(newHairColor)
|
||||||
|
.WithFacialHairColor(newHairColor));
|
||||||
|
UpdateHairPickers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ using Content.Client.Interfaces;
|
|||||||
using Content.Shared;
|
using Content.Shared;
|
||||||
using Content.Shared.Jobs;
|
using Content.Shared.Jobs;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
using Content.Shared.Text;
|
|
||||||
using Robust.Client.Graphics.Drawing;
|
using Robust.Client.Graphics.Drawing;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
@@ -15,11 +14,10 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
|
||||||
|
|
||||||
namespace Content.Client.UserInterface
|
namespace Content.Client.UserInterface
|
||||||
{
|
{
|
||||||
public class HumanoidProfileEditor : Control
|
public partial class HumanoidProfileEditor : Control
|
||||||
{
|
{
|
||||||
private static readonly StyleBoxFlat HighlightedStyle = new StyleBoxFlat
|
private static readonly StyleBoxFlat HighlightedStyle = new StyleBoxFlat
|
||||||
{
|
{
|
||||||
@@ -31,7 +29,6 @@ namespace Content.Client.UserInterface
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly LineEdit _ageEdit;
|
private readonly LineEdit _ageEdit;
|
||||||
|
|
||||||
private readonly LineEdit _nameEdit;
|
private readonly LineEdit _nameEdit;
|
||||||
private readonly IClientPreferencesManager _preferencesManager;
|
private readonly IClientPreferencesManager _preferencesManager;
|
||||||
private readonly Button _saveButton;
|
private readonly Button _saveButton;
|
||||||
@@ -47,15 +44,10 @@ namespace Content.Client.UserInterface
|
|||||||
public HumanoidCharacterProfile Profile;
|
public HumanoidCharacterProfile Profile;
|
||||||
public event Action<HumanoidCharacterProfile> OnProfileChanged;
|
public event Action<HumanoidCharacterProfile> OnProfileChanged;
|
||||||
|
|
||||||
private void NameChanged(string newName)
|
|
||||||
{
|
|
||||||
Profile = Profile?.WithName(newName);
|
|
||||||
IsDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HumanoidProfileEditor(ILocalizationManager localization,
|
public HumanoidProfileEditor(ILocalizationManager localization,
|
||||||
IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager)
|
IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager)
|
||||||
{
|
{
|
||||||
|
_random = IoCManager.Resolve<IRobustRandom>();
|
||||||
Profile = (HumanoidCharacterProfile) preferencesManager.Preferences.SelectedCharacter;
|
Profile = (HumanoidCharacterProfile) preferencesManager.Preferences.SelectedCharacter;
|
||||||
CharacterSlot = preferencesManager.Preferences.SelectedCharacterIndex;
|
CharacterSlot = preferencesManager.Preferences.SelectedCharacterIndex;
|
||||||
_preferencesManager = preferencesManager;
|
_preferencesManager = preferencesManager;
|
||||||
@@ -87,10 +79,9 @@ namespace Content.Client.UserInterface
|
|||||||
var panel = HighlightedContainer();
|
var panel = HighlightedContainer();
|
||||||
var randomizeEverythingButton = new Button
|
var randomizeEverythingButton = new Button
|
||||||
{
|
{
|
||||||
Text = localization.GetString("Randomize everything"),
|
Text = localization.GetString("Randomize everything")
|
||||||
Disabled = true,
|
|
||||||
ToolTip = "Not yet implemented!"
|
|
||||||
};
|
};
|
||||||
|
randomizeEverythingButton.OnPressed += args => { RandomizeEverything(); };
|
||||||
panel.AddChild(randomizeEverythingButton);
|
panel.AddChild(randomizeEverythingButton);
|
||||||
leftColumn.AddChild(panel);
|
leftColumn.AddChild(panel);
|
||||||
}
|
}
|
||||||
@@ -111,22 +102,12 @@ namespace Content.Client.UserInterface
|
|||||||
CustomMinimumSize = (270, 0),
|
CustomMinimumSize = (270, 0),
|
||||||
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
||||||
};
|
};
|
||||||
_nameEdit.OnTextChanged += args => { NameChanged(args.Text); };
|
_nameEdit.OnTextChanged += args => { SetName(args.Text); };
|
||||||
var nameRandomButton = new Button
|
var nameRandomButton = new Button
|
||||||
{
|
{
|
||||||
Text = localization.GetString("Randomize"),
|
Text = localization.GetString("Randomize"),
|
||||||
};
|
};
|
||||||
nameRandomButton.OnPressed += args =>
|
nameRandomButton.OnPressed += args => RandomizeName();
|
||||||
{
|
|
||||||
var random = IoCManager.Resolve<IRobustRandom>();
|
|
||||||
var firstName = random.Pick(
|
|
||||||
Profile.Sex == Sex.Male
|
|
||||||
? Names.MaleFirstNames
|
|
||||||
: Names.FemaleFirstNames);
|
|
||||||
var lastName = random.Pick(Names.LastNames);
|
|
||||||
_nameEdit.Text = $"{firstName} {lastName}";
|
|
||||||
NameChanged(_nameEdit.Text);
|
|
||||||
};
|
|
||||||
hBox.AddChild(nameLabel);
|
hBox.AddChild(nameLabel);
|
||||||
hBox.AddChild(_nameEdit);
|
hBox.AddChild(_nameEdit);
|
||||||
hBox.AddChild(nameRandomButton);
|
hBox.AddChild(nameRandomButton);
|
||||||
@@ -169,8 +150,7 @@ namespace Content.Client.UserInterface
|
|||||||
};
|
};
|
||||||
_sexMaleButton.OnPressed += args =>
|
_sexMaleButton.OnPressed += args =>
|
||||||
{
|
{
|
||||||
Profile = Profile?.WithSex(Sex.Male);
|
SetSex(Sex.Male);
|
||||||
IsDirty = true;
|
|
||||||
};
|
};
|
||||||
_sexFemaleButton = new Button
|
_sexFemaleButton = new Button
|
||||||
{
|
{
|
||||||
@@ -179,8 +159,7 @@ namespace Content.Client.UserInterface
|
|||||||
};
|
};
|
||||||
_sexFemaleButton.OnPressed += args =>
|
_sexFemaleButton.OnPressed += args =>
|
||||||
{
|
{
|
||||||
Profile = Profile?.WithSex(Sex.Female);
|
SetSex(Sex.Female);
|
||||||
IsDirty = true;
|
|
||||||
};
|
};
|
||||||
hBox.AddChild(sexLabel);
|
hBox.AddChild(sexLabel);
|
||||||
hBox.AddChild(_sexMaleButton);
|
hBox.AddChild(_sexMaleButton);
|
||||||
@@ -202,8 +181,7 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
if (!int.TryParse(args.Text, out var newAge))
|
if (!int.TryParse(args.Text, out var newAge))
|
||||||
return;
|
return;
|
||||||
Profile = Profile?.WithAge(newAge);
|
SetAge(newAge);
|
||||||
IsDirty = true;
|
|
||||||
};
|
};
|
||||||
hBox.AddChild(ageLabel);
|
hBox.AddChild(ageLabel);
|
||||||
hBox.AddChild(_ageEdit);
|
hBox.AddChild(_ageEdit);
|
||||||
@@ -395,6 +373,24 @@ namespace Content.Client.UserInterface
|
|||||||
IsDirty = false;
|
IsDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetAge(int newAge)
|
||||||
|
{
|
||||||
|
Profile = Profile?.WithAge(newAge);
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetSex(Sex newSex)
|
||||||
|
{
|
||||||
|
Profile = Profile?.WithSex(newSex);
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetName(string newName)
|
||||||
|
{
|
||||||
|
Profile = Profile?.WithName(newName);
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
IsDirty = false;
|
IsDirty = false;
|
||||||
@@ -420,6 +416,16 @@ namespace Content.Client.UserInterface
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateNameEdit()
|
||||||
|
{
|
||||||
|
_nameEdit.Text = Profile.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateAgeEdit()
|
||||||
|
{
|
||||||
|
_ageEdit.Text = Profile.Age.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateSexControls()
|
private void UpdateSexControls()
|
||||||
{
|
{
|
||||||
if (Profile.Sex == Sex.Male)
|
if (Profile.Sex == Sex.Male)
|
||||||
@@ -430,10 +436,10 @@ namespace Content.Client.UserInterface
|
|||||||
|
|
||||||
private void UpdateHairPickers()
|
private void UpdateHairPickers()
|
||||||
{
|
{
|
||||||
_hairPicker.SetInitialData(
|
_hairPicker.SetData(
|
||||||
Profile.Appearance.HairColor,
|
Profile.Appearance.HairColor,
|
||||||
Profile.Appearance.HairStyleName);
|
Profile.Appearance.HairStyleName);
|
||||||
_facialHairPicker.SetInitialData(
|
_facialHairPicker.SetData(
|
||||||
Profile.Appearance.FacialHairColor,
|
Profile.Appearance.FacialHairColor,
|
||||||
Profile.Appearance.FacialHairStyleName);
|
Profile.Appearance.FacialHairStyleName);
|
||||||
}
|
}
|
||||||
@@ -446,9 +452,9 @@ namespace Content.Client.UserInterface
|
|||||||
public void UpdateControls()
|
public void UpdateControls()
|
||||||
{
|
{
|
||||||
if (Profile is null) return;
|
if (Profile is null) return;
|
||||||
_nameEdit.Text = Profile?.Name;
|
UpdateNameEdit();
|
||||||
UpdateSexControls();
|
UpdateSexControls();
|
||||||
_ageEdit.Text = Profile?.Age.ToString();
|
UpdateAgeEdit();
|
||||||
UpdateHairPickers();
|
UpdateHairPickers();
|
||||||
UpdateSaveButton();
|
UpdateSaveButton();
|
||||||
UpdateJobPriorities();
|
UpdateJobPriorities();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
namespace Content.Shared.Preferences.Appearance
|
namespace Content.Shared.Preferences.Appearance
|
||||||
{
|
{
|
||||||
@@ -268,5 +269,15 @@ namespace Content.Shared.Preferences.Appearance
|
|||||||
|
|
||||||
return string.Compare(styleA, styleB, StringComparison.CurrentCulture);
|
return string.Compare(styleA, styleB, StringComparison.CurrentCulture);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
public static IReadOnlyList<Color> RealisticHairColors = new List<Color>
|
||||||
|
{
|
||||||
|
Color.Yellow,
|
||||||
|
Color.Black,
|
||||||
|
Color.SandyBrown,
|
||||||
|
Color.Brown,
|
||||||
|
Color.Wheat,
|
||||||
|
Color.Gray
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ namespace Content.Shared.Preferences
|
|||||||
public class HumanoidCharacterProfile : ICharacterProfile
|
public class HumanoidCharacterProfile : ICharacterProfile
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, JobPriority> _jobPriorities;
|
private readonly Dictionary<string, JobPriority> _jobPriorities;
|
||||||
|
public static int MinimumAge = 18;
|
||||||
|
public static int MaximumAge = 90;
|
||||||
|
|
||||||
private HumanoidCharacterProfile(
|
private HumanoidCharacterProfile(
|
||||||
string name,
|
string name,
|
||||||
|
|||||||
Reference in New Issue
Block a user