You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
314 lines
11 KiB
C#
314 lines
11 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using ArabicSupport;
|
|
|
|
public class EmailOpenPanel : MonoBehaviour
|
|
{
|
|
[Header("Main Email View")]
|
|
public TextMeshProUGUI senderName;
|
|
public TextMeshProUGUI senderEmail;
|
|
public TextMeshProUGUI subject;
|
|
public TextMeshProUGUI bodyText;
|
|
public TextMeshProUGUI linkPreview;
|
|
public GameObject phishingIcon;
|
|
|
|
public TextMeshProUGUI senderInitial;
|
|
public Image senderBg;
|
|
|
|
public Button reportBtn;
|
|
public Button ignoreBtn;
|
|
public Button infoButton;
|
|
|
|
private EmailData emailData;
|
|
public EmailData Email => emailData;
|
|
|
|
[Header("Info Panel")]
|
|
public GameObject infoPanel;
|
|
public TextMeshProUGUI infoFrom;
|
|
public TextMeshProUGUI infoTo;
|
|
public TextMeshProUGUI infoDate;
|
|
public TextMeshProUGUI infoSubject;
|
|
public Button closeInfoButton;
|
|
public Button MainButtonToDisable;
|
|
|
|
public void PlayButtonClick()
|
|
{
|
|
SoundManager.Instance.PlayButtonClick();
|
|
}
|
|
public void Setup(EmailData data, string initial, Sprite iconSprite)
|
|
{
|
|
emailData = data;
|
|
senderName.text = data.senderName;
|
|
|
|
LocalizeTMP(subject, data.subject, data.subjectAr);
|
|
LocalizeTMP(bodyText, data.fullBodyText, data.fullBodyTextAr);
|
|
|
|
if (phishingIcon != null)
|
|
phishingIcon.SetActive(data.isPhishing);
|
|
|
|
senderInitial?.SetText(initial);
|
|
if (senderBg != null)
|
|
senderBg.sprite = iconSprite;
|
|
|
|
reportBtn?.onClick.RemoveAllListeners();
|
|
reportBtn?.onClick.AddListener(() => OnAction("report"));
|
|
|
|
ignoreBtn?.onClick.RemoveAllListeners();
|
|
ignoreBtn?.onClick.AddListener(() => OnAction("ignore"));
|
|
|
|
infoButton?.onClick.RemoveAllListeners();
|
|
infoButton?.onClick.AddListener(ShowInfoPanel);
|
|
|
|
//closeInfoButton?.onClick.RemoveAllListeners();
|
|
//closeInfoButton?.onClick.AddListener(() => infoPanel.SetActive(false));
|
|
}
|
|
|
|
void ShowInfoPanel()
|
|
{
|
|
bool isArabic = LanguageManager.Instance.currentLanguage == "Arabic";
|
|
|
|
// Compose 'From'
|
|
string from = $"{emailData.senderName} <{emailData.senderEmail}>";
|
|
if (emailData.otherSenderEmails != null && emailData.otherSenderEmails.Length > 0)
|
|
from += $", {string.Join(", ", emailData.otherSenderEmails)}";
|
|
|
|
// Compose 'To'
|
|
string to = emailData.toRecipients != null && emailData.toRecipients.Length > 0
|
|
? string.Join(", ", emailData.toRecipients)
|
|
: "self@cybercompanion.com";
|
|
|
|
// Subject & Date
|
|
string subj = isArabic ? emailData.subjectAr : emailData.subject;
|
|
string date = isArabic ? emailData.timeOrDateAr : emailData.sentDate;
|
|
|
|
// Set localized text
|
|
infoFrom.text = from;
|
|
infoTo.text = to;
|
|
infoSubject.text = subj;
|
|
infoDate.text = date;
|
|
//SetLocalizedTMP(infoFrom, from, isArabic);
|
|
//SetLocalizedTMP(infoTo, to, isArabic);
|
|
//SetLocalizedTMP(infoSubject, subj, isArabic);
|
|
//SetLocalizedTMP(infoDate, date, isArabic);
|
|
|
|
infoPanel.SetActive(true);
|
|
}
|
|
|
|
void SetLocalizedTMP(TextMeshProUGUI tmp, string text, bool isArabic)
|
|
{
|
|
if (tmp == null) return;
|
|
|
|
tmp.text = isArabic ? ArabicFixer.Fix(text) : text;
|
|
tmp.font = LanguageManager.Instance.GetCurrentFont();
|
|
// tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
|
|
//tmp.isRightToLeftText = isArabic;
|
|
}
|
|
void OnAction(string action)
|
|
{
|
|
// Disable both buttons to prevent double clicks
|
|
reportBtn.interactable = false;
|
|
ignoreBtn.interactable = false;
|
|
MainButtonToDisable.interactable=false;
|
|
gameObject.SetActive(false);
|
|
|
|
string englishLog = $"{action.ToUpper()} clicked on email from '{emailData.senderName}' with subject '{emailData.subject}'";
|
|
string arabicAction = action == "report" ? "الإبلاغ" : "تجاهل";
|
|
string arabicLog = $"تم الضغط على زر {arabicAction} للبريد من '{emailData.senderName}' بعنوان '{emailData.subjectAr}'";
|
|
|
|
UserActionLogger.Instance?.Log(englishLog, arabicLog);
|
|
|
|
bool isCorrect =
|
|
(action == "report" && emailData.isPhishing) ||
|
|
(action == "ignore" && !emailData.isPhishing);
|
|
|
|
// Score 9 if correct
|
|
SceneOutcomeManager.Instance.OnEmailDecision(isCorrect, 9);
|
|
|
|
if (isCorrect)
|
|
{
|
|
SoundManager.Instance?.PlayCorrectAction();
|
|
InstructionManager.Instance?.ShowScreenInstruction("correct_choice", 3f);
|
|
}
|
|
else
|
|
{
|
|
SoundManager.Instance?.PlayPhishingAlert();
|
|
}
|
|
|
|
// Trigger action-specific feedback
|
|
if (action == "report")
|
|
{
|
|
SceneOutcomeManager.Instance.Reported(emailData);
|
|
}
|
|
//else if (action == "ignore")
|
|
//{
|
|
// SceneOutcomeManager.Instance.Clicked(emailData); // or Ignored handler if you prefer
|
|
//}
|
|
|
|
SupabaseEventLogger.Instance?.CompleteSessionAndSubmitResult(
|
|
userId: SystemInfo.deviceUniqueIdentifier,
|
|
passed: isCorrect,
|
|
optimal: isCorrect ? 1 : 0,
|
|
suboptimal: isCorrect ? 0 : 1,
|
|
scenarioId: "scene_1"
|
|
);
|
|
}
|
|
|
|
// void OnAction(string action)
|
|
// {
|
|
// gameObject.SetActive(false);
|
|
|
|
// //string summary = $"{action.ToUpper()} clicked on email from '{emailData.senderName}' with subject '{emailData.subject}'";
|
|
// //UserActionLogger.Instance?.Log(summary);
|
|
// string englishLog = $"{action.ToUpper()} clicked on email from '{emailData.senderName}' with subject '{emailData.subject}'";
|
|
// string arabicAction = action == "report" ? "الإبلاغ" : "تجاهل";
|
|
// string arabicLog = $"تم الضغط على زر {arabicAction} للبريد من '{emailData.senderName}' بعنوان '{emailData.subjectAr}'";
|
|
|
|
// UserActionLogger.Instance?.Log(englishLog, arabicLog);
|
|
// bool isCorrect =
|
|
// (action == "report" && emailData.isPhishing) ||
|
|
// (action == "ignore" && !emailData.isPhishing);
|
|
// int score = isCorrect ? 5 : 0;
|
|
// //SceneOutcomeManager.Instance.ScoreUpdater(score);
|
|
// SceneOutcomeManager.Instance.OnEmailDecision(isCorrect,9);
|
|
// //SupabaseEventLogger.Instance.LogScoreEvent(score);
|
|
// if (isCorrect)
|
|
// {
|
|
// SoundManager.Instance?.PlayCorrectAction();
|
|
// InstructionManager.Instance?.ShowScreenInstruction("correct_choice", 3f);
|
|
// }
|
|
// else
|
|
// {
|
|
// SoundManager.Instance?.PlayPhishingAlert();
|
|
// }
|
|
// switch (action)
|
|
// {
|
|
// case "report":
|
|
// SceneOutcomeManager.Instance.Reported(emailData);
|
|
// break;
|
|
// case "ignore":
|
|
// bool wasCorrect = !emailData.isPhishing; // Ignoring only correct if not phishing
|
|
// SceneOutcomeManager.Instance.OnEmailDecision(wasCorrect);
|
|
// break;
|
|
// }
|
|
|
|
// SupabaseEventLogger.Instance?.CompleteSessionAndSubmitResult(
|
|
// userId: SystemInfo.deviceUniqueIdentifier, // replace with real user ID if available
|
|
// passed: isCorrect,
|
|
// optimal: isCorrect ? 1 : 0,
|
|
// suboptimal: isCorrect ? 0 : 1,
|
|
// scenarioId: "scene_1"
|
|
//);
|
|
// }
|
|
|
|
void LocalizeTMP(TextMeshProUGUI tmp, string english, string arabic)
|
|
{
|
|
if (tmp == null) return;
|
|
|
|
bool isArabic = LanguageManager.Instance.currentLanguage == "Arabic";
|
|
|
|
tmp.text = isArabic ? ArabicFixerHelper.FixPreservingTags(arabic) : english;
|
|
tmp.font = LanguageManager.Instance.GetCurrentFont();
|
|
// tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
|
|
// tmp.isRightToLeftText = isArabic;
|
|
}
|
|
}
|
|
|
|
|
|
//using UnityEngine;
|
|
//using TMPro;
|
|
//using UnityEngine.UI;
|
|
//using ArabicSupport;
|
|
|
|
//public class EmailOpenPanel : MonoBehaviour
|
|
//{
|
|
// public TextMeshProUGUI senderName;
|
|
// public TextMeshProUGUI senderEmail;
|
|
// public TextMeshProUGUI subject;
|
|
// public TextMeshProUGUI bodyText;
|
|
// public TextMeshProUGUI linkPreview;
|
|
// public GameObject phishingIcon;
|
|
|
|
// public TextMeshProUGUI senderInitial;
|
|
// public Image senderBg;
|
|
|
|
// public Button reportBtn;
|
|
// public Button ignoreBtn;
|
|
|
|
// private EmailData emailData;
|
|
// public EmailData Email => emailData;
|
|
|
|
// public void Setup(EmailData data, string initial, Sprite iconSprite)
|
|
// {
|
|
// emailData = data;
|
|
// senderName.text = data.senderName;
|
|
// // senderEmail.text = data.senderEmail;
|
|
// LocalizeTMP(subject, data.subject, data.subjectAr);
|
|
// LocalizeTMP(bodyText, data.fullBodyText, data.fullBodyTextAr);
|
|
// //linkPreview.text=data.linkPreview;
|
|
// if (phishingIcon != null)
|
|
// phishingIcon.SetActive(data.isPhishing);
|
|
|
|
// senderInitial?.SetText(initial);
|
|
// if (senderBg != null)
|
|
// senderBg.sprite = iconSprite;
|
|
|
|
// reportBtn?.onClick.RemoveAllListeners();
|
|
// reportBtn?.onClick.AddListener(() => OnAction("report"));
|
|
|
|
// ignoreBtn?.onClick.RemoveAllListeners();
|
|
// ignoreBtn?.onClick.AddListener(() => OnAction("ignore"));
|
|
// }
|
|
|
|
// void OnAction(string action)
|
|
// {
|
|
// gameObject.SetActive(false);
|
|
|
|
// string summary = $"{action.ToUpper()} clicked on email from '{emailData.senderName}' with subject '{emailData.subject}'";
|
|
// UserActionLogger.Instance?.Log(summary);
|
|
|
|
// bool isCorrect =
|
|
// (action == "report" && emailData.isPhishing) ||
|
|
// (action == "ignore" && !emailData.isPhishing);
|
|
|
|
// if (isCorrect)
|
|
// {
|
|
// // ✅ Correct choice → Show instruction
|
|
// InstructionManager.Instance?.ShowScreenInstruction("correct_choice", 3f);
|
|
// }
|
|
|
|
// switch (action)
|
|
// {
|
|
// case "report":
|
|
// SceneOutcomeManager.Instance.Reported(emailData);
|
|
// break;
|
|
// case "ignore":
|
|
// SceneOutcomeManager.Instance.Ignored(emailData);
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// //void LocalizeTMP(TextMeshProUGUI tmp, string english, string arabic)
|
|
// //{
|
|
// // if (tmp == null) return;
|
|
|
|
// // bool isArabic = LanguageManager.Instance != null && LanguageManager.Instance.currentLanguage == "Arabic";
|
|
// // tmp.text = isArabic ? ArabicFixer.Fix(arabic) : english;
|
|
// // tmp.font = LanguageManager.Instance?.GetCurrentFont();
|
|
// // //tmp.isRightToLeftText = isArabic;
|
|
// // //tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
|
|
// //}
|
|
// void LocalizeTMP(TextMeshProUGUI tmp, string english, string arabic)
|
|
// {
|
|
// if (tmp == null) return;
|
|
|
|
// bool isArabic = LanguageManager.Instance.currentLanguage == "Arabic";
|
|
|
|
// tmp.text = isArabic ? ArabicFixerHelper.FixPreservingTags(arabic) : english;
|
|
// tmp.font = LanguageManager.Instance.GetCurrentFont();
|
|
// // tmp.isRightToLeftText = isArabic;
|
|
// //tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
|
|
// }
|
|
|
|
//}
|