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.

224 lines
7.7 KiB

  1. using CustomUI.BeatSaber;
  2. using CustomUI.Utilities;
  3. using IPA.Loader;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using TMPro;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using VRUI;
  13. namespace BSIPA_ModList.UI
  14. {
  15. internal class ModInfoViewController : VRUIViewController
  16. {
  17. internal Sprite Icon;
  18. internal string Name;
  19. internal string Version;
  20. internal string Author;
  21. internal string Description;
  22. internal PluginLoader.PluginMetadata UpdateInfo;
  23. private ModInfoView view;
  24. public void Init(Sprite icon, string name, string version, string author, string description, PluginLoader.PluginMetadata updateInfo)
  25. {
  26. Logger.log.Debug($"init info view controller");
  27. Icon = icon;
  28. Name = name;
  29. Version = version;
  30. Author = author;
  31. Description = description;
  32. UpdateInfo = updateInfo;
  33. // i also have no clue why this is necessary
  34. rectTransform.anchorMin = new Vector2(0f, 0f);
  35. rectTransform.anchorMax = new Vector2(0.5f, 1f);
  36. var go = new GameObject("Info View", typeof(RectTransform));
  37. go.SetActive(false);
  38. go.AddComponent<RectMask2D>();
  39. view = go.AddComponent<ModInfoView>();
  40. var rt = view.transform as RectTransform;
  41. rt.SetParent(transform);
  42. rt.anchorMin = new Vector2(0f, 0f);
  43. rt.anchorMax = new Vector2(1f, 1f);
  44. rt.anchoredPosition = new Vector2(0f, 0f);
  45. view.Init(this);
  46. go.SetActive(true);
  47. }
  48. }
  49. internal class ModInfoView : MonoBehaviour
  50. {
  51. private ModInfoViewController controller;
  52. private TextMeshProUGUI titleText;
  53. private TextMeshProUGUI authorText;
  54. private TextMeshProUGUI descText;
  55. private Image icon;
  56. public void Init(ModInfoViewController controller)
  57. {
  58. Logger.log.Debug($"init info view");
  59. this.controller = controller;
  60. var rectTransform = transform as RectTransform;
  61. rectTransform.sizeDelta = new Vector2(60f, 10f);
  62. titleText = BeatSaberUI.CreateText(rectTransform, $"{controller.Name} <size=60%>{controller.Version}", new Vector2(11f, 27.5f));
  63. titleText.fontSize = 6f;
  64. authorText = BeatSaberUI.CreateText(rectTransform, controller.Author, new Vector2(11f, 22f));
  65. authorText.fontSize = 4.5f;
  66. descText = BeatSaberUI.CreateText(rectTransform, controller.Description, new Vector2(-4.5f, 12f));
  67. descText.fontSize = 3.5f;
  68. descText.enableWordWrapping = true;
  69. descText.overflowMode = TextOverflowModes.ScrollRect;
  70. icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent<Image>();
  71. icon.gameObject.SetActive(false);
  72. icon.rectTransform.SetParent(rectTransform, false);
  73. icon.rectTransform.anchorMin = new Vector2(0.5f, 0.44f);
  74. icon.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
  75. icon.rectTransform.sizeDelta = new Vector2(60f, 10f);
  76. icon.rectTransform.anchoredPosition = new Vector2(-27.8f, 27.3f);
  77. icon.sprite = controller.Icon;
  78. icon.preserveAspect = true;
  79. icon.useSpriteMesh = true;
  80. icon.material = UIUtilities.NoGlowMaterial;
  81. icon.gameObject.SetActive(true);
  82. }
  83. #if DEBUG
  84. #if ADJUST_INFO_TEXT_UI_KEYS
  85. private int currentItem = 0;
  86. #endif
  87. public void Update()
  88. {
  89. #if ADJUST_INFO_TEXT_UI_KEYS
  90. RectTransform rt;
  91. switch (currentItem)
  92. {
  93. default:
  94. currentItem = 0;
  95. goto case 0; // idk why this is needed tbh
  96. case 0:
  97. rt = titleText.rectTransform;
  98. break;
  99. case 1:
  100. rt = authorText.rectTransform;
  101. break;
  102. case 2:
  103. rt = descText.rectTransform;
  104. break;
  105. }
  106. if (Input.GetKeyDown(KeyCode.N))
  107. currentItem++;
  108. var cpos = rt.anchoredPosition;
  109. if (Input.GetKey(KeyCode.LeftArrow))
  110. {
  111. rt.anchoredPosition = new Vector2(cpos.x - .1f, cpos.y);
  112. }
  113. else if (Input.GetKey(KeyCode.RightArrow))
  114. {
  115. rt.anchoredPosition = new Vector2(cpos.x + .1f, cpos.y);
  116. }
  117. else if (Input.GetKey(KeyCode.UpArrow))
  118. {
  119. rt.anchoredPosition = new Vector2(cpos.x, cpos.y + .1f);
  120. }
  121. else if (Input.GetKey(KeyCode.DownArrow))
  122. {
  123. rt.anchoredPosition = new Vector2(cpos.x, cpos.y - .1f);
  124. }
  125. else
  126. return;
  127. Logger.log.Debug($"Position now at {rt.anchoredPosition}");
  128. #endif
  129. #if ADJUST_INFO_ICON_UI_KEYS
  130. var rt = icon.rectTransform;
  131. if (Input.GetKey(KeyCode.Z))
  132. { // adjust anchormin
  133. var cpos = rt.anchorMin;
  134. if (Input.GetKey(KeyCode.LeftArrow))
  135. {
  136. rt.anchorMin = new Vector2(cpos.x - .001f, cpos.y);
  137. }
  138. else if (Input.GetKey(KeyCode.RightArrow))
  139. {
  140. rt.anchorMin = new Vector2(cpos.x + .001f, cpos.y);
  141. }
  142. else if (Input.GetKey(KeyCode.UpArrow))
  143. {
  144. rt.anchorMin = new Vector2(cpos.x, cpos.y + .001f);
  145. }
  146. else if (Input.GetKey(KeyCode.DownArrow))
  147. {
  148. rt.anchorMin = new Vector2(cpos.x, cpos.y - .001f);
  149. }
  150. else
  151. return;
  152. Logger.log.Debug($"Anchor min now at {rt.anchorMin}");
  153. }
  154. else if(Input.GetKey(KeyCode.X))
  155. { // adjust anchorMax
  156. var cpos = rt.anchorMax;
  157. if (Input.GetKey(KeyCode.LeftArrow))
  158. {
  159. rt.anchorMax = new Vector2(cpos.x - .001f, cpos.y);
  160. }
  161. else if (Input.GetKey(KeyCode.RightArrow))
  162. {
  163. rt.anchorMax = new Vector2(cpos.x + .001f, cpos.y);
  164. }
  165. else if (Input.GetKey(KeyCode.UpArrow))
  166. {
  167. rt.anchorMax = new Vector2(cpos.x, cpos.y + .001f);
  168. }
  169. else if (Input.GetKey(KeyCode.DownArrow))
  170. {
  171. rt.anchorMax = new Vector2(cpos.x, cpos.y - .001f);
  172. }
  173. else
  174. return;
  175. Logger.log.Debug($"Anchor max now at {rt.anchorMax}");
  176. }
  177. else
  178. {
  179. var cpos = rt.anchoredPosition;
  180. if (Input.GetKey(KeyCode.LeftArrow))
  181. {
  182. rt.anchoredPosition = new Vector2(cpos.x - .1f, cpos.y);
  183. }
  184. else if (Input.GetKey(KeyCode.RightArrow))
  185. {
  186. rt.anchoredPosition = new Vector2(cpos.x + .1f, cpos.y);
  187. }
  188. else if (Input.GetKey(KeyCode.UpArrow))
  189. {
  190. rt.anchoredPosition = new Vector2(cpos.x, cpos.y + .1f);
  191. }
  192. else if (Input.GetKey(KeyCode.DownArrow))
  193. {
  194. rt.anchoredPosition = new Vector2(cpos.x, cpos.y - .1f);
  195. }
  196. else
  197. return;
  198. Logger.log.Debug($"Position now at {rt.anchoredPosition}");
  199. }
  200. #endif
  201. }
  202. #endif
  203. }
  204. }