diff --git a/Content.Client/Research/UI/ResearchConsoleMenu.xaml.cs b/Content.Client/Research/UI/ResearchConsoleMenu.xaml.cs index 8ff79a11f7..d40cf3cfdf 100644 --- a/Content.Client/Research/UI/ResearchConsoleMenu.xaml.cs +++ b/Content.Client/Research/UI/ResearchConsoleMenu.xaml.cs @@ -1,8 +1,11 @@ using Content.Client.UserInterface.Controls; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Research.Components; using Content.Shared.Research.Prototypes; using Robust.Client.AutoGenerated; using Robust.Client.GameObjects; +using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; @@ -19,9 +22,11 @@ public sealed partial class ResearchConsoleMenu : FancyWindow [Dependency] private readonly IEntityManager _entity = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; + [Dependency] private readonly IPlayerManager _player = default!; private readonly TechnologyDatabaseComponent? _technologyDatabase; private readonly ResearchSystem _research; private readonly SpriteSystem _sprite; + private readonly AccessReaderSystem _accessReader = default!; public readonly EntityUid Entity; @@ -32,6 +37,7 @@ public sealed partial class ResearchConsoleMenu : FancyWindow _research = _entity.System(); _sprite = _entity.System(); + _accessReader = _entity.System(); Entity = entity; ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke(); @@ -60,10 +66,14 @@ public sealed partial class ResearchConsoleMenu : FancyWindow { MinHeight = 10 }); + + var hasAccess = _player.LocalPlayer?.ControlledEntity is not { } local || + !_entity.TryGetComponent(Entity, out var access) || + _accessReader.IsAllowed(local, access); foreach (var techId in _technologyDatabase.CurrentTechnologyCards) { var tech = _prototype.Index(techId); - var cardControl = new TechnologyCardControl(tech, _prototype, _sprite, GetTechnologyDescription(tech), state.Points); + var cardControl = new TechnologyCardControl(tech, _prototype, _sprite, GetTechnologyDescription(tech), state.Points, hasAccess); cardControl.OnPressed += () => OnTechnologyCardPressed?.Invoke(techId); TechnologyCardsContainer.AddChild(cardControl); } diff --git a/Content.Client/Research/UI/TechnologyCardControl.xaml.cs b/Content.Client/Research/UI/TechnologyCardControl.xaml.cs index 76e30354c6..f547457203 100644 --- a/Content.Client/Research/UI/TechnologyCardControl.xaml.cs +++ b/Content.Client/Research/UI/TechnologyCardControl.xaml.cs @@ -13,7 +13,7 @@ public sealed partial class TechnologyCardControl : Control { public Action? OnPressed; - public TechnologyCardControl(TechnologyPrototype technology, IPrototypeManager prototypeManager, SpriteSystem spriteSys, FormattedMessage description, int points) + public TechnologyCardControl(TechnologyPrototype technology, IPrototypeManager prototypeManager, SpriteSystem spriteSys, FormattedMessage description, int points, bool hasAccess) { RobustXamlLoader.Load(this); @@ -30,7 +30,10 @@ public sealed partial class TechnologyCardControl : Control TechnologyTexture.Texture = spriteSys.Frame0(technology.Icon); - ResearchButton.Disabled = points < technology.Cost; + if (!hasAccess) + ResearchButton.ToolTip = Loc.GetString("research-console-no-access-popup"); + + ResearchButton.Disabled = points < technology.Cost || !hasAccess; ResearchButton.OnPressed += _ => OnPressed?.Invoke(); } } diff --git a/Content.Server/Research/Systems/ResearchSystem.Console.cs b/Content.Server/Research/Systems/ResearchSystem.Console.cs index f057cc9fd6..369c007cdb 100644 --- a/Content.Server/Research/Systems/ResearchSystem.Console.cs +++ b/Content.Server/Research/Systems/ResearchSystem.Console.cs @@ -1,6 +1,7 @@ using Content.Server.Power.EntitySystems; using Content.Server.Research.Components; using Content.Server.UserInterface; +using Content.Shared.Access.Components; using Content.Shared.Research.Components; namespace Content.Server.Research.Systems; @@ -18,9 +19,18 @@ public sealed partial class ResearchSystem private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args) { + if (args.Session.AttachedEntity is not { } ent) + return; + if (!this.IsPowered(uid, EntityManager)) return; + if (TryComp(uid, out var access) && !_accessReader.IsAllowed(ent, access)) + { + _popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), ent); + return; + } + if (!UnlockTechnology(uid, args.Id)) return; diff --git a/Content.Server/Research/Systems/ResearchSystem.cs b/Content.Server/Research/Systems/ResearchSystem.cs index 92e17df7f9..dd73c60df2 100644 --- a/Content.Server/Research/Systems/ResearchSystem.cs +++ b/Content.Server/Research/Systems/ResearchSystem.cs @@ -1,5 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Shared.Access.Systems; +using Content.Shared.Popups; using Content.Shared.Research.Components; using Content.Shared.Research.Systems; using JetBrains.Annotations; @@ -12,7 +14,9 @@ namespace Content.Server.Research.Systems public sealed partial class ResearchSystem : SharedResearchSystem { [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; public override void Initialize() { diff --git a/Resources/Locale/en-US/research/components/research-console-component.ftl b/Resources/Locale/en-US/research/components/research-console-component.ftl index bc53ad5d9d..1063e6ebcb 100644 --- a/Resources/Locale/en-US/research/components/research-console-component.ftl +++ b/Resources/Locale/en-US/research/components/research-console-component.ftl @@ -14,3 +14,5 @@ research-console-cost = Cost: [color=orchid]{$amount}[/color] research-console-unlocks-list-start = Unlocks: research-console-unlocks-list-entry = - [color=yellow]{$name}[/color] research-console-unlocks-list-entry-generic = - [color=green]{$text}[/color] + +research-console-no-access-popup = No access! diff --git a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml index 6ddc7b5a3e..9585e250b9 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml @@ -385,6 +385,8 @@ priority: Low - type: Computer board: ResearchComputerCircuitboard + - type: AccessReader + access: [["Research"]] - type: PointLight radius: 1.5 energy: 1.6