Skip to content

Commit

Permalink
Adds CD records, height slider
Browse files Browse the repository at this point in the history
  • Loading branch information
revsys413 committed Apr 4, 2024
1 parent 4fe623a commit 9948d1d
Show file tree
Hide file tree
Showing 64 changed files with 9,164 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:at="clr-namespace:Content.Client.Administration.UI.Tabs.AdminTab"
xmlns:cdAdmin="clr-namespace:Content.Client._CD.Admin.UI"
Margin="4"
MinSize="50 50">
<BoxContainer Orientation="Vertical">
Expand All @@ -16,6 +17,8 @@
<cc:UICommandButton Command="callshuttle" Text="{Loc admin-player-actions-window-shuttle}" WindowType="{x:Type at:AdminShuttleWindow}"/>
<cc:CommandButton Command="adminlogs" Text="{Loc admin-player-actions-window-admin-logs}"/>
<cc:CommandButton Command="faxui" Text="{Loc admin-player-actions-window-admin-fax}"/>
<!-- CD: records purge button -->
<cc:UICommandButton Command="purgecharacterrecords" Text="{Loc admin-player-actions-window-cd-record-purge}" WindowType="{x:Type cdAdmin:ModifyCharacterRecords}"/>
</GridContainer>
</BoxContainer>
</Control>
10 changes: 10 additions & 0 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Numerics;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Robust.Client.GameObjects;
using Robust.Client.Console;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

Expand All @@ -12,6 +14,8 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly MarkingManager _markingManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;

public override void Initialize()
{
Expand All @@ -30,6 +34,11 @@ private void UpdateSprite(HumanoidAppearanceComponent component, SpriteComponent
UpdateLayers(component, sprite);
ApplyMarkingSet(component, sprite);

var speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(component.Species);
var height = Math.Clamp(MathF.Round(component.Height, 1), speciesPrototype.MinHeight, speciesPrototype.MaxHeight); // should NOT be locked, at all

sprite.Scale = new Vector2(speciesPrototype.ScaleHeight ? height : 1f, height);

sprite[sprite.LayerMapReserveBlank(HumanoidVisualLayers.Eyes)].Color = component.EyeColor;
}

Expand Down Expand Up @@ -194,6 +203,7 @@ public override void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile
humanoid.Species = profile.Species;
humanoid.SkinColor = profile.Appearance.SkinColor;
humanoid.EyeColor = profile.Appearance.EyeColor;
humanoid.Height = profile.Height;

UpdateSprite(humanoid, Comp<SpriteComponent>(uid));
}
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
<Control HorizontalExpand="True"/>
<LineEdit Name="CAgeEdit" MinSize="40 0" HorizontalAlignment="Right" />
</BoxContainer>
<!-- CD Height -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-height-label'}" />
<Control HorizontalExpand="True" />
<Slider Name="CDHeightSlider" HorizontalAlignment="Right" SetWidth="300" MinValue="0.0" MaxValue="1.0"/>
<LineEdit HorizontalAlignment="Right" Name="CHeight" MinSize="60 0" Text="1.0" />
<Button Name="CHeightReset" Text="{Loc 'humanoid-profile-editor-reset-height-button'}" HorizontalAlignment="Right"/>
</BoxContainer>
<!-- Sex -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-sex-label'}" />
Expand Down
91 changes: 91 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Linq;
using System.Numerics;
using Content.Client.Guidebook;
Expand Down Expand Up @@ -36,6 +37,10 @@
using static Robust.Client.UserInterface.Controls.BoxContainer;
using Direction = Robust.Shared.Maths.Direction;

// CD: Records editor imports
using Content.Client._CD.Records.UI;
using Content.Shared._CD.Records;

namespace Content.Client.Preferences.UI
{
public sealed class HighlightedContainer : PanelContainer
Expand Down Expand Up @@ -78,6 +83,7 @@ public sealed partial class HumanoidProfileEditor : Control
private SingleMarkingPicker _hairPicker => CHairStylePicker;
private SingleMarkingPicker _facialHairPicker => CFacialHairPicker;
private EyeColorPicker _eyesPicker => CEyeColorPicker;
private LineEdit _heightPicker => CHeight;

private TabContainer _tabContainer => CTabContainer;
private BoxContainer _jobList => CJobList;
Expand Down Expand Up @@ -108,6 +114,11 @@ public sealed partial class HumanoidProfileEditor : Control

public event Action<HumanoidCharacterProfile, int>? OnProfileChanged;

private float _defaultHeight = 1f;

// CD: Record editor
private readonly RecordEditorGui _recordsTab;

public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager,
IEntityManager entityManager, IConfigurationManager configurationManager)
{
Expand Down Expand Up @@ -196,6 +207,41 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt

#endregion Species

#region CDHeight

_heightPicker.OnTextChanged += args =>
{
if (Profile is null || !float.TryParse(args.Text, out var newHeight))
return;
var prototype = _prototypeManager.Index<SpeciesPrototype>(Profile.Species);
newHeight = MathF.Round(Math.Clamp(newHeight, prototype.MinHeight, prototype.MaxHeight), 2);
// The percentage between the start and end numbers, aka "inverse lerp"
var sliderPercent = (newHeight - prototype.MinHeight) /
(prototype.MaxHeight - prototype.MinHeight);
CDHeightSlider.Value = sliderPercent;
SetProfileHeight(newHeight);
};

CHeightReset.OnPressed += _ =>
{
_heightPicker.SetText(_defaultHeight.ToString(CultureInfo.InvariantCulture), true);
};

CDHeightSlider.OnValueChanged += _ =>
{
if (Profile is null)
return;
var prototype = _prototypeManager.Index<SpeciesPrototype>(Profile.Species);
var newHeight = MathF.Round(MathHelper.Lerp(prototype.MinHeight, prototype.MaxHeight, CDHeightSlider.Value), 2);
_heightPicker.Text = newHeight.ToString(CultureInfo.InvariantCulture);
SetProfileHeight(newHeight);
};

#endregion CDHeight

#region Skin


Expand Down Expand Up @@ -481,6 +527,14 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt

#endregion Markings

#region CosmaticRecords

_recordsTab = new RecordEditorGui(UpdateProfileRecords);
_tabContainer.AddChild(_recordsTab);
_tabContainer.SetTabTitle(_tabContainer.ChildCount - 1, Loc.GetString("humanoid-profile-editor-cd-records-tab"));

#endregion CosmaticRecords

#region FlavorText

if (_configurationManager.GetCVar(CCVars.FlavorText))
Expand Down Expand Up @@ -658,6 +712,15 @@ private void UpdateRoleRequirements()
}
}

// CD: Records editor
private void UpdateProfileRecords(CharacterRecords records)
{
if (Profile is null)
return;
Profile = Profile.WithCDCharacterRecords(records);
IsDirty = true;
}

/// <summary>
/// DeltaV - Make sure that no invalid job priorities get through.
/// </summary>
Expand Down Expand Up @@ -869,6 +932,12 @@ private void SetBackpack(BackpackPreference newBackpack)
IsDirty = true;
}

private void SetProfileHeight(float height)
{
Profile = Profile?.WithHeight(height);
IsDirty = true;
}

private void SetSpawnPriority(SpawnPriorityPreference newSpawnPriority)
{
Profile = Profile?.WithSpawnPriorityPreference(newSpawnPriority);
Expand Down Expand Up @@ -1069,6 +1138,24 @@ private void UpdateBackpackControls()
_backpackButton.SelectId((int) Profile.Backpack);
}

private void UpdateHeightControls()
{
if (Profile == null)
{
return;
}

var species = _speciesList.Find(x => x.ID == Profile.Species);
if (species != null)
_defaultHeight = species.DefaultHeight;

var prototype = _prototypeManager.Index<SpeciesPrototype>(Profile.Species);
var sliderPercent = (Profile.Height - prototype.MinHeight) /
(prototype.MaxHeight - prototype.MinHeight);
CDHeightSlider.Value = sliderPercent;
_heightPicker.Text = Profile.Height.ToString(CultureInfo.InvariantCulture);
}

private void UpdateSpawnPriorityControls()
{
if (Profile == null)
Expand Down Expand Up @@ -1230,6 +1317,10 @@ public void UpdateControls()
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
UpdateHeightControls();

// CD: Update record editor
_recordsTab.Update(Profile);

_preferenceUnavailableButton.SelectId((int) Profile.PreferenceUnavailable);
}
Expand Down
14 changes: 14 additions & 0 deletions Content.Client/_CD/Admin/UI/ModifyCharacterRecords.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc cd-actions-admin-modify-records}"
MinSize="300 300">
<BoxContainer Orientation="Vertical">
<LineEdit Name="EntityEdit" PlaceHolder="Entity" HorizontalExpand="True" />
<OptionButton Name="EntityEntryType" HorizontalExpand="True" />
<LineEdit Name="EntityEntryIndex" PlaceHolder="Index"/>
<BoxContainer Orientation="Horizontal" >
<cc:CommandButton Name="PurgeCommand" Text="{Loc cd-actions-admin-modify-reset}"/>
<cc:CommandButton Name="DelCommand" Text="{Loc cd-actions-admin-modify-del-entry}"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
48 changes: 48 additions & 0 deletions Content.Client/_CD/Admin/UI/ModifyCharacterRecords.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Content.Shared._CD.Records;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.Admin.UI;

[GenerateTypedNameReferences]
public sealed partial class ModifyCharacterRecords : DefaultWindow
{
public ModifyCharacterRecords()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

foreach (var v in Enum.GetValues<CharacterRecordType>())
{
EntityEntryType.AddItem(v.ToString());
}

EntityEntryType.OnItemSelected += args =>
{
EntityEntryType.SelectId(args.Id);
UpdateCommands();
};

EntityEdit.OnTextChanged += _ => UpdateCommands();
EntityEntryIndex.OnTextChanged += _ => UpdateCommands();
}

private void UpdateCommands()
{
if (!int.TryParse(EntityEdit.Text, out var uid))
{
return;
}

if (!int.TryParse(EntityEntryIndex.Text, out var idx))
{
return;
}

var ty = (CharacterRecordType)EntityEntryType.SelectedId;

PurgeCommand.Command = $"purgecharacterrecords {uid}";
DelCommand.Command = $"delrecordentry {uid} {ty.ToString()} {idx}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Content.Shared._CD.Records;
using Content.Shared.CriminalRecords;
using Content.Shared.CriminalRecords.Components;
using Content.Shared.Security;
using Content.Shared.StationRecords;
using JetBrains.Annotations;

namespace Content.Client._CD.Records.UI;

[UsedImplicitly]
public sealed class CharacterRecordConsoleBoundUserInterface : BoundUserInterface
{
[ViewVariables] private CharacterRecordViewer? _window;

public CharacterRecordConsoleBoundUserInterface(EntityUid owner, Enum key)
: base(owner, key)
{
}

protected override void UpdateState(BoundUserInterfaceState baseState)
{
base.UpdateState(baseState);
if (baseState is not CharacterRecordConsoleState state)
return;

if (_window?.IsSecurity() ?? false)
{
var comp = EntMan.GetComponent<CriminalRecordsConsoleComponent>(Owner);
_window!.SecurityWantedStatusMaxLength = comp.MaxStringLength;
}

_window?.UpdateState(state);
}

protected override void Open()
{
base.Open();

_window = new();
_window.OnClose += Close;
_window.OnListingItemSelected += (ent, stationRecordKey) =>
{
SendMessage(new CharacterRecordConsoleSelectMsg(ent));
// If we are a security records console, we also need to inform the criminal records
// system of our state.
if (_window.IsSecurity() && stationRecordKey != null)
{
SendMessage(new SelectStationRecord(stationRecordKey));
_window.SetSecurityStatusEnabled(true);
}
else
{
// If the user does not have criminal records for some reason, we should not be able
// to set their wanted status
_window.SetSecurityStatusEnabled(false);
}
};

_window.OnFiltersChanged += (ty, txt) =>
{
if (txt == null)
SendMessage(new CharacterRecordsConsoleFilterMsg(null));
else
SendMessage(new CharacterRecordsConsoleFilterMsg(new StationRecordsFilter(ty, txt)));
};

_window.OnSetSecurityStatus += (status, reason) =>
{
SendMessage(new CriminalRecordChangeStatus(status, reason));
};

_window.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

_window?.Close();
}
}
Loading

0 comments on commit 9948d1d

Please sign in to comment.