| | 1 | | using DCL.Helpers; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface IRealmViewerComponentView |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Event that will be triggered when the Logo button is clicked. |
| | 10 | | /// </summary> |
| | 11 | | Button.ButtonClickedEvent onLogoClick { get; } |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Set the realm label. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="newRealm">New realm.</param> |
| | 17 | | void SetRealm(string newRealm); |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Set the number of users label. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="newNumberOfUsers">New number of users.</param> |
| | 23 | | void SetNumberOfUsers(int newNumberOfUsers); |
| | 24 | | } |
| | 25 | |
|
| | 26 | | public class RealmViewerComponentView : BaseComponentView, IRealmViewerComponentView, IComponentModelConfig |
| | 27 | | { |
| | 28 | | [Header("Prefab References")] |
| | 29 | | [SerializeField] internal HorizontalLayoutGroup horizontalLayoutGroup; |
| | 30 | | [SerializeField] internal TMP_Text realm; |
| | 31 | | [SerializeField] internal TMP_Text numberOfusers; |
| | 32 | | [SerializeField] internal ButtonComponentView logoButton; |
| | 33 | |
|
| | 34 | | [Header("Configuration")] |
| | 35 | | [SerializeField] internal RealmViewerComponentModel model; |
| | 36 | |
|
| 0 | 37 | | public Button.ButtonClickedEvent onLogoClick => logoButton?.onClick; |
| | 38 | |
|
| | 39 | | public void Configure(BaseComponentModel newModel) |
| | 40 | | { |
| 1 | 41 | | model = (RealmViewerComponentModel)newModel; |
| 1 | 42 | | RefreshControl(); |
| 1 | 43 | | } |
| | 44 | |
|
| | 45 | | public override void RefreshControl() |
| | 46 | | { |
| 1 | 47 | | if (model == null) |
| 0 | 48 | | return; |
| | 49 | |
|
| 1 | 50 | | SetRealm(model.realmName); |
| 1 | 51 | | SetNumberOfUsers(model.numberOfUsers); |
| 1 | 52 | | } |
| | 53 | |
|
| | 54 | | public void SetRealm(string newRealm) |
| | 55 | | { |
| 2 | 56 | | model.realmName = newRealm; |
| | 57 | |
|
| 2 | 58 | | if (realm == null) |
| 0 | 59 | | return; |
| | 60 | |
|
| 2 | 61 | | realm.text = newRealm; |
| | 62 | |
|
| 2 | 63 | | RebuildLayouts(); |
| 2 | 64 | | } |
| | 65 | |
|
| | 66 | | public void SetNumberOfUsers(int newNumberOfUsers) |
| | 67 | | { |
| 3 | 68 | | model.numberOfUsers = newNumberOfUsers; |
| | 69 | |
|
| 3 | 70 | | if (numberOfusers == null) |
| 0 | 71 | | return; |
| | 72 | |
|
| 3 | 73 | | numberOfusers.text = ExploreV2CommonUtils.FormatNumberToString(newNumberOfUsers); |
| | 74 | |
|
| 3 | 75 | | RebuildLayouts(); |
| 3 | 76 | | } |
| | 77 | |
|
| | 78 | | internal void RebuildLayouts() |
| | 79 | | { |
| 5 | 80 | | if (horizontalLayoutGroup != null) |
| 5 | 81 | | Utils.ForceRebuildLayoutImmediate(horizontalLayoutGroup.transform as RectTransform); |
| 5 | 82 | | } |
| | 83 | | } |