Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Sep 9, 2024
2 parents 3605bb4 + 5eb66c2 commit b77c803
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 44 deletions.
26 changes: 0 additions & 26 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,32 +409,6 @@ private void LoadAppSettings()
}
UpdatePatternButtons();

// conversion of global color level settings to specific options. Remove around 2024-09
if (Properties.Settings.Default.ChartHueEvenMax != int.MaxValue)
{
var defaultSettings = StatsLevelColors.StatsOptionsDict[string.Empty].StatOptions;
for (var s = 0; s < Stats.StatsCount; s++)
{
defaultSettings[s].LevelGraphRepresentation.LowerColor = Utils.ColorFromHue(Properties.Settings.Default.ChartHueEvenMin);
defaultSettings[s].LevelGraphRepresentation.UpperColor = Utils.ColorFromHue(Properties.Settings.Default.ChartHueEvenMax);
defaultSettings[s].LevelGraphRepresentation.ColorGradientReversed = Properties.Settings.Default.ChartHueEvenMax < Properties.Settings.Default.ChartHueEvenMin;

if (Properties.Settings.Default.HighlightEvenOdd)
{
defaultSettings[s].LevelGraphRepresentationOdd = new LevelGraphRepresentation
{
LowerColor = Utils.ColorFromHue(Properties.Settings.Default.ChartHueOddMin),
UpperColor = Utils.ColorFromHue(Properties.Settings.Default.ChartHueOddMax),
ColorGradientReversed = Properties.Settings.Default.ChartHueOddMax < Properties.Settings.Default.ChartHueOddMin,
};
defaultSettings[s].UseDifferentColorsForOddLevels = true;
}
}

Properties.Settings.Default.ChartHueEvenMax = int.MaxValue;
}
// end of level color settings conversion

// Load column-widths, display-indices and sort-order of the TimerControlListView
LoadListViewSettings(timerList1.ListViewTimers, nameof(Properties.Settings.Default.TCLVColumnWidths),
nameof(Properties.Settings.Default.TCLVColumnDisplayIndices),
Expand Down
4 changes: 2 additions & 2 deletions ARKBreedingStats/Form1.extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ private void SetCreatureValuesToExtractor(CreatureValues cv, bool setInfoInput =
}
else if (cv.motherArkId != 0)
{
cv.Mother = new Creature(cv.motherArkId);
cv.Mother = new Creature(cv.motherArkId, cv.Species);
_creatureCollection.creatures.Add(cv.Mother);
}
}
Expand All @@ -1296,7 +1296,7 @@ private void SetCreatureValuesToExtractor(CreatureValues cv, bool setInfoInput =
}
else if (cv.fatherArkId != 0)
{
cv.Father = new Creature(cv.fatherArkId);
cv.Father = new Creature(cv.fatherArkId, cv.Species);
_creatureCollection.creatures.Add(cv.Father);
}
}
Expand Down
3 changes: 2 additions & 1 deletion ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ private void CalculateTopStats(List<Creature> creatures, Species onlySpecies = n
var considerTopStats = new Dictionary<Species, bool[]>();
foreach (Creature c in creatures)
{
if (c.Species == null) continue;
if (c.Species == null || c.flags.HasFlag(CreatureFlags.Placeholder))
continue;
if (!considerTopStats.TryGetValue(c.Species, out var consideredTopStats))
{
consideredTopStats = StatsTopStats.GetStatsOptions(c.Species).StatOptions.Select(si => si.ConsiderStat).ToArray();
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.63.0.1")]
[assembly: AssemblyFileVersion("0.63.1.0")]
[assembly: NeutralResourcesLanguage("en")]

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Forms;
using System;
using System.Windows.Forms;

namespace ARKBreedingStats.StatsOptions.LevelColorSettings
{
Expand All @@ -15,22 +16,52 @@ protected override void InitializeStatControls()
{
var c = new StatLevelGraphOptionsControl($"[{si}] {Utils.StatName(si, true)}", si, Tt);
_statOptionsControls[si] = c;
StatsContainer.Controls.Add(c);
StatsContainer.SetFlowBreak(c, true);
AddWithFlowBreak(c);
}
StatsContainer.Controls.Add(new Label

AddWithFlowBreak(new Label
{
Text = @"Drag color gradient with mouse for fast editing.
On color gradients use shift + right click to copy and shift + left click to paste color settings.
Ctrl + left click to cycle through presets.",
AutoSize = true
});

var btReset = new Button { Text = "Reset all stats to default colors and ranges", AutoSize = true };
btReset.Click += ResetCurrentSettingsToDefault;
AddWithFlowBreak(btReset);

return;

void AddWithFlowBreak(Control c)
{
StatsContainer.Controls.Add(c);
StatsContainer.SetFlowBreak(c, true);
}
}

protected override void UpdateStatsControls(bool isNotRoot)
{
for (var si = 0; si < Stats.StatsCount; si++)
_statOptionsControls[si].SetStatOptions(SelectedStatsOptions.StatOptions?[si], isNotRoot, SelectedStatsOptions.ParentOptions);
}

private void ResetCurrentSettingsToDefault(object sender, EventArgs e)
{
if (SelectedStatsOptions == null) return;
if (SelectedStatsOptions.StatOptions == null)
SelectedStatsOptions.StatOptions = new StatLevelColors[Stats.StatsCount];

var isNotRoot = !string.IsNullOrEmpty(SelectedStatsOptions.Name);
for (var si = 0; si < Stats.StatsCount; si++)
{
SelectedStatsOptions.StatOptions[si] = new StatLevelColors
{
LevelGraphRepresentation = LevelGraphRepresentation.GetDefaultValue,
LevelGraphRepresentationMutation = LevelGraphRepresentation.GetDefaultMutationLevelValue
};
_statOptionsControls[si].SetStatOptions(SelectedStatsOptions.StatOptions[si], isNotRoot, SelectedStatsOptions.ParentOptions);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public StatLevelGraphOptionsControl(string name, int statIndex, ToolTip tt) : th
_statIndex = statIndex;
hueControl.UpdateTooltips(tt);
hueControlOdd.UpdateTooltips(tt);
tt.SetToolTip(CbUseDifferentColorsForOddLevels, "Use different colors for odd levels");
tt.SetToolTip(CbUseDifferentColorsForOddLevels, "Use different colors for odd wild levels");
tt.SetToolTip(CbUseDifferentColorsForMutationLevels, "Use different colors for mutation levels");
}

Expand All @@ -33,7 +33,7 @@ public void SetStatOptions(StatLevelColors so, bool isNotRoot, StatsOptions<Stat
hueControl.SetValues(so?.LevelGraphRepresentation);
hueControlOdd.SetValues(so?.LevelGraphRepresentationOdd);
HueControlMutations.SetValues(so?.LevelGraphRepresentationMutation);
CbOverrideGraphSettings.Checked = so?.OverrideParent == true;
CbOverrideGraphSettings.Checked = !isNotRoot || so?.OverrideParent == true;
CbOverrideGraphSettings.Visible = isNotRoot;
}

Expand Down
10 changes: 10 additions & 0 deletions ARKBreedingStats/StatsOptions/StatsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public class StatsOptions<T> where T : StatOptionsBase
[JsonProperty]
public T[] StatOptions;

/// <summary>
/// List of species these settings are valid.
/// Possible values are the blueprint path and shorter defined names, e.g. Species.name, Species.DescriptiveName.
/// </summary>
[JsonProperty("sp", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string[] AffectedSpecies;

/// <summary>
/// Used for UI layout.
/// </summary>
public int HierarchyLevel;
}
}
60 changes: 59 additions & 1 deletion ARKBreedingStats/StatsOptions/StatsOptionsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ internal class StatsOptionsControl<T> : TableLayoutPanel where T : StatOptionsBa
protected Button BtRemove;
protected TextBox TbOptionsName;
protected Label LbParent;
protected Label LbParentParent;
protected Label LbAffectedSpecies;
protected StatsOptions<T> SelectedStatsOptions;
protected StatsOptionsSettings<T> StatsOptionsSettings;
protected TextBox TbAffectedSpecies;
protected FlowLayoutPanel StatsContainer;
protected ToolTip Tt;
private bool _ignoreIndexChange;
Expand Down Expand Up @@ -74,6 +77,22 @@ protected void InitializeControls(StatsOptionsSettings<T> settings, ToolTip tt)
CbbParent.SelectedIndexChanged += CbbParent_SelectedIndexChanged;
flpHeaderControls.Controls.Add(CbbParent);

var marginLabelDefault = new Padding(5, 7, 5, 0);

LbParentParent = new Label { Margin = marginLabelDefault, AutoSize = true };
tt.SetToolTip(LbParentParent, "If the parent setting has no value for a stat, the parent's parent's values are used etc.");
flpHeaderControls.Controls.Add(LbParentParent);
flpHeaderControls.SetFlowBreak(LbParentParent, true);

LbAffectedSpecies = new Label { Text = "Affected species: ", Margin = marginLabelDefault, AutoSize = true };
tt.SetToolTip(LbAffectedSpecies, @"Comma separated list of species affected by this setting.
More specific identifier will be used first. Specificity order is
BlueprintPath > DescriptiveNameAndMod > DescriptiveName > Name");
flpHeaderControls.Controls.Add(LbAffectedSpecies);
TbAffectedSpecies = new TextBox { AutoSize = true, MinimumSize = new Size(50, 0) };
flpHeaderControls.Controls.Add(TbAffectedSpecies);
TbAffectedSpecies.Leave += TbAffectedSpeciesLeave;

InitializeStatControls();
InitializeOptions();
}
Expand Down Expand Up @@ -150,13 +169,47 @@ private void CbbOptions_SelectedIndexChanged(object sender, EventArgs e)
LbParent.Visible = isNotRoot;
CbbParent.Visible = isNotRoot;
BtRemove.Visible = isNotRoot;
LbParentParent.Text = ParentsParentText(SelectedStatsOptions.ParentOptions);
LbAffectedSpecies.Visible = isNotRoot;
TbAffectedSpecies.Visible = isNotRoot;
TbAffectedSpecies.Text = SelectedStatsOptions.AffectedSpecies == null ? string.Empty : string.Join(", ", SelectedStatsOptions.AffectedSpecies);

UpdateStatsControls(isNotRoot);

CbbParent.SelectedItem = SelectedStatsOptions.ParentOptions;
this.ResumeDrawing();
}

private void TbAffectedSpeciesLeave(object sender, EventArgs e)
{
if (SelectedStatsOptions == null) return;
var sp = TbAffectedSpecies.Text
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s))
.Distinct()
.ToArray();
SelectedStatsOptions.AffectedSpecies = sp.Any() ? sp : null;
}

private string ParentsParentText(StatsOptions<T> selectedStatsOptions)
{
var maxGenerationsShown = 5;
var currentParent = selectedStatsOptions?.ParentOptions;
var parentText = string.Empty;
while (currentParent != null)
{
if (maxGenerationsShown-- <= 0)
{
parentText += " \u2794";
break;
}
parentText += " \u2794 " + (string.IsNullOrEmpty(currentParent.Name) ? currentParent.ToString() : currentParent.Name);
currentParent = currentParent.ParentOptions;
}

return parentText;
}

/// <summary>
/// Override this method to update the UI of the stat controls.
/// </summary>
Expand All @@ -167,7 +220,9 @@ private void CbbParent_SelectedIndexChanged(object sender, EventArgs e)
if (_ignoreIndexChange) return;
SelectedStatsOptions = CbbOptions.SelectedItem as StatsOptions<T>;
if (SelectedStatsOptions == null) return;
SelectedStatsOptions.ParentOptions = CbbParent.SelectedItem as StatsOptions<T>;
var selectedParent = CbbParent.SelectedItem as StatsOptions<T>;
if (SelectedStatsOptions == selectedParent) return; // ignore if node itself is selected as parent
SelectedStatsOptions.ParentOptions = selectedParent;
InitializeOptions(true);
StatsOptionsSettings.ClearSpeciesCache();
}
Expand All @@ -187,6 +242,9 @@ private void TbOptionsName_Leave(object sender, EventArgs e)
StatsOptionsSettings.StatsOptionsDict.Add(newName, SelectedStatsOptions);
// update text in combobox
CbbOptions.Items[CbbOptions.SelectedIndex] = SelectedStatsOptions;
var cbbParentIndex = CbbParent.Items.IndexOf(SelectedStatsOptions);
if (cbbParentIndex >= 0)
CbbParent.Items[cbbParentIndex] = SelectedStatsOptions;
StatsOptionsSettings.ClearSpeciesCache();
}

Expand Down
18 changes: 13 additions & 5 deletions ARKBreedingStats/StatsOptions/StatsOptionsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ARKBreedingStats.StatsOptions
{
/// <summary>
/// Base access to stats options.
/// Base access to all stats options of one kind, e.g. all level color options.
/// </summary>
/// <typeparam name="T"></typeparam>
public class StatsOptionsSettings<T> where T : StatOptionsBase
Expand Down Expand Up @@ -150,10 +150,18 @@ public StatsOptions<T> GetStatsOptions(Species species)
if (_cache.TryGetValue(species.blueprintPath, out var o)) return o;

StatsOptions<T> speciesStatsOptions;
if (StatsOptionsDict.TryGetValue(species.blueprintPath, out o)
|| StatsOptionsDict.TryGetValue(species.DescriptiveNameAndMod, out o)
|| StatsOptionsDict.TryGetValue(species.DescriptiveName, out o)
|| StatsOptionsDict.TryGetValue(species.name, out o))

var dict = new Dictionary<string, StatsOptions<T>>();
var list = StatsOptionsDict
.Where(kv => kv.Value.AffectedSpecies != null)
.SelectMany(kv => kv.Value.AffectedSpecies.Select(sp => (sp, kv.Value)));
foreach (var sp in list)
dict[sp.sp] = sp.Value;

if (dict.TryGetValue(species.blueprintPath, out o)
|| dict.TryGetValue(species.DescriptiveNameAndMod, out o)
|| dict.TryGetValue(species.DescriptiveName, out o)
|| dict.TryGetValue(species.name, out o))
{
speciesStatsOptions = GenerateStatsOptions(o);
}
Expand Down
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.63.0.1"
"version": "0.63.1.0"
},
"SpeciesColorImages": {
"Id": "SpeciesColorImages",
Expand Down
3 changes: 2 additions & 1 deletion ARKBreedingStats/library/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ public Species Species
/// Creates a placeholder creature with the given ArkId, which have to be imported
/// </summary>
/// <param name="arkId">ArkId from an imported source (no user input)</param>
public Creature(long arkId)
public Creature(long arkId, Species species)
{
ArkId = arkId;
ArkIdImported = true;
guid = Utils.ConvertArkIdToGuid(arkId);
Species = species;
flags = CreatureFlags.Placeholder;
}

Expand Down

0 comments on commit b77c803

Please sign in to comment.