Pull down popup from common.

This commit is contained in:
2022-11-15 17:17:30 +08:00
parent cb3e3e5f28
commit 3a54d2023f
10 changed files with 47 additions and 47 deletions

View File

@@ -9,14 +9,6 @@ namespace Cryville.Common.Unity {
return (num2 & num) == num; return (num2 & num) == num;
} }
public static void ShowException(Exception ex) {
ShowMessageBox(ex.ToString());
}
public static void ShowMessageBox(string message) {
GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Popup")).GetComponent<Popup>().Message = message;
}
public static void Purge(Transform obj) { public static void Purge(Transform obj) {
foreach (Transform i in obj) foreach (Transform i in obj)
GameObject.Destroy(i.gameObject); GameObject.Destroy(i.gameObject);

View File

@@ -1,34 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity {
public class Popup : MonoBehaviour {
public string Message = "";
LayoutElement layout;
float timer = 0;
const float DURATION = 5.0f;
const float DURIN = 0.4f;
const float DUROUT = 0.4f;
const float HEIGHT = 50f;
#pragma warning disable IDE0051
void Start() {
layout = GetComponent<LayoutElement>();
GetComponentInChildren<Text>().text = Message;
transform.SetParent(GameObject.Find("PopupList").transform);
layout.minHeight = 0;
}
void Update() {
if (timer <= DURIN) layout.minHeight = timer / DURIN * HEIGHT;
else if (timer >= DURATION) GameObject.Destroy(gameObject);
else if (timer >= DURATION - DUROUT) layout.minHeight = (DURATION - timer) / DUROUT * HEIGHT;
timer += Time.deltaTime;
}
#pragma warning restore IDE0051
}
}

View File

@@ -133,10 +133,10 @@ namespace Cryville.Common.Unity {
prop.SetValue(Target, v, new object[]{ }); prop.SetValue(Target, v, new object[]{ });
} }
catch (TargetInvocationException ex) { catch (TargetInvocationException ex) {
CallHelper.ShowMessageBox(ex.InnerException.Message); // CallHelper.ShowMessageBox(ex.InnerException.Message);
} }
catch (Exception ex) { catch (Exception ex) {
CallHelper.ShowMessageBox(ex.Message); // CallHelper.ShowMessageBox(ex.Message);
} }
} }
UpdateValue(); UpdateValue();

View File

@@ -121,7 +121,7 @@ namespace Cryville.Crtr.Browsing {
resources = converter.ConvertFrom(file); resources = converter.ConvertFrom(file);
} }
catch (Exception ex) { catch (Exception ex) {
CallHelper.ShowMessageBox(ex.Message); Popup.Create(ex.Message);
return false; return false;
} }
foreach (var res in resources) { foreach (var res in resources) {

View File

@@ -59,11 +59,11 @@ namespace Cryville.Crtr.Browsing {
private void OnAddDialogClosed() { private void OnAddDialogClosed() {
if (_dialog.FileName == null) return; if (_dialog.FileName == null) return;
if (ResourceManager.ImportItemFrom(_dialog.FileName)) { if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
CallHelper.ShowMessageBox("Import succeeded"); Popup.Create("Import succeeded");
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1); OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
} }
else { else {
CallHelper.ShowMessageBox("Import failed"); Popup.Create("Import failed");
} }
} }
} }

View File

@@ -142,6 +142,7 @@ namespace Cryville.Crtr {
} }
catch (Exception ex) { catch (Exception ex) {
Game.LogException("Game", "An error occured while playing", ex); Game.LogException("Game", "An error occured while playing", ex);
Popup.CreateException(ex);
Stop(); Stop();
} }
} }
@@ -396,6 +397,7 @@ namespace Cryville.Crtr {
} }
catch (Exception ex) { catch (Exception ex) {
Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex); Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex);
Popup.CreateException(ex);
Stop(); Stop();
} }
} }
@@ -417,6 +419,7 @@ namespace Cryville.Crtr {
catch (Exception ex) { catch (Exception ex) {
if (!logEnabled) ToggleLogs(); if (!logEnabled) ToggleLogs();
Game.LogException("Game", "An error occured while stopping", ex); Game.LogException("Game", "An error occured while stopping", ex);
Popup.CreateException(ex);
} }
finally { finally {
if (started) { if (started) {

View File

@@ -0,0 +1,39 @@
using System;
using UnityEditor.VersionControl;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr {
public class Popup : MonoBehaviour {
public string Message = "";
CanvasGroup group;
float timer = 0;
const float DURATION = 5.0f;
const float DURIN = 0.4f;
const float DUROUT = 0.4f;
void Start() {
group = GetComponent<CanvasGroup>();
group.alpha = 0;
GetComponentInChildren<Text>().text = Message;
transform.SetParent(GameObject.Find("PopupList").transform);
}
void Update() {
if (timer <= DURIN) group.alpha = timer / DURIN;
else if (timer >= DURATION) GameObject.Destroy(gameObject);
else if (timer >= DURATION - DUROUT) group.alpha = (DURATION - timer) / DUROUT;
timer += Time.deltaTime;
}
public static void CreateException(Exception ex) {
Create(ex.Message);
}
public static void Create(string msg) {
Instantiate(Resources.Load<GameObject>("Common/Popup")).GetComponent<Popup>().Message = msg;
}
}
}

Binary file not shown.

Binary file not shown.