예제 #1
0
 private void UpdatePDAAppearance(PDAComponent pda)
 {
     if (EntityManager.TryGetComponent(pda.Owner, out AppearanceComponent? appearance))
     {
         appearance.SetData(PDAVisuals.IDCardInserted, pda.ContainedID != null);
     }
 }
예제 #2
0
 private void OnActivateInWorld(EntityUid uid, PDAComponent pda, ActivateInWorldEvent args)
 {
     if (args.Handled)
     {
         return;
     }
     args.Handled = OpenUI(pda, args.User);
 }
예제 #3
0
 private void OnUse(EntityUid uid, PDAComponent pda, UseInHandEvent args)
 {
     if (args.Handled)
     {
         return;
     }
     args.Handled = OpenUI(pda, args.User);
 }
예제 #4
0
        private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
        {
            // cast EntityUid? to EntityUid
            if (msg.Session.AttachedEntity is not {
                Valid: true
            } playerUid)
            {
                return;
            }

            switch (msg.Message)
            {
            case PDARequestUpdateInterfaceMessage _:
                UpdatePDAUserInterface(pda, playerUid);
                break;

            case PDAToggleFlashlightMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out UnpoweredFlashlightComponent? flashlight))
                {
                    _unpoweredFlashlight.ToggleLight(flashlight);
                }
                break;
            }

            case PDAEjectIDMessage _:
            {
                ItemSlotsSystem.TryEjectToHands(pda.Owner, pda.IdSlot, playerUid);
                break;
            }

            case PDAEjectPenMessage _:
            {
                ItemSlotsSystem.TryEjectToHands(pda.Owner, pda.PenSlot, playerUid);
                break;
            }

            case PDAShowUplinkMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out UplinkComponent? uplink))
                {
                    _uplinkSystem.ToggleUplinkUI(uplink, msg.Session);
                }
                break;
            }

            case PDAShowRingtoneMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out RingerComponent? ringer))
                {
                    _ringerSystem.ToggleRingerUI(ringer, msg.Session);
                }
                break;
            }
            }
        }
예제 #5
0
        private void OnItemRemoved(EntityUid uid, PDAComponent pda, EntRemovedFromContainerMessage args)
        {
            if (args.Container.ID == pda.IdSlot.ID)
            {
                pda.ContainedID = null;
            }

            UpdatePDAAppearance(pda);
            UpdatePDAUserInterface(pda);
        }
예제 #6
0
        private void OnItemInserted(EntityUid uid, PDAComponent pda, EntInsertedIntoContainerMessage args)
        {
            if (args.Container.ID == pda.IdSlot.ID)
            {
                pda.ContainedID = EntityManager.GetComponentOrNull <IdCardComponent>(args.Entity);
            }

            UpdatePDAAppearance(pda);
            UpdatePDAUserInterface(pda);
        }
예제 #7
0
        private void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
        {
            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            if (ui != null)
            {
                ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
            }

            UpdatePDAAppearance(pda);
        }
예제 #8
0
        protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
        {
            base.OnComponentInit(uid, pda, args);

            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            if (ui != null)
            {
                ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
            }
        }
예제 #9
0
        private bool OpenUI(PDAComponent pda, EntityUid user)
        {
            if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
            {
                return(false);
            }

            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            ui?.Toggle(actor.PlayerSession);

            return(true);
        }
예제 #10
0
 private void OnMapInit(EntityUid uid, PDAComponent pda, MapInitEvent args)
 {
     // try to place ID inside item slot
     if (!string.IsNullOrEmpty(pda.StartingIdCard))
     {
         // if pda prototype doesn't have slots, ID will drop down on ground
         var idCard = EntityManager.SpawnEntity(pda.StartingIdCard, pda.Owner.Transform.Coordinates);
         if (EntityManager.TryGetComponent(uid, out SharedItemSlotsComponent? itemSlots))
         {
             _slotsSystem.TryInsertContent(itemSlots, idCard, pda.IdSlot);
         }
     }
 }
예제 #11
0
        protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
        {
            base.OnComponentInit(uid, pda, args);

            if (!TryComp(uid, out ServerUserInterfaceComponent? uiComponent))
            {
                return;
            }

            if (_uiSystem.TryGetUi(uid, PDAUiKey.Key, out var ui, uiComponent))
            {
                ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
            }
        }
예제 #12
0
        private void UpdatePDAUserInterface(PDAComponent pda)
        {
            var ownerInfo = new PDAIdInfoText
            {
                ActualOwnerName = pda.OwnerName,
                IdOwner         = pda.ContainedID?.FullName,
                JobTitle        = pda.ContainedID?.JobTitle
            };

            var hasUplink = EntityManager.HasComponent <UplinkComponent>(pda.Owner);

            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            ui?.SetState(new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, hasUplink));
        }
예제 #13
0
        private void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
        {
            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            if (ui != null)
            {
                ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
            }

            if (pda.IdCard != null)
            {
                pda.IdSlot.StartingItem = pda.IdCard;
            }
            _itemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-id", pda.IdSlot);
            _itemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-pen", pda.PenSlot);
        }
예제 #14
0
        private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
        {
            // todo: move this to entity events
            switch (msg.Message)
            {
            case PDARequestUpdateInterfaceMessage _:
                UpdatePDAUserInterface(pda);
                break;

            case PDAToggleFlashlightMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out UnpoweredFlashlightComponent? flashlight))
                {
                    _unpoweredFlashlight.ToggleLight(flashlight);
                }
                break;
            }

            case PDAShowUplinkMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out UplinkComponent? uplink))
                {
                    _uplinkSystem.ToggleUplinkUI(uplink, msg.Session);
                }
                break;
            }

            case PDAShowRingtoneMessage _:
            {
                if (EntityManager.TryGetComponent(pda.Owner, out RingerComponent? ringer))
                {
                    _ringerSystem.ToggleRingerUI(ringer, msg.Session);
                }
                break;
            }

            case PDAShowMusicMessage _:
            {
                if (TryComp(pda.Owner, out InstrumentComponent? instrument))
                {
                    _instrumentSystem.ToggleInstrumentUi(pda.Owner, msg.Session, instrument);
                }
                break;
            }
            }
        }
예제 #15
0
        private void UpdatePDAUserInterface(PDAComponent pda)
        {
            var ownerInfo = new PDAIdInfoText
            {
                ActualOwnerName = pda.OwnerName,
                IdOwner         = pda.ContainedID?.FullName,
                JobTitle        = pda.ContainedID?.JobTitle
            };

            if (!_uiSystem.TryGetUi(pda.Owner, PDAUiKey.Key, out var ui))
            {
                return;
            }

            var hasInstrument = HasComp <InstrumentComponent>(pda.Owner);
            var state         = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, false, hasInstrument);

            ui.SetState(state);

            // TODO UPLINK RINGTONES/SECRETS This is just a janky placeholder way of hiding uplinks from non syndicate
            // players. This should really use a sort of key-code entry system that selects an account which is not directly tied to
            // a player entity.

            if (!HasComp <UplinkComponent>(pda.Owner))
            {
                return;
            }

            var uplinkState = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, true, hasInstrument);

            foreach (var session in ui.SubscribedSessions)
            {
                if (session.AttachedEntity is not EntityUid {
                    Valid: true
                } user)
                {
                    continue;
                }

                if (_uplinkAccounts.HasAccount(user))
                {
                    ui.SetState(uplinkState, session);
                }
            }
        }
예제 #16
0
        private void UpdatePDAUserInterface(PDAComponent pda, EntityUid?user = null)
        {
            var ownerInfo = new PDAIdInfoText
            {
                ActualOwnerName = pda.OwnerName,
                IdOwner         = pda.ContainedID?.FullName,
                JobTitle        = pda.ContainedID?.JobTitle
            };

            var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);

            if (ui == null)
            {
                return;
            }

            ui.SetState(new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, ShouldShowUplink(pda.Owner, ui, user)));
        }
예제 #17
0
        private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
        {
            switch (msg.Message)
            {
            case PDARequestUpdateInterfaceMessage _:
                UpdatePDAUserInterface(pda);
                break;

            case PDAToggleFlashlightMessage _:
            {
                if (pda.Owner.TryGetComponent(out UnpoweredFlashlightComponent? flashlight))
                {
                    _unpoweredFlashlight.ToggleLight(flashlight);
                }
                break;
            }

            case PDAEjectIDMessage _:
            {
                _slotsSystem.TryEjectContent(pda.Owner.Uid, pda.IdSlot, msg.Session.AttachedEntity);
                break;
            }

            case PDAEjectPenMessage _:
            {
                _slotsSystem.TryEjectContent(pda.Owner.Uid, pda.PenSlot, msg.Session.AttachedEntity);
                break;
            }

            case PDAShowUplinkMessage _:
            {
                if (pda.Owner.TryGetComponent(out UplinkComponent? uplink))
                {
                    _uplinkSystem.ToggleUplinkUI(uplink, msg.Session);
                }
                break;
            }
            }
        }
예제 #18
0
        private void OnItemSlotChanged(EntityUid uid, PDAComponent pda, ItemSlotChangedEvent args)
        {
            // check if ID slot changed
            if (args.SlotName == pda.IdSlot)
            {
                var item = args.ContainedItem;
                if (item == null || !EntityManager.TryGetComponent(item.Value, out IdCardComponent ? idCard))
                {
                    pda.ContainedID = null;
                }
                else
                {
                    pda.ContainedID = idCard;
                }
            }
            else if (args.SlotName == pda.PenSlot)
            {
                var item = args.ContainedItem;
                pda.PenInserted = item != null;
            }

            UpdatePDAAppearance(pda);
            UpdatePDAUserInterface(pda);
        }
예제 #19
0
        private void AfterUIOpen(EntityUid uid, PDAComponent pda, AfterActivatableUIOpenEvent args)
        {
            // A new user opened the UI --> Check if they are a traitor and should get a user specific UI state override.
            if (!HasComp <UplinkComponent>(pda.Owner) || !_uplinkAccounts.HasAccount(args.User))
            {
                return;
            }

            if (!_uiSystem.TryGetUi(pda.Owner, PDAUiKey.Key, out var ui))
            {
                return;
            }

            var ownerInfo = new PDAIdInfoText
            {
                ActualOwnerName = pda.OwnerName,
                IdOwner         = pda.ContainedID?.FullName,
                JobTitle        = pda.ContainedID?.JobTitle
            };

            var state = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, true, HasComp <InstrumentComponent>(pda.Owner));

            ui.SetState(state, args.Session);
        }
예제 #20
0
 protected override void OnItemRemoved(EntityUid uid, PDAComponent pda, EntRemovedFromContainerMessage args)
 {
     base.OnItemRemoved(uid, pda, args);
     UpdatePDAUserInterface(pda);
 }
예제 #21
0
 private void OnComponentRemove(EntityUid uid, PDAComponent pda, ComponentRemove args)
 {
     _itemSlotsSystem.RemoveItemSlot(uid, pda.IdSlot);
     _itemSlotsSystem.RemoveItemSlot(uid, pda.PenSlot);
 }
예제 #22
0
 private void OnLightToggle(EntityUid uid, PDAComponent pda, LightToggleEvent args)
 {
     pda.FlashlightOn = args.IsOn;
     UpdatePDAUserInterface(pda);
 }
예제 #23
0
 private void OnUplinkRemoved(EntityUid uid, PDAComponent pda, UplinkRemovedEvent args)
 {
     UpdatePDAUserInterface(pda);
 }
예제 #24
0
 public void SetOwner(PDAComponent pda, string ownerName)
 {
     pda.OwnerName = ownerName;
     UpdatePDAUserInterface(pda);
 }
예제 #25
0
        private void UpdateStationName(PDAComponent pda)
        {
            var station = _stationSystem.GetOwningStation(pda.Owner);

            pda.StationName = station is null ? null : Name(station.Value);
        }
예제 #26
0
 public PdaAccessSet(PDAComponent pdaComponent)
 {
     _pdaComponent = pdaComponent;
 }
예제 #27
0
 private void OnGridChanged(EntityUid uid, PDAComponent pda, GridModifiedEvent args)
 {
     UpdateStationName(pda);
     UpdatePDAUserInterface(pda);
 }