Skip to content

Commit

Permalink
Stats options now use a csv list to accept multiple species
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Sep 9, 2024
1 parent 5746df0 commit 053fff9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 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
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;
}
}
30 changes: 29 additions & 1 deletion ARKBreedingStats/StatsOptions/StatsOptionsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ internal class StatsOptionsControl<T> : TableLayoutPanel where T : StatOptionsBa
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 @@ -75,9 +77,21 @@ protected void InitializeControls(StatsOptionsSettings<T> settings, ToolTip tt)
CbbParent.SelectedIndexChanged += CbbParent_SelectedIndexChanged;
flpHeaderControls.Controls.Add(CbbParent);

LbParentParent = new Label { Margin = new Padding(5, 7, 5, 0), AutoSize = true };
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 @@ -156,13 +170,27 @@ private void CbbOptions_SelectedIndexChanged(object sender, EventArgs e)
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;
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

0 comments on commit 053fff9

Please sign in to comment.