BackgroundSelectorPane.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. 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("bgDropdown", 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. int selectedIndex = this.bgDropdown.SelectedItemIndex;
  27. bool isCreative = this.bgDropdown.SelectedItemIndex >= Constants.MyRoomCustomBGIndex;
  28. string bg = isCreative
  29. ? Constants.MyRoomCustomBGList[selectedIndex - Constants.MyRoomCustomBGIndex].Key
  30. : Constants.BGList[selectedIndex];
  31. environmentManager.ChangeBackground(bg, isCreative);
  32. };
  33. this.prevBGButton = new Button("<");
  34. this.prevBGButton.ControlEvent += (s, a) => this.bgDropdown.Step(-1);
  35. this.nextBGButton = new Button(">");
  36. this.nextBGButton.ControlEvent += (s, a) => this.bgDropdown.Step(1);
  37. }
  38. public override void Draw(params GUILayoutOption[] layoutOptions)
  39. {
  40. float arrowButtonSize = 30;
  41. GUILayoutOption[] arrowLayoutOptions = {
  42. GUILayout.Width(arrowButtonSize),
  43. GUILayout.Height(arrowButtonSize)
  44. };
  45. float dropdownButtonHeight = arrowButtonSize;
  46. float dropdownButtonWidth = 153f;
  47. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  48. GUILayout.Height(dropdownButtonHeight),
  49. GUILayout.Width(dropdownButtonWidth)
  50. };
  51. GUILayout.BeginHorizontal();
  52. this.prevBGButton.Draw(arrowLayoutOptions);
  53. this.bgDropdown.Draw(dropdownLayoutOptions);
  54. this.nextBGButton.Draw(arrowLayoutOptions);
  55. GUILayout.EndHorizontal();
  56. }
  57. }
  58. }