Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed May 17, 2023
2 parents dbc48e5 + 0e5ff39 commit 4fb8cbe
Show file tree
Hide file tree
Showing 25 changed files with 999 additions and 740 deletions.
132 changes: 118 additions & 14 deletions ARKBreedingStats/ARKOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ARKBreedingStats.ocr;
using ARKBreedingStats.species;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -18,33 +17,47 @@ public partial class ARKOverlay : Form
public Form1 ExtractorForm;
private bool _ocrPossible;
private bool _OCRing;
public List<TimerListEntry> timers;
public TimerListEntry[] timers;
public List<Creature> CreatureTimers;
public List<IncubationTimerEntry> IncubationTimers;
private string _notes;
public static ARKOverlay theOverlay;
private DateTime _infoShownAt;
public int InfoDuration;
private bool _currentlyInInventory;
public bool checkInventoryStats;
private bool _toggleInventoryCheck; // check inventory only every other time
private Dictionary<Label, float> _initialFontSizes;

public ARKOverlay()
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
Win32API.SetHitTestVisibility(this.Handle, false);
TopMost = true;
parentInheritance1.ForeColor = Color.FromArgb(1, 1, 1); // so it's not transparent (black == TransparencyKey)
Win32API.SetHitTestVisibility(this.Handle, false);

_infoShownAt = DateTime.Now.AddMinutes(-10);
_labels = new[] { lblHealth, lblStamina, lblOxygen, lblFood, lblWeight, lblMeleeDamage, lblMovementSpeed, lblLevel };

// save initial font sizes for later adjustment
_initialFontSizes = new Dictionary<Label, float>();

foreach (Label l in _labels)
{
l.Text = string.Empty;
_initialFontSizes[l] = l.Font.Size;
}
lblStatus.Text = string.Empty;
labelTimer.Text = string.Empty;
labelInfo.Text = string.Empty;

_initialFontSizes[lblStatus] = lblStatus.Font.Size;
_initialFontSizes[labelTimer] = labelTimer.Font.Size;
_initialFontSizes[labelInfo] = labelInfo.Font.Size;


Size = ArkOcr.Ocr.GetScreenshotOfProcess()?.Size ?? default;
if (Size == default)
Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Expand All @@ -56,20 +69,19 @@ public ARKOverlay()

_ocrPossible = ArkOcr.Ocr.ocrConfig != null && ArkOcr.Ocr.CheckResolutionSupportedByOcr();

SetInfoPositions();
SetInfoPositionsAndFontSize();
_notes = string.Empty;
SetInheritanceCreatures();
SetLocatlizations();
SetLocalizations();

InfoDuration = 10;

Location = new Point(0, 0);
}

public void SetInfoPositions()
public void SetInfoPositionsAndFontSize()
{
labelTimer.Location = Properties.Settings.Default.OverlayTimerPosition;
labelInfo.Location = new Point(Size.Width - labelInfo.Width - Properties.Settings.Default.OverlayInfoPosition.X, Properties.Settings.Default.OverlayInfoPosition.Y);
SetLabelFontSize(Properties.Settings.Default.OverlayRelativeFontSize);
}

public void InitLabelPositions()
Expand Down Expand Up @@ -177,14 +189,15 @@ internal void SetInfoText(string infoText, Color textColor)
/// </summary>
private void SetTimerAndNotesText()
{
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();

if (timers?.Any() ?? false)
{
bool timerListChanged = false;
var timerListChanged = false;
foreach (TimerListEntry tle in timers)
{
int secLeft = (int)tle.time.Subtract(DateTime.Now).TotalSeconds + 1;
var timeLeft = tle.time.Subtract(DateTime.Now);
int secLeft = (int)timeLeft.TotalSeconds + 1;
if (secLeft < 10)
{
if (!Properties.Settings.Default.KeepExpiredTimersInOverlay && secLeft < -20)
Expand All @@ -195,10 +208,53 @@ private void SetTimerAndNotesText()
}
sb.Append("expired ");
}
sb.AppendLine($"{Utils.TimeLeft(tle.time)} : {tle.name}");
sb.AppendLine($"{Utils.Duration(timeLeft)} : {tle.name}");
}
if (timerListChanged)
timers = timers.Where(t => t.showInOverlay).ToList();
timers = timers.Where(t => t.showInOverlay).ToArray();
}
if (IncubationTimers?.Any() ?? false)
{
sb.AppendLine();
sb.AppendLine(Loc.S("Incubation"));
foreach (var it in IncubationTimers)
{
var timeLeft = it.incubationEnd.Subtract(DateTime.Now);
int secLeft = (int)timeLeft.TotalSeconds + 1;
if (secLeft < 10)
{
if (!Properties.Settings.Default.KeepExpiredTimersInOverlay && secLeft < -20)
{
it.ShowInOverlay = false;
RemoveTimer(it);
continue;
}
sb.Append("incubated ");
}
sb.AppendLine($"{Utils.Duration(timeLeft)} : {(it.Mother?.Species ?? it.Father?.Species)?.DescriptiveName ?? "unknown species"}");
}
}
if (CreatureTimers?.Any() ?? false)
{
sb.AppendLine();
sb.AppendLine(Loc.S("Maturation"));
foreach (var c in CreatureTimers)
{
var timeLeft = c.growingUntil?.Subtract(DateTime.Now);
int secLeft = timeLeft == null ? -100 : (int)timeLeft.Value.TotalSeconds + 1;
if (secLeft < 10)
{
if (!Properties.Settings.Default.KeepExpiredTimersInOverlay && secLeft < -20)
{
c.ShowInOverlay = false;
RemoveTimer(c);
continue;
}

timeLeft = null;
}
sb.AppendLine($"{(timeLeft == null ? "grown" : Utils.Duration(timeLeft.Value))} : {c.name} ({c.Species.DescriptiveName})");
}
}
sb.Append(_notes);
labelTimer.Text = sb.ToString();
Expand All @@ -212,7 +268,55 @@ internal void SetNotes(string notes)

internal void SetInheritanceCreatures(Creature creature = null, Creature mother = null, Creature father = null) => parentInheritance1.SetCreatures(creature, mother, father);

internal void SetLocatlizations()
public static void AddTimer(Creature creature)
{
creature.ShowInOverlay = true;

if (theOverlay == null)
return;

if (theOverlay.CreatureTimers == null)
theOverlay.CreatureTimers = new List<Creature> { creature };
else theOverlay.CreatureTimers.Add(creature);
}

public static void RemoveTimer(Creature creature)
{
creature.ShowInOverlay = false;
if (theOverlay?.CreatureTimers == null) return;
theOverlay.CreatureTimers.Remove(creature);
if (!theOverlay.CreatureTimers.Any())
theOverlay.CreatureTimers = null;
}

public static void AddTimer(IncubationTimerEntry incubationTimer)
{
incubationTimer.ShowInOverlay = true;

if (theOverlay == null)
return;

if (theOverlay.IncubationTimers == null)
theOverlay.IncubationTimers = new List<IncubationTimerEntry> { incubationTimer };
else theOverlay.IncubationTimers.Add(incubationTimer);
}

public static void RemoveTimer(IncubationTimerEntry incubationTimer)
{
incubationTimer.ShowInOverlay = false;
if (theOverlay?.IncubationTimers == null) return;
theOverlay.IncubationTimers.Remove(incubationTimer);
if (!theOverlay.IncubationTimers.Any())
theOverlay.IncubationTimers = null;
}

public void SetLabelFontSize(float relativeSize)
{
foreach (var l in _initialFontSizes)
l.Key.Font = new Font(l.Key.Font.FontFamily, l.Value * relativeSize, l.Key.Font.Style);
}

internal void SetLocalizations()
{
parentInheritance1.SetLocalizations();
}
Expand Down
3 changes: 3 additions & 0 deletions ARKBreedingStats/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@
<setting name="language2" serializeAs="String">
<value />
</setting>
<setting name="OverlayRelativeFontSize" serializeAs="String">
<value>1</value>
</setting>
</ARKBreedingStats.Properties.Settings>
</userSettings>
</configuration>
4 changes: 2 additions & 2 deletions ARKBreedingStats/BreedingPlanning/BreedingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
{
// display warning if breeding pairs are filtered out
string warningText = null;
if (creaturesTagFilteredOut) warningText = Loc.S("BPsomeCreaturesAreFilteredOutTags") + ".\n" + Loc.S("BPTopStatsShownMightNotTotalTopStats");
if (creaturesMutationsFilteredOut) warningText = (!string.IsNullOrEmpty(warningText) ? warningText + "\n" : string.Empty) + Loc.S("BPsomePairingsAreFilteredOutMutations");
if (creaturesTagFilteredOut) warningText = Loc.S("BPsomeCreaturesAreFilteredOutTags") + ".\r\n" + Loc.S("BPTopStatsShownMightNotTotalTopStats");
if (creaturesMutationsFilteredOut) warningText = (!string.IsNullOrEmpty(warningText) ? warningText + "\r\n" : string.Empty) + Loc.S("BPsomePairingsAreFilteredOutMutations");
if (!string.IsNullOrEmpty(warningText)) SetMessageLabelText(warningText, MessageBoxIcon.Warning);
}

Expand Down
5 changes: 3 additions & 2 deletions ARKBreedingStats/CreatureInfoInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,9 @@ public void GenerateCreatureName(Creature creature, int[] speciesTopLevels, int[
{
SetCreatureData(creature);
CreatureName = NamePattern.GenerateCreatureName(creature, _sameSpecies, speciesTopLevels, speciesLowestLevels, customReplacings, showDuplicateNameWarning, namingPatternIndex, false, colorsExisting: ColorAlreadyExistingInformation);
if (CreatureName.Length > 24)
SetMessageLabelText?.Invoke("The generated name is longer than 24 characters, the name will look like this in game:\n" + CreatureName.Substring(0, 24), MessageBoxIcon.Error);
const int maxNameLengthInGame = 24;
if (CreatureName.Length > maxNameLengthInGame)
SetMessageLabelText?.Invoke($"The generated name is longer than {maxNameLengthInGame} characters, the name will look like this in game:\r\n" + CreatureName.Substring(0, maxNameLengthInGame), MessageBoxIcon.Error);
else SetMessageLabelText?.Invoke();
}

Expand Down
Loading

0 comments on commit 4fb8cbe

Please sign in to comment.