コード例 #1
0
        public static void SetMessage(string which, string msg, bool forceUnread, Action <bool> onRun = null)
        {
            Promises.Promises.AddPostWorldLoadOncePromise(() => {
                InboxMessages inbox = ModHelpersMod.Instance.Inbox?.Messages;
                if (inbox == null)
                {
                    LogHelpers.Warn("Inbox or Inbox.Messages is null");
                    return;
                }

                int idx = inbox.Order.IndexOf(which);

                inbox.Messages[which]       = msg;
                inbox.MessageActions[which] = onRun;

                if (idx >= 0)
                {
                    if (forceUnread)
                    {
                        if (idx < inbox.Current)
                        {
                            inbox.Current--;
                        }

                        inbox.Order.Remove(which);
                        inbox.Order.Add(which);
                    }
                }
                else
                {
                    inbox.Order.Add(which);
                }
//LogHelpers.Log("which:"+which+", curr:"+inbox.Current+", pos:"+inbox.Order.IndexOf( which )+", forced:"+force_unread);
            });
        }
コード例 #2
0
        public static string ReadMessage(string which)
        {
            InboxMessages inbox = ModHelpersMod.Instance.Inbox.Messages;

            int idx = inbox.Order.IndexOf(which);

            if (idx == -1)
            {
                return(null);
            }

            string msg = null;

            if (!inbox.Messages.TryGetValue(which, out msg))
            {
                return(null);
            }

            bool isUnread = idx >= inbox.Current;

            inbox.MessageActions[which]?.Invoke(isUnread);

            if (isUnread)
            {
                if (inbox.Current != idx)
                {
                    inbox.Order.RemoveAt(idx);
                    inbox.Order.Insert(inbox.Current, which);
                }
                inbox.Current++;
            }

            return(msg);
        }
コード例 #3
0
        public static string ReadMessage(string which)
        {
            InboxMessages inbox = HamstarHelpersMod.Instance.Inbox.Messages;

            int idx = inbox.Order.IndexOf(which);

            if (idx == -1)
            {
                return(null);
            }

            string msg       = inbox.Messages[which];
            bool   is_unread = idx >= inbox.Current;

            inbox.MessageActions[which]?.Invoke(is_unread);

            if (is_unread)
            {
                if (inbox.Current != idx)
                {
                    inbox.Order.RemoveAt(idx);
                    inbox.Order.Insert(inbox.Current, which);
                }
                inbox.Current++;
            }

            return(msg);
        }
コード例 #4
0
        public static int CountUnreadMessages()
        {
            InboxMessages inbox = ModHelpersMod.Instance.Inbox?.Messages;

            if (inbox == null)
            {
                return(0);
            }

            return(inbox.Messages.Count - inbox.Current);
        }
コード例 #5
0
        public static string DequeueMessage()
        {
            InboxMessages inbox = HamstarHelpersMod.Instance.Inbox.Messages;

            if (inbox.Current >= inbox.Order.Count)
            {
                return(null);
            }

            string which = inbox.Order[inbox.Current++];
            string msg   = inbox.Messages[which];

            inbox.MessageActions[which]?.Invoke(true);

            return(msg);
        }
コード例 #6
0
        public static string DequeueMessage()
        {
            InboxMessages inbox = ModHelpersMod.Instance.Inbox.Messages;

            if (inbox.Current >= inbox.Order.Count)
            {
                return(null);
            }

            string which = inbox.Order[inbox.Current++];
            string msg   = null;

            if (inbox.Messages.TryGetValue(which, out msg))
            {
                inbox.MessageActions[which]?.Invoke(true);
            }

            return(msg);
        }
コード例 #7
0
        public static string GetMessageAt(int idx, out bool is_unread)
        {
            InboxMessages inbox = HamstarHelpersMod.Instance.Inbox.Messages;

            is_unread = false;

            if (idx < 0 || idx >= inbox.Order.Count)
            {
                return(null);
            }

            string which = inbox.Order[idx];
            string msg   = inbox.Messages[which];

            is_unread = idx >= inbox.Current;

            inbox.MessageActions[which]?.Invoke(is_unread);

            return(msg);
        }
コード例 #8
0
        public static string GetMessageAt(int idx, out bool isUnread)
        {
            InboxMessages inbox = ModHelpersMod.Instance.Inbox.Messages;

            isUnread = false;

            if (idx < 0 || idx >= inbox.Order.Count)
            {
                return(null);
            }

            string which = inbox.Order[idx];
            string msg   = null;

            if (inbox.Messages.TryGetValue(which, out msg))
            {
                isUnread = idx >= inbox.Current;
                inbox.MessageActions[which]?.Invoke(isUnread);
            }

            return(msg);
        }
コード例 #9
0
        public static int CountUnreadMessages()
        {
            InboxMessages inbox = HamstarHelpersMod.Instance.Inbox.Messages;

            return(inbox.Messages.Count - inbox.Current);
        }