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 KancolleSniffer.View;
\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 private readonly MainForm _main;
\r
29 private readonly MainForm.TimeOutChecker _suppressActivate;
\r
30 private readonly CheckBox[] _shipTypeCheckBoxes;
\r
31 public const int PanelWidth = 217;
\r
33 public enum SortOrder
\r
40 ExpToNextAscend = ExpToNext,
\r
45 public ListForm(MainForm main)
\r
47 InitializeComponent();
\r
49 _sniffer = main.Sniffer;
\r
50 _config = main.Config;
\r
51 _suppressActivate = main.SuppressActivate;
\r
52 _shipTypeCheckBoxes = new[]
\r
54 checkBoxSTypeBattleShip,
\r
55 checkBoxSTypeAircraftCarrier,
\r
56 checkBoxSTypeHeavyCruiser,
\r
57 checkBoxSTypeLightCruiser,
\r
58 checkBoxSTypeDestroyer,
\r
59 checkBoxSTypeEscort,
\r
60 checkBoxSTypeSubmarine,
\r
61 checkBoxSTypeAuxiliary
\r
63 battleResultPanel.HpLabelClick += ToggleHpPercent;
\r
64 shipListPanel.HpLabelClick += ToggleHpPercent;
\r
65 var swipe = new SwipeScrollify();
\r
66 swipe.AddShipListPanel(shipListPanel);
\r
67 swipe.AddTreeView(itemTreeView);
\r
68 swipe.AddPanel(fleetPanel);
\r
71 public void UpdateList()
\r
73 SetHeaderVisibility();
\r
74 SetPanelVisibility();
\r
77 itemTreeView.SetNodes(_sniffer.ItemList);
\r
79 else if (InFleetInfo)
\r
81 fleetPanel.Update(_sniffer);
\r
85 antiAirPanel.Update(_sniffer);
\r
87 else if (InMiscText)
\r
89 richTextBoxMiscText.Text = _sniffer.MiscText;
\r
91 else if (InShipStatus || InGroupConfig || InRepairList)
\r
93 SetHeaderSortOrder();
\r
94 shipListPanel.Update(_sniffer, comboBoxGroup.Text, _config.ShipList);
\r
96 if (shipListPanel.GroupUpdated)
\r
98 StoreShipGroupToConfig();
\r
100 shipListPanel.GroupUpdated = false;
\r
104 private class Visibility
\r
106 public Control Control { get; }
\r
107 public bool Visible { get; }
\r
109 public Visibility(Control control, bool visible)
\r
116 private void SetHeaderVisibility()
\r
118 var headers = new[]
\r
120 new Visibility(panelItemHeader, InItemList || InAntiAir || InBattleResult || InMiscText),
\r
121 new Visibility(panelGroupHeader, InGroupConfig),
\r
122 new Visibility(panelRepairHeader, InRepairList),
\r
123 new Visibility(panelFleetHeader, InFleetInfo)
\r
125 foreach (var header in headers)
\r
127 header.Control.Visible = header.Visible;
\r
128 if (header.Visible)
\r
129 header.Control.BringToFront();
\r
133 private void SetPanelVisibility()
\r
137 new Visibility(shipListPanel, InShipStatus || InGroupConfig || InRepairList),
\r
138 new Visibility(itemTreeView, InItemList),
\r
139 new Visibility(fleetPanel, InFleetInfo),
\r
140 new Visibility(antiAirPanel, InAntiAir),
\r
141 new Visibility(airBattleResultPanel, InBattleResult),
\r
142 new Visibility(battleResultPanel, InBattleResult),
\r
143 new Visibility(richTextBoxMiscText, InMiscText)
\r
145 foreach (var panel in panels)
\r
147 // SwipeScrollifyが誤作動するのでEnabledも切り替える
\r
148 panel.Control.Visible = panel.Control.Enabled = panel.Visible;
\r
152 public void UpdateAirBattleResult()
\r
154 airBattleResultPanel.ShowResultAutomatic = (_config.Spoilers & Spoiler.AirBattleResult) != 0;
\r
155 airBattleResultPanel.SetResult(_sniffer);
\r
158 public void UpdateBattleResult()
\r
160 battleResultPanel.Spoilers = _config.Spoilers;
\r
161 battleResultPanel.Update(_sniffer);
\r
164 public void UpdateCellInfo()
\r
166 battleResultPanel.Spoilers = _config.Spoilers;
\r
167 battleResultPanel.UpdateCellInfo(_sniffer.CellInfo);
\r
170 private void SetHeaderSortOrder()
\r
172 switch (_config.ShipList.SortOrder)
\r
174 case SortOrder.None:
\r
175 labelHeaderCond.Text = "cond";
\r
176 labelHeaderExp.Text = "Exp";
\r
178 case SortOrder.CondAscend:
\r
179 labelHeaderCond.Text = "cond▴";
\r
180 labelHeaderExp.Text = "Exp";
\r
182 case SortOrder.CondDescend:
\r
183 labelHeaderCond.Text = "cond▾";
\r
184 labelHeaderExp.Text = "Exp";
\r
186 case SortOrder.ExpToNextAscend:
\r
187 labelHeaderCond.Text = "cond";
\r
188 labelHeaderExp.Text = "Exp▴";
\r
190 case SortOrder.ExpToNextDescend:
\r
191 labelHeaderCond.Text = "cond";
\r
192 labelHeaderExp.Text = "Exp▾";
\r
197 private bool InShipStatus => Array.Exists(new[] {"全艦", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x);
\r
199 private bool InGroupConfig => comboBoxGroup.Text == "分類";
\r
201 private bool InRepairList => comboBoxGroup.Text == "修復";
\r
203 private bool InItemList => comboBoxGroup.Text == "装備";
\r
205 private bool InFleetInfo => comboBoxGroup.Text == "艦隊";
\r
207 private bool InAntiAir => comboBoxGroup.Text == "対空";
\r
209 private bool InBattleResult => comboBoxGroup.Text == "戦況";
\r
211 private bool InMiscText => comboBoxGroup.Text == "情報";
\r
213 private void ListForm_Load(object sender, EventArgs e)
\r
215 /* DPIではなくズームしたときにパネルは大きくなるがScrollBarはそのままなので隙間ができる。
\r
216 そこでScrollBarの幅に合わせて全体の横幅を設定し直す。*/
\r
217 Width = Scaler.ScaleWidth(PanelWidth + 12 /* PanelとFrameの内側 */) +
\r
218 SystemInformation.VerticalScrollBarWidth + 2 /* 縁の幅 */ + Width - ClientSize.Width;
\r
219 MinimumSize = new Size(Width, 0);
\r
220 MaximumSize = new Size(Width, int.MaxValue);
\r
221 var config = _config.ShipList;
\r
222 if (config.ShowHpInPercent)
\r
224 shipListPanel.ToggleHpPercent();
\r
225 battleResultPanel.ToggleHpPercent();
\r
227 LoadShipGroupFromConfig();
\r
228 comboBoxGroup.SelectedItem = config.Mode ?? "全艦";
\r
229 SetCheckBoxSTypeSate();
\r
230 if (config.Location.X == int.MinValue)
\r
232 var bounds = new Rectangle(config.Location, config.Size);
\r
233 if (MainForm.IsTitleBarOnAnyScreen(bounds.Location))
\r
234 Location = bounds.Location;
\r
235 Height = bounds.Height;
\r
238 private void LoadShipGroupFromConfig()
\r
240 var group = _config.ShipList.ShipGroup;
\r
241 for (var i = 0; i < GroupConfigLabels.GroupCount; i++)
\r
242 shipListPanel.GroupSettings[i] = i < group.Count ? new HashSet<int>(group[i]) : new HashSet<int>();
\r
245 private void SetCheckBoxSTypeSate()
\r
247 for (var type = 0; type < _shipTypeCheckBoxes.Length; type++)
\r
248 _shipTypeCheckBoxes[type].Checked = ((int)_config.ShipList.ShipCategories & (1 << type)) != 0;
\r
249 checkBoxSTypeAll.Checked = _config.ShipList.ShipCategories == ShipCategory.All;
\r
250 checkBoxSTypeDetails.Checked = _config.ShipList.ShipType;
\r
253 private void ListForm_FormClosing(object sender, FormClosingEventArgs e)
\r
256 if (!Visible) // 非表示のときは保存すべき情報がないのでスキップする
\r
258 var config = _config.ShipList;
\r
259 StoreShipGroupToConfig();
\r
260 var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;
\r
261 config.Location = bounds.Location;
\r
262 config.Size = bounds.Size;
\r
263 config.Mode = (string)comboBoxGroup.SelectedItem;
\r
267 public void ChangeWindowState(FormWindowState newState)
\r
271 if (newState == FormWindowState.Minimized)
\r
273 if (WindowState == FormWindowState.Normal)
\r
274 WindowState = FormWindowState.Minimized;
\r
275 if (_config.HideOnMinimized)
\r
276 ShowInTaskbar = false;
\r
280 if (WindowState == FormWindowState.Minimized)
\r
282 Application.DoEvents();
\r
283 if (_config.HideOnMinimized)
\r
284 ShowInTaskbar = true;
\r
285 WindowState = FormWindowState.Normal;
\r
290 private void ListForm_Activated(object sender, EventArgs e)
\r
292 if (_suppressActivate.Check())
\r
294 if (WindowState == FormWindowState.Minimized)
\r
296 RaiseBothWindows();
\r
299 private void RaiseBothWindows()
\r
301 _main.Owner = null;
\r
307 private void StoreShipGroupToConfig()
\r
309 var all = _sniffer.ShipList.Select(s => s.Id).ToArray();
\r
310 var group = _config.ShipList.ShipGroup;
\r
312 for (var i = 0; i < GroupConfigLabels.GroupCount; i++)
\r
314 if (all.Length > 0)
\r
315 shipListPanel.GroupSettings[i].IntersectWith(all);
\r
316 group.Add(shipListPanel.GroupSettings[i].ToList());
\r
320 public void ShowShip(int id)
\r
324 shipListPanel.ShowShip(id);
\r
326 else if (InFleetInfo)
\r
328 fleetPanel.ShowShip(id);
\r
330 else if (InAntiAir)
\r
332 antiAirPanel.ShowShip(id);
\r
336 private void comboBoxGroup_DropDownClosed(object sender, EventArgs e)
\r
338 SetActiveControl();
\r
341 private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
\r
344 SetActiveControl();
\r
345 copyToolStripMenuItem.Enabled = InShipStatus | InItemList;
\r
346 if (!(InShipStatus || InGroupConfig || InRepairList))
\r
347 SetPanelSTypeState(false);
\r
350 private void ListForm_KeyPress(object sender, KeyPressEventArgs e)
\r
352 var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'Y', 'S', 'I'},
\r
353 x => x == char.ToUpper(e.KeyChar));
\r
356 comboBoxGroup.SelectedIndex = g;
\r
360 // マウスホイールでスクロールするためにコントロールにフォーカスを合わせる。
\r
361 private void SetActiveControl()
\r
365 ActiveControl = itemTreeView;
\r
367 else if (InFleetInfo)
\r
369 ActiveControl = fleetPanel;
\r
371 else if (InAntiAir)
\r
373 ActiveControl = antiAirPanel;
\r
377 ActiveControl = shipListPanel;
\r
381 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
\r
383 Clipboard.SetText(TextGenerator.GenerateItemList(_sniffer.ItemList));
\r
386 private void textToolStripMenuItem_Click(object sender, EventArgs e)
\r
388 Clipboard.SetText(TextGenerator.GenerateFleetData(_sniffer));
\r
391 private void deckBuilderToolStripMenuItem_Click(object sender, EventArgs e)
\r
393 Clipboard.SetText(TextGenerator.GenerateDeckBuilderData(_sniffer));
\r
396 private void labelHeaderCond_Click(object sender, EventArgs e)
\r
398 var sl = _config.ShipList;
\r
399 switch (sl.SortOrder)
\r
401 case SortOrder.CondAscend:
\r
402 sl.SortOrder = SortOrder.CondDescend;
\r
404 case SortOrder.CondDescend:
\r
405 sl.SortOrder = SortOrder.None;
\r
408 sl.SortOrder = SortOrder.CondAscend;
\r
414 private void labelHeaderExp_Click(object sender, EventArgs e)
\r
416 var sl = _config.ShipList;
\r
417 switch (sl.SortOrder)
\r
419 case SortOrder.ExpToNextAscend:
\r
420 sl.SortOrder = SortOrder.ExpToNextDescend;
\r
422 case SortOrder.ExpToNextDescend:
\r
423 sl.SortOrder = SortOrder.None;
\r
426 sl.SortOrder = SortOrder.ExpToNextAscend;
\r
432 private void csvToolStripMenuItem_Click(object sender, EventArgs e)
\r
434 Clipboard.SetText(TextGenerator.GenerateShipList(shipListPanel.CurrentShipList));
\r
437 // ReSharper disable IdentifierTypo
\r
438 private void kantaiSarashiToolStripMenuItem_Click(object sender, EventArgs e)
\r
440 Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(shipListPanel.CurrentShipList));
\r
442 // ReSharper enable IdentifierTypo
\r
444 private void labelFleet_Click(object sender, EventArgs e)
\r
446 fleetPanel.ShowFleet(((Label)sender).Text);
\r
449 private void labelHeaderHp_Click(object sender, EventArgs e)
\r
454 private void ToggleHpPercent()
\r
456 _config.ShipList.ShowHpInPercent = !_config.ShipList.ShowHpInPercent;
\r
457 shipListPanel.ToggleHpPercent();
\r
458 battleResultPanel.ToggleHpPercent();
\r
461 private void labelSTypeButton_Click(object sender, EventArgs e)
\r
463 SetPanelSTypeState(!panelSType.Visible);
\r
466 private void checkBoxSType_Click(object sender, EventArgs e)
\r
468 _config.ShipList.ShipCategories = SelectedShipTypes;
\r
470 SetActiveControl();
\r
473 private ShipCategory SelectedShipTypes =>
\r
474 (ShipCategory)_shipTypeCheckBoxes.Select((cb, type) => cb.Checked ? 1 << type : 0).Sum();
\r
476 private void checkBoxSTypeAll_Click(object sender, EventArgs e)
\r
478 foreach (var checkBox in _shipTypeCheckBoxes)
\r
479 checkBox.Checked = checkBoxSTypeAll.Checked;
\r
480 checkBoxSType_Click(sender, e);
\r
483 private void panelSType_Click(object sender, EventArgs e)
\r
485 SetPanelSTypeState(false);
\r
488 private void SetPanelSTypeState(bool visible)
\r
490 panelSType.Visible = visible;
\r
491 labelSTypeButton.BackColor = visible ? CustomColors.ActiveButtonColor : DefaultBackColor;
\r
494 private void checkBoxSTypeDetails_Click(object sender, EventArgs e)
\r
496 _config.ShipList.ShipType = checkBoxSTypeDetails.Checked;
\r
498 SetActiveControl();
\r