OSDN Git Service

IUpdatableを導入して処理を簡略化する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / NumberAndHistory.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System.Drawing;\r
16 using System.Windows.Forms;\r
17 using KancolleSniffer.Model;\r
18 \r
19 namespace KancolleSniffer.View\r
20 {\r
21     public class NumberAndHistoryLabels\r
22     {\r
23         public Label FuelHistory { get; set; }\r
24         public Label BulletHistory { get; set; }\r
25         public Label SteelHistory { get; set; }\r
26         public Label BauxiteHistory { get; set; }\r
27         public ToolTip ToolTip { get; set; }\r
28     }\r
29 \r
30     public class NumberAndHistory\r
31     {\r
32         private readonly NumberAndHistoryLabels _labels;\r
33         private readonly Sniffer _sniffer;\r
34         private readonly ToolTip _toolTip;\r
35         private readonly MainForm.INotifySubmitter _submitter;\r
36 \r
37         public NumberAndHistory(NumberAndHistoryLabels labels, Sniffer sniffer, MainForm.INotifySubmitter submitter)\r
38         {\r
39             _labels = labels;\r
40             _sniffer = sniffer;\r
41             _toolTip = labels.ToolTip;\r
42             _submitter = submitter;\r
43         }\r
44 \r
45         public void Update()\r
46         {\r
47             UpdateMaterialHistory();\r
48         }\r
49 \r
50         private void UpdateMaterialHistory()\r
51         {\r
52             var labels = new[] {_labels.FuelHistory, _labels.BulletHistory, _labels.SteelHistory, _labels.BauxiteHistory };\r
53             var text = new[] { "燃料", "弾薬", "鋼材", "ボーキ" };\r
54             for (var i = 0; i < labels.Length; i++)\r
55             {\r
56                 var count = _sniffer.Material.MaterialHistory[i];\r
57                 var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999);\r
58                 var day = CutOverflow(count.Now - count.BegOfDay, 99999);\r
59                 var week = CutOverflow(count.Now - count.BegOfWeek, 99999);\r
60                 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";\r
61             }\r
62         }\r
63 \r
64         private int CutOverflow(int value, int limit)\r
65         {\r
66             if (value > limit)\r
67                 return limit;\r
68             if (value < -limit)\r
69                 return -limit;\r
70             return value;\r
71         }\r
72     }\r
73 }