1 // Copyright (C) 2014, 2015 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.Collections.Generic;
\r
17 using System.Drawing;
\r
19 using System.Windows.Forms;
\r
20 using static System.Math;
\r
22 namespace KancolleSniffer
\r
24 public partial class ListForm : Form
\r
26 private readonly Sniffer _sniffer;
\r
27 private readonly Config _config;
\r
28 public const int PanelWidth = 217;
\r
30 public enum SortOrder
\r
38 public ListForm(Sniffer sniffer, Config config)
\r
40 InitializeComponent();
\r
43 var swipe = new SwipeScrollify();
\r
44 swipe.AddPanel(shipListPanel);
\r
45 swipe.AddTreeView(itemTreeView);
\r
46 swipe.AddPanel(fleetPanel);
\r
49 public void UpdateList()
\r
51 panelItemHeader.Visible = InItemList || InAntiAir || InMiscText;
\r
52 panelGroupHeader.Visible = InGroupConfig;
\r
53 panelRepairHeader.Visible = InRepairList;
\r
54 panelFleetHeader.Visible = InFleetInfo;
\r
55 // SwipeScrollifyが誤作動するのでEnabledも切り替える
\r
56 shipListPanel.Visible = shipListPanel.Enabled = InShipStatus || InGroupConfig || InRepairList;
\r
57 itemTreeView.Visible = itemTreeView.Enabled = InItemList;
\r
58 fleetPanel.Visible = fleetPanel.Enabled = InFleetInfo;
\r
59 antiAirPanel.Visible = antiAirPanel.Enabled = InAntiAir;
\r
60 airBattleResultPanel.Visible = airBattleResultPanel.Enabled = InAntiAir;
\r
61 richTextBoxMiscText.Visible = InMiscText;
\r
64 itemTreeView.SetNodes(_sniffer.ItemList);
\r
66 else if (InFleetInfo)
\r
68 fleetPanel.Update(_sniffer);
\r
72 antiAirPanel.Update(_sniffer);
\r
74 else if (InMiscText)
\r
76 richTextBoxMiscText.Text = _sniffer.MiscText;
\r
80 SetHeaderSortOrder();
\r
81 shipListPanel.Update(_sniffer, comboBoxGroup.Text, _config.ShipList.SortOrder, _config.ShipList.ShipType);
\r
85 public void UpdateAirBattleResult()
\r
87 airBattleResultPanel.SetResult(_sniffer.Battle.AirBattleResults);
\r
90 private void SetHeaderSortOrder()
\r
92 switch (_config.ShipList.SortOrder)
\r
94 case SortOrder.None:
\r
95 labelHeaderCond.Text = "cond";
\r
96 labelHeaderExp.Text = "Exp";
\r
98 case SortOrder.Cond:
\r
99 labelHeaderCond.Text = "cond▴";
\r
100 labelHeaderExp.Text = "Exp";
\r
102 case SortOrder.ExpToNext:
\r
103 labelHeaderCond.Text = "cond";
\r
104 labelHeaderExp.Text = "Exp▴";
\r
109 private bool InShipStatus => Array.Exists(new[] {"全員", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x);
\r
111 private bool InGroupConfig => comboBoxGroup.Text == "分類";
\r
113 private bool InRepairList => comboBoxGroup.Text == "修復";
\r
115 private bool InItemList => comboBoxGroup.Text == "装備";
\r
117 private bool InFleetInfo => comboBoxGroup.Text == "艦隊";
\r
119 private bool InAntiAir => comboBoxGroup.Text == "対空";
\r
121 private bool InMiscText => comboBoxGroup.Text == "情報";
\r
123 private void ShipListForm_Load(object sender, EventArgs e)
\r
125 shipListPanel.Width = itemTreeView.Width = fleetPanel.Width =
\r
126 (int)Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 + SystemInformation.VerticalScrollBarWidth;
\r
127 Width = shipListPanel.Width + 12 + (Width - ClientSize.Width);
\r
128 MinimumSize = new Size(Width, 0);
\r
129 MaximumSize = new Size(Width, int.MaxValue);
\r
130 var config = _config.ShipList;
\r
131 checkBoxShipType.Checked = config.ShipType;
\r
132 ActiveControl = shipListPanel;
\r
133 for (var i = 0; i < ShipListPanel.GroupCount; i++)
\r
135 shipListPanel.GroupSettings[i] = i < config.ShipGroup.Count
\r
136 ? new HashSet<int>(config.ShipGroup[i])
\r
137 : new HashSet<int>();
\r
139 comboBoxGroup.SelectedIndex = 0;
\r
140 if (config.Location.X == int.MinValue)
\r
142 var bounds = new Rectangle(config.Location, config.Size);
\r
143 if (MainForm.IsVisibleOnAnyScreen(bounds))
\r
144 Location = bounds.Location;
\r
145 Height = bounds.Height;
\r
148 private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e)
\r
153 var config = _config.ShipList;
\r
154 var all = _sniffer.ShipList.Select(s => s.Id).ToArray();
\r
155 config.ShipGroup.Clear();
\r
156 for (var i = 0; i < ShipListPanel.GroupCount; i++)
\r
158 if (all.Length > 0)
\r
159 shipListPanel.GroupSettings[i].IntersectWith(all);
\r
160 config.ShipGroup.Add(shipListPanel.GroupSettings[i].ToList());
\r
162 var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
\r
163 config.Location = bounds.Location;
\r
164 config.Size = bounds.Size;
\r
168 public void ShowShip(int id)
\r
172 shipListPanel.ShowShip(id);
\r
174 else if (InFleetInfo)
\r
176 fleetPanel.ShowShip(id);
\r
178 else if (InAntiAir)
\r
180 antiAirPanel.ShowShip(id);
\r
184 private void checkBoxShipType_CheckedChanged(object sender, EventArgs e)
\r
186 _config.ShipList.ShipType = checkBoxShipType.Checked;
\r
188 SetActiveControl();
\r
191 private void comboBoxGroup_DropDownClosed(object sender, EventArgs e)
\r
193 SetActiveControl();
\r
196 private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
\r
199 SetActiveControl();
\r
200 copyToolStripMenuItem.Enabled = InShipStatus | InItemList;
\r
203 private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e)
\r
205 var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'Y', 'I'},
\r
206 x => x == char.ToUpper(e.KeyChar));
\r
209 comboBoxGroup.SelectedIndex = g;
\r
213 // マウスホイールでスクロールするためにコントロールにフォーカスを合わせる。
\r
214 private void SetActiveControl()
\r
218 ActiveControl = itemTreeView;
\r
220 else if (InFleetInfo)
\r
222 ActiveControl = fleetPanel;
\r
224 else if (InAntiAir)
\r
226 ActiveControl = antiAirPanel;
\r
230 ActiveControl = shipListPanel;
\r
234 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
\r
236 Clipboard.SetText(TextGenerator.GenerateItemList(_sniffer.ItemList));
\r
239 private void textToolStripMenuItem_Click(object sender, EventArgs e)
\r
241 Clipboard.SetText(TextGenerator.GenerateFleetData(_sniffer));
\r
244 private void deckBuilderToolStripMenuItem_Click(object sender, EventArgs e)
\r
246 Clipboard.SetText(TextGenerator.GenerateDeckBuilderData(_sniffer));
\r
249 private void labelHeaderCond_Click(object sender, EventArgs e)
\r
251 _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.Cond ? SortOrder.None : SortOrder.Cond;
\r
255 private void labelHeaderExp_Click(object sender, EventArgs e)
\r
257 _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.ExpToNext
\r
259 : SortOrder.ExpToNext;
\r
263 private void csvToolStripMenuItem_Click(object sender, EventArgs e)
\r
265 Clipboard.SetText(TextGenerator.GenerateShipList(shipListPanel.CurrentShipList));
\r
268 private void kantaiSarashiToolStripMenuItem_Click(object sender, EventArgs e)
\r
270 Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(shipListPanel.CurrentShipList));
\r
273 private void labelFleet_Click(object sender, EventArgs e)
\r
275 fleetPanel.ShowFleet(((Label)sender).Text);
\r