From 90d122289f19653ff252963a77f673a809a588cc Mon Sep 17 00:00:00 2001 From: tobitege Date: Sun, 28 Aug 2022 17:12:06 +0200 Subject: [PATCH] v0.640 byproducts as links --- DU Industry Tool/AboutForm.Designer.cs | 121 ++++++++----- DU Industry Tool/AboutForm.cs | 6 +- DU Industry Tool/AboutForm.resx | 3 - DU Industry Tool/IndustryManager.cs | 11 +- DU Industry Tool/MainForm.cs | 242 +++++++++---------------- 5 files changed, 175 insertions(+), 208 deletions(-) diff --git a/DU Industry Tool/AboutForm.Designer.cs b/DU Industry Tool/AboutForm.Designer.cs index e97f4e5..37c7f5d 100644 --- a/DU Industry Tool/AboutForm.Designer.cs +++ b/DU Industry Tool/AboutForm.Designer.cs @@ -32,12 +32,14 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm)); this.panelLeft = new ComponentFactory.Krypton.Toolkit.KryptonPanel(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.githubLink = new ComponentFactory.Krypton.Toolkit.KryptonLinkLabel(); + this.TobiReleasesLink = new ComponentFactory.Krypton.Toolkit.KryptonLinkLabel(); this.kryptonLabel1 = new ComponentFactory.Krypton.Toolkit.KryptonLabel(); this.kryptonLabel2 = new ComponentFactory.Krypton.Toolkit.KryptonLabel(); this.discordLink = new ComponentFactory.Krypton.Toolkit.KryptonLinkLabel(); - this.kryptonButton1 = new ComponentFactory.Krypton.Toolkit.KryptonButton(); - this.kryptonLabel3 = new ComponentFactory.Krypton.Toolkit.KryptonLabel(); + this.OkButton = new ComponentFactory.Krypton.Toolkit.KryptonButton(); + this.labelMain = new ComponentFactory.Krypton.Toolkit.KryptonLabel(); + this.kryptonLabel4 = new ComponentFactory.Krypton.Toolkit.KryptonLabel(); + this.DimenciaGithubLink = new ComponentFactory.Krypton.Toolkit.KryptonLinkLabel(); ((System.ComponentModel.ISupportInitialize)(this.panelLeft)).BeginInit(); this.panelLeft.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); @@ -50,7 +52,7 @@ private void InitializeComponent() this.panelLeft.Location = new System.Drawing.Point(0, 0); this.panelLeft.Name = "panelLeft"; this.panelLeft.PanelBackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.FormMain; - this.panelLeft.Size = new System.Drawing.Size(90, 293); + this.panelLeft.Size = new System.Drawing.Size(90, 415); this.panelLeft.TabIndex = 0; // // pictureBox1 @@ -60,31 +62,34 @@ private void InitializeComponent() this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Margin = new System.Windows.Forms.Padding(0); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Padding = new System.Windows.Forms.Padding(13, 12, 13, 12); - this.pictureBox1.Size = new System.Drawing.Size(90, 293); + this.pictureBox1.Padding = new System.Windows.Forms.Padding(13, 13, 13, 13); + this.pictureBox1.Size = new System.Drawing.Size(90, 415); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // - // githubLink + // TobiReleasesLink // - this.githubLink.Location = new System.Drawing.Point(120, 216); - this.githubLink.Name = "githubLink"; - this.githubLink.Size = new System.Drawing.Size(388, 24); - this.githubLink.TabIndex = 2; - this.githubLink.Values.Text = "https://github.com/tobitege/DU-Industry-Tool/releases"; + this.TobiReleasesLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.TobiReleasesLink.Location = new System.Drawing.Point(99, 317); + this.TobiReleasesLink.Name = "TobiReleasesLink"; + this.TobiReleasesLink.Size = new System.Drawing.Size(388, 24); + this.TobiReleasesLink.TabIndex = 2; + this.TobiReleasesLink.Values.Text = "https://github.com/tobitege/DU-Industry-Tool/releases"; // // kryptonLabel1 // - this.kryptonLabel1.Location = new System.Drawing.Point(120, 195); + this.kryptonLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.kryptonLabel1.Location = new System.Drawing.Point(99, 297); this.kryptonLabel1.Name = "kryptonLabel1"; - this.kryptonLabel1.Size = new System.Drawing.Size(193, 24); + this.kryptonLabel1.Size = new System.Drawing.Size(285, 24); this.kryptonLabel1.TabIndex = 3; - this.kryptonLabel1.Values.Text = "Github repository releases:"; + this.kryptonLabel1.Values.Text = "Tobi\'s binary releases v0.500+ (Github)s:"; // // kryptonLabel2 // - this.kryptonLabel2.Location = new System.Drawing.Point(120, 135); + this.kryptonLabel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.kryptonLabel2.Location = new System.Drawing.Point(99, 173); this.kryptonLabel2.Name = "kryptonLabel2"; this.kryptonLabel2.Size = new System.Drawing.Size(306, 24); this.kryptonLabel2.TabIndex = 4; @@ -92,46 +97,68 @@ private void InitializeComponent() // // discordLink // - this.discordLink.Location = new System.Drawing.Point(120, 154); + this.discordLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.discordLink.Location = new System.Drawing.Point(99, 199); this.discordLink.Name = "discordLink"; this.discordLink.Size = new System.Drawing.Size(211, 24); this.discordLink.TabIndex = 5; this.discordLink.Values.Text = "https://discord.gg/7psYcmAb"; // - // kryptonButton1 - // - this.kryptonButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.kryptonButton1.AutoSize = true; - this.kryptonButton1.DialogResult = System.Windows.Forms.DialogResult.OK; - this.kryptonButton1.Location = new System.Drawing.Point(236, 252); - this.kryptonButton1.Name = "kryptonButton1"; - this.kryptonButton1.Size = new System.Drawing.Size(95, 29); - this.kryptonButton1.TabIndex = 0; - this.kryptonButton1.Values.Text = "Ok"; - // - // kryptonLabel3 - // - this.kryptonLabel3.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.BoldControl; - this.kryptonLabel3.Location = new System.Drawing.Point(120, 16); - this.kryptonLabel3.Name = "kryptonLabel3"; - this.kryptonLabel3.Size = new System.Drawing.Size(366, 104); - this.kryptonLabel3.TabIndex = 7; - this.kryptonLabel3.Values.Text = "DU Industry Tool v0.640\r\nA tool to find cost for elements in Dual Universe.\r\n\r\nCr" + + // OkButton + // + this.OkButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.OkButton.AutoSize = true; + this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.OkButton.Location = new System.Drawing.Point(276, 371); + this.OkButton.Name = "OkButton"; + this.OkButton.Size = new System.Drawing.Size(95, 32); + this.OkButton.TabIndex = 0; + this.OkButton.Values.Text = "Ok"; + // + // labelMain + // + this.labelMain.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.TitleControl; + this.labelMain.Location = new System.Drawing.Point(96, 12); + this.labelMain.Name = "labelMain"; + this.labelMain.Size = new System.Drawing.Size(545, 155); + this.labelMain.TabIndex = 7; + this.labelMain.Values.Text = "DU Industry Tool v0.640\r\nA tool to find cost for elements in Dual Universe.\r\n\r\nCr" + "eated by Dimencia (2020-2021)\r\nContributor: tobitege (2022)\r\n"; + // + // kryptonLabel4 + // + this.kryptonLabel4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.kryptonLabel4.Location = new System.Drawing.Point(99, 245); + this.kryptonLabel4.Name = "kryptonLabel4"; + this.kryptonLabel4.Size = new System.Drawing.Size(272, 24); + this.kryptonLabel4.TabIndex = 8; + this.kryptonLabel4.Values.Text = "Dimencia\'s master repository (Github):"; + // + // DimenciaGithubLink + // + this.DimenciaGithubLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.DimenciaGithubLink.Location = new System.Drawing.Point(99, 267); + this.DimenciaGithubLink.Name = "DimenciaGithubLink"; + this.DimenciaGithubLink.Size = new System.Drawing.Size(334, 24); + this.DimenciaGithubLink.TabIndex = 9; + this.DimenciaGithubLink.Values.Text = "https://github.com/Dimencia/DU-Industry-Tool"; // // AboutForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(532, 293); - this.Controls.Add(this.kryptonLabel3); - this.Controls.Add(this.kryptonButton1); + this.AcceptButton = this.OkButton; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.ClientSize = new System.Drawing.Size(637, 415); + this.Controls.Add(this.DimenciaGithubLink); + this.Controls.Add(this.kryptonLabel4); + this.Controls.Add(this.labelMain); + this.Controls.Add(this.OkButton); this.Controls.Add(this.discordLink); this.Controls.Add(this.kryptonLabel2); this.Controls.Add(this.kryptonLabel1); - this.Controls.Add(this.githubLink); + this.Controls.Add(this.TobiReleasesLink); this.Controls.Add(this.panelLeft); - this.Font = new System.Drawing.Font("Verdana", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.DoubleBuffered = true; + this.Font = new System.Drawing.Font("Verdana", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "AboutForm"; @@ -150,11 +177,13 @@ private void InitializeComponent() private ComponentFactory.Krypton.Toolkit.KryptonPanel panelLeft; private System.Windows.Forms.PictureBox pictureBox1; - private ComponentFactory.Krypton.Toolkit.KryptonLinkLabel githubLink; + private ComponentFactory.Krypton.Toolkit.KryptonLinkLabel TobiReleasesLink; private ComponentFactory.Krypton.Toolkit.KryptonLabel kryptonLabel1; private ComponentFactory.Krypton.Toolkit.KryptonLabel kryptonLabel2; private ComponentFactory.Krypton.Toolkit.KryptonLinkLabel discordLink; - private ComponentFactory.Krypton.Toolkit.KryptonButton kryptonButton1; - private ComponentFactory.Krypton.Toolkit.KryptonLabel kryptonLabel3; + private ComponentFactory.Krypton.Toolkit.KryptonButton OkButton; + private ComponentFactory.Krypton.Toolkit.KryptonLabel labelMain; + private ComponentFactory.Krypton.Toolkit.KryptonLabel kryptonLabel4; + private ComponentFactory.Krypton.Toolkit.KryptonLinkLabel DimenciaGithubLink; } } \ No newline at end of file diff --git a/DU Industry Tool/AboutForm.cs b/DU Industry Tool/AboutForm.cs index 5ae8f10..311e40a 100644 --- a/DU Industry Tool/AboutForm.cs +++ b/DU Industry Tool/AboutForm.cs @@ -16,11 +16,13 @@ public partial class AboutForm : Form public AboutForm() { InitializeComponent(); + discordLink.Click += LinkOnClick; - githubLink.Click += LinkOnClick; + DimenciaGithubLink.Click += LinkOnClick; + TobiReleasesLink.Click += LinkOnClick; } - private void LinkOnClick(object sender, EventArgs e) + private static void LinkOnClick(object sender, EventArgs e) { if (sender is KryptonLinkLabel klb) { diff --git a/DU Industry Tool/AboutForm.resx b/DU Industry Tool/AboutForm.resx index 34bb9bf..a85ca01 100644 --- a/DU Industry Tool/AboutForm.resx +++ b/DU Industry Tool/AboutForm.resx @@ -185,9 +185,6 @@ RDTh5+Sf6+hfdotWjRr/B1gyqbQxi59TAAAAAElFTkSuQmCC - - True - AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEIAAAAAAAAAAAAAAAAAAAAA diff --git a/DU Industry Tool/IndustryManager.cs b/DU Industry Tool/IndustryManager.cs index e9c4ff4..1ca77a4 100644 --- a/DU Industry Tool/IndustryManager.cs +++ b/DU Industry Tool/IndustryManager.cs @@ -960,9 +960,10 @@ public IndustryManager(ProgressBar progressBar = null) if (dmpRcp) { + /* var missingRec = _luaRecipes.Values.Where(x => x.Products?.Count > 0 && Recipes.Values.All(y => y.NqId != x.Products[0].Id)) - .OrderBy(x => x.Products[0].DisplayNameWithSize); + .OrderBy(x => x.Products[0].DisplayNameWithSize); foreach (var missing in missingRec) { Debug.WriteLine(missing.Products[0].Id.ToString().PadRight(30) + " " + @@ -970,13 +971,14 @@ public IndustryManager(ProgressBar progressBar = null) } // Check for missing Plasma in recipes' ingredients - List plasmaIds = new List { + var plasmaIds = new List { 1769135512, 1831558336, 1831557945, 1831558342, 1831558338, 1831558341, 1831558343, 1831558340, 1831558339, 1831558337 }; var plas = _luaRecipes.Values.Where(x => x.Ingredients.Count > 0 && - x.Ingredients.Any(y => plasmaIds.Contains(y.Id))).OrderBy(x => x.Products[0].DisplayNameWithSize).ToList(); + x.Ingredients.Any(y => plasmaIds.Contains(y.Id))) + .OrderBy(x => x.Products[0].DisplayNameWithSize).ToList(); foreach (var pl in plas) { var ingName = pl.Ingredients.First(x => x.DisplayNameWithSize.StartsWith("Relic Plasma")).DisplayNameWithSize; @@ -988,9 +990,10 @@ public IndustryManager(ProgressBar progressBar = null) } if (rec.Value.Ingredients.All(x => x.Name != ingName)) { - Debug.WriteLine(rec.Key + " " + rec.Value.Name + " missing " + ingName); + Debug.WriteLine(rec.Key + " " + rec.Value.Name + " is missing " + ingName); } } + */ } //SaveRecipes(); diff --git a/DU Industry Tool/MainForm.cs b/DU Industry Tool/MainForm.cs index 0b7a4c6..321328f 100644 --- a/DU Industry Tool/MainForm.cs +++ b/DU Industry Tool/MainForm.cs @@ -99,8 +99,7 @@ private void SelectRecipe(object sender, TreeNode e) _infoPanel.Controls.Clear(); _infoPanel.BorderStyle = BorderStyle.None; - _infoPanel.Controls.Add(new Label - { + _infoPanel.Controls.Add(new Label { AutoSize = false, Font = new Font(_infoPanel.Font.FontFamily, 12f, FontStyle.Bold), Padding = new Padding(2, 5, 4, 2), @@ -108,40 +107,24 @@ private void SelectRecipe(object sender, TreeNode e) Height = 30, Width = 370 }); - _infoPanel.Controls.Add(new Label - { + _infoPanel.Controls.Add(new Label { AutoSize = true, Font = new Font(_infoPanel.Font.FontFamily, 9f), Padding = new Padding(4, 0, 4, 5), Text = $"Unit mass: {recipe.UnitMass:N1} volume: {recipe.UnitVolume:N1}"+(recipe.Nanocraftable ? " *nanocraftable*" : "") }); - var costPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; _manager.ProductQuantity = int.Parse(QuantityBox.Text); if (!double.TryParse(QuantityBox.Text, out var cnt)) cnt = 1d; var costToMake = _manager.GetTotalCost(recipe.Key, cnt, silent: true); - costPanel.Controls.Add(new Label - { - AutoSize = true, - Text = "Cost To Make " + costToMake.ToString("N02") + "q" - }); - _infoPanel.Controls.Add(costPanel); + AddFlowLabel(_infoPanel.Controls, "Cost To Make " + costToMake.ToString("N02") + "q"); - costPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; var cost = _manager.GetBaseCost(recipe.Key); - costPanel.Controls.Add(new Label - { - Text = "Untalented (without schematics) " + cost.ToString("N02") + "q", - AutoSize = true - }); + AddFlowLabel(_infoPanel.Controls, $"Untalented (without schematics) {cost:N1}q"); + + cost = recipe.Time > 0 ? 86400/recipe.Time : 0; + var pnl = AddFlowLabel(_infoPanel.Controls, $"Per Industry {cost:N1} / Day"); + pnl.Padding = new Padding(0, 0, 0, 10); // IDK why sometimes prices are listed as 0 var orders = _market.MarketOrders.Values.Where(o => o.ItemType == recipe.NqId && @@ -149,88 +132,33 @@ private void SelectRecipe(object sender, TreeNode e) DateTime.Now < o.ExpirationDate && o.Price > 0); var mostRecentOrder = orders.OrderBy(o => o.Price).FirstOrDefault(); - if (mostRecentOrder == null) - { - _infoPanel.Controls.Add(costPanel); - } - else + if (mostRecentOrder != null) { - costPanel.Controls.Add(new Label - { - Text = "Market " + mostRecentOrder.Price.ToString("N02") + "q", - AutoSize = true - }); - costPanel.Controls.Add(new Label - { - Text = "Until " + mostRecentOrder.ExpirationDate - }); - _infoPanel.Controls.Add(costPanel); - - var costPanelm = new FlowLayoutPanel + var costPanel = new FlowLayoutPanel { + AutoSize = true, FlowDirection = FlowDirection.TopDown, - AutoSize = true + Padding = new Padding(0) }; - costPanelm.Controls.Add(new Label - { - Text = "Profit Margin ", - AutoSize = true - }); - cost = ((mostRecentOrder.Price-costToMake)/mostRecentOrder.Price); - costPanelm.Controls.Add(new Label - { - Text = cost.ToString("0%"), - AutoSize = true - }); - _infoPanel.Controls.Add(costPanelm); - + AddLabel(costPanel.Controls, "Market " + mostRecentOrder.Price.ToString("N02") + "q"); + AddLabel(costPanel.Controls, "Until " + mostRecentOrder.ExpirationDate); + AddLabel(costPanel.Controls, "Profit Margin "); + cost = ((mostRecentOrder.Price-costToMake) / mostRecentOrder.Price); + AddLabel(costPanel.Controls, cost.ToString("0%")); cost = (mostRecentOrder.Price - costToMake)*(86400/recipe.Time); - costPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; - costPanel.Controls.Add(new Label - { - Text = "Profit/Day/Industry " + cost.ToString("N02") + "q", - AutoSize = true - }); + AddLabel(costPanel.Controls, "Profit/Day/Industry " + cost.ToString("N02") + "q"); _infoPanel.Controls.Add(costPanel); } - var costPanel2 = new FlowLayoutPanel - { - AutoSize = false, - FlowDirection = FlowDirection.TopDown, - }; - - cost = recipe.Time > 0 ? 86400/recipe.Time : 0; - costPanel2.Controls.Add(new Label - { - Text = "Per Industry " + cost.ToString("0.0") + "/Day", - AutoSize = true - }); - _infoPanel.Controls.Add(costPanel2); - // ----- Ingredients ----- - costPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; - _infoPanel.Controls.Add(new Label - { - AutoSize = true, - Text = "Ingredients", - Font = new Font(_infoPanel.Font, FontStyle.Bold) - }); - + var newPanel = AddFlowLabel(_infoPanel.Controls, "Ingredients", FontStyle.Bold); var grid = new TableLayoutPanel { ColumnCount = 2, RowCount = recipe.Ingredients.Count, AutoSize = true, - Padding = new Padding(0, 0, 0, 10) + Margin = new Padding(0), + Padding = new Padding(0,0,0,10) }; foreach (var ingredient in recipe.Ingredients) { @@ -238,106 +166,81 @@ private void SelectRecipe(object sender, TreeNode e) { AutoSize = true, Font = new Font(_infoPanel.Font, FontStyle.Underline), - Text = ingredient.Name, ForeColor = Color.CornflowerBlue, - Tag = ingredient.Type + Padding = new Padding(0), + Tag = ingredient.Type, + Text = ingredient.Name, }; label.Click += Label_Click; grid.Controls.Add(label); - grid.Controls.Add(new Label - { - AutoSize = true, - Text = ingredient.Quantity.ToString("0.0") - }); + AddLabel(grid.Controls, ingredient.Quantity.ToString("0.0")); } - _infoPanel.Controls.Add(grid); + newPanel.Controls.Add(grid); // ----- Products ----- - var prodPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; - var prodLabel = new Label - { - AutoSize = true, - Font = new Font(_infoPanel.Font, FontStyle.Bold), - Text = "Products" - }; - prodPanel.Controls.Add(prodLabel); - _infoPanel.Controls.Add(prodPanel); - + newPanel = AddFlowLabel(_infoPanel.Controls, "Products", FontStyle.Bold); grid = new TableLayoutPanel { ColumnCount = 2, RowCount = recipe.Products.Count, AutoSize = true, - Padding = new Padding(0, 0, 0, 10) + Padding = new Padding(0,4,0,10) }; - foreach (var ingredient in recipe.Products) + foreach (var prod in recipe.Products) { - grid.Controls.Add(new Label + var isSame = prod.Type == recipe.Key; + var prodLbl = new Label { AutoSize = true, + ForeColor = isSame ? Color.Black : Color.CornflowerBlue, Font = new Font(_infoPanel.Font, FontStyle.Regular), - Text = ingredient.Name - }); - grid.Controls.Add(new Label + Text = prod.Name, + Tag = isSame ? null : prod.Type + }; + if (!isSame) { - AutoSize = true, - Font = new Font(_infoPanel.Font, FontStyle.Regular), - Text = ingredient.Quantity.ToString("0.0") - }); + prodLbl.Click += Label_Click; + } + grid.Controls.Add(prodLbl); + AddLabel(grid.Controls, prod.Quantity.ToString("0.0")); } - _infoPanel.Controls.Add(grid); + newPanel.Controls.Add(grid); if (recipe.ParentGroupName.EndsWith("Ore", StringComparison.InvariantCultureIgnoreCase) || recipe.ParentGroupName.EndsWith("Parts", StringComparison.InvariantCultureIgnoreCase) || recipe.ParentGroupName.EndsWith("Product", StringComparison.InvariantCultureIgnoreCase) || recipe.ParentGroupName.EndsWith("Pure", StringComparison.InvariantCultureIgnoreCase) || - recipe.Name.StartsWith("Relic Plasma", StringComparison.InvariantCultureIgnoreCase)) + recipe.Name?.StartsWith("Relic Plasma", StringComparison.InvariantCultureIgnoreCase) == true) { var containedIn = _manager.Recipes.Values.Where(x => - true == x.Ingredients?.Any(y => y.Name.Equals(recipe.Name, StringComparison.InvariantCultureIgnoreCase))); + true == x.Ingredients?.Any(y => y.Name.Equals(recipe.Name, StringComparison.InvariantCultureIgnoreCase))).ToList(); if (containedIn?.Any() == true) { - prodPanel = new FlowLayoutPanel - { - FlowDirection = FlowDirection.TopDown, - AutoSize = true - }; - prodPanel.Controls.Add(new Label - { - AutoSize = true, - Font = new Font(_infoPanel.Font, FontStyle.Bold), - Text = "Part of recipes:" - }); + newPanel = AddFlowLabel(_infoPanel.Controls, "Part of recipes:", FontStyle.Bold); grid = new TableLayoutPanel { AutoScroll = true, - AutoSize = false, ColumnCount = 1, - Padding = new Padding(0, 0, 0, 0), + Padding = new Padding(0), RowCount = containedIn.Count(), - Width = 350, Height = 400, + Width = 450, VerticalScroll = { Visible = true } }; - foreach (var master in containedIn) + foreach (var label in containedIn.Select(master => new Label + { + AutoSize = true, + Font = new Font(_infoPanel.Font, FontStyle.Underline), + Text = master.Name, + ForeColor = Color.CornflowerBlue, + Padding = new Padding(0), + Tag = master.Key + })) { - var label = new Label - { - AutoSize = true, - Font = new Font(_infoPanel.Font, FontStyle.Underline), - Text = master.Name, - ForeColor = Color.CornflowerBlue, - Tag = master.Key - }; label.Click += Label_Click; grid.Controls.Add(label); } - prodPanel.Controls.Add(grid); - _infoPanel.Controls.Add(prodPanel); + newPanel.Controls.Add(grid); } } @@ -377,6 +280,39 @@ private void SelectRecipe(object sender, TreeNode e) OnMainformResize(null, null); } + private FlowLayoutPanel AddFlowLabel(System.Windows.Forms.Control.ControlCollection cc, string lblText, FontStyle fstyle = FontStyle.Regular) + { + var panel = new FlowLayoutPanel + { + AutoSize = true, + FlowDirection = FlowDirection.TopDown, + Padding = new Padding(0) + }; + var lbl = new Label + { + AutoSize = true, + Font = new Font(_infoPanel.Font, fstyle), + Padding = new Padding(0), + Text = lblText + }; + panel.Controls.Add(lbl); + cc.Add(panel); + return panel; + } + + private Label AddLabel(System.Windows.Forms.Control.ControlCollection cc, string lblText, FontStyle fstyle = FontStyle.Regular) + { + var lbl = new Label + { + AutoSize = true, + Font = new Font(_infoPanel.Font, fstyle), + Padding = new Padding(0), + Text = lblText + }; + cc.Add(lbl); + return lbl; + } + private void Label_Click(object sender, EventArgs e) { var label = sender as Label;