Правки

This commit is contained in:
DyCTaTOR 2023-11-22 10:50:20 +04:00
parent 215d2447dd
commit dcb5a06f7f
4 changed files with 98 additions and 101 deletions

View File

@ -18,7 +18,7 @@ namespace Monorail.DrawningObjects
return new DrawningMonorail(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), return new DrawningMonorail(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
Color.FromName(strs[2]), width, height); Color.FromName(strs[2]), width, height);
} }
if (strs.Length == 6) if (strs.Length == 7)
{ {
return new DrawningSecondMonorail(Convert.ToInt32(strs[0]), return new DrawningSecondMonorail(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Convert.ToInt32(strs[1]),

View File

@ -198,6 +198,7 @@ EventArgs e)
MessageBox.Show("Не загрузилось", "Результат", MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
ReloadObjects();
} }
} }
} }

View File

@ -29,6 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
ButtonOk = new Button();
ButtonCancel = new Button();
label_body_color = new Label();
label_additional_color = new Label();
labelModifiedObject = new Label(); labelModifiedObject = new Label();
labelSimpleObject = new Label(); labelSimpleObject = new Label();
GroupColor = new GroupBox(); GroupColor = new GroupBox();
@ -48,11 +52,7 @@
numericUpDownSpeed = new NumericUpDown(); numericUpDownSpeed = new NumericUpDown();
pictureBoxObject = new PictureBox(); pictureBoxObject = new PictureBox();
label4 = new Label(); label4 = new Label();
ButtonOk = new Button();
ButtonCancel = new Button();
PanelObject = new Panel(); PanelObject = new Panel();
label_body_color = new Label();
label_additional_color = new Label();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
GroupColor.SuspendLayout(); GroupColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
@ -84,6 +84,59 @@
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Параметры"; groupBox1.Text = "Параметры";
// //
// ButtonOk
//
ButtonOk.BackColor = SystemColors.Info;
ButtonOk.ForeColor = SystemColors.ControlText;
ButtonOk.Location = new Point(313, 480);
ButtonOk.Name = "ButtonOk";
ButtonOk.Size = new Size(101, 46);
ButtonOk.TabIndex = 12;
ButtonOk.Text = "Добавить";
ButtonOk.UseVisualStyleBackColor = false;
ButtonOk.Click += ButtonOk_Click;
//
// ButtonCancel
//
ButtonCancel.BackColor = SystemColors.Info;
ButtonCancel.ForeColor = SystemColors.ControlText;
ButtonCancel.Location = new Point(6, 480);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(106, 46);
ButtonCancel.TabIndex = 13;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = false;
//
// label_body_color
//
label_body_color.AllowDrop = true;
label_body_color.BackColor = SystemColors.Info;
label_body_color.BorderStyle = BorderStyle.FixedSingle;
label_body_color.ForeColor = SystemColors.ControlText;
label_body_color.Location = new Point(6, 382);
label_body_color.Name = "label_body_color";
label_body_color.Size = new Size(106, 56);
label_body_color.TabIndex = 10;
label_body_color.Text = "Осн. цвет";
label_body_color.TextAlign = ContentAlignment.MiddleCenter;
label_body_color.DragDrop += PanelColor_DragDrop;
label_body_color.DragEnter += PanelColor_DragEnter;
//
// label_additional_color
//
label_additional_color.AllowDrop = true;
label_additional_color.BackColor = SystemColors.Info;
label_additional_color.BorderStyle = BorderStyle.FixedSingle;
label_additional_color.ForeColor = SystemColors.ControlText;
label_additional_color.Location = new Point(250, 382);
label_additional_color.Name = "label_additional_color";
label_additional_color.Size = new Size(101, 56);
label_additional_color.TabIndex = 10;
label_additional_color.Text = "Доп. цвет";
label_additional_color.TextAlign = ContentAlignment.MiddleCenter;
label_additional_color.DragDrop += PanelColor_DragDrop;
label_additional_color.DragEnter += PanelColor_DragEnter;
//
// labelModifiedObject // labelModifiedObject
// //
labelModifiedObject.AllowDrop = true; labelModifiedObject.AllowDrop = true;
@ -159,7 +212,7 @@
// //
// panelBlue // panelBlue
// //
panelBlue.BackColor = Color.FromArgb(0, 0, 192); panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(174, 32); panelBlue.Location = new Point(174, 32);
panelBlue.Name = "panelBlue"; panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(78, 55); panelBlue.Size = new Size(78, 55);
@ -195,7 +248,7 @@
// //
// panelRed // panelRed
// //
panelRed.BackColor = Color.FromArgb(192, 0, 0); panelRed.BackColor = Color.Red;
panelRed.Location = new Point(6, 32); panelRed.Location = new Point(6, 32);
panelRed.Name = "panelRed"; panelRed.Name = "panelRed";
panelRed.Size = new Size(78, 55); panelRed.Size = new Size(78, 55);
@ -282,29 +335,6 @@
label4.Size = new Size(0, 20); label4.Size = new Size(0, 20);
label4.TabIndex = 2; label4.TabIndex = 2;
// //
// ButtonOk
//
ButtonOk.BackColor = SystemColors.Info;
ButtonOk.ForeColor = SystemColors.ControlText;
ButtonOk.Location = new Point(313, 480);
ButtonOk.Name = "ButtonOk";
ButtonOk.Size = new Size(101, 46);
ButtonOk.TabIndex = 12;
ButtonOk.Text = "Добавить";
ButtonOk.UseVisualStyleBackColor = false;
ButtonOk.Click += ButtonOk_Click;
//
// ButtonCancel
//
ButtonCancel.BackColor = SystemColors.Info;
ButtonCancel.ForeColor = SystemColors.ControlText;
ButtonCancel.Location = new Point(6, 480);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(106, 46);
ButtonCancel.TabIndex = 13;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = false;
//
// PanelObject // PanelObject
// //
PanelObject.AllowDrop = true; PanelObject.AllowDrop = true;
@ -316,36 +346,6 @@
PanelObject.DragDrop += PanelObject_DragDrop; PanelObject.DragDrop += PanelObject_DragDrop;
PanelObject.DragEnter += PanelObject_DragEnter; PanelObject.DragEnter += PanelObject_DragEnter;
// //
// label_body_color
//
label_body_color.AllowDrop = true;
label_body_color.BackColor = SystemColors.Info;
label_body_color.BorderStyle = BorderStyle.FixedSingle;
label_body_color.ForeColor = SystemColors.ControlText;
label_body_color.Location = new Point(6, 382);
label_body_color.Name = "label_body_color";
label_body_color.Size = new Size(106, 56);
label_body_color.TabIndex = 10;
label_body_color.Text = "Осн. цвет";
label_body_color.TextAlign = ContentAlignment.MiddleCenter;
label_body_color.DragDrop += PanelColor_DragDrop;
label_body_color.DragEnter += PanelColor_DragEnter;
//
// label_additional_color
//
label_additional_color.AllowDrop = true;
label_additional_color.BackColor = SystemColors.Info;
label_additional_color.BorderStyle = BorderStyle.FixedSingle;
label_additional_color.ForeColor = SystemColors.ControlText;
label_additional_color.Location = new Point(250, 382);
label_additional_color.Name = "label_additional_color";
label_additional_color.Size = new Size(101, 56);
label_additional_color.TabIndex = 10;
label_additional_color.Text = "Доп. цвет";
label_additional_color.TextAlign = ContentAlignment.MiddleCenter;
label_additional_color.DragDrop += PanelColor_DragDrop;
label_additional_color.DragEnter += PanelColor_DragEnter;
//
// FormMonorailConfig // FormMonorailConfig
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);

View File

@ -59,6 +59,7 @@ namespace Monorail.Generics
File.Delete(filename); File.Delete(filename);
} }
StringBuilder data = new(); StringBuilder data = new();
foreach (KeyValuePair<string,MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>> foreach (KeyValuePair<string,MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>>
record in _monorailsStorages) record in _monorailsStorages)
{ {
@ -73,10 +74,8 @@ namespace Monorail.Generics
{ {
return false; return false;
} }
using FileStream fs = new(filename, FileMode.Create); using StreamWriter sw = new(filename);
byte[] info = new sw.Write($"MonorailStorage{Environment.NewLine}{data}");
UTF8Encoding(true).GetBytes($"MonorailStorage{Environment.NewLine}{data}");
fs.Write(info, 0, info.Length);
return true; return true;
} }
public bool LoadData(string filename) public bool LoadData(string filename)
@ -85,55 +84,52 @@ namespace Monorail.Generics
{ {
return false; return false;
} }
string bufferTextFromFile = ""; using (StreamReader sr = File.OpenText(filename))
using (FileStream fs = new(filename, FileMode.Open))
{ {
byte[] b = new byte[fs.Length]; string str = sr.ReadLine();
UTF8Encoding temp = new(true); if (str == null || str.Length == 0)
while (fs.Read(b, 0, b.Length) > 0)
{ {
bufferTextFromFile += temp.GetString(b); return false;
} }
} if (!str.StartsWith("MonorailStorage"))
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("MonorailStorage"))
{
//если нет такой записи, то это не те данные
return false;
}
_monorailsStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{ {
continue; return false;
} }
MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>
collection = new(_pictureWidth, _pictureHeight); _monorailsStorages.Clear();
string[] set = record[1].Split(_separatorRecords, string strs = "";
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set) while ((strs = sr.ReadLine()) != null)
{ {
DrawningMonorail? monorail = if (strs == null)
elem?.CreateDrawningMonorail(_separatorForObject, _pictureWidth, _pictureHeight);
if (monorail != null)
{ {
if ((collection + monorail)==-1) return false;
}
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
continue;
}
MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> collection =
new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningMonorail? monorail = elem?.CreateDrawningMonorail(_separatorForObject,
_pictureWidth, _pictureHeight);
if (monorail != null)
{ {
return false; if ((collection + monorail) == -1)
{
return false;
}
} }
} }
_monorailsStorages.Add(record[0], collection);
} }
_monorailsStorages.Add(record[0], collection); return true;
} }
return true;
} }
} }