// curmats may be null Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, MaterialCommoditiesList curmats, HistoryList hl, Point matpos, Size matsize) { Point startpos = matpos; Point maximum = matpos; int noperline = 0; bool noncommon = ShowMaterialsRare; string matclicktext = sn.DisplayMaterials(2, curmats, hl.GetLast?.MaterialCommodity); foreach (KeyValuePair <string, double> sd in sn.Materials) { string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, curmats, hl.GetLast?.MaterialCommodity); Color fillc = Color.Yellow; string abv = sd.Key.Substring(0, 1); MaterialCommodityData mc = MaterialCommodityData.GetByFDName(sd.Key); if (mc != null) { abv = mc.Shortname; fillc = mc.Colour; if (HideFullMaterials) // check full { int?limit = mc.MaterialLimit(); MaterialCommodities matnow = curmats?.Find(mc); // allow curmats = null // debug if (matnow != null && mc.shortname == "Fe") matnow.count = 10000; if (matnow != null && matnow.Count >= limit) // and limit { continue; } } if (noncommon && mc.IsCommonMaterial) { continue; } } CreateMaterialImage(pc, matpos, matsize, abv, tooltip + "\n\n" + "All " + matclicktext, tooltip, fillc, Color.Black); maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height)); if (++noperline == 4) { matpos = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy); noperline = 0; } else { matpos.X += matsize.Width + materiallinespacerxy; } } return(maximum); }
public string DisplayMaterial(string name, double percent, MaterialCommoditiesList historicmatlist = null, MaterialCommoditiesList currentmatlist = null) { StringBuilder scanText = new StringBuilder(); MaterialCommodityData mc = MaterialCommodityData.GetCachedMaterial(name); if (mc != null && (historicmatlist != null || currentmatlist != null)) { MaterialCommodities historic = historicmatlist?.Find(mc.name); MaterialCommodities current = ReferenceEquals(historicmatlist, currentmatlist) ? null : currentmatlist?.Find(mc.name); int?limit = MaterialCommodityData.MaterialLimit(mc); string matinfo = historic?.count.ToString() ?? "0"; if (limit != null) { matinfo += "/" + limit.Value.ToString(); } if (current != null && (historic == null || historic.count != current.count)) { matinfo += " Cur " + current.count.ToString(); } scanText.AppendFormat("{0} ({1}) {2} {3}% {4}\n", mc.name, mc.shortname, mc.type, percent.ToString("N1"), matinfo); } else { scanText.AppendFormat("{0} {1}%\n", System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()), percent.ToString("N1")); } return(scanText.ToNullSafeString()); }
// curmats may be null Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, MaterialCommoditiesList curmats, HistoryList hl, Point matpos, Size matsize) { Point startpos = matpos; Point maximum = matpos; int noperline = 0; string matclicktext = sn.DisplayMaterials(2, curmats, hl.GetLast?.MaterialCommodity); foreach (KeyValuePair <string, double> sd in sn.Materials) { string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, curmats, hl.GetLast?.MaterialCommodity); Color fillc = Color.Yellow; string abv = sd.Key.Substring(0, 1); MaterialCommodityData mc = MaterialCommodityData.GetByFDName(sd.Key); if (mc != null) { abv = mc.Shortname; fillc = mc.Colour; if (HideFullMaterials) // check full { int?limit = mc.MaterialLimit(); MaterialCommodities matnow = curmats?.Find(mc); // allow curmats = null // debug if (matnow != null && mc.shortname == "Fe") matnow.count = 10000; if (matnow != null && limit != null && matnow.Count >= limit) // and limit { continue; } } if (ShowOnlyMaterialsRare && mc.IsCommonMaterial) { continue; } } System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = fillc; Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)Icons.Controls.Scan_Bodies_Material, new System.Drawing.Imaging.ColorMap[] { colormap }); BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, stdfont, Color.Black); ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, tooltip + "\n\n" + "All " + matclicktext, tooltip); pc.Add(ie); maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height)); if (++noperline == 4) { matpos = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy); noperline = 0; } else { matpos.X += matsize.Width + materiallinespacerxy; } } return(maximum); }
private void extPictureTrades_ClickElement(object sender, MouseEventArgs eventargs, ExtendedControls.ExtPictureBox.ImageElement i, object tag) { if (i != null && tag is ElementTrade && last_mcl != null) // must be an element, with a tag, must have a current mcl { ElementTrade current = (ElementTrade)tag; System.Diagnostics.Debug.WriteLine("Clicked on " + current.type + " " + current.element.Name); if (selected != null) { int currenttotal = last_mcl.Find(current.element)?.Count ?? 0; // current mat total. If not there, its zero foreach (var trade in trades) { if (trade.fromelement.FDName == current.element.FDName) { currenttotal -= trade.offer; // may go negative if over offered } if (trade.element.FDName == current.element.FDName) { currenttotal += trade.receive; } } if (selected.element.FDName == current.element.FDName) // clicked on same.. deselect { selected = null; } else if (currenttotal >= current.offer) // if we have enough for at least 1 trade { DisplayTradeSelection(current.element); ExtendedControls.ConfigurableForm f = new ExtendedControls.ConfigurableForm(); int width = 250; int margin = 20; var butl = new ExtendedControls.ExtButton(); butl.Image = BaseUtils.Icons.IconSet.GetIcon("Controls.MaterialTrader.LeftArrow"); f.Add(new ExtendedControls.ConfigurableForm.Entry(butl, "less", "", new Point(margin, 64), new Size(32, 32), null)); var butr = new ExtendedControls.ExtButton(); butr.Image = BaseUtils.Icons.IconSet.GetIcon("Controls.MaterialTrader.RightArrow"); f.Add(new ExtendedControls.ConfigurableForm.Entry(butr, "more", "", new Point(width - margin - 32, 64), new Size(32, 32), null)); f.Add(new ExtendedControls.ConfigurableForm.Entry("olabel", typeof(Label), "Offer".T(EDTx.UserControlMaterialTrader_Offer), new Point(margin, 30), new Size(width - margin * 2, 20), null, 1.5f, ContentAlignment.MiddleCenter)); f.Add(new ExtendedControls.ConfigurableForm.Entry("offer", typeof(Label), "0/" + currenttotal.ToStringInvariant(), new Point(width / 2 - 12, 50), new Size(width / 2 - 20, 20), null, 1.2f, ContentAlignment.MiddleLeft)); var bar = new PictureBox(); bar.SizeMode = PictureBoxSizeMode.StretchImage; bar.Image = BaseUtils.Icons.IconSet.GetIcon("Controls.MaterialTrader.TraderBar"); f.Add(new ExtendedControls.ConfigurableForm.Entry(bar, "bar", "", new Point(width / 2 - 32, 70), new Size(64, 16), null)); f.Add(new ExtendedControls.ConfigurableForm.Entry("receive", typeof(Label), "0", new Point(width / 2 - 12, 90), new Size(width / 2 - 20, 20), null, 1.2f, ContentAlignment.MiddleLeft)); f.Add(new ExtendedControls.ConfigurableForm.Entry("rlabel", typeof(Label), "Receive".T(EDTx.UserControlMaterialTrader_Receive), new Point(margin, 110), new Size(width - margin * 2, 20), null, 1.5f, ContentAlignment.MiddleCenter)); f.AddOK(new Point(width - margin - 80, 150), "Press to Accept".T(EDTx.UserControlModules_PresstoAccept)); f.AddCancel(new Point(margin, 150), "Press to Cancel".T(EDTx.UserControlModules_PresstoCancel)); int currentoffer = 0; int currentreceive = 0; f.Trigger += (dialogname, controlname, xtag) => { if (controlname == "OK") { f.ReturnResult(DialogResult.OK); } else if (controlname == "Cancel" || controlname == "Close") { f.ReturnResult(DialogResult.Cancel); } else if (controlname == "less" || controlname == "more") { if (controlname == "less") { if (currentoffer > 0) { currentoffer -= current.offer; currentreceive -= current.receive; } } else { int newoffer = currentoffer + current.offer; if (newoffer <= currenttotal) { currentoffer = newoffer; currentreceive += current.receive; } } f.GetControl <Label>("offer").Text = currentoffer.ToStringInvariant() + "/" + currenttotal.ToStringInvariant(); f.GetControl <Label>("receive").Text = currentreceive.ToStringInvariant(); } }; f.RightMargin = margin; f.InitCentred(this.FindForm(), this.FindForm().Icon, " ", closeicon: true); DialogResult res = f.ShowDialog(); if (res == DialogResult.OK) { ElementTrade t = new ElementTrade() { element = selected.element, fromelement = current.element, offer = currentoffer, receive = currentreceive }; trades.Add(t); selected = null; StoreTrades(); DisplayTradeList(); } DisplayTradeSelection(); } } else { selected = current; } DisplayTradeSelection(); } }