Markings (#7072)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
28
Content.Client/Markings/MarkingPicker.xaml
Normal file
28
Content.Client/Markings/MarkingPicker.xaml
Normal file
@@ -0,0 +1,28 @@
|
||||
<Control xmlns="https://spacestation14.io">
|
||||
<!-- Primary container -->
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<!-- Marking lists -->
|
||||
<BoxContainer Orientation="Horizontal" SeparationOverride="5" HorizontalExpand="True">
|
||||
<!-- Unused markings -->
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'markings-unused'}" />
|
||||
<OptionButton Name="CMarkingCategoryButton" />
|
||||
<ItemList Name="CMarkingsUnused" VerticalExpand="True" MinSize="300 250" />
|
||||
<Label Name="CMarkingPoints" Text="uwu" />
|
||||
<Button Name="CMarkingAdd" Text="{Loc 'markings-add'}" />
|
||||
</BoxContainer>
|
||||
<!-- Used markings -->
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'markings-used'}" />
|
||||
<ItemList Name="CMarkingsUsed" VerticalExpand="True" MinSize="300 250" />
|
||||
<BoxContainer Orientation="Horizontal" SeparationOverride="5">
|
||||
<Button Name="CMarkingRankUp" Text="{Loc 'markings-rank-up'}" HorizontalExpand="True" />
|
||||
<Button Name="CMarkingRankDown" Text="{Loc 'markings-rank-down'}" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<Button Name="CMarkingRemove" Text="{Loc 'markings-remove'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<!-- Colors -->
|
||||
<BoxContainer Name="CMarkingColors" Orientation="Vertical" Visible="False" />
|
||||
</BoxContainer>
|
||||
</Control>
|
||||
439
Content.Client/Markings/MarkingPicker.xaml.cs
Normal file
439
Content.Client/Markings/MarkingPicker.xaml.cs
Normal file
@@ -0,0 +1,439 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.CharacterAppearance;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.CharacterAppearance;
|
||||
using Content.Shared.Markings;
|
||||
using Content.Shared.Species;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Markings
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class MarkingPicker : Control
|
||||
{
|
||||
[Dependency] private readonly MarkingManager _markingManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public Action<MarkingsSet>? OnMarkingAdded;
|
||||
public Action<MarkingsSet>? OnMarkingRemoved;
|
||||
public Action<MarkingsSet>? OnMarkingColorChange;
|
||||
public Action<MarkingsSet>? OnMarkingRankChange;
|
||||
|
||||
private List<Color> _currentMarkingColors = new();
|
||||
|
||||
private Dictionary<MarkingCategories, MarkingPoints> PointLimits = new();
|
||||
private Dictionary<MarkingCategories, MarkingPoints> PointsUsed = new();
|
||||
|
||||
private ItemList.Item? _selectedMarking;
|
||||
private ItemList.Item? _selectedUnusedMarking;
|
||||
private MarkingCategories _selectedMarkingCategory = MarkingCategories.Chest;
|
||||
|
||||
private MarkingsSet _currentMarkings = new();
|
||||
|
||||
private List<MarkingCategories> _markingCategories = Enum.GetValues<MarkingCategories>().ToList();
|
||||
|
||||
private string _currentSpecies = SpeciesManager.DefaultSpecies;
|
||||
|
||||
public void SetData(MarkingsSet newMarkings, string species)
|
||||
{
|
||||
_currentMarkings = newMarkings;
|
||||
_currentSpecies = species;
|
||||
|
||||
// Should marking limits be dependent on species prototypes,
|
||||
// or should it be dependent on the entity the
|
||||
// species contains? Having marking points as a part of
|
||||
// the component allows for any arbitrary thing to have
|
||||
// a marking (at this point, it's practically a sprite decoration),
|
||||
// but having it as a part of a species makes markings instead
|
||||
// be dependent on humanoid variants for constraints
|
||||
SpeciesPrototype speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(species);
|
||||
EntityPrototype body = _prototypeManager.Index<EntityPrototype>(speciesPrototype.Prototype);
|
||||
|
||||
body.TryGetComponent("Markings", out MarkingsComponent? markingsComponent);
|
||||
|
||||
PointLimits = markingsComponent!.LayerPoints;
|
||||
PointsUsed = MarkingPoints.CloneMarkingPointDictionary(PointLimits);
|
||||
|
||||
Populate();
|
||||
PopulateUsed();
|
||||
}
|
||||
|
||||
public MarkingPicker()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
for (int i = 0; i < _markingCategories.Count; i++)
|
||||
{
|
||||
CMarkingCategoryButton.AddItem(Loc.GetString($"markings-category-{_markingCategories[i].ToString()}"), i);
|
||||
}
|
||||
CMarkingCategoryButton.SelectId(_markingCategories.IndexOf(MarkingCategories.Chest));
|
||||
CMarkingCategoryButton.OnItemSelected += OnCategoryChange;
|
||||
CMarkingsUnused.OnItemSelected += item =>
|
||||
_selectedUnusedMarking = CMarkingsUnused[item.ItemIndex];
|
||||
|
||||
CMarkingAdd.OnPressed += args =>
|
||||
MarkingAdd();
|
||||
|
||||
CMarkingsUsed.OnItemSelected += OnUsedMarkingSelected;
|
||||
|
||||
CMarkingRemove.OnPressed += args =>
|
||||
MarkingRemove();
|
||||
|
||||
CMarkingRankUp.OnPressed += _ => SwapMarkingUp();
|
||||
CMarkingRankDown.OnPressed += _ => SwapMarkingDown();
|
||||
}
|
||||
|
||||
private string GetMarkingName(MarkingPrototype marking) => Loc.GetString($"marking-{marking.ID}");
|
||||
private List<string> GetMarkingStateNames(MarkingPrototype marking)
|
||||
{
|
||||
List<string> result = new();
|
||||
foreach (var markingState in marking.Sprites)
|
||||
{
|
||||
switch (markingState)
|
||||
{
|
||||
case SpriteSpecifier.Rsi rsi:
|
||||
result.Add(Loc.GetString($"marking-{marking.ID}-{rsi.RsiState}"));
|
||||
break;
|
||||
case SpriteSpecifier.Texture texture:
|
||||
result.Add(Loc.GetString($"marking-{marking.ID}-{texture.TexturePath.Filename}"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Populate()
|
||||
{
|
||||
CMarkingsUnused.Clear();
|
||||
_selectedUnusedMarking = null;
|
||||
|
||||
var markings = _markingManager.CategorizedMarkings();
|
||||
foreach (var marking in markings[_selectedMarkingCategory])
|
||||
{
|
||||
if (_currentMarkings.Contains(marking.AsMarking())) continue;
|
||||
if (marking.SpeciesRestrictions != null && !marking.SpeciesRestrictions.Contains(_currentSpecies)) continue;
|
||||
var item = CMarkingsUnused.AddItem($"{GetMarkingName(marking)}", marking.Sprites[0].Frame0());
|
||||
item.Metadata = marking;
|
||||
}
|
||||
|
||||
if (PointsUsed.ContainsKey(_selectedMarkingCategory))
|
||||
{
|
||||
CMarkingPoints.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CMarkingPoints.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the used marking list. Returns a list of markings that weren't
|
||||
// valid to add to the marking list.
|
||||
public void PopulateUsed()
|
||||
{
|
||||
CMarkingsUsed.Clear();
|
||||
CMarkingColors.Visible = false;
|
||||
_selectedMarking = null;
|
||||
|
||||
// a little slower than the original process
|
||||
// (the original method here had the logic
|
||||
// tied with the presentation, which did it all
|
||||
// in one go including display)
|
||||
//
|
||||
// BUT
|
||||
//
|
||||
// it's all client side
|
||||
// so does it really matter???
|
||||
//
|
||||
// actual validation/filtering occurs server side, but
|
||||
// it might be better to just have a Process function
|
||||
// that just iterates through all the markings with
|
||||
// a species and points dict to ensure that all markings
|
||||
// that were given are valid?
|
||||
//
|
||||
// one of the larger issues is that this doesn't
|
||||
// necessarily use the existing backing list, but rather it
|
||||
// allocates entirely new lists instead to perform
|
||||
// their functions, making a 'Process' function
|
||||
// more desirable imo, since this isn't *really* used
|
||||
// outside of this specific niche
|
||||
|
||||
var markings = new MarkingsSet(_currentMarkings);
|
||||
|
||||
// ensures all markings are valid
|
||||
markings = MarkingsSet.EnsureValid(_currentMarkings, _markingManager);
|
||||
|
||||
// filters out all non-valid species markings
|
||||
markings = MarkingsSet.FilterSpecies(_currentMarkings, _currentSpecies);
|
||||
|
||||
// processes all the points currently available
|
||||
markings = MarkingsSet.ProcessPoints(_currentMarkings, PointsUsed);
|
||||
|
||||
// if the marking set has changed, invoke the event that involves changed marking sets
|
||||
if (markings != _currentMarkings)
|
||||
{
|
||||
Logger.DebugS("Markings", "Marking set is different, resetting markings on dummy now");
|
||||
_currentMarkings = markings;
|
||||
OnMarkingRemoved?.Invoke(_currentMarkings);
|
||||
}
|
||||
|
||||
IEnumerator markingEnumerator = _currentMarkings.GetReverseEnumerator();
|
||||
|
||||
// walk backwards through the list for visual purposes
|
||||
while (markingEnumerator.MoveNext())
|
||||
{
|
||||
Marking marking = (Marking) markingEnumerator.Current;
|
||||
var newMarking = _markingManager.Markings()[marking.MarkingId];
|
||||
var _item = new ItemList.Item(CMarkingsUsed)
|
||||
{
|
||||
Text = Loc.GetString("marking-used", ("marking-name", $"{GetMarkingName(newMarking)}"), ("marking-category", Loc.GetString($"markings-category-{newMarking.MarkingCategory}"))),
|
||||
Icon = newMarking.Sprites[0].Frame0(),
|
||||
Selectable = true,
|
||||
Metadata = newMarking,
|
||||
IconModulate = marking.MarkingColors[0]
|
||||
};
|
||||
CMarkingsUsed.Add(_item);
|
||||
}
|
||||
|
||||
// since all the points have been processed, update the points visually
|
||||
UpdatePoints();
|
||||
}
|
||||
|
||||
private void SwapMarkingUp()
|
||||
{
|
||||
if (_selectedMarking == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var i = CMarkingsUsed.IndexOf(_selectedMarking);
|
||||
if (ShiftMarkingRank(i, -1))
|
||||
{
|
||||
OnMarkingRankChange?.Invoke(_currentMarkings);
|
||||
}
|
||||
}
|
||||
|
||||
private void SwapMarkingDown()
|
||||
{
|
||||
if (_selectedMarking == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var i = CMarkingsUsed.IndexOf(_selectedMarking);
|
||||
if (ShiftMarkingRank(i, 1))
|
||||
{
|
||||
OnMarkingRankChange?.Invoke(_currentMarkings);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShiftMarkingRank(int src, int places)
|
||||
{
|
||||
if (src + places >= CMarkingsUsed.Count || src + places < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var visualDest = src + places; // what it would visually look like
|
||||
var visualTemp = CMarkingsUsed[visualDest];
|
||||
CMarkingsUsed[visualDest] = CMarkingsUsed[src];
|
||||
CMarkingsUsed[src] = visualTemp;
|
||||
|
||||
switch (places)
|
||||
{
|
||||
// i.e., we're going down in rank
|
||||
case < 0:
|
||||
_currentMarkings.ShiftRankDownFromEnd(src);
|
||||
break;
|
||||
// i.e., we're going up in rank
|
||||
case > 0:
|
||||
_currentMarkings.ShiftRankUpFromEnd(src);
|
||||
break;
|
||||
// do nothing?
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// repopulate in case markings are restricted,
|
||||
// and also filter out any markings that are now invalid
|
||||
// attempt to preserve any existing markings as well:
|
||||
// it would be frustrating to otherwise have all markings
|
||||
// cleared, imo
|
||||
public void SetSpecies(string species)
|
||||
{
|
||||
_currentSpecies = species;
|
||||
var markingCount = _currentMarkings.Count;
|
||||
|
||||
SpeciesPrototype speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(species);
|
||||
EntityPrototype body = _prototypeManager.Index<EntityPrototype>(speciesPrototype.Prototype);
|
||||
|
||||
body.TryGetComponent("Markings", out MarkingsComponent? markingsComponent);
|
||||
|
||||
PointLimits = markingsComponent!.LayerPoints;
|
||||
PointsUsed = MarkingPoints.CloneMarkingPointDictionary(PointLimits);
|
||||
|
||||
Populate();
|
||||
PopulateUsed();
|
||||
}
|
||||
|
||||
private void UpdatePoints()
|
||||
{
|
||||
if (PointsUsed.TryGetValue(_selectedMarkingCategory, out var pointsRemaining))
|
||||
{
|
||||
CMarkingPoints.Text = Loc.GetString("marking-points-remaining", ("points", pointsRemaining.Points));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCategoryChange(OptionButton.ItemSelectedEventArgs category)
|
||||
{
|
||||
CMarkingCategoryButton.SelectId(category.Id);
|
||||
_selectedMarkingCategory = _markingCategories[category.Id];
|
||||
Populate();
|
||||
UpdatePoints();
|
||||
}
|
||||
|
||||
// TODO: This should be using ColorSelectorSliders once that's merged, so
|
||||
private void OnUsedMarkingSelected(ItemList.ItemListSelectedEventArgs item)
|
||||
{
|
||||
_selectedMarking = CMarkingsUsed[item.ItemIndex];
|
||||
var prototype = (MarkingPrototype) _selectedMarking.Metadata!;
|
||||
|
||||
if (prototype.FollowSkinColor)
|
||||
{
|
||||
CMarkingColors.Visible = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var stateNames = GetMarkingStateNames(prototype);
|
||||
_currentMarkingColors.Clear();
|
||||
CMarkingColors.DisposeAllChildren();
|
||||
List<ColorSelectorSliders> colorSliders = new();
|
||||
for (int i = 0; i < prototype.Sprites.Count; i++)
|
||||
{
|
||||
var colorContainer = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
};
|
||||
|
||||
CMarkingColors.AddChild(colorContainer);
|
||||
|
||||
ColorSelectorSliders colorSelector = new ColorSelectorSliders();
|
||||
colorSliders.Add(colorSelector);
|
||||
|
||||
colorContainer.AddChild(new Label { Text = $"{stateNames[i]} color:" });
|
||||
colorContainer.AddChild(colorSelector);
|
||||
|
||||
var currentColor = new Color(
|
||||
_currentMarkings[_currentMarkings.Count - 1 - item.ItemIndex].MarkingColors[i].RByte,
|
||||
_currentMarkings[_currentMarkings.Count - 1 - item.ItemIndex].MarkingColors[i].GByte,
|
||||
_currentMarkings[_currentMarkings.Count - 1 - item.ItemIndex].MarkingColors[i].BByte
|
||||
);
|
||||
colorSelector.Color = currentColor;
|
||||
_currentMarkingColors.Add(currentColor);
|
||||
int colorIndex = _currentMarkingColors.IndexOf(currentColor);
|
||||
|
||||
Action<Color> colorChanged = delegate(Color color)
|
||||
{
|
||||
_currentMarkingColors[colorIndex] = colorSelector.Color;
|
||||
|
||||
ColorChanged(colorIndex);
|
||||
};
|
||||
colorSelector.OnColorChanged += colorChanged;
|
||||
}
|
||||
|
||||
CMarkingColors.Visible = true;
|
||||
}
|
||||
|
||||
private void ColorChanged(int colorIndex)
|
||||
{
|
||||
if (_selectedMarking is null) return;
|
||||
var markingPrototype = (MarkingPrototype) _selectedMarking.Metadata!;
|
||||
int markingIndex = _currentMarkings.FindIndexOf(markingPrototype.ID);
|
||||
|
||||
if (markingIndex < 0) return;
|
||||
|
||||
_selectedMarking.IconModulate = _currentMarkingColors[colorIndex];
|
||||
_currentMarkings[markingIndex].SetColor(colorIndex, _currentMarkingColors[colorIndex]);
|
||||
OnMarkingColorChange?.Invoke(_currentMarkings);
|
||||
}
|
||||
|
||||
private void MarkingAdd()
|
||||
{
|
||||
if (_selectedUnusedMarking is null) return;
|
||||
|
||||
MarkingPrototype marking = (MarkingPrototype) _selectedUnusedMarking.Metadata!;
|
||||
|
||||
if (PointsUsed.TryGetValue(marking.MarkingCategory, out var points))
|
||||
{
|
||||
if (points.Points == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
points.Points--;
|
||||
}
|
||||
|
||||
UpdatePoints();
|
||||
|
||||
_currentMarkings.AddBack(marking.AsMarking());
|
||||
|
||||
CMarkingsUnused.Remove(_selectedUnusedMarking);
|
||||
var item = new ItemList.Item(CMarkingsUsed)
|
||||
{
|
||||
Text = Loc.GetString("marking-used", ("marking-name", $"{GetMarkingName(marking)}"), ("marking-category", Loc.GetString($"markings-category-{marking.MarkingCategory}"))),
|
||||
Icon = marking.Sprites[0].Frame0(),
|
||||
Selectable = true,
|
||||
Metadata = marking,
|
||||
};
|
||||
CMarkingsUsed.Insert(0, item);
|
||||
|
||||
_selectedUnusedMarking = null;
|
||||
OnMarkingAdded?.Invoke(_currentMarkings);
|
||||
}
|
||||
|
||||
private void MarkingRemove()
|
||||
{
|
||||
if (_selectedMarking is null) return;
|
||||
|
||||
MarkingPrototype marking = (MarkingPrototype) _selectedMarking.Metadata!;
|
||||
|
||||
if (PointsUsed.TryGetValue(marking.MarkingCategory, out var points))
|
||||
{
|
||||
points.Points++;
|
||||
}
|
||||
|
||||
UpdatePoints();
|
||||
|
||||
_currentMarkings.Remove(marking.AsMarking());
|
||||
CMarkingsUsed.Remove(_selectedMarking);
|
||||
|
||||
if (marking.MarkingCategory == _selectedMarkingCategory)
|
||||
{
|
||||
var item = CMarkingsUnused.AddItem($"{GetMarkingName(marking)}", marking.Sprites[0].Frame0());
|
||||
item.Metadata = marking;
|
||||
}
|
||||
_selectedMarking = null;
|
||||
CMarkingColors.Visible = false;
|
||||
OnMarkingRemoved?.Invoke(_currentMarkings);
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Content.Client/Markings/MarkingsSystem.cs
Normal file
162
Content.Client/Markings/MarkingsSystem.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.CharacterAppearance.Systems;
|
||||
using Content.Shared.Markings;
|
||||
using Content.Shared.CharacterAppearance;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Markings
|
||||
{
|
||||
public sealed class MarkingsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly MarkingManager _markingManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MarkingsComponent, SharedHumanoidAppearanceSystem.ChangedHumanoidAppearanceEvent>(UpdateMarkings);
|
||||
}
|
||||
|
||||
public void ToggleMarkingVisibility(EntityUid uid, SpriteComponent body, HumanoidVisualLayers layer, bool toggle)
|
||||
{
|
||||
if(!EntityManager.TryGetComponent(uid, out MarkingsComponent? markings)) return;
|
||||
|
||||
if (markings.ActiveMarkings.TryGetValue(layer, out List<Marking>? layerMarkings))
|
||||
foreach (Marking activeMarking in layerMarkings)
|
||||
body.LayerSetVisible(activeMarking.MarkingId, toggle);
|
||||
}
|
||||
|
||||
public void SetActiveMarkings(EntityUid uid, MarkingsSet markingList, MarkingsComponent? markings = null)
|
||||
{
|
||||
if (!Resolve(uid, ref markings))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
markings.ActiveMarkings.Clear();
|
||||
|
||||
foreach (HumanoidVisualLayers layer in HumanoidAppearanceSystem.BodyPartLayers)
|
||||
{
|
||||
markings.ActiveMarkings.Add(layer, new List<Marking>());
|
||||
}
|
||||
|
||||
foreach (var marking in markingList)
|
||||
{
|
||||
markings.ActiveMarkings[_markingManager.Markings()[marking.MarkingId].BodyPart].Add(marking);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMarkings(EntityUid uid, MarkingsComponent markings, SharedHumanoidAppearanceSystem.ChangedHumanoidAppearanceEvent args)
|
||||
{
|
||||
var appearance = args.Appearance;
|
||||
if (!EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) return;
|
||||
MarkingsSet totalMarkings = new MarkingsSet(appearance.Markings);
|
||||
|
||||
Dictionary<MarkingCategories, MarkingPoints> usedPoints = MarkingPoints.CloneMarkingPointDictionary(markings.LayerPoints);
|
||||
|
||||
var markingsEnumerator = appearance.Markings.GetReverseEnumerator();
|
||||
// Reverse ordering
|
||||
while (markingsEnumerator.MoveNext())
|
||||
{
|
||||
var marking = (Marking) markingsEnumerator.Current;
|
||||
if (!_markingManager.IsValidMarking(marking, out MarkingPrototype? markingPrototype))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usedPoints.TryGetValue(markingPrototype.MarkingCategory, out MarkingPoints? points))
|
||||
{
|
||||
if (points.Points == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
points.Points--;
|
||||
}
|
||||
|
||||
if (!sprite.LayerMapTryGet(markingPrototype.BodyPart, out int targetLayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < markingPrototype.Sprites.Count(); j++)
|
||||
{
|
||||
var rsi = (SpriteSpecifier.Rsi) markingPrototype.Sprites[j];
|
||||
string layerId = $"{markingPrototype.ID}-{rsi.RsiState}";
|
||||
|
||||
if (sprite.LayerMapTryGet(layerId, out var existingLayer))
|
||||
{
|
||||
sprite.RemoveLayer(existingLayer);
|
||||
sprite.LayerMapRemove(marking.MarkingId);
|
||||
}
|
||||
|
||||
int layer = sprite.AddLayer(markingPrototype.Sprites[j], targetLayer + j + 1);
|
||||
sprite.LayerMapSet(layerId, layer);
|
||||
if (markingPrototype.FollowSkinColor)
|
||||
{
|
||||
sprite.LayerSetColor(layerId, appearance.SkinColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.LayerSetColor(layerId, marking.MarkingColors[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// for each layer, check if it's required and
|
||||
// if the points are greater than zero
|
||||
//
|
||||
// if so, then we start applying default markings
|
||||
// until the point requirement is satisfied -
|
||||
// this can also mean that a specific set of markings
|
||||
// is applied on top of existing markings
|
||||
//
|
||||
// All default markings will follow the skin color of
|
||||
// the current body.
|
||||
foreach (var (layerType, points) in usedPoints)
|
||||
{
|
||||
if (points.Required && points.Points > 0)
|
||||
{
|
||||
while (points.Points > 0)
|
||||
{
|
||||
// this all has to be checked, continues shouldn't occur because
|
||||
// points.Points needs to be subtracted
|
||||
if (points.DefaultMarkings.TryGetValue(points.Points - 1, out var marking)
|
||||
&& _markingManager.Markings().TryGetValue(marking, out var markingPrototype)
|
||||
&& markingPrototype.MarkingCategory == layerType // check if this actually belongs on this layer, too
|
||||
&& sprite.LayerMapTryGet(markingPrototype.BodyPart, out int targetLayer))
|
||||
{
|
||||
for (int j = 0; j < markingPrototype.Sprites.Count(); j++)
|
||||
{
|
||||
var rsi = (SpriteSpecifier.Rsi) markingPrototype.Sprites[j];
|
||||
string layerId = $"{markingPrototype.ID}-{rsi.RsiState}";
|
||||
|
||||
if (sprite.LayerMapTryGet(layerId, out var existingLayer))
|
||||
{
|
||||
sprite.RemoveLayer(existingLayer);
|
||||
sprite.LayerMapRemove(markingPrototype.ID);
|
||||
}
|
||||
|
||||
int layer = sprite.AddLayer(markingPrototype.Sprites[j], targetLayer + j + 1);
|
||||
sprite.LayerMapSet(layerId, layer);
|
||||
sprite.LayerSetColor(layerId, appearance.SkinColor);
|
||||
}
|
||||
|
||||
totalMarkings.AddBack(markingPrototype.AsMarking());
|
||||
}
|
||||
|
||||
points.Points--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetActiveMarkings(uid, totalMarkings, markings);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user