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 25, 2022
2 parents b1c222e + 0ff5e96 commit 054c09c
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 130 deletions.
126 changes: 52 additions & 74 deletions ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,7 @@ private Creature AddCreatureToCollection(bool fromExtractor = true, long motherA
if (goToLibraryTab)
{
tabControlMain.SelectedTab = tabPageLibrary;

// select new creature and ensure visibility
_reactOnCreatureSelectionChange = false;
listViewLibrary.SelectedIndices.Clear();
_reactOnCreatureSelectionChange = true;
for (int i = 0; i < listViewLibrary.Items.Count; i++)
{
if (creature == (Creature)listViewLibrary.Items[i].Tag)
{
listViewLibrary.Items[i].Focused = true;
listViewLibrary.Items[i].Selected = true;
listViewLibrary.EnsureVisible(i);
break;
}
}
SelectCreatureInLibrary(creature);
}

creatureInfoInputExtractor.parentListValid = false;
Expand Down Expand Up @@ -867,28 +853,57 @@ private void UpdateDisplayedCreatureValues(Creature cr, bool creatureStatusChang
UpdateOwnerServerTagLists();
SetCollectionChanged(true, cr.Species);

// select previous selected creatures again
int selectedCount = selectedCreatures.Count;
if (selectedCount > 0)
SelectCreaturesInLibrary(selectedCreatures);

_reactOnCreatureSelectionChange = true;
}

private void SelectCreaturesInLibrary(HashSet<Creature> selectedCreatures)
{
var selectedCount = selectedCreatures?.Count ?? 0;
if (selectedCount == 0)
{
// for loop is faster than foreach loop for small selected item amount, which is usually the case
for (int i = 0; i < listViewLibrary.Items.Count; i++)
listViewLibrary.SelectedIndices.Clear();
return;
}

_reactOnCreatureSelectionChange = false;

listViewLibrary.SelectedIndices.Clear();

// 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]))
{
var item = listViewLibrary.Items[i];
if (selectedCreatures.Contains((Creature)item.Tag))
if (--selectedCount == 0)
{
item.Focused = true;
item.Selected = true;
if (--selectedCount == 0)
{
listViewLibrary.EnsureVisible(i);
break;
}
_reactOnCreatureSelectionChange = true;
listViewLibrary.SelectedIndices.Add(i);
listViewLibrary.EnsureVisible(i);
break;
}
listViewLibrary.SelectedIndices.Add(i);
}
}
}

/// <summary>
/// Selects a creature in the library
/// </summary>
/// <param name="creature"></param>
private void SelectCreatureInLibrary(Creature creature)
{
if (creature == null) return;

var index = Array.IndexOf(_creaturesDisplayed, creature);
if (index == -1) return;

_reactOnCreatureSelectionChange = false;
listViewLibrary.SelectedIndices.Clear();
_reactOnCreatureSelectionChange = true;
listViewLibrary.SelectedIndices.Add(index);
listViewLibrary.EnsureVisible(index);
}

private void UpdateCreatureListViewItem(Creature creature)
Expand Down Expand Up @@ -1133,9 +1148,15 @@ private void libraryListView_ColumnClick(object sender, ColumnClickEventArgs e)
private void SortLibrary(int columnIndex = -1)
{
listViewLibrary.BeginUpdate();

var selectedCreatures = new HashSet<Creature>();
foreach (int i in listViewLibrary.SelectedIndices)
selectedCreatures.Add(_creaturesDisplayed[i]);

_creaturesDisplayed = _creatureListSorter.DoSort(_creaturesDisplayed, columnIndex);
_libraryListViewItemCache = null;
listViewLibrary.EndUpdate();
SelectCreaturesInLibrary(selectedCreatures);
}

private readonly Debouncer _libraryIndexChangedDebouncer = new Debouncer();
Expand Down Expand Up @@ -1214,11 +1235,9 @@ private void FilterLib()
return;

// save selected creatures to re-select them after the filtering
List<Creature> selectedCreatures = new List<Creature>();
var selectedCreatures = new HashSet<Creature>();
foreach (int i in listViewLibrary.SelectedIndices)
{
selectedCreatures.Add(_creaturesDisplayed[i]);
}

IEnumerable<Creature> filteredList;

Expand Down Expand Up @@ -1356,31 +1375,8 @@ private void FilterLib()
// display new results
ShowCreaturesInListView(filteredList);

// update creatureBox
creatureBoxListView.UpdateLabel();

// select previous selected creatures again
listViewLibrary.SelectedIndices.Clear();
creatureBoxListView.Clear();
int selectedCount = selectedCreatures.Count;
if (selectedCount != 0)
{
// for loop is faster than foreach loop for small selected item amount, which is usually the case
for (int i = 0; i < listViewLibrary.Items.Count; i++)
{
var item = listViewLibrary.Items[i];
if (selectedCreatures.Contains((Creature)item.Tag))
{
item.Selected = true;
if (--selectedCount == 0)
{
item.Focused = true;
listViewLibrary.EnsureVisible(i);
break;
}
}
}
}
SelectCreaturesInLibrary(selectedCreatures);
}

/// <summary>
Expand Down Expand Up @@ -1648,24 +1644,6 @@ private void saveInfographicsToFolderToolStripMenuItem_Click(object sender, Even
SetMessageLabelText($"Infographic{pluralS} for {imagesCreated} creature{pluralS} created at\n{(imagesCreated == 1 ? firstImageFilePath : folderPath)}", MessageBoxIcon.Information, firstImageFilePath);
}

/// <summary>
/// Selects a creature in the library
/// </summary>
/// <param name="creature"></param>
private void SelectCreatureInLibrary(Creature creature)
{
if (creature == null) return;

var index = Array.IndexOf(_creaturesDisplayed, creature);
if (index == -1) return;

_reactOnCreatureSelectionChange = false;
listViewLibrary.SelectedIndices.Clear();
_reactOnCreatureSelectionChange = true;
listViewLibrary.SelectedIndices.Add(index);
listViewLibrary.EnsureVisible(index);
}

#region Library ContextMenu

private void toolStripMenuItemEdit_Click(object sender, EventArgs e)
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.1.2")]
[assembly: AssemblyFileVersion("0.50.2.0")]
[assembly: NeutralResourcesLanguage("en")]

2 changes: 1 addition & 1 deletion ARKBreedingStats/_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ARK Smart Breeding": {
"Id": "ARK Smart Breeding",
"Category": "main",
"version": "0.50.1.2"
"version": "0.50.2.0"
},
"SpeciesColorImages": {
"Id": "SpeciesColorImages",
Expand Down
27 changes: 15 additions & 12 deletions ARKBreedingStats/library/CreatureInfoGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,23 @@ public static Bitmap InfoGraphic(this Creature creature, CreatureCollection cc,

if (displayExtraRegionNames || (!creatureImageShown && displayRegionNamesIfNoImage))
{
colorRegionName = creature.Species.colors[ci].name;
int totalColorLength = colorRegionName.Length + 11;
if (totalColorLength > maxColorNameLength)
colorRegionName = creature.Species.colors?[ci]?.name;
if (colorRegionName != null)
{
// shorten color region name
int lengthForRegionName =
colorRegionName.Length - (totalColorLength - maxColorNameLength);
colorRegionName = lengthForRegionName < 2
? string.Empty
: colorRegionName.Substring(0, lengthForRegionName - 1) + "…";
int totalColorLength = colorRegionName.Length + 11;
if (totalColorLength > maxColorNameLength)
{
// shorten color region name
int lengthForRegionName =
colorRegionName.Length - (totalColorLength - maxColorNameLength);
colorRegionName = lengthForRegionName < 2
? string.Empty
: colorRegionName.Substring(0, lengthForRegionName - 1) + "…";
}

if (!string.IsNullOrEmpty(colorRegionName))
colorRegionName = " (" + colorRegionName + ")";
}

if (!string.IsNullOrEmpty(colorRegionName))
colorRegionName = " (" + colorRegionName + ")";
}

g.DrawString($"{creature.colors[ci]} - [{ci}]{colorRegionName}",
Expand Down
Loading

0 comments on commit 054c09c

Please sign in to comment.