189 lines
4.5 KiB
C#
189 lines
4.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
using PygmyMonkey.AdvancedBuilder;
|
|
using SRDebugger.Internal;
|
|
using SRDebugger.Services;
|
|
using SRF;
|
|
using SRF.Service;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SRDebugger.UI.Other
|
|
{
|
|
public class BugReportSheetController : SRMonoBehaviourEx
|
|
{
|
|
[RequiredField]
|
|
public GameObject ButtonContainer;
|
|
|
|
[RequiredField]
|
|
public Text ButtonText;
|
|
|
|
[RequiredField]
|
|
public Button CancelButton;
|
|
|
|
public Action CancelPressed;
|
|
|
|
[RequiredField]
|
|
public InputField DescriptionField;
|
|
|
|
[RequiredField]
|
|
public InputField EmailField;
|
|
|
|
[RequiredField]
|
|
public Slider ProgressBar;
|
|
|
|
[RequiredField]
|
|
public Text ResultMessageText;
|
|
|
|
public Action ScreenshotComplete;
|
|
|
|
[RequiredField]
|
|
public Button SubmitButton;
|
|
|
|
public Action<bool, string> SubmitComplete;
|
|
|
|
public Action TakingScreenshot;
|
|
|
|
public bool IsCancelButtonEnabled
|
|
{
|
|
get
|
|
{
|
|
return CancelButton.gameObject.activeSelf;
|
|
}
|
|
set
|
|
{
|
|
CancelButton.gameObject.SetActive(value);
|
|
}
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
SetLoadingSpinnerVisible(false);
|
|
ClearErrorMessage();
|
|
}
|
|
|
|
public void Submit()
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
ProgressBar.value = 0f;
|
|
ClearErrorMessage();
|
|
SetLoadingSpinnerVisible(true);
|
|
SetFormEnabled(false);
|
|
StartCoroutine(SubmitCo());
|
|
}
|
|
|
|
public void Cancel()
|
|
{
|
|
if (CancelPressed != null)
|
|
{
|
|
CancelPressed();
|
|
}
|
|
}
|
|
|
|
private IEnumerator SubmitCo()
|
|
{
|
|
if (BugReportScreenshotUtil.ScreenshotData == null)
|
|
{
|
|
if (TakingScreenshot != null)
|
|
{
|
|
TakingScreenshot();
|
|
}
|
|
yield return new WaitForEndOfFrame();
|
|
yield return StartCoroutine(BugReportScreenshotUtil.ScreenshotCaptureCo());
|
|
if (ScreenshotComplete != null)
|
|
{
|
|
ScreenshotComplete();
|
|
}
|
|
}
|
|
IBugReportService s = SRServiceManager.GetService<IBugReportService>();
|
|
BugReport r = new BugReport
|
|
{
|
|
Email = EmailField.text,
|
|
UserDescription = " " + DescriptionField.text
|
|
};
|
|
r.UserDescription = r.UserDescription + "\n" + GlobalSettings.Instance.GetPlatformProfileID();
|
|
r.UserDescription = r.UserDescription + "\n" + GlobalSettings.Instance.GetPlatformProfileName();
|
|
r.UserDescription = r.UserDescription + "\n" + GlobalSettings.Instance.currentPlatform;
|
|
if (VRManager.IsVROn())
|
|
{
|
|
r.UserDescription = r.UserDescription + "\nVR " + VRManager.GetControllerType(true);
|
|
}
|
|
if (GlobalSettings.Instance.IsMyProfileCracked())
|
|
{
|
|
r.UserDescription += "\n!!IsMyProfileCracked!!";
|
|
}
|
|
string userDescription = r.UserDescription;
|
|
r.UserDescription = userDescription + "\n " + AppParameters.Get.bundleVersion + ":" + AppParameters.Get.buildNumber;
|
|
r.ConsoleLog = Service.Console.AllEntries.ToList();
|
|
r.SystemInformation = SRServiceManager.GetService<ISystemInformationService>().CreateReport();
|
|
r.ScreenshotData = BugReportScreenshotUtil.ScreenshotData;
|
|
BugReportScreenshotUtil.ScreenshotData = null;
|
|
s.SendBugReport(r, OnBugReportComplete, OnBugReportProgress);
|
|
}
|
|
|
|
private void OnBugReportProgress(float progress)
|
|
{
|
|
ProgressBar.value = progress;
|
|
}
|
|
|
|
private void OnBugReportComplete(bool didSucceed, string errorMessage)
|
|
{
|
|
if (!didSucceed)
|
|
{
|
|
ShowErrorMessage(Utilities.GetTranslation("BUG_REPORT/SENDING_ERROR"), errorMessage);
|
|
}
|
|
else
|
|
{
|
|
ClearForm();
|
|
ShowErrorMessage(Utilities.GetTranslation("BUG_REPORT/SENDING_SUCCESS"));
|
|
}
|
|
SetLoadingSpinnerVisible(false);
|
|
SetFormEnabled(true);
|
|
if (SubmitComplete != null)
|
|
{
|
|
SubmitComplete(didSucceed, errorMessage);
|
|
}
|
|
}
|
|
|
|
protected void SetLoadingSpinnerVisible(bool visible)
|
|
{
|
|
ProgressBar.gameObject.SetActive(visible);
|
|
ButtonContainer.SetActive(!visible);
|
|
}
|
|
|
|
protected void ClearForm()
|
|
{
|
|
EmailField.text = string.Empty;
|
|
DescriptionField.text = string.Empty;
|
|
}
|
|
|
|
protected void ShowErrorMessage(string userMessage, string serverMessage = null)
|
|
{
|
|
string text = userMessage;
|
|
if (!string.IsNullOrEmpty(serverMessage))
|
|
{
|
|
text += " (<b>{0}</b>)".Fmt(serverMessage);
|
|
}
|
|
ResultMessageText.text = text;
|
|
ResultMessageText.gameObject.SetActive(true);
|
|
}
|
|
|
|
protected void ClearErrorMessage()
|
|
{
|
|
ResultMessageText.text = string.Empty;
|
|
ResultMessageText.gameObject.SetActive(false);
|
|
}
|
|
|
|
protected void SetFormEnabled(bool e)
|
|
{
|
|
SubmitButton.interactable = e;
|
|
CancelButton.interactable = e;
|
|
EmailField.interactable = e;
|
|
DescriptionField.interactable = e;
|
|
}
|
|
}
|
|
}
|