MyRoomPropsPane.cs 3.4 KB

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