4 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
40 private readonly List<Element> elements =
new List<Element>();
58 public override Color Color
76 get => base.HoverColor;
79 base.HoverColor = value;
88 RelativeSpacing = 0.05f,
93 GUIStyle.Apply(
LeftButton,
"LeftButton",
this);
95 GUIStyle.Apply(
TextBlock,
"TextBlock",
this);
102 if (newElements !=
null && newElements.Any())
123 var matchingElement = elements.Where(e => value.Equals(e.value))
125 if (matchingElement !=
null)
144 this.elements.Clear();
156 this.elements.Clear();
165 var newElement =
new Element(value, text, tooltip ??
string.Empty);
166 elements.Add(newElement);
188 private bool SelectNextValidElement(
bool directionLeft =
false)
190 if (elements.Count < 2) {
return false; }
194 int newIndex = currentIndex;
195 for (
int i = 0; i < elements.Count; i++)
197 newIndex = directionLeft ? MathUtils.PositiveModulo((newIndex - 1), elements.Count) : (newIndex + 1) % elements.Count;
virtual RichString ToolTip
RectTransform RectTransform
An UI element that allows toggling through a set of options with buttons to the left and right
override Color HoverColor
void SetElements(params(T value, LocalizedString text, LocalizedString toolTip)[] elements)
Clears all existing elements from the carousels and adds the specified new elements to it
GUISelectionCarousel(RectTransform rectT, string style="", params(T value, LocalizedString text)[] newElements)
OnValueChangedHandler? OnValueChanged
void Refresh()
Refresh the current selection, for example if there are conditions for which elements are valid,...
record class Element(T value, LocalizedString text, LocalizedString toolTip)
object? GetSelectedElement()
delegate void OnValueChangedHandler(GUISelectionCarousel< T > carousel)
void SelectElement(object? value)
Select the element whose value matches the specified value. If null, deselects the currently selected...
void SelectElement(Element? element)
Func< T, bool >? ElementSelectionCondition
Are there some conditions for selecting a particular element?
void SetElements(params(T value, LocalizedString text)[] elements)
Clears all existing elements from the carousels and adds the specified new elements to it
LocalizedString SelectedText
void AddElement(T value, LocalizedString text, LocalizedString? tooltip=null)
Allows accessing the element selected in the carousel in contexts where the type of T isn't known....
void SelectElement(object? value)
object? GetSelectedElement()