|
|
|
|
using UnityEngine;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using ArabicSupport;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
public class EmailUIController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public TextMeshProUGUI senderInitial;
|
|
|
|
|
public Image senderBg;
|
|
|
|
|
public TextMeshProUGUI senderNameText;
|
|
|
|
|
public TextMeshProUGUI subjectText;
|
|
|
|
|
public TextMeshProUGUI previewText;
|
|
|
|
|
public TextMeshProUGUI timeOrDateText;
|
|
|
|
|
|
|
|
|
|
public Sprite[] backgroundSprites;
|
|
|
|
|
public EmailData data;
|
|
|
|
|
|
|
|
|
|
[SerializeField, HideInInspector]
|
|
|
|
|
public string cachedInitial;
|
|
|
|
|
[SerializeField, HideInInspector]
|
|
|
|
|
public Sprite cachedSprite;
|
|
|
|
|
bool isAlreadyOpened=false;
|
|
|
|
|
EmailOpenPanel m_EmailOpenPanel;
|
|
|
|
|
public void Setup(EmailData emailData)
|
|
|
|
|
{
|
|
|
|
|
data = emailData;
|
|
|
|
|
|
|
|
|
|
bool isArabic = LanguageManager.Instance != null && LanguageManager.Instance.currentLanguage == "Arabic";
|
|
|
|
|
|
|
|
|
|
senderNameText.text = isArabic ? ArabicFixer.Fix(data.senderName) : data.senderName;
|
|
|
|
|
subjectText.text = isArabic ? ArabicFixer.Fix(data.subjectAr) : data.subject;
|
|
|
|
|
previewText.text = isArabic ? ArabicFixer.Fix(GeneratePreview(data.fullBodyTextAr)) : GeneratePreview(data.fullBodyText);
|
|
|
|
|
timeOrDateText.text = isArabic ? ArabicFixer.Fix(data.timeOrDateAr) : data.timeOrDate;
|
|
|
|
|
|
|
|
|
|
AlignText(subjectText, isArabic);
|
|
|
|
|
AlignText(previewText, isArabic);
|
|
|
|
|
AlignText(timeOrDateText, isArabic);
|
|
|
|
|
|
|
|
|
|
cachedInitial = data.senderName[0].ToString().ToUpper();
|
|
|
|
|
cachedSprite = backgroundSprites[Random.Range(0, backgroundSprites.Length)];
|
|
|
|
|
|
|
|
|
|
senderInitial.text = cachedInitial;
|
|
|
|
|
senderBg.sprite = cachedSprite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AlignText(TextMeshProUGUI tmp, bool isArabic)
|
|
|
|
|
{
|
|
|
|
|
if (tmp == null) return;
|
|
|
|
|
tmp.font = LanguageManager.Instance?.GetCurrentFont();
|
|
|
|
|
//tmp.isRightToLeftText = isArabic;
|
|
|
|
|
//tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string GeneratePreview(string body)
|
|
|
|
|
{
|
|
|
|
|
int max = 60;
|
|
|
|
|
string clean = body.Replace("\n", " ").Trim();
|
|
|
|
|
return clean.Length <= max ? clean : clean.Substring(0, max) + "...";
|
|
|
|
|
}
|
|
|
|
|
bool audioAlreadyDone = false;
|
|
|
|
|
public void OnClick()
|
|
|
|
|
{
|
|
|
|
|
if(!audioAlreadyDone)
|
|
|
|
|
{
|
|
|
|
|
audioAlreadyDone = true;
|
|
|
|
|
NarrationPlayer.Instance.PlayNarration(NarrationID.ScanEmail);
|
|
|
|
|
}
|
|
|
|
|
//InstructionManager.Instance.HideScreenInstruction();
|
|
|
|
|
SoundManager.Instance.PlayButtonClick();
|
|
|
|
|
GameObject panel = Instantiate(Resources.Load<GameObject>("EmailOpenPanel"), transform.root);
|
|
|
|
|
panel.transform.SetSiblingIndex(5);
|
|
|
|
|
m_EmailOpenPanel=panel.GetComponent<EmailOpenPanel>();
|
|
|
|
|
WorldTimelineManager.Instance.OpenedEmailPanel = panel;
|
|
|
|
|
EmailOpenPanel controller = panel.GetComponent<EmailOpenPanel>();
|
|
|
|
|
controller.Setup(data, cachedInitial, cachedSprite);
|
|
|
|
|
string englishLog = $"Opened email from '{data.senderName}' with subject '{data.subject}'";
|
|
|
|
|
string arabicLog = $"تم فتح البريد من '{data.senderName}' بعنوان '{data.subjectAr}'";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isAlreadyOpened) return;
|
|
|
|
|
UserActionLogger.Instance?.Log(englishLog, arabicLog);
|
|
|
|
|
SceneOutcomeManager.Instance.OnEmailOpened();
|
|
|
|
|
isAlreadyOpened = true;
|
|
|
|
|
//UserActionLogger.Instance?.Log($"Opened email from '{data.senderName}' with subject '{data.subject}'");
|
|
|
|
|
}
|
|
|
|
|
public void ButtonSetter(Button button)
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(ButtonSetterRoutine(button));
|
|
|
|
|
}
|
|
|
|
|
IEnumerator ButtonSetterRoutine(Button button)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitUntil(()=>m_EmailOpenPanel!=null);
|
|
|
|
|
m_EmailOpenPanel.MainButtonToDisable = button;
|
|
|
|
|
}
|
|
|
|
|
}
|