Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ViewGameLogDialog.cs
浏览该文件的文档.
1using System.Text.Json.Nodes;
2using System.Xml.Linq;
3using Engine;
4
5namespace Game {
6 public class ViewGameLogDialog : Dialog {
8
10
12
13 public static string fName = "ViewGameLogDialog";
14
16
17 public void SetErrorHead(int headLangIndex, int adviceLangIndex) {
18 m_headText.Text = LanguageControl.Get(fName, headLangIndex);
19 m_adviceText.Text = LanguageControl.Get(fName, adviceLangIndex);
20 }
21
23 XElement node = ContentManager.Get<XElement>("Dialogs/ViewGameLogDialog");
24 LoadContents(this, node);
25 m_listPanel = Children.Find<ListPanelWidget>("ViewGameLogDialog.ListPanel");
26 m_clearButton = Children.Find<ButtonWidget>("ViewGameLogDialog.Clear");
27 m_copyButton = Children.Find<ButtonWidget>("ViewGameLogDialog.Copy");
28 m_filterButton = Children.Find<ButtonWidget>("ViewGameLogDialog.Filter");
29 m_filterButton.Style = ContentManager.Get<XElement>("Styles/ButtonStyle_160x60");
30 m_closeButton = Children.Find<ButtonWidget>("ViewGameLogDialog.Close");
31 m_uploadButton = Children.Find<ButtonWidget>("ViewGameLogDialog.Upload");
32 m_headText = Children.Find<LabelWidget>("HeadText");
33 m_adviceText = Children.Find<LabelWidget>("AdviceText");
34 m_listPanel.ItemClicked += delegate(object item) {
35 if (m_listPanel.SelectedItem == item) {
38 new MessageDialog(
39 "Log Item",
40 item.ToString(),
43 button => {
44 if (button == MessageDialogButton.Button2) {
45 ClipboardManager.ClipboardString = item.ToString();
46 }
47 }
48 )
49 );
50 }
51 };
53 }
54
55 public override void Update() {
56 if (m_clearButton.IsClicked) {
57 GameLogSink.m_stream.SetLength(0);
58 m_listPanel.ClearItems();
59 }
60 if (m_copyButton.IsClicked) {
62 }
63 if (m_filterButton.IsClicked) {
67 }
68 if (Input.Cancel
69 || m_closeButton.IsClicked) {
71 }
72 if (m_filter == LogType.Debug) {
73 m_filterButton.Text = LanguageControl.Get(fName, "15");
74 }
75 else if (m_filter == LogType.Warning) {
76 m_filterButton.Text = LanguageControl.Get(fName, "16");
77 }
78 else if (m_filter == LogType.Error) {
79 m_filterButton.Text = LanguageControl.Get(fName, "17");
80 }
81 if (m_uploadButton.IsClicked) {
82 if (string.IsNullOrEmpty(SettingsManager.ScpboxAccessToken)) {
83 MessageDialog messageDialog = new(
88 _ => { DialogsManager.HideAllDialogs(); }
89 );
90 DialogsManager.ShowDialog(this, messageDialog);
91 }
92 else {
93 CancellableProgress cancellableProgress = new();
94 CancellableBusyDialog dialog = new(LanguageControl.Get(fName, 5), true);
95 DialogsManager.ShowDialog(this, dialog);
96 JsonObject jsonObject = new();
97 Dictionary<string, string> dictionary = new();
98 jsonObject.Add("path", $"/GameLog/{DateTime.Now.Ticks}.log");
99 dictionary.Add("Authorization", $"Bearer {SettingsManager.ScpboxAccessToken}");
100 dictionary.Add("Content-Type", "application/octet-stream");
101 dictionary.Add("Dropbox-API-Arg", jsonObject.ToJsonString());
102 MemoryStream memoryStream = new();
103 GameLogSink.m_stream.Seek(0, SeekOrigin.Begin);
104 GameLogSink.m_stream.CopyTo(memoryStream);
105 memoryStream.Seek(0, SeekOrigin.Begin);
107 $"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/files/upload",
108 null,
109 dictionary,
110 memoryStream,
111 cancellableProgress,
112 delegate {
113 dialog.LargeMessage = LanguageControl.Get(fName, 6);
114 dialog.m_cancelButtonWidget.Text = "OK";
115 GameLogSink.m_writer.BaseStream.SetLength(0);
116 GameLogSink.m_writer.Flush();
117 PopulateList();
118 },
119 delegate(Exception error) {
120 dialog.LargeMessage = LanguageControl.Get(fName, 7);
121 dialog.SmallMessage = error.Message;
122 }
123 );
124 }
125 }
126 }
127
128 public void PopulateList() {
129 m_listPanel.ItemWidgetFactory = delegate(object item) {
130 string text = item != null ? item.ToString() : string.Empty;
131 Color color = Color.Gray;
132 if (text.Contains("ERROR:")) {
133 color = Color.Red;
134 }
135 else if (text.Contains("WARNING:")) {
136 color = Color.DarkYellow;
137 }
138 else if (text.Contains("INFO:")) {
139 color = Color.LightGray;
140 }
142 "ModifyLogColor",
143 loader => {
144 loader.ModifyLogColor(text, ref color);
145 return false;
146 }
147 );
148 return new LabelWidget {
149 Text = text,
150 Font = LabelWidget.BitmapFont,
153 FontScale = 0.6f,
154 Color = color,
155 Ellipsis = true
156 };
157 };
158 List<string> recentLogLines = GameLogSink.GetRecentLogLines(131072);
159 m_listPanel.ClearItems();
160 if (recentLogLines.Count > 1000) {
161 recentLogLines.RemoveRange(0, recentLogLines.Count - 1000);
162 }
163 foreach (string item in recentLogLines) {
164 if (m_filter == LogType.Warning) {
165 if (!item.Contains("WARNING:")
166 && !item.Contains("ERROR:")) {
167 continue;
168 }
169 }
170 else if (m_filter == LogType.Error
171 && !item.Contains("ERROR:")) {
172 continue;
173 }
174 m_listPanel.AddItem(item);
175 }
176 m_listPanel.ScrollPosition = m_listPanel.Items.Count * m_listPanel.ItemSize;
177 }
178 }
179}
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static List< string > GetRecentLogLines(int bytesCount)
static string GetRecentLog(int bytesCount)
static StreamWriter m_writer
static Stream m_stream
static BitmapFont BitmapFont
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
void SetErrorHead(int headLangIndex, int adviceLangIndex)
static void Post(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, Stream data, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
ContainerWidget ParentWidget
virtual WidgetAlignment VerticalAlignment
virtual WidgetAlignment HorizontalAlignment
virtual void LoadContents(object eventsTarget, XElement node)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Color DarkYellow
static Color Red
static Color LightGray
static Color Gray