Example #1
0
        /// <summary>
        /// OnNewMessage runs before the message can be found in the stack. So we try to get
        /// rid of it here Mostly copied from https://github.com/mabako/reddit-for-city-skylines/
        /// </summary>
        public override void OnUpdate()
        {
            // If there's no message to remove, continue on
            if (_messageRemovalTarget == null)
                return;

            if (ChirpPanel.instance == null) 
                return;

            // This code is roughly based on the work by Juuso "Zuppi" Hietala.
            // Get the Chirper container, where all of the chirps reside
            var container = ChirpPanel.instance.transform.Find("Chirps").Find("Clipper").Find("Container").gameObject.transform;
            for (var i = 0; i < container.childCount; ++i)
            {
                // Keep looping until we get the one we want. It should pretty much be the very first one we snag every time, on very rare
                // occurence the second one
                if (!container.GetChild(i).GetComponentInChildren<UILabel>().text.Equals(_messageRemovalTarget.GetText()))
                    continue;

                // Remove the message
                UITemplateManager.RemoveInstance("ChirpTemplate", container.GetChild(i).GetComponent<UIPanel>());
                MessageManager.instance.DeleteMessage(_messageRemovalTarget);

                // We're done here
                _messageRemovalTarget = null;

                break;
            }
        }
        // Custom method to delete a single message - uses ChirpMessages.
        private void DeleteMessage(ChirpMessage message)
        {
            // Get container for chirps
            Transform container = chirpPane.transform.FindChild("Chirps").FindChild("Clipper").FindChild("Container").gameObject.transform;

            for (int i = 0; i < container.childCount; ++i)
            {
                if (container.GetChild(i).GetComponentInChildren <UILabel>().text.Equals(message.GetText()))
                {
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "[SuperChirper] Deleted Message:" + message.text);
                    // Remove both visual and internal message.
                    UITemplateManager.RemoveInstance("ChirpTemplate", container.GetChild(i).GetComponent <UIPanel>());

                    // Find the original message, remove it from manager.
                    IChirperMessage delMessage;
                    messageMap.TryGetValue(message, out delMessage);
                    messageManager.DeleteMessage(delMessage);


                    if (!userOpened)
                    {
                        chirpPane.Collapse();
                    }
                    return;
                }
            }
        }
 public void OnClick(UIComponent comp, UIMouseEventParameter p)
 {
     if (p != null && p.source is UIButton && p.source.name == "Remove")
     {
         if (Singleton <SimulationManager> .exists && Singleton <MessageManager> .exists)
         {
             Singleton <SimulationManager> .instance.AddAction(this.SimulationDeleteMessage((MessageBase)p.source.parent.objectUserData));
         }
         UITemplateManager.RemoveInstance(kChirpTemplate, p.source.parent);
         if (this.m_Container.childCount == 0)
         {
             this.Hide();
         }
     }
 }
Example #4
0
 public void OnUpdate()
 {
     if (!chirperDestroyed)
     {
         if (recentMessages.Count != 0)
         {
             if (recentMessages[0].filtered)
             {
                 cpanel.Collapse();
                 cpanel.m_NotificationSound = soundStore;
                 if (chirpContainer.transform.childCount > 0)
                 {
                     for (int i = 0; i < chirpContainer.transform.childCount; i++)
                     {
                         if (chirpContainer.transform.GetChild(i).GetComponentInChildren <UILabel>().text.Equals(recentMessages[0].chirpmessagetext))
                         {
                             UITemplateManager.RemoveInstance("ChirpTemplate", chirpContainer.transform.GetChild(i).GetComponent <UIPanel>());
                             messageManager.DeleteMessage(recentMessages[0].cm);
                             recentMessages.RemoveAt(0);
                             break;
                         }
                     }
                 }
                 else
                 {
                     recentMessages.RemoveAt(0);
                 }
             }
             else
             {
                 if (chirpContainer.transform.childCount > 0)
                 {
                     for (int i = 0; i < chirpContainer.transform.childCount; i++)
                     {
                         if (chirpContainer.transform.GetChild(i).GetComponentInChildren <UILabel>().text.Equals(recentMessages[0].chirpmessagetext))
                         {
                             chirpContainer.transform.GetChild(i).GetComponentInChildren <UILabel>().text = module.removeTwitterness(recentMessages[0].chirpmessagetext);
                             break;
                         }
                     }
                 }
                 recentMessages.RemoveAt(0);
             }
         }
     }
 }
        // In development - not used!
        private void ReplaceMessage(ChirpMessage delMessage, ChirpMessage replaceMessage)
        {
            // Get container for chirps
            Transform container = chirpPane.transform.FindChild("Chirps").FindChild("Clipper").FindChild("Container").gameObject.transform;

            for (int i = 0; i < container.childCount; ++i)
            {
                if (container.GetChild(i).GetComponentInChildren <UILabel>().text.Equals(delMessage.GetText()))
                {
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "[SuperChirper] Replaced Message:" + delMessage.text);
                    // Remove both visual and internal message.
                    UITemplateManager.RemoveInstance("ChirpTemplate", container.GetChild(i).GetComponent <UIPanel>());
                    chirpPane.AddMessage(replaceMessage, true);

                    // Find the original message, replace it in manager.
                    MessageBase[] messages = (MessageBase[])typeof(MessageManager).GetField("m_recentMessages", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(MessageManager.instance);

                    for (int j = 0; j < messages.Length; ++j)
                    {
                        if (messages[i].text.Equals(delMessage))
                        {
                            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "[SuperChirper] New Message:" + delMessage.text);
                            messages[i] = replaceMessage;
                        }
                    }

                    //DEBUGGING
                    MessageBase[] finalMessages = (MessageBase[])typeof(MessageManager).GetField("m_recentMessages", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(MessageManager.instance);
                    foreach (MessageBase message in finalMessages)
                    {
                        DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "[SuperChirper] Final Message:" + message.text);
                    }
                    return;
                }
            }
        }
Example #6
0
 private void RemoveButton(UIButton button, UIComponent parent)
 {
     button.eventClick -= Click;
     parent.RemoveUIComponent(button);
     UITemplateManager.RemoveInstance(button.text, parent);
 }