| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IRealmViewerComponentView |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Fill the model and updates the realm viewer with this data. |
| | 8 | | /// </summary> |
| | 9 | | /// <param name="model">Data to configure the real viewer.</param> |
| | 10 | | void Configure(RealmViewerComponentModel model); |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Set the realm label. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="newRealm">New realm.</param> |
| | 16 | | void SetRealm(string newRealm); |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Set the number of users label. |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="newNumberOfUsers">New number of users.</param> |
| | 22 | | void SetNumberOfUsers(int newNumberOfUsers); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public class RealmViewerComponentView : BaseComponentView, IRealmViewerComponentView |
| | 26 | | { |
| | 27 | | [Header("Prefab References")] |
| | 28 | | [SerializeField] internal TMP_Text realm; |
| | 29 | | [SerializeField] internal TMP_Text numberOfusers; |
| | 30 | |
|
| | 31 | | [Header("Configuration")] |
| | 32 | | [SerializeField] internal RealmViewerComponentModel model; |
| | 33 | |
|
| 34 | 34 | | public override void PostInitialization() { Configure(model); } |
| | 35 | |
|
| | 36 | | public virtual void Configure(RealmViewerComponentModel model) |
| | 37 | | { |
| 18 | 38 | | this.model = model; |
| 18 | 39 | | RefreshControl(); |
| 18 | 40 | | } |
| | 41 | |
|
| | 42 | | public override void RefreshControl() |
| | 43 | | { |
| 19 | 44 | | if (model == null) |
| 0 | 45 | | return; |
| | 46 | |
|
| 19 | 47 | | SetRealm(model.realmName); |
| 19 | 48 | | SetNumberOfUsers(model.numberOfUsers); |
| 19 | 49 | | } |
| | 50 | |
|
| | 51 | | public void SetRealm(string newRealm) |
| | 52 | | { |
| 20 | 53 | | model.realmName = newRealm; |
| | 54 | |
|
| 20 | 55 | | if (realm == null) |
| 0 | 56 | | return; |
| | 57 | |
|
| 20 | 58 | | realm.text = newRealm; |
| 20 | 59 | | } |
| | 60 | |
|
| | 61 | | public void SetNumberOfUsers(int newNumberOfUsers) |
| | 62 | | { |
| 21 | 63 | | model.numberOfUsers = newNumberOfUsers; |
| | 64 | |
|
| 21 | 65 | | if (numberOfusers == null) |
| 0 | 66 | | return; |
| | 67 | |
|
| 21 | 68 | | float formattedUsersCount = newNumberOfUsers >= 1000 ? (newNumberOfUsers / 1000f) : newNumberOfUsers; |
| 21 | 69 | | numberOfusers.text = newNumberOfUsers >= 1000 ? $"{formattedUsersCount}k" : $"{formattedUsersCount}"; |
| 21 | 70 | | } |
| | 71 | | } |