3 using System.Collections.Generic;
6 using Microsoft.Xna.Framework;
10 abstract partial class WorkshopMenu
29 new RectTransform(Vector2.One, containingListBox.Content.RectTransform),
30 "", style:
"GUITextBoxNoBorder", wrap:
true,
31 textAlignment: Alignment.
TopLeft);
32 textBox.OnTextChanged += (textBox, text) =>
34 string wrappedText = textBox.TextBlock.WrappedText.Value;
35 int measuredHeight = (int)textBox.Font.MeasureString(wrappedText).Y;
36 textBox.RectTransform.NonScaledSize =
37 (containingListBox.Content.Rect.Width,
38 Math.Max(measuredHeight, containingListBox.Content.Rect.Height));
39 containingListBox.UpdateScrollBarSize();
43 textBox.OnEnterPressed += (textBox, text) =>
45 string str = textBox.Text;
46 int cursorPos = textBox.CaretIndex;
47 textBox.Text = $
"{str[..cursorPos]}\n{str[cursorPos..]}";
48 textBox.CaretIndex = cursorPos + 1;
57 GUILayoutGroup parent, Func<T, LocalizedString> textFunc, T currentValue,
58 Action<T> setter) where T : Enum
59 => Dropdown(parent, textFunc, (T[])Enum.GetValues(typeof(T)), currentValue, setter);
62 GUILayoutGroup parent, Func<T, LocalizedString> textFunc, IReadOnlyList<T> values, T currentValue,
63 Action<T> setter,
float heightScale = 1.0f)
66 SwapDropdownValues(dropdown, textFunc, values, currentValue, setter);
72 Func<T, LocalizedString> textFunc,
73 IReadOnlyList<T> values,
79 throw new Exception(
"SwapValues must preserve the type of the dropdown's userdata");
85 values.ForEach(v => dropdown.
AddItem(text: textFunc(v), userData: v));
86 dropdown.
Select(values.IndexOf(currentValue));
94 protected static int Round(
float v) => (int)MathF.Round(v);
95 protected static string Percentage(
float v) => $
"{Round(v * 100)}";
99 public readonly Identifier
Id;
114 var searchHolder =
new GUIFrame(searchRectT, style:
null);
115 var searchBox =
new GUITextBox(
new RectTransform(Vector2.One, searchHolder.RectTransform),
"", createClearButton:
true);
117 textColor: Color.DarkGray * 0.6f,
118 text: TextManager.Get(
"Search") + TextManager.Get(
"ellipsis"),
119 textAlignment: Alignment.CenterLeft)
126 searchTitle.RectTransform.NonScaledSize = searchBox.Frame.RectTransform.NonScaledSize;
128 searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible =
false; };
129 searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = searchBox.Text.IsNullOrWhiteSpace(); };
131 searchBox.OnTextChanged += (sender, str) =>
144 const int maxErrorsToShow = 5;
147 TextManager.GetWithVariable(
"ContentPackageHasFatalErrors",
"[packagename]", mod.
Name)
148 +
'\n' +
string.Join(
'\n', mod.
FatalLoadErrors.Take(maxErrorsToShow).Select(e => e.Message));
151 uiElement.
ToolTip +=
'\n' + TextManager.GetWithVariable(
"workshopitemdownloadprompttruncated",
"[number]", (mod.
FatalLoadErrors.Count() - maxErrorsToShow).ToString());
158 if (!uiElement.
ToolTip.IsNullOrWhiteSpace()) { uiElement.
ToolTip +=
"\n"; }
159 uiElement.
ToolTip += TextManager.GetWithVariable(
160 "ContentPackageEnableError",
"[packagename]", mod.
Name);
ImmutableArray< LoadError > FatalLoadErrors
Errors that occurred when loading this content package. Currently, all errors are considered fatal an...
Option< ContentPackageManager.LoadProgress.Error > EnableError
An error that occurred when trying to enable this mod. This field doesn't directly affect whether or ...
virtual RichString ToolTip
RectTransform RectTransform
IEnumerable< GUIComponent > Children
GUIComponent that can be used to render custom content on the UI
GUIComponent AddItem(LocalizedString text, object userData=null, LocalizedString toolTip=null, Color? color=null, Color? textColor=null)
OnSelectedHandler OnSelected
Triggers when some item is cliecked from the dropdown. Note that SelectedData is not set yet when thi...
override void ClearChildren()
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.