/// <summary> /// Saves the new selected NPC into the event. /// </summary> /// <param name="sender">Control calling the method.</param> /// <param name="e">Arguments from the action whose caused the call of this method.</param> private void Cbo_npcs_SelectedIndexChanged(object sender, EventArgs e) { if (editor.Get_Is_Loading() || this.loading) { return; } editor.Set_Is_Loading(true); ComboBoxFix cbo = (ComboBoxFix)sender; JObject file_data = Tools.Get_From_JSON(this.file_path); int file_id = cbo.SelectedIndex + 1; switch (this.type) { case "dialogs": file_data[event_id.ToString()]["npc"]["id"] = file_id; break; case "items": file_data[event_id.ToString()]["item"]["name"] = cbo.SelectedItem.ToString().Split('>')[1].Substring(1); file_data[event_id.ToString()]["item"]["id"] = file_id; break; default: throw new ArgumentException("Invalid argument in EventEdition!"); } Tools.Set_To_JSON(this.file_path, file_data); editor.Set_Is_Loading(false); }
/// <summary> /// Save the input data to the linked file. /// </summary> /// <param name="sender">Control calling the method.</param> /// <param name="e">Arguments from the action whose caused the call of this method.</param> private void Cbo_Redirect_SelectedIndexChanged(object sender, EventArgs e) { if (this.loading) { return; } ComboBoxFix cbo = (ComboBoxFix)sender; ((JObject)this.data["c" + cbo.Tag])["redirect"] = cbo.SelectedIndex - 1; Tools.Set_To_JSON(this.file_path, this.data); }
/// <summary> /// Saves the new selected dialog into the event. /// </summary> /// <param name="sender">Control calling the method.</param> /// <param name="e">Arguments from the action whose caused the call of this method.</param> private void Cbo_dialogs_SelectedIndexChanged(object sender, EventArgs e) { if (editor.Get_Is_Loading() || this.loading) { return; } editor.Set_Is_Loading(true); ComboBoxFix cbo = (ComboBoxFix)sender; JObject file_data = Tools.Get_From_JSON(this.file_path); file_data[event_id.ToString()]["quizz"] = cbo.SelectedIndex + 1; Tools.Set_To_JSON(this.file_path, file_data); editor.Set_Is_Loading(false); }
/// <summary> /// Creates and adds all necessary Controls to the QuizzEdition for displaying a choice of the specified id. /// </summary> /// <param name="id">Id of the choice which need Controls management.</param> public void Add_Choice(int id) { // Generates choice's management controls. // Panel containing all following controls. Panel pan_choice = new Panel() { Name = "pan_choice" + id, BackColor = Color.FromArgb(int.Parse((string)this.theme["1"]["R"]), int.Parse((string)this.theme["1"]["G"]), int.Parse((string)this.theme["1"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Width = this.Width - 20, Height = 50 }; this.Controls.Add(pan_choice); // Textbox for the answer. TextBox txt_answer = new TextBox() { Name = "txt_answer" + id, Text = (string)((JObject)data["c" + id])["answer"], Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), ShortcutsEnabled = false, Tag = id, BorderStyle = BorderStyle.FixedSingle }; txt_answer.KeyPress += new KeyPressEventHandler(this.Txt_Answer_KeyPress); pan_choice.Controls.Add(txt_answer); toolTip.SetToolTip(txt_answer, "Réponse proposée."); // NumericUpDown accepting only numbers for the score. NumericUpDownFix nud_score = new NumericUpDownFix() { Name = "nud_score" + id, Maximum = 1000000M, Minimum = -1000000M, Increment = 1, Text = int.Parse(((JObject)data["c" + id])["score"].ToString()).ToString(), Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Tag = id, BorderStyle = BorderStyle.FixedSingle }; nud_score.KeyPress += new KeyPressEventHandler(this.Nud_Score_KeyPress); nud_score.ValueChanged += new EventHandler(this.Nud_Score_ValueChanged); pan_choice.Controls.Add(nud_score); toolTip.SetToolTip(nud_score, "Score donné ou retiré au choix de cette réponse, négatif " + "\npour une réponse fausse et positif pour réponse juste."); // ComboBox for the redirection (or not) to another existing dialog. ComboBoxFix cbo_redirect = new ComboBoxFix() { Name = "cbo_redirect" + id, DataSource = new List <string>(cbo_redirect_list), Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), DropDownStyle = ComboBoxStyle.DropDownList, BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Tag = id }; cbo_redirect.SelectedIndexChanged += new EventHandler(this.Cbo_Redirect_SelectedIndexChanged); pan_choice.Controls.Add(cbo_redirect); toolTip.SetToolTip(cbo_redirect, "Dialogue vers lequel le joueur sera redirigé lors de ce choix." + "\nLa redirection vers [_FIN_] indique la fin de la situation et" + "\n[_CONTINUER_] l'absence de redirection."); try { cbo_redirect.SelectedIndex = int.Parse(((JObject)data["c" + id])["redirect"].ToString()) + 1; } catch (System.FormatException e) { cbo_redirect.SelectedIndex = 0; } // PictureBox allowing to delete this choice. PictureBox pb_discard_choice = new PictureBox() { Name = "pb_discard_choice" + id, Cursor = Cursors.Hand, Size = new Size(30, 30), Image = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "internal" + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + "delete.png"), SizeMode = PictureBoxSizeMode.StretchImage, Tag = id }; pb_discard_choice.Click += new EventHandler(this.Discard_Choice); pan_choice.Controls.Add(pb_discard_choice); toolTip.SetToolTip(pb_discard_choice, "Supprimer cette réponse"); // Sizing of all created controls. int size_taken = 10 * 2 + 8 * 3 + nud_score.Width + pb_discard_choice.Width; int size_left = pan_choice.Width - size_taken; txt_answer.Width = size_left / 2; cbo_redirect.Width = size_left / 2; // Placement of all created controls. pan_choice.Location = new Point(10, this.prev_line_loc); txt_answer.Location = new Point(10, 10); nud_score.Location = new Point(txt_answer.Location.X + txt_answer.Width + 8, 10); cbo_redirect.Location = new Point(nud_score.Location.X + nud_score.Width + 8, 10); pb_discard_choice.Location = new Point(cbo_redirect.Location.X + cbo_redirect.Width + 8, 10); this.prev_line_loc += pan_choice.Height + 10; this.Height = this.prev_line_loc; }