|
@@ -0,0 +1,231 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using TMPro;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.UI;
|
|
|
+
|
|
|
+public class MailUIContent : MonoSingleton<MailUIContent>
|
|
|
+{
|
|
|
+
|
|
|
+ public MailUIItem mailItem;
|
|
|
+
|
|
|
+ public Transform uiContent;
|
|
|
+
|
|
|
+ public ScrollRect scrollRect;
|
|
|
+ public RectTransform contentPanel;
|
|
|
+ public RectTransform sampleListItem;
|
|
|
+ public HorizontalLayoutGroup HLG;
|
|
|
+
|
|
|
+ public Button leftNextBtn;
|
|
|
+ public Button rightNextBtn;
|
|
|
+ public Button delBtn;
|
|
|
+
|
|
|
+ public TMP_Text page;
|
|
|
+ public TMP_Text titleName;
|
|
|
+ public TMP_Text errorMsg;
|
|
|
+ public TMP_Text levelText;
|
|
|
+ public TMP_Text timeText;
|
|
|
+ public Image levelImage;
|
|
|
+
|
|
|
+ public GameObject mailUI;
|
|
|
+
|
|
|
+ public float snapFore;
|
|
|
+ float snapSpeed = 0;
|
|
|
+ bool isSnapped;
|
|
|
+ public int currentItem;
|
|
|
+
|
|
|
+ public GameObject unread;
|
|
|
+ public TMP_Text unreadText;
|
|
|
+ public float unreadNum;
|
|
|
+
|
|
|
+ public GameObject ShowMailUIColor;
|
|
|
+ public GameObject ShowImagePoint;
|
|
|
+
|
|
|
+ public GameObject CloseSync;
|
|
|
+
|
|
|
+ public GameObject MailShow;
|
|
|
+ public GameObject MailNull;
|
|
|
+
|
|
|
+ LangChaoMailItem nowItem;
|
|
|
+
|
|
|
+
|
|
|
+ private void Start()
|
|
|
+ {
|
|
|
+ unreadNum = 0;
|
|
|
+ LangChaoMailManager.Instance.mailUIItem = mailItem;
|
|
|
+ LangChaoMailManager.Instance.mailContent = uiContent;
|
|
|
+ LangChaoMailManager.Instance.showImagePoint = ShowImagePoint.transform;
|
|
|
+ leftNextBtn.onClick.AddListener(()=> { NetPage(true);});
|
|
|
+ rightNextBtn.onClick.AddListener(() => { NetPage(false);});
|
|
|
+ delBtn.onClick.AddListener(() => { DelItem(); });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void Update()
|
|
|
+ {
|
|
|
+ currentItem = Mathf.RoundToInt((0 - contentPanel.localPosition.x / (sampleListItem.rect.width + HLG.spacing)));
|
|
|
+
|
|
|
+ if (scrollRect.velocity.magnitude < 200&& !isSnapped)
|
|
|
+ {
|
|
|
+ scrollRect.velocity = Vector2.zero;
|
|
|
+ snapSpeed += snapFore * Time.deltaTime;
|
|
|
+ contentPanel.localPosition = new Vector3(Mathf.MoveTowards(contentPanel.localPosition.x, 0 - (currentItem * (sampleListItem.rect.width + HLG.spacing)), snapSpeed), contentPanel.localPosition.y,contentPanel.localPosition.z);
|
|
|
+ if (contentPanel.localPosition.x == 0 - (currentItem * (sampleListItem.rect.width + HLG.spacing)))
|
|
|
+ {
|
|
|
+ isSnapped = false;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LangChaoMailManager.Instance.listMailItem.Count > currentItem && mailUI.activeSelf)
|
|
|
+ {
|
|
|
+ if (nowItem != LangChaoMailManager.Instance.listMailItem[currentItem])
|
|
|
+ {
|
|
|
+ nowItem = LangChaoMailManager.Instance.listMailItem[currentItem];
|
|
|
+ UpdateUI();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(scrollRect.velocity.magnitude > 200)
|
|
|
+ {
|
|
|
+ isSnapped = false;
|
|
|
+
|
|
|
+ snapSpeed = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void UpdateUI()
|
|
|
+ {
|
|
|
+ UpdatePage();
|
|
|
+
|
|
|
+
|
|
|
+ System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
|
|
|
+ System.DateTime dt = startTime.AddMilliseconds(nowItem.timestamp);
|
|
|
+
|
|
|
+ timeText.text = dt.Year + "-" + dt.Month + "-" + dt.Day + " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second;
|
|
|
+
|
|
|
+ if (nowItem.title != null)
|
|
|
+ {
|
|
|
+ levelText.gameObject.SetActive(true);
|
|
|
+ levelImage.gameObject.SetActive(true);
|
|
|
+ titleName.gameObject.SetActive(true);
|
|
|
+ errorMsg.gameObject.SetActive(true);
|
|
|
+
|
|
|
+ Color color;
|
|
|
+ switch (nowItem.level)
|
|
|
+ {
|
|
|
+ case 4:
|
|
|
+ levelText.text = "低级";
|
|
|
+ ColorUtility.TryParseHtmlString("27CFE3", out color);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ levelText.text = "中级";
|
|
|
+ ColorUtility.TryParseHtmlString("F1B720", out color);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ levelText.text = "高级";
|
|
|
+ ColorUtility.TryParseHtmlString("DA791E", out color);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ levelText.text = "重大";
|
|
|
+ ColorUtility.TryParseHtmlString("ED5254", out color);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ titleName.text = nowItem.title;
|
|
|
+ errorMsg.text = "设备位置: " + nowItem.room + "/" + nowItem.rack + "/" + nowItem.u_addr;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ levelText.gameObject.SetActive(false);
|
|
|
+ levelImage.gameObject.SetActive(false);
|
|
|
+ titleName.gameObject.SetActive(false);
|
|
|
+ errorMsg.gameObject.SetActive(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nowItem.isShow == false)
|
|
|
+ {
|
|
|
+ nowItem.isShow = true;
|
|
|
+
|
|
|
+ ShowUnread(-1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void NetPage( bool isleft)
|
|
|
+ {
|
|
|
+ if (isleft)
|
|
|
+ {
|
|
|
+ contentPanel.localPosition += new Vector3(sampleListItem.rect.width + HLG.spacing, 0, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ contentPanel.localPosition -= new Vector3(sampleListItem.rect.width + HLG.spacing, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DelItem()
|
|
|
+ {
|
|
|
+ if (nowItem == null)
|
|
|
+ return;
|
|
|
+ LangChaoMailManager.Instance.RemoveMail(nowItem);
|
|
|
+ nowItem = null;
|
|
|
+ currentItem = Mathf.RoundToInt((0 - contentPanel.localPosition.x / (sampleListItem.rect.width + HLG.spacing)));
|
|
|
+ UpdatePage();
|
|
|
+ if (LangChaoMailManager.Instance.listMailItem.Count > currentItem)
|
|
|
+ {
|
|
|
+
|
|
|
+ nowItem = LangChaoMailManager.Instance.listMailItem[currentItem];
|
|
|
+ UpdateUI();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LangChaoMailManager.Instance.listMailItem.Count < 1)
|
|
|
+ {
|
|
|
+ levelText.gameObject.SetActive(false);
|
|
|
+ levelImage.gameObject.SetActive(false);
|
|
|
+ titleName.gameObject.SetActive(false);
|
|
|
+ errorMsg.gameObject.SetActive(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void UpdatePage()
|
|
|
+ {
|
|
|
+ page.text = (currentItem+1).ToString() + "/" + LangChaoMailManager.Instance.listMailItem.Count.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void ShowMailUI(GameObject mailUI)
|
|
|
+ {
|
|
|
+ mailUI.SetActive(!mailUI.activeSelf);
|
|
|
+
|
|
|
+ ShowMailUIColor.SetActive(mailUI.activeSelf);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ShowUnread( int num)
|
|
|
+ {
|
|
|
+ unreadNum += num;
|
|
|
+ if(unreadNum > 0)
|
|
|
+ {
|
|
|
+ unread.SetActive(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ unread.SetActive(false);
|
|
|
+ unreadNum = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unreadText.text = unreadNum.ToString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void StopSync()
|
|
|
+ {
|
|
|
+ SynPlayerTransform.Instance.StoPushOnClick();
|
|
|
+
|
|
|
+ }
|
|
|
+}
|