Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
OriginalCommunityContentScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
14
16
18
20
22
24
26
28
30
32
34
36
38
39 public const string fName = "OriginalCommunityContentScreen";
40 public const string fName1 = "CommunityContentScreen";
41
42 public CancellableBusyDialog m_busyDialog = new($"[{fName1}:2]", false);
43
44 public object m_filter;
45
46 public Order m_order;
47
48 public string m_search;
49
51
53
54 public Dictionary<string, IEnumerable<object>> m_itemsCache = new();
55
57 XElement node = ContentManager.Get<XElement>("Screens/OriginalCommunityContentScreen");
58 LoadContents(this, node);
59 m_listPanel = Children.Find<ListPanelWidget>("List");
60 m_orderLabel = Children.Find<LabelWidget>("Order");
61 m_changeOrderButton = Children.Find<ButtonWidget>("ChangeOrder");
62 m_filterLabel = Children.Find<LabelWidget>("Filter");
63 m_changeFilterButton = Children.Find<ButtonWidget>("ChangeFilter");
64 m_searchTextBox = Children.Find<TextBoxWidget>("Search");
65 m_searchLabel = Children.Find<LabelWidget>("SearchLabel");
66 m_clearSearchLink = Children.Find<LinkWidget>("ClearSearchLink");
67 m_downloadButton = Children.Find<ButtonWidget>("Download");
68 m_deleteButton = Children.Find<ButtonWidget>("Delete");
69 m_moreOptionsButton = Children.Find<ButtonWidget>("MoreOptions");
70 m_listPanel.ItemWidgetFactory = delegate(object item) {
71 if (item is OriginalCommunityContentEntry communityContentEntry) {
72 XElement node2 = ContentManager.Get<XElement>("Widgets/CommunityContentItem");
73 ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node2, null);
74 containerWidget.Children.Find<RectangleWidget>("CommunityContentItem.Icon").Subtexture =
75 ExternalContentManager.GetEntryTypeIcon(communityContentEntry.Type);
76 containerWidget.Children.Find<LabelWidget>("CommunityContentItem.Text").Text = communityContentEntry.Name;
77 containerWidget.Children.Find<LabelWidget>("CommunityContentItem.Details").Text =
78 $"{ExternalContentManager.GetEntryTypeDescription(communityContentEntry.Type)} {DataSizeFormatter.Format(communityContentEntry.Size)}";
79 containerWidget.Children.Find<StarRatingWidget>("CommunityContentItem.Rating").Rating = communityContentEntry.RatingsAverage;
80 containerWidget.Children.Find<StarRatingWidget>("CommunityContentItem.Rating").IsVisible =
81 communityContentEntry.RatingsAverage > 0f;
82 containerWidget.Children.Find<LabelWidget>("CommunityContentItem.ExtraText").Text = communityContentEntry.ExtraText;
83 return containerWidget;
84 }
85 XElement node3 = ContentManager.Get<XElement>("Widgets/CommunityContentItemMore");
86 ContainerWidget containerWidget2 = (ContainerWidget)LoadWidget(this, node3, null);
87 m_moreLink = containerWidget2.Children.Find<LinkWidget>("CommunityContentItemMore.Link");
88 m_moreLink.Tag = item as string;
89 return containerWidget2;
90 };
91 m_searchTextBox.TextChanged += delegate {
92 m_search = m_searchTextBox.Text.Replace("\n", "").Trim();
93 PopulateList(null);
94 };
95 m_listPanel.SelectionChanged += delegate {
96 if (m_listPanel.SelectedItem != null
97 && !(m_listPanel.SelectedItem is OriginalCommunityContentEntry)) {
98 m_listPanel.SelectedItem = null;
99 }
100 };
101 }
102
103 public override void Enter(object[] parameters) {
104 m_filter = string.Empty;
105 m_order = Order.ByRank;
106 m_search = string.Empty;
107 PopulateList(null);
108 }
109
110 public override void Update() {
111 OriginalCommunityContentEntry communityContentEntry = m_listPanel.SelectedItem as OriginalCommunityContentEntry;
112 m_downloadButton.IsEnabled = communityContentEntry != null;
113 m_deleteButton.IsEnabled = UserManager.ActiveUser != null
114 && communityContentEntry != null
115 && m_filter as string == UserManager.ActiveUser.UniqueId;
116 m_orderLabel.Text = GetOrderDisplayName(m_order);
117 m_filterLabel.Text = GetFilterDisplayName(m_filter);
118 if (!m_searchTextBox.HasFocus) {
119 m_searchTextBox.Text = m_search;
120 }
121 m_searchLabel.IsVisible = string.IsNullOrEmpty(m_searchTextBox.Text) && !m_searchTextBox.HasFocus;
122 m_clearSearchLink.IsVisible = !string.IsNullOrEmpty(m_searchTextBox.Text) || !string.IsNullOrEmpty(m_search) || m_searchTextBox.HasFocus;
124 && m_busyDialog.RootWidget != ScreensManager.RootWidget) {
126 }
127 if (m_populatingListCount <= 0
128 && m_busyDialog.RootWidget == ScreensManager.RootWidget) {
130 }
131 if (m_changeOrderButton.IsClicked) {
132 List<Order> items = EnumUtils.GetEnumValues<Order>().Cast<Order>().ToList();
134 null,
137 items,
138 60f,
139 item => GetOrderDisplayName((Order)item),
140 delegate(object item) {
141 m_order = (Order)item;
142 PopulateList(null);
143 }
144 )
145 );
146 }
147 if (m_changeFilterButton.IsClicked) {
148 List<object> list = [string.Empty];
150 .GetEnumValues<OriginalExternalContentType>()
152 select t) {
153 list.Add(item);
154 }
155 if (UserManager.ActiveUser != null) {
157 }
158 if (m_listPanel.SelectedItem is OriginalCommunityContentEntry communityContentEntry2) {
159 list.Add(communityContentEntry2.Url);
160 }
162 null,
165 list,
166 60f,
167 item => GetFilterDisplayName(item),
168 delegate(object item) {
169 m_filter = item;
170 PopulateList(null);
171 }
172 )
173 );
174 }
175 if (m_clearSearchLink.IsClicked) {
176 m_search = string.Empty;
177 PopulateList(null);
178 }
179 if (m_downloadButton.IsClicked
180 && communityContentEntry != null) {
181 DownloadEntry(communityContentEntry);
182 }
183 if (m_deleteButton.IsClicked
184 && communityContentEntry != null) {
185 DeleteEntry(communityContentEntry);
186 }
187 if (m_moreOptionsButton.IsClicked) {
189 }
190 if (m_moreLink != null
191 && m_moreLink.IsClicked) {
192 PopulateList((string)m_moreLink.Tag);
193 }
194 if (Input.Back
195 || Children.Find<BevelledButtonWidget>("TopBar.Back").IsClicked) {
196 ScreensManager.SwitchScreen("Content");
197 }
198 if (Input.Hold.HasValue
199 && Input.HoldTime > 2f
200 && Input.Hold.Value.Y < 20f) {
202 Task.Delay(250).Wait();
203 }
204 }
205
206 public void PopulateList(string cursor) {
207 string text = string.Empty;
208 string text2 = string.Empty;
209 if (m_filter is string) {
210 string text3 = (string)m_filter;
211 if (text3.StartsWith("http")) {
212 text2 = text3;
213 }
214 else {
215 text = text3;
216 }
217 }
218 string text4 = m_filter is OriginalExternalContentType ? m_filter.ToString() : string.Empty;
219 string text5 = string.Empty;
221 text5 = "1";
222 }
224 text5 = "0";
225 }
226 string text6 = m_order.ToString();
227 string cacheKey = $"{text}\n{text2}\n{text4}\n{text5}\n{m_search}\n{text6}";
228 m_moreLink = null;
229 if (string.IsNullOrEmpty(cursor)
230 && m_itemsCacheExpiryTime != 0.0
232 && m_itemsCache.TryGetValue(cacheKey, out IEnumerable<object> value)) {
233 m_listPanel.ClearItems();
234 m_listPanel.AddItems(value);
235 m_listPanel.ScrollPosition = 0f;
236 return;
237 }
238 object[] prefixItems = !string.IsNullOrEmpty(cursor) ? m_listPanel.Items.Where(i => i is OriginalCommunityContentEntry).ToArray() : [];
241 cursor,
242 text,
243 text2,
244 text4,
245 text5,
246 m_search,
247 text6,
248 m_busyDialog.Progress,
249 delegate(List<OriginalCommunityContentEntry> list, string nextCursor) {
251 m_listPanel.ClearItems();
252 m_listPanel.AddItems(prefixItems);
253 m_listPanel.AddItems(list);
254 if (prefixItems.Length == 0) {
255 m_listPanel.ScrollPosition = 0f;
256 }
257 if (list.Count > 0
258 && !string.IsNullOrEmpty(nextCursor)) {
259 m_listPanel.AddItem(nextCursor);
260 }
261 m_itemsCache[cacheKey] = new List<object>(m_listPanel.Items);
263 },
264 delegate(Exception error) {
266 DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Error, error.Message, LanguageControl.Ok, null, null));
267 }
268 );
269 }
270
272 string userId = UserManager.ActiveUser != null ? UserManager.ActiveUser.UniqueId : string.Empty;
273 CancellableBusyDialog busyDialog = new(string.Format(LanguageControl.Get(fName1, "1"), entry.Name), false);
274 DialogsManager.ShowDialog(null, busyDialog);
276 entry.Url,
277 entry.Name,
278 entry.Type,
279 userId,
280 busyDialog.Progress,
281 delegate { DialogsManager.HideDialog(busyDialog); },
282 delegate(Exception error) {
283 DialogsManager.HideDialog(busyDialog);
284 DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Error, error.Message, LanguageControl.Ok, null, null));
285 }
286 );
287 }
288
290 if (UserManager.ActiveUser == null) {
291 return;
292 }
294 null,
295 new MessageDialog(
300 delegate(MessageDialogButton button) {
301 if (button == MessageDialogButton.Button1) {
302 CancellableBusyDialog busyDialog = new(string.Format(LanguageControl.Get(fName1, "3"), entry.Name), false);
303 DialogsManager.ShowDialog(null, busyDialog);
305 entry.Url,
307 busyDialog.Progress,
308 delegate {
309 DialogsManager.HideDialog(busyDialog);
310 DialogsManager.ShowDialog(
311 null,
312 new MessageDialog(
313 LanguageControl.Get(fName1, "6"),
314 LanguageControl.Get(fName1, "7"),
315 LanguageControl.Ok,
316 null,
317 null
318 )
319 );
320 },
321 delegate(Exception error) {
322 DialogsManager.HideDialog(busyDialog);
324 null,
325 new MessageDialog(LanguageControl.Error, error.Message, LanguageControl.Ok, null, null)
326 );
327 }
328 );
329 }
330 }
331 )
332 );
333 }
334
335 public static string GetFilterDisplayName(object filter) {
336 if (filter is string) {
337 string text = (string)filter;
338 return text.StartsWith("http") ? LanguageControl.Get(fName, "3") :
339 string.IsNullOrEmpty(text) ? LanguageControl.Get(fName1, "9") : LanguageControl.Get(fName1, "8");
340 }
341 if (filter is OriginalExternalContentType) {
343 }
344 throw new InvalidOperationException(LanguageControl.Get(fName1, "10"));
345 }
346
347 public static string GetOrderDisplayName(Order order) {
348 return order switch {
355 _ => throw new InvalidOperationException(LanguageControl.Get(fName1, "13"))
356 };
357 }
358
368
370 const string fName2 = "ExternalContentManager";
371 return type switch {
377 _ => string.Empty
378 };
379 }
380 }
381}
static double RealTime
定义 Time.cs:38
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static IList< int > GetEnumValues(Type type)
static Subtexture GetEntryTypeIcon(ExternalContentType type)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
ExternalContentType Type
string Name
string Url
Dictionary< string, IEnumerable< object > > m_itemsCache
static bool IsEntryTypeDownloadSupported(OriginalExternalContentType type)
static string GetEntryTypeDescription(OriginalExternalContentType type)
void DeleteEntry(OriginalCommunityContentEntry entry)
void DownloadEntry(OriginalCommunityContentEntry entry)
static void SwitchScreen(string name, params object[] parameters)
static ContainerWidget RootWidget
static CommunityContentMode OriginalCommunityContentMode
readonly string UniqueId
static UserInfo ActiveUser
virtual string Name
static Widget LoadWidget(object eventsTarget, XElement node, ContainerWidget parentWidget)
virtual bool IsVisible
virtual void LoadContents(object eventsTarget, XElement node)
static void Download(string address, string name, ExternalContentType type, string userId, CancellableProgress progress, Action success, Action< Exception > failure)
static void Delete(string address, string userId, CancellableProgress progress, Action success, Action< Exception > failure)
static void List(string cursor, string userId, string userUrl, string type, string moderation, string search, string sortOrder, CancellableProgress progress, Action< List< OriginalCommunityContentEntry >, string > success, Action< Exception > failure)