Move contraband text to a separate examine tab (#32250)
This commit is contained in:
@@ -4,8 +4,10 @@ using Content.Shared.CCVar;
|
|||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Localizations;
|
using Content.Shared.Localizations;
|
||||||
using Content.Shared.Roles;
|
using Content.Shared.Roles;
|
||||||
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Contraband;
|
namespace Content.Shared.Contraband;
|
||||||
|
|
||||||
@@ -17,22 +19,18 @@ public sealed class ContrabandSystem : EntitySystem
|
|||||||
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
[Dependency] private readonly SharedIdCardSystem _id = default!;
|
[Dependency] private readonly SharedIdCardSystem _id = default!;
|
||||||
|
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
||||||
|
|
||||||
private bool _contrabandExamineEnabled;
|
private bool _contrabandExamineEnabled;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<ContrabandComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<ContrabandComponent, GetVerbsEvent<ExamineVerb>>(OnDetailedExamine);
|
||||||
|
|
||||||
Subs.CVar(_configuration, CCVars.ContrabandExamine, SetContrabandExamine, true);
|
Subs.CVar(_configuration, CCVars.ContrabandExamine, SetContrabandExamine, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetContrabandExamine(bool val)
|
|
||||||
{
|
|
||||||
_contrabandExamineEnabled = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CopyDetails(EntityUid uid, ContrabandComponent other, ContrabandComponent? contraband = null)
|
public void CopyDetails(EntityUid uid, ContrabandComponent other, ContrabandComponent? contraband = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref contraband))
|
if (!Resolve(uid, ref contraband))
|
||||||
@@ -44,39 +42,39 @@ public sealed class ContrabandSystem : EntitySystem
|
|||||||
Dirty(uid, contraband);
|
Dirty(uid, contraband);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExamined(Entity<ContrabandComponent> ent, ref ExaminedEvent args)
|
private void OnDetailedExamine(EntityUid ent,ContrabandComponent component, ref GetVerbsEvent<ExamineVerb> args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!_contrabandExamineEnabled)
|
if (!_contrabandExamineEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// CanAccess is not used here, because we want people to be able to examine legality in strip menu.
|
||||||
|
if (!args.CanInteract)
|
||||||
|
return;
|
||||||
|
|
||||||
// two strings:
|
// two strings:
|
||||||
// one, the actual informative 'this is restricted'
|
// one, the actual informative 'this is restricted'
|
||||||
// then, the 'you can/shouldn't carry this around' based on the ID the user is wearing
|
// then, the 'you can/shouldn't carry this around' based on the ID the user is wearing
|
||||||
|
var localizedDepartments = component.AllowedDepartments.Select(p => Loc.GetString("contraband-department-plural", ("department", Loc.GetString(_proto.Index(p).Name))));
|
||||||
using (args.PushGroup(nameof(ContrabandComponent)))
|
var localizedJobs = component.AllowedJobs.Select(p => Loc.GetString("contraband-job-plural", ("job", _proto.Index(p).LocalizedName)));
|
||||||
{
|
var severity = _proto.Index(component.Severity);
|
||||||
var localizedDepartments = ent.Comp.AllowedDepartments.Select(p => Loc.GetString("contraband-department-plural", ("department", Loc.GetString(_proto.Index(p).Name))));
|
String departmentExamineMessage;
|
||||||
var localizedJobs = ent.Comp.AllowedJobs.Select(p => Loc.GetString("contraband-job-plural", ("job", _proto.Index(p).LocalizedName)));
|
|
||||||
|
|
||||||
var severity = _proto.Index(ent.Comp.Severity);
|
|
||||||
if (severity.ShowDepartmentsAndJobs)
|
if (severity.ShowDepartmentsAndJobs)
|
||||||
{
|
{
|
||||||
//creating a combined list of jobs and departments for the restricted text
|
//creating a combined list of jobs and departments for the restricted text
|
||||||
var list = ContentLocalizationManager.FormatList(localizedDepartments.Concat(localizedJobs).ToList());
|
var list = ContentLocalizationManager.FormatList(localizedDepartments.Concat(localizedJobs).ToList());
|
||||||
|
|
||||||
// department restricted text
|
// department restricted text
|
||||||
args.PushMarkup(Loc.GetString("contraband-examine-text-Restricted-department", ("departments", list)));
|
departmentExamineMessage = Loc.GetString("contraband-examine-text-Restricted-department", ("departments", list));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.PushMarkup(Loc.GetString(severity.ExamineText));
|
departmentExamineMessage = Loc.GetString(severity.ExamineText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// text based on ID card
|
// text based on ID card
|
||||||
List<ProtoId<DepartmentPrototype>> departments = new();
|
List<ProtoId<DepartmentPrototype>> departments = new();
|
||||||
var jobId = "";
|
var jobId = "";
|
||||||
|
if (_id.TryFindIdCard(args.User, out var id))
|
||||||
if (_id.TryFindIdCard(args.Examiner, out var id))
|
|
||||||
{
|
{
|
||||||
departments = id.Comp.JobDepartments;
|
departments = id.Comp.JobDepartments;
|
||||||
if (id.Comp.LocalizedJobTitle is not null)
|
if (id.Comp.LocalizedJobTitle is not null)
|
||||||
@@ -85,18 +83,39 @@ public sealed class ContrabandSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the jobs we compare the localized string in case you use an agent ID or custom job name that is not a prototype
|
String carryingMessage;
|
||||||
if (departments.Intersect(ent.Comp.AllowedDepartments).Any()
|
// either its fully restricted, you have no departments, or your departments dont intersect with the restricted departments
|
||||||
|
if (departments.Intersect(component.AllowedDepartments).Any()
|
||||||
|| localizedJobs.Contains(jobId))
|
|| localizedJobs.Contains(jobId))
|
||||||
{
|
{
|
||||||
// you are allowed to use this!
|
carryingMessage = Loc.GetString("contraband-examine-text-in-the-clear");
|
||||||
args.PushMarkup(Loc.GetString("contraband-examine-text-in-the-clear"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// straight to jail!
|
// otherwise fine to use :tm:
|
||||||
args.PushMarkup(Loc.GetString("contraband-examine-text-avoid-carrying-around"));
|
carryingMessage = Loc.GetString("contraband-examine-text-avoid-carrying-around");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var examineMarkup = GetContrabandExamine(departmentExamineMessage, carryingMessage);
|
||||||
|
_examine.AddDetailedExamineVerb(args,
|
||||||
|
component,
|
||||||
|
examineMarkup,
|
||||||
|
Loc.GetString("contraband-examinable-verb-text"),
|
||||||
|
"/Textures/Interface/VerbIcons/lock.svg.192dpi.png",
|
||||||
|
Loc.GetString("contraband-examinable-verb-message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FormattedMessage GetContrabandExamine(String deptMessage, String carryMessage)
|
||||||
|
{
|
||||||
|
var msg = new FormattedMessage();
|
||||||
|
msg.AddMarkupOrThrow(deptMessage);
|
||||||
|
msg.PushNewline();
|
||||||
|
msg.AddMarkupOrThrow(carryMessage);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetContrabandExamine(bool val)
|
||||||
|
{
|
||||||
|
_contrabandExamineEnabled = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,8 @@ contraband-examine-text-Syndicate = [color=crimson]This item is highly illegal S
|
|||||||
contraband-examine-text-avoid-carrying-around = [color=red][italic]You probably want to avoid visibly carrying this around without a good reason.[/italic][/color]
|
contraband-examine-text-avoid-carrying-around = [color=red][italic]You probably want to avoid visibly carrying this around without a good reason.[/italic][/color]
|
||||||
contraband-examine-text-in-the-clear = [color=green][italic]You should be in the clear to visibly carry this around.[/italic][/color]
|
contraband-examine-text-in-the-clear = [color=green][italic]You should be in the clear to visibly carry this around.[/italic][/color]
|
||||||
|
|
||||||
|
contraband-examinable-verb-text = Legality
|
||||||
|
contraband-examinable-verb-message = Check legality of this item.
|
||||||
|
|
||||||
contraband-department-plural = {$department}
|
contraband-department-plural = {$department}
|
||||||
contraband-job-plural = {MAKEPLURAL($job)}
|
contraband-job-plural = {MAKEPLURAL($job)}
|
||||||
|
|||||||
Reference in New Issue
Block a user