From e1323491681757ccf1749364ba6f1dc56c3a13aa Mon Sep 17 00:00:00 2001 From: Deweh <76853940+Deweh@users.noreply.github.com> Date: Fri, 25 Jun 2021 15:21:17 -0400 Subject: [PATCH] Finished AdvancedAppearanceDialog. --- CP2077SaveEditor/Utils/TypeExtensions.cs | 5 +++ .../AdvancedAppearanceDialog.Designer.cs | 36 ++++++++------- .../Views/AdvancedAppearanceDialog.cs | 45 ++++++++++++++++++- CP2077SaveEditor/Views/Form1.cs | 3 +- 4 files changed, 69 insertions(+), 20 deletions(-) diff --git a/CP2077SaveEditor/Utils/TypeExtensions.cs b/CP2077SaveEditor/Utils/TypeExtensions.cs index 7d44444..5e58704 100644 --- a/CP2077SaveEditor/Utils/TypeExtensions.cs +++ b/CP2077SaveEditor/Utils/TypeExtensions.cs @@ -216,5 +216,10 @@ public static void SetPath(this CharacterCustomizationAppearances.HashValueEntry { entry.Hash = HashGenerator.CalcFNV1A64(value); } + + public static bool IsPathValid(this CharacterCustomizationAppearances.HashValueEntry entry, string value) + { + return pathHashes.Values.Contains(value); + } } } diff --git a/CP2077SaveEditor/Views/AdvancedAppearanceDialog.Designer.cs b/CP2077SaveEditor/Views/AdvancedAppearanceDialog.Designer.cs index d834f36..f8851e8 100644 --- a/CP2077SaveEditor/Views/AdvancedAppearanceDialog.Designer.cs +++ b/CP2077SaveEditor/Views/AdvancedAppearanceDialog.Designer.cs @@ -36,7 +36,7 @@ private void InitializeComponent() this.firstBox = new System.Windows.Forms.TextBox(); this.secondBox = new System.Windows.Forms.TextBox(); this.pathBox = new System.Windows.Forms.TextBox(); - this.modernButton1 = new CP2077SaveEditor.ModernButton(); + this.applyButton = new CP2077SaveEditor.ModernButton(); this.SuspendLayout(); // // optionsBox @@ -97,20 +97,22 @@ private void InitializeComponent() this.pathBox.Size = new System.Drawing.Size(431, 50); this.pathBox.TabIndex = 6; // - // modernButton1 - // - this.modernButton1.BackColor = System.Drawing.Color.White; - this.modernButton1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.modernButton1.ClickEffectEnabled = true; - this.modernButton1.DefaultColor = System.Drawing.Color.White; - this.modernButton1.HoverColor = System.Drawing.Color.LightGray; - this.modernButton1.Location = new System.Drawing.Point(925, 247); - this.modernButton1.Name = "modernButton1"; - this.modernButton1.Size = new System.Drawing.Size(120, 29); - this.modernButton1.TabIndex = 7; - this.modernButton1.Text = "Apply"; - this.modernButton1.TextColor = System.Drawing.SystemColors.ControlText; - this.modernButton1.TextFont = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + // applyButton + // + this.applyButton.BackColor = System.Drawing.Color.White; + this.applyButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.applyButton.ClickEffectEnabled = true; + this.applyButton.DefaultColor = System.Drawing.Color.White; + this.applyButton.Enabled = false; + this.applyButton.HoverColor = System.Drawing.Color.LightGray; + this.applyButton.Location = new System.Drawing.Point(925, 247); + this.applyButton.Name = "applyButton"; + this.applyButton.Size = new System.Drawing.Size(120, 29); + this.applyButton.TabIndex = 7; + this.applyButton.Text = "Apply"; + this.applyButton.TextColor = System.Drawing.SystemColors.ControlText; + this.applyButton.TextFont = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.applyButton.Click += new System.EventHandler(this.applyButton_Click); // // AdvancedAppearanceDialog // @@ -118,7 +120,7 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(1061, 291); - this.Controls.Add(this.modernButton1); + this.Controls.Add(this.applyButton); this.Controls.Add(this.pathBox); this.Controls.Add(this.secondBox); this.Controls.Add(this.firstBox); @@ -146,6 +148,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox firstBox; private System.Windows.Forms.TextBox secondBox; private System.Windows.Forms.TextBox pathBox; - private ModernButton modernButton1; + private ModernButton applyButton; } } \ No newline at end of file diff --git a/CP2077SaveEditor/Views/AdvancedAppearanceDialog.cs b/CP2077SaveEditor/Views/AdvancedAppearanceDialog.cs index 43b0461..c656abe 100644 --- a/CP2077SaveEditor/Views/AdvancedAppearanceDialog.cs +++ b/CP2077SaveEditor/Views/AdvancedAppearanceDialog.cs @@ -15,16 +15,20 @@ namespace CP2077SaveEditor public partial class AdvancedAppearanceDialog : Form { private Dictionary options = new Dictionary(); - private Form1 parent; + public delegate void ApplyEvent(); + public ApplyEvent ChangesApplied; public AdvancedAppearanceDialog() { InitializeComponent(); + + firstBox.TextChanged += inputBox_TextChanged; + secondBox.TextChanged += inputBox_TextChanged; + pathBox.TextChanged += inputBox_TextChanged; } private void AdvancedAppearanceDialog_Load(object sender, EventArgs e) { - parent = this.Owner as Form1; var container = Form1.activeSaveFile.GetAppearanceContainer(); foreach (var section in container.FirstSection.AppearanceSections) @@ -64,6 +68,43 @@ private void optionsBox_SelectedIndexChanged(object sender, EventArgs e) secondBox.Text = entry.SecondString; pathBox.Text = entry.GetPath(); } + else + { + firstBox.Text = string.Empty; + secondBox.Text = string.Empty; + pathBox.Text = string.Empty; + } + + applyButton.Enabled = false; + } + + private void inputBox_TextChanged(object sender, EventArgs e) + { + applyButton.Enabled = true; + } + + private void applyButton_Click(object sender, EventArgs e) + { + if (optionsBox.SelectedItem is null) + { + MessageBox.Show("Error: No appearance entry selected."); + return; + } + + HashValueEntry entry = options[(string)optionsBox.SelectedItem]; + + if (!entry.IsPathValid(pathBox.Text)) + { + MessageBox.Show("Invalid path. Must be a valid path to a base game '.app' file."); + return; + } + + entry.FirstString = firstBox.Text; + entry.SecondString = secondBox.Text; + entry.SetPath(pathBox.Text); + + ChangesApplied(); + applyButton.Enabled = false; } } } diff --git a/CP2077SaveEditor/Views/Form1.cs b/CP2077SaveEditor/Views/Form1.cs index 35dfc0b..13ac691 100644 --- a/CP2077SaveEditor/Views/Form1.cs +++ b/CP2077SaveEditor/Views/Form1.cs @@ -242,7 +242,7 @@ private void SwapTab(ModernButton tabButton, Panel tabPanel) activeTabPanel = tabPanel; } - private void RefreshAppearanceValues() + public void RefreshAppearanceValues() { foreach (ModernValuePicker picker in appearanceOptionsPanel.Controls) { @@ -1355,6 +1355,7 @@ private void PlayerStatChanged(object sender, EventArgs e) private void advancedAppearanceButton_Click(object sender, EventArgs e) { var advancedDialog = new AdvancedAppearanceDialog(); + advancedDialog.ChangesApplied += RefreshAppearanceValues; advancedDialog.ShowDialog(); } }