Crew manifest as a PDA cartridge program (#18498)
Co-authored-by: Phill101 <holypics4@gmail.com>
This commit is contained in:
29
Content.Client/CartridgeLoader/Cartridges/CrewManifestUi.cs
Normal file
29
Content.Client/CartridgeLoader/Cartridges/CrewManifestUi.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.CartridgeLoader.Cartridges;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
public sealed class CrewManifestUi : UIFragment
|
||||
{
|
||||
private CrewManifestUiFragment? _fragment;
|
||||
|
||||
public override Control GetUIFragmentRoot()
|
||||
{
|
||||
return _fragment!;
|
||||
}
|
||||
|
||||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
|
||||
{
|
||||
_fragment = new CrewManifestUiFragment();
|
||||
}
|
||||
|
||||
public override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is not CrewManifestUiState crewManifestState)
|
||||
return;
|
||||
|
||||
_fragment?.UpdateState(crewManifestState.StationName, crewManifestState.Entries);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<cartridges:CrewManifestUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:ui="clr-namespace:Content.Client.CrewManifest.UI"
|
||||
xmlns="https://spacestation14.io" Margin="1 0 2 0">
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
||||
<controls:StripeBack Name="StationNameContainer">
|
||||
<PanelContainer>
|
||||
<Label Name="StationName" Align="Center" Text="{Loc 'crew-manifest-cartridge-loading'}"/>
|
||||
</PanelContainer>
|
||||
</controls:StripeBack>
|
||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
|
||||
<ui:CrewManifestListing
|
||||
Name="CrewManifestListing"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
Margin="8,0,0,0"/>
|
||||
</ScrollContainer>
|
||||
</BoxContainer>
|
||||
</cartridges:CrewManifestUiFragment>
|
||||
@@ -0,0 +1,34 @@
|
||||
using Content.Shared.CrewManifest;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class CrewManifestUiFragment : BoxContainer
|
||||
{
|
||||
public CrewManifestUiFragment()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
StationName.AddStyleClass("LabelBig");
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
HorizontalExpand = true;
|
||||
VerticalExpand = true;
|
||||
}
|
||||
|
||||
public void UpdateState(string stationName, CrewManifestEntries? entries)
|
||||
{
|
||||
CrewManifestListing.DisposeAllChildren();
|
||||
CrewManifestListing.RemoveAllChildren();
|
||||
|
||||
StationNameContainer.Visible = entries != null;
|
||||
StationName.Text = stationName;
|
||||
|
||||
if (entries == null)
|
||||
return;
|
||||
|
||||
CrewManifestListing.AddCrewManifestEntries(entries);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:ui="clr-namespace:Content.Client.CrewManifest.UI"
|
||||
Title="{Loc 'crew-manifest-window-title'}"
|
||||
SetSize="450 750">
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
|
||||
@@ -11,9 +12,9 @@
|
||||
<BoxContainer HorizontalExpand="True" VerticalExpand="True">
|
||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
|
||||
<!-- this MIGHT have race conditions -->
|
||||
<BoxContainer Name="CrewManifestListing" Orientation="Vertical" HorizontalExpand="True">
|
||||
<ui:CrewManifestListing Name="CrewManifestListing" Orientation="Vertical" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'crew-manifest-no-valid-station'}" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
</ui:CrewManifestListing>
|
||||
<!-- Crew manifest goes here. -->
|
||||
</ScrollContainer>
|
||||
</BoxContainer>
|
||||
|
||||
@@ -1,37 +1,16 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CrewManifest;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.CrewManifest;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class CrewManifestUi : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
|
||||
private readonly CrewManifestSystem _crewManifestSystem;
|
||||
|
||||
public CrewManifestUi()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
_crewManifestSystem = _entitySystemManager.GetEntitySystem<CrewManifestSystem>();
|
||||
|
||||
StationName.AddStyleClass("LabelBig");
|
||||
}
|
||||
@@ -44,131 +23,9 @@ public sealed partial class CrewManifestUi : DefaultWindow
|
||||
StationNameContainer.Visible = entries != null;
|
||||
StationName.Text = name;
|
||||
|
||||
if (entries == null) return;
|
||||
if (entries == null)
|
||||
return;
|
||||
|
||||
var entryList = SortEntries(entries);
|
||||
|
||||
foreach (var item in entryList)
|
||||
{
|
||||
CrewManifestListing.AddChild(new CrewManifestSection(item.section, item.entries, _resourceCache, _crewManifestSystem));
|
||||
}
|
||||
}
|
||||
|
||||
private List<(string section, List<CrewManifestEntry> entries)> SortEntries(CrewManifestEntries entries)
|
||||
{
|
||||
var entryDict = new Dictionary<string, List<CrewManifestEntry>>();
|
||||
|
||||
foreach (var entry in entries.Entries)
|
||||
{
|
||||
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
||||
{
|
||||
// this is a little expensive, and could be better
|
||||
if (department.Roles.Contains(entry.JobPrototype))
|
||||
{
|
||||
entryDict.GetOrNew(department.ID).Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var entryList = new List<(string section, List<CrewManifestEntry> entries)>();
|
||||
|
||||
foreach (var (section, listing) in entryDict)
|
||||
{
|
||||
entryList.Add((section, listing));
|
||||
}
|
||||
|
||||
var sortOrder = _configManager.GetCVar(CCVars.CrewManifestOrdering).Split(",").ToList();
|
||||
|
||||
entryList.Sort((a, b) =>
|
||||
{
|
||||
var ai = sortOrder.IndexOf(a.section);
|
||||
var bi = sortOrder.IndexOf(b.section);
|
||||
|
||||
// this is up here so -1 == -1 occurs first
|
||||
if (ai == bi)
|
||||
return 0;
|
||||
|
||||
if (ai == -1)
|
||||
return -1;
|
||||
|
||||
if (bi == -1)
|
||||
return 1;
|
||||
|
||||
return ai.CompareTo(bi);
|
||||
});
|
||||
|
||||
return entryList;
|
||||
}
|
||||
|
||||
private sealed class CrewManifestSection : BoxContainer
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
||||
private readonly SpriteSystem _spriteSystem = default!;
|
||||
|
||||
public CrewManifestSection(string sectionTitle, List<CrewManifestEntry> entries, IResourceCache cache, CrewManifestSystem crewManifestSystem)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>();
|
||||
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
HorizontalExpand = true;
|
||||
|
||||
if (Loc.TryGetString($"department-{sectionTitle}", out var localizedDepart))
|
||||
sectionTitle = localizedDepart;
|
||||
|
||||
AddChild(new Label()
|
||||
{
|
||||
StyleClasses = { "LabelBig" },
|
||||
Text = Loc.GetString(sectionTitle)
|
||||
});
|
||||
|
||||
var gridContainer = new GridContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
Columns = 2
|
||||
};
|
||||
|
||||
AddChild(gridContainer);
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
var name = new RichTextLabel()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
name.SetMessage(entry.Name);
|
||||
|
||||
var titleContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
HorizontalExpand = true
|
||||
};
|
||||
|
||||
var title = new RichTextLabel();
|
||||
title.SetMessage(entry.JobTitle);
|
||||
|
||||
|
||||
if (_prototypeManager.TryIndex<StatusIconPrototype>(entry.JobIcon, out var jobIcon))
|
||||
{
|
||||
var icon = new TextureRect()
|
||||
{
|
||||
TextureScale = new Vector2(2, 2),
|
||||
Stretch = TextureRect.StretchMode.KeepCentered,
|
||||
Texture = _spriteSystem.Frame0(jobIcon.Icon),
|
||||
};
|
||||
|
||||
titleContainer.AddChild(icon);
|
||||
titleContainer.AddChild(title);
|
||||
}
|
||||
else
|
||||
{
|
||||
titleContainer.AddChild(title);
|
||||
}
|
||||
|
||||
gridContainer.AddChild(name);
|
||||
gridContainer.AddChild(titleContainer);
|
||||
}
|
||||
}
|
||||
CrewManifestListing.AddCrewManifestEntries(entries);
|
||||
}
|
||||
}
|
||||
|
||||
74
Content.Client/CrewManifest/UI/CrewManifestListing.cs
Normal file
74
Content.Client/CrewManifest/UI/CrewManifestListing.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CrewManifest;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Client.CrewManifest.UI;
|
||||
|
||||
public sealed class CrewManifestListing : BoxContainer
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
private readonly SpriteSystem _spriteSystem;
|
||||
|
||||
public CrewManifestListing()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>();
|
||||
}
|
||||
|
||||
public void AddCrewManifestEntries(CrewManifestEntries entries)
|
||||
{
|
||||
var entryDict = new Dictionary<string, List<CrewManifestEntry>>();
|
||||
|
||||
foreach (var entry in entries.Entries)
|
||||
{
|
||||
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
||||
{
|
||||
// this is a little expensive, and could be better
|
||||
if (department.Roles.Contains(entry.JobPrototype))
|
||||
{
|
||||
entryDict.GetOrNew(department.ID).Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var entryList = new List<(string section, List<CrewManifestEntry> entries)>();
|
||||
|
||||
foreach (var (section, listing) in entryDict)
|
||||
{
|
||||
entryList.Add((section, listing));
|
||||
}
|
||||
|
||||
var sortOrder = _configManager.GetCVar(CCVars.CrewManifestOrdering).Split(",").ToList();
|
||||
|
||||
entryList.Sort((a, b) =>
|
||||
{
|
||||
var ai = sortOrder.IndexOf(a.section);
|
||||
var bi = sortOrder.IndexOf(b.section);
|
||||
|
||||
// this is up here so -1 == -1 occurs first
|
||||
if (ai == bi)
|
||||
return 0;
|
||||
|
||||
if (ai == -1)
|
||||
return -1;
|
||||
|
||||
if (bi == -1)
|
||||
return 1;
|
||||
|
||||
return ai.CompareTo(bi);
|
||||
});
|
||||
|
||||
foreach (var item in entryList)
|
||||
{
|
||||
AddChild(new CrewManifestSection(_prototypeManager, _spriteSystem, item.section, item.entries));
|
||||
}
|
||||
}
|
||||
}
|
||||
74
Content.Client/CrewManifest/UI/CrewManifestSection.cs
Normal file
74
Content.Client/CrewManifest/UI/CrewManifestSection.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Content.Shared.CrewManifest;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Client.CrewManifest.UI;
|
||||
|
||||
public sealed class CrewManifestSection : BoxContainer
|
||||
{
|
||||
public CrewManifestSection(IPrototypeManager prototypeManager, SpriteSystem spriteSystem, string sectionTitle,
|
||||
List<CrewManifestEntry> entries)
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
HorizontalExpand = true;
|
||||
|
||||
if (Loc.TryGetString($"department-{sectionTitle}", out var localizedDepart))
|
||||
sectionTitle = localizedDepart;
|
||||
|
||||
AddChild(new Label()
|
||||
{
|
||||
StyleClasses = { "LabelBig" },
|
||||
Text = Loc.GetString(sectionTitle)
|
||||
});
|
||||
|
||||
var gridContainer = new GridContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
Columns = 2
|
||||
};
|
||||
|
||||
AddChild(gridContainer);
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
var name = new RichTextLabel()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
name.SetMessage(entry.Name);
|
||||
|
||||
var titleContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
HorizontalExpand = true
|
||||
};
|
||||
|
||||
var title = new RichTextLabel();
|
||||
title.SetMessage(entry.JobTitle);
|
||||
|
||||
|
||||
if (prototypeManager.TryIndex<StatusIconPrototype>(entry.JobIcon, out var jobIcon))
|
||||
{
|
||||
var icon = new TextureRect()
|
||||
{
|
||||
TextureScale = new Vector2(2, 2),
|
||||
Stretch = TextureRect.StretchMode.KeepCentered,
|
||||
Texture = spriteSystem.Frame0(jobIcon.Icon),
|
||||
};
|
||||
|
||||
titleContainer.AddChild(icon);
|
||||
titleContainer.AddChild(title);
|
||||
}
|
||||
else
|
||||
{
|
||||
titleContainer.AddChild(title);
|
||||
}
|
||||
|
||||
gridContainer.AddChild(name);
|
||||
gridContainer.AddChild(titleContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
using Content.Client.CartridgeLoader;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.CrewManifest;
|
||||
using Content.Shared.PDA;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -13,8 +11,6 @@ namespace Content.Client.PDA
|
||||
[UsedImplicitly]
|
||||
public sealed class PdaBoundUserInterface : CartridgeLoaderBoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private PdaMenu? _menu;
|
||||
|
||||
@@ -34,15 +30,6 @@ namespace Content.Client.PDA
|
||||
SendMessage(new PdaToggleFlashlightMessage());
|
||||
};
|
||||
|
||||
if (_configManager.GetCVar(CCVars.CrewManifestUnsecure))
|
||||
{
|
||||
_menu.CrewManifestButton.Visible = true;
|
||||
_menu.CrewManifestButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new CrewManifestOpenUiMessage());
|
||||
};
|
||||
}
|
||||
|
||||
_menu.EjectIdButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaIdSlotId));
|
||||
|
||||
@@ -60,11 +60,6 @@
|
||||
Access="Public"
|
||||
Text="{Loc 'comp-pda-ui-ringtone-button'}"
|
||||
Description="{Loc 'comp-pda-ui-ringtone-button-description'}"/>
|
||||
<pda:PdaSettingsButton Name="CrewManifestButton"
|
||||
Access="Public"
|
||||
Text="{Loc 'crew-manifest-button-label'}"
|
||||
Description="{Loc 'crew-manifest-button-description'}"
|
||||
Visible="False" />
|
||||
<pda:PdaSettingsButton Name="ActivateMusicButton"
|
||||
Access="Public"
|
||||
Text="{Loc 'pda-bound-user-interface-music-button'}"
|
||||
|
||||
Reference in New Issue
Block a user