The Swartz-Manning’s first exhibit will provide a detailed history of Aaron Swartz Day. https://www.aaronswartzday.org/vr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pb_AboutWindow.cs 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.IO;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using ProBuilder2.Common;
  8. namespace ProBuilder2.EditorCommon
  9. {
  10. /**
  11. * INSTRUCTIONS
  12. *
  13. * - Only modify properties in the USER SETTINGS region.
  14. * - All content is loaded from external files (pc_AboutEntry_YourProduct. Use the templates!
  15. */
  16. /**
  17. * Used to pop up the window on import.
  18. */
  19. [InitializeOnLoad]
  20. static class pb_AboutWindowSetup
  21. {
  22. static pb_AboutWindowSetup()
  23. {
  24. EditorApplication.delayCall += () => { pb_AboutWindow.Init(false); };
  25. }
  26. }
  27. /**
  28. * Changelog.txt file should follow this format:
  29. *
  30. * | # Product Name 2.1.0
  31. * |
  32. * | ## Features
  33. * |
  34. * | - All kinds of awesome stuff
  35. * | - New flux capacitor design achieves time travel at lower velocities.
  36. * | - Dark matter reactor recalibrated.
  37. * |
  38. * | ## Bug Fixes
  39. * |
  40. * | - No longer explodes when spacebar is pressed.
  41. * | - Fix rolling issue in rickmeter.
  42. * |
  43. * | # Changes
  44. * |
  45. * | - Changed Blue to Red.
  46. * | - Enter key now causes explosions.
  47. *
  48. * This path is relative to the PRODUCT_ROOT path.
  49. *
  50. * Note that your changelog may contain multiple entries. Only the top-most
  51. * entry will be displayed.
  52. */
  53. public class pb_AboutWindow : EditorWindow
  54. {
  55. // Modify these constants to customize about screen.
  56. const string PACKAGE_NAME = "ProBuilder";
  57. private static string aboutRoot = "Assets/ProCore/" + PACKAGE_NAME + "/About";
  58. // Path to the root folder
  59. internal static string AboutRoot
  60. {
  61. get
  62. {
  63. if( Directory.Exists(aboutRoot) )
  64. {
  65. return aboutRoot;
  66. }
  67. else
  68. {
  69. aboutRoot = pb_FileUtil.FindFolder("ProBuilder/About");
  70. if(aboutRoot.EndsWith("/"))
  71. aboutRoot = aboutRoot.Remove(aboutRoot.LastIndexOf("/"), 1);
  72. return aboutRoot;
  73. }
  74. }
  75. }
  76. GUIContent gc_Learn = new GUIContent("Learn ProBuilder", "Documentation");
  77. GUIContent gc_Forum = new GUIContent("Support Forum", "ProCore Support Forum");
  78. GUIContent gc_Contact = new GUIContent("Contact Us", "Send us an email!");
  79. GUIContent gc_Banner = new GUIContent("", "ProBuilder Quick-Start Video Tutorials");
  80. private const string VIDEO_URL = @"http://bit.ly/pbstarter";
  81. private const string LEARN_URL = @"http://procore3d.com/docs/probuilder";
  82. private const string SUPPORT_URL = @"http://www.procore3d.com/forum/";
  83. private const string CONTACT_EMAIL = @"http://www.procore3d.com/about/";
  84. private const float BANNER_WIDTH = 480f;
  85. private const float BANNER_HEIGHT = 270f;
  86. internal const string FONT_REGULAR = "Asap-Regular.otf";
  87. internal const string FONT_MEDIUM = "Asap-Medium.otf";
  88. // Use less contast-y white and black font colors for better readabililty
  89. public static readonly Color font_white = HexToColor(0xCECECE);
  90. public static readonly Color font_black = HexToColor(0x545454);
  91. public static readonly Color font_blue_normal = HexToColor(0x00AAEF);
  92. public static readonly Color font_blue_hover = HexToColor(0x008BEF);
  93. private string productName = pb_Constant.PRODUCT_NAME;
  94. private pb_AboutEntry about = null;
  95. private string changelogRichText = "";
  96. internal static GUIStyle bannerStyle,
  97. header1Style,
  98. versionInfoStyle,
  99. linkStyle,
  100. separatorStyle,
  101. changelogStyle,
  102. changelogTextStyle;
  103. Vector2 scroll = Vector2.zero;
  104. /**
  105. * Return true if Init took place, false if not.
  106. */
  107. public static bool Init (bool fromMenu)
  108. {
  109. pb_AboutEntry about;
  110. if(!pb_VersionUtil.GetAboutEntry(out about))
  111. {
  112. Debug.LogWarning("Couldn't find pb_AboutEntry_ProBuilder.txt");
  113. return false;
  114. }
  115. if(fromMenu || pb_PreferencesInternal.GetString(about.identifier) != about.version)
  116. {
  117. pb_AboutWindow win;
  118. win = (pb_AboutWindow)EditorWindow.GetWindow(typeof(pb_AboutWindow), true, about.name, true);
  119. win.ShowUtility();
  120. win.SetAbout(about);
  121. pb_PreferencesInternal.SetString(about.identifier, about.version, pb_PreferenceLocation.Global);
  122. return true;
  123. }
  124. else
  125. {
  126. return false;
  127. }
  128. }
  129. private static Color HexToColor(uint x)
  130. {
  131. return new Color( ((x >> 16) & 0xFF) / 255f,
  132. ((x >> 8) & 0xFF) / 255f,
  133. (x & 0xFF) / 255f,
  134. 1f);
  135. }
  136. public static void InitGuiStyles()
  137. {
  138. bannerStyle = new GUIStyle()
  139. {
  140. // RectOffset(left, right, top, bottom)
  141. margin = new RectOffset(12, 12, 12, 12),
  142. normal = new GUIStyleState() {
  143. background = LoadAssetAtPath<Texture2D>(string.Format("{0}/Images/Banner_Normal.png", AboutRoot))
  144. },
  145. hover = new GUIStyleState() {
  146. background = LoadAssetAtPath<Texture2D>(string.Format("{0}/Images/Banner_Hover.png", AboutRoot))
  147. },
  148. };
  149. header1Style = new GUIStyle()
  150. {
  151. margin = new RectOffset(10, 10, 10, 10),
  152. alignment = TextAnchor.MiddleCenter,
  153. fontSize = 24,
  154. // fontStyle = FontStyle.Bold,
  155. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_MEDIUM)),
  156. normal = new GUIStyleState() { textColor = EditorGUIUtility.isProSkin ? font_white : font_black }
  157. };
  158. versionInfoStyle = new GUIStyle()
  159. {
  160. margin = new RectOffset(10, 10, 10, 10),
  161. fontSize = 14,
  162. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_REGULAR)),
  163. normal = new GUIStyleState() { textColor = EditorGUIUtility.isProSkin ? font_white : font_black }
  164. };
  165. linkStyle = new GUIStyle()
  166. {
  167. margin = new RectOffset(10, 10, 10, 10),
  168. alignment = TextAnchor.MiddleCenter,
  169. fontSize = 16,
  170. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_REGULAR)),
  171. normal = new GUIStyleState() {
  172. textColor = font_blue_normal,
  173. background = LoadAssetAtPath<Texture2D>(
  174. string.Format("{0}/Images/ScrollBackground_{1}.png",
  175. AboutRoot,
  176. EditorGUIUtility.isProSkin ? "Pro" : "Light"))
  177. },
  178. hover = new GUIStyleState() {
  179. textColor = font_blue_hover,
  180. background = LoadAssetAtPath<Texture2D>(
  181. string.Format("{0}/Images/ScrollBackground_{1}.png",
  182. AboutRoot,
  183. EditorGUIUtility.isProSkin ? "Pro" : "Light"))
  184. }
  185. };
  186. separatorStyle = new GUIStyle()
  187. {
  188. margin = new RectOffset(10, 10, 10, 10),
  189. alignment = TextAnchor.MiddleCenter,
  190. fontSize = 16,
  191. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_REGULAR)),
  192. normal = new GUIStyleState() { textColor = EditorGUIUtility.isProSkin ? font_white : font_black }
  193. };
  194. changelogStyle = new GUIStyle()
  195. {
  196. margin = new RectOffset(10, 10, 10, 10),
  197. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_REGULAR)),
  198. richText = true,
  199. normal = new GUIStyleState() { background = LoadAssetAtPath<Texture2D>(
  200. string.Format("{0}/Images/ScrollBackground_{1}.png",
  201. AboutRoot,
  202. EditorGUIUtility.isProSkin ? "Pro" : "Light"))
  203. }
  204. };
  205. changelogTextStyle = new GUIStyle()
  206. {
  207. margin = new RectOffset(10, 10, 10, 10),
  208. font = LoadAssetAtPath<Font>(string.Format("{0}/Font/{1}", AboutRoot, FONT_REGULAR)),
  209. fontSize = 14,
  210. normal = new GUIStyleState() { textColor = EditorGUIUtility.isProSkin ? font_white : font_black },
  211. richText = true,
  212. wordWrap = true
  213. };
  214. }
  215. public void OnEnable()
  216. {
  217. InitGuiStyles();
  218. Texture2D banner = bannerStyle.normal.background;
  219. if(banner == null)
  220. {
  221. Debug.LogWarning("Could not load About window resources");
  222. this.Close();
  223. }
  224. else
  225. {
  226. bannerStyle.fixedWidth = BANNER_WIDTH; // banner.width;
  227. bannerStyle.fixedHeight = BANNER_HEIGHT; // banner.height;
  228. this.wantsMouseMove = true;
  229. this.minSize = new Vector2(BANNER_WIDTH + 24, BANNER_HEIGHT * 2.5f);
  230. this.maxSize = new Vector2(BANNER_WIDTH + 24, BANNER_HEIGHT * 2.5f);
  231. if(!productName.Contains("Basic"))
  232. productName = "ProBuilder Advanced";
  233. }
  234. }
  235. void SetAbout(pb_AboutEntry about)
  236. {
  237. this.about = about;
  238. if(!File.Exists(about.changelogPath))
  239. about.changelogPath = pb_FileUtil.FindFile("ProBuilder/About/changelog.txt");
  240. if(File.Exists(about.changelogPath))
  241. {
  242. string raw = File.ReadAllText(about.changelogPath);
  243. if(!string.IsNullOrEmpty(raw))
  244. {
  245. pb_VersionInfo vi;
  246. pb_VersionUtil.FormatChangelog(raw, out vi, out changelogRichText);
  247. }
  248. }
  249. }
  250. internal static T LoadAssetAtPath<T>(string InPath) where T : UnityEngine.Object
  251. {
  252. return (T) AssetDatabase.LoadAssetAtPath(InPath, typeof(T));
  253. }
  254. void OnGUI()
  255. {
  256. Vector2 mousePosition = Event.current.mousePosition;
  257. if( GUILayout.Button(gc_Banner, bannerStyle) )
  258. Application.OpenURL(VIDEO_URL);
  259. if(GUILayoutUtility.GetLastRect().Contains(mousePosition))
  260. Repaint();
  261. GUILayout.BeginVertical(changelogStyle);
  262. GUILayout.Label(productName, header1Style);
  263. GUILayout.BeginHorizontal();
  264. GUILayout.FlexibleSpace();
  265. if(GUILayout.Button(gc_Learn, linkStyle))
  266. Application.OpenURL(LEARN_URL);
  267. GUILayout.Label("|", separatorStyle);
  268. if(GUILayout.Button(gc_Forum, linkStyle))
  269. Application.OpenURL(SUPPORT_URL);
  270. GUILayout.Label("|", separatorStyle);
  271. if(GUILayout.Button(gc_Contact, linkStyle))
  272. Application.OpenURL(CONTACT_EMAIL);
  273. GUILayout.FlexibleSpace();
  274. GUILayout.EndHorizontal();
  275. if(GUILayoutUtility.GetLastRect().Contains(mousePosition))
  276. Repaint();
  277. GUILayout.EndVertical();
  278. // always bold the first line (cause it's the version info stuff)
  279. scroll = EditorGUILayout.BeginScrollView(scroll, changelogStyle);
  280. GUILayout.Label(string.Format("Version: {0}", about.version), versionInfoStyle);
  281. GUILayout.Label("\n" + changelogRichText, changelogTextStyle);
  282. EditorGUILayout.EndScrollView();
  283. }
  284. /**
  285. * Draw a horizontal line across the screen and update the guilayout.
  286. */
  287. void HorizontalLine()
  288. {
  289. Rect r = GUILayoutUtility.GetLastRect();
  290. Color og = GUI.backgroundColor;
  291. GUI.backgroundColor = Color.black;
  292. GUI.Box(new Rect(0f, r.y + r.height + 2, Screen.width, 2f), "");
  293. GUI.backgroundColor = og;
  294. GUILayout.Space(6);
  295. }
  296. }
  297. }