Client LuaCsForBarotrauma
ImmutableWorkshopMenu.cs
1 #nullable enable
2 using System;
3 using System.Linq;
5 using Microsoft.Xna.Framework;
6 
7 namespace Barotrauma.Steam
8 {
10  {
11  private readonly GUIListBox regularList;
12  private readonly GUITextBox filterBox;
13 
14  public ImmutableWorkshopMenu(GUIFrame parent) : base(parent)
15  {
16  var mainLayout
17  = new GUILayoutGroup(new RectTransform((0.5f, 1.0f), parent.RectTransform, Anchor.Center), isHorizontal: false);
18 
19  Label(mainLayout, TextManager.Get("enabledcore"), GUIStyle.SubHeadingFont);
20  var coreBox = new GUIButton(
21  NewItemRectT(mainLayout), style: "GUITextBoxNoIcon", text: ContentPackageManager.EnabledPackages.Core!.Name, textAlignment: Alignment.CenterLeft)
22  {
23  CanBeFocused = false,
24  CanBeSelected = false
25  };
26  coreBox.TextBlock.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f);
27 
28  Label(mainLayout, TextManager.Get("enabledregular"), GUIStyle.SubHeadingFont);
29  regularList = new GUIListBox(
30  NewItemRectT(mainLayout, heightScale: 11f))
31  {
32  OnSelected = (component, o) => false,
33  HoverCursor = CursorState.Default
34  };
35  foreach (var p in ContentPackageManager.EnabledPackages.Regular)
36  {
37  var regularBox = new GUITextBlock(
38  new RectTransform((1.0f, 0.07f), regularList.Content.RectTransform), text: p.Name)
39  {
40  CanBeFocused = false,
41  UserData = p
42  };
43  if (p.FatalLoadErrors.Any())
44  {
45  CreateModErrorInfo(p, regularBox, regularBox);
46  regularBox.CanBeFocused = true;
47  }
48  }
49 
50  var searchRectT = NewItemRectT(mainLayout, heightScale: 1.0f);
51  searchRectT.RelativeSize = (1.0f, searchRectT.RelativeSize.Y);
52  filterBox = CreateSearchBox(searchRectT);
53 
54  Label(mainLayout, TextManager.Get("CannotChangeMods"), GUIStyle.Font);
55  }
56 
57  protected override void UpdateModListItemVisibility()
58  {
59  string str = filterBox.Text;
60  regularList.Content.Children
61  .ForEach(c => c.Visible = !(c.UserData is ContentPackage p)
62  || ModNameMatches(p, str));
63  }
64  }
65 }
GUITextBlock TextBlock
Definition: GUIButton.cs:11
RectTransform RectTransform
bool ModNameMatches(ContentPackage p, string query)
static void CreateModErrorInfo(ContentPackage mod, GUIComponent uiElement, GUITextBlock nameText)
Definition: UiUtil.cs:139
static GUITextBlock Label(GUILayoutGroup parent, LocalizedString str, GUIFont font, float heightScale=1.0f)
Definition: UiUtil.cs:20
static RectTransform NewItemRectT(GUILayoutGroup parent, float heightScale=1.0f)
GUITextBox CreateSearchBox(RectTransform searchRectT)
Definition: UiUtil.cs:112
CursorState
Definition: GUI.cs:40