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
19 // ReSharper disable CoVariantArrayConversion
\r
21 namespace KancolleSniffer.View
\r
23 public class QuestLabels
\r
25 public ShipLabel Color { get; set; }
\r
26 public ShipLabel Name { get; set; }
\r
27 public ShipLabel Count { get; set; }
\r
28 public ShipLabel Progress { get; set; }
\r
30 public ShipLabel[] Labels => new[] {Color, Count, Progress, Name};
\r
33 public class QuestPanel : PanelWithToolTip
\r
35 private const int TopMargin = 5;
\r
36 private const int LeftMargin = 2;
\r
37 private const int LabelHeight = 12;
\r
38 public const int LineHeight = 14;
\r
39 private QuestLabels[] _labels;
\r
40 private QuestStatus[] _questList = new QuestStatus[0];
\r
41 private ListScroller _listScroller;
\r
44 public void CreateLabels(int lines, EventHandler onDoubleClick)
\r
46 _lines = LimitLines(lines);
\r
47 _labels = new QuestLabels[_lines];
\r
49 Height = (int)Math.Round((TopMargin * 2 + LineHeight * lines) * ShipLabel.ScaleFactor.Height);
\r
50 for (var i = 0; i < _lines; i++)
\r
52 var y = TopMargin + i * LineHeight;
\r
53 _labels[i] = new QuestLabels
\r
55 Color = new ShipLabel
\r
57 Location = new Point(LeftMargin, y + 1),
\r
58 Size = new Size(4, LabelHeight - 1)
\r
60 Name = new ShipLabel
\r
62 Location = new Point(LeftMargin + 4, y),
\r
63 Size = new Size(193, LabelHeight)
\r
65 Count = new ShipLabel
\r
67 Location = new Point(LeftMargin + 189, y),
\r
71 Progress = new ShipLabel
\r
73 Location = new Point(LeftMargin + 186, y),
\r
74 Size = new Size(29, LabelHeight),
\r
75 TextAlign = ContentAlignment.MiddleRight
\r
78 _labels[i].Name.DoubleClick += onDoubleClick;
\r
79 Controls.AddRange(_labels[i].Labels);
\r
80 foreach (var label in _labels[i].Labels)
\r
84 SetupListScroller();
\r
87 private static int LimitLines(int lines)
\r
91 return Math.Min(Math.Max(lines, min), max);
\r
94 private void SetupListScroller()
\r
96 _listScroller = new ListScroller(this, _labels[0].Labels, _labels[_lines - 1].Labels)
\r
101 _listScroller.Update += ShowQuestList;
\r
104 public void Update(QuestStatus[] quests)
\r
106 _questList = quests;
\r
107 _listScroller.DataCount = quests.Length;
\r
108 if (quests.Length <= _lines)
\r
109 _listScroller.Position = 0;
\r
113 private void ShowQuestList()
\r
116 for (var i = 0; i < _lines; i++)
\r
118 var labels = _labels[i];
\r
119 if (i >= _questList.Length)
\r
121 ClearQuest(labels);
\r
122 ClearCount(labels.Count);
\r
125 var quest = _questList[i + _listScroller.Position];
\r
126 SetQuest(labels, quest);
\r
127 if (quest.Count.Id == 0)
\r
129 ClearCount(labels.Count);
\r
132 SetCount(labels.Count, quest.Count);
\r
134 ResumeLayout(true);
\r
135 _listScroller.DrawMark();
\r
138 private void ClearQuest(QuestLabels labels)
\r
140 labels.Color.BackColor = DefaultBackColor;
\r
141 labels.Name.Text = labels.Progress.Text = "";
\r
142 ToolTip.SetToolTip(labels.Name, "");
\r
145 private void ClearCount(Label label)
\r
148 label.ForeColor = Color.Black;
\r
149 ToolTip.SetToolTip(label, "");
\r
152 private void SetQuest(QuestLabels labels, QuestStatus quest)
\r
154 labels.Color.BackColor = quest.Color;
\r
155 labels.Name.Text = quest.Name;
\r
156 labels.Progress.Text = $"{quest.Progress:D}%";
\r
157 ToolTip.SetToolTip(labels.Name, quest.ToToolTip());
\r
160 private void SetCount(Label label, QuestCount count)
\r
162 label.Text = " " + count;
\r
163 label.ForeColor = count.Cleared ? CUDColors.Red : Color.Black;
\r
164 ToolTip.SetToolTip(label, count.ToToolTip());
\r