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.

223 lines
7.7 KiB

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