diff --git a/ARKBreedingStats/species/ARKColors.cs b/ARKBreedingStats/species/ARKColors.cs index a7c79aab..a92739dd 100644 --- a/ARKBreedingStats/species/ARKColors.cs +++ b/ARKBreedingStats/species/ARKColors.cs @@ -6,11 +6,12 @@ namespace ARKBreedingStats.species { public class ARKColors { - public Dictionary colorsByHash; - public Dictionary colorsByName; - public List colorsList; + private Dictionary colorsByHash; + private Dictionary colorsByName; + public readonly List colorsList; + private Dictionary colorsById; - public ARKColors(List> colorDefinitions) + public ARKColors(List> colorDefinitions, List> colorDefinitions2 = null) { colorsByHash = new Dictionary(); colorsByName = new Dictionary(); @@ -20,39 +21,45 @@ public ARKColors(List> 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 cd in colorDefinitions) + void ParseColors(List> 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 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(); } diff --git a/ARKBreedingStats/uiControls/MyColorPicker.Designer.cs b/ARKBreedingStats/uiControls/MyColorPicker.Designer.cs index e631216e..c0f67bb0 100644 --- a/ARKBreedingStats/uiControls/MyColorPicker.Designer.cs +++ b/ARKBreedingStats/uiControls/MyColorPicker.Designer.cs @@ -28,33 +28,21 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.panel1 = new System.Windows.Forms.Panel(); this.checkBoxOnlyNatural = new System.Windows.Forms.CheckBox(); this.label1 = new System.Windows.Forms.Label(); this.buttonCancel = new System.Windows.Forms.Button(); - this.panel1.SuspendLayout(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // - // panel1 - // - this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.panel1.Controls.Add(this.checkBoxOnlyNatural); - this.panel1.Controls.Add(this.label1); - this.panel1.Controls.Add(this.buttonCancel); - this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel1.Location = new System.Drawing.Point(0, 0); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(367, 260); - this.panel1.TabIndex = 0; - this.panel1.MouseLeave += new System.EventHandler(this.panel1_MouseLeave); - // // checkBoxOnlyNatural // this.checkBoxOnlyNatural.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxOnlyNatural.AutoSize = true; this.checkBoxOnlyNatural.Checked = true; this.checkBoxOnlyNatural.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBoxOnlyNatural.Location = new System.Drawing.Point(11, 236); + this.checkBoxOnlyNatural.Location = new System.Drawing.Point(3, 334); this.checkBoxOnlyNatural.Name = "checkBoxOnlyNatural"; this.checkBoxOnlyNatural.Size = new System.Drawing.Size(154, 17); this.checkBoxOnlyNatural.TabIndex = 2; @@ -64,11 +52,12 @@ private void InitializeComponent() // // label1 // - this.label1.Dock = System.Windows.Forms.DockStyle.Top; + this.tableLayoutPanel1.SetColumnSpan(this.label1, 2); + this.label1.Dock = System.Windows.Forms.DockStyle.Fill; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Location = new System.Drawing.Point(3, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(365, 20); + this.label1.Size = new System.Drawing.Size(414, 30); this.label1.TabIndex = 1; this.label1.Text = "title"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -77,7 +66,7 @@ private void InitializeComponent() // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(287, 232); + this.buttonCancel.Location = new System.Drawing.Point(342, 328); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 0; @@ -85,29 +74,59 @@ private void InitializeComponent() this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.button1_Click); // + // flowLayoutPanel1 + // + this.tableLayoutPanel1.SetColumnSpan(this.flowLayoutPanel1, 2); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 33); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(414, 288); + this.flowLayoutPanel1.TabIndex = 3; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.checkBoxOnlyNatural, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.buttonCancel, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(8, 8); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(420, 354); + this.tableLayoutPanel1.TabIndex = 1; + // // MyColorPicker // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(367, 260); - this.Controls.Add(this.panel1); + this.ClientSize = new System.Drawing.Size(436, 370); + this.Controls.Add(this.tableLayoutPanel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "MyColorPicker"; + this.Padding = new System.Windows.Forms.Padding(8); this.ShowInTaskbar = false; this.Load += new System.EventHandler(this.MyColorPicker_Load); this.Leave += new System.EventHandler(this.MyColorPicker_Leave); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); + this.MouseLeave += new System.EventHandler(this.MyColorPicker_MouseLeave); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.Label label1; private System.Windows.Forms.CheckBox checkBoxOnlyNatural; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; } } \ No newline at end of file diff --git a/ARKBreedingStats/uiControls/MyColorPicker.cs b/ARKBreedingStats/uiControls/MyColorPicker.cs index 45484e72..66a02b28 100644 --- a/ARKBreedingStats/uiControls/MyColorPicker.cs +++ b/ARKBreedingStats/uiControls/MyColorPicker.cs @@ -9,16 +9,22 @@ namespace ARKBreedingStats.uiControls { public partial class MyColorPicker : Form { - private readonly List panels = new List(); private int regionId; private int[] creatureColors; private List 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 naturalColors = null) @@ -29,47 +35,42 @@ public void SetColors(int[] creatureColors, int regionId, string name, List ac.id).ToList(); - SuspendLayout(); - // clear unused panels - if (panels.Count - colors.Count > 0) - { - List 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) @@ -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(); } } } diff --git a/ARKBreedingStats/values/Values.cs b/ARKBreedingStats/values/Values.cs index 296664b9..db05b465 100644 --- a/ARKBreedingStats/values/Values.cs +++ b/ARKBreedingStats/values/Values.cs @@ -13,7 +13,7 @@ namespace ARKBreedingStats.values { - [DataContract] + [JsonObject(MemberSerialization.OptIn)] public class Values { public const int STATS_COUNT = 12; @@ -21,20 +21,20 @@ public class Values private static Values _V; - [DataMember] + [JsonProperty] private string version = "0.0"; /// /// Must be present and a supported value. Defaults to an invalid value /// - [DataMember] + [JsonProperty] private string format = string.Empty; public Version Version = new Version(0, 0); public Version modVersion = new Version(0, 0); - [DataMember] + [JsonProperty] public List species = new List(); - [DataMember] + [JsonProperty] public List> colorDefinitions; - [DataMember] + [JsonProperty] public List> dyeDefinitions; public ARKColors Colors; @@ -74,14 +74,13 @@ public class Values /// /// If this represents values for a mod, the mod-infos are found here. /// - [DataMember] + [JsonProperty] public Mod mod; /// /// Contains all species-classes that should be ignored when importing a savegame. /// This is e.g. used to filter out rafts which are species in ARK. /// - [IgnoreDataMember] private List ignoreSpeciesClassesOnImport; /// @@ -339,14 +338,12 @@ private void ParseVersion(StreamingContext ct) if (!Version.TryParse(version, out Version)) Version = new Version(0, 0); - Colors = new ARKColors(colorDefinitions); + Colors = new ARKColors(colorDefinitions, dyeDefinitions); Dyes = new ARKColors(dyeDefinitions); foreach (var s in species) s.InitializeColors(Colors); - return; - //// for debugging, test if there are duplicates in the species-names //var duplicateSpeciesNames = string.Join("\n", species // //.GroupBy(s => s.DescriptiveName)