Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Jul 31, 2022
2 parents 054c09c + d2800cf commit 92825ba
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 60 deletions.
12 changes: 12 additions & 0 deletions ARKBreedingStats/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@
<setting name="UseTribeFilterForBreedingPlan" serializeAs="String">
<value>False</value>
</setting>
<setting name="FilterHideAdults" serializeAs="String">
<value>False</value>
</setting>
<setting name="FilterHideNonAdults" serializeAs="String">
<value>False</value>
</setting>
<setting name="FilterHideCooldowns" serializeAs="String">
<value>False</value>
</setting>
<setting name="FilterHideNonCooldowns" serializeAs="String">
<value>False</value>
</setting>
</ARKBreedingStats.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion ARKBreedingStats/BreedingPlanning/BreedingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ private void DetermineBestLevels(List<Creature> creatures = null)
/// <param name="bestInSpecies">If true, the display of the best species library will be updated, if false the best filtered species will be updated.</param>
private void SetBestLevels(int[] bestLevels, IEnumerable<Creature> creatures, bool bestInSpecies)
{
BreedingScore.SetBestLevels(creatures, bestLevels, _statWeights);
BreedingScore.SetBestLevels(creatures, bestLevels, _statWeights, CbConsiderOnlyEvenForHighStats.Checked);

// display top levels in species
int? levelStep = CreatureCollection.getWildLevelStep();
Expand Down Expand Up @@ -1181,6 +1181,7 @@ private void CbConsiderOnlyEvenForHighStats_CheckedChanged(object sender, EventA
{
Settings.Default.BreedingPlannerConsiderOnlyEvenForHighStats = CbConsiderOnlyEvenForHighStats.Checked;
CalculateBreedingScoresAndDisplayPairs();
DetermineBestLevels();
}

private void CbDontSuggestOverLimitOffspring_CheckedChanged(object sender, EventArgs e)
Expand Down
10 changes: 8 additions & 2 deletions ARKBreedingStats/BreedingPlanning/BreedingScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
return breedingPairs;
}

public static void SetBestLevels(IEnumerable<Creature> creatures, int[] bestLevels, double[] statWeights)
/// <summary>
/// Sets the best levels in the passed bestLevels array, depending on the statWeights and onlyHighEvenLevels.
/// </summary>
public static void SetBestLevels(IEnumerable<Creature> creatures, int[] bestLevels, double[] statWeights, bool onlyHighEvenLevels)
{
for (int s = 0; s < Stats.StatsCount; s++)
bestLevels[s] = -1;
Expand All @@ -217,7 +220,10 @@ public static void SetBestLevels(IEnumerable<Creature> creatures, int[] bestLeve
for (int s = 0; s < Stats.StatsCount; s++)
{
if ((s == Stats.Torpidity || statWeights[s] >= 0) && c.levelsWild[s] > bestLevels[s])
bestLevels[s] = c.levelsWild[s];
{
if (!onlyHighEvenLevels || c.levelsWild[s] % 2 == 0)
bestLevels[s] = c.levelsWild[s];
}
else if (s != Stats.Torpidity && statWeights[s] < 0 && c.levelsWild[s] >= 0 && (c.levelsWild[s] < bestLevels[s] || bestLevels[s] < 0))
bestLevels[s] = c.levelsWild[s];
}
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = fal
FilterLibRecalculate();

// apply last sorting
//listViewLibrary.Sort(); // TODO
SortLibrary();

UpdateTempCreatureDropDown();

Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ private void lbLibrarySelectionInfo_Click(object sender, EventArgs e)
private void listBoxSpeciesLib_SelectedIndexChanged(object sender, EventArgs e)
{
SetSpecies(listBoxSpeciesLib.SelectedItem as Species);
FilterLibRecalculate();
FilterLibRecalculate(true);
}

/// <summary>
Expand Down
49 changes: 42 additions & 7 deletions ARKBreedingStats/Form1.importExported.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,56 @@ private void ImportLastExportedCreature()
if (Utils.GetFirstImportExportFolder(out string folder))
{
var files = Directory.GetFiles(folder);
if (files.Length > 0)
if (files.Length == 0)
{
ExtractExportedFileInExtractor(files.OrderByDescending(f => File.GetLastWriteTime(f)).First());
// some users forget to select the id folder where the export files are located. Check if that's the case
FileInfo lastExportFile = null;
if (Path.GetFileName(folder) == "DinoExports")
{
// check subfolders for export files
var subFolders = Directory.GetDirectories(folder);
foreach (var sf in subFolders)
{
var d = new DirectoryInfo(sf);
var fs = d.GetFiles("*.ini");
if (!fs.Any()) continue;
var expFile = fs.OrderByDescending(f => f.LastWriteTime).First();
if (lastExportFile == null || expFile.LastWriteTime > lastExportFile.LastWriteTime)
lastExportFile = expFile;
}
}

if (lastExportFile == null)
{
MessageBoxes.ShowMessageBox(
$"No exported creature-file found in the set folder\n{folder}\nYou have to export a creature first ingame.\n\n" +
"You may also want to check the set folder in the settings. Usually the folder path ends with\n" +
@"…\ARK\ShooterGame\Saved\DinoExports\<ID>",
$"No files found");
return;
}

if (MessageBox.Show(
$"No exported creature-file found in the set folder\n{folder}\n\nThere seems to be an export file in a subfolder, do you want to use this folder instead?\n{lastExportFile.DirectoryName}",
$"Use subfolder with export file? - {Utils.ApplicationNameVersion}",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
var exportFolders = Properties.Settings.Default.ExportCreatureFolders;
var firstExportFolder = ATImportExportedFolderLocation.CreateFromString(exportFolders[0]);
firstExportFolder.FolderPath = lastExportFile.DirectoryName;
exportFolders[0] = firstExportFolder.ToString();

ExtractExportedFileInExtractor(lastExportFile.FullName);
}
return;
}

MessageBoxes.ShowMessageBox($"No exported creature-file found in the set folder\n{folder}\nYou have to export a creature first ingame.\n\n" +
"You may also want to check the set folder in the settings. Usually the folder is\n" +
@"…\Steam\steamapps\common\ARK\ShooterGame\Saved\DinoExports\<ID>",
$"No files found");
ExtractExportedFileInExtractor(files.OrderByDescending(File.GetLastWriteTime).First());
return;
}

if (MessageBox.Show("There is no folder set where the exported creatures are located, or the set folder does not exist. Set this folder in the settings. " +
"Usually the folder is\n" + @"…\Steam\steamapps\common\ARK\ShooterGame\Saved\DinoExports\<ID>" + "\n\nOpen the settings-page?",
"Usually the folder path ends with\n" + @"…\ARK\ShooterGame\Saved\DinoExports\<ID>" + "\n\nOpen the settings-page?",
$"No default export-folder set - {Utils.ApplicationNameVersion}", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
{
OpenSettingsDialog(Settings.SettingsTabPages.ExportedImport);
Expand Down
63 changes: 52 additions & 11 deletions ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private void UpdateIncubationParents(CreatureCollection cc)
private void ShowCreaturesInListView(IEnumerable<Creature> creatures)
{
listViewLibrary.BeginUpdate();
_creaturesDisplayed = _creatureListSorter.DoSort(creatures.Where(cr => cr.Species != null));
_creaturesDisplayed = _creatureListSorter.DoSort(creatures);
listViewLibrary.VirtualListSize = _creaturesDisplayed.Length;
_libraryListViewItemCache = null;
listViewLibrary.EndUpdate();
Expand Down Expand Up @@ -828,7 +828,6 @@ private void ListViewLibrary_CacheVirtualItems(object sender, CacheVirtualItemsE
/// <param name="creatureStatusChanged"></param>
private void UpdateDisplayedCreatureValues(Creature cr, bool creatureStatusChanged, bool ownerServerChanged)
{
_reactOnCreatureSelectionChange = false;
// if row is selected, save and reselect later
var selectedCreatures = new HashSet<Creature>();
foreach (int i in listViewLibrary.SelectedIndices)
Expand All @@ -854,28 +853,42 @@ private void UpdateDisplayedCreatureValues(Creature cr, bool creatureStatusChang
SetCollectionChanged(true, cr.Species);

SelectCreaturesInLibrary(selectedCreatures);

_reactOnCreatureSelectionChange = true;
}

private void SelectCreaturesInLibrary(HashSet<Creature> selectedCreatures)
/// <summary>
/// Selects the passed creatures in the library and sets _reactOnCreatureSelectionChange on true again.
/// </summary>
/// <param name="selectedCreatures"></param>
private void SelectCreaturesInLibrary(HashSet<Creature> selectedCreatures, bool selectFirstIfNothingIsSelected = false)
{
var selectedCount = selectedCreatures?.Count ?? 0;
if (selectedCount == 0)
{
listViewLibrary.SelectedIndices.Clear();
if (selectFirstIfNothingIsSelected && _creaturesDisplayed.Length != 0)
{
_reactOnCreatureSelectionChange = true;
listViewLibrary.SelectedIndices.Add(0);
listViewLibrary.EnsureVisible(0);
}
else
{
creatureBoxListView.Clear();
}
return;
}

_reactOnCreatureSelectionChange = false;

listViewLibrary.SelectedIndices.Clear();

var creatureSelected = false;
// for loop is faster than foreach loop for small selected item amount, which is usually the case
for (int i = 0; i < _creaturesDisplayed.Length; i++)
{
if (selectedCreatures.Contains(_creaturesDisplayed[i]))
{
creatureSelected = true;
if (--selectedCount == 0)
{
_reactOnCreatureSelectionChange = true;
Expand All @@ -886,6 +899,22 @@ private void SelectCreaturesInLibrary(HashSet<Creature> selectedCreatures)
listViewLibrary.SelectedIndices.Add(i);
}
}

if (!creatureSelected)
{
if (selectFirstIfNothingIsSelected && _creaturesDisplayed.Length != 0)
{
_reactOnCreatureSelectionChange = true;
listViewLibrary.SelectedIndices.Add(0);
listViewLibrary.EnsureVisible(0);
}
else
{
creatureBoxListView.Clear();
}
}

_reactOnCreatureSelectionChange = true; // make sure it reacts again even if the previously creature is not visible anymore
}

/// <summary>
Expand Down Expand Up @@ -1145,6 +1174,9 @@ private void libraryListView_ColumnClick(object sender, ColumnClickEventArgs e)
SortLibrary(e.Column);
}

/// <summary>
/// /// Sort the library by given column index. If the columnIndex is -1, use last sorting.
/// </summary>
private void SortLibrary(int columnIndex = -1)
{
listViewLibrary.BeginUpdate();
Expand Down Expand Up @@ -1219,17 +1251,17 @@ private void LibrarySelectedIndexChanged()
/// Display the creatures with the current filter.
/// Recalculate all filters.
/// </summary>
private void FilterLibRecalculate()
private void FilterLibRecalculate(bool selectFirstIfNothingIsSelected = false)
{
_creaturesPreFiltered = null;
FilterLib();
FilterLib(selectFirstIfNothingIsSelected);
}

/// <summary>
/// Display the creatures with the current filter.
/// Use the pre filtered list (if available) and only apply the live filter.
/// </summary>
private void FilterLib()
private void FilterLib(bool selectFirstIfNothingIsSelected = false)
{
if (!_filterListAllowed)
return;
Expand All @@ -1244,7 +1276,7 @@ private void FilterLib()
if (_creaturesPreFiltered == null)
{
filteredList = from creature in _creatureCollection.creatures
where !creature.flags.HasFlag(CreatureFlags.Placeholder)
where creature.Species != null && !creature.flags.HasFlag(CreatureFlags.Placeholder)
select creature;

// if only one species should be shown adjust headers if the selected species has custom statNames
Expand Down Expand Up @@ -1376,7 +1408,7 @@ private void FilterLib()
ShowCreaturesInListView(filteredList);

// select previous selected creatures again
SelectCreaturesInLibrary(selectedCreatures);
SelectCreaturesInLibrary(selectedCreatures, selectFirstIfNothingIsSelected);
}

/// <summary>
Expand All @@ -1399,6 +1431,15 @@ private IEnumerable<Creature> ApplyLibraryFilterSettings(IEnumerable<Creature> c
if (Properties.Settings.Default.FilterOnlyIfColorId != 0)
creatures = creatures.Where(c => c.colors.Contains(Properties.Settings.Default.FilterOnlyIfColorId));

if (Properties.Settings.Default.FilterHideAdults)
creatures = creatures.Where(c => c.Maturation < 1);
if (Properties.Settings.Default.FilterHideNonAdults)
creatures = creatures.Where(c => c.Maturation >= 1);
if (Properties.Settings.Default.FilterHideCooldowns)
creatures = creatures.Where(c => c.cooldownUntil == null || c.cooldownUntil < DateTime.Now);
if (Properties.Settings.Default.FilterHideNonCooldowns)
creatures = creatures.Where(c => c.cooldownUntil != null && c.cooldownUntil > DateTime.Now);

// tags filter
if (Properties.Settings.Default.FilterHideTags?.Any() ?? false)
{
Expand Down Expand Up @@ -1556,7 +1597,7 @@ private void ShowMultiSetter()

private void ToolStripTextBoxLibraryFilter_TextChanged(object sender, EventArgs e)
{
filterLibraryDebouncer.Debounce(ToolStripTextBoxLibraryFilter.Text == string.Empty ? 0 : 300, FilterLib, Dispatcher.CurrentDispatcher);
filterLibraryDebouncer.Debounce(ToolStripTextBoxLibraryFilter.Text == string.Empty ? 0 : 500, FilterLib, Dispatcher.CurrentDispatcher, false);
}

private void ToolStripButtonLibraryFilterClear_Click(object sender, EventArgs e)
Expand Down
2 changes: 2 additions & 0 deletions ARKBreedingStats/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ static class Program
static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
#if !DEBUG
currentDomain.UnhandledException += UnhandledExceptionHandler;
#endif

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.50.2.0")]
[assembly: AssemblyFileVersion("0.50.3.0")]
[assembly: NeutralResourcesLanguage("en")]

48 changes: 48 additions & 0 deletions ARKBreedingStats/Properties/Settings.Designer.cs

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

12 changes: 12 additions & 0 deletions ARKBreedingStats/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,17 @@
<Setting Name="UseTribeFilterForBreedingPlan" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FilterHideAdults" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FilterHideNonAdults" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FilterHideCooldowns" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FilterHideNonCooldowns" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 92825ba

Please sign in to comment.