| | 1 | | using DCL.Components; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using TMPro; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | public class SmartItemUIParameterAdapter : MonoBehaviour |
| | 10 | | { |
| | 11 | |
|
| | 12 | | public TextMeshProUGUI labelTxt; |
| | 13 | | public Action<SmartItemParameter> OnParameterChange; |
| | 14 | |
|
| | 15 | | protected SmartItemParameter currentParameter; |
| | 16 | |
|
| | 17 | | protected string KEY_NAME; |
| | 18 | |
|
| | 19 | | protected Dictionary<object, object> currentValues; |
| | 20 | |
|
| | 21 | | public virtual void SetParameter(SmartItemParameter parameter, Dictionary<object, object> values) |
| | 22 | | { |
| 0 | 23 | | currentParameter = parameter; |
| 0 | 24 | | labelTxt.text = parameter.label; |
| 0 | 25 | | KEY_NAME = parameter.label; |
| 0 | 26 | | currentValues = values; |
| 0 | 27 | | SetInfo(); |
| 0 | 28 | | } |
| | 29 | |
|
| 0 | 30 | | public virtual void SetInfo() { } |
| | 31 | |
|
| 0 | 32 | | public virtual void ChangeParameter() { OnParameterChange?.Invoke(currentParameter); } |
| | 33 | |
|
| | 34 | | protected virtual void SetParameterValue(object value) |
| | 35 | | { |
| 0 | 36 | | if (currentValues.ContainsKey(KEY_NAME)) |
| 0 | 37 | | currentValues[KEY_NAME] = value; |
| | 38 | |
|
| | 39 | | else |
| 0 | 40 | | currentValues.Add(KEY_NAME, value); |
| | 41 | |
|
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | protected virtual object GetParameterValue() |
| | 45 | | { |
| 0 | 46 | | if (currentValues.ContainsKey(KEY_NAME)) |
| 0 | 47 | | return currentValues[KEY_NAME]; |
| | 48 | |
|
| 0 | 49 | | if (!string.IsNullOrEmpty(currentParameter.@default)) |
| 0 | 50 | | return currentParameter.@default; |
| | 51 | |
|
| 0 | 52 | | return null; |
| | 53 | | } |
| | 54 | | } |