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"
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||||
|
xmlns:ui="clr-namespace:Content.Client.CrewManifest.UI"
|
||||||
Title="{Loc 'crew-manifest-window-title'}"
|
Title="{Loc 'crew-manifest-window-title'}"
|
||||||
SetSize="450 750">
|
SetSize="450 750">
|
||||||
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
|
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
|
||||||
@@ -11,9 +12,9 @@
|
|||||||
<BoxContainer HorizontalExpand="True" VerticalExpand="True">
|
<BoxContainer HorizontalExpand="True" VerticalExpand="True">
|
||||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
|
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
|
||||||
<!-- this MIGHT have race conditions -->
|
<!-- 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" />
|
<Label Text="{Loc 'crew-manifest-no-valid-station'}" HorizontalExpand="True" />
|
||||||
</BoxContainer>
|
</ui:CrewManifestListing>
|
||||||
<!-- Crew manifest goes here. -->
|
<!-- Crew manifest goes here. -->
|
||||||
</ScrollContainer>
|
</ScrollContainer>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
|||||||
@@ -1,37 +1,16 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Numerics;
|
|
||||||
using Content.Shared.CCVar;
|
|
||||||
using Content.Shared.CrewManifest;
|
using Content.Shared.CrewManifest;
|
||||||
using Content.Shared.Roles;
|
|
||||||
using Content.Shared.StatusIcon;
|
|
||||||
using Robust.Client.AutoGenerated;
|
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.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
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;
|
namespace Content.Client.CrewManifest;
|
||||||
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class CrewManifestUi : DefaultWindow
|
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()
|
public CrewManifestUi()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
|
||||||
_crewManifestSystem = _entitySystemManager.GetEntitySystem<CrewManifestSystem>();
|
|
||||||
|
|
||||||
StationName.AddStyleClass("LabelBig");
|
StationName.AddStyleClass("LabelBig");
|
||||||
}
|
}
|
||||||
@@ -44,131 +23,9 @@ public sealed partial class CrewManifestUi : DefaultWindow
|
|||||||
StationNameContainer.Visible = entries != null;
|
StationNameContainer.Visible = entries != null;
|
||||||
StationName.Text = name;
|
StationName.Text = name;
|
||||||
|
|
||||||
if (entries == null) return;
|
if (entries == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var entryList = SortEntries(entries);
|
CrewManifestListing.AddCrewManifestEntries(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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.Client.CartridgeLoader;
|
||||||
using Content.Shared.CartridgeLoader;
|
using Content.Shared.CartridgeLoader;
|
||||||
using Content.Shared.CCVar;
|
|
||||||
using Content.Shared.Containers.ItemSlots;
|
using Content.Shared.Containers.ItemSlots;
|
||||||
using Content.Shared.CrewManifest;
|
|
||||||
using Content.Shared.PDA;
|
using Content.Shared.PDA;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
@@ -13,8 +11,6 @@ namespace Content.Client.PDA
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class PdaBoundUserInterface : CartridgeLoaderBoundUserInterface
|
public sealed class PdaBoundUserInterface : CartridgeLoaderBoundUserInterface
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private PdaMenu? _menu;
|
private PdaMenu? _menu;
|
||||||
|
|
||||||
@@ -34,15 +30,6 @@ namespace Content.Client.PDA
|
|||||||
SendMessage(new PdaToggleFlashlightMessage());
|
SendMessage(new PdaToggleFlashlightMessage());
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_configManager.GetCVar(CCVars.CrewManifestUnsecure))
|
|
||||||
{
|
|
||||||
_menu.CrewManifestButton.Visible = true;
|
|
||||||
_menu.CrewManifestButton.OnPressed += _ =>
|
|
||||||
{
|
|
||||||
SendMessage(new CrewManifestOpenUiMessage());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_menu.EjectIdButton.OnPressed += _ =>
|
_menu.EjectIdButton.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
SendMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaIdSlotId));
|
SendMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaIdSlotId));
|
||||||
|
|||||||
@@ -60,11 +60,6 @@
|
|||||||
Access="Public"
|
Access="Public"
|
||||||
Text="{Loc 'comp-pda-ui-ringtone-button'}"
|
Text="{Loc 'comp-pda-ui-ringtone-button'}"
|
||||||
Description="{Loc 'comp-pda-ui-ringtone-button-description'}"/>
|
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"
|
<pda:PdaSettingsButton Name="ActivateMusicButton"
|
||||||
Access="Public"
|
Access="Public"
|
||||||
Text="{Loc 'pda-bound-user-interface-music-button'}"
|
Text="{Loc 'pda-bound-user-interface-music-button'}"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace Content.Server.CartridgeLoader;
|
namespace Content.Server.CartridgeLoader;
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
|
|||||||
return new List<EntityUid>();
|
return new List<EntityUid>();
|
||||||
|
|
||||||
//Don't count a cartridge that has already been installed as available to avoid confusion
|
//Don't count a cartridge that has already been installed as available to avoid confusion
|
||||||
if (loader.CartridgeSlot.HasItem && IsInstalled(Prototype(loader.CartridgeSlot.Item!.Value)?.ID, loader))
|
if (loader.CartridgeSlot.HasItem && TryFindInstalled(Prototype(loader.CartridgeSlot.Item!.Value)?.ID, loader, out _))
|
||||||
return loader.InstalledPrograms;
|
return loader.InstalledPrograms;
|
||||||
|
|
||||||
var available = new List<EntityUid>();
|
var available = new List<EntityUid>();
|
||||||
@@ -127,7 +128,13 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
//Prevent installing cartridges that have already been installed
|
//Prevent installing cartridges that have already been installed
|
||||||
if (IsInstalled(prototype, loader))
|
if (TryFindInstalled(prototype, loader, out _))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var ev = new ProgramInstallationAttempt(loaderUid, prototype);
|
||||||
|
RaiseLocalEvent(ref ev);
|
||||||
|
|
||||||
|
if (ev.Cancelled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var installedProgram = Spawn(prototype, new EntityCoordinates(loaderUid, 0, 0));
|
var installedProgram = Spawn(prototype, new EntityCoordinates(loaderUid, 0, 0));
|
||||||
@@ -141,6 +148,22 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uninstalls a program using its prototype
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loaderUid">The cartridge loader uid</param>
|
||||||
|
/// <param name="prototype">The prototype name of the program to be uninstalled</param>
|
||||||
|
/// <param name="loader">The cartridge loader component</param>
|
||||||
|
/// <returns>Whether uninstalling the program was successful</returns>
|
||||||
|
public bool UninstallProgram(EntityUid loaderUid, string prototype, CartridgeLoaderComponent? loader = default!)
|
||||||
|
{
|
||||||
|
if (!Resolve(loaderUid, ref loader))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return TryFindInstalled(prototype, loader, out var programUid) &&
|
||||||
|
UninstallProgram(loaderUid, programUid.Value, loader);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uninstalls a program using its uid
|
/// Uninstalls a program using its uid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -345,16 +368,20 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if a program is already installed by searching for its prototype name in the list of installed programs
|
/// Searches for a program by its prototype name in the list of installed programs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool IsInstalled(string? prototype, CartridgeLoaderComponent loader)
|
private bool TryFindInstalled(string? prototype, CartridgeLoaderComponent loader, [NotNullWhen(true)] out EntityUid? programUid)
|
||||||
{
|
{
|
||||||
foreach (var program in loader.InstalledPrograms)
|
foreach (var program in loader.InstalledPrograms)
|
||||||
{
|
{
|
||||||
if (Prototype(program)?.ID == prototype)
|
if (Prototype(program)?.ID == prototype)
|
||||||
|
{
|
||||||
|
programUid = program;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
programUid = default;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,3 +441,9 @@ public sealed class CartridgeAfterInteractEvent : EntityEventArgs
|
|||||||
InteractEvent = interactEvent;
|
InteractEvent = interactEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on an attempt of program installation.
|
||||||
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct ProgramInstallationAttempt(EntityUid LoaderUid, string Prototype, bool Cancelled = false);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Server.CartridgeLoader.Cartridges;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class CrewManifestCartridgeComponent : Component
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using Content.Server.CrewManifest;
|
||||||
|
using Content.Server.Station.Systems;
|
||||||
|
using Content.Shared.CartridgeLoader;
|
||||||
|
using Content.Shared.CartridgeLoader.Cartridges;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
|
|
||||||
|
namespace Content.Server.CartridgeLoader.Cartridges;
|
||||||
|
|
||||||
|
public sealed class CrewManifestCartridgeSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly CartridgeLoaderSystem _cartridgeLoader = default!;
|
||||||
|
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||||
|
[Dependency] private readonly CrewManifestSystem _crewManifest = default!;
|
||||||
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||||
|
|
||||||
|
private const string CartridgePrototypeName = "CrewManifestCartridge";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flag that shows that if crew manifest is allowed to be viewed from 'unsecure' entities,
|
||||||
|
/// which is the keys for the cartridge.
|
||||||
|
/// </summary>
|
||||||
|
private bool _unsecureViewersAllowed = true;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<CrewManifestCartridgeComponent, CartridgeMessageEvent>(OnUiMessage);
|
||||||
|
SubscribeLocalEvent<CrewManifestCartridgeComponent, CartridgeUiReadyEvent>(OnUiReady);
|
||||||
|
SubscribeLocalEvent<ProgramInstallationAttempt>(OnInstallationAttempt);
|
||||||
|
_configManager.OnValueChanged(CCVars.CrewManifestUnsecure, OnCrewManifestUnsecureChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ui messages received here get wrapped by a CartridgeMessageEvent and are relayed from the <see cref="CartridgeLoaderSystem"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The cartridge specific ui message event needs to inherit from the CartridgeMessageEvent
|
||||||
|
/// </remarks>
|
||||||
|
private void OnUiMessage(EntityUid uid, CrewManifestCartridgeComponent component, CartridgeMessageEvent args)
|
||||||
|
{
|
||||||
|
UpdateUiState(uid, args.LoaderUid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This gets called when the ui fragment needs to be updated for the first time after activating
|
||||||
|
/// </summary>
|
||||||
|
private void OnUiReady(EntityUid uid, CrewManifestCartridgeComponent component, CartridgeUiReadyEvent args)
|
||||||
|
{
|
||||||
|
UpdateUiState(uid, args.Loader, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateUiState(EntityUid uid, EntityUid loaderUid, CrewManifestCartridgeComponent? component)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var owningStation = _stationSystem.GetOwningStation(uid);
|
||||||
|
|
||||||
|
if (owningStation is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var (stationName, entries) = _crewManifest.GetCrewManifest(owningStation.Value);
|
||||||
|
|
||||||
|
var state = new CrewManifestUiState(stationName, entries);
|
||||||
|
_cartridgeLoader.UpdateCartridgeUiState(loaderUid, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInstallationAttempt(ref ProgramInstallationAttempt args)
|
||||||
|
{
|
||||||
|
if (args.Prototype == CartridgePrototypeName && !_unsecureViewersAllowed)
|
||||||
|
args.Cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCrewManifestUnsecureChanged(bool unsecureViewersAllowed)
|
||||||
|
{
|
||||||
|
_unsecureViewersAllowed = unsecureViewersAllowed;
|
||||||
|
|
||||||
|
var allCartridgeLoaders = AllEntityQuery<CartridgeLoaderComponent>();
|
||||||
|
|
||||||
|
while (allCartridgeLoaders.MoveNext(out EntityUid loaderUid, out CartridgeLoaderComponent? comp))
|
||||||
|
{
|
||||||
|
if (_unsecureViewersAllowed)
|
||||||
|
_cartridgeLoader?.InstallProgram(loaderUid, CartridgePrototypeName, false, comp);
|
||||||
|
else
|
||||||
|
_cartridgeLoader?.UninstallProgram(loaderUid, CartridgePrototypeName, comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
_configManager.UnsubValueChanged(CCVars.CrewManifestUnsecure, OnCrewManifestUnsecureChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Content.Shared.CrewManifest;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.CartridgeLoader.Cartridges;
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class CrewManifestUiState : BoundUserInterfaceState
|
||||||
|
{
|
||||||
|
public string StationName;
|
||||||
|
public CrewManifestEntries? Entries;
|
||||||
|
|
||||||
|
public CrewManifestUiState(string stationName, CrewManifestEntries? entries)
|
||||||
|
{
|
||||||
|
StationName = stationName;
|
||||||
|
Entries = entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
notekeeper-program-name = Notekeeper
|
notekeeper-program-name = Notekeeper
|
||||||
news-read-program-name = Station news
|
news-read-program-name = Station news
|
||||||
|
|
||||||
|
crew-manifest-program-name = Crew manifest
|
||||||
|
crew-manifest-cartridge-loading = Loading ...
|
||||||
|
|
||||||
net-probe-program-name = NetProbe
|
net-probe-program-name = NetProbe
|
||||||
net-probe-scan = Scanned {$device}!
|
net-probe-scan = Scanned {$device}!
|
||||||
net-probe-label-name = Name
|
net-probe-label-name = Name
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
sprite: Objects/Devices/cartridge.rsi
|
||||||
state: cart-y
|
state: cart-y
|
||||||
- type: Icon
|
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
|
||||||
state: cart-y
|
|
||||||
- type: UIFragment
|
- type: UIFragment
|
||||||
ui: !type:NotekeeperUi
|
ui: !type:NotekeeperUi
|
||||||
- type: Cartridge
|
- type: Cartridge
|
||||||
@@ -28,9 +25,6 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
sprite: Objects/Devices/cartridge.rsi
|
||||||
state: cart-y
|
state: cart-y
|
||||||
- type: Icon
|
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
|
||||||
state: cart-y
|
|
||||||
- type: UIFragment
|
- type: UIFragment
|
||||||
ui: !type:NewsReadUi
|
ui: !type:NewsReadUi
|
||||||
- type: Cartridge
|
- type: Cartridge
|
||||||
@@ -40,6 +34,24 @@
|
|||||||
state: news_read
|
state: news_read
|
||||||
- type: NewsReadCartridge
|
- type: NewsReadCartridge
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
parent: BaseItem
|
||||||
|
id: CrewManifestCartridge
|
||||||
|
name: Crew Manifest Cartridge
|
||||||
|
description: A program for listing your fellow crewmembers
|
||||||
|
components:
|
||||||
|
- type: Sprite
|
||||||
|
sprite: Objects/Devices/cartridge.rsi
|
||||||
|
state: cart-y
|
||||||
|
- type: UIFragment
|
||||||
|
ui: !type:CrewManifestUi
|
||||||
|
- type: Cartridge
|
||||||
|
programName: crew-manifest-program-name
|
||||||
|
icon:
|
||||||
|
sprite: Interface/Misc/program_icons.rsi
|
||||||
|
state: crew_manifest
|
||||||
|
- type: CrewManifestCartridge
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
id: NetProbeCartridge
|
id: NetProbeCartridge
|
||||||
@@ -49,9 +61,6 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
sprite: Objects/Devices/cartridge.rsi
|
||||||
state: cart-y
|
state: cart-y
|
||||||
- type: Icon
|
|
||||||
sprite: Objects/Devices/cartridge.rsi
|
|
||||||
state: cart-y
|
|
||||||
- type: UIFragment
|
- type: UIFragment
|
||||||
ui: !type:NetProbeUi
|
ui: !type:NetProbeUi
|
||||||
- type: Cartridge
|
- type: Cartridge
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
- type: CartridgeLoader
|
- type: CartridgeLoader
|
||||||
uiKey: enum.PdaUiKey.Key
|
uiKey: enum.PdaUiKey.Key
|
||||||
preinstalled:
|
preinstalled:
|
||||||
|
- CrewManifestCartridge
|
||||||
- NotekeeperCartridge
|
- NotekeeperCartridge
|
||||||
- NewsReadCartridge
|
- NewsReadCartridge
|
||||||
cartridgeSlot:
|
cartridgeSlot:
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"license": "CC-BY-SA-3.0",
|
"license": "CC-BY-SA-3.0",
|
||||||
"copyright": "Made with love, by Misha_Unity",
|
"copyright": "news_read by Misha_Unity, crew_manifest by Phill101",
|
||||||
"size": {
|
"size": {
|
||||||
"x": 32,
|
"x": 32,
|
||||||
"y": 32
|
"y": 32
|
||||||
@@ -9,6 +9,9 @@
|
|||||||
"states": [
|
"states": [
|
||||||
{
|
{
|
||||||
"name": "news_read"
|
"name": "news_read"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "crew_manifest"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user