Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ContentScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
5 public class ContentScreen : Screen {
11 public static string fName = "ContentScreen";
12
19
20 public bool m_isAdmin;
21
22 public ContentScreen() {
23 XElement node = ContentManager.Get<XElement>("Screens/ContentScreen");
24 LoadContents(this, node);
26 m_deviceButton = Children.Find<ButtonWidget>("Device");
28 m_linkButton = Children.Find<ButtonWidget>("Link");
31 }
32
33 public override void Enter(object[] parameters) {
34 base.Enter(parameters);
35#if RELEASE
36 CommunityContentManager.IsAdmin(new CancellableProgress(), delegate(bool isAdmin) { m_isAdmin = isAdmin; }, _ => { });
37#endif
38 }
39
40 public void OpenManageSelectDialog() {
41 List<string> list = [LanguageControl.Get(fName, 1), LanguageControl.Get(fName, 2)];
42 if (m_isAdmin) {
43 list = [LanguageControl.Get(fName, 1), LanguageControl.Get(fName, 2), "用户管理"];
44 }
46 null,
48 null,
49 list,
50 70f,
51 item => (string)item,
52 item => {
53 string selectionResult = (string)item;
54 if (selectionResult == LanguageControl.Get(fName, 1)) {
55 ScreensManager.SwitchScreen("ModsManageContent");
56 }
57 else if (selectionResult == LanguageControl.Get(fName, 2)) {
58 ScreensManager.SwitchScreen("ManageContent");
59 }
60 else {
61 ScreensManager.SwitchScreen("ManageUser");
62 }
63 }
64 )
65 );
66 }
67
68 public override void Update() {
70 if (m_externalContentButton.IsClicked) {
71 ScreensManager.SwitchScreen("ExternalContent");
72 }
73 if (m_deviceButton.IsClicked) {
74 Task.Run(async () => {
75 try {
76#if WINDOWS
77 KeyValuePair<string, string[]>[] filters = [
78 new(LanguageControl.Get(fName, "ExtensionName", ".scworld"), ["*.scworld"]),
79 new(LanguageControl.Get(fName, "ExtensionName", ".scbtex"), ["*.scbtex", "*.png", "*.webp", "*.astc", "*.astcsrgb"]),
80 new(LanguageControl.Get(fName, "ExtensionName", ".scskin"), ["*.scskin"]),
81 new(LanguageControl.Get(fName, "ExtensionName", ".scfpack"), ["*.scfpack"]),
82 new(LanguageControl.Get(fName, "ExtensionName", ".scmod"), ["*.scmod"])
83 ];
84 (Stream stream, string fileName) = await Storage.ChooseFile(LanguageControl.Get(fName, "3"), filters);
85#else
86 KeyValuePair<string, string[]>[] filters = [
87 new(LanguageControl.Get(fName, "ExtensionName", ".scworld"), [".scworld"]),
88 new(LanguageControl.Get(fName, "ExtensionName", ".scbtex"), [".scbtex", ".png", ".webp", ".astc", ".astcsrgb"]),
89 new(LanguageControl.Get(fName, "ExtensionName", ".scskin"), [".scskin"]),
90 new(LanguageControl.Get(fName, "ExtensionName", ".scfpack"), [".scfpack"]),
91 new(LanguageControl.Get(fName, "ExtensionName", ".scmod"), [".scmod"])
92 ];
93 (Stream stream, string fileName) = await Storage.ChooseFile(LanguageControl.Get(fName, "3"), filters);
94#endif
95 if (stream == null) {
96 if (!string.IsNullOrEmpty(fileName)) {
97 Dispatcher.Dispatch(() => {
99 null,
100 new MessageDialog(
102 string.Format(LanguageControl.Get(fName, "6"), fileName),
104 null,
105 null
106 )
107 );
108 }
109 );
110 }
111 return;
112 }
113 await using (stream) {
114 if (fileName != null) {
117 Dispatcher.Dispatch(() => {
119 null,
120 new MessageDialog(
122 string.Format(LanguageControl.Get(fName, "4"), fileName),
124 null,
125 null
126 )
127 );
128 }
129 );
130 }
131 }
132 }
133 catch (Exception e) {
134 Log.Error(e);
135 Dispatcher.Dispatch(() => {
137 null,
138 new MessageDialog(LanguageControl.Error, e.Message, LanguageControl.Ok, null, null)
139 );
140 }
141 );
142 }
143 }
144 );
145 }
146 if (m_communityContentButton.IsClicked) {
148 /*List<CommunityType> items = [];
149 if (SettingsManager.OriginalCommunityContentMode != CommunityContentMode.Disabled) {
150 items.Add(CommunityType.OriginalCommunity);
151 }
152 if (SettingsManager.CommunityContentMode != CommunityContentMode.Disabled) {
153 items.Add(CommunityType.ChineseCommunity);
154 items.Add(CommunityType.ChineseCommunityWebsite);
155 }
156 DialogsManager.ShowDialog(
157 null,
158 new ListSelectionDialog(
159 LanguageControl.Get(fName, "5"),
160 items,
161 70f,
162 item => item is CommunityType type ? LanguageControl.Get(fName, "CommunityType", type.ToString()) : null,
163 item => {
164 if (item is CommunityType type) {
165 switch (type) {
166 case CommunityType.OriginalCommunity:
167 ScreensManager.SwitchScreen("OriginalCommunityContent");
168 break;
169 case CommunityType.ChineseCommunity:
170 ScreensManager.SwitchScreen("CommunityContent");
171 break;
172 case CommunityType.ChineseCommunityWebsite:
173 WebBrowserManager.LaunchBrowser("https://test.suancaixianyu.cn/");
174 break;
175 }
176 }
177 }
178 )
179 );*/
180 }
181 if (m_linkButton.IsClicked) {
183 }
184 if (m_manageButton.IsClicked) {
185 ScreensManager.SwitchScreen("ManageContent");
186 }
187 if (m_manageModButton.IsClicked) {
188 ScreensManager.SwitchScreen("ModsManageContent");
189 }
190 if (Input.Back
191 || Input.Cancel
192 || Children.Find<ButtonWidget>("TopBar.Back").IsClicked) {
193 ScreensManager.SwitchScreen("MainMenu");
194 }
195 }
196 }
197}
static void Dispatch(Action action, bool waitUntilCompleted=false)
static void Error(object message)
定义 Log.cs:80
static string GetExtension(string path)
static async Task<(Stream, string)> ChooseFile(string title=null, KeyValuePair< string, string[]>[] filters=null, string defaultPath=null, OpenFileMode mode=OpenFileMode.Read)
static void IsAdmin(CancellableProgress progress, Action< bool > success, Action< Exception > failure)
readonly WidgetsList Children
static object Get(Type type, string name)
override void Enter(object[] parameters)
ButtonWidget m_externalContentButton
ButtonWidget m_communityContentButton
ButtonWidget m_manageModButton
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static ExternalContentType ExtensionToType(string extension)
static string ImportExternalContentSync(Stream stream, ExternalContentType type, string name)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static void SwitchScreen(string name, params object[] parameters)
static CommunityContentMode CommunityContentMode
static CommunityContentMode OriginalCommunityContentMode
virtual void LoadContents(object eventsTarget, XElement node)