Skip to content

Commit

Permalink
custom overlay pattern for import
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Nov 2, 2024
1 parent f4f9510 commit 0fb1b89
Show file tree
Hide file tree
Showing 10 changed files with 1,737 additions and 1,658 deletions.
3 changes: 3 additions & 0 deletions ARKBreedingStats/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
<setting name="LevelColorWindowRectangle" serializeAs="String">
<value>200, 200, 1000, 650</value>
</setting>
<setting name="OverlayImportPattern" serializeAs="String">
<value />
</setting>
</ARKBreedingStats.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion ARKBreedingStats/CreatureInfoInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ public void OpenNamePatternEditor(Creature creature, TopLevels topLevels, Dictio
{
if (!parentListValid)
ParentListRequested?.Invoke(this);
using (var pe = new PatternEditor(creature, _sameSpecies, topLevels, ColorAlreadyExistingInformation, customReplacings, namingPatternIndex, reloadCallback, LibraryCreatureCount))
using (var pe = new PatternEditor(creature, _sameSpecies, topLevels, ColorAlreadyExistingInformation,
customReplacings, $"pattern {namingPatternIndex + 1}", Settings.Default.NamingPatterns?[namingPatternIndex], reloadCallback, LibraryCreatureCount))
{
if (pe.ShowDialog() == DialogResult.OK)
{
Expand Down
20 changes: 17 additions & 3 deletions ARKBreedingStats/Form1.importExported.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private Creature ImportExportedAddIfPossible(string filePath)
creature = GetCreatureFromInput(true, species, levelStep);
}

OverlayFeedbackForImport(creature, uniqueExtraction, alreadyExists, addedToLibrary, copiedNameToClipboard);
OverlayFeedbackForImport(creature, uniqueExtraction, alreadyExistingCreature, addedToLibrary, copiedNameToClipboard);

if (addedToLibrary)
{
Expand Down Expand Up @@ -374,7 +374,7 @@ private bool CopyCreatureNameToClipboardOnImportIfSetting(string creatureName, b
/// <summary>
/// Give feedback in overlay for imported creature.
/// </summary>
private void OverlayFeedbackForImport(Creature creature, bool uniqueExtraction, bool alreadyExists, bool addedToLibrary,
private void OverlayFeedbackForImport(Creature creature, bool uniqueExtraction, Creature alreadyExistingCreature, bool addedToLibrary,
bool copiedNameToClipboard)
{
string infoText;
Expand All @@ -383,7 +383,7 @@ private void OverlayFeedbackForImport(Creature creature, bool uniqueExtraction,
if (uniqueExtraction)
{
var sb = new StringBuilder();
sb.AppendLine($"{creature.SpeciesName} \"{creature.name}\" {(alreadyExists ? "updated in " : "added to")} the library.");
sb.AppendLine($"{creature.SpeciesName} \"{creature.name}\" {(alreadyExistingCreature != null ? "updated in " : "added to")} the library.");
if (addedToLibrary && copiedNameToClipboard)
sb.AppendLine("Name copied to clipboard.");

Expand All @@ -407,6 +407,20 @@ private void OverlayFeedbackForImport(Creature creature, bool uniqueExtraction,

if (_overlay != null)
{
var overlayPattern = Properties.Settings.Default.OverlayImportPattern;
if (!string.IsNullOrEmpty(overlayPattern))
{
var overlayPatternResult = NamePattern.GenerateCreatureName(creature, alreadyExistingCreature,
_creatureCollection.creatures.Where(c => c.Species == creature.Species).ToArray(),
_topLevels.TryGetValue(creature.Species, out var tl) ? tl : null,
_customReplacingNamingPattern, false, -1, false, overlayPattern,
false, colorsExisting: _creatureCollection.ColorAlreadyAvailable(creature.Species, creature.colors, out _),
libraryCreatureCount: _creatureCollection.GetTotalCreatureCount());

if (!string.IsNullOrEmpty(overlayPatternResult))
infoText += Environment.NewLine + Environment.NewLine + overlayPatternResult;
}

_overlay.SetInfoText(infoText, textColor);
if (Properties.Settings.Default.DisplayInheritanceInOverlay)
_overlay.SetInheritanceCreatures(creature, creature.Mother, creature.Father);
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/NamePatterns/NamePattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class NamePattern
/// </summary>
/// <param name="alreadyExistingCreature">If the creature already exists in the library, null if the creature is new.</param>
public static string GenerateCreatureName(Creature creature, Creature alreadyExistingCreature, Creature[] sameSpecies, TopLevels topLevels, Dictionary<string, string> customReplacings,
bool showDuplicateNameWarning, int namingPatternIndex, bool showTooLongWarning = true, string pattern = null, bool displayError = true, TokenModel tokenModel = null,
bool showDuplicateNameWarning = false, int namingPatternIndex = -1, bool showTooLongWarning = true, string pattern = null, bool displayError = true, TokenModel tokenModel = null,
ColorExisting[] colorsExisting = null, int libraryCreatureCount = 0, Action<string> consoleLog = null)
{
if (pattern == null)
Expand Down
7 changes: 4 additions & 3 deletions ARKBreedingStats/NamePatterns/PatternEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private static void SelectFullLines(TextBox textBox, out int endLine, out int st
textBox.Select(start, end - start);
}

public PatternEditor(Creature creature, Creature[] creaturesOfSameSpecies, TopLevels topLevels, CreatureCollection.ColorExisting[] colorExistings, Dictionary<string, string> customReplacings, int namingPatternIndex, Action<PatternEditor> reloadCallback, int libraryCreatureCount) : this()
public PatternEditor(Creature creature, Creature[] creaturesOfSameSpecies, TopLevels topLevels, CreatureCollection.ColorExisting[] colorExistings,
Dictionary<string, string> customReplacings, string namingPatternName, string patternString, Action<PatternEditor> reloadCallback, int libraryCreatureCount) : this()
{
Utils.SetWindowRectangle(this, Properties.Settings.Default.PatternEditorFormRectangle);
if (Properties.Settings.Default.PatternEditorSplitterDistance > 0)
Expand All @@ -145,11 +146,11 @@ public PatternEditor(Creature creature, Creature[] creaturesOfSameSpecies, TopLe
_customReplacings = customReplacings;
_reloadCallback = reloadCallback;
_libraryCreatureCount = libraryCreatureCount;
txtboxPattern.Text = Properties.Settings.Default.NamingPatterns?[namingPatternIndex] ?? string.Empty;
txtboxPattern.Text = patternString ?? string.Empty;
CbPatternNameToClipboardAfterManualApplication.Checked = Properties.Settings.Default.PatternNameToClipboardAfterManualApplication;
txtboxPattern.SelectionStart = txtboxPattern.Text.Length;

Text = $"Naming Pattern Editor: pattern {namingPatternIndex + 1}";
Text = $"Naming Pattern Editor: {namingPatternName}";

_alreadyExistingCreature = _creaturesOfSameSpecies?.FirstOrDefault(c => c.guid == creature.guid);
_tokenModel = NamePatterns.NamePattern.CreateTokenModel(creature, _alreadyExistingCreature, _creaturesOfSameSpecies, _colorExistings, _topLevels, _libraryCreatureCount);
Expand Down
12 changes: 12 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.

3 changes: 3 additions & 0 deletions ARKBreedingStats/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,8 @@
<Setting Name="LevelColorWindowRectangle" Type="System.Drawing.Rectangle" Scope="User">
<Value Profile="(Default)">200, 200, 1000, 650</Value>
</Setting>
<Setting Name="OverlayImportPattern" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 0fb1b89

Please sign in to comment.