Esempio n. 1
0
        protected override void ClientUpdate(ClientUpdateData data)
        {
            base.ClientUpdate(data);

            if (this.currentDisplayedRepairTooltip != null)
            {
                var tooltipDisplayedForObject =
                    ((ConstructionOrRepairRequirementsTooltip)this.currentDisplayedRepairTooltip.Control).WorldObject;
                if (data.GameObject == tooltipDisplayedForObject &&
                    !this.IsConstructionOrRepairRequirementsTooltipShouldBeDisplayed(data.SyncPublicState))
                {
                    // destroy tooltip
                    this.currentDisplayedRepairTooltip?.Destroy();
                    this.currentDisplayedRepairTooltip = null;
                }
            }

            if (this.currentDisplayedRepairTooltip == null &&
                this.IsConstructionOrRepairRequirementsTooltipShouldBeDisplayed(data.SyncPublicState))
            {
                // display tooltip
                var worldObject = data.GameObject;
                this.currentDisplayedRepairTooltip =
                    ConstructionOrRepairRequirementsTooltip.CreateAndAttach(worldObject);
            }
        }
        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;
                }
            }
        }
        private static void Update()
        {
            if (LoadingSplashScreenManager.Instance.CurrentState
                != LoadingSplashScreenState.Hidden)
            {
                return;
            }

            IStaticWorldObject    worldObject    = null;
            IProtoObjectStructure protoStructure = null;

            var selectedProtoItem = ClientHotbarSelectedItemManager.SelectedItem?.ProtoItem;

            if (selectedProtoItem is IProtoItemToolToolbox ||
                selectedProtoItem is IProtoItemToolCrowbar)
            {
                worldObject    = ClientComponentObjectInteractionHelper.MouseOverObject as IStaticWorldObject;
                protoStructure = worldObject?.ProtoGameObject as IProtoObjectStructure;
            }

            if (currentTooltipsWorldObject != worldObject)
            {
                tooltipBuildOrRepair?.Destroy();
                tooltipBuildOrRepair = null;

                tooltipRelocate?.Destroy();
                tooltipRelocate = null;

                tooltipDeconstruct?.Destroy();
                tooltipDeconstruct = null;

                currentTooltipsWorldObject = worldObject;
            }

            if (protoStructure is null)
            {
                return;
            }

            // process structure repair tooltip
            var isBuildTooltipRequired
                = selectedProtoItem is IProtoItemToolToolbox &&
                  protoStructure.ClientIsConstructionOrRepairRequirementsTooltipShouldBeDisplayed(worldObject);

            if (tooltipBuildOrRepair is null)
            {
                if (isBuildTooltipRequired)
                {
                    tooltipBuildOrRepair = ConstructionOrRepairRequirementsTooltip.CreateAndAttach(worldObject);
                }
            }
            else if (!isBuildTooltipRequired)
            {
                tooltipBuildOrRepair.Destroy();
                tooltipBuildOrRepair = null;
            }

            // process structure relocation tooltip
            var canRelocate = selectedProtoItem is IProtoItemToolToolbox &&
                              !ConstructionRelocationSystem.IsInObjectPlacementMode &&
                              ConstructionRelocationSystem.SharedIsRelocatable(worldObject);

            if (tooltipRelocate is null)
            {
                if (canRelocate)
                {
                    tooltipRelocate = ConstructionRelocationTooltip.CreateAndAttach(worldObject);
                }
            }
            else if (!canRelocate)
            {
                tooltipRelocate.Destroy();
                tooltipRelocate = null;
            }

            // process structure deconstruction tooltip
            var canDeconstruct = selectedProtoItem is IProtoItemToolCrowbar &&
                                 DeconstructionSystem.SharedIsDeconstructable(protoStructure);

            if (tooltipDeconstruct is null)
            {
                if (canDeconstruct)
                {
                    tooltipDeconstruct = ConstructionDeconstructTooltip.CreateAndAttach(worldObject);
                }
            }
            else if (!canDeconstruct)
            {
                tooltipDeconstruct.Destroy();
                tooltipDeconstruct = null;
            }
        }