PropManagerPane.cs 5.7 KB

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