private void UpdateDisplayedTimeNoTimer()
        {
            {
                // update harvest time
                var totalDuration        = this.totalHarvestDuration;
                var timeRemainingSeconds = GetTimeRemainingSeconds(this.nextHarvestTime);
                this.HarvestInTimeText = timeRemainingSeconds > 0
                                             ? ClientTimeFormatHelper.FormatTimeDuration(timeRemainingSeconds)
                                             : CoreStrings.FarmPlantTooltip_TitleHarvestInCountdown_Ready;
                this.HarvestInTimePercent = (float)(100 * (totalDuration - timeRemainingSeconds) / totalDuration);
            }

            if (this.VisibilityWatered == Visibility.Visible)
            {
                // update watering time
                var totalDuration = this.wateringDuration;
                if (totalDuration < double.MaxValue)
                {
                    var timeRemainingSeconds = GetTimeRemainingSeconds(this.wateringEndsTime);
                    timeRemainingSeconds         = MathHelper.Clamp(timeRemainingSeconds, 0, totalDuration);
                    this.WateringEndsTimeText    = ClientTimeFormatHelper.FormatTimeDuration(timeRemainingSeconds);
                    this.WateringEndsTimePercent = (float)(100 * timeRemainingSeconds / totalDuration);
                }
                else
                {
                    this.WateringEndsTimeText    = TitlePermanent;
                    this.WateringEndsTimePercent = 100;
                }
            }
            else
            {
                this.WateringEndsTimePercent = 0;
            }
        }
        private static void PlayerLoginHook(string playerName, out string errorMessage)
        {
            if (ServerOperatorSystem.ServerIsOperator(playerName))
            {
                // operators cannot be banned, blocked or kicked
                errorMessage = null;
                return;
            }

            if (IsInBlackList(playerName))
            {
                errorMessage = CannotJoinBanned;
                return;
            }

            if (isWhiteListEnabled && !whiteList.Contains(playerName, StringComparer.OrdinalIgnoreCase))
            {
                errorMessage = CannotJoinNotInWhitelist;
                return;
            }

            if (IsKicked(playerName, out var secondsRemains))
            {
                errorMessage = string.Format(CannotJoinKicked,
                                             ClientTimeFormatHelper.FormatTimeDuration(secondsRemains));
                return;
            }

            // all checks passed successfully
            errorMessage = null;
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize information about entity - invoked after all entity view Models created,
        /// so you can use links to other entity by using <see cref="EntityViewModelsManager.GetEntityViewModel" />
        /// and <see cref="EntityViewModelsManager.GetAllEntityViewModels" />.
        /// </summary>
        public override void InitInformation()
        {
            base.InitInformation();

            if (ProtoEntity is IProtoItemFood food)
            {
                EntityInformation.Add(new ViewModelEntityInformation("Stay fresh",
                                                                     food.FreshnessDuration == TimeSpan.Zero
                        ? "forever"
                        : ClientTimeFormatHelper.FormatTimeDuration(food.FreshnessDuration)));
                if (Math.Abs(food.FoodRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Food restore", food.FoodRestore));
                }
                if (Math.Abs(food.WaterRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Water restore", food.WaterRestore));
                }
                if (Math.Abs(food.StaminaRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Stamina restore", food.StaminaRestore));
                }
                foreach (EffectAction effect in food.Effects)
                {
                    EntityInformation.Add(new ViewModelEntityInformation(effect.Intensity > 0 ? "Add effect" : "Remove effect",
                                                                         EntityViewModelsManager.GetEntityViewModel(effect.ProtoStatusEffect), effect.Intensity));
                }
            }
        }
        private void Update()
        {
            if (this.IsDisposed)
            {
                return;
            }

            // schedule next update
            ClientTimersSystem.AddAction(1, this.Update);

            var timeRemains = this.characterPublicState.UnstuckExecutionTime
                              - Client.CurrentGame.ServerFrameTimeApproximated;

            timeRemains = Math.Max(timeRemains, 0);
            if (this.lastTimeRemains == timeRemains)
            {
                return;
            }

            this.lastTimeRemains = timeRemains;
            if (timeRemains > 0)
            {
                this.VisibilityUnstuckInfo = Visibility.Visible;
                this.UnstuckInfoMessage    = string.Format(CoreStrings.UnstuckInFormat,
                                                           ClientTimeFormatHelper.FormatTimeDuration(timeRemains));
            }
            else
            {
                this.VisibilityUnstuckInfo = Visibility.Collapsed;
                this.UnstuckInfoMessage    = string.Empty;
            }
        }
Esempio n. 5
0
        public static async void ClientInvitationAccept(string clanTag)
        {
            if (NewbieProtectionSystem.ClientIsNewbie)
            {
                NewbieProtectionSystem.ClientNotifyNewbieCannotPerformAction(null);
                return;
            }

            if (ClientCheckIsUnderJoinCooldown(showErrorNotification: true))
            {
                return;
            }

            var timeRemains = await Instance.CallServer(
                _ => _.ServerRemote_GetCooldownRemainsToJoinReturnToFaction(clanTag));

            if (timeRemains > 0)
            {
                var factionEmblem =
                    await ClientFactionEmblemTextureProvider.GetEmblemTextureAsync(clanTag, useCache : true);

                NotificationSystem.ClientShowNotification(
                    title: CoreStrings.Faction_ErrorUnderJoinCooldown,
                    // TODO: consider using a separate text constant here
                    message: string.Format(CoreStrings.ShieldProtection_CooldownRemains_Format,
                                           ClientTimeFormatHelper.FormatTimeDuration(timeRemains)),
                    NotificationColor.Bad,
                    icon: factionEmblem);
                return;
            }

            DialogWindow.ShowDialog(
                title: CoreStrings.Faction_Join,
                text: string.Format(CoreStrings.Faction_DialogJoinConfirmation_Message_Format,
                                    @$ "\[{clanTag}\]")
Esempio n. 6
0
        private static void UpdateNotificationControlText()
        {
            if (notificationControl is null ||
                serverSaveScheduledTime is null)
            {
                return;
            }

            string message;

            var secondsRemains = serverSaveScheduledTime.Value - Api.Client.CurrentGame.ServerFrameTimeApproximated;

            if (secondsRemains <= 0)
            {
                secondsRemains = 0;
                message        = CoreStrings.AutosaveNotification_Saving;
            }
            else
            {
                message = string.Format(CoreStrings.AutosaveNotification_DelayRemains_Format,
                                        ClientTimeFormatHelper.FormatTimeDuration(secondsRemains));
            }

            notificationControl.Message = NotificationMessageBaseText + message;

            if (secondsRemains > 0)
            {
                ClientTimersSystem.AddAction(1, UpdateNotificationControlText);
            }
        }
        public string Execute(ICharacter character, int?minutes = null)
        {
            if (character == null)
            {
                throw new Exception("The character name is not provided");
            }

            if (character == this.ExecutionContextCurrentCharacter)
            {
                throw new Exception("You cannot mute yourself");
            }

            if (minutes == null)
            {
                minutes = DefaultDuration;
            }

            if (minutes < 1)
            {
                throw new Exception($"Minutes must be in 1-{int.MaxValue} range");
            }

            ServerPlayerMuteSystem.Mute(character, minutes.Value);
            return(string.Format("{0} successfully muted on the server for {1}",
                                 character.Name,
                                 ClientTimeFormatHelper.FormatTimeDuration(minutes.Value * 60.0)));
        }
Esempio n. 8
0
 private void ClientRemote_UnstuckQueued(double unstuckDelaySecondsTotal)
 {
     NotificationSystem.ClientShowNotification(
         NotificationUnstuckRequested_Title,
         string.Format(NotificationUnstuckRequested_MessageFormat,
                       ClientTimeFormatHelper.FormatTimeDuration(unstuckDelaySecondsTotal)));
 }
Esempio n. 9
0
        /// <summary>
        /// Initilize information about entity - invoked after all entity view Models created,
        /// so you can use links to other entity by using <see cref="EntityViewModelsManager.GetEntityViewModel" />
        /// and <see cref="EntityViewModelsManager.GetAllEntityViewModels" />.
        /// </summary>
        public override void InitInformation()
        {
            base.InitInformation();

            if (ProtoEntity is IProtoItemFood food)
            {
                EntityInformation.Add(new ViewModelEntityInformation("Stay fresh",
                                                                     food.FreshnessDuration == TimeSpan.Zero
                        ? "forever"
                        : ClientTimeFormatHelper.FormatTimeDuration(food.FreshnessDuration)));
                if (Math.Abs(food.FoodRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Food restore", food.FoodRestore));
                }
                if (Math.Abs(food.WaterRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Water restore", food.WaterRestore));
                }
                if (Math.Abs(food.HealthRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Health restore", food.HealthRestore));
                }
                if (Math.Abs(food.StaminaRestore) > 0)
                {
                    EntityInformation.Add(new ViewModelEntityInformation("Stamina restore", food.StaminaRestore));
                }
            }

            // TODO: Rework this.
            // Hardcoded information
            AddStatusEffectsInformation();
        }
Esempio n. 10
0
        private static void GetText(
            LandClaimAreasGroupPublicState publicState,
            bool canDeactivate,
            out string message,
            out string title)
        {
            var time = Api.Client.CurrentGame.ServerFrameTimeApproximated;

            switch (publicState.Status)
            {
            case ShieldProtectionStatus.Active:
            {
                var timeRemains = publicState.ShieldEstimatedExpirationTime - time;
                timeRemains = Math.Max(0, timeRemains);

                title = CoreStrings.ShieldProtection_NotificationBaseUnderShield_Title;

                message = string.Format(CoreStrings.ShieldProtection_NotificationBaseUnderShield_Message_Format,
                                        ClientTimeFormatHelper.FormatTimeDuration(
                                            timeRemains,
                                            appendSeconds: false));

                if (canDeactivate)
                {
                    message += "[br][br]"
                               + CoreStrings.ShieldProtection_NotificationBaseUnderShield_MessageOwner;
                }

                message += "[br][br]"
                           + CoreStrings.ShieldProtection_Description_2
                           + "[br]"
                           + CoreStrings.ShieldProtection_Description_3;
                break;
            }

            case ShieldProtectionStatus.Activating:
            {
                var timeRemains = publicState.ShieldActivationTime - time;
                timeRemains = Math.Max(0, timeRemains);

                title   = CoreStrings.ShieldProtection_NotificationBaseActivatingShield_Title;
                message = string.Format(
                    CoreStrings.ShieldProtection_NotificationBaseActivatingShield_Message_Format,
                    ClientTimeFormatHelper.FormatTimeDuration(timeRemains));

                if (canDeactivate)
                {
                    message += "[br][br]"
                               + CoreStrings.ShieldProtection_NotificationBaseUnderShield_MessageOwner;
                }

                break;
            }

            default:
                title   = null;
                message = null;
                break;
            }
        }
Esempio n. 11
0
        private string GetShutdownMessage()
        {
            var secondsRemains = this.GetSecondsRemains();

            return(string.Format(NotificationShutdown_MessageFormat,
                                 ClientTimeFormatHelper.FormatTimeDuration(secondsRemains),
                                 this.shutdownReasonMessage));
        }
Esempio n. 12
0
        private static string SharedGetShutdownMessage()
        {
            var secondsRemains = SharedGetSecondsRemains();

            return(string.Format(NotificationShutdown_MessageFormat,
                                 ClientTimeFormatHelper.FormatTimeDuration(secondsRemains),
                                 GetFormattedShutdownReasonMessage()));
        }
        private static void ClientRefreshCurrentUnstuckRequestStatus()
        {
            // invoke self again a second later
            ClientTimersSystem.AddAction(delaySeconds: 1,
                                         ClientRefreshCurrentUnstuckRequestStatus);

            var characterPublicState = ClientCurrentCharacterHelper.PublicState;

            if (ClientCurrentUnstuckNotification != null)
            {
                if (ClientCurrentUnstuckNotification.IsHiding)
                {
                    ClientCurrentUnstuckNotification = null;
                }
                else if (ClientCurrentUnstuckNotification.Tag != characterPublicState)
                {
                    // outdated notification
                    ClientCurrentUnstuckNotification?.Hide(quick: false);
                    ClientCurrentUnstuckNotification = null;
                }
            }

            if (characterPublicState == null)
            {
                ClientCurrentUnstuckNotification?.Hide(quick: false);
                ClientCurrentUnstuckNotification = null;
                return;
            }

            var timeRemains = characterPublicState.UnstuckExecutionTime
                              - Client.CurrentGame.ServerFrameTimeApproximated;

            if (timeRemains <= 0)
            {
                // no active unstuck requests
                ClientCurrentUnstuckNotification?.Hide(quick: false);
                ClientCurrentUnstuckNotification = null;
                return;
            }

            // has active unstuck request, create or update the notification
            var message = string.Format(NotificationUnstuckRequested_MessageFormat,
                                        ClientTimeFormatHelper.FormatTimeDuration(timeRemains));

            if (ClientCurrentUnstuckNotification == null)
            {
                ClientCurrentUnstuckNotification = NotificationSystem.ClientShowNotification(
                    NotificationUnstuckRequested_Title,
                    message,
                    autoHide: false);
                ClientCurrentUnstuckNotification.Tag = characterPublicState;
            }
            else
            {
                ClientCurrentUnstuckNotification.Message = message;
            }
        }
Esempio n. 14
0
        private static string GetNotificationText(double timeRemains)
        {
            if (timeRemains < 1)
            {
                timeRemains = 1;
            }

            return(string.Format(Notification_Message_Format,
                                 ClientTimeFormatHelper.FormatTimeDuration(timeRemains)));
        }
Esempio n. 15
0
        private void UpdateText()
        {
            if (this.IsDisposed)
            {
                return;
            }

            this.ProtectionTimeRemainingText = ClientTimeFormatHelper.FormatTimeDuration(this.timeRemaining);
            ClientTimersSystem.AddAction(1, this.UpdateText);
        }
Esempio n. 16
0
        public static void ClientDeactivateShield(ILogicObject areasGroup)
        {
            var status = SharedGetShieldPublicStatus(areasGroup);

            if (status == ShieldProtectionStatus.Inactive)
            {
                Logger.Important("The shield is already inactive");
                return;
            }

            var stackPanel = new StackPanel();

            stackPanel.Children.Add(
                DialogWindow.CreateTextElement(
                    string.Format(CoreStrings.ShieldProtection_DeactivationNotes_Format,
                                  ClientTimeFormatHelper.FormatTimeDuration(
                                      SharedCooldownDuration,
                                      appendSeconds: false)),
                    TextAlignment.Left));

            var accessRight            = FactionMemberAccessRights.BaseShieldManagement;
            var areasGroupPublicState  = LandClaimAreasGroup.GetPublicState(areasGroup);
            var hasNoFactionPermission = !string.IsNullOrEmpty(areasGroupPublicState.FactionClanTag) &&
                                         !FactionSystem.ClientHasAccessRight(accessRight);

            if (hasNoFactionPermission)
            {
                var message = FactionSystem.ClientHasFaction
                                  ? string.Format(
                    CoreStrings.Faction_Permission_Required_Format,
                    accessRight.GetDescription())
                                  : CoreStrings.Faction_ErrorDontHaveFaction;

                var textElement = DialogWindow.CreateTextElement("[br]" + message,
                                                                 TextAlignment.Left);

                textElement.Foreground = Client.UI.GetApplicationResource <Brush>("BrushColorRed6");
                textElement.FontWeight = FontWeights.Bold;
                stackPanel.Children.Add(textElement);
            }

            var dialog = DialogWindow.ShowDialog(
                CoreStrings.ShieldProtection_Dialog_ConfirmDeactivation,
                stackPanel,
                okText: CoreStrings.ShieldProtection_Button_DeactivateShield,
                okAction: () => Instance.CallServer(_ => _.ServerRemote_DeactivateShield(areasGroup)),
                cancelAction: () => { },
                focusOnCancelButton: true);

            if (hasNoFactionPermission)
            {
                dialog.ButtonOk.IsEnabled = false;
            }
        }
Esempio n. 17
0
        private static string GetNotificationText(DroppedLootInfo mark)
        {
            var secondsRemains = mark.DestroyAtTime - Api.Client.CurrentGame.ServerFrameTimeApproximated;

            if (secondsRemains < 1)
            {
                secondsRemains = 1;
            }

            return(string.Format(NotificationItemsDropped_MessageFormat,
                                 ClientTimeFormatHelper.FormatTimeDuration(
                                     secondsRemains)));
        }
Esempio n. 18
0
        private void UpdateDisplayedTimeNoTimer()
        {
            if (!this.destroyTime.HasValue)
            {
                this.DestroyTimeoutEndsTimePercent = 0;
                return;
            }

            var totalDuration        = this.protoObjectLandClaim.DestructionTimeout.TotalSeconds;
            var timeRemainingSeconds = GetTimeRemainingSeconds(this.destroyTime.Value);

            timeRemainingSeconds = MathHelper.Clamp(timeRemainingSeconds, 0, totalDuration);
            this.DestroyTimeText = ClientTimeFormatHelper.FormatTimeDuration(timeRemainingSeconds);
            this.DestroyTimeoutEndsTimePercent = (float)(100 * timeRemainingSeconds / totalDuration);
        }
        // This notification should be displayed when raiding window is just opened
        // or when player is logged in during the opened raiding window
        public static void ClientShowNotificationRaidingWindowNowOpened()
        {
            var timeUntilRaidEnds = SharedCalculateTimeUntilRaidEnds();

            if (timeUntilRaidEnds.TotalSeconds < 30)
            {
                return;
            }

            NotificationSystem.ClientShowNotification(
                CoreStrings.WindowPolitics_RaidingRestriction_Title,
                string.Format(CoreStrings.WindowPolitics_RaidingRestriction_CurrentRaidWindow,
                              ClientTimeFormatHelper.FormatTimeDuration(timeUntilRaidEnds, trimRemainder: true)),
                onClick: Menu.Open <WindowPolitics>);
        }
Esempio n. 20
0
        private void ClientRemote_ShutdownNotification(string shutdownReasonMessage, double shutdownServerTime)
        {
            var timeRemains    = shutdownServerTime - Client.CurrentGame.ServerFrameTimeRounded;
            var secondsRemains = (uint)Math.Round(timeRemains, MidpointRounding.AwayFromZero);

            Logger.Important(string.Format(NotificationShutdown_MessageFormat,
                                           ClientTimeFormatHelper.FormatTimeDuration(secondsRemains),
                                           shutdownReasonMessage));

            NotificationSystem.ClientShowNotification(
                title: NotificationShutdown_Title,
                message: string.Format(NotificationShutdown_MessageFormat,
                                       ClientTimeFormatHelper.FormatTimeDuration(secondsRemains),
                                       shutdownReasonMessage),
                color: NotificationColor.Bad,
                autoHide: false);
        }
Esempio n. 21
0
        private static void MarkerAddedHandler(NetworkSyncList <Vector2Ushort> source, int index, Vector2Ushort value)
        {
            HideLastNotification();

            var icon = Api.GetProtoEntity <ObjectPlayerLootContainer>().DefaultTexture;

            var notification = NotificationSystem.ClientShowNotification(
                title: NotificationItemsDropped_Title,
                message: string.Format(NotificationItemsDropped_MessageFormat,
                                       ClientTimeFormatHelper.FormatTimeDuration(
                                           ObjectPlayerLootContainer.AutoDestroyTimeoutSeconds)),
                color: NotificationColor.Bad,
                icon: icon,
                autoHide: false);

            lastNotification = new WeakReference <HUDNotificationControl>(notification);
        }
Esempio n. 22
0
        private void UpdateText()
        {
            if (this.IsDisposed)
            {
                return;
            }

            if (!this.isDemoVersion)
            {
                this.Visibility = Visibility.Collapsed;
                return;
            }

            this.Visibility            = Visibility.Visible;
            this.DemoTimeRemainingText = ClientTimeFormatHelper.FormatTimeDuration(this.timeRemaining);

            ClientTimersSystem.AddAction(0.333, this.UpdateText);
        }
Esempio n. 23
0
        protected override bool IsSatisfied(CharacterContext context, out string errorMessage)
        {
            var timeRemains = this.CalculateTimeRemains();
            var isSatisfied = timeRemains <= 0;

            if (isSatisfied)
            {
                errorMessage = null;
                return(true);
            }

            errorMessage = string.Format(DescriptionFormat,
                                         ClientTimeFormatHelper.FormatTimeDuration(
                                             TimeSpan.FromSeconds(this.DurationSeconds),
                                             trimRemainder: true),
                                         ClientTimeFormatHelper.FormatTimeDuration(timeRemains));
            return(false);
        }
Esempio n. 24
0
        protected override void ClientTooltipCreateControlsInternal(IItem item, List <UIElement> controls)
        {
            base.ClientTooltipCreateControlsInternal(item, controls);

            if (this.CooldownDuration > 0)
            {
                var control = ItemTooltipInfoEntryControl.Create(
                    Api.GetProtoEntity <StatusEffectMedicalCooldown>().Name,
                    ClientTimeFormatHelper.FormatTimeDuration(this.CooldownDuration));
                ((FrameworkElement)control).Margin = new Thickness(0, 7, 0, 7);
                controls.Add(control);
            }

            if (this.Effects.Count > 0)
            {
                controls.Add(ItemTooltipInfoEffectActionsControl.Create(this.Effects));
            }
        }
Esempio n. 25
0
        private static void PlayerLoginHook(string playerName, out string errorMessage)
        {
            if (ServerOperatorSystem.ServerIsOperator(playerName) ||
                ServerModeratorSystem.ServerIsModerator(playerName))
            {
                // operators/moderators cannot be blocked or kicked
                errorMessage = null;
                return;
            }

            if (IsInBlackList(playerName))
            {
                errorMessage = CannotJoinBanned;
                return;
            }

            if (IsWhiteListEnabled &&
                !WhiteList.Contains(playerName))
            {
                errorMessage = CannotJoinNotInWhitelist;
                return;
            }

            if (IsKicked(playerName,
                         out var secondsRemains,
                         out var message))
            {
                errorMessage = string.Format(CannotJoinKicked,
                                             ClientTimeFormatHelper.FormatTimeDuration(secondsRemains));

                if (!string.IsNullOrEmpty(message))
                {
                    errorMessage = message
                                   + Environment.NewLine
                                   + "[br][br]"
                                   + errorMessage;
                }

                return;
            }

            // all checks passed successfully
            errorMessage = null;
        }
        private async void RequestDecayInfoTextAsync()
        {
            var result = await LandClaimSystem.ClientGetDecayInfoText(this.landClaimWorldObject);

            if (this.IsDisposed)
            {
                return;
            }

            this.DecayInfoText = string.Format(
                DecayInfoFormat,
                ClientTimeFormatHelper.FormatTimeDuration(
                    TimeSpan.FromSeconds(result.DecayDelayDuration),
                    trimRemainder: true),
                ClientTimeFormatHelper.FormatTimeDuration(
                    TimeSpan.FromSeconds(result.DecayDuration),
                    trimRemainder: true),
                this.ViewModelProtoLandClaimInfoCurrent.CurrentStructureLandClaimDestructionTimeout);
        }
Esempio n. 27
0
            private string GetUpdatedEventNotificationText(int timeRemains)
            {
                if (this.activeEvents.Count == 0 ||
                    this.activeEvents.TrueForAll(e => e.IsDestroyed) ||
                    timeRemains < 1)
                {
                    return(string.Format("{0}[br][br][b]{1}[/b]",
                                         this.ProtoEvent.Description,
                                         ClientWorldMapEventVisualizer.Notification_ActiveEvent_Finished));
                }

                var sb = new StringBuilder(this.ProtoEvent.Description)
                         .Append("[br][br]");

                sb.AppendFormat(ClientWorldMapEventVisualizer.Notification_ActiveEvent_TimeRemainingFormat,
                                ClientTimeFormatHelper.FormatTimeDuration(timeRemains));

                return(sb.ToString());
            }
Esempio n. 28
0
        private async void ClientShowDialog(ClientItemData data)
        {
            var(cooldownDuration, cooldownRemainsSeconds)
                = await this.CallServer(_ => _.ServerRemote_GetCooldownRemainsSeconds());

            if (cooldownRemainsSeconds > 0)
            {
                // under active cooldown
                NotificationSystem.ClientShowNotification(
                    this.Name,
                    string.Format(Message_UsedRecently_Format,
                                  ClientTimeFormatHelper.FormatTimeDuration(
                                      TimeSpan.FromSeconds(
                                          Math.Max(1, cooldownRemainsSeconds)),
                                      trimRemainder: true)),
                    NotificationColor.Bad,
                    this.Icon);
            }
            else // if no active cooldown
            {
                var messageText = string.Format(Message_CannotBeUsedOften_Format,
                                                ClientTimeFormatHelper.FormatTimeDuration(
                                                    TimeSpan.FromSeconds(cooldownDuration),
                                                    trimRemainder: true));

                DialogWindow.ShowDialog(
                    string.Format(CoreStrings.Dialog_AreYouSureWantToUse_Format, this.Name),
                    messageText,
                    okAction: () =>
                {
                    if (base.ClientItemUseFinish(data))
                    {
                        this.SoundPresetItem.PlaySound(ItemSound.Use);
                    }
                },
                    cancelAction: () => { },
                    okText: this.ItemUseCaption,
                    cancelText: CoreStrings.Button_Cancel,
                    focusOnCancelButton: true);
            }
        }
Esempio n. 29
0
        private void ClientRemote_ShutdownNotification(
            string shutdownReasonMessage,
            double shutdownServerTime)
        {
            this.notification?.Hide(quick: true); // hide already existing notification

            this.shutdownReasonMessage = shutdownReasonMessage;
            this.shutdownServerTime    = shutdownServerTime;

            Logger.Important(string.Format(NotificationShutdown_MessageFormat,
                                           ClientTimeFormatHelper.FormatTimeDuration(this.GetSecondsRemains()),
                                           shutdownReasonMessage));

            this.notification = NotificationSystem.ClientShowNotification(
                title: NotificationShutdown_Title,
                message: this.GetShutdownMessage(),
                color: NotificationColor.Bad,
                autoHide: false);

            this.UpdateMessage();
        }
Esempio n. 30
0
        protected override void ClientTooltipCreateControlsInternal(IItem item, List <UIElement> controls)
        {
            base.ClientTooltipCreateControlsInternal(item, controls);

            if (this.CooldownDuration > 0)
            {
                var stackPanel = new StackPanel();
                stackPanel.Orientation = Orientation.Horizontal;

                var statusEffectMedicalCooldown = Api.GetProtoEntity <StatusEffectMedicalCooldown>();
                var icon = new Rectangle()
                {
                    Fill = Api.Client.UI.GetTextureBrush(
                        ((IProtoStatusEffect)statusEffectMedicalCooldown).Icon),
                    Width             = 26,
                    Height            = 26,
                    UseLayoutRounding = true
                };

                var controlInfoEntry = ItemTooltipInfoEntryControl.Create(
                    statusEffectMedicalCooldown.Name,
                    ClientTimeFormatHelper.FormatTimeDuration(
                        Math.Min(this.CooldownDuration, StatusEffectMedicalCooldown.MaxDuration)));
                controlInfoEntry.Margin            = new Thickness(4, 0, 0, -5);
                controlInfoEntry.VerticalAlignment = VerticalAlignment.Center;
                controlInfoEntry.Foreground
                      = controlInfoEntry.ValueBrush
                      = Api.Client.UI.GetApplicationResource <Brush>("BrushColorAltLabelForeground");

                stackPanel.Children.Add(icon);
                stackPanel.Children.Add(controlInfoEntry);
                stackPanel.Margin = new Thickness(0, 7, 0, 7);
                controls.Add(stackPanel);
            }

            if (this.Effects.Count > 0)
            {
                controls.Add(ItemTooltipInfoEffectActionsControl.Create(this.Effects));
            }
        }