forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CrimeAssist * linefix * linefix * linefix * linefix * linefix
- Loading branch information
Showing
23 changed files
with
1,570 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
Content.Client/_CorvaxNext/CartridgeLoader/Cartridges/CrimeAssistUi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Robust.Client.UserInterface; | ||
using Content.Client.UserInterface.Fragments; | ||
using Content.Shared._CorvaxNext.CartridgeLoader.Cartridges; | ||
using Content.Shared.CartridgeLoader; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client._CorvaxNext.CartridgeLoader.Cartridges; | ||
|
||
public sealed partial class CrimeAssistUi : UIFragment | ||
{ | ||
private CrimeAssistUiFragment? _fragment; | ||
|
||
public override Control GetUIFragmentRoot() | ||
{ | ||
return _fragment!; | ||
} | ||
|
||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner) | ||
{ | ||
_fragment = new CrimeAssistUiFragment(); | ||
|
||
_fragment.OnSync += _ => SendSyncMessage(userInterface); | ||
} | ||
|
||
private void SendSyncMessage(BoundUserInterface userInterface) | ||
{ | ||
var syncMessage = new CrimeAssistSyncMessageEvent(); | ||
var message = new CartridgeUiMessage(syncMessage); | ||
userInterface.SendMessage(message); | ||
} | ||
|
||
public override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Content.Client/_CorvaxNext/CartridgeLoader/Cartridges/CrimeAssistUiFragment.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<cartridges:CrimeAssistUiFragment xmlns:cartridges="clr-namespace:Content.Client._CorvaxNext.CartridgeLoader.Cartridges" | ||
xmlns="https://spacestation14.io" | ||
Margin="1 0 2 0"> | ||
|
||
<!-- Main background container --> | ||
<PanelContainer StyleClasses="BackgroundDark"> | ||
<BoxContainer Orientation="Vertical" | ||
HorizontalExpand="True" | ||
VerticalExpand="True" | ||
Margin="5" | ||
SeparationOverride="2"> | ||
|
||
<!-- Explanation Box: Contains title, subtitle, explanations, and punishment details --> | ||
<BoxContainer Name="ExplanationBox" | ||
Orientation="Vertical" | ||
MaxWidth="400" | ||
VerticalExpand="True" | ||
SeparationOverride="2"> | ||
<RichTextLabel Name="Title" /> | ||
<RichTextLabel Name="Subtitle" /> | ||
<RichTextLabel Name="Explanation" /> | ||
<RichTextLabel Name="Punishment" Margin="0,20" /> | ||
</BoxContainer> | ||
|
||
<!-- Question Box: Contains navigation/option buttons --> | ||
<BoxContainer Name="QuestionBox" | ||
Orientation="Horizontal" | ||
HorizontalAlignment="Center" | ||
HorizontalExpand="True" | ||
VerticalExpand="False" | ||
SeparationOverride="2"> | ||
<Button Name="StartButton" Access="Public" /> | ||
<Button Name="HomeButton" Access="Public" Visible="False" /> | ||
<Button Name="YesButton" Access="Public" Visible="False" /> | ||
<Button Name="NoButton" Access="Public" Visible="False" /> | ||
</BoxContainer> | ||
|
||
</BoxContainer> | ||
</PanelContainer> | ||
</cartridges:CrimeAssistUiFragment> |
156 changes: 156 additions & 0 deletions
156
Content.Client/_CorvaxNext/CartridgeLoader/Cartridges/CrimeAssistUiFragment.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
using Content.Client.Message; | ||
using Content.Shared._CorvaxNext.CartridgeLoader.Cartridges; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.ResourceManagement; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Prototypes; | ||
using static Content.Client._CorvaxNext.CartridgeLoader.Cartridges.CrimeAssistUi; | ||
|
||
namespace Content.Client._CorvaxNext.CartridgeLoader.Cartridges | ||
{ | ||
[GenerateTypedNameReferences] | ||
public sealed partial class CrimeAssistUiFragment : BoxContainer | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IResourceCache _resourceCache = default!; | ||
|
||
public event Action<bool>? OnSync; | ||
|
||
private List<CrimeAssistPage>? _pages; | ||
private CrimeAssistPage _currentPage; | ||
private CrimeAssistPage _mainMenuPage; | ||
|
||
public CrimeAssistUiFragment() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
Orientation = LayoutOrientation.Vertical; | ||
HorizontalExpand = true; | ||
VerticalExpand = true; | ||
|
||
StartButton.Text = Loc.GetString("crime-assist-start-button"); | ||
StartButton.ToolTip = Loc.GetString("crime-assist-start-button-tooltip"); | ||
|
||
HomeButton.Text = Loc.GetString("crime-assist-home-button"); | ||
HomeButton.ToolTip = Loc.GetString("crime-assist-home-button-tooltip"); | ||
|
||
YesButton.Text = Loc.GetString("crime-assist-yes-button"); | ||
YesButton.ToolTip = Loc.GetString("crime-assist-yes-button-tooltip"); | ||
|
||
NoButton.Text = Loc.GetString("crime-assist-no-button"); | ||
NoButton.ToolTip = Loc.GetString("crime-assist-no-button-tooltip"); | ||
|
||
// Load all pages | ||
_pages = new List<CrimeAssistPage>(_prototypeManager.EnumeratePrototypes<CrimeAssistPage>()); | ||
|
||
// Initialize the main menu page | ||
_mainMenuPage = FindPageById("mainmenu"); | ||
_currentPage = _mainMenuPage; | ||
|
||
UpdateUI(_currentPage); | ||
|
||
// Set up button actions | ||
StartButton.OnPressed += _ => | ||
{ | ||
var startTarget = _mainMenuPage.OnStart; | ||
if (startTarget != null) UpdateUI(FindPageById(startTarget)); | ||
}; | ||
|
||
HomeButton.OnPressed += _ => UpdateUI(_mainMenuPage); | ||
YesButton.OnPressed += _ => AdvanceState(_currentPage, true); | ||
NoButton.OnPressed += _ => AdvanceState(_currentPage, false); | ||
} | ||
|
||
public void AdvanceState(CrimeAssistPage currentPage, bool yesPressed) | ||
{ | ||
var nextId = yesPressed ? currentPage.OnYes : currentPage.OnNo; | ||
if (nextId != null) | ||
{ | ||
var nextPage = FindPageById(nextId); | ||
UpdateUI(nextPage); | ||
} | ||
} | ||
|
||
public void UpdateUI(CrimeAssistPage page) | ||
{ | ||
_currentPage = page; | ||
bool isResult = page.LocKeyPunishment != null; | ||
|
||
StartButton.Visible = page.OnStart != null; | ||
YesButton.Visible = page.OnYes != null; | ||
NoButton.Visible = page.OnNo != null; | ||
HomeButton.Visible = page.OnStart == null; | ||
Explanation.Visible = page.OnStart == null; | ||
|
||
Subtitle.Visible = page.LocKeySeverity != null; | ||
Punishment.Visible = page.LocKeyPunishment != null; | ||
|
||
if (!isResult) | ||
{ | ||
UpdateAsQuestionPage(page); | ||
} | ||
else | ||
{ | ||
UpdateAsResultPage(page); | ||
} | ||
} | ||
|
||
private void UpdateAsQuestionPage(CrimeAssistPage page) | ||
{ | ||
var baseString = page.LocKey != null ? Loc.GetString(page.LocKey) : string.Empty; | ||
string questionMarkup = $"\n[font size=15]{baseString}[/font]"; | ||
|
||
if (questionMarkup.ToLower().Contains("sophont")) | ||
{ | ||
string sophontExplanation = Loc.GetString("crime-assist-sophont-explanation"); | ||
questionMarkup += $"\n[font size=8][color=#999999]{sophontExplanation}[/color][/font]"; | ||
} | ||
|
||
Title.SetMarkup(questionMarkup); | ||
Subtitle.SetMarkup(string.Empty); | ||
Explanation.SetMarkup(string.Empty); | ||
Punishment.SetMarkup(string.Empty); | ||
} | ||
|
||
private void UpdateAsResultPage(CrimeAssistPage page) | ||
{ | ||
var severityColor = GetSeverityColor(page.LocKeySeverity); | ||
|
||
var titleString = page.LocKeyTitle != null ? Loc.GetString(page.LocKeyTitle) : string.Empty; | ||
var severityString = page.LocKeySeverity != null ? Loc.GetString(page.LocKeySeverity) : string.Empty; | ||
var descriptionString = page.LocKeyDescription != null ? Loc.GetString(page.LocKeyDescription) : string.Empty; | ||
var punishmentString = page.LocKeyPunishment != null ? Loc.GetString(page.LocKeyPunishment) : string.Empty; | ||
|
||
Title.SetMarkup($"\n[bold][font size=13][color=#a4885c]{titleString}[/color][/font][/bold]"); | ||
Subtitle.SetMarkup($"\n[font size=13][color={severityColor}]{severityString}[/color][/font]"); | ||
Explanation.SetMarkup($"\n[title]{descriptionString}[/title]\n"); | ||
Punishment.SetMarkup($"[bold][font size=13]{punishmentString}[/font][/bold]"); | ||
} | ||
|
||
private CrimeAssistPage FindPageById(string id) | ||
{ | ||
if (_pages == null) | ||
throw new InvalidOperationException("Pages not initialized."); | ||
|
||
var page = _pages.Find(o => o.ID == id); | ||
if (page == null) | ||
throw new KeyNotFoundException($"No CrimeAssistPage found with ID: {id}"); | ||
|
||
return page; | ||
} | ||
|
||
private string GetSeverityColor(string? severityKey) | ||
{ | ||
return severityKey switch | ||
{ | ||
"crime-assist-crime-type-corporate" => "#0044cc", | ||
"crime-assist-crime-type-personal" => "#cc0000", | ||
"crime-assist-crime-type-property" => "#ffaa00", | ||
"crime-assist-crime-type-public-order" => "#008000", | ||
_ => "#ff00ff" | ||
}; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Content.Server/_CorvaxNext/CartridgeLoader/CrimeAssistCartridgeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Content.Server._CorvaxNext.CartridgeLoader.Cartridges; | ||
|
||
[RegisterComponent] | ||
public sealed partial class CrimeAssistCartridgeComponent : Component | ||
{ } |
16 changes: 16 additions & 0 deletions
16
Content.Server/_CorvaxNext/CartridgeLoader/CrimeAssistCartridgeSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Content.Shared.CartridgeLoader; | ||
using Content.Server._CorvaxNext.CartridgeLoader; | ||
using Content.Server.CartridgeLoader.Cartridges; | ||
using Content.Server.CartridgeLoader; | ||
|
||
namespace Content.Server._CorvaxNext.CartridgeLoader.Cartridges; | ||
|
||
public sealed class CrimeAssistCartridgeSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly CartridgeLoaderSystem? _cartridgeLoaderSystem = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Content.Shared/_CorvaxNext/CartridgeLoader/Cartridges/CrimeAssistPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared._CorvaxNext.CartridgeLoader.Cartridges; | ||
|
||
[Prototype("crimeAssistPage")] | ||
public sealed partial class CrimeAssistPage : IPrototype | ||
{ | ||
[ViewVariables] | ||
[IdDataField] | ||
public string ID { get; private set; } = ""; | ||
|
||
[DataField("onStart")] | ||
public string? OnStart { get; private set; } | ||
|
||
[DataField("locKey")] | ||
public string? LocKey { get; private set; } | ||
|
||
[DataField("onYes")] | ||
public string? OnYes { get; private set; } | ||
|
||
[DataField("onNo")] | ||
public string? OnNo { get; private set; } | ||
|
||
[DataField("locKeyTitle")] | ||
public string? LocKeyTitle { get; private set; } | ||
|
||
[DataField("locKeyDescription")] | ||
public string? LocKeyDescription { get; private set; } | ||
|
||
[DataField("locKeySeverity")] | ||
public string? LocKeySeverity { get; private set; } | ||
|
||
[DataField("locKeyPunishment")] | ||
public string? LocKeyPunishment { get; private set; } | ||
} |
18 changes: 18 additions & 0 deletions
18
Content.Shared/_CorvaxNext/CartridgeLoader/Cartridges/CrimeAssistUiState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Content.Shared.CartridgeLoader; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._CorvaxNext.CartridgeLoader.Cartridges; | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class CrimeAssistUiState : BoundUserInterfaceState | ||
{ | ||
public CrimeAssistUiState() | ||
{ } | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class CrimeAssistSyncMessageEvent : CartridgeMessageEvent | ||
{ | ||
public CrimeAssistSyncMessageEvent() | ||
{ } | ||
} |
Oops, something went wrong.