BackgroundSelectorPane.cs 3.0 KB

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