X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=KancolleSniffer%2FView%2FAntiAirPanel.cs;h=45d627a38e95d932719b6b35c158d761dc767411;hb=c7ebe46dd5769c36eacad57420aac0c0ce2847df;hp=b2e860e2d1b71e7a0d65b2349b6f69cb0daa56e4;hpb=a695cb742e2510490c5db67bd31fb63138d4d5f2;p=kancollesniffer%2FKancolleSniffer.git diff --git a/KancolleSniffer/View/AntiAirPanel.cs b/KancolleSniffer/View/AntiAirPanel.cs index b2e860e..45d627a 100644 --- a/KancolleSniffer/View/AntiAirPanel.cs +++ b/KancolleSniffer/View/AntiAirPanel.cs @@ -16,16 +16,24 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; +using KancolleSniffer.Model; namespace KancolleSniffer.View { public class AntiAirPanel : Panel { private const int LineHeight = 16; - private readonly List _labelList = new List(); - private readonly List _panelList = new List(); + private readonly List _labelList = new List(); private readonly List _table = new List(); + private class AntiAirLabels : ShipLabels + { + public Label Rate { get; set; } + public Label Diff { get; set; } + + public override Control[] AddedControls => new Control[] {Rate, Diff}; + } + public void Update(Sniffer sniffer) { CreateTable(sniffer); @@ -60,27 +68,57 @@ namespace KancolleSniffer.View var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray(); _table.Add(new Record { - Fleet = fn[fleet.Number] + " : " + string.Join("/", forFleet.Select(x => x.ToString("f1"))) + Fleet = fn[fleet.Number] + " 防空" + string.Join("/", forFleet.Select(x => x.ToString("f1"))) }); foreach (var ship in ships) { - var rate = ship.EffectiveAntiAirForShip / 4.0; - var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0); - _table.Add(new Record - { - Ship = ship.Name + " Lv" + ship.Level + - " : " + ship.EffectiveAntiAirForShip.ToString("d"), - Id = ship.Id - }); - _table.Add(new Record - { - Rate = "割合: " + rate.ToString("f1") + "% ", - Diff = "固定: " + string.Join("/", diff.Select(d => d.ToString("f1"))) - }); + _table.Add(CreateShipRecord(ship)); + _table.Add(CreateAntiAirRecord(forFleet, ship)); } } } + private Record CreateShipRecord(ShipStatus ship) + { + var param = " Lv" + ship.Level + + " 加重" + ship.EffectiveAntiAirForShip.ToString("d") + + AntiAirPropellantBarrageChance(ship); + var name = ship.Name; + var realWidth = Scaler.ScaleWidth(ListForm.PanelWidth - 10); + return new Record + { + Ship = StringTruncator.Truncate(name, param, realWidth, GetFont(name)) + param, + Id = ship.Id + }; + } + + private Record CreateAntiAirRecord(double[] forFleet, ShipStatus ship) + { + var rate = ship.EffectiveAntiAirForShip / 4.0; + var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0); + return new Record + { + Rate = "割合" + rate.ToString("f1") + "% ", + Diff = "固定" + string.Join("/", diff.Select(d => d.ToString("f1"))) + }; + } + + private static Font GetFont(string name) + { + return ShipLabel.Name.StartWithLetter(name) + ? ShipLabel.Name.LatinFont + : ShipLabel.Name.BaseFont; + } + + private static string AntiAirPropellantBarrageChance(ShipStatus ship) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + if (ship.AntiAirPropellantBarrageChance == 0) + return ""; + var chance = ship.AntiAirPropellantBarrageChance; + return " 弾幕" + (chance < 100 ? chance.ToString("f1") : ((int)chance).ToString()); + } + private void CreateLabels() { for (var i = _labelList.Count; i < _table.Count; i++) @@ -90,53 +128,40 @@ namespace KancolleSniffer.View private void CreateLabels(int i) { var y = 1 + LineHeight * i; - var lbp = new Panel + var labels = new AntiAirLabels { - Location = new Point(0, y), - Size = new Size(ListForm.PanelWidth, LineHeight), - BackColor = CustomColors.ColumnColors.BrightFirst(i), - Visible = false - }; - Scaler.Scale(lbp); - lbp.Tag = lbp.Location.Y; - var labels = new[] - { - new ShipLabel {Location = new Point(1, 3), AutoSize = true}, - new ShipLabel {Location = new Point(10, 3), AutoSize = true}, - new ShipLabel {Location = new Point(35, 3), AutoSize = true}, - new ShipLabel {Location = new Point(100, 3), AutoSize = true} + Fleet = new ShipLabel.Fleet(new Point(1, 3)), + Name = new ShipLabel.Name(new Point(10, 3), ShipNameWidth.Max), + Rate = new Label {Location = new Point(35, 3), AutoSize = true}, + Diff = new Label {Location = new Point(100, 3), AutoSize = true}, + BackPanel = new Panel + { + Location = new Point(0, y), + Size = new Size(ListForm.PanelWidth, LineHeight) + } }; _labelList.Add(labels); - _panelList.Add(lbp); - // ReSharper disable once CoVariantArrayConversion - lbp.Controls.AddRange(labels); - Controls.Add(lbp); - foreach (var label in labels) - { - Scaler.Scale(label); - label.BackColor = CustomColors.ColumnColors.BrightFirst(i); - } + labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i)); + labels.Move(AutoScrollPosition); } private void SetRecords() { for (var i = 0; i < _table.Count; i++) SetRecord(i); - for (var i = _table.Count; i < _panelList.Count; i++) - _panelList[i].Visible = false; + for (var i = _table.Count; i < _labelList.Count; i++) + _labelList[i].BackPanel.Visible = false; } private void SetRecord(int i) { - var lbp = _panelList[i]; - if (!lbp.Visible) - lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y); + var lbp = _labelList[i].BackPanel; var column = _table[i]; var labels = _labelList[i]; - labels[0].Text = column.Fleet; - labels[1].SetName(column.Ship); - labels[2].Text = column.Rate; - labels[3].Text = column.Diff; + labels.Fleet.Text = column.Fleet; + labels.Name.SetName(column.Ship); + labels.Rate.Text = column.Rate; + labels.Diff.Text = column.Diff; lbp.Visible = true; }