using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MetroFramework.Forms; namespace uolter { public partial class DevConsoleForm : MetroForm { private Form1 mainForm; private Dictionary gameVariables; private Dictionary gameStages; // Словарь с названиями стадий игры и их номерами public DevConsoleForm(Form1 mainForm) { InitializeComponent(); this.mainForm = mainForm; this.FormClosing += DevConsoleForm_FormClosing; // Инициализируем словарь игровых стадий InitializeGameStages(); // Сразу обновляем значения при создании формы UpdateValues(); } private void InitializeGameStages() { gameStages = new Dictionary() { // Начальные стадии { "0: Начало", 0 }, { "1: Решение варить самому", 1 }, { "2: Найти Джесси", 2 }, { "3: Купить RV", 3 }, { "5: Купить легальные ингредиенты", 5 }, { "7: Варка в пустыне", 7 }, { "9: Продажа через Джесси", 9 }, // Средние стадии { "12: Сделка с Туко", 12 }, { "16: Сотрудничество с Туко", 16 }, { "20: Найти адвоката (Сол Гудман)", 20 }, { "27: Встреча с Гасом", 27 }, { "34: Работа в суперлабе", 34 }, { "37: Работа с Гейлом", 37 }, { "40: Работа с Джесси в суперлабе", 40 }, // Продвинутые стадии { "47: Гейл убит", 47 }, { "50: Война с Гасом", 50 }, { "62: Гас мертв!", 62 }, { "64: Планирование после Гаса", 64 }, { "68: Создание нового бизнеса", 68 }, { "69: Варка в Vamonos Pest", 69 }, // Финальные стадии { "91: Хэнк находит книгу", 91 }, { "96: Перестрелка в пустыне", 96 }, { "100: Возвращение в Альбукерке", 100 }, { "105: Финальная бойня", 105 }, // Концовки { "200: Игра окончена - Пойман", 200 }, { "202: Конец - Осторожный Уолт", 202 }, { "203: Конец - Начало Империи", 203 }, { "204: Конец - Страх/В бегах", 204 }, { "106: Конец - Исчезновение", 106 } }; // Заполняем комбобокс стадиями comboBoxStages.Items.Clear(); foreach (var stage in gameStages) { comboBoxStages.Items.Add(stage.Key); } } private void DevConsoleForm_FormClosing(object sender, FormClosingEventArgs e) { // Скрываем вместо закрытия if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; this.Hide(); } } public void UpdateValues() { if (mainForm != null) // Добавляем проверку на null { gameVariables = mainForm.GetAllGameVariables(); UpdateVariablesList(); // Обновляем текущую стадию в комбобоксе if (gameVariables.TryGetValue("currentStage", out object stageObj) && stageObj is int currentStage) { string currentStageName = gameStages.FirstOrDefault(x => x.Value == currentStage).Key; if (currentStageName != null) { comboBoxStages.SelectedItem = currentStageName; } } } } private void UpdateVariablesList() { // Очищаем и обновляем список переменных listBoxVariables.Items.Clear(); if (gameVariables != null) // Добавляем проверку на null { foreach (var variable in gameVariables.OrderBy(v => v.Key)) { listBoxVariables.Items.Add($"{variable.Key} = {variable.Value}"); } } } private void InitializeComponent() { this.listBoxVariables = new System.Windows.Forms.ListBox(); this.buttonSetMoney = new MetroFramework.Controls.MetroButton(); this.buttonSetSuspicion = new MetroFramework.Controls.MetroButton(); this.textBoxValue = new MetroFramework.Controls.MetroTextBox(); this.labelValue = new MetroFramework.Controls.MetroLabel(); this.buttonSetVariable = new MetroFramework.Controls.MetroButton(); this.comboBoxStages = new System.Windows.Forms.ComboBox(); this.buttonJumpToStage = new MetroFramework.Controls.MetroButton(); this.labelJumpToStage = new MetroFramework.Controls.MetroLabel(); this.SuspendLayout(); // // listBoxVariables // this.listBoxVariables.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listBoxVariables.FormattingEnabled = true; this.listBoxVariables.Location = new System.Drawing.Point(23, 63); this.listBoxVariables.Name = "listBoxVariables"; this.listBoxVariables.Size = new System.Drawing.Size(354, 212); this.listBoxVariables.TabIndex = 0; this.listBoxVariables.SelectedIndexChanged += new System.EventHandler(this.listBoxVariables_SelectedIndexChanged); // // buttonSetMoney // this.buttonSetMoney.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonSetMoney.Location = new System.Drawing.Point(23, 316); this.buttonSetMoney.Name = "buttonSetMoney"; this.buttonSetMoney.Size = new System.Drawing.Size(100, 23); this.buttonSetMoney.TabIndex = 1; this.buttonSetMoney.Text = "Установить деньги"; this.buttonSetMoney.Click += new System.EventHandler(this.buttonSetMoney_Click); // // buttonSetSuspicion // this.buttonSetSuspicion.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonSetSuspicion.Location = new System.Drawing.Point(139, 316); this.buttonSetSuspicion.Name = "buttonSetSuspicion"; this.buttonSetSuspicion.Size = new System.Drawing.Size(148, 23); this.buttonSetSuspicion.TabIndex = 2; this.buttonSetSuspicion.Text = "Установить подозрение"; this.buttonSetSuspicion.Click += new System.EventHandler(this.buttonSetSuspicion_Click); // // textBoxValue // this.textBoxValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBoxValue.Location = new System.Drawing.Point(139, 287); this.textBoxValue.Name = "textBoxValue"; this.textBoxValue.Size = new System.Drawing.Size(238, 23); this.textBoxValue.TabIndex = 3; // // labelValue // this.labelValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelValue.AutoSize = true; this.labelValue.Location = new System.Drawing.Point(23, 287); this.labelValue.Name = "labelValue"; this.labelValue.Size = new System.Drawing.Size(73, 19); this.labelValue.TabIndex = 4; this.labelValue.Text = "Значение:"; // // buttonSetVariable // this.buttonSetVariable.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonSetVariable.Location = new System.Drawing.Point(293, 316); this.buttonSetVariable.Name = "buttonSetVariable"; this.buttonSetVariable.Size = new System.Drawing.Size(84, 23); this.buttonSetVariable.TabIndex = 5; this.buttonSetVariable.Text = "Установить"; this.buttonSetVariable.Click += new System.EventHandler(this.buttonSetVariable_Click); // // comboBoxStages // this.comboBoxStages.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.comboBoxStages.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxStages.FormattingEnabled = true; this.comboBoxStages.Location = new System.Drawing.Point(139, 33); this.comboBoxStages.Name = "comboBoxStages"; this.comboBoxStages.Size = new System.Drawing.Size(238, 21); this.comboBoxStages.TabIndex = 6; // // buttonJumpToStage // this.buttonJumpToStage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonJumpToStage.Location = new System.Drawing.Point(293, 63); this.buttonJumpToStage.Name = "buttonJumpToStage"; this.buttonJumpToStage.Size = new System.Drawing.Size(84, 23); this.buttonJumpToStage.TabIndex = 7; this.buttonJumpToStage.Text = "Перейти"; this.buttonJumpToStage.Click += new System.EventHandler(this.buttonJumpToStage_Click); // // labelJumpToStage // this.labelJumpToStage.AutoSize = true; this.labelJumpToStage.Location = new System.Drawing.Point(23, 33); this.labelJumpToStage.Name = "labelJumpToStage"; this.labelJumpToStage.Size = new System.Drawing.Size(92, 19); this.labelJumpToStage.TabIndex = 8; this.labelJumpToStage.Text = "Перейти к этапу:"; // // DevConsoleForm // this.ClientSize = new System.Drawing.Size(400, 380); this.Controls.Add(this.labelJumpToStage); this.Controls.Add(this.buttonJumpToStage); this.Controls.Add(this.comboBoxStages); this.Controls.Add(this.buttonSetVariable); this.Controls.Add(this.labelValue); this.Controls.Add(this.textBoxValue); this.Controls.Add(this.buttonSetSuspicion); this.Controls.Add(this.buttonSetMoney); this.Controls.Add(this.listBoxVariables); this.DisplayHeader = false; this.MinimumSize = new System.Drawing.Size(400, 380); this.Name = "DevConsoleForm"; this.Padding = new System.Windows.Forms.Padding(20, 30, 20, 20); this.Text = "Консоль разработчика"; this.ResumeLayout(false); this.PerformLayout(); } private System.Windows.Forms.ListBox listBoxVariables; private MetroFramework.Controls.MetroButton buttonSetMoney; private MetroFramework.Controls.MetroButton buttonSetSuspicion; private MetroFramework.Controls.MetroTextBox textBoxValue; private MetroFramework.Controls.MetroLabel labelValue; private MetroFramework.Controls.MetroButton buttonSetVariable; private System.Windows.Forms.ComboBox comboBoxStages; private MetroFramework.Controls.MetroButton buttonJumpToStage; private MetroFramework.Controls.MetroLabel labelJumpToStage; private void listBoxVariables_SelectedIndexChanged(object sender, EventArgs e) { if (listBoxVariables.SelectedIndex != -1) { string selectedItem = listBoxVariables.SelectedItem.ToString(); int equalsPos = selectedItem.IndexOf('='); if (equalsPos > 0) { string variableName = selectedItem.Substring(0, equalsPos).Trim(); string value = selectedItem.Substring(equalsPos + 1).Trim(); textBoxValue.Text = value; } } } private void buttonSetMoney_Click(object sender, EventArgs e) { if (int.TryParse(textBoxValue.Text, out int moneyValue)) { mainForm.SetMoney(moneyValue); UpdateValues(); } else { MessageBox.Show("Введите корректное числовое значение!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonSetSuspicion_Click(object sender, EventArgs e) { if (int.TryParse(textBoxValue.Text, out int suspicionValue)) { mainForm.SetSuspicion(suspicionValue); UpdateValues(); } else { MessageBox.Show("Введите корректное числовое значение!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonSetVariable_Click(object sender, EventArgs e) { if (listBoxVariables.SelectedIndex != -1) { string selectedItem = listBoxVariables.SelectedItem.ToString(); int equalsPos = selectedItem.IndexOf('='); if (equalsPos > 0) { string variableName = selectedItem.Substring(0, equalsPos).Trim(); string valueText = textBoxValue.Text.Trim(); // Определяем тип переменной и пытаемся конвертировать значение object originalValue; if (gameVariables.TryGetValue(variableName, out originalValue)) { object newValue = null; try { if (originalValue is bool) { newValue = bool.Parse(valueText); } else if (originalValue is int) { newValue = int.Parse(valueText); } else if (originalValue is string) { newValue = valueText; } if (newValue != null) { if (mainForm.SetGameVariable(variableName, newValue)) { UpdateValues(); } else { MessageBox.Show($"Не удалось установить переменную {variableName}!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show($"Ошибка при установке значения: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } private void buttonJumpToStage_Click(object sender, EventArgs e) { // Получаем выбранный этап if (comboBoxStages.SelectedItem != null) { string selectedStageName = comboBoxStages.SelectedItem.ToString(); if (gameStages.TryGetValue(selectedStageName, out int stageNumber)) { // Переходим к выбранному этапу if (mainForm.SetGameVariable("currentStage", stageNumber)) { // Вызываем GoToStage в основной форме mainForm.GoToStage(stageNumber); UpdateValues(); // Можно показать сообщение об успешном переходе MessageBox.Show($"Выполнен переход к этапу: {selectedStageName}", "Переход выполнен", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Не удалось перейти к выбранному этапу!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } }