123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class ManaNotify
- {
- private class Content
- {
- public bool IsImage;
- public string text;
- public TextAnchor Alignment;
- public Content(bool isImage, string text, TextAnchor alignment)
- {
- this.text = text;
- this.IsImage = isImage;
- this.Alignment = alignment;
- }
- }
- public static bool Initialized;
- private static List<Text> TextList = new List<Text>();
- private static Dictionary<string, List<Content>> ContentsDic = new Dictionary<string, List<Content>>();
- public static void AddLine(bool isImage, string language, string content, TextAnchor alignment)
- {
- if (language == "null")
- {
- AddLine(isImage, "English", content, alignment);
- AddLine(isImage, "Chinese", content, alignment);
- AddLine(isImage, "ChineseTraditional", content, alignment);
- }
- if (!ContentsDic.ContainsKey(language))
- {
- ContentsDic.Add(language, new List<Content>());
- }
- ContentsDic[language].Add(new Content(isImage, content, alignment));
- }
- public static void Show()
- {
- if (!Initialized)
- {
- Initialize(GetLanguage());
- }
- else
- {
- SwitchLanguage(GetLanguage());
- }
- ManaReso.Get("R_Notify").TweenForCG();
- }
- public static void Initialize(string language)
- {
- Initialized = true;
- List<Content> contents = ContentsDic[language];
- for (int i = 0; i < contents.Count; i++)
- {
- Transform transform = ManaReso.Get("NotifyItem", Folder.UI, false, ManaReso.Get("R_Grid"), false);
- if (contents[i].IsImage)
- {
- transform.GetComponent<Text>().fontSize = 300;
- transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
- transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
- transform.GetComponent<Text>().resizeTextForBestFit = false;
- transform.GetComponent<ContentSizeFitter>().enabled = true;
- transform.GetChild(0).GetComponent<Image>().sprite = ManaServer.NotificationSprite;
- }
- transform.GetComponent<Text>().text = contents[i].text;
- transform.GetComponent<Text>().alignment = contents[i].Alignment;
- TextList.Add(transform.GetComponent<Text>());
- }
- Auxiliary.Instance.DelayCall
- (
- () =>
- {
- ManaReso.Get<VerticalLayoutGroup>("R_Grid").enabled = true;
- },
- 1
- );
- }
- public static void SwitchLanguage(string language)
- {
- for (int i = 0; i < TextList.Count; i++)
- {
- TextList[i].text = ContentsDic[language][i].text;
- }
- }
- public static string GetLanguage()
- {
- if (ManaLan.CurrentLan == Lan.ChineseSimplified)
- {
- return "Chinese";
- }
- else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
- {
- return "ChineseTraditional";
- }
- else if (ManaLan.CurrentLan == Lan.English)
- {
- return "English";
- }
- else
- {
- throw new Exception();
- }
- }
- }
|