PropManagerPane.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class PropManagerPane : BasePane
  5. {
  6. private readonly PropManager propManager;
  7. private readonly Dropdown propDropdown;
  8. private readonly Button previousPropButton;
  9. private readonly Button nextPropButton;
  10. private readonly Toggle dragPointToggle;
  11. private readonly Toggle gizmoToggle;
  12. private readonly Toggle shadowCastingToggle;
  13. private readonly Button deletePropButton;
  14. private readonly Button copyPropButton;
  15. private string propManagerHeader;
  16. private int CurrentDoguIndex => propManager.CurrentDoguIndex;
  17. public PropManagerPane(PropManager propManager)
  18. {
  19. this.propManager = propManager;
  20. this.propManager.DoguListChange += (s, a) =>
  21. {
  22. UpdatePropList();
  23. UpdateToggles();
  24. };
  25. this.propManager.DoguSelectChange += (s, a) =>
  26. {
  27. updating = true;
  28. propDropdown.SelectedItemIndex = CurrentDoguIndex;
  29. updating = false;
  30. UpdateToggles();
  31. };
  32. propDropdown = new Dropdown(this.propManager.PropNameList);
  33. propDropdown.SelectionChange += (s, a) =>
  34. {
  35. if (updating) return;
  36. this.propManager.SetCurrentDogu(propDropdown.SelectedItemIndex);
  37. UpdateToggles();
  38. };
  39. previousPropButton = new Button("<");
  40. previousPropButton.ControlEvent += (s, a) => propDropdown.Step(-1);
  41. nextPropButton = new Button(">");
  42. nextPropButton.ControlEvent += (s, a) => propDropdown.Step(1);
  43. dragPointToggle = new Toggle(Translation.Get("propManagerPane", "dragPointToggle"));
  44. dragPointToggle.ControlEvent += (s, a) =>
  45. {
  46. if (updating || this.propManager.DoguCount == 0) return;
  47. this.propManager.CurrentDogu.DragPointEnabled = dragPointToggle.Value;
  48. };
  49. gizmoToggle = new Toggle(Translation.Get("propManagerPane", "gizmoToggle"));
  50. gizmoToggle.ControlEvent += (s, a) =>
  51. {
  52. if (updating || this.propManager.DoguCount == 0) return;
  53. this.propManager.CurrentDogu.GizmoEnabled = gizmoToggle.Value;
  54. };
  55. shadowCastingToggle = new Toggle(Translation.Get("propManagerPane", "shadowCastingToggle"));
  56. shadowCastingToggle.ControlEvent += (s, a) =>
  57. {
  58. if (updating || this.propManager.DoguCount == 0) return;
  59. this.propManager.CurrentDogu.ShadowCasting = shadowCastingToggle.Value;
  60. };
  61. copyPropButton = new Button(Translation.Get("propManagerPane", "copyButton"));
  62. copyPropButton.ControlEvent += (s, a) => this.propManager.CopyDogu(CurrentDoguIndex);
  63. deletePropButton = new Button(Translation.Get("propManagerPane", "deleteButton"));
  64. deletePropButton.ControlEvent += (s, a) => this.propManager.RemoveDogu(CurrentDoguIndex);
  65. propManagerHeader = Translation.Get("propManagerPane", "header");
  66. }
  67. protected override void ReloadTranslation()
  68. {
  69. dragPointToggle.Label = Translation.Get("propManagerPane", "dragPointToggle");
  70. gizmoToggle.Label = Translation.Get("propManagerPane", "gizmoToggle");
  71. shadowCastingToggle.Label = Translation.Get("propManagerPane", "shadowCastingToggle");
  72. copyPropButton.Label = Translation.Get("propManagerPane", "copyButton");
  73. deletePropButton.Label = Translation.Get("propManagerPane", "deleteButton");
  74. propManagerHeader = Translation.Get("propManagerPane", "header");
  75. }
  76. public override void Draw()
  77. {
  78. const float buttonHeight = 30;
  79. GUILayoutOption[] arrowLayoutOptions = {
  80. GUILayout.Width(buttonHeight),
  81. GUILayout.Height(buttonHeight)
  82. };
  83. const float dropdownButtonWidth = 140f;
  84. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  85. GUILayout.Height(buttonHeight),
  86. GUILayout.Width(dropdownButtonWidth)
  87. };
  88. MpsGui.Header(propManagerHeader);
  89. MpsGui.WhiteLine();
  90. GUI.enabled = propManager.DoguCount > 0;
  91. GUILayout.BeginHorizontal();
  92. propDropdown.Draw(dropdownLayoutOptions);
  93. previousPropButton.Draw(arrowLayoutOptions);
  94. nextPropButton.Draw(arrowLayoutOptions);
  95. GUILayout.EndHorizontal();
  96. GUILayoutOption noExpandWidth = GUILayout.ExpandWidth(false);
  97. GUILayout.BeginHorizontal();
  98. dragPointToggle.Draw(noExpandWidth);
  99. gizmoToggle.Draw(noExpandWidth);
  100. copyPropButton.Draw(noExpandWidth);
  101. deletePropButton.Draw(noExpandWidth);
  102. GUILayout.EndHorizontal();
  103. GUILayout.BeginHorizontal();
  104. shadowCastingToggle.Draw(noExpandWidth);
  105. GUILayout.EndHorizontal();
  106. GUI.enabled = true;
  107. }
  108. private void UpdatePropList()
  109. {
  110. updating = true;
  111. propDropdown.SetDropdownItems(propManager.PropNameList, CurrentDoguIndex);
  112. updating = false;
  113. }
  114. private void UpdateToggles()
  115. {
  116. DragPointDogu dogu = propManager.CurrentDogu;
  117. if (dogu == null) return;
  118. updating = true;
  119. dragPointToggle.Value = dogu.DragPointEnabled;
  120. gizmoToggle.Value = dogu.GizmoEnabled;
  121. shadowCastingToggle.Value = dogu.ShadowCasting;
  122. updating = false;
  123. }
  124. }
  125. }