From c4ca34399f3578ceb5302b2c357ba47db94bc05c Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Sun, 21 Apr 2019 18:01:35 +0900 Subject: [PATCH] =?utf8?q?=E6=95=B0=E5=AD=97=E3=82=84=E5=B1=A5=E6=AD=B4?= =?utf8?q?=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=82=92NumberAndHistory=E3=82=AF?= =?utf8?q?=E3=83=A9=E3=82=B9=E3=81=AB=E5=88=86=E9=9B=A2=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer/KancolleSniffer.csproj | 1 + KancolleSniffer/MainForm.cs | 119 ++++++++++---------------- KancolleSniffer/View/NumberAndHistory.cs | 140 +++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 74 deletions(-) create mode 100644 KancolleSniffer/View/NumberAndHistory.cs diff --git a/KancolleSniffer/KancolleSniffer.csproj b/KancolleSniffer/KancolleSniffer.csproj index f61e584..96dd75f 100644 --- a/KancolleSniffer/KancolleSniffer.csproj +++ b/KancolleSniffer/KancolleSniffer.csproj @@ -110,6 +110,7 @@ + Component diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index c3848bd..6b31260 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -33,8 +33,8 @@ using KancolleSniffer.Net; using KancolleSniffer.Util; using KancolleSniffer.View; using Microsoft.CSharp.RuntimeBinder; -using Timer = System.Windows.Forms.Timer; using static System.Math; +using Timer = System.Windows.Forms.Timer; namespace KancolleSniffer { @@ -51,6 +51,7 @@ namespace KancolleSniffer private bool _combinedFleet; private readonly Label[] _labelCheckFleets; private MainFormLabels _mainLabels; + private NumberAndHistory _numberAndHistory; private readonly ListForm _listForm; private readonly NotificationManager _notificationManager; private bool _started; @@ -79,6 +80,7 @@ namespace KancolleSniffer labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1]; _listForm = new ListForm(_sniffer, _config, this); _notificationManager = new NotificationManager(Alarm); + CreateNumberAndHistory(); _config.Load(); _proxyManager = new ProxyManager(_config, this); _errorLog = new ErrorLog(_sniffer); @@ -102,6 +104,43 @@ namespace KancolleSniffer _mainLabels.CreateNDockLabels(labelNDock_Click); } + private void CreateNumberAndHistory() + { + _numberAndHistory = new NumberAndHistory(new NumberAndHistoryLabels + { + NumOfShips = labelNumOfShips, + NumOfEquips = labelNumOfEquips, + NumOfBuckets = labelNumOfBuckets, + BucketHistory = labelBucketHistory, + Achievement = labelAchievement, + FuelHistory = labelFuelHistory, + BulletHistory = labelBulletHistory, + SteelHistory = labelSteelHistory, + BauxiteHistory = labelBouxiteHistory, + ToolTip = _toolTip + }, _sniffer, new NotifySubmitter(_notificationManager)); + } + + private class NotifySubmitter : INotifySubmitter + { + private readonly NotificationManager _manager; + + public NotifySubmitter(NotificationManager manager) + { + _manager = manager; + } + + public void Flash() + { + _manager.Flash(); + } + + public void Enqueue(string key, string subject) + { + _manager.Enqueue(key, subject); + } + } + /// /// パネルのz-orderがくるうのを避ける /// https://stackoverflow.com/a/5777090/1429506 @@ -439,7 +478,7 @@ namespace KancolleSniffer { control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100); } - foreach (var toolTip in new[]{_toolTip, _toolTipQuest, _tooltipCopy}) + foreach (var toolTip in new[] {_toolTip, _toolTipQuest, _tooltipCopy}) { toolTip.Font = new Font(toolTip.Font.FontFamily, toolTip.Font.Size * _config.Zoom / 100); } @@ -462,9 +501,9 @@ namespace KancolleSniffer if (TopMost != _config.TopMost) TopMost = _listForm.TopMost = _config.TopMost; _sniffer.ShipCounter.Margin = _config.MarginShips; - UpdateNumOfShips(); + _numberAndHistory.UpdateNumOfShips(); _sniffer.ItemCounter.Margin = _config.MarginEquips; - UpdateNumOfEquips(); + _numberAndHistory.UpdateNumOfEquips(); _sniffer.Achievement.ResetHours = _config.ResetHours; labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible = labelPresetAkashiTimer.Visible = _config.UsePresetAkashi; @@ -558,82 +597,14 @@ namespace KancolleSniffer _listForm.ShowShip(ship.Id); } + private void UpdateItemInfo() { - UpdateNumOfShips(); - UpdateNumOfEquips(); - _notificationManager.Flash(); - labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D"); - UpdateBucketHistory(); - var ac = _sniffer.Achievement.Value; - if (ac >= 10000) - ac = 9999; - labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1"); - _toolTip.SetToolTip(labelAchievement, - "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" + - "EO " + _sniffer.ExMap.Achievement); - UpdateMaterialHistory(); + _numberAndHistory.Update(); if (_listForm.Visible) _listForm.UpdateList(); } - private void UpdateNumOfShips() - { - var ship = _sniffer.ShipCounter; - labelNumOfShips.Text = $"{ship.Now:D}/{ship.Max:D}"; - labelNumOfShips.ForeColor = ship.TooMany ? CUDColors.Red : Color.Black; - if (ship.Alarm) - { - var message = $"残り{ship.Rest:D}隻"; - _notificationManager.Enqueue("艦娘数超過", message); - ship.Alarm = false; - } - } - - private void UpdateNumOfEquips() - { - var item = _sniffer.ItemCounter; - labelNumOfEquips.Text = $"{item.Now:D}/{item.Max:D}"; - labelNumOfEquips.ForeColor = item.TooMany ? CUDColors.Red : Color.Black; - if (item.Alarm) - { - var message = $"残り{item.Rest:D}個"; - _notificationManager.Enqueue("装備数超過", message); - item.Alarm = false; - } - } - - private void UpdateBucketHistory() - { - var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket]; - var day = CutOverflow(count.Now - count.BegOfDay, 999); - var week = CutOverflow(count.Now - count.BegOfWeek, 999); - labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週"; - } - - private void UpdateMaterialHistory() - { - var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory}; - var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"}; - for (var i = 0; i < labels.Length; i++) - { - var count = _sniffer.Material.MaterialHistory[i]; - var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999); - var day = CutOverflow(count.Now - count.BegOfDay, 99999); - var week = CutOverflow(count.Now - count.BegOfWeek, 99999); - labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}"; - } - } - - private int CutOverflow(int value, int limit) - { - if (value > limit) - return limit; - if (value < -limit) - return -limit; - return value; - } - private void UpdateShipInfo() { SetCurrentFleet(); diff --git a/KancolleSniffer/View/NumberAndHistory.cs b/KancolleSniffer/View/NumberAndHistory.cs new file mode 100644 index 0000000..5460ba6 --- /dev/null +++ b/KancolleSniffer/View/NumberAndHistory.cs @@ -0,0 +1,140 @@ +// Copyright (C) 2019 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.Drawing; +using System.Windows.Forms; +using KancolleSniffer.Model; + +namespace KancolleSniffer.View +{ + public class NumberAndHistoryLabels + { + public Label NumOfShips { get; set; } + public Label NumOfEquips { get; set; } + public Label NumOfBuckets { get; set; } + public Label BucketHistory { get; set; } + public Label Achievement { get; set; } + public Label FuelHistory { get; set; } + public Label BulletHistory { get; set; } + public Label SteelHistory { get; set; } + public Label BauxiteHistory { get; set; } + public ToolTip ToolTip { get; set; } + } + + public interface INotifySubmitter + { + void Flash(); + void Enqueue(string key, string subject); + } + + public class NumberAndHistory + { + private readonly NumberAndHistoryLabels _labels; + private readonly Sniffer _sniffer; + private readonly ToolTip _toolTip; + private readonly INotifySubmitter _submitter; + + public NumberAndHistory(NumberAndHistoryLabels labels, Sniffer sniffer, INotifySubmitter submitter) + { + _labels = labels; + _sniffer = sniffer; + _toolTip = labels.ToolTip; + _submitter = submitter; + } + + public void Update() + { + UpdateNumOfShips(); + UpdateNumOfEquips(); + _submitter.Flash(); + UpdateNumOfBuckets(); + UpdateBucketHistory(); + UpdateAchievement(); + UpdateMaterialHistory(); + } + + private void UpdateNumOfBuckets() + { + _labels.NumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D"); + } + + private void UpdateAchievement() + { + var ac = _sniffer.Achievement.Value; + if (ac >= 10000) + ac = 9999; + _labels.Achievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1"); + _toolTip.SetToolTip(_labels.Achievement, + "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" + + "EO " + _sniffer.ExMap.Achievement); + } + + public void UpdateNumOfShips() + { + var ship = _sniffer.ShipCounter; + _labels.NumOfShips.Text = $"{ship.Now:D}/{ship.Max:D}"; + _labels.NumOfShips.ForeColor = ship.TooMany ? CUDColors.Red : Color.Black; + if (ship.Alarm) + { + var message = $"残り{ship.Rest:D}隻"; + _submitter.Enqueue("艦娘数超過", message); + ship.Alarm = false; + } + } + + public void UpdateNumOfEquips() + { + var item = _sniffer.ItemCounter; + _labels.NumOfEquips.Text = $"{item.Now:D}/{item.Max:D}"; + _labels.NumOfEquips.ForeColor = item.TooMany ? CUDColors.Red : Color.Black; + if (item.Alarm) + { + var message = $"残り{item.Rest:D}個"; + _submitter.Enqueue("装備数超過", message); + item.Alarm = false; + } + } + + private void UpdateBucketHistory() + { + var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket]; + var day = CutOverflow(count.Now - count.BegOfDay, 999); + var week = CutOverflow(count.Now - count.BegOfWeek, 999); + _labels.BucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週"; + } + + private void UpdateMaterialHistory() + { + var labels = new[] {_labels.FuelHistory, _labels.BulletHistory, _labels.SteelHistory, _labels.BauxiteHistory }; + var text = new[] { "燃料", "弾薬", "鋼材", "ボーキ" }; + for (var i = 0; i < labels.Length; i++) + { + var count = _sniffer.Material.MaterialHistory[i]; + var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999); + var day = CutOverflow(count.Now - count.BegOfDay, 99999); + var week = CutOverflow(count.Now - count.BegOfWeek, 99999); + labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}"; + } + } + + private int CutOverflow(int value, int limit) + { + if (value > limit) + return limit; + if (value < -limit) + return -limit; + return value; + } + } +} \ No newline at end of file -- 2.11.0