private void TryCreateNotification() { if (this.notification != null) { return; } var timeRemains = this.CalculateEventTimeRemains(); if (timeRemains <= 0) { return; } if (!(this.notification is null)) { // notification already exist return; } // notify player about the new event this.notification = NotificationSystem.ClientShowNotification( ClientWorldMapEventVisualizer.Notification_ActiveEvent_Title, this.GetUpdatedEventNotificationText(timeRemains), icon: this.ProtoEvent.Icon, autoHide: false, playSound: false); this.RefreshNotification(); ClientEventSoundHelper.PlayEventStartedSound(); }
internal void RefreshRaidedState() { var isRaidedNow = LandClaimSystem.SharedIsAreasGroupUnderRaid(this.areasGroup); if (this.lastIsRaided == isRaidedNow) { // no changes return; } // remove outdated notifications (if exists) this.RemoveRaidNotification(); this.lastIsRaided = isRaidedNow; if (!this.lastIsRaided) { return; } // was not raided, is raided now var worldPosition = LandClaimSystem.SharedGetLandClaimGroupCenterPosition(this.areasGroup); var positionText = WorldMapSectorHelper.FormatWorldPositionWithSectorCoordinate(worldPosition); var title = ClientWorldMapLandClaimsGroupVisualizer.NotificationBaseUnderAttack_Title; var message = ClientWorldMapLandClaimsGroupVisualizer.NotificationBaseUnderAttack_Message; message += "[br]" + positionText; this.raidNotification = NotificationSystem.ClientShowNotification( title, message, NotificationColor.Bad, autoHide: false, icon: TextureIconRaidNotification); }
private void ClientCurrentCharacterIdleStateChangedHandler() { if (!ClientIsCurrentPlayerIdle) { this.clientNotificationIsIdle?.Hide(quick: true); this.clientNotificationIsIdle = null; return; } // idle player if (this.clientNotificationIsIdle != null && !this.clientNotificationIsIdle.IsHiding) { return; } this.clientNotificationIsIdle = NotificationSystem.ClientShowNotification( title: Notification_PlayerIdle_Title, message: Notification_PlayerIdle_Message_Part1 + "[br]" + Notification_PlayerIdle_Message_Part2 + "[br]" + Notification_PlayerIdle_Message_Part3, color: NotificationColor.Good, autoHide: false, playSound: false); }
private void NotificationSystem_ClientNotificationDisplayed(HudNotificationControl obj) { if (obj == null || string.IsNullOrEmpty(obj.Message)) { return; } this.AddMarkerFromMessage(obj.Message, true); }
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; } }
private void RemoveRaidNotification() { this.raidNotification?.Hide(quick: true); this.raidNotification = null; if (this.markRaidControl is null) { return; } this.worldMapController.RemoveControl(this.markRaidControl); this.markRaidControl = null; }
private static void ClientSaveScheduledHandler(double scheduledTime) { serverSaveScheduledTime = scheduledTime; notificationControl?.Hide(quick: true); notificationControl = null; notificationControl = NotificationSystem.ClientShowNotification( CoreStrings.AutosaveNotification_Title, NotificationMessageBaseText, NotificationColor.Neutral, icon: TextureResourceIconSave, autoHide: false); UpdateNotificationControlText(); }
private void RefreshRaidedState() { var isRaidedNow = LandClaimSystem.SharedIsAreasGroupUnderRaid(this.areasGroup); if (this.isRaided == isRaidedNow) { // no changes return; } // remove outdated notifications (if exists) this.RemoveRaidNotification(); this.isRaided = isRaidedNow; if (!this.isRaided) { return; } // was not raided, is raided now var worldPosition = this.GetAreasGroupWorldPosition(); // add raid mark control to map this.markRaidControl = new WorldMapMarkRaid(); var canvasPosition = this.GetAreasGroupCanvasPosition(worldPosition); Canvas.SetLeft(this.markRaidControl, canvasPosition.X); Canvas.SetTop(this.markRaidControl, canvasPosition.Y); Panel.SetZIndex(this.markRaidControl, 11); this.worldMapController.AddControl(this.markRaidControl); // show notification message var localPosition = worldPosition.ToVector2Ushort() - Api.Client.World.WorldBounds.Offset; this.raidNotification = NotificationSystem.ClientShowNotification( NotificationBaseUnderAttack_Title, string.Format(NotificationBaseUnderAttack_MessageFormat, localPosition.X, localPosition.Y), NotificationColor.Bad, autoHide: false, icon: Api.GetProtoEntity <ItemBombModern>().Icon); // start refresh timer ClientTimersSystem.AddAction(delaySeconds: 1, this.RaidRefreshTimerCallback); }
private static void ClientSaveFinishedHandler() { var control = notificationControl; if (control is null) { return; } notificationControl = null; serverSaveScheduledTime = null; control.Message = NotificationMessageBaseText + CoreStrings.AutosaveNotification_Completed; ClientTimersSystem.AddAction(2, () => control.Hide(quick: false)); }
public static HudNotificationControl ClientShowNotification( string title, string message = null, NotificationColor color = NotificationColor.Neutral, ITextureResource icon = null, Action onClick = null, bool autoHide = true, bool playSound = true, bool writeToLog = true) { Api.ValidateIsClient(); var(brushBackground, brushBorder) = GetBrush(color); var soundToPlay = playSound ? GetSound(color) : null; if (writeToLog) { Api.Logger.Important( string.Format( "Showing notification:{0}Title: {1}{0}Message: {2}", Environment.NewLine, title, message)); } var notificationControl = HudNotificationControl.Create( title, message, brushBackground, brushBorder, icon, onClick, autoHide, soundToPlay); HudNotificationsPanelControl.ShowNotificationControl(notificationControl); Api.SafeInvoke(() => ClientNotificationDisplayed?.Invoke(notificationControl)); return(notificationControl); }
private static void Refresh() { var position = ClientCurrentCharacterHelper.Character?.TilePosition ?? Vector2Ushort.Zero; var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(position, addGracePadding: false) ?? LandClaimSystem.SharedGetLandClaimAreasGroup(position, addGracePadding: true); var lastRaidTime = areasGroup is not null ? LandClaimAreasGroup.GetPublicState(areasGroup).LastRaidTime ?? double.MinValue : double.MinValue; var time = Api.Client.CurrentGame.ServerFrameTimeRounded; var timeSinceRaidStart = time - lastRaidTime; var timeRemainsToRaidEnd = LandClaimSystemConstants.SharedRaidBlockDurationSeconds - timeSinceRaidStart; timeRemainsToRaidEnd = Math.Max(timeRemainsToRaidEnd, 0); if (timeRemainsToRaidEnd <= 0) { // no raid here - hide notification currentNotification?.Hide(quick: true); currentNotification = null; return; } // raid here, display/update notification var text = GetNotificationText(timeRemainsToRaidEnd); if (currentNotification is not null && !currentNotification.IsHiding) { currentNotification.Message = text; return; } currentNotification = NotificationSystem.ClientShowNotification( title: Notification_Title, message: text, autoHide: false, // TODO: add custom icon here, currently we're using a placeholder icon icon: Api.GetProtoEntity <ItemBombModern>().Icon, playSound: false); }
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(); }
private void ClientRemote_ShutdownNotification( string message, double serverTime) { this.clientNotification?.Hide(quick: true); // hide already existing notification sharedShutdownReasonMessageRaw = message; sharedServerShutdownServerTime = serverTime; Logger.Important( string.Format(NotificationShutdown_MessageFormat, ClientTimeFormatHelper.FormatTimeDuration(SharedGetSecondsRemains()), GetFormattedShutdownReasonMessage())); this.clientNotification = NotificationSystem.ClientShowNotification( title: SharedGetShutdownNotificationTitle(), message: SharedGetShutdownMessage(), color: NotificationColor.Bad, autoHide: false); this.ClientUpdateMessage(); }
private static void UpdateNotification(DroppedLootInfo mark, HudNotificationControl notification) { if (notification.IsHiding) { return; } var timeRemains = mark.DestroyAtTime - Api.Client.CurrentGame.ServerFrameTimeApproximated; if (timeRemains <= 0) { notification.Hide(quick: false); return; } notification.Message = GetNotificationText(mark); // schedule recursive update in a second ClientTimersSystem.AddAction( delaySeconds: 1, () => UpdateNotification(mark, notification)); }
private static void Refresh() { var areasGroup = GetAreasGroupNearPlayerCharacter(); if (areasGroup is null) { currentNotification?.Hide(quick: true); currentNotification = null; return; } var publicState = LandClaimAreasGroup.GetPublicState(areasGroup); if (publicState.Status == ShieldProtectionStatus.Inactive) { currentNotification?.Hide(quick: true); currentNotification = null; return; } var isOwner = IsOwner(areasGroup); if (currentNotification is null || currentNotification.IsHiding) { currentNotification = CreateNotification(); } GetText(publicState, canDeactivate: isOwner, out var message, out var title); currentNotification.Title = title; currentNotification.Message = message; }
private static void Refresh() { var areasGroup = GetAreasGroupNearPlayerCharacter(); if (areasGroup is null) { currentNotification?.Hide(quick: true); currentNotification = null; return; } var status = LandClaimAreasGroup.GetPublicState(areasGroup).Status; if (status == ShieldProtectionStatus.Inactive) { currentNotification?.Hide(quick: true); currentNotification = null; return; } var isOwner = IsOwner(areasGroup); if (currentNotification is null || currentNotification.IsHiding) { currentNotification = CreateNotification(); } var publicState = LandClaimAreasGroup.GetPublicState(areasGroup); var time = Api.Client.CurrentGame.ServerFrameTimeApproximated; string message, title; if (status == ShieldProtectionStatus.Active) { var timeRemains = publicState.ShieldEstimatedExpirationTime - time; title = CoreStrings.ShieldProtection_NotificationBaseUnderShield_Title; message = string.Format(CoreStrings.ShieldProtection_NotificationBaseUnderShield_Message_Format, ClientTimeFormatHelper.FormatTimeDuration(timeRemains, appendSeconds: false)); if (isOwner) { message += "[br][br]" + CoreStrings.ShieldProtection_NotificationBaseUnderShield_MessageOwner; } message += "[br][br]" + CoreStrings.ShieldProtection_Description_2 + "[br]" + CoreStrings.ShieldProtection_Description_3; } else // 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 (isOwner) { message += "[br][br]" + CoreStrings.ShieldProtection_NotificationBaseUnderShield_MessageOwner; } } currentNotification.Title = title; currentNotification.Message = message; }
private void RemoveRaidNotification() { this.lastIsRaided = false; this.raidNotification?.Hide(quick: true); this.raidNotification = null; }
private static void ConnectionStateChangedHandler() { notificationControl?.Hide(quick: true); notificationControl = null; }