2024-04-02 23:14:34 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2024-04-18 08:38:59 +08:00
|
|
|
|
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
|
2024-04-02 23:14:34 +08:00
|
|
|
|
|
|
|
|
|
namespace CDSAE3_Lian_Lian_Kan.Forms
|
|
|
|
|
{
|
2024-04-18 08:38:59 +08:00
|
|
|
|
public partial class Setting : Form, IThemeChangeable
|
2024-04-02 23:14:34 +08:00
|
|
|
|
{
|
2024-04-18 08:38:59 +08:00
|
|
|
|
private readonly List<string> _albums;
|
|
|
|
|
private readonly List<string> _themes;
|
|
|
|
|
TextBox[] textBoxes;
|
2024-04-02 23:14:34 +08:00
|
|
|
|
public Setting()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-04-18 08:38:59 +08:00
|
|
|
|
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
|
|
|
|
|
textBoxes = [cusWidth, cusHeight, time, songVolumeText, soundScapeVolumeText];
|
|
|
|
|
_albums = Etcs.musics.Keys.ToList();
|
|
|
|
|
albumSelector.Items.AddRange(_albums.ToArray());
|
|
|
|
|
_themes = Etcs.themes.Keys.ToList();
|
|
|
|
|
themeSelector.Items.AddRange(_themes.ToArray());
|
|
|
|
|
themeSelector.SelectedItem = "Fruit";
|
|
|
|
|
SetTheme();
|
|
|
|
|
}
|
|
|
|
|
public void SetTheme()
|
|
|
|
|
{
|
|
|
|
|
Etcs.ThemeInfo themeInfo = Etcs.currentThemeInfo;
|
|
|
|
|
BackColor = Color.FromArgb(themeInfo.ThemeColor![0], themeInfo.ThemeColor[1], themeInfo.ThemeColor[2]);
|
|
|
|
|
foreach (var item in textBoxes)
|
|
|
|
|
{
|
|
|
|
|
contextPanel.BackColor = BackColor;
|
|
|
|
|
item.BackColor = BackColor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool is_pause = false;
|
|
|
|
|
public void Resume()
|
|
|
|
|
{
|
|
|
|
|
is_pause = false;
|
|
|
|
|
psButton.Image = Properties.Resources.pause;
|
|
|
|
|
Etcs.song_Audio_Processer.resume_song();
|
|
|
|
|
}
|
|
|
|
|
public void Pause()
|
|
|
|
|
{
|
|
|
|
|
is_pause = true;
|
|
|
|
|
psButton.Image = Properties.Resources.play_buttton;
|
|
|
|
|
Etcs.song_Audio_Processer.pause_song();
|
|
|
|
|
}
|
|
|
|
|
private void psButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (is_pause)
|
|
|
|
|
Resume();
|
|
|
|
|
else
|
|
|
|
|
Pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lastSong_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Etcs.song_Audio_Processer.set_song(Etcs.song_Audio_Processer.get_last_song());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nextSong_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Etcs.song_Audio_Processer.set_song(Etcs.song_Audio_Processer.get_next_song());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void SetSongInfo(string songName)
|
|
|
|
|
{
|
|
|
|
|
this.songName.Text = "歌曲:" + songName;
|
|
|
|
|
Console.WriteLine(this.songName.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void SetAlbum(string albumName)
|
|
|
|
|
{
|
|
|
|
|
if ((albumSelector.SelectedItem?.ToString() ?? "") != albumName)
|
|
|
|
|
{
|
|
|
|
|
albumSelector.SelectedItem = albumName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void albumSelector_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var s = albumSelector.SelectedItem?.ToString();
|
|
|
|
|
if (s != null)
|
2024-04-19 10:00:37 +08:00
|
|
|
|
{
|
2024-04-18 08:38:59 +08:00
|
|
|
|
Etcs.song_Audio_Processer.set_albums(s);
|
2024-04-19 10:00:37 +08:00
|
|
|
|
Etcs.curAlbum = s;
|
|
|
|
|
}
|
2024-04-18 08:38:59 +08:00
|
|
|
|
nextSong_Click(this, new EventArgs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void musicVolume_Scroll(object? sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-19 10:00:37 +08:00
|
|
|
|
Etcs.Song_Volume = musicVolume.Value;
|
2024-04-18 08:38:59 +08:00
|
|
|
|
Etcs.song_Audio_Processer.volume_change(musicVolume.Value);
|
|
|
|
|
if (sender != null)
|
|
|
|
|
songVolumeText.Text = musicVolume.Value.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void soundScapeVolume_Scroll(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Etcs.Info_Volume = soundScapeVolume.Value;
|
|
|
|
|
if (sender != null)
|
|
|
|
|
soundScapeVolumeText.Text = soundScapeVolume.Value.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _canBack = true;
|
|
|
|
|
private async void back_ClickAsync(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CusSize_Validated(this, new EventArgs());
|
|
|
|
|
if (_canBack)
|
2024-04-19 10:00:37 +08:00
|
|
|
|
await Etcs.form!.change_form((Etcs.gameMenuForm as Form)!, false, null, null);
|
2024-04-18 08:38:59 +08:00
|
|
|
|
}
|
|
|
|
|
private void SetTimeText(int t) => time.Text = $"{t / 60}:{((t % 60) < 10 ? ("0" + (t % 60).ToString()) : (t % 60).ToString())}";
|
|
|
|
|
private int CalcTime(int total) => (int)(Math.Ceiling((double)total / 50)) * 60;//50per minute 向上取整
|
|
|
|
|
private int LimitedCalcTime(int total) => (int)((double)total / 90 * 60);//90per minute 不取整 极限值
|
|
|
|
|
private void Difficulty_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch ((sender as RadioButton)!.Name)
|
|
|
|
|
{
|
|
|
|
|
case "easy":
|
|
|
|
|
Etcs.current_difficulty = Etcs.Difficulty.easy;
|
|
|
|
|
break;
|
|
|
|
|
case "normal":
|
|
|
|
|
Etcs.current_difficulty = Etcs.Difficulty.normal;
|
|
|
|
|
break;
|
|
|
|
|
case "hard":
|
|
|
|
|
Etcs.current_difficulty = Etcs.Difficulty.hard;
|
|
|
|
|
break;
|
|
|
|
|
case "custom":
|
|
|
|
|
Etcs.current_difficulty = Etcs.Difficulty.custom;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
var (a, b) = Etcs.get_length_width();
|
|
|
|
|
int ans = CalcTime(a * b);
|
|
|
|
|
Etcs.left_time = ans;
|
|
|
|
|
SetTimeText(ans);
|
|
|
|
|
}
|
|
|
|
|
private bool _cusDataChanged = false;
|
|
|
|
|
private void cusWidth_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(cusWidth.Text, out int a))
|
|
|
|
|
{
|
|
|
|
|
_cusDataChanged = true;
|
|
|
|
|
Etcs.cus_width = a;
|
|
|
|
|
custom.Checked = true;
|
|
|
|
|
Difficulty_CheckedChanged(custom, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cusWidth.Text = new string(cusWidth.Text.Where(x => char.IsDigit(x)).ToArray());
|
|
|
|
|
}
|
|
|
|
|
private void cusHeight_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(cusHeight.Text, out int a))
|
|
|
|
|
{
|
|
|
|
|
_cusDataChanged = true;
|
|
|
|
|
Etcs.cus_height = a;
|
|
|
|
|
custom.Checked = true;
|
|
|
|
|
Difficulty_CheckedChanged(custom, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cusHeight.Text = new string(cusHeight.Text.Where(x => char.IsDigit(x)).ToArray());
|
|
|
|
|
}
|
|
|
|
|
private void CusSize_Validated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_cusDataChanged)
|
|
|
|
|
return;
|
|
|
|
|
var (a, b) = Etcs.get_length_width();
|
|
|
|
|
int total = a * b;
|
|
|
|
|
if (Etcs.left_time < LimitedCalcTime(total))
|
|
|
|
|
{
|
|
|
|
|
int t = LimitedCalcTime(total);
|
|
|
|
|
DialogResult result = MessageBox.Show($"你这个时间挺极限的,建议设置的时间不小于{t / 60}:{((t % 60) < 10 ? ("0" + (t % 60).ToString()) : (t % 60).ToString())} \n 确定退出吗?", "注意", MessageBoxButtons.OKCancel);
|
|
|
|
|
if (result == DialogResult.Cancel || result == DialogResult.None)
|
|
|
|
|
_canBack = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int lastTime = 0;
|
|
|
|
|
private int getTime()
|
|
|
|
|
{
|
|
|
|
|
string s = time.Text;
|
|
|
|
|
string[] strings = s.Split(":");
|
|
|
|
|
return int.Parse(strings[0]) * 60 + int.Parse(strings[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void time_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lastTime = getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void time_Validated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int newTime = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
newTime = getTime();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(Text = "输入格式错误");
|
|
|
|
|
SetTimeText(lastTime);
|
|
|
|
|
}
|
|
|
|
|
if (lastTime != newTime)
|
|
|
|
|
{
|
|
|
|
|
_cusDataChanged = true;
|
|
|
|
|
Etcs.left_time = newTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void songVolumeText_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(songVolumeText.Text, out int a))
|
|
|
|
|
{
|
|
|
|
|
if (a > 100)
|
|
|
|
|
a = 100;
|
|
|
|
|
if (a < 0)
|
|
|
|
|
a = 0;
|
|
|
|
|
songVolumeText.Text = a.ToString();
|
|
|
|
|
if (sender != null)
|
|
|
|
|
{
|
|
|
|
|
musicVolume.Value = a;
|
|
|
|
|
musicVolume_Scroll(null, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
songVolumeText.Text = new string(songVolumeText.Text.Where(x => char.IsDigit(x)).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void soundScapeVolumeText_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(soundScapeVolumeText.Text, out int a))
|
|
|
|
|
{
|
|
|
|
|
if (a > 100)
|
|
|
|
|
a = 100;
|
|
|
|
|
if (a < 0)
|
|
|
|
|
a = 0;
|
|
|
|
|
soundScapeVolumeText.Text = a.ToString();
|
|
|
|
|
if (sender != null)
|
|
|
|
|
{
|
|
|
|
|
soundScapeVolume.Value = a;
|
|
|
|
|
soundScapeVolume_Scroll(null, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
soundScapeVolumeText.Text = new string(soundScapeVolumeText.Text.Where(x => char.IsDigit(x)).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void themeSelector_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var s = themeSelector.SelectedItem?.ToString();
|
|
|
|
|
if (s == null || s.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
Etcs.currentThemeInfo = Etcs.themes[s!];
|
|
|
|
|
SetTheme();
|
2024-04-02 23:14:34 +08:00
|
|
|
|
}
|
2024-04-19 10:00:37 +08:00
|
|
|
|
|
|
|
|
|
private void Algorithm_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch ((sender as RadioButton)!.Name)
|
|
|
|
|
{
|
|
|
|
|
case "ArrayAlgorithm":
|
|
|
|
|
Etcs.curAlgorithm = Etcs.Algorithm.Array;
|
|
|
|
|
break;
|
|
|
|
|
case "GraphAlgorithm":
|
|
|
|
|
Etcs.curAlgorithm = Etcs.Algorithm.Graph;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-02 23:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|