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.

222 lines
7.6 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.enableWordWrapping = true;
  67. descText.overflowMode = TextOverflowModes.ScrollRect;
  68. icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent<Image>();
  69. icon.gameObject.SetActive(false);
  70. icon.rectTransform.SetParent(rectTransform, false);
  71. icon.rectTransform.anchorMin = new Vector2(0.5f, 0.44f);
  72. icon.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
  73. icon.rectTransform.sizeDelta = new Vector2(60f, 10f);
  74. icon.rectTransform.anchoredPosition = new Vector2(-27.8f, 27.3f);
  75. icon.sprite = controller.Icon;
  76. icon.preserveAspect = true;
  77. icon.useSpriteMesh = true;
  78. icon.material = UIUtilities.NoGlowMaterial;
  79. icon.gameObject.SetActive(true);
  80. }
  81. #if DEBUG
  82. #if ADJUST_INFO_TEXT_UI_KEYS
  83. private int currentItem = 0;
  84. #endif
  85. public void Update()
  86. {
  87. #if ADJUST_INFO_TEXT_UI_KEYS
  88. RectTransform rt;
  89. switch (currentItem)
  90. {
  91. default:
  92. currentItem = 0;
  93. goto case 0; // idk why this is needed tbh
  94. case 0:
  95. rt = titleText.rectTransform;
  96. break;
  97. case 1:
  98. rt = authorText.rectTransform;
  99. break;
  100. case 2:
  101. rt = descText.rectTransform;
  102. break;
  103. }
  104. if (Input.GetKeyDown(KeyCode.N))
  105. currentItem++;
  106. var cpos = rt.anchoredPosition;
  107. if (Input.GetKey(KeyCode.LeftArrow))
  108. {
  109. rt.anchoredPosition = new Vector2(cpos.x - .1f, cpos.y);
  110. }
  111. else if (Input.GetKey(KeyCode.RightArrow))
  112. {
  113. rt.anchoredPosition = new Vector2(cpos.x + .1f, cpos.y);
  114. }
  115. else if (Input.GetKey(KeyCode.UpArrow))
  116. {
  117. rt.anchoredPosition = new Vector2(cpos.x, cpos.y + .1f);
  118. }
  119. else if (Input.GetKey(KeyCode.DownArrow))
  120. {
  121. rt.anchoredPosition = new Vector2(cpos.x, cpos.y - .1f);
  122. }
  123. else
  124. return;
  125. Logger.log.Debug($"Position now at {rt.anchoredPosition}");
  126. #endif
  127. #if ADJUST_INFO_ICON_UI_KEYS
  128. var rt = icon.rectTransform;
  129. if (Input.GetKey(KeyCode.Z))
  130. { // adjust anchormin
  131. var cpos = rt.anchorMin;
  132. if (Input.GetKey(KeyCode.LeftArrow))
  133. {
  134. rt.anchorMin = new Vector2(cpos.x - .001f, cpos.y);
  135. }
  136. else if (Input.GetKey(KeyCode.RightArrow))
  137. {
  138. rt.anchorMin = new Vector2(cpos.x + .001f, cpos.y);
  139. }
  140. else if (Input.GetKey(KeyCode.UpArrow))
  141. {
  142. rt.anchorMin = new Vector2(cpos.x, cpos.y + .001f);
  143. }
  144. else if (Input.GetKey(KeyCode.DownArrow))
  145. {
  146. rt.anchorMin = new Vector2(cpos.x, cpos.y - .001f);
  147. }
  148. else
  149. return;
  150. Logger.log.Debug($"Anchor min now at {rt.anchorMin}");
  151. }
  152. else if(Input.GetKey(KeyCode.X))
  153. { // adjust anchorMax
  154. var cpos = rt.anchorMax;
  155. if (Input.GetKey(KeyCode.LeftArrow))
  156. {
  157. rt.anchorMax = new Vector2(cpos.x - .001f, cpos.y);
  158. }
  159. else if (Input.GetKey(KeyCode.RightArrow))
  160. {
  161. rt.anchorMax = new Vector2(cpos.x + .001f, cpos.y);
  162. }
  163. else if (Input.GetKey(KeyCode.UpArrow))
  164. {
  165. rt.anchorMax = new Vector2(cpos.x, cpos.y + .001f);
  166. }
  167. else if (Input.GetKey(KeyCode.DownArrow))
  168. {
  169. rt.anchorMax = new Vector2(cpos.x, cpos.y - .001f);
  170. }
  171. else
  172. return;
  173. Logger.log.Debug($"Anchor max now at {rt.anchorMax}");
  174. }
  175. else
  176. {
  177. var cpos = rt.anchoredPosition;
  178. if (Input.GetKey(KeyCode.LeftArrow))
  179. {
  180. rt.anchoredPosition = new Vector2(cpos.x - .1f, cpos.y);
  181. }
  182. else if (Input.GetKey(KeyCode.RightArrow))
  183. {
  184. rt.anchoredPosition = new Vector2(cpos.x + .1f, cpos.y);
  185. }
  186. else if (Input.GetKey(KeyCode.UpArrow))
  187. {
  188. rt.anchoredPosition = new Vector2(cpos.x, cpos.y + .1f);
  189. }
  190. else if (Input.GetKey(KeyCode.DownArrow))
  191. {
  192. rt.anchoredPosition = new Vector2(cpos.x, cpos.y - .1f);
  193. }
  194. else
  195. return;
  196. Logger.log.Debug($"Position now at {rt.anchoredPosition}");
  197. }
  198. #endif
  199. }
  200. #endif
  201. }
  202. }