3 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
6 using System.Threading;
10 sealed
partial class MutableWorkshopMenu : WorkshopMenu
26 ShowOnlyItemAssemblies
34 private readonly
GUIFrame contentFrame;
36 private CancellationTokenSource taskCancelSrc =
new CancellationTokenSource();
37 private readonly HashSet<SteamManager.Workshop.ItemThumbnail> itemThumbnails =
new HashSet<SteamManager.Workshop.ItemThumbnail>();
39 private readonly Option<GUIListBox> popularModsListOption;
40 private readonly Option<GUIListBox> selfModsListOption;
42 private uint memSubscribedModCount = 0;
44 private static bool EnableWorkshopSupport => SteamManager.IsInitialized;
52 AbsoluteSpacing = GUI.IntScale(4)
55 Vector2 tabberSize = EnableWorkshopSupport ? (1.0f, 0.05f) : Vector2.Zero;
59 tabContents =
new Dictionary<Tab, (GUIButton Button, GUIFrame Content)>();
61 if (EnableWorkshopSupport)
64 style:
"GUIButtonSmall", text: TextManager.Get(
"FindModsButton"))
66 OnClicked = (button, o) =>
68 SteamManager.OverlayCustomUrl($
"https://steamcommunity.com/app/{SteamManager.AppID}/workshop/");
81 onUpdate: (f, component) => UpdateSubscribedModInstalls());
83 CreateInstalledModsTab(
84 out enabledCoreDropdown,
85 out enabledRegularModsList,
86 out disabledRegularModsList,
87 out onInstalledInfoButtonHit,
89 out modsListFilterTickboxes,
90 out bulkUpdateButtonOption);
92 if (EnableWorkshopSupport)
94 CreatePopularModsTab(out
GUIListBox popularModList);
97 popularModsListOption = Option<GUIListBox>.Some(popularModList);
98 selfModsListOption = Option<GUIListBox>.Some(selfModsList);
102 popularModsListOption = Option.None;
103 selfModsListOption = Option.None;
109 private void SwitchContent(
GUIFrame newContent)
111 contentFrame.Children.ForEach(c => c.Visible =
false);
118 SwitchContent(tabContents[tab].Content);
119 tabber.Children.ForEach(c =>
121 if (c is
GUIButton btn) { btn.Selected = btn == tabContents[tab].Button; }
123 if (!taskCancelSrc.IsCancellationRequested) { taskCancelSrc.Cancel(); }
124 itemThumbnails.ForEach(t => t.Dispose());
125 itemThumbnails.Clear();
128 case Tab.InstalledMods:
131 case Tab.PopularMods when popularModsListOption.TryUnwrap(out var popularModsList):
132 PopulateItemList(popularModsList, SteamManager.Workshop.GetPopularItems(), includeSubscribeButton:
true);
134 case Tab.Publish when selfModsListOption.TryUnwrap(out var selfModsList):
135 PopulateItemList(selfModsList, SteamManager.Workshop.GetPublishedItems(), includeSubscribeButton:
false, onFill: AddUnpublishedMods);
140 private void AddButtonToTabber(
Tab tab,
GUIFrame content)
142 var button =
new GUIButton(
new RectTransform(Vector2.One, tabber.RectTransform,
Anchor.BottomCenter,
Pivot.BottomCenter), TextManager.Get($
"workshopmenutab.{tab}"), style:
"GUITabButton")
144 OnClicked = (b, _) =>
153 button.RectTransform.MaxSize = RectTransform.MaxPoint;
154 button.Children.ForEach(c => c.RectTransform.MaxSize = RectTransform.MaxPoint);
156 tabContents.Add(tab, (button, content));
159 private GUIFrame CreateNewContentFrame(
Tab tab)
161 var content =
new GUIFrame(
new RectTransform(Vector2.One * 0.98f, contentFrame.RectTransform,
Anchor.Center,
Pivot.Center), style:
null);
162 AddButtonToTabber(tab, content);
166 private void CreatePopularModsTab(out GUIListBox popularModsList)
168 GUIFrame content = CreateNewContentFrame(
Tab.PopularMods);
169 if (!SteamManager.IsInitialized)
171 tabContents[
Tab.PopularMods].Button.Enabled =
false;
173 GUIFrame listFrame =
new GUIFrame(
new RectTransform(Vector2.One, content.RectTransform), style:
null);
174 CreateWorkshopItemList(listFrame, out _, out popularModsList, onSelected: PopulateFrameWithItemInfo);
177 private void CreatePublishTab(out GUIListBox selfModsList)
179 GUIFrame content = CreateNewContentFrame(
Tab.Publish);
180 if (!SteamManager.IsInitialized)
182 tabContents[
Tab.Publish].Button.Enabled =
false;
184 CreateWorkshopItemOrPackageList(content, out _, out selfModsList, onSelected: PopulatePublishTab);
189 ContentPackageManager.EnabledPackages.SetCore(EnabledCorePackage);
190 ContentPackageManager.EnabledPackages.SetRegular(enabledRegularModsList.
Content.
Children
193 ContentPackageManager.LogEnabledRegularPackageErrors();
197 : GUIStyle.TextColorNormal;
RectTransform RectTransform
IEnumerable< GUIComponent > Children
GUIComponent that can be used to render custom content on the UI
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.