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.

92 lines
3.4 KiB

  1. using CustomUI.BeatSaber;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using TMPro;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using VRUI;
  11. namespace BSIPA_ModList.UI
  12. {
  13. internal class ModInfoViewController : VRUIViewController
  14. {
  15. internal Sprite Icon;
  16. internal string Name;
  17. internal string Version;
  18. internal string Author;
  19. internal string Description;
  20. internal bool CanUpdate;
  21. private ModInfoView view;
  22. public void Init(Sprite icon, string name, string version, string author, string description, bool canUpdate)
  23. {
  24. Icon = icon;
  25. Name = name;
  26. Version = version;
  27. Author = author;
  28. Description = description;
  29. CanUpdate = canUpdate;
  30. rectTransform.anchorMin = new Vector2(0f, 0f);
  31. rectTransform.anchorMax = new Vector2(0.4f, 1f);
  32. var go = new GameObject("Info View");
  33. go.SetActive(false);
  34. view = go.AddComponent<ModInfoView>();
  35. view.gameObject.AddComponent<RectMask2D>();
  36. view.Init(this);
  37. var rt = view.transform as RectTransform;
  38. rt.SetParent(transform);
  39. rt.anchorMin = new Vector2(0f, 0f);
  40. rt.anchorMax = new Vector2(1f, 1f);
  41. rt.anchoredPosition = new Vector2(0.2f, 0f);
  42. go.SetActive(true);
  43. }
  44. }
  45. internal class ModInfoView : MonoBehaviour
  46. {
  47. private ModInfoViewController controller;
  48. private TextMeshProUGUI titleText;
  49. private TextMeshProUGUI authorText;
  50. private TextMeshProUGUI descText;
  51. public void Init(ModInfoViewController controller)
  52. {
  53. this.controller = controller;
  54. var rectTransform = transform as RectTransform;
  55. rectTransform.sizeDelta = new Vector2(60f, 10f);
  56. titleText = BeatSaberUI.CreateText(rectTransform, $"{controller.Name} <size=60%>{controller.Version}", new Vector2(0f, 0f));
  57. titleText.rectTransform.anchorMin = new Vector2(0f, .8f);
  58. titleText.rectTransform.anchorMax = new Vector2(1f, 1f);
  59. titleText.fontSize = 6f;
  60. authorText = BeatSaberUI.CreateText(rectTransform, controller.Author, new Vector2(0f, 0f));
  61. titleText.rectTransform.anchorMin = new Vector2(0f, .6f);
  62. titleText.rectTransform.anchorMax = new Vector2(1f, .8f);
  63. authorText.fontSize = 3f;
  64. descText = BeatSaberUI.CreateText(rectTransform, controller.Description, new Vector2(0f, 0f));
  65. descText.rectTransform.anchorMin = new Vector2(0f, .0f);
  66. descText.rectTransform.anchorMax = new Vector2(1f, .6f);
  67. }
  68. public void OnUpdate()
  69. {
  70. var cpos = titleText.rectTransform.anchoredPosition;
  71. if (Input.GetKeyDown(KeyCode.LeftArrow))
  72. titleText.rectTransform.anchoredPosition = new Vector2(cpos.x - .1f, cpos.y);
  73. if (Input.GetKeyDown(KeyCode.RightArrow))
  74. titleText.rectTransform.anchoredPosition = new Vector2(cpos.x + .1f, cpos.y);
  75. if (Input.GetKeyDown(KeyCode.UpArrow))
  76. titleText.rectTransform.anchoredPosition = new Vector2(cpos.x, cpos.y + .1f);
  77. if (Input.GetKeyDown(KeyCode.DownArrow))
  78. titleText.rectTransform.anchoredPosition = new Vector2(cpos.x, cpos.y - .1f);
  79. }
  80. }
  81. }