From e3c8d4dd1d041f7b58ca881d9153a8e91e74b590 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Mon, 8 Aug 2016 23:19:33 +0900 Subject: [PATCH] =?utf8?q?=E5=AF=BE=E5=BF=9C=E8=A1=A8=E3=81=A7=E3=81=AF?= =?utf8?q?=E3=81=AA=E3=81=8F=E6=A8=AA=E5=B9=85=E3=82=92=E6=8C=87=E5=AE=9A?= =?utf8?q?=E3=81=97=E3=81=A6=E8=89=A6=E5=A8=98=E3=81=AE=E5=90=8D=E5=89=8D?= =?utf8?q?=E3=82=92=E7=B8=AE=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer.Test/KancolleSniffer.Test.csproj | 2 + .../KancolleSniffer.Test.csproj.DotSettings | 2 + KancolleSniffer.Test/ShipLabelTest.cs | 107 +++++++++++++++++++++ KancolleSniffer/ListForm.cs | 2 +- KancolleSniffer/ShipLabels.cs | 84 ++++++++-------- 5 files changed, 150 insertions(+), 47 deletions(-) create mode 100644 KancolleSniffer.Test/KancolleSniffer.Test.csproj.DotSettings create mode 100644 KancolleSniffer.Test/ShipLabelTest.cs diff --git a/KancolleSniffer.Test/KancolleSniffer.Test.csproj b/KancolleSniffer.Test/KancolleSniffer.Test.csproj index 47bf3af..993a98f 100644 --- a/KancolleSniffer.Test/KancolleSniffer.Test.csproj +++ b/KancolleSniffer.Test/KancolleSniffer.Test.csproj @@ -48,6 +48,7 @@ ..\packages\Moq.4.2.1506.2515\lib\net40\Moq.dll + @@ -63,6 +64,7 @@ + diff --git a/KancolleSniffer.Test/KancolleSniffer.Test.csproj.DotSettings b/KancolleSniffer.Test/KancolleSniffer.Test.csproj.DotSettings new file mode 100644 index 0000000..6e7fff8 --- /dev/null +++ b/KancolleSniffer.Test/KancolleSniffer.Test.csproj.DotSettings @@ -0,0 +1,2 @@ + + No \ No newline at end of file diff --git a/KancolleSniffer.Test/ShipLabelTest.cs b/KancolleSniffer.Test/ShipLabelTest.cs new file mode 100644 index 0000000..bee2ddf --- /dev/null +++ b/KancolleSniffer.Test/ShipLabelTest.cs @@ -0,0 +1,107 @@ +// Copyright (C) 2016 Kazuhiro Fujieda +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Collections.Generic; +using System.Windows.Forms; +using ExpressionToCodeLib; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace KancolleSniffer.Test +{ + [TestClass] + public class ShipLabelTest + { + /// + /// 明石タイマー表示中の艦娘の名前を縮める + /// + [TestMethod] + public void TrancateNameForAkashiTimer() + { + var dict = new Dictionary + { + {"夕立改二", "夕立改二"}, + {"千代田航改", "千代田航"}, + {"千代田航改二", "千代田航"}, + {"Bismarck改", "Bismarck"}, + {"Bismarck twei", "Bismarck"}, + {"Bismarck drei", "Bismarck"}, + {"Prinz Eugen", "Prinz Eug"}, + {"Prinz Eugen改", "Prinz Eug"}, + {"Graf Zeppelin", "Graf Zep"}, + {"Graf Zeppelin改", "Graf Zep"}, + {"Libeccio改", "Libeccio"}, + }; + var label = new ShipLabel {Parent = new Panel()}; + foreach (var entry in dict) + { + label.SetName("", entry.Key, "", ShipNameWidth.AkashiTimer); + PAssert.That(() => label.Text == entry.Value, entry.Key); + } + } + + /// + /// 入渠中の艦娘名の名前を縮める + /// + [TestMethod] + public void TrancateNameForNDock() + { + var dict = new Dictionary + { + {"千歳航改二", "千歳航改二"}, + {"Graf Zeppelin", "Graf Zeppeli"}, + {"Graf Zeppelin改", "Graf Zeppeli"}, + {"千代田航改二", "千代田航改"} + }; + var label = new ShipLabel {Parent = new Panel()}; + foreach (var entry in dict) + { + label.SetName("", entry.Key, "", ShipNameWidth.NDock); + PAssert.That(() => label.Text == entry.Value, entry.Key); + } + } + + /// + /// 一覧ウィンドウの要修復一覧の艦娘の名前を縮める + /// + [TestMethod] + public void TrancateNameForRepairList() + { + var dict = new Dictionary + { + {"Graf Zeppelin", "Graf Zeppelin"}, + {"Graf Zeppelin改", "Graf Zeppelin"}, + {"千代田航改二", "千代田航改"} + }; + var label = new ShipLabel {Parent = new Panel()}; + foreach (var entry in dict) + { + label.SetName("", entry.Key, "", ShipNameWidth.RepairListFull); + PAssert.That(() => label.Text == entry.Value, entry.Key); + } + } + + /// + /// prefixとsuffixを加える + /// + [TestMethod] + public void SetName() + { + var label = new ShipLabel {Parent= new Panel()}; + label.SetName("[避]", "綾波改二", "▫"); + PAssert.That(() => label.Text == "[避]綾波改二▫"); + label.SetName("[避]", "朝潮改二丁", "▫", ShipNameWidth.AkashiTimer); + PAssert.That(() => label.Text == "[避]朝潮改二▫"); + } + } +} \ No newline at end of file diff --git a/KancolleSniffer/ListForm.cs b/KancolleSniffer/ListForm.cs index 097fd53..4b9ac31 100644 --- a/KancolleSniffer/ListForm.cs +++ b/KancolleSniffer/ListForm.cs @@ -436,7 +436,7 @@ namespace KancolleSniffer rpl[1].SetLevel(s); rpl[2].SetRepairTime(s); rpl[3].Text = TimeSpan.FromSeconds(s.RepairSecPerHp).ToString(@"mm\:ss"); - rpl[4].SetName(s, new Dictionary {{"Graf Zeppelin改", "Graf Zeppelin"}, {"千代田航改二", "千代田航改"}}); + rpl[4].SetName(s, ShipNameWidth.RepairListFull); rpl[5].SetFleet(s); rpp.Visible = true; } diff --git a/KancolleSniffer/ShipLabels.cs b/KancolleSniffer/ShipLabels.cs index aae46cd..54490bf 100644 --- a/KancolleSniffer/ShipLabels.cs +++ b/KancolleSniffer/ShipLabels.cs @@ -13,7 +13,6 @@ // limitations under the License. using System; -using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text.RegularExpressions; @@ -22,6 +21,15 @@ using static System.Math; namespace KancolleSniffer { + public enum ShipNameWidth + { + AkashiTimer = 53, + NDock = 69, + RepairList = NDock, + RepairListFull = 75, + Max = int.MaxValue + } + public class ShipLabels { private readonly ShipLabel[][] _labels = new ShipLabel[ShipInfo.MemberCount][]; @@ -229,7 +237,7 @@ namespace KancolleSniffer label.Visible = true; label.Text = timer.Span.ToString(@"mm\:ss"); label.ForeColor = Control.DefaultForeColor; - labelName.SetName(stat, _shortNameDict); + labelName.SetName(stat, ShipNameWidth.AkashiTimer); if (timer.Diff == 0) { labelHp.ForeColor = Control.DefaultForeColor; @@ -242,27 +250,6 @@ namespace KancolleSniffer } } - private readonly Dictionary _shortNameDict = new Dictionary - { - {"千代田航改", "千代田航"}, - {"千代田航改二", "千代田航"}, - {"千歳航改二", "千歳航改"}, - {"五十鈴改二", "五十鈴改"}, - {"あきつ丸改", "あきつ丸"}, - {"Bismarck改", "Bismarck"}, - {"Bismarck twei", "Bismarck"}, - {"Bismarck drei", "Bismarck"}, - {"Prinz Eugen", "Prinz Eug"}, - {"Prinz Eugen改", "Prinz Eug"}, - {"Graf Zeppelin", "Graf Zep"}, - {"Graf Zeppelin改", "Graf Zep"}, - {"Libeccio改", "Libeccio"}, - {"阿武隈改二", "阿武隈改"}, - {"瑞鶴改二甲", "瑞鶴改二"}, - {"翔鶴改二甲", "翔鶴改二"}, - {"朝潮改二丁", "朝潮改二"} - }; - public void CreateRepairList(Control parent, EventHandler onClick) { parent.SuspendLayout(); @@ -310,12 +297,7 @@ namespace KancolleSniffer var s = list[i]; var labels = _repairList[i]; labels[fleet].SetFleet(s); - labels[name].SetName(s, new Dictionary - { - {"Graf Zeppelin", "Graf Zeppeli"}, - {"Graf Zeppelin改", "Graf Zeppeli"}, - {"千代田航改二", "千代田航改"} - }); + labels[name].SetName(s, ShipNameWidth.RepairList); labels[time].SetRepairTime(s); labels[damage].BackColor = ShipLabel.DamageColor(s, labels[damage].PresetColor); } @@ -347,17 +329,8 @@ namespace KancolleSniffer public void SetNDockLabels(NameAndTimer[] ndock) { - var dict = new Dictionary - { - {"Graf Zeppelin", "Graf Zeppeli"}, - {"Graf Zeppelin改", "Graf Zeppeli"}, - {"千代田航改二", "千代田航改"} - }; for (var i = 0; i < _ndockLabels.Length; i++) - { - string name; - _ndockLabels[i][1].SetName(dict.TryGetValue(ndock[i].Name, out name) ? name : ndock[i].Name); - } + _ndockLabels[i][1].SetName("", ndock[i].Name, "", ShipNameWidth.NDock); } public void SetNDockTimer(int dock, RingTimer timer, bool finishTime) @@ -383,20 +356,24 @@ namespace KancolleSniffer UseMnemonic = false; } - public void SetName(ShipStatus status, Dictionary convDict = null) + public void SetName(ShipStatus status, ShipNameWidth width = ShipNameWidth.Max) { - string name; - if (convDict == null || !convDict.TryGetValue(status.Name, out name)) - name = status.Name; var empty = status.Id != -1 && status.Slot.All(e => e.Id == -1) ? "▫" : ""; var dc = status.PreparedDamageControl; var dcname = dc == 42 ? "[ダ]" : dc == 43 ? "[メ]" : ""; - SetName((status.Escaped ? "[避]" : dcname) + name + empty); + SetName((status.Escaped ? "[避]" : dcname), status.Name, empty, width); } public void SetName(string name) { - var lu = name != null && new Regex(@"^(?:\[.\])?\p{Lu}").IsMatch(name); + SetName("", name, ""); + } + + public void SetName(string prefix, string name, string suffix, ShipNameWidth width = ShipNameWidth.Max) + { + if (name == null) + return; + var lu = new Regex(@"^\p{Lu}").IsMatch(name); var shift = (int)Round(ScaleFactor.Height); if (lu && Font.Equals(Parent.Font)) { @@ -408,7 +385,22 @@ namespace KancolleSniffer Location += new Size(0, shift); Font = Parent.Font; } - Text = name; + var result = prefix + name + suffix; + var measured = TextRenderer.MeasureText(result, Font).Width; + if (measured <= (int)width) + { + Text = result; + return; + } + var truncated = ""; + foreach (var ch in name) + { + var tmp = truncated + ch; + if (TextRenderer.MeasureText(tmp, Font).Width > (int)width) + break; + truncated = tmp; + } + Text = prefix + truncated.TrimEnd(' ') + suffix; } public void SetHp(ShipStatus status) -- 2.11.0