Skip to content

Commit

Permalink
null exception fix for parent selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaei committed Dec 4, 2019
1 parent 7634968 commit a16ab46
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
36 changes: 18 additions & 18 deletions ARKBreedingStats/CreatureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public partial class CreatureBox : UserControl

public CreatureBox()
{
initializeVars();
InitializeVars();
}

public CreatureBox(Creature creature)
{
initializeVars();
setCreature(creature);
InitializeVars();
SetCreature(creature);
}

private void initializeVars()
private void InitializeVars()
{
InitializeComponent();
creature = null;
Expand All @@ -52,14 +52,14 @@ private void initializeVars()
tt.SetToolTip(buttonStatus, "Status: Available, Unavailable, Dead");
}

public void setCreature(Creature creature)
public void SetCreature(Creature creature)
{
Clear();
this.creature = creature;
regionColorChooser1.SetSpecies(creature.Species, creature.colors);
colorRegionUseds = regionColorChooser1.ColorRegionsUseds;

updateLabel();
UpdateLabel();
renewLargeImage = true;
}

Expand All @@ -75,14 +75,14 @@ private void buttonEdit_Click(object sender, EventArgs e)
{
if (panel1.Visible)
{
closeSettings(false);
CloseSettings(false);
}
else
{
checkBoxIsBred.Checked = creature.isBred;
panelParents.Visible = creature.isBred;
if (creature.isBred)
populateParentsList();
PopulateParentsList();
textBoxName.Text = creature.name;
textBoxOwner.Text = creature.owner;
textBoxNote.Text = creature.note;
Expand All @@ -98,22 +98,22 @@ private void buttonEdit_Click(object sender, EventArgs e)
ResumeLayout();
}

private void populateParentsList()
private void PopulateParentsList()
{
if (parentList[0] == null || parentList[1] == null)
{
GiveParents(this, creature);

parentComboBoxMother.PreselectedCreatureGuid = creature.motherGuid;
parentComboBoxFather.PreselectedCreatureGuid = creature.fatherGuid;
parentComboBoxMother.parentsSimilarity = parentListSimilarity[0];
parentComboBoxMother.ParentList = parentList[0];
parentComboBoxMother.PreselectedCreatureGuid = creature.motherGuid;
parentComboBoxFather.parentsSimilarity = parentListSimilarity[1];
parentComboBoxFather.ParentList = parentList[1];
parentComboBoxFather.PreselectedCreatureGuid = creature.fatherGuid;
}
}

public void updateLabel()
public void UpdateLabel()
{
labelParents.Text = "";
if (creature != null)
Expand Down Expand Up @@ -145,7 +145,7 @@ public void updateLabel()
}
}

private void closeSettings(bool save)
private void CloseSettings(bool save)
{
panel1.Visible = false;
if (save)
Expand Down Expand Up @@ -183,7 +183,7 @@ private void closeSettings(bool save)
creature.status = creatureStatus;

Changed(creature, creatureStatusChanged);
updateLabel();
UpdateLabel();
ResumeLayout();
}
}
Expand All @@ -194,7 +194,7 @@ public void Clear()
parentComboBoxMother.Items.Clear();
parentComboBoxFather.Items.Clear();
parentList = new List<Creature>[2];
closeSettings(false);
CloseSettings(false);
groupBox1.Text = "";
creature = null;
labelParents.Text = "";
Expand All @@ -205,12 +205,12 @@ public void Clear()

private void button1_Click(object sender, EventArgs e)
{
closeSettings(true);
CloseSettings(true);
}

private void buttonCancel_Click(object sender, EventArgs e)
{
closeSettings(false);
CloseSettings(false);
}

private void buttonSex_Click(object sender, EventArgs e)
Expand All @@ -229,7 +229,7 @@ private void checkBoxIsBred_CheckedChanged(object sender, EventArgs e)
{
panelParents.Visible = checkBoxIsBred.Checked;
if (checkBoxIsBred.Checked)
populateParentsList();
PopulateParentsList();
}

private void RegionColorChooser1_RegionColorChosen()
Expand Down
6 changes: 3 additions & 3 deletions ARKBreedingStats/Form1.extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ private void ExtractExportedFileInExtractor(string exportFile)
SetStatsActiveAccordingToUsage(cv.Species);

ExtractLevels(autoExtraction: true, statInputsHighPrecision: true);
SetCreatureValuesToInfoInput(cv, creatureInfoInputExtractor);
UpdateParentListInput(creatureInfoInputExtractor); // this function is only used for single-creature extractions, e.g. LastExport
SetCreatureValuesToInfoInput(cv, creatureInfoInputExtractor);

tabControlMain.SelectedTab = tabPageExtractor;
SetMessageLabelText("Creature of the exported file\n" + exportFile);
Expand All @@ -778,8 +778,8 @@ private void ExtractExportedFileInExtractor(importExported.ExportedCreatureContr
exportedCreatureControl = ecc;

// not for batch-extractions, only for single creatures
if (updateParentVisuals)
UpdateParentListInput(creatureInfoInputExtractor);
//if (updateParentVisuals) // TODO parents need to be updated always to be able to select the correct parent. Change GetParent from parentCombobox so that it only returns a guid?
UpdateParentListInput(creatureInfoInputExtractor);

SetCreatureValuesToInfoInput(exportedCreatureControl.creatureValues, creatureInfoInputExtractor);
if (exportedCreatureList != null && exportedCreatureList.ownerSuffix != null)
Expand Down
4 changes: 2 additions & 2 deletions ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ private void LibrarySelectedIndexChanged()
if (cnt == 1)
{
Creature c = (Creature)listViewLibrary.SelectedItems[0].Tag;
creatureBoxListView.setCreature(c);
creatureBoxListView.SetCreature(c);
if (tabControlLibFilter.SelectedTab == tabPageLibRadarChart)
radarChartLibrary.setLevels(c.levelsWild);
pedigreeNeedsUpdate = true;
Expand Down Expand Up @@ -1035,7 +1035,7 @@ private void FilterLib()
ShowCreaturesInListView(filteredList.OrderBy(c => c.name).ToList());

// update creaturebox
creatureBoxListView.updateLabel();
creatureBoxListView.UpdateLabel();

// select previous selecteded creatures again
int selectedCount = selectedCreatures.Count;
Expand Down
4 changes: 2 additions & 2 deletions ARKBreedingStats/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ static class Program
static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += unhandledExceptionHandler;
currentDomain.UnhandledException += UnhandledExceptionHandler;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

private static void unhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
if (e is ConfigurationErrorsException ex)
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("0.34.7.1")]
[assembly: AssemblyFileVersion("0.34.7.2")]
[assembly: NeutralResourcesLanguage("en")]

7 changes: 6 additions & 1 deletion ARKBreedingStats/uiControls/ParentComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public Guid PreselectedCreatureGuid
set
{
_preselectedCreatureGuid = value;
if (_preselectedCreatureGuid == Guid.Empty) return;
if (_preselectedCreatureGuid == Guid.Empty || parentList == null)
{
SelectedIndex = 0;
return;
}

int selIndex = 0;
for (int c = 0; c < parentList.Count; c++)
{
Expand Down

0 comments on commit a16ab46

Please sign in to comment.