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.ShowResultAutomatic = _config.AlwaysShowResultRank;
\r
88 airBattleResultPanel.SetResult(_sniffer.Battle.AirBattleResults);
\r
91 private void SetHeaderSortOrder()
\r
93 switch (_config.ShipList.SortOrder)
\r
95 case SortOrder.None:
\r
96 labelHeaderCond.Text = "cond";
\r
97 labelHeaderExp.Text = "Exp";
\r
99 case SortOrder.Cond:
\r
100 labelHeaderCond.Text = "cond▴";
\r
101 labelHeaderExp.Text = "Exp";
\r
103 case SortOrder.ExpToNext:
\r
104 labelHeaderCond.Text = "cond";
\r
105 labelHeaderExp.Text = "Exp▴";
\r
110 private bool InShipStatus => Array.Exists(new[] {"全員", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x);
\r
112 private bool InGroupConfig => comboBoxGroup.Text == "分類";
\r
114 private bool InRepairList => comboBoxGroup.Text == "修復";
\r
116 private bool InItemList => comboBoxGroup.Text == "装備";
\r
118 private bool InFleetInfo => comboBoxGroup.Text == "艦隊";
\r
120 private bool InAntiAir => comboBoxGroup.Text == "対空";
\r
122 private bool InMiscText => comboBoxGroup.Text == "情報";
\r
124 private void ShipListForm_Load(object sender, EventArgs e)
\r
126 shipListPanel.Width = itemTreeView.Width = fleetPanel.Width =
\r
127 (int)Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 + SystemInformation.VerticalScrollBarWidth;
\r
128 Width = shipListPanel.Width + 12 + (Width - ClientSize.Width);
\r
129 MinimumSize = new Size(Width, 0);
\r
130 MaximumSize = new Size(Width, int.MaxValue);
\r
131 var config = _config.ShipList;
\r
132 checkBoxShipType.Checked = config.ShipType;
\r
133 ActiveControl = shipListPanel;
\r
134 for (var i = 0; i < ShipListPanel.GroupCount; i++)
\r
136 shipListPanel.GroupSettings[i] = i < config.ShipGroup.Count
\r
137 ? new HashSet<int>(config.ShipGroup[i])
\r
138 : new HashSet<int>();
\r
140 comboBoxGroup.SelectedIndex = 0;
\r
141 if (config.Location.X == int.MinValue)
\r
143 var bounds = new Rectangle(config.Location, config.Size);
\r
144 if (MainForm.IsVisibleOnAnyScreen(bounds))
\r
145 Location = bounds.Location;
\r
146 Height = bounds.Height;
\r
149 private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e)
\r
154 var config = _config.ShipList;
\r
155 var all = _sniffer.ShipList.Select(s => s.Id).ToArray();
\r
156 config.ShipGroup.Clear();
\r
157 for (var i = 0; i < ShipListPanel.GroupCount; i++)
\r
159 if (all.Length > 0)
\r
160 shipListPanel.GroupSettings[i].IntersectWith(all);
\r
161 config.ShipGroup.Add(shipListPanel.GroupSettings[i].ToList());
\r
163 var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
\r
164 config.Location = bounds.Location;
\r
165 config.Size = bounds.Size;
\r
169 public void ShowShip(int id)
\r
173 shipListPanel.ShowShip(id);
\r
175 else if (InFleetInfo)
\r
177 fleetPanel.ShowShip(id);
\r
179 else if (InAntiAir)
\r
181 antiAirPanel.ShowShip(id);
\r
185 private void checkBoxShipType_CheckedChanged(object sender, EventArgs e)
\r
187 _config.ShipList.ShipType = checkBoxShipType.Checked;
\r
189 SetActiveControl();
\r
192 private void comboBoxGroup_DropDownClosed(object sender, EventArgs e)
\r
194 SetActiveControl();
\r
197 private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
\r
200 SetActiveControl();
\r
201 copyToolStripMenuItem.Enabled = InShipStatus | InItemList;
\r
204 private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e)
\r
206 var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'Y', 'I'},
\r
207 x => x == char.ToUpper(e.KeyChar));
\r
210 comboBoxGroup.SelectedIndex = g;
\r
214 // マウスホイールでスクロールするためにコントロールにフォーカスを合わせる。
\r
215 private void SetActiveControl()
\r
219 ActiveControl = itemTreeView;
\r
221 else if (InFleetInfo)
\r
223 ActiveControl = fleetPanel;
\r
225 else if (InAntiAir)
\r
227 ActiveControl = antiAirPanel;
\r
231 ActiveControl = shipListPanel;
\r
235 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
\r
237 Clipboard.SetText(TextGenerator.GenerateItemList(_sniffer.ItemList));
\r
240 private void textToolStripMenuItem_Click(object sender, EventArgs e)
\r
242 Clipboard.SetText(TextGenerator.GenerateFleetData(_sniffer));
\r
245 private void deckBuilderToolStripMenuItem_Click(object sender, EventArgs e)
\r
247 Clipboard.SetText(TextGenerator.GenerateDeckBuilderData(_sniffer));
\r
250 private void labelHeaderCond_Click(object sender, EventArgs e)
\r
252 _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.Cond ? SortOrder.None : SortOrder.Cond;
\r
256 private void labelHeaderExp_Click(object sender, EventArgs e)
\r
258 _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.ExpToNext
\r
260 : SortOrder.ExpToNext;
\r
264 private void csvToolStripMenuItem_Click(object sender, EventArgs e)
\r
266 Clipboard.SetText(TextGenerator.GenerateShipList(shipListPanel.CurrentShipList));
\r
269 private void kantaiSarashiToolStripMenuItem_Click(object sender, EventArgs e)
\r
271 Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(shipListPanel.CurrentShipList));
\r
274 private void labelFleet_Click(object sender, EventArgs e)
\r
276 fleetPanel.ShowFleet(((Label)sender).Text);
\r