1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using System.Collections.Generic;
\r
17 using System.Drawing;
\r
18 using System.Windows.Forms;
\r
19 using static System.Math;
\r
21 namespace KancolleSniffer
\r
23 public enum ShipNameWidth
\r
29 RepairListFull = 75,
\r
38 public class MainFormLabels
\r
40 private readonly ShipLabel[][] _shiplabels = new ShipLabel[ShipInfo.MemberCount][];
\r
41 private readonly ShipLabel[][] _shipLabels7 = new ShipLabel[7][];
\r
42 private readonly ShipLabel[][] _combinedLabels = new ShipLabel[ShipInfo.MemberCount * 2][];
\r
43 private readonly ShipLabel[] _akashiTimers = new ShipLabel[ShipInfo.MemberCount];
\r
44 private readonly ShipLabel[] _akashiTimers7 = new ShipLabel[ShipInfo.MemberCount];
\r
45 private readonly ShipLabel[][] _ndockLabels = new ShipLabel[DockInfo.DockCount][];
\r
46 private readonly List<ShipLabel> _hpLables = new List<ShipLabel>();
\r
47 public bool ShowHpInPercent { get; private set; }
\r
49 public void CreateShipLabels(Control parent, EventHandler onClick)
\r
51 CreateShipLabels(parent, onClick, _shiplabels, 16);
\r
54 public void CreateShipLabels7(Control parent, EventHandler onClick)
\r
56 CreateShipLabels(parent, onClick, _shipLabels7, 14);
\r
59 public void CreateShipLabels(Control parent, EventHandler onClick, ShipLabel[][] shipLabels, int lineHeight)
\r
61 parent.SuspendLayout();
\r
62 const int top = 1, height = 12;
\r
63 ShipLabel[] headings;
\r
64 parent.Controls.AddRange(headings = new[]
\r
66 new ShipLabel {Location = new Point(109, top), Text = "HP", AutoSize = true},
\r
67 new ShipLabel {Location = new Point(128, top), Text = "cond", AutoSize = true},
\r
68 new ShipLabel {Location = new Point(162, top), Text = "Lv", AutoSize = true},
\r
69 new ShipLabel {Location = new Point(194, top), Text = "Exp", AutoSize = true},
\r
70 new ShipLabel {Location = new Point(0, 1), Size = new Size(parent.Width, lineHeight - 1)}
\r
72 foreach (var label in headings)
\r
75 label.BackColor = ShipLabel.ColumnColors[1];
\r
77 for (var i = 0; i < shipLabels.Length; i++)
\r
79 var y = top + lineHeight * (i + 1);
\r
80 parent.Controls.AddRange(shipLabels[i] = new[]
\r
84 Location = new Point(129, y),
\r
87 MinimumSize = new Size(0, lineHeight),
\r
88 TextAlign = ContentAlignment.MiddleLeft,
\r
89 Cursor = Cursors.Hand
\r
93 Location = new Point(131, y),
\r
94 Size = new Size(24, lineHeight),
\r
95 TextAlign = ContentAlignment.MiddleRight
\r
99 Location = new Point(155, y + 2),
\r
100 Size = new Size(24, height),
\r
101 TextAlign = ContentAlignment.MiddleRight
\r
105 Location = new Point(176, y + 2),
\r
106 Size = new Size(42, height),
\r
107 TextAlign = ContentAlignment.MiddleRight
\r
109 new ShipLabel {Location = new Point(2, y + 2), AutoSize = true}, // 名前のZ-orderを下に
\r
110 new ShipLabel {Location = new Point(0, y), Size = new Size(parent.Width, lineHeight)}
\r
112 foreach (var label in shipLabels[i])
\r
115 label.PresetColor = label.BackColor = ShipLabel.ColumnColors[i % 2];
\r
117 label.Click += onClick;
\r
119 var hpLabel = shipLabels[i][0];
\r
120 _hpLables.Add(hpLabel);
\r
121 hpLabel.DoubleClick += HpLabelClickHander;
\r
123 headings[0].Cursor = Cursors.Hand;
\r
124 headings[0].Click += HpLabelClickHander;
\r
125 parent.ResumeLayout();
\r
128 private void HpLabelClickHander(object sender, EventArgs ev)
\r
133 public void ToggleHpPercent()
\r
135 ShowHpInPercent = !ShowHpInPercent;
\r
136 foreach (var label in _hpLables)
\r
137 label.ToggleHpPercent();
\r
140 public void SetShipLabels(ShipStatus[] statuses)
\r
142 SetShipLabels(statuses, statuses.Length == 7 ? _shipLabels7 : _shiplabels);
\r
145 public void SetShipLabels(ShipStatus[] statuses, ShipLabel[][] shipLabels)
\r
147 for (var i = 0; i < shipLabels.Length; i++)
\r
149 var labels = shipLabels[i];
\r
150 var s = i < statuses.Length ? statuses[i] : null;
\r
151 labels[0].SetHp(s);
\r
152 labels[1].SetCond(s);
\r
153 labels[2].SetLevel(s);
\r
154 labels[3].SetExpToNext(s);
\r
155 labels[4].SetName(s, ShipNameWidth.MainPanel);
\r
159 public void CreateCombinedShipLabels(Control parent, EventHandler onClick)
\r
161 parent.SuspendLayout();
\r
162 const int top = 1, lh = 16;
\r
163 const int parentWidth = 220; // parent.Widthを使うとDPIスケーリング時に計算がくるうので
\r
164 ShipLabel[] headings;
\r
165 parent.Controls.AddRange(headings = new[]
\r
167 new ShipLabel {Location = new Point(68, top), Text = "HP", AutoSize = true},
\r
168 new ShipLabel {Location = new Point(86, top), Text = "cnd", AutoSize = true},
\r
169 new ShipLabel {Location = new Point(177, top), Text = "HP", AutoSize = true},
\r
170 new ShipLabel {Location = new Point(195, top), Text = "cnd", AutoSize = true},
\r
171 new ShipLabel {Location = new Point(0, 1), Size = new Size(parentWidth, lh - 1)}
\r
173 foreach (var label in headings)
\r
176 label.BackColor = ShipLabel.ColumnColors[1];
\r
178 for (var i = 0; i < _combinedLabels.Length; i++)
\r
180 var x = parentWidth / 2 * (i / ShipInfo.MemberCount);
\r
181 var y = top + lh * (i % ShipInfo.MemberCount + 1);
\r
182 parent.Controls.AddRange(_combinedLabels[i] = new[]
\r
186 Location = new Point(x + 88, y),
\r
188 AnchorRight = true,
\r
189 MinimumSize = new Size(0, lh),
\r
190 TextAlign = ContentAlignment.MiddleLeft,
\r
191 Cursor = Cursors.Hand
\r
195 Location = new Point(x + 85, y),
\r
196 Size = new Size(24, lh),
\r
197 TextAlign = ContentAlignment.MiddleRight
\r
199 new ShipLabel {Location = new Point(x + 2, y + 2), AutoSize = true}, // 名前のZ-orderを下に
\r
200 new ShipLabel {Location = new Point(x, y), Size = new Size(parentWidth / 2, lh)}
\r
202 foreach (var label in _combinedLabels[i])
\r
205 label.PresetColor = label.BackColor = ShipLabel.ColumnColors[i % 2];
\r
207 label.Click += onClick;
\r
209 var hpLavel = _combinedLabels[i][0];
\r
210 _hpLables.Add(hpLavel);
\r
211 hpLavel.DoubleClick += HpLabelClickHander;
\r
213 headings[0].Cursor = headings[2].Cursor = Cursors.Hand;
\r
214 headings[0].Click += HpLabelClickHander;
\r
215 headings[2].Click += HpLabelClickHander;
\r
216 parent.ResumeLayout();
\r
219 public void SetCombinedShipLabels(ShipStatus[] first, ShipStatus[] second)
\r
221 for (var i = 0; i < _combinedLabels.Length; i++)
\r
223 var idx = i % ShipInfo.MemberCount;
\r
224 var statuses = i < ShipInfo.MemberCount ? first : second;
\r
225 var labels = _combinedLabels[i];
\r
226 var s = idx < statuses.Length ? statuses[idx] : null;
\r
227 labels[0].SetHp(s);
\r
228 labels[1].SetCond(s);
\r
229 labels[2].SetName(s, ShipNameWidth.Combined);
\r
233 public void CreateAkashiTimers(Control parent)
\r
235 CreateAkashiTimers(parent, _akashiTimers, 16);
\r
238 public void CreateAkashiTimers7(Control parent)
\r
240 CreateAkashiTimers(parent, _akashiTimers7, 14);
\r
243 public void CreateAkashiTimers(Control parent, ShipLabel[] timerLabels, int lineHeight)
\r
245 parent.SuspendLayout();
\r
246 for (var i = 0; i < timerLabels.Length; i++)
\r
249 var y = 3 + lineHeight * (i + 1);
\r
251 parent.Controls.Add(
\r
252 label = timerLabels[i] =
\r
255 Location = new Point(x, y),
\r
256 Size = new Size(31, 12),
\r
257 TextAlign = ContentAlignment.TopRight
\r
259 label.BackColor = ShipLabel.ColumnColors[i % 2];
\r
261 foreach (var label in timerLabels)
\r
263 parent.ResumeLayout();
\r
266 public void AdjustAkashiTimers()
\r
268 AdjustAkashiTimers(_akashiTimers, 16);
\r
269 AdjustAkashiTimers(_akashiTimers7, 14);
\r
272 public void AdjustAkashiTimers(ShipLabel[] timers, int lineHeight)
\r
274 var scale = ShipLabel.ScaleFactor;
\r
275 if (scale.Height < 1.2)
\r
277 for (var i = 0; i < timers.Length; i++)
\r
280 var y = 3 + lineHeight * (i + 1);
\r
281 timers[i].Location = new Point((int)Round(x * scale.Width) - 3, (int)Round(y * scale.Height));
\r
282 timers[i].Size = new Size((int)Round(31 * scale.Width) + 1, (int)Round(12 * scale.Height));
\r
286 public void SetAkashiTimer(ShipStatus[] statuses, AkashiTimer.RepairSpan[] timers)
\r
288 if (statuses.Length == 7)
\r
290 SetAkashiTimer(statuses, timers, _akashiTimers7, _shipLabels7);
\r
294 SetAkashiTimer(statuses, timers, _akashiTimers, _shiplabels);
\r
298 public void SetAkashiTimer(ShipStatus[] statuses, AkashiTimer.RepairSpan[] timers, ShipLabel[] timerLabels,
\r
299 ShipLabel[][] shipLabels)
\r
302 for (var i = 0; i < timers.Length; i++)
\r
304 if (timers[i].Span <= TimeSpan.Zero)
\r
306 if (shortest == -1 || timers[i].Span < timers[shortest].Span)
\r
309 for (var i = 0; i < timerLabels.Length; i++)
\r
311 var label = timerLabels[i];
\r
312 var labelHp = shipLabels[i][0];
\r
313 var labelName = shipLabels[i][4];
\r
314 if (i >= timers.Length || timers[i].Span == TimeSpan.MinValue)
\r
316 label.Visible = false;
\r
317 labelHp.ForeColor = Control.DefaultForeColor;
\r
320 var timer = timers[i];
\r
321 var stat = statuses[i];
\r
322 label.Visible = true;
\r
323 label.Text = timer.Span.ToString(@"mm\:ss");
\r
324 label.ForeColor = Control.DefaultForeColor;
\r
325 labelName.SetName(stat, ShipNameWidth.AkashiTimer);
\r
326 if (timer.Diff == 0)
\r
328 labelHp.ForeColor = Control.DefaultForeColor;
\r
332 label.ForeColor = CUDColor.Red;
\r
333 labelHp.ForeColor = Color.DimGray;
\r
334 labelHp.SetHp(stat.NowHp + timer.Diff, stat.MaxHp);
\r
338 public void CreateNDockLabels(Control parent, EventHandler onClick)
\r
341 for (var i = 0; i < _ndockLabels.Length; i++)
\r
344 parent.Controls.AddRange(
\r
345 _ndockLabels[i] = new[]
\r
349 Location = new Point(138, y + 2),
\r
351 AnchorRight = true,
\r
352 MinimumSize = new Size(0, lh),
\r
353 TextAlign = ContentAlignment.MiddleLeft,
\r
354 Cursor = Cursors.Hand
\r
356 new ShipLabel {Location = new Point(29, y + 3), AutoSize = true} // 名前のZ-orderを下に
\r
358 foreach (var label in _ndockLabels[i])
\r
361 label.Click += onClick;
\r
366 public void SetNDockLabels(NameAndTimer[] ndock)
\r
368 for (var i = 0; i < _ndockLabels.Length; i++)
\r
369 _ndockLabels[i][1].SetName(ndock[i].Name, ShipNameWidth.NDock);
\r
372 public void SetNDockTimer(int dock, AlarmTimer timer, DateTime now, bool finishTime)
\r
374 var label = _ndockLabels[dock][0];
\r
375 label.ForeColor = timer.IsFinished(now) ? CUDColor.Red : Color.Black;
\r
376 label.Text = timer.ToString(now, finishTime);
\r