Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ModsManageContentScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3using Game;
4
6 public static string fName = "ModsManageContentScreen";
7
12
13 public bool m_needRestart;
14
15 public static bool IsOldApiVersionMod(ModEntity modEntity, out string description) {
16 ModInfo modInfo = modEntity.modInfo;
17 if (modInfo == null) {
18 description = string.Format(LanguageControl.Get(fName, "68"), LanguageControl.Unknown);
19 return true;
20 }
21 if (modInfo.ApiVersion.StartsWith("1.4")
22 || modInfo.ApiVersion.StartsWith("1.5")
23 || modInfo.ApiVersion.StartsWith("1.6")
24 || modInfo.ApiVersion.StartsWith("1.7")) {
25 description = string.Format(LanguageControl.Get(fName, "68"), modInfo.ApiVersion);
26 return true;
27 }
28 if (modInfo.ApiVersionRange != null) {
29 if (!modInfo.ApiVersionRange.Satisfies(ModsManager.APINuGetVersion)) {
30 description = string.Format(LanguageControl.Get(fName, "76"), modInfo.ApiVersion);
31 return true;
32 }
33 if (!modInfo.ApiVersionRange.HasUpperBound
34 && modInfo.ApiVersionRange.MinVersion != null
35 && modInfo.ApiVersionRange.MinVersion.Major == 1
36 && modInfo.ApiVersionRange.MinVersion.Minor <= 7) {
37 description = string.Format(LanguageControl.Get(fName, "68"), modInfo.ApiVersion);
38 return true;
39 }
40 }
41 description = modEntity.IsDisabled ? $"{LanguageControl.Get("ModDetailsDialog", "8")}{Storage.GetFileName(modEntity.ModFilePath)}" : modInfo.Description;
42 return false;
43 }
44
46 XElement node = ContentManager.Get<XElement>("Screens/ModsManageContentScreen");
47 LoadContents(this, node);
48 m_modsContentList = Children.Find<ListPanelWidget>("ModsContentList");
49 Children.Find<LabelWidget>("TopBar.Label").Text = LanguageControl.Get(fName, "1");
50 m_viewDetailButton = Children.Find<ButtonWidget>("ViewDetailButton");
51 m_triggerEnableButton = Children.Find<BevelledButtonWidget>("TriggerEnableButton");
52 m_openHomepageButton = Children.Find<BevelledButtonWidget>("OpenHomepageButton");
53 m_viewDetailButton.IsEnabled = false;
54 m_viewDetailButton.Text = LanguageControl.Get(fName, "80");
55 m_triggerEnableButton.IsEnabled = false;
56 m_triggerEnableButton.Text = LanguageControl.Get(fName, "18");
57 m_openHomepageButton.IsEnabled = false;
58 m_openHomepageButton.Text = LanguageControl.Get(fName, "77");
59 m_modsContentList.ItemWidgetFactory = item => {
60 if (item is not ModEntity entity) {
61 return null;
62 }
63 GetTriggerAndTitle(entity, out string title, out Color titleColor);
64 ModsManageContentItemWidget result = new() { Title = title, IsDisabled = entity.IsDisabled, TitleColor = titleColor };
65 if (IsOldApiVersionMod(entity, out string description)) {
66 result.TitleColor = Color.Red;
67 if (string.IsNullOrEmpty(entity.ModFilePath)) {
68 result.IsInformationVisible = false;
69 }
70 else {
71 result.Information = Storage.GetFileName(entity.ModFilePath);
72 }
73 }
74 else {
75 result.Information = string.Format(
77 entity.modInfo!.Version,
78 entity.modInfo.ApiVersion,
79 entity.modInfo.Author,
80 DataSizeFormatter.Format(entity.Size)
81 );
82 }
83 if (entity.Icon != null) {
84 result.Icon = entity.Icon;
85 }
86 result.Description = description;
87 return result;
88 };
89 m_modsContentList.ItemClicked += item => {
90 if (item is not ModEntity entity) {
91 return;
92 }
93 m_viewDetailButton.IsEnabled = true;
94 m_triggerEnableButton.IsEnabled = entity.IsDisabled
95 ? entity.DisableReason == ModDisableReason.Manually
96 : entity.modInfo?.PackageName is not "survivalcraft" and not "fastdebug";
97 m_triggerEnableButton.Text = LanguageControl.Get(fName, GetTrigger(entity) ? "19" : "18");
98 m_openHomepageButton.IsEnabled = true;
99 if (ReferenceEquals(entity, m_modsContentList.SelectedItem)) {
100 DialogsManager.ShowDialog(null, new ModDetailsDialog(this, entity));
101 }
102 };
103 }
104
105 public override void Enter(object[] parameters) {
107 }
108
109 public override void Leave() {
110 m_modsContentList.ClearItems();
111 m_viewDetailButton.IsEnabled = false;
112 m_triggerEnableButton.IsEnabled = false;
113 m_openHomepageButton.IsEnabled = false;
114 }
115
116 public override void Update() {
117 if (m_modsContentList.SelectedItem is ModEntity entity) {
118 if (m_viewDetailButton.IsClicked) {
119 DialogsManager.ShowDialog(null, new ModDetailsDialog(this, entity));
120 }
121 if (m_triggerEnableButton.IsClicked) {
122 TriggerEnable(entity);
123 }
124 if (m_openHomepageButton.IsClicked) {
125 if (string.IsNullOrEmpty(entity.modInfo?.Link)) {
127 null,
129 );
130 }
131 else {
132 WebBrowserManager.LaunchBrowser(entity.modInfo.Link);
133 }
134 }
135 }
136 if (Input.Back
137 || Input.Cancel
138 || Children.Find<ButtonWidget>("TopBar.Back").IsClicked) {
139 if (m_needRestart) {
141 null,
142 new MessageDialog(
147 delegate(MessageDialogButton result) {
148 if (result == MessageDialogButton.Button1) {
150 Window.Restart();
151 }
152 if (result == MessageDialogButton.Button2) {
153 ScreensManager.SwitchScreen("Content");
154 }
155 }
156 )
157 );
158 }
159 else {
160 ScreensManager.SwitchScreen("Content");
161 }
162 }
163 }
164
165 public void TriggerEnable(ModEntity entity) {
166 if (entity.IsDisabled) {
167 if (entity.DisableReason == ModDisableReason.Manually) {
168 if (ModsManager.DisabledMods.TryGetValue(entity.modInfo!.PackageName, out HashSet<string> versions)) {
169 if (!versions.Remove(entity.modInfo.Version)) {
170 versions.Add(entity.modInfo.Version);
171 }
172 }
173 else {
175 }
176 m_needRestart = true;
177 }
178 }
179 else if (entity.modInfo!.PackageName is not "survivalcraft" and not "fastdebug") {
180 if (ModsManager.DisabledMods.TryGetValue(entity.modInfo.PackageName, out HashSet<string> versions)) {
181 if (!versions.Remove(entity.modInfo.Version)) {
182 versions.Add(entity.modInfo.Version);
183 }
184 }
185 else {
187 }
188 m_needRestart = true;
189 }
190 if (m_modsContentList.m_widgetsByIndex[m_modsContentList.SelectedIndex!.Value] is ModsManageContentItemWidget itemWidget) {
191 m_triggerEnableButton.Text = LanguageControl.Get(fName, GetTriggerAndTitle(entity, out string title, out Color titleColor) ? "19" : "18");
192 itemWidget.Title = title;
193 itemWidget.TitleColor = titleColor;
194 }
195 }
196
198 public static bool GetTriggerAndTitle(ModEntity entity, out string title, out Color titleColor) {
199 title = entity.modInfo?.Name ?? Storage.GetFileName(entity.ModFilePath);
200 titleColor = Color.White;
201 if (entity.IsDisabled) {
202 if (entity.DisableReason == ModDisableReason.Manually) {
203 if (ModsManager.DisabledMods.TryGetValue(entity.modInfo!.PackageName, out HashSet<string> versions1)
204 && versions1.Contains(entity.modInfo.Version)) {
205 title = $"[{LanguageControl.Get(fName, "22")}] {title}";
206 titleColor = Color.Red;
207 return true;
208 }
209 title = $"[{LanguageControl.Get(fName, "23")} {LanguageControl.Get(fName, "81")}] {title}";
210 titleColor = Color.Yellow;
211 return false;
212 }
213 title = $"[{LanguageControl.Get(fName, "22")}] {title}";
214 titleColor = Color.Red;
215 return true;
216 }
217 if (entity.modInfo != null
218 && ModsManager.DisabledMods.TryGetValue(entity.modInfo!.PackageName, out HashSet<string> versions2)
219 && versions2.Contains(entity.modInfo.Version)) {
220 title = $"[{LanguageControl.Get(fName, "22")} {LanguageControl.Get(fName, "81")}] {title}";
221 titleColor = Color.Yellow;
222 return true;
223 }
224 return false;
225 }
226
228 public static bool GetTrigger(ModEntity entity) {
229 if (entity.IsDisabled) {
230 if (entity.DisableReason == ModDisableReason.Manually) {
231 return ModsManager.DisabledMods.TryGetValue(entity.modInfo!.PackageName, out HashSet<string> versions1)
232 && versions1.Contains(entity.modInfo.Version);
233 }
234 return true;
235 }
236 return entity.modInfo != null
237 && ModsManager.DisabledMods.TryGetValue(entity.modInfo!.PackageName, out HashSet<string> versions2)
238 && versions2.Contains(entity.modInfo.Version);
239 }
240}
static string GetFileName(string path)
static void Restart()
readonly WidgetsList Children
static object Get(Type type, string name)
static string Format(long bytes, int significantDigits=3)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
ModDisableReason DisableReason
string PackageName
VersionRange ApiVersionRange
string Description
string ApiVersion
static void SwitchScreen(string name, params object[] parameters)
static void LaunchBrowser(string url)
virtual void LoadContents(object eventsTarget, XElement node)
static bool IsOldApiVersionMod(ModEntity modEntity, out string description)
override void Enter(object[] parameters)
static bool GetTrigger(ModEntity entity)
true: mod能被启用,false:mod能被禁用
static bool GetTriggerAndTitle(ModEntity entity, out string title, out Color titleColor)
true: mod能被启用,false:mod能被禁用
static NuGetVersion APINuGetVersion
static Dictionary< string, HashSet< string > > DisabledMods
static List< ModEntity > ModListAll
所有模组,含禁用的
static Color Red
static Color White
static Color Yellow