1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
19 using System.Collections.Generic;
\r
20 using System.Drawing;
\r
22 using System.Windows.Forms;
\r
24 namespace KancolleSniffer
\r
26 public partial class ShipListForm : Form
\r
28 private readonly Sniffer _sniffer;
\r
29 private readonly Config _config;
\r
30 private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();
\r
31 private const int HpLabelRight = 126;
\r
33 public ShipListForm(Sniffer sniffer, Config config)
\r
35 InitializeComponent();
\r
40 public void UpdateList()
\r
48 private void CreateListLabels()
\r
50 panelShipList.SuspendLayout();
\r
51 for (var i = _labelList.Count; i < _sniffer.Item.MaxShips; i++)
\r
53 const int height = 12;
\r
54 var y = 3 + 16 * i + panelShipList.AutoScrollPosition.Y;
\r
57 new ShipLabel {Location = new Point(1, y), Size = new Size(11, height)},
\r
58 new ShipLabel {Location = new Point(HpLabelRight, y), AutoSize = true},
\r
61 Location = new Point(132, y),
\r
62 Size = new Size(23, height),
\r
63 TextAlign = ContentAlignment.MiddleRight
\r
67 Location = new Point(166, y),
\r
68 Size = new Size(23, height),
\r
69 TextAlign = ContentAlignment.MiddleRight
\r
73 Location = new Point(191, y),
\r
74 Size = new Size(41, height),
\r
75 TextAlign = ContentAlignment.MiddleRight
\r
77 new ShipLabel {Location = new Point(10, y), AutoSize = true}
\r
79 _labelList.Add(labels);
\r
80 // ReSharper disable once CoVariantArrayConversion
\r
81 panelShipList.Controls.AddRange(labels);
\r
82 labels[1].SizeChanged += labelHP_SizeChanged;
\r
84 for (var i = _labelList.Count; i > _sniffer.Item.MaxShips; i--)
\r
86 foreach (var label in _labelList[i - 1])
\r
88 panelShipList.Controls.Remove(label);
\r
91 _labelList.RemoveAt(i - 1);
\r
93 panelShipList.ResumeLayout();
\r
96 private class CompareShipByExp : IComparer<ShipStatus>
\r
98 public int Compare(ShipStatus a, ShipStatus b)
\r
100 if (a.Level != b.Level)
\r
101 return b.Level - a.Level;
\r
102 if (a.ExpToNext != b.ExpToNext)
\r
103 return a.ExpToNext - b.ExpToNext;
\r
104 return a.Spec.Id - b.Spec.Id;
\r
108 private void SetShipLabels()
\r
110 var shipList = _sniffer.ShipList;
\r
111 var fn = new[] {"", "1", "2", "3", "4"};
\r
113 foreach (var s in shipList.OrderBy(s => s, new CompareShipByExp()))
\r
115 var labels = _labelList[i++];
\r
116 labels[0].Text = fn[s.Fleet + 1];
\r
117 labels[1].SetHp(s);
\r
118 labels[2].SetCond(s);
\r
119 labels[3].SetLevel(s);
\r
120 labels[4].SetExpToNext(s);
\r
121 labels[5].SetName(s);
\r
125 private void labelHP_SizeChanged(object sender, EventArgs e)
\r
127 var label = (Label)sender;
\r
128 label.Location = new Point(HpLabelRight - label.Width, label.Top);
\r
131 private void ShipListForm_Load(object sender, EventArgs e)
\r
133 var config = _config.ShipList;
\r
134 if (config.Location.X == int.MinValue)
\r
136 var bounds = new Rectangle(config.Location, config.Size);
\r
137 if (MainForm.IsVisibleOnAnyScreen(bounds))
\r
138 Location = bounds.Location;
\r
139 Size = bounds.Size;
\r
142 private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e)
\r
144 var config = _config.ShipList;
\r
145 var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
\r
146 config.Location = bounds.Location;
\r
147 config.Size = bounds.Size;
\r