PropsPane.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. internal class PropsPane : BasePane
  7. {
  8. private PropManager propManager;
  9. private string currentCategory;
  10. private string SelectedCategory => Constants.DoguCategories[this.doguCategoryDropdown.SelectedItemIndex];
  11. private Dropdown doguCategoryDropdown;
  12. private Dropdown doguDropdown;
  13. private Button addDoguButton;
  14. private Button nextDoguButton;
  15. private Button prevDoguButton;
  16. private Button nextDoguCategoryButton;
  17. private Button prevDoguCategoryButton;
  18. private string header;
  19. private static bool handItemsReady = false;
  20. private bool itemSelectorEnabled = true;
  21. public PropsPane(PropManager propManager)
  22. {
  23. this.header = Translation.Get("propsPane", "header");
  24. this.propManager = propManager;
  25. handItemsReady = Constants.HandItemsInitialized;
  26. if (!handItemsReady) Constants.MenuFilesChange += InitializeHandItems;
  27. this.doguCategoryDropdown = new Dropdown(Translation.GetArray("doguCategories", Constants.DoguCategories));
  28. this.doguCategoryDropdown.SelectionChange += (s, a) => ChangeDoguCategory(SelectedCategory);
  29. this.doguDropdown = new Dropdown(new[] { string.Empty });
  30. this.addDoguButton = new Button("+");
  31. this.addDoguButton.ControlEvent += (s, a) => SpawnObject();
  32. this.nextDoguButton = new Button(">");
  33. this.nextDoguButton.ControlEvent += (s, a) => this.doguDropdown.Step(1);
  34. this.prevDoguButton = new Button("<");
  35. this.prevDoguButton.ControlEvent += (s, a) => this.doguDropdown.Step(-1);
  36. this.nextDoguCategoryButton = new Button(">");
  37. this.nextDoguCategoryButton.ControlEvent += (s, a) => this.doguCategoryDropdown.Step(1);
  38. this.prevDoguCategoryButton = new Button("<");
  39. this.prevDoguCategoryButton.ControlEvent += (s, a) => this.doguCategoryDropdown.Step(-1);
  40. ChangeDoguCategory(SelectedCategory);
  41. }
  42. protected override void ReloadTranslation()
  43. {
  44. this.header = Translation.Get("propsPane", "header");
  45. this.doguCategoryDropdown.SetDropdownItems(
  46. Translation.GetArray("doguCategories", Constants.DoguCategories)
  47. );
  48. string category = SelectedCategory;
  49. string[] translationArray;
  50. if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem] && !handItemsReady)
  51. {
  52. translationArray = new[] { Translation.Get("systemMessage", "initializing") };
  53. }
  54. else
  55. {
  56. translationArray = GetTranslations(category);
  57. }
  58. doguDropdown.SetDropdownItems(translationArray);
  59. }
  60. public override void Draw()
  61. {
  62. float arrowButtonSize = 30;
  63. GUILayoutOption[] arrowLayoutOptions = {
  64. GUILayout.Width(arrowButtonSize),
  65. GUILayout.Height(arrowButtonSize)
  66. };
  67. float dropdownButtonHeight = arrowButtonSize;
  68. float dropdownButtonWidth = 120f;
  69. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  70. GUILayout.Height(dropdownButtonHeight),
  71. GUILayout.Width(dropdownButtonWidth)
  72. };
  73. // MiscGUI.Header(this.header);
  74. // MiscGUI.WhiteLine();
  75. GUILayout.BeginHorizontal();
  76. this.prevDoguCategoryButton.Draw(arrowLayoutOptions);
  77. this.doguCategoryDropdown.Draw(dropdownLayoutOptions);
  78. this.nextDoguCategoryButton.Draw(arrowLayoutOptions);
  79. GUILayout.EndHorizontal();
  80. GUI.enabled = itemSelectorEnabled;
  81. GUILayout.BeginHorizontal();
  82. this.doguDropdown.Draw(dropdownLayoutOptions);
  83. this.prevDoguButton.Draw(arrowLayoutOptions);
  84. this.nextDoguButton.Draw(arrowLayoutOptions);
  85. this.addDoguButton.Draw(arrowLayoutOptions);
  86. GUILayout.EndHorizontal();
  87. GUI.enabled = true;
  88. }
  89. private void InitializeHandItems(object sender, MenuFilesEventArgs args)
  90. {
  91. if (args.Type == MenuFilesEventArgs.EventType.HandItems)
  92. {
  93. handItemsReady = true;
  94. string selectedCategory = SelectedCategory;
  95. if (selectedCategory == Constants.customDoguCategories[Constants.DoguCategory.HandItem])
  96. {
  97. ChangeDoguCategory(selectedCategory, true);
  98. }
  99. }
  100. }
  101. private void ChangeDoguCategory(string category, bool force = false)
  102. {
  103. if (category != currentCategory || force)
  104. {
  105. currentCategory = category;
  106. string[] translationArray;
  107. if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem] && !handItemsReady)
  108. {
  109. translationArray = new[] { Translation.Get("systemMessage", "initializing") };
  110. itemSelectorEnabled = false;
  111. }
  112. else
  113. {
  114. translationArray = GetTranslations(category);
  115. itemSelectorEnabled = true;
  116. }
  117. doguDropdown.SetDropdownItems(translationArray, 0);
  118. }
  119. }
  120. private string[] GetTranslations(string category)
  121. {
  122. IEnumerable<string> itemList = Constants.DoguDict[category];
  123. if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem])
  124. {
  125. itemList = itemList.Select(item =>
  126. {
  127. string handItemAsOdogu = Utility.HandItemToOdogu(item);
  128. if (Translation.Has("propNames", handItemAsOdogu)) return handItemAsOdogu;
  129. else return item;
  130. });
  131. }
  132. string translationCategory = category == Constants.customDoguCategories[Constants.DoguCategory.BGSmall]
  133. ? "bgNames"
  134. : "propNames";
  135. return Translation.GetArray(translationCategory, itemList);
  136. }
  137. private void SpawnObject()
  138. {
  139. string assetName = Constants.DoguDict[SelectedCategory][this.doguDropdown.SelectedItemIndex];
  140. if (SelectedCategory == Constants.customDoguCategories[Constants.DoguCategory.BGSmall])
  141. {
  142. this.propManager.SpawnBG(assetName);
  143. }
  144. else
  145. {
  146. this.propManager.SpawnObject(assetName);
  147. }
  148. }
  149. }
  150. }