1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
16 using System.Drawing;
\r
17 using System.Windows.Forms;
\r
18 using KancolleSniffer.Model;
\r
20 namespace KancolleSniffer.View
\r
22 public class QuestLabels
\r
24 public Label Color { get; set; }
\r
25 public Label Name { get; set; }
\r
26 public ShipLabel Count { get; set; }
\r
27 public Label Progress { get; set; }
\r
29 public Label[] Labels => new[] {Color, Count, Progress, Name};
\r
32 public class QuestPanel : PanelWithToolTip
\r
34 const int TopMargin = 5;
\r
35 const int LeftMargin = 2;
\r
36 const int LineHeight = 14;
\r
37 private const int Lines = 6;
\r
38 private readonly QuestLabels[] _labels = new QuestLabels[Lines];
\r
39 private QuestStatus[] _questList = new QuestStatus[0];
\r
40 private int _listPosition;
\r
44 const int height = 12;
\r
47 for (var i = 0; i < Lines; i++)
\r
49 var y = TopMargin + i * LineHeight;
\r
50 _labels[i] = new QuestLabels
\r
54 Location = new Point(LeftMargin, y + 1),
\r
55 Size = new Size(4, height - 1)
\r
59 Location = new Point(LeftMargin + 4, y),
\r
62 Count = new ShipLabel
\r
64 Location = new Point(LeftMargin + 189, y),
\r
68 Progress = new Label
\r
70 Location = new Point(LeftMargin + 186, y),
\r
71 Size = new Size(29, height),
\r
72 TextAlign = ContentAlignment.MiddleRight
\r
75 _labels[i].Name.DoubleClick += NameLabelDoubleClickHandler;
\r
76 // ReSharper disable once CoVariantArrayConversion
\r
77 Controls.AddRange(_labels[i].Labels);
\r
80 SetScrollEventHandlers();
\r
83 private void SetScrollEventHandlers()
\r
85 foreach (var label in _labels[0].Labels)
\r
87 label.MouseEnter += TopLineOnMouseEnter;
\r
88 label.MouseLeave += TopLineOnMouseLeave;
\r
90 foreach (var label in _labels[Lines - 1].Labels)
\r
92 label.MouseEnter += BottomLineOnMouseEnter;
\r
93 label.MouseLeave += BottomLineOnMouseLeave;
\r
95 _topScrollRepeatTimer.Tick += TopLineOnMouseEnter;
\r
96 _bottomScrollRepeatTimer.Tick += BottomLineOnMouseEnter;
\r
99 private readonly Timer _topScrollRepeatTimer = new Timer {Interval = 100};
\r
100 private readonly Timer _bottomScrollRepeatTimer = new Timer {Interval = 100};
\r
102 private void TopLineOnMouseEnter(object sender, EventArgs e)
\r
104 if (_listPosition == 0)
\r
108 _topScrollRepeatTimer.Start();
\r
111 private void TopLineOnMouseLeave(object sender, EventArgs e)
\r
113 _topScrollRepeatTimer.Stop();
\r
116 private void BottomLineOnMouseEnter(object sender, EventArgs e)
\r
118 if (_listPosition + Lines >= _questList.Length)
\r
122 _bottomScrollRepeatTimer.Start();
\r
125 private void BottomLineOnMouseLeave(object sender, EventArgs e)
\r
127 _bottomScrollRepeatTimer.Stop();
\r
130 public void Update(QuestStatus[] quests)
\r
132 _questList = quests;
\r
133 if (quests.Length <= Lines)
\r
138 public void ShowQuestList()
\r
141 for (var i = 0; i < Lines; i++)
\r
143 var labels = _labels[i];
\r
144 if (i >= _questList.Length)
\r
146 ClearQuest(labels);
\r
147 ClearCount(labels.Count);
\r
150 var quest = _questList[i + _listPosition];
\r
151 SetQuest(labels, quest);
\r
152 if (quest.Count.Id == 0)
\r
154 ClearCount(labels.Count);
\r
157 SetCount(labels.Count, quest.Count);
\r
159 ResumeLayout(true);
\r
163 private void ClearQuest(QuestLabels labels)
\r
165 labels.Color.BackColor = DefaultBackColor;
\r
166 labels.Name.Text = labels.Count.Text = labels.Progress.Text = "";
\r
169 private void ClearCount(Label label)
\r
172 label.ForeColor = Color.Black;
\r
173 ToolTip.SetToolTip(label, "");
\r
176 private void SetQuest(QuestLabels labels, QuestStatus quest)
\r
178 labels.Color.BackColor = quest.Color;
\r
179 labels.Name.Text = quest.Name;
\r
180 labels.Progress.Text = $"{quest.Progress:D}%";
\r
181 ToolTip.SetToolTip(labels.Name, quest.ToToolTip());
\r
184 private void SetCount(Label label, QuestCount count)
\r
186 label.Text = " " + count;
\r
187 label.ForeColor = count.Cleared ? CUDColors.Red : Color.Black;
\r
188 ToolTip.SetToolTip(label, count.ToToolTip());
\r
191 private void NameLabelDoubleClickHandler(object sender, EventArgs e)
\r
193 NameLabelDoubleClick?.Invoke(sender, e);
\r
196 public event EventHandler NameLabelDoubleClick;
\r
198 protected override void OnPaint(PaintEventArgs e)
\r
204 private void DrawMark()
\r
206 using (var g = CreateGraphics())
\r
208 var topBrush = _listPosition > 0 ? Brushes.Black : new SolidBrush(BackColor);
\r
209 g.FillPolygon(topBrush,
\r
212 new PointF(Width * 0.45f, TopMargin), new PointF(Width * 0.55f, TopMargin),
\r
213 new PointF(Width * 0.5f, 0), new PointF(Width * 0.45f, TopMargin)
\r
215 var bottomBrush = _listPosition + Lines < _questList.Length
\r
217 : new SolidBrush(BackColor);
\r
218 g.FillPolygon(bottomBrush,
\r
221 new PointF(Width * 0.45f, Height - TopMargin - 2),
\r
222 new PointF(Width * 0.55f, Height - TopMargin - 2),
\r
223 new PointF(Width * 0.5f, Height - 2), new PointF(Width * 0.45f, Height - TopMargin - 2)
\r