2using System.Collections.Generic;
4using System.Reflection;
7using Microsoft.Xna.Framework;
8using Microsoft.Xna.Framework.Input;
9using Microsoft.Xna.Framework.Graphics;
19 private List<string> options =
new List<string>();
27 set => options = value.ToList();
29 public event Action<string> OnSelect;
30 public Action<string> AddOnSelect {
set { OnSelect += value; } }
32 [CUISerializable]
public bool CycleOnClick {
get;
set; } =
true;
33 public int SelectedIndex
35 get => options.IndexOf(Selected);
38 if (options.Count == 0)
44 Selected = options.ElementAtOrDefault(value % options.Count) ??
"";
49 public string Selected
55 OnSelect?.Invoke(value);
59 public void Add(
string option) => options.Add(option);
60 public void Remove(
string option)
62 int i = options.IndexOf(option);
63 options.Remove(option);
64 if (option == Selected) Select(i);
66 public void Select(
int i) => SelectedIndex = i;
67 public void Select(
string option) => Selected = option;
68 public void SelectNext() => SelectedIndex++;
69 public void SelectPrev() => SelectedIndex--;
71 public CUIMultiButton() : base()
92 if ((!WrappedForThisSize.HasValue || size == WrappedForThisSize.Value) && !TextPropChanged)
return WrappedSize;
94 TextPropChanged =
false;
95 WrappedForThisSize = size;
97 if (Vertical) size =
new Vector2(0, size.Y);
100 IEnumerable<string> WrappedTexts;
101 if (Wrap || Vertical)
103 WrappedText = Font.WrapText(Text, size.X / TextScale -
Padding.X * 2).Trim(
'\n');
104 WrappedTexts = options.Select(o => Font.WrapText(o, size.X / TextScale -
Padding.X * 2).Trim(
'\n'));
109 WrappedTexts = options;
112 IEnumerable<Vector2> RealTextSizes = WrappedTexts.Select(t => Font.MeasureString(t) * TextScale);
116 foreach (Vector2 s
in RealTextSizes)
118 if (s.X > maxX) maxX = s.X;
119 if (s.Y > maxY) maxY = s.Y;
122 Vector2 MaxTextSize =
new Vector2(maxX, maxY);
124 RealTextSize = Font.MeasureString(WrappedText) * TextScale;
126 if (WrappedText ==
"") RealTextSize =
new Vector2(0, 0);
127 RealTextSize =
new Vector2((
float)Math.Round(RealTextSize.X), (
float)Math.Round(RealTextSize.Y));
129 Vector2 minSize = MaxTextSize +
Padding * 2;
131 if (!Wrap || Vertical)
136 WrappedSize =
new Vector2(Math.Max(size.X, minSize.X), Math.Max(size.Y, minSize.Y));
141 internal override Vector2 AmIOkWithThisSize(Vector2 size)
Vector2 Padding
Used for text, should be in CUITextBlock really.
string Command
This command will be dispatched up when some component specific event happens.
void DispatchUp(CUICommand command)
Dispathes command up the component tree until someone consumes it.
record CUICommand(string Name, object Data=null)
Can be dispatched up the component tree to notify parent about something add pass some event data wit...