123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- struct TweetBufferData
- {
- public string messageText;
- public string senderName;
- public string userName;
- public string hastags;
- public string followersTxt;
- public Sprite avatarImage;
- }
- public class TweetePrefabeControler : GameNotification
- {
- public static event Action AddTweetToPhone;
- [SerializeField] private Image SenderAvatar;
- [SerializeField] private Text TweetText;
- [SerializeField] private Text SenderName;
- [SerializeField] private Text UserName;
- [SerializeField] private Text HashTags;
- [SerializeField] private Text NumberOfFollowers;
- [SerializeField] private Animator animator;
- [SerializeField] private GameObject AcceptBTN;
- [SerializeField] private GameObject Followers;
- string TweedID;
- private List<TweetBufferData> tweetBuffer;
- public void SetTweet(string _tweetText, string _senderName, string _userName, string _hashtags, int _numberOfFollow, Sprite _face = null, bool inQueue = false)
- {
- Debug.LogError("SetTweet");
-
- SenderName.text = _senderName;
- UserName.text = _userName;
- HashTags.text = _hashtags;
- NumberOfFollowers.text = "";
- if (NumberOfFollowers.transform.parent.gameObject.activeSelf)
- {
- NumberOfFollowers.transform.parent.gameObject.SetActive(false);
- }
- bool hasFollowers = _numberOfFollow != 0;
- string follow_t = "";
- if (hasFollowers)//To show correct number of new followers if it negative
- {
- NumberOfFollowers.text = follow_t = ((_numberOfFollow < 0) ? "" : "+") + _numberOfFollow.ToString();
- if (!NumberOfFollowers.transform.parent.gameObject.activeSelf)
- {
- NumberOfFollowers.transform.parent.gameObject.SetActive(true);
- }
- }
-
- SenderAvatar.sprite = _face;
- TweetText.text = ChangeTweet(_tweetText);
- if(!inQueue)
- {
- RegisterNotification();
- SaveToBuffer(ChangeTweet(_tweetText), _senderName, _userName, _hashtags, follow_t, _face);
- }
-
- }
- private void SaveToBuffer(string txt, string sender, string name, string htags, string follow, Sprite ava)
- {
- TweetBufferData tbd = new TweetBufferData();
- tbd.messageText = txt;
- tbd.senderName = sender;
- tbd.userName = name;
- tbd.followersTxt = follow;
- tbd.hastags = htags;
- tbd.avatarImage = ava;
- if (tweetBuffer == null)
- {
- tweetBuffer = new List<TweetBufferData>();
- }
- tweetBuffer.Add(tbd);
- }
- private void ReadFirstInBuffer()
- {
- if (tweetBuffer != null)
- {
- if (tweetBuffer.Count > 0)
- {
- TweetBufferData tbd = tweetBuffer[0];
- SenderAvatar.sprite = tbd.avatarImage;
- SenderName.text = tbd.senderName;
- UserName.text = tbd.userName;
- HashTags.text = tbd.hastags;
- TweetText.text = tbd.messageText;
- NumberOfFollowers.text = tbd.followersTxt;
- NumberOfFollowers.transform.parent.gameObject.SetActive(tbd.followersTxt.Length>0);
- tweetBuffer.RemoveAt(0);
- }
- else
- {
- Debug.LogWarning("Tweet buffer empty when reading");
- }
- }
-
- }
- public string ChangeTweet(string _text)
- {
- string text = _text;
- if (_text.Contains("1 hours"))
- text = _text.Replace("1 hours", "1 hour");
- text = ChangeStrings.ChangeText(text);
- return text;
- }
- public void TurnTweetOff()
- {
- gameObject.SetActive(false);
- }
- public void PauseAnimation()
- {
- if (animator != null)
- {
- animator.enabled = false;
- StartCoroutine(ResumeAnimAfterDelay(8.0f));
- }
- }
- public void ResumeAnimation()
- {
- if (animator != null)
- animator.enabled = true;
- }
- private bool PhoneIsntActive()
- {
- bool result = !WebTools.Phone.PanelPhoneBehaviour.Instance.gameObject.activeSelf;
- return result;
- }
- IEnumerator ResumeAnimAfterDelay(float delay)
- {
- yield return new WaitUntil(PhoneIsntActive);
- yield return new WaitForSeconds(delay);
- if (animator != null)
- {
- if(!animator.enabled)
- {
- animator.enabled = true;
- }
- }
- }
-
- }
|