private static (Brush background, Brush border) GetBrush(NotificationColor notificationColor)
        {
            Brush background;
            Brush border;

            switch (notificationColor)
            {
            case NotificationColor.Neutral:
                background = BrushBackgroundNeutral.Value;
                border     = BrushBorderNeutral.Value;
                break;

            case NotificationColor.Good:
                background = BrushBackgroundGood.Value;
                border     = BrushBorderGood.Value;
                break;

            case NotificationColor.Bad:
                background = BrushBackgroundBad.Value;
                border     = BrushBorderBad.Value;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(notificationColor), notificationColor, null);
            }

            return(background, border);
        }
示例#2
0
        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)
        {
            Api.ValidateIsClient();
            var(brushBackground, brushBorder) = GetBrush(color);
            var soundToPlay = playSound
                                  ? GetSound(color)
                                  : null;

            return(HUDNotificationsPanelControl.Show(
                       title,
                       message,
                       brushBackground,
                       brushBorder,
                       icon,
                       onClick,
                       autoHide,
                       soundToPlay));
        }
示例#3
0
        public Notification getNotification(bool generateHaveToAct)
        {
            int  sourceIndex = random.Next(0, sourcesNumber);
            bool isSilent    = random.Next(0, 2) == 0;

            if (generateHaveToAct)
            {
                sourceIndex = mapNameToIndex();
                isSilent    = false;
            }
            string             id = Guid.NewGuid().ToString();
            NotificationSource notificationSource = (NotificationSource)Enum.GetValues(typeof(NotificationSource)).GetValue(sourceIndex);
            string             sourceName         = EnumDescription.getDescription(notificationSource);
            NotificationImage  notificationImage  = (NotificationImage)Enum.GetValues(typeof(NotificationImage)).GetValue(sourceIndex);
            string             sourceImage        = EnumDescription.getDescription(notificationImage);
            NotificationColor  notificationColor  = (NotificationColor)Enum.GetValues(typeof(NotificationColor)).GetValue(sourceIndex);
            Color sourceColor = EnumDescription.getColor(EnumDescription.getDescription(notificationColor));
            Array values      = Enum.GetValues(typeof(NotificationAuthor));
            int   authorIndex = random.Next(values.Length);

            if (generateHaveToAct)
            {
                authorIndex = mapAuthorToIndex();
            }
            NotificationAuthor notificationAuthor = (NotificationAuthor)values.GetValue(authorIndex);
            string             author             = EnumDescription.getDescription(notificationAuthor);

            values = Enum.GetValues(typeof(NotificationIcon));
            NotificationIcon notificationIcon = (NotificationIcon)values.GetValue(authorIndex);
            string           icon             = EnumDescription.getDescription(notificationIcon);
            string           text;

            if (sourceIndex == 2 || sourceIndex == 3) // post or youtube
            {
                values = Enum.GetValues(typeof(NotificationHeader));
                NotificationHeader notificationHeader = (NotificationHeader)values.GetValue(random.Next(values.Length));
                text = EnumDescription.getDescription(notificationHeader);
            }
            else // messengers
            {
                values = Enum.GetValues(typeof(NotificationText));
                NotificationText notificationText = (NotificationText)values.GetValue(random.Next(values.Length));
                text = EnumDescription.getDescription(notificationText);
            }
            if (isSilent)
            {
                sourceColor = EnumDescription.getColor(EnumDescription.getDescription(NotificationColor.Silent));
                sourceImage = "_silent_";
            }
            long         timestamp    = DateTime.Now.Ticks;
            Notification notification = new Notification(id, sourceImage, sourceName, author, icon, text, timestamp, isSilent, sourceColor, generateHaveToAct);

            Debug.Log(string.Format("Notification which is {0} and has the following data: {1} was created", generateHaveToAct ? "correct" : "incorrect", notification));
            return(notification);
        }
 public static void ServerSendNotification(
     ICharacter character,
     string title,
     string message,
     NotificationColor color,
     string iconTextureLocalPath = null,
     bool autoHide = true)
 {
     Instance.CallClient(
         character,
         _ => _.ClientRemote_ShowNotification(title, message, color, iconTextureLocalPath, autoHide));
 }
 private void ClientRemote_ShowNotification(
     string title,
     string message,
     NotificationColor color,
     string iconTextureLocalPath,
     bool autoHide)
 {
     ClientShowNotification(
         title,
         message,
         color,
         icon: iconTextureLocalPath != null
                   ? new TextureResource(iconTextureLocalPath)
                   : null,
         autoHide: autoHide);
 }
        private static SoundResource GetSound(NotificationColor color)
        {
            switch (color)
            {
            case NotificationColor.Neutral:
                return(SoundResourceNeutral);

            case NotificationColor.Good:
                return(SoundResourceGood);

            case NotificationColor.Bad:
                return(SoundResourceBad);

            default:
                throw new ArgumentOutOfRangeException(nameof(color), color, null);
            }
        }
        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);
        }
示例#8
0
 public void SetColor(NotificationColor color)
 {
     _color = color;
 }
示例#9
0
 /// <summary>
 /// Get Color Name
 /// </summary>
 /// <param name="jsonColor"></param>
 /// <returns>string</returns>
 public static string ToColorName(this NotificationColor jsonColor) => jsonColor.ToString().ToLower();
	public void SetColor(NotificationColor color) {
		_color = color;
	}