BackgroundSelectorPane.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class BackgroundSelectorPane : BasePane
  6. {
  7. private EnvironmentManager environmentManager;
  8. private Dropdown bgDropdown;
  9. private Button prevBGButton;
  10. private Button nextBGButton;
  11. public BackgroundSelectorPane(EnvironmentManager environmentManager)
  12. {
  13. this.environmentManager = environmentManager;
  14. int theaterIndex = Constants.BGList.FindIndex(bg => bg == "Theater");
  15. List<string> bgList = new List<string>(Translation.GetList("bgNames", Constants.BGList));
  16. if (Constants.MyRoomCustomBGIndex >= 0)
  17. {
  18. foreach (KeyValuePair<string, string> kvp in Constants.MyRoomCustomBGList)
  19. {
  20. bgList.Add(kvp.Value);
  21. }
  22. }
  23. this.bgDropdown = new Dropdown(bgList.ToArray(), theaterIndex);
  24. this.bgDropdown.SelectionChange += (s, a) =>
  25. {
  26. if (updating) return;
  27. int selectedIndex = this.bgDropdown.SelectedItemIndex;
  28. bool isCreative = this.bgDropdown.SelectedItemIndex >= Constants.MyRoomCustomBGIndex;
  29. string bg = isCreative
  30. ? Constants.MyRoomCustomBGList[selectedIndex - Constants.MyRoomCustomBGIndex].Key
  31. : Constants.BGList[selectedIndex];
  32. environmentManager.ChangeBackground(bg, isCreative);
  33. };
  34. this.prevBGButton = new Button("<");
  35. this.prevBGButton.ControlEvent += (s, a) => this.bgDropdown.Step(-1);
  36. this.nextBGButton = new Button(">");
  37. this.nextBGButton.ControlEvent += (s, a) => this.bgDropdown.Step(1);
  38. }
  39. protected override void ReloadTranslation()
  40. {
  41. List<string> bgList = new List<string>(Translation.GetList("bgNames", Constants.BGList));
  42. if (Constants.MyRoomCustomBGIndex >= 0)
  43. {
  44. foreach (KeyValuePair<string, string> kvp in Constants.MyRoomCustomBGList)
  45. {
  46. bgList.Add(kvp.Value);
  47. }
  48. }
  49. updating = true;
  50. this.bgDropdown.SetDropdownItems(bgList.ToArray());
  51. updating = false;
  52. }
  53. public override void Draw()
  54. {
  55. float arrowButtonSize = 30;
  56. GUILayoutOption[] arrowLayoutOptions = {
  57. GUILayout.Width(arrowButtonSize),
  58. GUILayout.Height(arrowButtonSize)
  59. };
  60. float dropdownButtonHeight = arrowButtonSize;
  61. float dropdownButtonWidth = 153f;
  62. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  63. GUILayout.Height(dropdownButtonHeight),
  64. GUILayout.Width(dropdownButtonWidth)
  65. };
  66. GUILayout.BeginHorizontal();
  67. this.prevBGButton.Draw(arrowLayoutOptions);
  68. this.bgDropdown.Draw(dropdownLayoutOptions);
  69. this.nextBGButton.Draw(arrowLayoutOptions);
  70. GUILayout.EndHorizontal();
  71. }
  72. }
  73. }