| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Builder |
| | 9 | | { |
| | 10 | | public interface IPublishProjectDetailView |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// If the publish is canceled this action will be called |
| | 14 | | /// </summary> |
| | 15 | | public event Action OnCancel; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// If the publish button is pressed this action will be called |
| | 19 | | /// </summary> |
| | 20 | | public event Action OnPublishButtonPressed; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Set the project to publish |
| | 24 | | /// </summary> |
| | 25 | | /// <param name="scene"></param> |
| | 26 | | void SetProjectToPublish(BuilderScene scene); |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// This will show the detail modal |
| | 30 | | /// </summary> |
| | 31 | | void Show(); |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// This will hide the detail modal |
| | 35 | | /// </summary> |
| | 36 | | void Hide(); |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Dispose the view |
| | 40 | | /// </summary> |
| | 41 | | void Dispose(); |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public class PublishProjectDetailView : BaseComponentView, IPublishProjectDetailView |
| | 45 | | { |
| | 46 | | private const string SCREENSHOT_TEXT = @"{0} parcel = {1}x{2}m"; |
| | 47 | |
|
| | 48 | | //TODO: This will be implemented in the future |
| | 49 | | public event Action OnProjectRotate; |
| | 50 | | public event Action OnCancel; |
| | 51 | | public event Action OnPublishButtonPressed; |
| | 52 | |
|
| | 53 | | [SerializeField] internal Button cancelButton; |
| | 54 | | [SerializeField] internal Button publishButton; |
| | 55 | |
|
| | 56 | | //TODO: This functionality will be implemented in the future |
| | 57 | | [SerializeField] internal Button rotateLeftButton; |
| | 58 | | [SerializeField] internal Button rotateRightButton; |
| | 59 | |
|
| | 60 | | [SerializeField] internal Button zoomInButton; |
| | 61 | | [SerializeField] internal Button zoomOutButton; |
| | 62 | | [SerializeField] internal Button resetToLandButton; |
| | 63 | | [SerializeField] internal Image mapImage; |
| | 64 | |
|
| | 65 | | [SerializeField] internal RawImage sceneScreenshotImage; |
| | 66 | |
|
| | 67 | | [SerializeField] internal ModalComponentView modal; |
| | 68 | |
|
| | 69 | | [SerializeField] internal TMP_Text sceneScreenshotParcelText; |
| | 70 | | [SerializeField] internal LimitInputField nameInputField; |
| | 71 | | [SerializeField] internal LimitInputField descriptionInputField; |
| | 72 | |
|
| | 73 | | [SerializeField] internal TMP_Dropdown landsDropDown; |
| | 74 | |
|
| | 75 | | internal BuilderScene scene; |
| | 76 | |
|
| 0 | 77 | | internal Dictionary<string, LandWithAccess> landsDropdownDictionary = new Dictionary<string, LandWithAccess>(); |
| | 78 | |
|
| | 79 | | public override void RefreshControl() |
| | 80 | | { |
| 0 | 81 | | if (scene == null) |
| 0 | 82 | | return; |
| | 83 | |
|
| 0 | 84 | | SetProjectToPublish(scene); |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | public override void Awake() |
| | 88 | | { |
| 0 | 89 | | base.Awake(); |
| 0 | 90 | | modal.OnCloseAction += CancelPublish; |
| | 91 | |
|
| 0 | 92 | | cancelButton.onClick.AddListener(CancelButtonPressed); |
| 0 | 93 | | publishButton.onClick.AddListener(PublishButtonPressed); |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | public override void Dispose() |
| | 97 | | { |
| 0 | 98 | | base.Dispose(); |
| | 99 | |
|
| 0 | 100 | | modal.OnCloseAction -= CancelPublish; |
| | 101 | |
|
| 0 | 102 | | cancelButton.onClick.RemoveAllListeners(); |
| 0 | 103 | | publishButton.onClick.RemoveAllListeners(); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetProjectToPublish(BuilderScene scene) |
| | 107 | | { |
| 0 | 108 | | this.scene = scene; |
| | 109 | |
|
| | 110 | | //We set the screenshot |
| 0 | 111 | | sceneScreenshotImage.texture = scene.sceneScreenshotTexture; |
| | 112 | |
|
| | 113 | | //We set the scene info |
| 0 | 114 | | nameInputField.SetText(scene.manifest.project.title); |
| 0 | 115 | | descriptionInputField.SetText(scene.manifest.project.description); |
| 0 | 116 | | sceneScreenshotParcelText.text = GetScreenshotText(scene.scene.sceneData.parcels); |
| | 117 | |
|
| | 118 | | //We fill the land drop down |
| 0 | 119 | | FillLandDropDown(); |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | private string GetScreenshotText(Vector2Int[] parcels) |
| | 123 | | { |
| 0 | 124 | | Vector2Int sceneSize = BIWUtils.GetSceneSize(parcels); |
| 0 | 125 | | return string.Format(SCREENSHOT_TEXT, parcels.Length, sceneSize.x * DCL.Configuration.ParcelSettings.PARCEL_ |
| | 126 | | } |
| | 127 | |
|
| | 128 | | private void FillLandDropDown() |
| | 129 | | { |
| 0 | 130 | | landsDropdownDictionary.Clear(); |
| | 131 | |
|
| 0 | 132 | | List<TMP_Dropdown.OptionData> landsOption = new List<TMP_Dropdown.OptionData>(); |
| 0 | 133 | | foreach (var land in DataStore.i.builderInWorld.landsWithAccess.Get()) |
| | 134 | | { |
| 0 | 135 | | TMP_Dropdown.OptionData landData = new TMP_Dropdown.OptionData(); |
| 0 | 136 | | string text = land.name + " " + land.baseCoords.x + "," + land.baseCoords.y; |
| 0 | 137 | | landData.text = text; |
| 0 | 138 | | landsOption.Add(landData); |
| 0 | 139 | | landsDropdownDictionary.Add(text, land); |
| | 140 | | } |
| | 141 | |
|
| 0 | 142 | | landsDropDown.options = landsOption; |
| 0 | 143 | | } |
| | 144 | |
|
| 0 | 145 | | public void Show() { modal.Show(); } |
| | 146 | |
|
| 0 | 147 | | public void Hide() { modal.Hide(); } |
| | 148 | |
|
| | 149 | | private void PublishButtonPressed() |
| | 150 | | { |
| 0 | 151 | | modal.Hide(); |
| 0 | 152 | | OnPublishButtonPressed?.Invoke(); |
| 0 | 153 | | } |
| | 154 | |
|
| 0 | 155 | | private void CancelPublish() { OnCancel?.Invoke(); } |
| | 156 | |
|
| | 157 | | private void CancelButtonPressed() |
| | 158 | | { |
| 0 | 159 | | modal.Hide(); |
| 0 | 160 | | CancelPublish(); |
| 0 | 161 | | } |
| | 162 | |
|
| | 163 | | } |
| | 164 | | } |