Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ModDetailsDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3using NuGet.Versioning;
4
5namespace Game {
6 public class ModDetailsDialog : Dialog {
9
15
16 public const string fName = "ModDetailsDialog";
17
19 m_screen = screen;
20 m_entity = entity;
21 XElement node = ContentManager.Get<XElement>("Dialogs/ModDetailsDialog");
22 LoadContents(this, node);
23 m_titleLabel = Children.Find<LabelWidget>("ModDetailsDialog.Title");
24 m_contentPanel = Children.Find<StackPanelWidget>("ModDetailsDialog.Content");
25 m_triggerEnableButton = Children.Find<ButtonWidget>("ModDetailsDialog.TriggerEnable");
26 m_deleteButton = Children.Find<ButtonWidget>("ModDetailsDialog.Delete");
27 m_closeButton = Children.Find<ButtonWidget>("ModDetailsDialog.Close");
28 Vector2 margin = new Vector2(0f, 4f);
29 if (entity.IsDisabled) {
30 m_contentPanel.Children.Add(
31 new LabelWidget {
32 Text = $"{LanguageControl.Get(fName, "1")}{LanguageControl.Get("ModDisableReason", entity.DisableReason.ToString())}",
33 Margin = margin
34 }
35 );
36 }
37 ModInfo modInfo = entity.modInfo;
38 if (modInfo == null) {
39 Size = new Vector2(600f, 250f);
40 }
41 else {
42 m_contentPanel.Children.Add(
43 new LabelWidget {
44 Text = $"{LanguageControl.Get(fName, "2")}{(string.IsNullOrEmpty(modInfo.Version) ? LanguageControl.None : modInfo.Version)}",
45 Margin = margin
46 }
47 );
48 m_contentPanel.Children.Add(
49 new LabelWidget {
50 Text =
51 $"{LanguageControl.Get(fName, "3")}{(string.IsNullOrEmpty(modInfo.ApiVersion) ? LanguageControl.Unknown : modInfo.ApiVersion)}",
52 Margin = margin
53 }
54 );
55 m_contentPanel.Children.Add(
56 new LabelWidget {
57 Text =
58 $"{LanguageControl.Get(fName, "4")}{(string.IsNullOrEmpty(modInfo.Author) ? LanguageControl.Unknown : modInfo.Author)}",
59 WordWrap = true,
60 Margin = margin
61 }
62 );
63 m_contentPanel.Children.Add(
64 new LabelWidget { Text = $"{LanguageControl.Get(fName, "5")}{DataSizeFormatter.Format(entity.Size)}", Margin = margin }
65 );
66 m_contentPanel.Children.Add(
67 new LabelWidget {
68 Text =
69 $"{LanguageControl.Get(fName, "6")}{(string.IsNullOrEmpty(modInfo.Description) ? LanguageControl.None : modInfo.Description)}",
70 WordWrap = true,
71 Margin = margin
72 }
73 );
74 if (string.IsNullOrEmpty(modInfo.Link)) {
75 m_contentPanel.Children.Add(
76 new LabelWidget { Text = $"{LanguageControl.Get(fName, "7")}{LanguageControl.None}", Margin = margin }
77 );
78 }
79 else {
80 m_contentPanel.Children.Add(
82 Direction = LayoutDirection.Horizontal,
83 Children = {
84 new LabelWidget { Text = LanguageControl.Get(fName, "7") },
85 new LinkWidget { Text = modInfo.Link, Url = modInfo.Link, Color = new Color(64, 192, 64) }
86 },
87 Margin = margin
88 }
89 );
90 }
91 if (!string.IsNullOrEmpty(entity.ModFilePath)) {
92 m_contentPanel.Children.Add(
93 new LabelWidget {
94 Text = $"{LanguageControl.Get(fName, "8")}{Storage.GetFileName(entity.ModFilePath)}", WordWrap = true, Margin = margin
95 }
96 );
97 }
98 m_contentPanel.Children.Add(new LabelWidget { Text = $"{LanguageControl.Get(fName, "9")}{modInfo.PackageName}", WordWrap = true });
99 if (modInfo.DependencyRanges.Count > 0) {
100 m_contentPanel.Children.Add(new CanvasWidget { Size = new Vector2(0f, 8f) });
101 m_contentPanel.Children.Add(new LabelWidget { Text = LanguageControl.Get(fName, "10") });
102 foreach (KeyValuePair<string, VersionRange> dependency in modInfo.DependencyRanges) {
103 m_contentPanel.Children.Add(new LabelWidget { Text = $" - {dependency.Key} {dependency.Value}" });
104 }
105 }
106 }
107 m_triggerEnableButton.IsEnabled = entity.IsDisabled
108 ? entity.DisableReason == ModDisableReason.Manually
109 : entity.modInfo?.PackageName is not "survivalcraft" and not "fastdebug";
110 m_deleteButton.IsEnabled = entity.modInfo?.PackageName is not "survivalcraft" and not "fastdebug"
111 && !string.IsNullOrEmpty(entity.ModFilePath);
113 }
114
115 public override void Update() {
116 if (m_triggerEnableButton.IsClicked) {
117 m_screen.TriggerEnable(m_entity);
119 }
120 if (m_deleteButton.IsClicked) {
122 null,
123 new MessageDialog(
125 string.Format(LanguageControl.Get(fName, "12"), m_entity.ModFilePath),
128 button => {
129 if (button == MessageDialogButton.Button1) {
130 try {
131 Storage.DeleteFile(m_entity.ModFilePath);
132 m_screen.m_needRestart = true;
133 ModsManager.ModListAll.Remove(m_entity);
134 ModsManager.ModList.Remove(m_entity);
135 if (m_entity.modInfo != null && !string.IsNullOrEmpty(m_entity.modInfo.PackageName)) {
136 ModsManager.PackageNameToModEntity.Remove(m_entity.modInfo.PackageName);
137 if (ModsManager.DisabledMods.TryGetValue(m_entity.modInfo.PackageName, out HashSet<string> versions)) {
138 versions.Remove(m_entity.modInfo.Version);
139 if (versions.Count == 0) {
140 ModsManager.DisabledMods.Remove(m_entity.modInfo.PackageName);
141 }
142 }
143 }
144 m_screen.m_modsContentList.RemoveItem(m_entity);
145 DialogsManager.HideDialog(this);
146 DialogsManager.ShowDialog(
147 null,
148 new MessageDialog(
149 LanguageControl.Success,
150 string.Format(LanguageControl.Get(fName, "14"), m_entity.ModFilePath),
151 LanguageControl.Ok,
152 null,
153 null
154 )
155 );
156 }
157 catch (Exception e) {
158 string str = string.Format(LanguageControl.Get(fName, "13"), m_entity.ModFilePath, e.Message);
159 Log.Error(str);
160 DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Error, str, LanguageControl.Ok, null, null));
161 }
162 }
163 }
164 )
165 );
166 }
167 if (Input.Back
168 || Input.Cancel
171 }
172 }
173
175 bool canBeEnabled = ModsManageContentScreen.GetTriggerAndTitle(m_entity, out string title, out Color titleColor);
176 m_titleLabel.Text = title;
177 m_titleLabel.Color = titleColor;
178 m_triggerEnableButton.Text = LanguageControl.Get("ModsManageContentScreen", canBeEnabled ? "19" : "18");
179 }
180 }
181}
Engine.Color Color
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
ModsManageContentScreen m_screen
ModDetailsDialog(ModsManageContentScreen screen, ModEntity entity)
Dictionary< string, VersionRange > DependencyRanges
string PackageName
virtual Vector2 Margin
virtual void LoadContents(object eventsTarget, XElement node)
static bool GetTriggerAndTitle(ModEntity entity, out string title, out Color titleColor)
true: mod能被启用,false:mod能被禁用