Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / Editor / Tools / Startup Window / InkUnityIntegrationStartupWindow.cs
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace Ink.UnityIntegration {
  7. [InitializeOnLoad]
  8. public class InkUnityIntegrationStartupWindow : EditorWindow {
  9. const string editorPrefsKeyForVersionSeen = "Ink Unity Integration Startup Window Version Confirmed";
  10. const int announcementVersion = 2;
  11. Vector2 scrollPosition;
  12. static int announcementVersionPreviouslySeen;
  13. static string changelogText;
  14. static InkUnityIntegrationStartupWindow () {
  15. EditorApplication.delayCall += TryCreateWindow;
  16. }
  17. static void TryCreateWindow() {
  18. if (InkSettings.instance.suppressStartupWindow) return;
  19. announcementVersionPreviouslySeen = EditorPrefs.GetInt(editorPrefsKeyForVersionSeen, -1);
  20. if(announcementVersion != announcementVersionPreviouslySeen) {
  21. ShowWindow();
  22. }
  23. }
  24. public static void ShowWindow () {
  25. InkUnityIntegrationStartupWindow window = GetWindow(typeof(InkUnityIntegrationStartupWindow), true, "Ink Update "+InkLibrary.unityIntegrationVersionCurrent, true) as InkUnityIntegrationStartupWindow;
  26. window.minSize = new Vector2(200, 200);
  27. var size = new Vector2(520, 320);
  28. window.position = new Rect((Screen.currentResolution.width-size.x) * 0.5f, (Screen.currentResolution.height-size.y) * 0.5f, size.x, size.y);
  29. EditorPrefs.SetInt(editorPrefsKeyForVersionSeen, announcementVersion);
  30. }
  31. void OnEnable() {
  32. var packageDirectory = InkEditorUtils.FindAbsolutePluginDirectory();
  33. changelogText = File.ReadAllText(Path.Combine(packageDirectory, "CHANGELOG.md"));
  34. }
  35. void OnGUI ()
  36. {
  37. EditorGUILayout.BeginVertical();
  38. var areaSize = new Vector2(90,90);
  39. GUILayout.BeginArea(new Rect((position.width-areaSize.x)*0.5f, 15, areaSize.x, areaSize.y));
  40. EditorGUILayout.BeginVertical();
  41. EditorGUILayout.LabelField(new GUIContent(InkEditorUtils.inkLogoIcon), GUILayout.Width(areaSize.x), GUILayout.Height(areaSize.x*((float)InkEditorUtils.inkLogoIcon.height/InkEditorUtils.inkLogoIcon.width)));
  42. GUILayout.Space(5);
  43. EditorGUILayout.LabelField("Version "+InkLibrary.unityIntegrationVersionCurrent, EditorStyles.centeredGreyMiniLabel);
  44. EditorGUILayout.LabelField("Ink version "+InkLibrary.inkVersionCurrent, EditorStyles.centeredGreyMiniLabel);
  45. EditorGUILayout.EndVertical();
  46. GUILayout.EndArea();
  47. GUILayout.Space(20+areaSize.y);
  48. if(announcementVersionPreviouslySeen == -1) {
  49. EditorGUILayout.BeginVertical(GUI.skin.box);
  50. EditorGUILayout.LabelField("New to ink?", EditorStyles.boldLabel);
  51. EditorGUILayout.EndVertical();
  52. }
  53. {
  54. EditorGUILayout.BeginHorizontal();
  55. if (GUILayout.Button("About Ink")) {
  56. Application.OpenURL("https://www.inklestudios.com/ink/");
  57. }
  58. if (GUILayout.Button("❤️Support Us!❤️")) {
  59. Application.OpenURL("https://www.patreon.com/inkle");
  60. }
  61. if (GUILayout.Button("Discord Community+Support")) {
  62. Application.OpenURL("https://discord.gg/inkle");
  63. }
  64. if (GUILayout.Button("Close")) {
  65. Close();
  66. }
  67. EditorGUILayout.EndHorizontal();
  68. }
  69. EditorGUILayout.Space();
  70. if(changelogText != null) {
  71. scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
  72. var versionSections = Regex.Split(changelogText, "## "); // Split markdown text into version sections
  73. foreach (var section in versionSections) {
  74. if (string.IsNullOrWhiteSpace(section)) continue;
  75. var lines = section.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Split each section into lines
  76. var version = lines[0]; // First line is version
  77. EditorGUILayout.BeginVertical(GUI.skin.box);
  78. EditorGUILayout.LabelField($"{version}", EditorStyles.boldLabel);
  79. for (int i = 1; i < lines.Length; i++) {
  80. var bulletPoint = lines[i].TrimStart('-').TrimStart(' ');
  81. EditorGUILayout.LabelField($"• {bulletPoint}", EditorStyles.wordWrappedLabel);
  82. }
  83. EditorGUILayout.EndVertical();
  84. }
  85. EditorGUILayout.EndScrollView();
  86. }
  87. EditorGUILayout.Space();
  88. EditorGUILayout.EndVertical();
  89. }
  90. }
  91. }