added Character Setup (#511)
* added Character Setup * whoops * reverted unrelated changes * Made everything work post-rebase * Removed unused PreferencesChanged event * nope, don't need this * HumanoidProfileEditorPanel -> HumanoidProfileEditor * Set initial data for hair pickers * Fixed nullable warning * Renamed LooksComponent -> HumanoidAppearanceComponent * Renamed LooksComponentState -> HumanoidAppearanceComponentState * Final renaming maybe * Use a human-like dummy instead of a real human * Change preferences structs back to classes
This commit is contained in:
committed by
Pieter-Jan Briers
parent
d03da83fda
commit
a4e369e629
@@ -1,109 +0,0 @@
|
||||
using System;
|
||||
using Content.Shared.Preferences.Appearance;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs
|
||||
{
|
||||
public abstract class SharedHairComponent : Component
|
||||
{
|
||||
private static readonly Color DefaultHairColor = Color.FromHex("#232323");
|
||||
|
||||
private string _facialHairStyleName = HairStyles.DefaultFacialHairStyle;
|
||||
private string _hairStyleName = HairStyles.DefaultHairStyle;
|
||||
private Color _hairColor = DefaultHairColor;
|
||||
private Color _facialHairColor = DefaultHairColor;
|
||||
|
||||
public sealed override string Name => "Hair";
|
||||
public sealed override uint? NetID => ContentNetIDs.HAIR;
|
||||
public sealed override Type StateType => typeof(HairComponentState);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual string HairStyleName
|
||||
{
|
||||
get => _hairStyleName;
|
||||
set
|
||||
{
|
||||
_hairStyleName = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual string FacialHairStyleName
|
||||
{
|
||||
get => _facialHairStyleName;
|
||||
set
|
||||
{
|
||||
_facialHairStyleName = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual Color HairColor
|
||||
{
|
||||
get => _hairColor;
|
||||
set
|
||||
{
|
||||
_hairColor = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual Color FacialHairColor
|
||||
{
|
||||
get => _facialHairColor;
|
||||
set
|
||||
{
|
||||
_facialHairColor = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new HairComponentState(HairStyleName, FacialHairStyleName, HairColor, FacialHairColor);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
||||
{
|
||||
var cast = (HairComponentState) curState;
|
||||
|
||||
HairStyleName = cast.HairStyleName;
|
||||
FacialHairStyleName = cast.FacialHairStyleName;
|
||||
HairColor = cast.HairColor;
|
||||
FacialHairColor = cast.FacialHairColor;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _hairColor, "hairColor", DefaultHairColor);
|
||||
serializer.DataField(ref _facialHairColor, "facialHairColor", DefaultHairColor);
|
||||
serializer.DataField(ref _hairStyleName, "hairStyle", HairStyles.DefaultHairStyle);
|
||||
serializer.DataField(ref _facialHairStyleName, "facialHairStyle", HairStyles.DefaultFacialHairStyle);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class HairComponentState : ComponentState
|
||||
{
|
||||
public string HairStyleName { get; }
|
||||
public string FacialHairStyleName { get; }
|
||||
public Color HairColor { get; }
|
||||
public Color FacialHairColor { get; }
|
||||
|
||||
public HairComponentState(string hairStyleName, string facialHairStyleName, Color hairColor, Color facialHairColor) : base(ContentNetIDs.HAIR)
|
||||
{
|
||||
HairStyleName = hairStyleName;
|
||||
FacialHairStyleName = facialHairStyleName;
|
||||
HairColor = hairColor;
|
||||
FacialHairColor = facialHairColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs
|
||||
{
|
||||
public abstract class SharedHumanoidAppearanceComponent : Component
|
||||
{
|
||||
private HumanoidCharacterAppearance _appearance;
|
||||
private Sex _sex;
|
||||
|
||||
public sealed override string Name => "HumanoidAppearance";
|
||||
public sealed override uint? NetID => ContentNetIDs.HUMANOID_APPEARANCE;
|
||||
public sealed override Type StateType => typeof(HumanoidAppearanceComponentState);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual HumanoidCharacterAppearance Appearance
|
||||
{
|
||||
get => _appearance;
|
||||
set
|
||||
{
|
||||
_appearance = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual Sex Sex
|
||||
{
|
||||
get => _sex;
|
||||
set
|
||||
{
|
||||
_sex = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new HumanoidAppearanceComponentState(Appearance, Sex);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
||||
{
|
||||
var cast = (HumanoidAppearanceComponentState) curState;
|
||||
Appearance = cast.Appearance;
|
||||
Sex = cast.Sex;
|
||||
}
|
||||
|
||||
public void UpdateFromProfile(ICharacterProfile profile)
|
||||
{
|
||||
var humanoid = (HumanoidCharacterProfile) profile;
|
||||
Appearance = (HumanoidCharacterAppearance) humanoid.CharacterAppearance;
|
||||
Sex = humanoid.Sex;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[NetSerializable]
|
||||
private sealed class HumanoidAppearanceComponentState : ComponentState
|
||||
{
|
||||
public HumanoidAppearanceComponentState(HumanoidCharacterAppearance appearance, Sex sex) : base(ContentNetIDs.HUMANOID_APPEARANCE)
|
||||
{
|
||||
Appearance = appearance;
|
||||
Sex = sex;
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance Appearance { get; }
|
||||
public Sex Sex { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@
|
||||
public const uint ITEMCOOLDOWN = 1029;
|
||||
public const uint CARGO_ORDER_DATABASE = 1030;
|
||||
public const uint GALACTIC_MARKET = 1031;
|
||||
public const uint HAIR = 1032;
|
||||
public const uint HUMANOID_APPEARANCE = 1032;
|
||||
public const uint INSTRUMENTS = 1033;
|
||||
public const uint WELDER = 1034;
|
||||
public const uint STACK = 1035;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Preferences.Appearance
|
||||
{
|
||||
public enum HumanoidVisualLayers
|
||||
{
|
||||
Hair,
|
||||
FacialHair,
|
||||
Body
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,24 +7,69 @@ namespace Content.Shared.Preferences
|
||||
[Serializable, NetSerializable]
|
||||
public class HumanoidCharacterAppearance : ICharacterAppearance
|
||||
{
|
||||
public string HairStyleName { get; set; }
|
||||
public Color HairColor { get; set; }
|
||||
public string FacialHairStyleName { get; set; }
|
||||
public Color FacialHairColor { get; set; }
|
||||
public Color EyeColor { get; set; }
|
||||
public Color SkinColor { get; set; }
|
||||
public HumanoidCharacterAppearance(string hairStyleName,
|
||||
Color hairColor,
|
||||
string facialHairStyleName,
|
||||
Color facialHairColor,
|
||||
Color eyeColor,
|
||||
Color skinColor)
|
||||
{
|
||||
HairStyleName = hairStyleName;
|
||||
HairColor = hairColor;
|
||||
FacialHairStyleName = facialHairStyleName;
|
||||
FacialHairColor = facialHairColor;
|
||||
EyeColor = eyeColor;
|
||||
SkinColor = skinColor;
|
||||
}
|
||||
|
||||
public string HairStyleName { get; }
|
||||
public Color HairColor { get; }
|
||||
public string FacialHairStyleName { get; }
|
||||
public Color FacialHairColor { get; }
|
||||
public Color EyeColor { get; }
|
||||
public Color SkinColor { get; }
|
||||
|
||||
public HumanoidCharacterAppearance WithHairStyleName(string newName)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(newName, HairColor, FacialHairStyleName, FacialHairColor, EyeColor, SkinColor);
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance WithHairColor(Color newColor)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(HairStyleName, newColor, FacialHairStyleName, FacialHairColor, EyeColor, SkinColor);
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance WithFacialHairStyleName(string newName)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(HairStyleName, HairColor, newName, FacialHairColor, EyeColor, SkinColor);
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance WithFacialHairColor(Color newColor)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(HairStyleName, HairColor, FacialHairStyleName, newColor, EyeColor, SkinColor);
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance WithEyeColor(Color newColor)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(HairStyleName, HairColor, FacialHairStyleName, FacialHairColor, newColor, SkinColor);
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance WithSkinColor(Color newColor)
|
||||
{
|
||||
return new HumanoidCharacterAppearance(HairStyleName, HairColor, FacialHairStyleName, FacialHairColor, EyeColor, newColor);
|
||||
}
|
||||
|
||||
public static HumanoidCharacterAppearance Default()
|
||||
{
|
||||
return new HumanoidCharacterAppearance
|
||||
{
|
||||
HairStyleName = "Bald",
|
||||
HairColor = Color.Black,
|
||||
FacialHairStyleName = "Shaved",
|
||||
FacialHairColor = Color.Black,
|
||||
EyeColor = Color.Black,
|
||||
SkinColor = Color.Black
|
||||
};
|
||||
(
|
||||
"Bald",
|
||||
Color.Black,
|
||||
"Shaved",
|
||||
Color.Black,
|
||||
Color.Black,
|
||||
Color.Black
|
||||
);
|
||||
}
|
||||
|
||||
public bool MemberwiseEquals(ICharacterAppearance maybeOther)
|
||||
|
||||
@@ -6,21 +6,49 @@ namespace Content.Shared.Preferences
|
||||
[Serializable, NetSerializable]
|
||||
public class HumanoidCharacterProfile : ICharacterProfile
|
||||
{
|
||||
public static HumanoidCharacterProfile Default()
|
||||
public HumanoidCharacterProfile(string name,
|
||||
int age,
|
||||
Sex sex,
|
||||
HumanoidCharacterAppearance appearance)
|
||||
{
|
||||
return new HumanoidCharacterProfile
|
||||
{
|
||||
Name = "John Doe",
|
||||
Age = 18,
|
||||
Sex = Sex.Male,
|
||||
CharacterAppearance = HumanoidCharacterAppearance.Default()
|
||||
};
|
||||
Name = name;
|
||||
Age = age;
|
||||
Sex = sex;
|
||||
Appearance = appearance;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public int Age { get; set; }
|
||||
public Sex Sex { get; set; }
|
||||
public ICharacterAppearance CharacterAppearance { get; set; }
|
||||
public static HumanoidCharacterProfile Default()
|
||||
{
|
||||
return new HumanoidCharacterProfile("John Doe", 18, Sex.Male, HumanoidCharacterAppearance.Default());
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public int Age { get; }
|
||||
public Sex Sex { get; }
|
||||
public ICharacterAppearance CharacterAppearance => Appearance;
|
||||
public HumanoidCharacterAppearance Appearance { get; }
|
||||
|
||||
public HumanoidCharacterProfile WithName(string name)
|
||||
{
|
||||
return new HumanoidCharacterProfile(name, Age, Sex, Appearance);
|
||||
}
|
||||
|
||||
public HumanoidCharacterProfile WithAge(int age)
|
||||
{
|
||||
return new HumanoidCharacterProfile(Name, age, Sex, Appearance);
|
||||
}
|
||||
|
||||
public HumanoidCharacterProfile WithSex(Sex sex)
|
||||
{
|
||||
return new HumanoidCharacterProfile(Name, Age, sex, Appearance);
|
||||
}
|
||||
|
||||
public HumanoidCharacterProfile WithCharacterAppearance(HumanoidCharacterAppearance appearance)
|
||||
{
|
||||
return new HumanoidCharacterProfile(Name, Age, Sex, appearance);
|
||||
}
|
||||
|
||||
public string Summary => $"{Name}, {Age} years old {Sex.ToString().ToLower()} human.\nOccupation: to be implemented.";
|
||||
|
||||
public bool MemberwiseEquals(ICharacterProfile maybeOther)
|
||||
{
|
||||
@@ -28,9 +56,7 @@ namespace Content.Shared.Preferences
|
||||
if (Name != other.Name) return false;
|
||||
if (Age != other.Age) return false;
|
||||
if (Sex != other.Sex) return false;
|
||||
if (CharacterAppearance is null)
|
||||
return other.CharacterAppearance is null;
|
||||
return CharacterAppearance.MemberwiseEquals(other.CharacterAppearance);
|
||||
return Appearance.MemberwiseEquals(other.Appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ namespace Content.Shared.Preferences
|
||||
{
|
||||
public interface ICharacterProfile
|
||||
{
|
||||
string Name { get; }
|
||||
ICharacterAppearance CharacterAppearance { get; }
|
||||
bool MemberwiseEquals(ICharacterProfile other);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Preferences
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains all player characters and the index of the currently selected character.
|
||||
/// Serialized both over the network and to disk.
|
||||
/// Contains all player characters and the index of the currently selected character.
|
||||
/// Serialized both over the network and to disk.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public class PlayerPreferences
|
||||
[Serializable]
|
||||
[NetSerializable]
|
||||
public sealed class PlayerPreferences
|
||||
{
|
||||
private List<ICharacterProfile> _characters;
|
||||
|
||||
public PlayerPreferences(IEnumerable<ICharacterProfile> characters, int selectedCharacterIndex)
|
||||
{
|
||||
_characters = characters.ToList();
|
||||
SelectedCharacterIndex = selectedCharacterIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All player characters.
|
||||
/// </summary>
|
||||
public IEnumerable<ICharacterProfile> Characters => _characters.AsEnumerable();
|
||||
|
||||
/// <summary>
|
||||
/// Index of the currently selected character.
|
||||
/// </summary>
|
||||
public int SelectedCharacterIndex { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected character.
|
||||
/// </summary>
|
||||
public ICharacterProfile SelectedCharacter => Characters.ElementAtOrDefault(SelectedCharacterIndex);
|
||||
|
||||
public int FirstEmptySlot => IndexOfCharacter(null);
|
||||
|
||||
public static PlayerPreferences Default()
|
||||
{
|
||||
return new PlayerPreferences
|
||||
{
|
||||
Characters = new List<ICharacterProfile>
|
||||
return new PlayerPreferences(new List<ICharacterProfile>
|
||||
{
|
||||
HumanoidCharacterProfile.Default()
|
||||
},
|
||||
SelectedCharacterIndex = 0
|
||||
};
|
||||
0);
|
||||
}
|
||||
|
||||
private List<ICharacterProfile> _characters;
|
||||
private int _selectedCharacterIndex;
|
||||
|
||||
/// <summary>
|
||||
/// All player characters.
|
||||
/// </summary>
|
||||
public List<ICharacterProfile> Characters
|
||||
public int IndexOfCharacter(ICharacterProfile profile)
|
||||
{
|
||||
get => _characters;
|
||||
set => _characters = value;
|
||||
return _characters.FindIndex(x => x == profile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index of the currently selected character.
|
||||
/// </summary>
|
||||
public int SelectedCharacterIndex
|
||||
{
|
||||
get => _selectedCharacterIndex;
|
||||
set => _selectedCharacterIndex = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the currently selected character.
|
||||
/// </summary>
|
||||
public ICharacterProfile SelectedCharacter => Characters.ElementAtOrDefault(SelectedCharacterIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user