2025-09-08 17:37:12 +08:00

98 lines
3.5 KiB
C#

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using ZXKFramework;
using static System.Net.Mime.MediaTypeNames;
namespace DongWuYiXue.DaoNiaoShu
{
public class TipPanel : UIBase
{
public override string GroupName => "TipPanel";
public override string Name => "TipPanel";
TextMeshProUGUI tip;
List<string> str = new();
public Transform p1; // ÆðʼµãTransform
public Transform p2; // ½áÊøµãTransform
public RectTransform container;
Button upBtn;
Button downBtn;
ScrollRect scrollRect;
Coroutine coroutine;
public override void Init(IUIManager uictrl)
{
base.Init(uictrl);
tip = transform.FindFirst<TextMeshProUGUI>("showText");
upBtn = transform.FindFirst<Button>("upBtn");
downBtn = transform.FindFirst<Button>("downBtn");
scrollRect = transform.FindFirst<ScrollRect>("Scroll View");
upBtn.onClick.AddListener(MoveUp);
downBtn.onClick.AddListener(MoveDown);
}
public void AddTip(string tips)
{
SetActive(false);
str.Clear();
str = tips.Split('|').ToList();
}
public void ShowTip(int i)
{
SetActive(true);
Game.Instance.IEnumeratorManager.Stop(coroutine);
tip.text = str[i].Replace("<br>", "\n");
//Debug.Log(Regex.Replace(Regex.Replace(tip.text, @"<color=[^>]*>", ""), @"</color>", "").Length + "==" + (Regex.Replace(Regex.Replace(tip.text, @"<color=[^>]*>", ""), @"</color>", "").Length + 70 - 1) / 70);
//if (scrollRect.content.rect.height > 57)
//{
// coroutine = Game.Instance.IEnumeratorManager.Run(Scroll((int)(scrollRect.content.rect.height + 56 - 1) / 56));
//}
container.position = p1.position;
coroutine = Game.Instance.IEnumeratorManager.Run(Scroll());
}
public void ShowTip(string str)
{
SetActive(true);
tip.text = str.Replace("<br>", "\n");
}
public override void Hide()
{
base.Hide();
Game.Instance.IEnumeratorManager.Stop(coroutine);
Game.Instance.sound.StopBGM();
}
public void MoveDown()
{
container.DOMove(p2.position, 0.5f);
upBtn.gameObject.SetActive(true);
downBtn.gameObject.SetActive(false);
}
public void MoveUp()
{
container.DOMove(p1.position, 0.5f);
upBtn.gameObject.SetActive(false);
downBtn.gameObject.SetActive(true);
}
IEnumerator Scroll()
{
scrollRect.normalizedPosition = new Vector2(0, 1);
yield return new WaitForSeconds(1);
//Debug.Log(scrollRect.content.rect.height);
if (scrollRect.content.rect.height > 57)
{
int i = (int)(scrollRect.content.rect.height + 56 - 1) / 56;
for (int j = 0; j < i; j++)
{
//Debug.Log((int)scrollRect.normalizedPosition.y);
if ((int)scrollRect.normalizedPosition.y == 0) yield break;
yield return new WaitForSeconds(13f);
scrollRect.normalizedPosition -= new Vector2(0, 1 - (1 / i));
}
}
}
}
}