This repository has been archived on 2024-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
CDSAE3/CDSAE3_Lian_Lian_Kan/Forms/Charts.cs

113 lines
4.8 KiB
C#
Raw Normal View History

2024-04-18 00:38:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
using System.Threading.Tasks;
using System.Windows.Forms;
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
using static CDSAE3_Lian_Lian_Kan.Etcs;
namespace CDSAE3_Lian_Lian_Kan.Forms
{
public partial class Charts : Form, IThemeChangeable
{
private int[] _width = { 504, 328, 156, 157, 178 };
private int _top = 0, _left = 0;
public Charts()
{
InitializeComponent();
scoreRecord = JsonSerializer.Deserialize<Etcs.ScoreRecord>(File.ReadAllText("Resources\\charts.json"), new JsonSerializerOptions()
{
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
})!;
}
private Label[] LabelsMaker(string[] info, int height, Color? color, Font? font)
{
int oriHeight = height;
color ??= Color.FromArgb(0, 0, 0, 0);
List<Label> labels = new();
int temp_left = _left;
for (int i = 0; i < 5; i++)
{
labels.Add(new Label { Text = info[i], Width = _width[i], Height = height, Left = temp_left, Top = _top, BackColor = color.Value, Font = font, TextAlign = ContentAlignment.MiddleCenter });
temp_left += _width[i];
height = Math.Max(labels[i].Height, height);
tablePanel.Controls.Add(labels[i]);
}
if (oriHeight < height)
foreach (var item in labels)
item.Height = height;
_top += height;
return labels.ToArray();
}
ScoreRecord scoreRecord;
public void Init()
{
var lt = scoreRecord.RecordInfos;
if (lt == null || lt.Count == 0)
return;
lt = lt.OrderByDescending(x => x.Score).ToList();
for (int i = 1; i <= lt.Count; i++)
{
List<string> strings = new List<string>();
strings.Add(lt[i - 1].Name!);
strings.Add(string.Format("{0:yyyy}-" + "{0:MM}-" + "{0:dd}" + " {0:HH}:{0:mm}", lt[i - 1].Time));
strings.Add($"{lt[i - 1].CostTime!.Value / 60}:{((lt[i - 1].CostTime!.Value % 60) < 10 ? ("0" + (lt[i - 1].CostTime!.Value % 60).ToString()) : (lt[i - 1].CostTime!.Value % 60).ToString())}");
strings.Add(lt[i - 1].Score.ToString()!);
strings.Add(lt[i - 1].Difficulty!);
Invoke(() => LabelsMaker(strings.ToArray(), 60, null, Font = new Font("Microsoft YaHei UI", 18F)));
}
Console.WriteLine("Charts Fill done");
}
public void AddRecord(Etcs.RecordInfo recordInfo)
{
scoreRecord.RecordInfos!.Add(recordInfo);
using StreamWriter fileWriter = new StreamWriter("Resources\\charts.json");
fileWriter.Write(JsonSerializer.Serialize(scoreRecord, new JsonSerializerOptions { WriteIndented = true }));
}
public void SetTheme()
{
//(30,135) 504 328 156 157 178
Etcs.ThemeInfo themeInfo = Etcs.currentThemeInfo;
BackColor = Color.FromArgb(themeInfo.ThemeColor![0], themeInfo.ThemeColor[1], themeInfo.ThemeColor[2]);
string[] title_info = { "姓名", "完成时间", "用时", "分数", "难度" };
if (themeInfo.ThemeColor[0] < themeInfo.ThemeColor[2])
{
LabelsMaker(title_info, 65, Color.FromArgb(50, 255, 255, 255), Font = new Font("Microsoft YaHei UI", 18F));
tablePanel.BackColor = Color.FromArgb(50, 255, 255, 255);
}
else
{
LabelsMaker(title_info, 65, Color.FromArgb(50, 0, 0, 0), Font = new Font("Microsoft YaHei UI", 18F));
tablePanel.BackColor = Color.FromArgb(50, 0, 0, 0);
}
if (themeInfo.PlayPanelUsePicture)
{
if (themeInfo.PlayPanelPictureIsOutPicture)
BackgroundImage = new Bitmap(themeInfo.PlayPanelPictureName!);
else
BackgroundImage = (Image)Etcs.res_Manager.GetObject(themeInfo.PictureName!, Etcs.res_Culture)!;
back.BackColor = Color.FromArgb(0, 0, 0, 0);
.BackColor = Color.FromArgb(0, 0, 0, 0);
}
Thread initThread = new Thread(Init);
initThread.Start();
}
private async void back_Click(object sender, EventArgs e)
{
Thread thread= new Thread(()=>Invoke(()=>tablePanel.Controls.Clear()));
_left = _top = 0;
2024-04-19 02:00:37 +00:00
await Etcs.form!.change_form((Etcs.gameMenuForm as Form)!, false, null, null);
2024-04-18 00:38:59 +00:00
thread.Start();
}
}
}