Esempio n. 1
0
        public static void ClientObserving(IStaticWorldObject worldObject, bool isObserving)
        {
            if (isObserving)
            {
                structureLandClaimIndicator = ControlsCache <StructureLandClaimIndicator> .Instance.Pop();

                structureLandClaimIndicator.Setup(
                    isClaimed: LandClaimSystem.SharedIsLandClaimedByAnyone(worldObject.Bounds));

                var offset = worldObject.ProtoStaticWorldObject.SharedGetObjectCenterWorldOffset(worldObject);
                componentStructureLandClaimIndicator = Api.Client.UI.AttachControl(
                    worldObject,
                    structureLandClaimIndicator,
                    positionOffset: offset + (0, 0.3),
                    isFocusable: false);
            }
            else
            {
                componentStructureLandClaimIndicator.Destroy();
                componentStructureLandClaimIndicator = null;
                ControlsCache <StructureLandClaimIndicator> .Instance.Push(structureLandClaimIndicator);

                structureLandClaimIndicator = null;
            }
        }
        public sealed override void ClientDeinitialize(IStaticWorldObject gameObject)
        {
            StructureLandClaimIndicatorManager.ClientDeinitialize(gameObject);

            base.ClientDeinitialize(gameObject);

            if (currentDisplayedRepairTooltip != null)
            {
                var tooltipDisplayedForObject =
                    ((ConstructionOrRepairRequirementsTooltip)currentDisplayedRepairTooltip.Control).WorldObject;
                if (ReferenceEquals(gameObject, tooltipDisplayedForObject))
                {
                    // destroy tooltip
                    currentDisplayedRepairTooltip.Destroy();
                    currentDisplayedRepairTooltip = null;
                }
            }

            if (currentDisplayedRelocateTooltip != null)
            {
                var tooltipDisplayedForObject =
                    ((ConstructionRelocationTooltip)currentDisplayedRelocateTooltip.Control).WorldObject;
                if (ReferenceEquals(gameObject, tooltipDisplayedForObject))
                {
                    // destroy tooltip
                    currentDisplayedRelocateTooltip.Destroy();
                    currentDisplayedRelocateTooltip = null;
                }
            }

            this.ClientDeinitializeStructure(gameObject);
        }
        protected override void ClientUpdate(ClientUpdateData data)
        {
            base.ClientUpdate(data);

            var worldObject = data.GameObject;

            if (currentDisplayedRepairTooltip is null)
            {
                if (this.ClientIsConstructionOrRepairRequirementsTooltipShouldBeDisplayed(data.PublicState))
                {
                    // display build/repair tooltip
                    currentDisplayedRepairTooltip =
                        ConstructionOrRepairRequirementsTooltip.CreateAndAttach(worldObject);
                }
            }
            else
            {
                var tooltipDisplayedForObject =
                    ((ConstructionOrRepairRequirementsTooltip)currentDisplayedRepairTooltip.Control).WorldObject;
                if (ReferenceEquals(worldObject, tooltipDisplayedForObject) &&
                    !this.ClientIsConstructionOrRepairRequirementsTooltipShouldBeDisplayed(data.PublicState))
                {
                    // destroy tooltip
                    currentDisplayedRepairTooltip?.Destroy();
                    currentDisplayedRepairTooltip = null;
                }
            }

            if (currentDisplayedRelocateTooltip is null)
            {
                if (ClientCanRelocateStructure(worldObject))
                {
                    currentDisplayedRelocateTooltip =
                        ConstructionRelocationTooltip.CreateAndAttach(worldObject);
                }
            }
            else
            {
                var tooltipDisplayedForObject =
                    ((ConstructionRelocationTooltip)currentDisplayedRelocateTooltip.Control).WorldObject;
                if (ReferenceEquals(worldObject, tooltipDisplayedForObject) &&
                    !ClientCanRelocateStructure(worldObject))
                {
                    // destroy tooltip
                    currentDisplayedRelocateTooltip?.Destroy();
                    currentDisplayedRelocateTooltip = null;
                }
            }
        }
Esempio n. 4
0
 // This method is currently used only for doors and walls to display an indicator
 public static void ClientObserving(IStaticWorldObject worldObject, bool isObserving)
 {
     if (isObserving)
     {
         // do not display the green indicator as it may be misleading to some players
         //var isLandClaimed = LandClaimSystem.SharedIsObjectInsideAnyArea(worldObject);
         //if (isLandClaimed)
         //{
         //    // display only the green indicator when hover (as the red indicator is always displayed)
         //    lastHoverIndicator = SetupFor(worldObject, isClaimed: true);
         //}
     }
     else if (lastHoverIndicator != null)
     {
         // was hovering over that world object, destroy the indicator
         var control = (StructureLandClaimIndicator)lastHoverIndicator.Control;
         lastHoverIndicator.Destroy();
         lastHoverIndicator          = null;
         control.AttachedToComponent = null;
         ControlsCache <StructureLandClaimIndicator> .Instance.Push(control);
     }
 }
        private void ClientInitializeOtherCharacter(ClientInitializeData data)
        {
            IComponentAttachedControl nicknameDisplay = null;

            var publicState = data.SyncPublicState;

            publicState.ClientSubscribe(
                _ => _.IsOnline,
                _ => Refresh(),
                data.ClientState);

            publicState.ClientSubscribe(
                _ => _.IsDead,
                _ => Refresh(),
                data.ClientState);

            Refresh();

            void Refresh()
            {
                nicknameDisplay?.Destroy();
                nicknameDisplay = null;
                if (publicState.IsDead)
                {
                    return;
                }

                // setup nickname display
                var character = data.GameObject;
                var nicknameDisplayControl = new NicknameDisplay();

                nicknameDisplayControl.Setup(character.Name, publicState.IsOnline);
                nicknameDisplay = Client.UI.AttachControl(
                    character,
                    nicknameDisplayControl,
                    positionOffset: (0, this.CharacterWorldHeight + 0.05),
                    isFocusable: false);
            }
        }