| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | #if UNITY_2022_2_OR_NEWER |
| | 6 | |
|
| | 7 | | using System; |
| | 8 | | using UnityEngine.UIElements; |
| | 9 | |
|
| | 10 | | namespace GDX.Developer |
| | 11 | | { |
| | 12 | | public class IntegerRangeWatch : WatchBase |
| | 13 | | { |
| | 14 | | readonly Func<int> m_GetValue; |
| | 15 | | readonly Func<int, Sentiment> m_GetSentiment; |
| | 16 | |
|
| | 17 | | Sentiment m_CachedSentiment; |
| 0 | 18 | | int m_CachedValue = int.MinValue; |
| | 19 | |
|
| | 20 | | readonly Label m_ValueLabel; |
| | 21 | |
|
| | 22 | | public IntegerRangeWatch(string uniqueIdentifier, string displayName, Func<int> getValue, Func<int, Sentiment> g |
| 0 | 23 | | : base(uniqueIdentifier, displayName, enabled, minWidth, minHeight) |
| 0 | 24 | | { |
| 0 | 25 | | m_GetValue = getValue; |
| 0 | 26 | | m_GetSentiment = getSentiment; |
| | 27 | |
|
| 0 | 28 | | Label displayNameLabel = new Label() { text = displayName }; |
| 0 | 29 | | displayNameLabel.AddToClassList("gdx-watch-left"); |
| | 30 | |
|
| 0 | 31 | | m_ValueLabel = new Label(); |
| 0 | 32 | | m_ValueLabel.AddToClassList("gdx-watch-right"); |
| 0 | 33 | | m_ValueLabel.AddToClassList("default"); |
| | 34 | |
|
| 0 | 35 | | ContainerElement.Add(displayNameLabel); |
| 0 | 36 | | ContainerElement.Add(m_ValueLabel); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | public override void Poll() |
| 0 | 40 | | { |
| 0 | 41 | | int getValue = m_GetValue(); |
| 0 | 42 | | if (getValue != m_CachedValue) |
| 0 | 43 | | { |
| 0 | 44 | | m_ValueLabel.text = getValue.ToString(); |
| 0 | 45 | | Sentiment sentiment = m_GetSentiment(getValue); |
| 0 | 46 | | if (sentiment != m_CachedSentiment) |
| 0 | 47 | | { |
| 0 | 48 | | AddSentimentToElement(m_ValueLabel, sentiment); |
| 0 | 49 | | m_CachedSentiment = sentiment; |
| 0 | 50 | | m_CachedValue = getValue; |
| 0 | 51 | | } |
| 0 | 52 | | } |
| 0 | 53 | | } |
| | 54 | | } |
| | 55 | | } |
| | 56 | |
|
| | 57 | | #endif // UNITY_2022_2_OR_NEWER |