/// <summary> /// Creates an inbox message. New unread messages will be visible by an inventory screen icon until opened. /// Past messages can be viewed. /// </summary> /// <param name="which">Identifier of a given message. Overrides messages with the given identifier.</param> /// <param name="msg">Message body. Plain text only, for now.</param> /// <param name="forceUnread">If the message has been read, this will force it to be "unread" again.</param> /// <param name="onRun">Code to activate when a given message is read. Parameter `true` if message is unread.</param> public static void SetMessage(string which, string msg, bool forceUnread, Action <bool> onRun = null) { LoadHooks.AddPostWorldLoadOnceHook(() => { 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); }); }
private void InitializeWithSync(NPC npc) { if (this.AwaitsInitialization || this.IsInitialized || !ElementsNPC.CanHaveElements(npc)) { return; } this.AwaitsInitialization = true; LoadHooks.AddPostWorldLoadOnceHook(() => { this.IsInitialized = true; this.AwaitsInitialization = false; if (ElementsAPI.PreNPCInitialize(npc)) { if (this.AutoInitializeElement(npc)) { if (Main.netMode == 2) { NPCElementsProtocol.Broadcast(npc.whoAmI); } else { this.InitializeColorAnimation(); } } } }); }