MyRoomPropsPane.cs 3.5 KB

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