276 lines
12 KiB
C#
276 lines
12 KiB
C#
|
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Security.Cryptography;
|
|||
|
using System.Text;
|
|||
|
using System.Text.Json;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using static CDSAE3_Lian_Lian_Kan.Etcs;
|
|||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|||
|
|
|||
|
namespace CDSAE3_Lian_Lian_Kan.Forms
|
|||
|
{
|
|||
|
public partial class CreateNewTheme : Form, IBack
|
|||
|
{
|
|||
|
public CreateNewTheme()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
MessageBox.Show("按esc键退出");
|
|||
|
Etcs.escapableForm = this;
|
|||
|
}
|
|||
|
Point currentOperControlLocation;
|
|||
|
private void MoveableControl_MouseDown(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
Control send = (sender as Control)!;
|
|||
|
Point MousePoint = Control.MousePosition; // 获取鼠标相对屏幕的坐标
|
|||
|
currentOperControlLocation = send.PointToClient(MousePoint); // 获取坐标相对于控件的相对坐标并赋值给MouseFirstLocation
|
|||
|
}
|
|||
|
|
|||
|
private void MoveableControl_MouseMove(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
Control send = (sender as Control)!;
|
|||
|
if (e.Button == MouseButtons.Left)
|
|||
|
{
|
|||
|
Point MousePoint = Control.MousePosition; // 获取鼠标相对屏幕的坐标
|
|||
|
Point MousePointToContainer = send.Parent!.PointToClient(MousePoint); // 获取鼠标相对控件父容器的坐标
|
|||
|
Point ControlNewLocation = new Point(MousePointToContainer.X - currentOperControlLocation.X, MousePointToContainer.Y - currentOperControlLocation.Y); // 计算控件应处于的, 新的坐标
|
|||
|
send.Location = ControlNewLocation; // 移动控件
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//private void ExempleButton_MouseUp(object sender, MouseEventArgs e)
|
|||
|
//{
|
|||
|
//}
|
|||
|
private void MoveableControl_MouseUp(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
changed = true;
|
|||
|
switch ((sender as Control)!.Name)
|
|||
|
{
|
|||
|
case "mainLabel":
|
|||
|
theme!.FontBlockPos = new List<int> { mainLabel.Location.X, mainLabel.Location.Y };
|
|||
|
break;
|
|||
|
case "start_Game":
|
|||
|
theme!.StartGamePos = new List<int> { start_Game.Location.X, start_Game.Location.Y };
|
|||
|
break;
|
|||
|
case "to_settings":
|
|||
|
theme!.SettingsPos = new List<int> { to_settings.Location.X, to_settings.Location.Y };
|
|||
|
break;
|
|||
|
case "to_Challenge_mode":
|
|||
|
theme!.ChallengeModePos = new List<int> { to_Challenge_mode.Location.X, to_Challenge_mode.Location.Y };
|
|||
|
break;
|
|||
|
case "to_table_of_scores":
|
|||
|
theme!.ScoreBoardPos = new List<int> { to_table_of_scores.Location.X, to_table_of_scores.Location.Y };
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool AnimationUseImage = false;
|
|||
|
bool IsOutPicture = false;
|
|||
|
Image? playPanelImage;
|
|||
|
Color menuThemeColor, playThemeColor;
|
|||
|
private IList<int> toShow(IList<int> src)
|
|||
|
{
|
|||
|
return new List<int> { (int)((double)src[0] * 1280 / 1440), (int)((double)src[1] * 800 / 960) };
|
|||
|
}
|
|||
|
private IList<int> toFile(IList<int> src)
|
|||
|
{
|
|||
|
return new List<int> { (int)((double)src[0] * 1440 / 1280), (int)((double)src[1] * 960 / 800) };
|
|||
|
}
|
|||
|
Etcs.ThemeInfo? theme;
|
|||
|
private bool changed = false;
|
|||
|
|
|||
|
private void toShow()
|
|||
|
{
|
|||
|
theme = (Etcs.ThemeInfo)Etcs.currentThemeInfo.Clone();
|
|||
|
theme.StartGamePos = toShow(theme.StartGamePos!);
|
|||
|
theme.ChallengeModePos = toShow(theme.ChallengeModePos!);
|
|||
|
theme.ScoreBoardPos = toShow(theme.ScoreBoardPos!);
|
|||
|
theme.SettingsPos = toShow(theme.SettingsPos!);
|
|||
|
theme.ButtonSize = toShow(theme.ButtonSize!);
|
|||
|
theme.FontBlockPos = toShow(theme.FontBlockPos!);
|
|||
|
theme.FontBlockSize = toShow(theme.FontBlockSize!);
|
|||
|
}
|
|||
|
private void toFile()
|
|||
|
{
|
|||
|
theme!.StartGamePos = toFile(theme.StartGamePos!);
|
|||
|
theme.ChallengeModePos = toFile(theme.ChallengeModePos!);
|
|||
|
theme.ScoreBoardPos = toFile(theme.ScoreBoardPos!);
|
|||
|
theme.SettingsPos = toFile(theme.SettingsPos!);
|
|||
|
theme.ButtonSize = toFile(theme.ButtonSize!);
|
|||
|
theme.FontBlockPos = toFile(theme.FontBlockPos!);
|
|||
|
theme.FontBlockSize = toFile(theme.FontBlockSize!);
|
|||
|
}
|
|||
|
private void AddRecord()
|
|||
|
{
|
|||
|
toFile();
|
|||
|
Etcs.themes.Add(theme!.Name, theme);
|
|||
|
using StreamWriter fileWriter = new StreamWriter("Resources\\sources.json");
|
|||
|
ThemeInfos themeInfos = new ThemeInfos { Themes = Etcs.themes.Values.ToList() };
|
|||
|
fileWriter.Write(JsonSerializer.Serialize(themeInfos, new JsonSerializerOptions { WriteIndented = true }));
|
|||
|
LoadComboBox();
|
|||
|
changed = false;
|
|||
|
}
|
|||
|
public void SetTheme()
|
|||
|
{
|
|||
|
themeNameTextBox.Text = theme!.Name;
|
|||
|
AnimationUseImage = theme!.AnimationUseImage;
|
|||
|
IsOutPicture = theme.IsOutPicture;
|
|||
|
if (IsOutPicture)
|
|||
|
DesignPanel.BackgroundImage = new Bitmap(theme.PictureName!);
|
|||
|
else
|
|||
|
DesignPanel.BackgroundImage = (Image)Etcs.res_Manager.GetObject(theme.PictureName!, Etcs.res_Culture)!;
|
|||
|
DesignPanel.BackgroundImageLayout = ImageLayout.Stretch;
|
|||
|
if (theme.PlayPanelUsePicture)
|
|||
|
if (theme.PlayPanelPictureIsOutPicture)
|
|||
|
playPanelImage = new Bitmap(theme.PlayPanelPictureName!);
|
|||
|
else
|
|||
|
playPanelImage = (Image)Etcs.res_Manager.GetObject(theme.PlayPanelPictureName!, Etcs.res_Culture)!;
|
|||
|
start_Game.Location = new Point(theme.StartGamePos![0], theme.StartGamePos[1]);
|
|||
|
to_Challenge_mode.Location = new Point(theme.ChallengeModePos![0], theme.ChallengeModePos[1]);
|
|||
|
to_table_of_scores.Location = new Point(theme.ScoreBoardPos![0], theme.ScoreBoardPos[1]);
|
|||
|
to_settings.Location = new Point(theme.SettingsPos![0], theme.SettingsPos[1]);
|
|||
|
menuThemeColor = Color.FromArgb(theme.ThemeColor![0], theme.ThemeColor[1], theme.ThemeColor[2]);
|
|||
|
themeColorTextBox.Text = "0x" + theme.ThemeColor![0].ToString("X") + theme.ThemeColor[1].ToString("X") + theme.ThemeColor[2].ToString("X");
|
|||
|
Color buttonColor = theme.ButtonColor!.Count == 3 ? Color.FromArgb(theme.ButtonColor![0], theme.ButtonColor![1], theme.ButtonColor![2]) :
|
|||
|
Color.FromArgb(theme.ButtonColor![0], theme.ButtonColor![1], theme.ButtonColor![2], theme.ButtonColor![3]);
|
|||
|
playThemeColor = Color.FromArgb(theme.PlayAreaThemeColor![0], theme.PlayAreaThemeColor[1], theme.PlayAreaThemeColor[2]);
|
|||
|
start_Game.BackColor = buttonColor;
|
|||
|
to_Challenge_mode.BackColor = buttonColor;
|
|||
|
to_table_of_scores.BackColor = buttonColor;
|
|||
|
to_settings.BackColor = buttonColor;
|
|||
|
start_Game.Size = new Size(theme.ButtonSize![0], theme.ButtonSize[1]);
|
|||
|
to_Challenge_mode.Size = new Size(theme.ButtonSize[0], theme.ButtonSize[1]);
|
|||
|
to_table_of_scores.Size = new Size(theme.ButtonSize[0], theme.ButtonSize[1]);
|
|||
|
to_settings.Size = new Size(theme.ButtonSize[0], theme.ButtonSize[1]);
|
|||
|
mainLabel.Font = new Font(theme.Font!, float.Parse(theme.FontSize!));
|
|||
|
mainLabel.BackColor = buttonColor;
|
|||
|
mainLabel.ForeColor = Color.FromArgb(theme.FontColor![0], theme.FontColor[1], theme.FontColor[2]);
|
|||
|
mainLabel.Location = new Point(theme.FontBlockPos![0], theme.FontBlockPos[1]);
|
|||
|
mainLabel.Size = new Size(theme.FontBlockSize![0], theme.FontBlockSize[1]);
|
|||
|
}
|
|||
|
|
|||
|
private void UseImageInGame_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
changed = true;
|
|||
|
if ((sender as CheckBox)!.Checked)
|
|||
|
theme!.PlayPanelUsePicture = true;
|
|||
|
else
|
|||
|
theme!.PlayPanelUsePicture = false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void Back()
|
|||
|
{
|
|||
|
if (changed)
|
|||
|
{
|
|||
|
var result = MessageBox.Show("没有保存,是否退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
if (result.Equals(DialogResult.Yes))
|
|||
|
{
|
|||
|
_ = Etcs.form!.change_form(Etcs.setting, false, null, null);
|
|||
|
}
|
|||
|
}
|
|||
|
_ = Etcs.form!.change_form(Etcs.setting, false, null, null);
|
|||
|
}
|
|||
|
|
|||
|
private void themeColorTextBox_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Regex.IsMatch(themeColorTextBox.Text, @"^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$"))
|
|||
|
theme!.ThemeColor = HexToRgb(themeColorTextBox.Text).ToList();
|
|||
|
}
|
|||
|
|
|||
|
private int[] HexToRgb(string hexColor)
|
|||
|
{
|
|||
|
hexColor = hexColor.TrimStart('#');
|
|||
|
|
|||
|
if (hexColor.Length == 3)
|
|||
|
{
|
|||
|
hexColor = string.Concat(hexColor[0], hexColor[0], hexColor[1], hexColor[1], hexColor[2], hexColor[2]);
|
|||
|
}
|
|||
|
|
|||
|
int rgb = Int32.Parse(hexColor, System.Globalization.NumberStyles.HexNumber);
|
|||
|
int red = (rgb >> 16) & 0xFF;
|
|||
|
int green = (rgb >> 8) & 0xFF;
|
|||
|
int blue = rgb & 0xFF;
|
|||
|
|
|||
|
return new int[] { red, green, blue };
|
|||
|
}
|
|||
|
private void themeSelector_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
changed = false;
|
|||
|
var s = themeSelector.SelectedItem?.ToString();
|
|||
|
if (s == null || s.Length == 0)
|
|||
|
return;
|
|||
|
Etcs.currentThemeInfo = Etcs.themes[s!];
|
|||
|
toShow();
|
|||
|
SetTheme();
|
|||
|
}
|
|||
|
|
|||
|
private void CreateNewTheme_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
findPicture.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|||
|
findPicture.Filter = "(*.jpg)|*.jpg|(*.png)|*.png";
|
|||
|
toShow();
|
|||
|
LoadComboBox();
|
|||
|
}
|
|||
|
private void LoadComboBox()
|
|||
|
{
|
|||
|
themeSelector.Items.Clear();
|
|||
|
themeSelector.Items.AddRange(Etcs.themes.Keys.ToList().ToArray());
|
|||
|
}
|
|||
|
|
|||
|
private void themeNameTextBox_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
changed = true;
|
|||
|
theme!.Name = themeNameTextBox.Text;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void saveTheme_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
List<string> names = Etcs.themes.Values.Select(x => x.Name).ToList();
|
|||
|
if (names.Contains(theme!.Name))
|
|||
|
{
|
|||
|
MessageBox.Show("已存在该主题");
|
|||
|
return;
|
|||
|
}
|
|||
|
AddRecord();
|
|||
|
}
|
|||
|
|
|||
|
private void findPicture_FileOk(object sender, CancelEventArgs e)
|
|||
|
{
|
|||
|
var send = (sender as OpenFileDialog)!;
|
|||
|
theme!.IsOutPicture = true;
|
|||
|
theme.PictureName = send.FileName;
|
|||
|
DesignPanel.BackgroundImage = new Bitmap(theme.PictureName!);
|
|||
|
}
|
|||
|
|
|||
|
private void insertImage_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
findPicture.ShowDialog();
|
|||
|
}
|
|||
|
|
|||
|
private void tranaportWord_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
changed = true;
|
|||
|
if (tranaportWord.Checked)
|
|||
|
{
|
|||
|
theme!.ButtonColor = new List<int> { 0, 0, 0, 0 };
|
|||
|
mainLabel.BackColor = Color.FromArgb(0, 0, 0, 0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
theme!.ButtonColor = new List<int> { theme.ThemeColor![0], theme.ThemeColor![1], theme.ThemeColor![2] };
|
|||
|
mainLabel.BackColor = Color.FromArgb(theme.ThemeColor![0], theme.ThemeColor![1], theme.ThemeColor![2]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|