OSDN Git Service

艦隊情報で長い装備名を適宜縮める
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 4 Aug 2016 13:18:33 +0000 (22:18 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 6 Aug 2016 10:46:51 +0000 (19:46 +0900)
KancolleSniffer/EquipPanel.cs

index fb1ae64..339342c 100644 (file)
@@ -93,12 +93,10 @@ namespace KancolleSniffer
                                 airspec = "航空戦 " + (int)(normal * 0.8) + "/" + (int)(normal * 1.5);\r
                             }\r
                         }\r
+\r
                         equips.Add(new EquipColumn\r
                         {\r
-                            Equip = item.Spec.Name +\r
-                                    (item.Alv == 0 ? "" : "+" + item.Alv) +\r
-                                    (item.Level == 0 ? "" : "★" + item.Level) +\r
-                                    (!item.Spec.IsAircraft ? "" : " " + onslot + "/" + max),\r
+                            Equip = GenEquipString(item, onslot, max),\r
                             AircraftSpec = airspec,\r
                             Color = item.Spec.Color\r
                         });\r
@@ -146,6 +144,29 @@ namespace KancolleSniffer
             _equipList = list.ToArray();\r
         }\r
 \r
+        private string GenEquipString(ItemStatus item, int onslot, int max)\r
+        {\r
+            var name = item.Spec.Name;\r
+            var attr = (item.Alv == 0 ? "" : "+" + item.Alv) +\r
+                       (item.Level == 0 ? "" : "★" + item.Level) +\r
+                       (!item.Spec.IsAircraft ? "" : " " + onslot + "/" + max);\r
+            var proposed = new Size(int.MaxValue, int.MaxValue);\r
+            const int maxWidth = 180;\r
+            var result = name + attr;\r
+            if (TextRenderer.MeasureText(result, Font, proposed).Width <= maxWidth)\r
+                return result;\r
+            attr = " " + attr;\r
+            var truncated = "";\r
+            foreach (var ch in name)\r
+            {\r
+                var tmp = truncated + ch;\r
+                if (TextRenderer.MeasureText(tmp + attr, Font, proposed).Width > maxWidth)\r
+                    break;\r
+                truncated = tmp;\r
+            }\r
+            return truncated + attr;\r
+        }\r
+\r
         private void CreateEquipLabels()\r
         {\r
             for (var i = _labelList.Count; i < _equipList.Length; i++)\r
@@ -168,8 +189,8 @@ namespace KancolleSniffer
             {\r
                 new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(40, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(37, 2), Size = new Size(4, LabelHeight - 2)},\r
+                new ShipLabel {Location = new Point(38, 2), AutoSize = true},\r
+                new ShipLabel {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},\r
                 new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
             };\r
             _labelList.Add(labels);\r