OSDN Git Service

ズームしたときに文字が欠けないようにゆとりを持たせる
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ShipLabels.cs
index 60b4e0c..ceb7371 100644 (file)
@@ -13,6 +13,7 @@
 // limitations under the License.\r
 \r
 using System;\r
+using System.ComponentModel;\r
 using System.Drawing;\r
 using System.Linq;\r
 using System.Text.RegularExpressions;\r
@@ -30,6 +31,7 @@ namespace KancolleSniffer
         RepairListFull = 75,\r
         ShipList = 82,\r
         GroupConfig = 82,\r
+        Combined = 54,\r
         Max = int.MaxValue\r
     }\r
 \r
@@ -38,8 +40,6 @@ namespace KancolleSniffer
         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[][] _repairList = new ShipLabel[16][];\r
-        private Control _panelRepairList;\r
         private readonly ShipLabel[][] _ndockLabels = new ShipLabel[DockInfo.DockCount][];\r
         public static Color[] ColumnColors = {SystemColors.Control, Color.FromArgb(255, 250, 250, 250)};\r
 \r
@@ -69,20 +69,20 @@ namespace KancolleSniffer
                     new ShipLabel {Location = new Point(129, y), AutoSize = true, AnchorRight = true},\r
                     new ShipLabel\r
                     {\r
-                        Location = new Point(132, y),\r
-                        Size = new Size(23, height),\r
+                        Location = new Point(131, y),\r
+                        Size = new Size(24, height),\r
                         TextAlign = ContentAlignment.MiddleRight\r
                     },\r
                     new ShipLabel\r
                     {\r
-                        Location = new Point(157, y),\r
-                        Size = new Size(23, height),\r
+                        Location = new Point(156, y),\r
+                        Size = new Size(24, height),\r
                         TextAlign = ContentAlignment.MiddleRight\r
                     },\r
                     new ShipLabel\r
                     {\r
-                        Location = new Point(177, y),\r
-                        Size = new Size(41, height),\r
+                        Location = new Point(176, y),\r
+                        Size = new Size(42, height),\r
                         TextAlign = ContentAlignment.MiddleRight\r
                     },\r
                     new ShipLabel {Location = new Point(2, y), AutoSize = true}, // 名前のZ-orderを下に\r
@@ -144,14 +144,14 @@ namespace KancolleSniffer
             for (var i = 0; i < _combinedLabels.Length; i++)\r
             {\r
                 var x = parentWidth / 2 * (i / ShipInfo.MemberCount);\r
-                var y = top + lh * ((i % ShipInfo.MemberCount) + 1);\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
+                        Location = new Point(x + 85, y),\r
+                        Size = new Size(24, height),\r
                         TextAlign = ContentAlignment.MiddleRight\r
                     },\r
                     new ShipLabel {Location = new Point(x + 2, y), AutoSize = true}, // 名前のZ-orderを下に\r
@@ -180,7 +180,7 @@ namespace KancolleSniffer
                     var s = statuses[idx];\r
                     labels[0].SetHp(s);\r
                     labels[1].SetCond(s);\r
-                    labels[2].SetName(s);\r
+                    labels[2].SetName(s, ShipNameWidth.Combined);\r
                 }\r
                 else\r
                 {\r
@@ -204,7 +204,7 @@ namespace KancolleSniffer
                         new ShipLabel\r
                         {\r
                             Location = new Point(x, y),\r
-                            Size = new Size(34, 12),\r
+                            Size = new Size(31, 12),\r
                             TextAlign = ContentAlignment.TopRight\r
                         });\r
                 label.BackColor = ColumnColors[i % 2];\r
@@ -214,6 +214,20 @@ namespace KancolleSniffer
             parent.ResumeLayout();\r
         }\r
 \r
+        public void AdjustAkashiTimers()\r
+        {\r
+            var scale = ShipLabel.ScaleFactor;\r
+            if (scale.Height < 1.2)\r
+                return;\r
+            for (var i = 0; i < _akashiTimers.Length; i++)\r
+            {\r
+                const int x = 55;\r
+                var y = 3 + 16 * (i + 1);\r
+                _akashiTimers[i].Location = new Point((int)Round(x * scale.Width) - 3, (int)Round(y * scale.Height));\r
+                _akashiTimers[i].Size = new Size((int)Round(31 * scale.Width) + 1, (int)Round(12 * scale.Height));\r
+            }\r
+        }\r
+\r
         public void SetAkashiTimer(ShipStatus[] statuses, AkashiTimer.RepairSpan[] timers)\r
         {\r
             var shortest = -1;\r
@@ -247,65 +261,12 @@ namespace KancolleSniffer
                     continue;\r
                 }\r
                 if (i == shortest)\r
-                    label.ForeColor = Color.Red;\r
+                    label.ForeColor = CUDColor.Red;\r
                 labelHp.ForeColor = Color.DimGray;\r
                 labelHp.SetHp(stat.NowHp + timer.Diff, stat.MaxHp);\r
             }\r
         }\r
 \r
-        public void CreateRepairList(Control parent, EventHandler onClick)\r
-        {\r
-            parent.SuspendLayout();\r
-            for (var i = 0; i < _repairList.Length; i++)\r
-            {\r
-                var y = 3 + i * 16;\r
-                const int height = 12;\r
-                parent.Controls.AddRange(_repairList[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(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
-                });\r
-                foreach (var label in _repairList[i])\r
-                {\r
-                    label.Scale();\r
-                    label.PresetColor = label.BackColor = ColumnColors[(i + 1) % 2];\r
-                    label.Click += onClick;\r
-                }\r
-            }\r
-            _panelRepairList = parent;\r
-            parent.ResumeLayout();\r
-        }\r
-\r
-        public void SetRepairList(ShipStatus[] list)\r
-        {\r
-            const int fleet = 0, name = 3, time = 2, damage = 1;\r
-            var parent = _panelRepairList;\r
-            var num = Min(list.Length, _repairList.Length);\r
-            if (num == 0)\r
-            {\r
-                parent.Size = new Size(parent.Width, (int)Round(ShipLabel.ScaleFactor.Height * 19));\r
-                var labels = _repairList[0];\r
-                labels[fleet].Text = "";\r
-                labels[name].SetName("なし");\r
-                labels[time].Text = "";\r
-                labels[damage].BackColor = labels[damage].PresetColor;\r
-                return;\r
-            }\r
-            parent.Size = new Size(parent.Width, (int)Round(ShipLabel.ScaleFactor.Height * (num * 16 + 3)));\r
-            for (var i = 0; i < num; i++)\r
-            {\r
-                var s = list[i];\r
-                var labels = _repairList[i];\r
-                labels[fleet].SetFleet(s);\r
-                labels[name].SetName(s, ShipNameWidth.RepairList);\r
-                labels[time].SetRepairTime(s);\r
-                labels[damage].BackColor = ShipLabel.DamageColor(s, labels[damage].PresetColor);\r
-            }\r
-        }\r
-\r
         public void CreateNDockLabels(Control parent, EventHandler onClick)\r
         {\r
             for (var i = 0; i < _ndockLabels.Length; i++)\r
@@ -333,18 +294,18 @@ namespace KancolleSniffer
         public void SetNDockLabels(NameAndTimer[] ndock)\r
         {\r
             for (var i = 0; i < _ndockLabels.Length; i++)\r
-                _ndockLabels[i][1].SetName("", ndock[i].Name, "", ShipNameWidth.NDock);\r
+                _ndockLabels[i][1].SetName(ndock[i].Name, ShipNameWidth.NDock);\r
         }\r
 \r
         public void SetNDockTimer(int dock, RingTimer timer, bool finishTime)\r
         {\r
             var label = _ndockLabels[dock][0];\r
-            label.ForeColor = timer.IsFinished ? Color.Red : Color.Black;\r
+            label.ForeColor = timer.IsFinished ? CUDColor.Red : Color.Black;\r
             label.Text = timer.ToString(finishTime);\r
         }\r
     }\r
 \r
-    [System.ComponentModel.DesignerCategory("Code")]\r
+    [DesignerCategory("Code")]\r
     public class ShipLabel : Label\r
     {\r
         public static SizeF ScaleFactor { get; set; }\r
@@ -353,6 +314,21 @@ namespace KancolleSniffer
         public bool AnchorRight { get; set; }\r
         private int _right = int.MinValue;\r
         private int _left;\r
+        private SlotStatus _slotStatus;\r
+\r
+        public override Color BackColor\r
+        {\r
+            get => base.BackColor;\r
+            set => base.BackColor = value == DefaultBackColor ? PresetColor : value;\r
+        }\r
+\r
+        [Flags]\r
+        private enum SlotStatus\r
+        {\r
+            Equipped = 0,\r
+            NormalEmpty = 1,\r
+            ExtraEmpty = 2\r
+        }\r
 \r
         public ShipLabel()\r
         {\r
@@ -361,7 +337,14 @@ namespace KancolleSniffer
 \r
         public void SetName(ShipStatus status, ShipNameWidth width = ShipNameWidth.Max)\r
         {\r
-            var empty = status.Id != -1 && status.Slot.All(e => e.Id == -1) ? "▫" : "";\r
+            SlotStatus empty = SlotStatus.Equipped;\r
+            if (status.Id != -1)\r
+            {\r
+                if (status.Slot.All(item => item.Id == -1))\r
+                    empty |= SlotStatus.NormalEmpty;\r
+                if (status.SlotEx.Id == -1)\r
+                    empty |= SlotStatus.ExtraEmpty;\r
+            }\r
             var dc = status.PreparedDamageControl;\r
             var dcname = dc == 42 ? "[ダ]" : dc == 43 ? "[メ]" : "";\r
             SetName((status.Escaped ? "[避]" : dcname), status.Name, empty, width);\r
@@ -369,13 +352,19 @@ namespace KancolleSniffer
 \r
         public void SetName(string name)\r
         {\r
-            SetName("", name, "");\r
+            SetName("", name, SlotStatus.Equipped);\r
+        }\r
+\r
+        public void SetName(string name, ShipNameWidth width)\r
+        {\r
+            SetName("", name, SlotStatus.Equipped, width);\r
         }\r
 \r
-        public void SetName(string prefix, string name, string suffix, ShipNameWidth width = ShipNameWidth.Max)\r
+        private void SetName(string prefix, string name, SlotStatus slotStatus, ShipNameWidth width = ShipNameWidth.Max)\r
         {\r
             if (name == null)\r
                 return;\r
+            _slotStatus = slotStatus;\r
             var lu = new Regex(@"^\p{Lu}").IsMatch(name);\r
             var shift = (int)Round(ScaleFactor.Height);\r
             if (lu && Font.Equals(Parent.Font))\r
@@ -388,22 +377,24 @@ namespace KancolleSniffer
                 Location += new Size(0, shift);\r
                 Font = Parent.Font;\r
             }\r
-            var result = prefix + name + suffix;\r
+            var result = prefix + name;\r
             var measured = TextRenderer.MeasureText(result, Font).Width;\r
             if (measured <= (int)width)\r
             {\r
                 Text = result;\r
+                Invalidate(); // 必ずOnPaintを実行させるため\r
                 return;\r
             }\r
             var truncated = "";\r
             foreach (var ch in name)\r
             {\r
                 var tmp = truncated + ch;\r
-                if (TextRenderer.MeasureText(tmp, Font).Width > (int)width)\r
+                if (TextRenderer.MeasureText(tmp, Font).Width > (int)width * ScaleFactor.Width)\r
                     break;\r
                 truncated = tmp;\r
             }\r
-            Text = prefix + truncated.TrimEnd(' ') + suffix;\r
+            Text = prefix + truncated.TrimEnd(' ');\r
+            Invalidate();\r
         }\r
 \r
         public void SetHp(ShipStatus status)\r
@@ -421,10 +412,12 @@ namespace KancolleSniffer
         {\r
             switch (status.DamageLevel)\r
             {\r
+                case ShipStatus.Damage.Sunk:\r
+                    return Color.CornflowerBlue;\r
                 case ShipStatus.Damage.Badly:\r
-                    return Color.Red;\r
+                    return CUDColor.Red;\r
                 case ShipStatus.Damage.Half:\r
-                    return Color.Orange;\r
+                    return CUDColor.Orange;\r
                 case ShipStatus.Damage.Small:\r
                     return Color.FromArgb(240, 240, 0);\r
                 default:\r
@@ -437,10 +430,12 @@ namespace KancolleSniffer
             var cond = status.Cond;\r
             Text = cond.ToString("D");\r
             BackColor = cond >= 50\r
-                ? Color.Yellow\r
+                ? CUDColor.Yellow\r
                 : cond >= 30\r
                     ? PresetColor\r
-                    : cond >= 20 ? Color.Orange : Color.Red;\r
+                    : cond >= 20\r
+                        ? CUDColor.Orange\r
+                        : CUDColor.Red;\r
         }\r
 \r
         public void SetLevel(ShipStatus status)\r
@@ -485,6 +480,25 @@ namespace KancolleSniffer
             Location = new Point(_left, Top);\r
         }\r
 \r
+        protected override void OnPaint(PaintEventArgs e)\r
+        {\r
+            base.OnPaint(e);\r
+            if ((_slotStatus & SlotStatus.NormalEmpty) != 0)\r
+            {\r
+                e.Graphics.DrawRectangle(\r
+                    Pens.Black,\r
+                    ClientSize.Width - 3 * ScaleFactor.Width, 1 * ScaleFactor.Height,\r
+                    2 * ScaleFactor.Width, 4 * ScaleFactor.Height);\r
+            }\r
+            if ((_slotStatus & SlotStatus.ExtraEmpty) != 0)\r
+            {\r
+                e.Graphics.DrawRectangle(\r
+                    Pens.Black,\r
+                    ClientSize.Width - 3 * ScaleFactor.Width, 7 * ScaleFactor.Height,\r
+                    2 * ScaleFactor.Width, 3 * ScaleFactor.Height);\r
+            }\r
+        }\r
+\r
         public void Scale()\r
         {\r
             Scale(ScaleFactor);\r