Skip to content

Commit

Permalink
dye colors can appear on creatures with mutations, added these to the…
Browse files Browse the repository at this point in the history
… possible creature colors.
  • Loading branch information
cadaei committed Dec 24, 2019
1 parent b5ef9e5 commit 2208f4b
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 96 deletions.
55 changes: 31 additions & 24 deletions ARKBreedingStats/species/ARKColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ namespace ARKBreedingStats.species
{
public class ARKColors
{
public Dictionary<int, ARKColor> colorsByHash;
public Dictionary<string, ARKColor> colorsByName;
public List<ARKColor> colorsList;
private Dictionary<int, ARKColor> colorsByHash;
private Dictionary<string, ARKColor> colorsByName;
public readonly List<ARKColor> colorsList;
private Dictionary<int, ARKColor> colorsById;

public ARKColors(List<List<object>> colorDefinitions)
public ARKColors(List<List<object>> colorDefinitions, List<List<object>> colorDefinitions2 = null)
{
colorsByHash = new Dictionary<int, ARKColor>();
colorsByName = new Dictionary<string, ARKColor>();
Expand All @@ -20,39 +21,45 @@ public ARKColors(List<List<object>> colorDefinitions)

if (colorDefinitions == null) return;

int id = 1;
ParseColors(colorDefinitions, 1);
if (colorDefinitions2 != null)
ParseColors(colorDefinitions2, 200); // dye colors can appear as color mutation, they start with id 200

foreach (List<object> cd in colorDefinitions)
void ParseColors(List<List<object>> colorDefs, int idStart)
{

var t = cd[0].GetType();
var tt = cd[1].GetType();

if (cd.Count == 2
&& cd[0] is string colorName
&& cd[1] is Newtonsoft.Json.Linq.JArray colorValues)
foreach (List<object> cd in colorDefs)
{
ARKColor ac = new ARKColor(colorName,
new double[] {
var t = cd[0].GetType();
var tt = cd[1].GetType();

if (cd.Count == 2
&& cd[0] is string colorName
&& cd[1] is Newtonsoft.Json.Linq.JArray colorValues)
{
ARKColor ac = new ARKColor(colorName,
new double[] {
(double)colorValues[0],
(double)colorValues[1],
(double)colorValues[2],
(double)colorValues[3],
})
{ id = id++ };
if (!colorsByHash.ContainsKey(ac.hash))
colorsByHash.Add(ac.hash, ac);
if (!colorsByName.ContainsKey(ac.name))
colorsByName.Add(ac.name, ac);
colorsList.Add(ac);
})
{ id = idStart };
if (!colorsByHash.ContainsKey(ac.hash))
colorsByHash.Add(ac.hash, ac);
if (!colorsByName.ContainsKey(ac.name))
colorsByName.Add(ac.name, ac);
colorsList.Add(ac);
}
idStart++;
}
}
colorsById = colorsList.ToDictionary(c => c.id, c => c);
}

public ARKColor ByID(int id)
{
if (id > 0 && id < colorsList.Count)
return colorsList[id];
if (colorsById.ContainsKey(id))
return colorsById[id];
return new ARKColor();
}

Expand Down
71 changes: 45 additions & 26 deletions ARKBreedingStats/uiControls/MyColorPicker.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 41 additions & 35 deletions ARKBreedingStats/uiControls/MyColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ namespace ARKBreedingStats.uiControls
{
public partial class MyColorPicker : Form
{
private readonly List<Panel> panels = new List<Panel>();
private int regionId;
private int[] creatureColors;
private List<int> naturalColorIDs;
public bool isShown;
private readonly ToolTip tt = new ToolTip();
private readonly ToolTip tt;

public MyColorPicker()
{
InitializeComponent();
tt = new ToolTip { AutomaticDelay = 200 };
Disposed += MyColorPicker_Disposed;
}

private void MyColorPicker_Disposed(object sender, EventArgs e)
{
tt.RemoveAll();
}

public void SetColors(int[] creatureColors, int regionId, string name, List<ARKColor> naturalColors = null)
Expand All @@ -29,47 +35,42 @@ public void SetColors(int[] creatureColors, int regionId, string name, List<ARKC

this.creatureColors = creatureColors;
this.naturalColorIDs = naturalColors?.Select(ac => ac.id).ToList();
SuspendLayout();
// clear unused panels
if (panels.Count - colors.Count > 0)
{
List<Panel> rm = panels.Skip(colors.Count).ToList();
foreach (Panel p in rm)
p.Dispose();
panels.RemoveRange(colors.Count, panels.Count - colors.Count);
}

flowLayoutPanel1.SuspendLayout();

for (int c = 0; c < colors.Count; c++)
{
if (panels.Count <= c)
if (flowLayoutPanel1.Controls.Count <= c)
{
Panel p = new Panel
Panel np = new Panel
{
Width = 40,
Height = 20,
Location = new Point(5 + (c % 8) * 45, 25 + (c / 8) * 25)
Height = 20
};
p.Click += ColorChoosen;
panel1.Controls.Add(p);
panels.Add(p);
np.Click += ColorChoosen;
flowLayoutPanel1.Controls.Add(np);
}
panels[c].BackColor = colors[c].color;
panels[c].BorderStyle = (creatureColors[regionId] == c ? BorderStyle.Fixed3D : BorderStyle.None);
panels[c].Visible = (!checkBoxOnlyNatural.Checked || naturalColorIDs == null || naturalColorIDs.Count == 0 || naturalColorIDs.Contains(c));
tt.SetToolTip(panels[c], c + ": " + species.CreatureColors.creatureColorName(c));
Panel p = flowLayoutPanel1.Controls[c] as Panel;
p.BackColor = colors[c].color;
p.Tag = colors[c].id;
p.BorderStyle = creatureColors[regionId] == c ? BorderStyle.Fixed3D : BorderStyle.None;
p.Visible = ColorPossible(colors[c].id);
tt.SetToolTip(p, colors[c].id + ": " + colors[c].name);
}
ResumeLayout();

flowLayoutPanel1.ResumeLayout();
isShown = true;
}

private bool ColorPossible(int id) => !checkBoxOnlyNatural.Checked || naturalColorIDs == null || naturalColorIDs.Count == 0 || naturalColorIDs.Contains(id);

private void ColorChoosen(object sender, EventArgs e)
{
// store selected color-id in creature-array and close this window
int i = panels.IndexOf((Panel)sender);
int i = (int)((Panel)sender).Tag;
if (i >= 0)
creatureColors[regionId] = i;
isShown = false;
DialogResult = DialogResult.OK;
HideWindow(true);
}

private void MyColorPicker_Load(object sender, EventArgs e)
Expand All @@ -79,32 +80,37 @@ private void MyColorPicker_Load(object sender, EventArgs e)
SetDesktopLocation(Cursor.Position.X - 20, y);
}

private void panel1_MouseLeave(object sender, EventArgs e)
private void MyColorPicker_MouseLeave(object sender, EventArgs e)
{
// mouse left, close
if (!panel1.ClientRectangle.Contains(PointToClient(MousePosition)) || PointToClient(MousePosition).X == 0 || PointToClient(MousePosition).Y == 0)
if (!ClientRectangle.Contains(PointToClient(MousePosition)) || PointToClient(MousePosition).X == 0 || PointToClient(MousePosition).Y == 0)
{
isShown = false;
DialogResult = DialogResult.Cancel;
HideWindow(false);
}
}

private void MyColorPicker_Leave(object sender, EventArgs e)
{
isShown = false;
DialogResult = DialogResult.Cancel;
HideWindow(false);
}

private void button1_Click(object sender, EventArgs e)
{
HideWindow(false);
}

private void HideWindow(bool ok)
{
isShown = false;
DialogResult = DialogResult.Cancel;
DialogResult = ok ? DialogResult.OK : DialogResult.Cancel;
}

private void checkBoxOnlyNatural_CheckedChanged(object sender, EventArgs e)
{
for (int c = 0; c < panels.Count; c++)
panels[c].Visible = (!checkBoxOnlyNatural.Checked || naturalColorIDs == null || naturalColorIDs.Count == 0 || naturalColorIDs.Contains(c));
flowLayoutPanel1.SuspendLayout();
for (int c = 0; c < flowLayoutPanel1.Controls.Count; c++)
flowLayoutPanel1.Controls[c].Visible = ColorPossible((int)flowLayoutPanel1.Controls[c].Tag);
flowLayoutPanel1.ResumeLayout();
}
}
}
Loading

0 comments on commit 2208f4b

Please sign in to comment.