// Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
// \r
-// This program is part of KancolleSniffer.\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
//\r
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
\r
using System;\r
using System.Drawing;\r
+using System.Linq;\r
using System.Text.RegularExpressions;\r
using System.Windows.Forms;\r
using static System.Math;\r
public class ShipLabels\r
{\r
private readonly ShipLabel[][] _labels = new ShipLabel[ShipInfo.MemberCount][];\r
+ private readonly ShipLabel[][] _combinedLabels = new ShipLabel[ShipInfo.MemberCount * 2][];\r
private readonly ShipLabel[] _akashiTimers = new ShipLabel[ShipInfo.MemberCount];\r
private readonly ShipLabel[][] _damagedShipList = new ShipLabel[16][];\r
private Control _panelDamagedShipList;\r
\r
public void SetShipInfo(ShipStatus[] statuses)\r
{\r
- var empty = new ShipStatus();\r
for (var i = 0; i < _labels.Length; i++)\r
{\r
var labels = _labels[i];\r
- var s = i < statuses.Length ? statuses[i] : empty;\r
- labels[0].SetHp(s);\r
- labels[1].SetCond(s);\r
- labels[2].SetLevel(s);\r
- labels[3].SetExpToNext(s);\r
- labels[4].SetName(s);\r
+ if (i < statuses.Length)\r
+ {\r
+ var s = statuses[i];\r
+ labels[0].SetHp(s);\r
+ labels[1].SetCond(s);\r
+ labels[2].SetLevel(s);\r
+ labels[3].SetExpToNext(s);\r
+ labels[4].SetName(s);\r
+ }\r
+ else\r
+ {\r
+ labels[0].Text = labels[1].Text = labels[2].Text = labels[3].Text = "";\r
+ labels[4].SetName("");\r
+ labels[0].BackColor = labels[1].BackColor = labels[0].PresetColor;\r
+ }\r
+ }\r
+ }\r
+\r
+ public void CreateCombinedShipLabels(Control parent, EventHandler onClick)\r
+ {\r
+ parent.SuspendLayout();\r
+ const int top = 3, height = 12, lh = 16;\r
+ ShipLabel[] headings;\r
+ parent.Controls.AddRange(headings = new[]\r
+ {\r
+ new ShipLabel {Location = new Point(68, top), Text = "HP", AutoSize = true},\r
+ new ShipLabel {Location = new Point(86, top), Text = "cnd", AutoSize = true},\r
+ new ShipLabel {Location = new Point(177, top), Text = "HP", AutoSize = true},\r
+ new ShipLabel {Location = new Point(195, top), Text = "cnd", AutoSize = true},\r
+ new ShipLabel {Location = new Point(0, 1), Size = new Size(parent.Width, lh - 1)}\r
+ });\r
+ foreach (var label in headings)\r
+ {\r
+ label.Scale();\r
+ label.BackColor = ColumnColors[1];\r
+ }\r
+ for (var i = 0; i < _combinedLabels.Length; i++)\r
+ {\r
+ var x = (parent.Width / 2) * (i / ShipInfo.MemberCount);\r
+ var y = top + lh * ((i % ShipInfo.MemberCount) + 1);\r
+ parent.Controls.AddRange(_combinedLabels[i] = new[]\r
+ {\r
+ new ShipLabel {Location = new Point(x + 88, y), AutoSize = true, AnchorRight = true},\r
+ new ShipLabel\r
+ {\r
+ Location = new Point(x + 86, y),\r
+ Size = new Size(23, height),\r
+ TextAlign = ContentAlignment.MiddleRight\r
+ },\r
+ new ShipLabel {Location = new Point(x + 2, y), AutoSize = true}, // 名前のZ-orderを下に\r
+ new ShipLabel {Location = new Point(x, y - 2), Size = new Size(parent.Width / 2, lh - 1)}\r
+ });\r
+ foreach (var label in _combinedLabels[i])\r
+ {\r
+ label.Scale();\r
+ label.PresetColor = label.BackColor = ColumnColors[i % 2];\r
+ label.Tag = i;\r
+ label.Click += onClick;\r
+ }\r
+ }\r
+ parent.ResumeLayout();\r
+ }\r
+\r
+ public void SetCombinedShipInfo(ShipStatus[] first, ShipStatus[] second)\r
+ {\r
+ for (var i = 0; i < _combinedLabels.Length; i++)\r
+ {\r
+ var idx = i % ShipInfo.MemberCount;\r
+ var statuses = i < ShipInfo.MemberCount ? first : second;\r
+ var labels = _combinedLabels[i];\r
+ if (idx < statuses.Length)\r
+ {\r
+ var s = statuses[idx];\r
+ labels[0].SetHp(s);\r
+ labels[1].SetCond(s);\r
+ labels[2].SetName(s);\r
+ }\r
+ else\r
+ {\r
+ labels[0].Text = labels[1].Text = "";\r
+ labels[2].SetName("");\r
+ labels[0].BackColor = labels[1].BackColor = labels[0].PresetColor;\r
+ }\r
}\r
}\r
\r
parent.SuspendLayout();\r
for (var i = 0; i < _akashiTimers.Length; i++)\r
{\r
- const int x = 51;\r
+ const int x = 55;\r
var y = 3 + 16 * (i + 1);\r
ShipLabel label;\r
parent.Controls.Add(\r
{\r
var label = _akashiTimers[i];\r
var labelHp = _labels[i][0];\r
+ var labelName = _labels[i][4];\r
if (i >= timers.Length || timers[i].Span == TimeSpan.MinValue)\r
{\r
label.Visible = false;\r
label.Visible = true;\r
label.Text = timer.Span.ToString(@"mm\:ss");\r
label.ForeColor = Control.DefaultForeColor;\r
+ labelName.SetShortName(stat);\r
if (timer.Diff == 0)\r
{\r
labelHp.ForeColor = Control.DefaultForeColor;\r
parent.Controls.AddRange(_damagedShipList[i] = new[]\r
{\r
new ShipLabel {Location = new Point(0, y), Size = new Size(11, height)},\r
- new ShipLabel {Location = new Point(119, y), Size = new Size(4, height - 1)},\r
+ new ShipLabel {Location = new Point(119, y), Size = new Size(5, height - 1)},\r
new ShipLabel {Location = new Point(75, y), AutoSize = true},\r
new ShipLabel {Location = new Point(9, y), AutoSize = true},\r
new ShipLabel {Location = new Point(0, y - 2), Size = new Size(parent.Width, height + 3)}\r
return;\r
}\r
parent.Size = new Size(parent.Width, (int)Round(ShipLabel.ScaleFactor.Height * (num * 16 + 3)));\r
- var colors = new[] {Color.FromArgb(255, 225, 225, 21), Color.Orange, Color.Red};\r
for (var i = 0; i < num; i++)\r
{\r
var s = list[i];\r
labels[fleet].SetFleet(s);\r
labels[name].SetName(s);\r
labels[time].SetRepairTime(s);\r
- labels[damage].BackColor = (int)s.DamageLevel == 0\r
- ? labels[damage].PresetColor\r
- : colors[(int)s.DamageLevel - 1];\r
+ labels[damage].BackColor = ShipLabel.DamageColor(s, labels[damage].PresetColor);\r
}\r
}\r
\r
{\r
new ShipLabel\r
{\r
- Location = new Point(93, y),\r
+ Location = new Point(138, y),\r
AutoSize = true,\r
- AnchorRight = true,\r
- Text = "00:00:00"\r
+ AnchorRight = true\r
},\r
new ShipLabel {Location = new Point(29, y), AutoSize = true} // 名前のZ-orderを下に\r
});\r
label.Click += onClick;\r
}\r
}\r
- parent.Click += onClick;\r
}\r
\r
public void SetNDockLabels(NameAndTimer[] ndock)\r
{\r
var label = _ndockLabels[dock][0];\r
label.ForeColor = timer.IsFinished ? Color.Red : Color.Black;\r
- if (finishTime)\r
- label.SetRepairFinishTime(timer.EndTime);\r
+ if (timer.EndTime == DateTime.MinValue)\r
+ {\r
+ label.Text = "";\r
+ }\r
else\r
- label.SetRepairTime(timer.Rest);\r
+ {\r
+ if (finishTime)\r
+ label.Text = timer.EndTime.ToString(@"dd\ HH\:mm");\r
+ else\r
+ label.SetRepairTime(timer.Rest);\r
+ }\r
}\r
}\r
\r
private int _right = int.MinValue;\r
private int _left;\r
\r
- public void SetName(ShipStatus status)\r
+ public void SetShortName(ShipStatus status)\r
+ {\r
+ SetName(status, true);\r
+ }\r
+\r
+ public void SetName(ShipStatus status, bool shortName = false)\r
{\r
- SetName((status.Escaped ? "[避]" : "") + status.Name);\r
+ var empty = status.Id != -1 && status.Slot.All(e => e.Id == -1) ? "▫" : "";\r
+ var dc = status.PreparedDamageControl;\r
+ var dcname = dc == 42 ? "[ダ]" : dc == 43 ? "[メ]" : "";\r
+ var name = shortName ? status.Spec.ShortName : status.Name;\r
+ SetName((status.Escaped ? "[避]" : dcname) + name + empty);\r
}\r
\r
public void SetName(string name)\r
{\r
- var lu = name != null && new Regex(@"^\p{Lu}").IsMatch(name);\r
+ var lu = name != null && new Regex(@"^(?:\[.\])?\p{Lu}").IsMatch(name);\r
var shift = (int)Round(ScaleFactor.Height);\r
if (lu && Font.Equals(Parent.Font))\r
{\r
\r
public void SetHp(ShipStatus status)\r
{\r
- SetHp(status.NowHp, status.MaxHp);\r
+ Text = $"{status.NowHp:D}/{status.MaxHp:D}";\r
+ BackColor = DamageColor(status, PresetColor);\r
}\r
\r
public void SetHp(int now, int max)\r
{\r
- var colors = new[] {PresetColor, Color.FromArgb(255, 240, 240, 100), Color.Orange, Color.Red};\r
- Text = $"{now:D}/{max:D}";\r
- BackColor = colors[(int)ShipStatus.CalcDamage(now, max)];\r
+ SetHp(new ShipStatus {NowHp = now, MaxHp = max});\r
}\r
\r
- public void SetCond(ShipStatus status)\r
+ public static Color DamageColor(ShipStatus status, Color backcolor)\r
{\r
- if (status.Level == 0)\r
+ switch (status.DamageLevel)\r
{\r
- Text = "0";\r
- BackColor = PresetColor;\r
- return;\r
+ case ShipStatus.Damage.Badly:\r
+ return Color.Red;\r
+ case ShipStatus.Damage.Half:\r
+ return Color.Orange;\r
+ case ShipStatus.Damage.Small:\r
+ return Color.FromArgb(240, 240, 0);\r
+ default:\r
+ return backcolor;\r
}\r
+ }\r
+\r
+ public void SetCond(ShipStatus status)\r
+ {\r
var cond = status.Cond;\r
Text = cond.ToString("D");\r
BackColor = cond >= 50\r
Text = $@"{(int)span.TotalHours:d2}:{span:mm\:ss}";\r
}\r
\r
- public void SetRepairFinishTime(DateTime time)\r
- {\r
- Text = time == DateTime.MinValue ? "-------" : time.ToString(@"dd\ HH\:mm");\r
- }\r
-\r
public void SetFleet(ShipStatus status)\r
{\r
Text = new[] {"", "1", "2", "3", "4"}[status.Fleet + 1];\r