Skip to content

Commit

Permalink
Finished AdvancedAppearanceDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deweh committed Jun 25, 2021
1 parent bc302b9 commit e132349
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CP2077SaveEditor/Utils/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
36 changes: 19 additions & 17 deletions CP2077SaveEditor/Views/AdvancedAppearanceDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions CP2077SaveEditor/Views/AdvancedAppearanceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ namespace CP2077SaveEditor
public partial class AdvancedAppearanceDialog : Form
{
private Dictionary<string, HashValueEntry> options = new Dictionary<string, HashValueEntry>();
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)
Expand Down Expand Up @@ -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;
}
}
}
3 changes: 2 additions & 1 deletion CP2077SaveEditor/Views/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit e132349

Please sign in to comment.