2024-10-10 14:40:22 +03:00
|
|
|
|
using GtaVUsersInfo.Controls;
|
2024-10-08 11:44:50 +03:00
|
|
|
|
using GtaVUsersInfo.Forms;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
using GtaVUsersInfo.Helpers;
|
2024-10-09 21:04:29 +03:00
|
|
|
|
using GtaVUsersInfo.Sources;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Data;
|
2024-10-06 12:32:33 +03:00
|
|
|
|
|
|
|
|
|
namespace GtaVUsersInfo
|
|
|
|
|
{
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
{
|
2024-10-08 09:53:24 +03:00
|
|
|
|
private List<Control> debugControlsList;
|
2024-10-08 14:41:32 +03:00
|
|
|
|
|
2024-10-08 09:53:24 +03:00
|
|
|
|
private List<Car> carList;
|
2024-10-08 14:41:32 +03:00
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
private List<ParameterControl> parameters;
|
2024-10-08 15:14:10 +03:00
|
|
|
|
private List<CarControl> cars;
|
2024-10-08 09:53:24 +03:00
|
|
|
|
|
2024-10-09 21:04:29 +03:00
|
|
|
|
private Font defaultFont;
|
|
|
|
|
private Color defaultColor;
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
private Color defaultPanelColor;
|
|
|
|
|
|
2024-10-09 21:04:29 +03:00
|
|
|
|
private List<Control> dtControls;
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
private FontSettings fontSettings;
|
2024-10-10 11:47:27 +03:00
|
|
|
|
private WindowParameters window;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
private PanelColorSettings panelColorSettings;
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
private bool isUser;
|
|
|
|
|
|
2024-10-06 12:32:33 +03:00
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-10-08 09:53:24 +03:00
|
|
|
|
|
2024-10-09 21:04:29 +03:00
|
|
|
|
defaultFont = new Font("Arial", 11, FontStyle.Regular);
|
|
|
|
|
defaultColor = Color.Black;
|
|
|
|
|
|
2024-10-08 09:53:24 +03:00
|
|
|
|
debugControlsList = new List<Control> { parserButton, readJsonButton };
|
|
|
|
|
|
|
|
|
|
this.visible(debugControlsList, false);
|
|
|
|
|
|
2024-10-08 11:44:50 +03:00
|
|
|
|
carList = LoadCarsFromJson(Resources.carJsonPath);
|
2024-10-08 14:41:32 +03:00
|
|
|
|
|
2024-10-08 15:14:10 +03:00
|
|
|
|
cars = new List<CarControl>();
|
2024-10-08 18:33:19 +03:00
|
|
|
|
parameters = new List<ParameterControl> { new ParameterControl("Имя"), new ParameterControl("Деньги") };
|
2024-10-08 14:41:32 +03:00
|
|
|
|
|
2024-10-10 12:30:53 +03:00
|
|
|
|
carsItems.ContextMenuStrip = new CarPanelMenuStrip(addCar_Click).Menu;
|
2024-10-08 15:14:10 +03:00
|
|
|
|
parametersPanel.ContextMenuStrip = new ParameterPanelMenuStrip(addNewParameter).Menu;
|
2024-10-09 21:04:29 +03:00
|
|
|
|
|
|
|
|
|
dtControls = new List<Control> { parserButton, readJsonButton };
|
|
|
|
|
|
|
|
|
|
fontSettings = FontSettings.LoadFontSettings();
|
|
|
|
|
if (fontSettings != null)
|
|
|
|
|
{
|
|
|
|
|
fontSettings.FontSettingsEdit(dtControls);
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fontSettings = new FontSettings(defaultFont, defaultColor, dtControls);
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
|
|
|
|
|
|
|
|
|
FontSettings.SaveFontSettings(fontSettings);
|
|
|
|
|
}
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
isUser = false;
|
|
|
|
|
window = WindowParameters.LoadWindowParameters();
|
|
|
|
|
if (window != null)
|
|
|
|
|
{
|
|
|
|
|
if (window.prevFile != null)
|
|
|
|
|
{
|
|
|
|
|
Cars_Parameters lists = LoadDataFromFile(window.prevFile);
|
|
|
|
|
if (lists != null)
|
|
|
|
|
{
|
|
|
|
|
cars = lists.cars.Select(car => new CarControl(car)).ToList();
|
|
|
|
|
parameters = lists.parameters.Select(parameter => new ParameterControl(parameter)).ToList();
|
|
|
|
|
|
|
|
|
|
AllPanelCreate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WindowResize();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-10-10 13:47:29 +03:00
|
|
|
|
window = new WindowParameters(new Size(this.Width, this.Height), new Size(this.splitterLeft.SplitPosition, this.splitterRigth.SplitPosition), IsFormFullscreen());
|
2024-10-10 11:47:27 +03:00
|
|
|
|
WindowParameters.SaveWindowParameters(window);
|
|
|
|
|
WindowResize();
|
|
|
|
|
}
|
2024-10-10 13:47:29 +03:00
|
|
|
|
|
|
|
|
|
panelColorSettings = PanelColorSettings.LoadPanelSettings();
|
|
|
|
|
if (panelColorSettings != null)
|
|
|
|
|
{
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
panelColorSettings = new PanelColorSettings(defaultPanelColor, defaultPanelColor, defaultPanelColor, defaultPanelColor);
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
}
|
2024-10-10 14:52:29 +03:00
|
|
|
|
isUser = true;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsFormFullscreen()
|
|
|
|
|
{
|
|
|
|
|
if (this.WindowState == FormWindowState.Maximized)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetFullscreen(bool fullscreen)
|
|
|
|
|
{
|
|
|
|
|
if (fullscreen)
|
|
|
|
|
{
|
|
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
|
|
}
|
2024-10-08 11:44:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-10-08 14:41:32 +03:00
|
|
|
|
AllPanelCreate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AllPanelCreate()
|
|
|
|
|
{
|
|
|
|
|
ParameterPanelCreate();
|
|
|
|
|
CarPanelCreate();
|
2024-10-09 21:04:29 +03:00
|
|
|
|
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
2024-10-10 19:00:53 +03:00
|
|
|
|
ChangePanelColor();
|
2024-10-08 14:41:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 11:47:27 +03:00
|
|
|
|
private void WindowResize()
|
|
|
|
|
{
|
|
|
|
|
this.Width = window.width;
|
|
|
|
|
this.Height = window.height;
|
|
|
|
|
this.splitterLeft.SplitPosition = window.leftPos;
|
|
|
|
|
this.splitterRigth.SplitPosition = window.rightPos;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
SetFullscreen(window.isFullScreen);
|
2024-10-10 11:47:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:41:32 +03:00
|
|
|
|
private void ParameterPanelCreate()
|
|
|
|
|
{
|
|
|
|
|
parametersPanel.Controls.Clear();
|
|
|
|
|
|
2024-10-10 19:00:53 +03:00
|
|
|
|
foreach (ParameterControl param in parameters)
|
2024-10-08 11:44:50 +03:00
|
|
|
|
{
|
|
|
|
|
param.Dock = DockStyle.Top;
|
2024-10-10 19:00:53 +03:00
|
|
|
|
param.MenuStrip = new ParameterItemMenuStrip(addNewParameter, deleteParameter, param).Menu;
|
2024-10-08 11:44:50 +03:00
|
|
|
|
parametersPanel.Controls.Add(param);
|
2024-10-08 14:41:32 +03:00
|
|
|
|
parametersPanel.Controls.SetChildIndex(param, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CarPanelCreate()
|
|
|
|
|
{
|
|
|
|
|
carsItems.Controls.Clear();
|
|
|
|
|
|
2024-10-08 15:14:10 +03:00
|
|
|
|
foreach (CarControl car in cars)
|
2024-10-08 14:41:32 +03:00
|
|
|
|
{
|
2024-10-10 13:47:29 +03:00
|
|
|
|
car.MenuStrip = new CarItemMenuStrip(addCar_Click, editCar, deleteCar, car.ChangeColor, car).Menu;
|
2024-10-08 14:41:32 +03:00
|
|
|
|
carsItems.Controls.Add(car);
|
2024-10-08 11:44:50 +03:00
|
|
|
|
}
|
2024-10-08 09:53:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Car> LoadCarsFromJson(string filePath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string json = File.ReadAllText(filePath);
|
|
|
|
|
List<Car> cars = JsonConvert.DeserializeObject<List<Car>>(json);
|
|
|
|
|
|
|
|
|
|
return cars;
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
2024-10-09 21:04:29 +03:00
|
|
|
|
ErrorsShow.ShowErrorMessage($"Файл с автомобилями не найден: {filePath}");
|
2024-10-08 09:53:24 +03:00
|
|
|
|
return new List<Car>();
|
|
|
|
|
}
|
|
|
|
|
catch (JsonException ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Ошибка при десериализации JSON автомобилей: {ex.Message}");
|
|
|
|
|
return new List<Car>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Произошла неожиданная ошибка при открытии файла с автомобилями: {ex.Message}");
|
|
|
|
|
return new List<Car>();
|
|
|
|
|
}
|
2024-10-06 12:32:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 09:53:24 +03:00
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
private void visible(List<Control> controls, bool isVisible)
|
|
|
|
|
{
|
|
|
|
|
controls.ForEach(control => { control.Visible = isVisible; control.Enabled = isVisible; });
|
2024-10-06 14:05:10 +03:00
|
|
|
|
}
|
2024-10-06 12:32:33 +03:00
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
private void readJsonButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
carList = LoadCarsFromJson(Resources.carJsonPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void debugCheck_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.visible(debugControlsList, debugCheck.Checked);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 09:53:24 +03:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-10-06 14:05:10 +03:00
|
|
|
|
async private void parserButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (var parser = new CarParser())
|
|
|
|
|
{
|
|
|
|
|
var cars = await parser.ParseCarsFromPages(25);
|
2024-10-08 11:44:50 +03:00
|
|
|
|
parser.SaveToJson(cars, Resources.carJsonPath);
|
|
|
|
|
ErrorsShow.ShowInfoMessage($"Данные сохранены: {Resources.carJsonPath}");
|
2024-10-08 09:53:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 11:44:50 +03:00
|
|
|
|
carList = LoadCarsFromJson(Resources.carJsonPath);
|
2024-10-08 09:53:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
#region Методы автомобильной панели
|
2024-10-08 09:53:24 +03:00
|
|
|
|
|
|
|
|
|
private void addCar_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (carList.Count <= 0)
|
|
|
|
|
{
|
2024-10-08 11:44:50 +03:00
|
|
|
|
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {Resources.carJsonPath}");
|
2024-10-08 09:53:24 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Car car = new Car();
|
|
|
|
|
|
2024-10-08 11:44:50 +03:00
|
|
|
|
using (AddCars form = new AddCars(carList, car))
|
2024-10-08 09:53:24 +03:00
|
|
|
|
{
|
2024-10-10 12:30:53 +03:00
|
|
|
|
form.ChangeFonts(fontSettings);
|
2024-10-08 11:44:50 +03:00
|
|
|
|
form.ShowDialog();
|
2024-10-08 09:53:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (car.Name != null)
|
|
|
|
|
{
|
2024-10-08 15:14:10 +03:00
|
|
|
|
CarControl item = new CarControl(car);
|
2024-10-08 14:41:32 +03:00
|
|
|
|
cars.Add(item);
|
2024-10-09 21:04:29 +03:00
|
|
|
|
AllPanelCreate();
|
2024-10-08 14:41:32 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void editCar(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (carList.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {Resources.carJsonPath}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
|
|
|
|
|
if (clickedMenuItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CarItemMenuStrip menu = clickedMenuItem.Tag as CarItemMenuStrip;
|
|
|
|
|
if (menu == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-10-08 15:14:10 +03:00
|
|
|
|
CarControl carItem = menu.Car;
|
2024-10-08 14:41:32 +03:00
|
|
|
|
if (carItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Car car = new Car();
|
|
|
|
|
|
|
|
|
|
using (AddCars form = new AddCars(carList, car))
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (car.Name != null)
|
|
|
|
|
{
|
|
|
|
|
carItem.EditCar(car);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void deleteCar(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (carList.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Список автомобилей пуст, ошибка чтения файла: {Resources.carJsonPath}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
|
|
|
|
|
if (clickedMenuItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CarItemMenuStrip menu = clickedMenuItem.Tag as CarItemMenuStrip;
|
|
|
|
|
if (menu == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-10-08 15:14:10 +03:00
|
|
|
|
CarControl carItem = menu.Car;
|
2024-10-08 14:41:32 +03:00
|
|
|
|
if (carItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cars.Contains(carItem))
|
|
|
|
|
{
|
2024-10-10 11:47:27 +03:00
|
|
|
|
DialogResult result = ErrorsShow.ShowQuestMessage(
|
2024-10-08 15:14:10 +03:00
|
|
|
|
$"Вы точно хотите удалить автомобиль: {carItem.Car.Name} - {carItem.Car.Price}?"
|
2024-10-10 11:47:27 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
2024-10-08 15:14:10 +03:00
|
|
|
|
{
|
|
|
|
|
cars.Remove(carItem);
|
2024-10-09 21:04:29 +03:00
|
|
|
|
AllPanelCreate();
|
2024-10-08 15:14:10 +03:00
|
|
|
|
}
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-06 14:05:10 +03:00
|
|
|
|
}
|
2024-10-06 12:32:33 +03:00
|
|
|
|
}
|
2024-10-08 11:44:50 +03:00
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Методы панели параметров
|
|
|
|
|
|
2024-10-08 11:44:50 +03:00
|
|
|
|
private void addParameter_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ParameterControl parameter = new ParameterControl();
|
|
|
|
|
|
|
|
|
|
using (AddParameter form = new AddParameter(parameters, parameter))
|
|
|
|
|
{
|
2024-10-10 12:30:53 +03:00
|
|
|
|
form.ChangeFonts(fontSettings);
|
2024-10-08 11:44:50 +03:00
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(parameter.ParamName))
|
|
|
|
|
{
|
|
|
|
|
parameter.Dock = DockStyle.Top;
|
|
|
|
|
parameters.Add(parameter);
|
2024-10-10 10:32:32 +03:00
|
|
|
|
AllPanelCreate();
|
2024-10-08 11:44:50 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-08 15:14:10 +03:00
|
|
|
|
|
|
|
|
|
private void addNewParameter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
addParameter_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void deleteParameter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (parameters.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Список параметров пуст");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem;
|
|
|
|
|
if (clickedMenuItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ParameterItemMenuStrip menu = clickedMenuItem.Tag as ParameterItemMenuStrip;
|
|
|
|
|
if (menu == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ParameterControl parameterControl = menu.Parameter;
|
|
|
|
|
if (parameterControl == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (parameters.Contains(parameterControl))
|
|
|
|
|
{
|
2024-10-10 11:47:27 +03:00
|
|
|
|
DialogResult result = ErrorsShow.ShowQuestMessage(
|
2024-10-08 15:14:10 +03:00
|
|
|
|
$"Вы точно хотите удалить элемент: {parameterControl.ParamName}?"
|
2024-10-10 11:47:27 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
2024-10-08 15:14:10 +03:00
|
|
|
|
{
|
|
|
|
|
parameters.Remove(parameterControl);
|
2024-10-10 10:32:32 +03:00
|
|
|
|
AllPanelCreate();
|
2024-10-08 15:14:10 +03:00
|
|
|
|
}
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-08 15:14:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-08 18:33:19 +03:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2024-10-09 21:04:29 +03:00
|
|
|
|
#region Раскрывающийся список "Файл"
|
2024-10-08 18:33:19 +03:00
|
|
|
|
|
|
|
|
|
private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cars_Parameters lists = LoadDataFromFile();
|
|
|
|
|
if (lists != null)
|
|
|
|
|
{
|
|
|
|
|
cars = lists.cars.Select(car => new CarControl(car)).ToList();
|
|
|
|
|
parameters = lists.parameters.Select(parameter => new ParameterControl(parameter)).ToList();
|
|
|
|
|
|
2024-10-10 11:47:27 +03:00
|
|
|
|
AllPanelCreate();
|
|
|
|
|
}
|
2024-10-08 18:33:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 21:04:29 +03:00
|
|
|
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SaveDataToFile("JSON files (*.json)|*.json|All files (*.*)|*.*");
|
|
|
|
|
AllPanelCreate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveAsКакToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SaveDataToFile("All files (*.*)|*.*");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveDataToFile(string filter)
|
2024-10-08 18:33:19 +03:00
|
|
|
|
{
|
|
|
|
|
Cars_Parameters data = new Cars_Parameters(Car.ConvertToCarList(cars), Parameter.ConvertToParameterList(parameters));
|
|
|
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
2024-10-09 21:04:29 +03:00
|
|
|
|
saveFileDialog.Filter = filter;
|
2024-10-08 18:33:19 +03:00
|
|
|
|
|
2024-10-10 13:55:13 +03:00
|
|
|
|
if (window.prevFile != null)
|
|
|
|
|
{
|
|
|
|
|
string jsonData = JsonConvert.SerializeObject(data, Formatting.Indented);
|
|
|
|
|
File.WriteAllText(window.prevFile, jsonData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
// Сериализуем данные в JSON
|
|
|
|
|
string jsonData = JsonConvert.SerializeObject(data, Formatting.Indented);
|
|
|
|
|
|
|
|
|
|
// Записываем данные в файл
|
|
|
|
|
File.WriteAllText(saveFileDialog.FileName, jsonData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Cars_Parameters LoadDataFromFile()
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
|
|
openFileDialog.Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
// Читаем данные из файла
|
|
|
|
|
string jsonData = File.ReadAllText(openFileDialog.FileName);
|
|
|
|
|
|
|
|
|
|
// Десериализуем данные в объект ListData
|
|
|
|
|
Cars_Parameters data = JsonConvert.DeserializeObject<Cars_Parameters>(jsonData);
|
2024-10-10 11:47:27 +03:00
|
|
|
|
var split = openFileDialog.FileName.Split('\\');
|
|
|
|
|
this.Text = split[split.Length - 1];
|
|
|
|
|
window.prevFile = openFileDialog.FileName;
|
2024-10-08 18:33:19 +03:00
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
return null; // Если пользователь отменил выбор файла
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 11:47:27 +03:00
|
|
|
|
public Cars_Parameters LoadDataFromFile(string filePath)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
ErrorsShow.ShowErrorMessage($"Ошибка открытия файла: {filePath}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Читаем данные из файла
|
|
|
|
|
string jsonData = File.ReadAllText(filePath);
|
|
|
|
|
|
|
|
|
|
// Десериализуем данные в объект ListData
|
|
|
|
|
Cars_Parameters data = JsonConvert.DeserializeObject<Cars_Parameters>(jsonData);
|
|
|
|
|
var split = filePath.Split('\\');
|
|
|
|
|
this.Text = split[split.Length - 1];
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
private void newToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-10-10 11:47:27 +03:00
|
|
|
|
DialogResult result = ErrorsShow.ShowQuestMessage("Хотите сохранить текущего персонажа?");
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
2024-10-08 18:33:19 +03:00
|
|
|
|
{
|
2024-10-09 21:04:29 +03:00
|
|
|
|
SaveDataToFile("JSON files (*.json)|*.json|All files (*.*)|*.*");
|
2024-10-08 18:33:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 11:47:27 +03:00
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
cars = new List<CarControl>();
|
|
|
|
|
parameters = new List<ParameterControl> { new ParameterControl("Имя"), new ParameterControl("Деньги") };
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
this.Text = "null";
|
|
|
|
|
|
|
|
|
|
window.prevFile = null;
|
|
|
|
|
|
2024-10-08 18:33:19 +03:00
|
|
|
|
AllPanelCreate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
2024-10-10 11:47:27 +03:00
|
|
|
|
DialogResult result = ErrorsShow.ShowQuestMessage("Хотите сохранить текущего персонажа?");
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
2024-10-08 18:33:19 +03:00
|
|
|
|
{
|
2024-10-09 21:04:29 +03:00
|
|
|
|
SaveDataToFile("JSON files (*.json)|*.json|All files (*.*)|*.*");
|
|
|
|
|
}
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-10 13:47:29 +03:00
|
|
|
|
|
|
|
|
|
SaveWindowSize();
|
2024-10-09 21:04:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Раскрывающийся список "Стили"
|
|
|
|
|
|
|
|
|
|
private void colorTextToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (ColorDialog colorDialog = new ColorDialog())
|
|
|
|
|
{
|
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fontSettings.FontSettingsEdit(colorDialog.Color);
|
|
|
|
|
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
|
|
|
|
|
|
|
|
|
FontSettings.SaveFontSettings(fontSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void styleTextToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (FontDialog fontDialog = new FontDialog())
|
|
|
|
|
{
|
|
|
|
|
if (fontDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fontSettings.FontSettingsEdit(fontDialog.Font);
|
|
|
|
|
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
|
|
|
|
|
|
|
|
|
FontSettings.SaveFontSettings(fontSettings);
|
|
|
|
|
}
|
2024-10-08 18:33:19 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-09 21:04:29 +03:00
|
|
|
|
|
|
|
|
|
private void defaultToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
fontSettings.FontSettingsEdit(defaultFont);
|
|
|
|
|
fontSettings.FontSettingsEdit(defaultColor);
|
|
|
|
|
|
|
|
|
|
FontSettings.ChangeFontInControls(this, fontSettings);
|
|
|
|
|
|
|
|
|
|
FontSettings.SaveFontSettings(fontSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-10-10 11:47:27 +03:00
|
|
|
|
|
|
|
|
|
private void SaveWindowSize()
|
|
|
|
|
{
|
|
|
|
|
if (isUser)
|
|
|
|
|
{
|
2024-10-10 13:47:29 +03:00
|
|
|
|
window = new WindowParameters(new Size(this.Width, this.Height), new Size(this.splitterLeft.SplitPosition, this.splitterRigth.SplitPosition), IsFormFullscreen(), window.prevFile);
|
2024-10-10 11:47:27 +03:00
|
|
|
|
WindowParameters.SaveWindowParameters(window);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
private void SaveColorPanel()
|
2024-10-10 11:47:27 +03:00
|
|
|
|
{
|
2024-10-10 13:47:29 +03:00
|
|
|
|
PanelColorSettings.SavePanelSettings(panelColorSettings);
|
2024-10-10 11:47:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
private void ChangePanelColor()
|
2024-10-10 11:47:27 +03:00
|
|
|
|
{
|
2024-10-10 13:47:29 +03:00
|
|
|
|
this.buttonsPanel.BackColor = panelColorSettings.leftPanel;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
|
|
|
|
|
PanelColorSettings.ChangeFontInControls(this.buttonsPanel, panelColorSettings.leftPanel);
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
this.parametersPanel.BackColor = panelColorSettings.rightPanel;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
|
|
|
|
|
PanelColorSettings.ChangeFontInControls(this.parametersPanel, panelColorSettings.rightPanel);
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
this.carsPanel.BackColor = panelColorSettings.centerPanel;
|
|
|
|
|
this.carsItems.BackColor = panelColorSettings.centerPanel;
|
|
|
|
|
this.upPanel.BackColor = panelColorSettings.upDownPanel;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
|
|
|
|
|
PanelColorSettings.ChangeFontInControls(this.upPanel, panelColorSettings.upDownPanel);
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
this.downPanel.BackColor = panelColorSettings.upDownPanel;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
|
|
|
|
|
PanelColorSettings.ChangeFontInControls(this.downPanel, panelColorSettings.upDownPanel);
|
|
|
|
|
|
2024-10-10 13:47:29 +03:00
|
|
|
|
this.menuStrip.BackColor = panelColorSettings.upDownPanel;
|
2024-10-10 14:40:22 +03:00
|
|
|
|
|
|
|
|
|
this.splitterLeft.BackColor = panelColorSettings.upDownPanel;
|
|
|
|
|
this.splitterRigth.BackColor = panelColorSettings.upDownPanel;
|
2024-10-10 13:47:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonPanelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (ColorDialog colorDialog = new ColorDialog())
|
|
|
|
|
{
|
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
panelColorSettings.leftPanel = colorDialog.Color;
|
|
|
|
|
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
|
|
|
|
|
SaveColorPanel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void parameterPanelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (ColorDialog colorDialog = new ColorDialog())
|
|
|
|
|
{
|
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
panelColorSettings.rightPanel = colorDialog.Color;
|
|
|
|
|
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
|
|
|
|
|
SaveColorPanel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void carPanelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (ColorDialog colorDialog = new ColorDialog())
|
|
|
|
|
{
|
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
panelColorSettings.centerPanel = colorDialog.Color;
|
|
|
|
|
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
|
|
|
|
|
SaveColorPanel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void top_downPanelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (ColorDialog colorDialog = new ColorDialog())
|
|
|
|
|
{
|
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
panelColorSettings.upDownPanel = colorDialog.Color;
|
|
|
|
|
|
|
|
|
|
ChangePanelColor();
|
|
|
|
|
|
|
|
|
|
SaveColorPanel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-10 11:47:27 +03:00
|
|
|
|
}
|
2024-10-06 12:32:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|