MyRoomPropsPane.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class MyRoomPropsPane : BasePane
  6. {
  7. private readonly PropManager propManager;
  8. private readonly Dropdown propCategoryDropdown;
  9. private Vector2 propListScrollPos;
  10. private string SelectedCategory => Constants.MyRoomPropCategories[propCategoryDropdown.SelectedItemIndex];
  11. private List<MyRoomItem> myRoomPropList;
  12. private string currentCategory;
  13. public MyRoomPropsPane(PropManager propManager)
  14. {
  15. this.propManager = propManager;
  16. propCategoryDropdown = new Dropdown(Translation.GetArray("doguCategories", Constants.MyRoomPropCategories));
  17. propCategoryDropdown.SelectionChange += (s, a) => ChangePropCategory(SelectedCategory);
  18. ChangePropCategory(SelectedCategory);
  19. }
  20. protected override void ReloadTranslation()
  21. {
  22. propCategoryDropdown.SetDropdownItems(
  23. Translation.GetArray("doguCategories", Constants.MyRoomPropCategories)
  24. );
  25. }
  26. public override void Draw()
  27. {
  28. const float dropdownButtonHeight = 30f;
  29. const float dropdownButtonWidth = 120f;
  30. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  31. GUILayout.Height(dropdownButtonHeight),
  32. GUILayout.Width(dropdownButtonWidth)
  33. };
  34. GUILayout.BeginHorizontal();
  35. GUILayout.FlexibleSpace();
  36. propCategoryDropdown.Draw(dropdownLayoutOptions);
  37. GUILayout.FlexibleSpace();
  38. GUILayout.EndHorizontal();
  39. Rect windowRect = parent.WindowRect;
  40. float windowHeight = windowRect.height;
  41. float windowWidth = windowRect.width;
  42. const float offsetTop = 80f;
  43. const int columns = 3;
  44. float buttonSize = (windowWidth / columns) - 10f;
  45. int listCount = myRoomPropList.Count;
  46. Rect positionRect = new Rect(
  47. 5f, offsetTop + dropdownButtonHeight, windowWidth - 10f, windowHeight - 145f
  48. );
  49. Rect viewRect = new Rect(
  50. 0f, 0f, buttonSize * columns, (buttonSize * Mathf.Ceil(listCount / (float)columns)) + 5f
  51. );
  52. propListScrollPos = GUI.BeginScrollView(positionRect, propListScrollPos, viewRect);
  53. for (int i = 0; i < listCount; i++)
  54. {
  55. float x = i % columns * buttonSize;
  56. float y = i / columns * buttonSize;
  57. MyRoomItem myRoomItem = myRoomPropList[i];
  58. Rect iconRect = new Rect(x, y, buttonSize, buttonSize);
  59. if (GUI.Button(iconRect, "")) propManager.AddMyRoomProp(myRoomItem);
  60. GUI.DrawTexture(iconRect, myRoomItem.Icon);
  61. }
  62. GUI.EndScrollView();
  63. }
  64. private void ChangePropCategory(string category)
  65. {
  66. if (currentCategory == category) return;
  67. currentCategory = category;
  68. propListScrollPos = Vector2.zero;
  69. myRoomPropList = Constants.MyRoomPropDict[category];
  70. if (myRoomPropList[0].Icon == null)
  71. {
  72. foreach (MyRoomItem item in myRoomPropList)
  73. {
  74. item.Icon = (Texture2D)MyRoomCustom.PlacementData.GetData(item.ID).GetThumbnail();
  75. }
  76. }
  77. }
  78. }
  79. }