X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=KancolleSniffer%2FListForm.cs;h=3b2df6dc8e58e00fbd0c0e28b6feef70edd8438f;hb=1538838b7b1c20235bc8b8ce8cd3bb1b72540c16;hp=41f4dfb3e72517e5f377cca497075719e3ba2326;hpb=f4a0cb66cb1a7cd64ec19884e96a7d5bc6b00a61;p=kancollesniffer%2FKancolleSniffer.git diff --git a/KancolleSniffer/ListForm.cs b/KancolleSniffer/ListForm.cs index 41f4dfb..3b2df6d 100644 --- a/KancolleSniffer/ListForm.cs +++ b/KancolleSniffer/ListForm.cs @@ -17,7 +17,8 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; -using static System.Math; +using KancolleSniffer.View; +using KancolleSniffer.View.ShipListPanel; namespace KancolleSniffer { @@ -25,423 +26,176 @@ namespace KancolleSniffer { private readonly Sniffer _sniffer; private readonly Config _config; - private const int LabelHeight = 12; - private const int LineHeight = 16; + private readonly MainForm _main; + private readonly MainForm.TimeOutChecker _suppressActivate; + private readonly CheckBox[] _shipTypeCheckBoxes; public const int PanelWidth = 217; - private ShipStatus[] _shipList; - private readonly List _labelList = new List(); - private readonly List _labelPanelList = new List(); - private readonly List _checkBoxesList = new List(); - private readonly List _configLabelList = new List(); - private readonly List _checkBoxPanelList = new List(); - private readonly List _repairLabelList = new List(); - private readonly List _repairPanelList = new List(); - public const int GroupCount = 4; - private readonly HashSet[] _groupSettings = new HashSet[GroupCount]; public enum SortOrder { None, Cond, + CondAscend = Cond, + CondDescend, ExpToNext, + ExpToNextAscend = ExpToNext, + ExpToNextDescend, Repair } - public ListForm(Sniffer sniffer, Config config) + public ListForm(MainForm main) { InitializeComponent(); - _sniffer = sniffer; - _config = config; + _main = main; + _sniffer = main.Sniffer; + _config = main.Config; + _suppressActivate = main.SuppressActivate; + _shipTypeCheckBoxes = new[] + { + checkBoxSTypeBattleShip, + checkBoxSTypeAircraftCarrier, + checkBoxSTypeHeavyCruiser, + checkBoxSTypeLightCruiser, + checkBoxSTypeDestroyer, + checkBoxSTypeEscort, + checkBoxSTypeSubmarine, + checkBoxSTypeAuxiliary + }; + battleResultPanel.HpLabelClick += ToggleHpPercent; + shipListPanel.HpLabelClick += ToggleHpPercent; var swipe = new SwipeScrollify(); - swipe.AddPanel(panelShipList); + swipe.AddShipListPanel(shipListPanel); swipe.AddTreeView(itemTreeView); - swipe.AddPanel(equipPanel); + swipe.AddPanel(fleetPanel); } public void UpdateList() { - panelItemHeader.Visible = InItemList || InEquip || InMiscText; - panelGroupHeader.Visible = InGroupConfig; - panelRepairHeader.Visible = InRepairList; - // SwipeScrollifyが誤作動するのでEnabledも切り替える - panelShipList.Visible = panelShipList.Enabled = InShipStatus || InGroupConfig || InRepairList; - itemTreeView.Visible = itemTreeView.Enabled = InItemList; - equipPanel.Visible = equipPanel.Enabled = InEquip; - richTextBoxMiscText.Visible = InMiscText; + SetHeaderVisibility(); + SetPanelVisibility(); if (InItemList) { itemTreeView.SetNodes(_sniffer.ItemList); } - else if (InEquip) + else if (InFleetInfo) + { + fleetPanel.Update(_sniffer); + } + else if (InAntiAir) { - equipPanel.UpdateEquip(_sniffer); + antiAirPanel.Update(_sniffer); } else if (InMiscText) { richTextBoxMiscText.Text = _sniffer.MiscText; } - else + else if (InShipStatus || InGroupConfig || InRepairList) { SetHeaderSortOrder(); - CreateShipList(); - CreateListLabels(); - SetShipLabels(); + shipListPanel.Update(_sniffer, comboBoxGroup.Text, _config.ShipList); } - } - - private void SetHeaderSortOrder() - { - switch (_config.ShipList.SortOrder) + if (shipListPanel.GroupUpdated) { - case SortOrder.None: - labelHeaderCond.Text = "cond"; - labelHeaderExp.Text = "Exp"; - break; - case SortOrder.Cond: - labelHeaderCond.Text = "cond▴"; - labelHeaderExp.Text = "Exp"; - break; - case SortOrder.ExpToNext: - labelHeaderCond.Text = "cond"; - labelHeaderExp.Text = "Exp▴"; - break; + StoreShipGroupToConfig(); + _config.Save(); + shipListPanel.GroupUpdated = false; } } - private void CreateShipList() + private class Visibility { - var ships = InRepairList ? _sniffer.RepairList : FilterByGroup(_sniffer.ShipList).ToArray(); - var order = InRepairList ? SortOrder.Repair : _config.ShipList.SortOrder; - if (!_config.ShipList.ShipType) - { - _shipList = ships.OrderBy(s => s, new CompareShip(false, order)).ToArray(); - return; - } - var types = ships.Select(s => new {Id = s.Spec.ShipType, Name = s.Spec.ShipTypeName}).Distinct(). - Select(stype => - new ShipStatus - { - Spec = new ShipSpec {Name = stype.Name, ShipType = stype.Id}, - Level = 1000, - NowHp = -1000, - Cond = -1000 - }); - _shipList = ships.Concat(types).OrderBy(s => s, new CompareShip(true, order)).ToArray(); - } + public Control Control { get; } + public bool Visible { get; } - private IEnumerable FilterByGroup(IEnumerable ships) - { - var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == comboBoxGroup.Text); - if (g == -1) - return ships; - return from s in ships where _groupSettings[g].Contains(s.Id) select s; - } - - private class CompareShip : IComparer - { - private readonly bool _type; - private readonly SortOrder _order; - - public CompareShip(bool type, SortOrder order) + public Visibility(Control control, bool visible) { - _type = type; - _order = order; - } - - public int Compare(ShipStatus a, ShipStatus b) - { - if (_type && a.Spec.ShipType != b.Spec.ShipType) - return a.Spec.ShipType - b.Spec.ShipType; - switch (_order) - { - case SortOrder.None: - case SortOrder.ExpToNext: - break; - case SortOrder.Cond: - if (a.Cond != b.Cond) - return a.Cond - b.Cond; - break; - case SortOrder.Repair: - if (a.RepairTime != b.RepairTime) - return (int)(b.RepairTime - a.RepairTime).TotalSeconds; - break; - } - if ((!_type || _order == SortOrder.ExpToNext) && a.Level != b.Level) - return b.Level - a.Level; - if (_order == SortOrder.ExpToNext && a.ExpToNext != b.ExpToNext) - return a.ExpToNext - b.ExpToNext; - if (a.Spec.SortNo != b.Spec.SortNo) - return a.Spec.SortNo - b.Spec.SortNo; - return a.Id - b.Id; + Control = control; + Visible = visible; } } - private void CreateListLabels() + private void SetHeaderVisibility() { - panelShipList.SuspendLayout(); - for (var i = _labelList.Count; i < _shipList.Length; i++) + var headers = new[] { - CreateConfigComponents(i); - CreateRepairLabels(i); - CreateShipLabels(i); - } - panelShipList.ResumeLayout(); - } - - private void CreateConfigComponents(int i) - { - var y = 3 + LineHeight * i; - var cfgp = new Panel - { - Location = new Point(0, y - 2), - Size = new Size(PanelWidth, LineHeight - 1), - BackColor = ShipLabels.ColumnColors[(i + 1) % 2], - Visible = false + new Visibility(panelItemHeader, InItemList || InAntiAir || InBattleResult || InMiscText), + new Visibility(panelGroupHeader, InGroupConfig), + new Visibility(panelRepairHeader, InRepairList), + new Visibility(panelFleetHeader, InFleetInfo) }; - cfgp.Scale(ShipLabel.ScaleFactor); - cfgp.Tag = cfgp.Location.Y; - var cfgl = new[] - { - new ShipLabel - { - Location = new Point(91, 2), - Size = new Size(23, LabelHeight), - TextAlign = ContentAlignment.MiddleRight, - }, - new ShipLabel {Location = new Point(10, 2), AutoSize = true}, - new ShipLabel {Location = new Point(1, 2), AutoSize = true} - }; - - var cb = new CheckBox[GroupCount]; - for (var j = 0; j < cb.Length; j++) - { - cb[j] = new CheckBox - { - Location = new Point(125 + j * 24, 2), - FlatStyle = FlatStyle.Flat, - Size = new Size(12, 11), - Tag = i * 10 + j - }; - cb[j].Scale(ShipLabel.ScaleFactor); - cb[j].CheckedChanged += checkboxGroup_CheckedChanged; - } - _configLabelList.Add(cfgl); - _checkBoxesList.Add(cb); - _checkBoxPanelList.Add(cfgp); - // ReSharper disable CoVariantArrayConversion - cfgp.Controls.AddRange(cfgl); - cfgp.Controls.AddRange(cb); - // ReSharper restore CoVariantArrayConversion - panelShipList.Controls.Add(cfgp); - foreach (var label in cfgl) + foreach (var header in headers) { - label.Scale(); - label.PresetColor = - label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2]; + header.Control.Visible = header.Visible; + if (header.Visible) + header.Control.BringToFront(); } } - private void CreateRepairLabels(int i) + private void SetPanelVisibility() { - var y = 3 + LineHeight * i; - const int height = LabelHeight; - var rpp = new Panel + var panels = new[] { - Location = new Point(0, y - 2), - Size = new Size(PanelWidth, LineHeight - 1), - BackColor = ShipLabels.ColumnColors[(i + 1) % 2], - Visible = false + new Visibility(shipListPanel, InShipStatus || InGroupConfig || InRepairList), + new Visibility(itemTreeView, InItemList), + new Visibility(fleetPanel, InFleetInfo), + new Visibility(antiAirPanel, InAntiAir), + new Visibility(airBattleResultPanel, InBattleResult), + new Visibility(battleResultPanel, InBattleResult), + new Visibility(richTextBoxMiscText, InMiscText) }; - rpp.Scale(ShipLabel.ScaleFactor); - rpp.Tag = rpp.Location.Y; - var rpl = new[] + foreach (var panel in panels) { - new ShipLabel {Location = new Point(118, 2), AutoSize = true, AnchorRight = true}, - new ShipLabel - { - Location = new Point(117, 2), - Size = new Size(23, height), - TextAlign = ContentAlignment.MiddleRight - }, - new ShipLabel {Location = new Point(141, 2), AutoSize = true}, - new ShipLabel {Location = new Point(186, 2), AutoSize = true}, - new ShipLabel {Location = new Point(10, 2), AutoSize = true}, - new ShipLabel {Location = new Point(1, 2), AutoSize = true} - }; - _repairLabelList.Add(rpl); - _repairPanelList.Add(rpp); -// ReSharper disable once CoVariantArrayConversion - rpp.Controls.AddRange(rpl); - panelShipList.Controls.Add(rpp); - foreach (var label in rpl) - { - label.Scale(); - label.PresetColor = - label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2]; + // SwipeScrollifyが誤作動するのでEnabledも切り替える + panel.Control.Visible = panel.Control.Enabled = panel.Visible; } } - private void CreateShipLabels(int i) + public void UpdateAirBattleResult() { - var y = 3 + LineHeight * i; - const int height = LabelHeight; - var lbp = new Panel - { - Location = new Point(0, y - 2), - Size = new Size(PanelWidth, LineHeight - 1), - BackColor = ShipLabels.ColumnColors[(i + 1) % 2], - Visible = false - }; - lbp.Scale(ShipLabel.ScaleFactor); - lbp.Tag = lbp.Location.Y; - var labels = new[] - { - new ShipLabel {Location = new Point(126, 2), AutoSize = true, AnchorRight = true}, - new ShipLabel - { - Location = new Point(129, 2), - Size = new Size(23, height), - TextAlign = ContentAlignment.MiddleRight - }, - new ShipLabel - { - Location = new Point(155, 2), - Size = new Size(23, height), - TextAlign = ContentAlignment.MiddleRight - }, - new ShipLabel - { - Location = new Point(176, 2), - Size = new Size(41, height), - TextAlign = ContentAlignment.MiddleRight - }, - new ShipLabel {Location = new Point(10, 2), AutoSize = true}, - new ShipLabel {Location = new Point(1, 2), AutoSize = true} - }; - _labelList.Add(labels); - _labelPanelList.Add(lbp); -// ReSharper disable once CoVariantArrayConversion - lbp.Controls.AddRange(labels); - panelShipList.Controls.Add(lbp); - foreach (var label in labels) - { - label.Scale(); - label.PresetColor = - label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2]; - } + airBattleResultPanel.ShowResultAutomatic = (_config.Spoilers & Spoiler.AirBattleResult) != 0; + airBattleResultPanel.SetResult(_sniffer); } - private void SetShipLabels() + public void UpdateBattleResult() { - panelShipList.SuspendLayout(); - for (var i = 0; i < _shipList.Length; i++) - { - if (!InShipStatus) - _labelPanelList[i].Visible = false; - if (!InGroupConfig) - _checkBoxPanelList[i].Visible = false; - if (!InRepairList) - _repairPanelList[i].Visible = false; - } - for (var i = 0; i < _shipList.Length; i++) - { - if (InShipStatus) - SetShipStatus(i); - if (InGroupConfig) - SetGroupConfig(i); - if (InRepairList) - SetRepairList(i); - } - for (var i = _shipList.Length; i < _labelPanelList.Count; i++) - { - _labelPanelList[i].Visible = _checkBoxPanelList[i].Visible = _repairPanelList[i].Visible = false; - } - panelShipList.ResumeLayout(); + battleResultPanel.Spoilers = _config.Spoilers; + battleResultPanel.Update(_sniffer); } - private void SetShipStatus(int i) + public void UpdateCellInfo() { - var lbp = _labelPanelList[i]; - if (!lbp.Visible) - lbp.Location = new Point(lbp.Left, (int)lbp.Tag + panelShipList.AutoScrollPosition.Y); - var s = _shipList[i]; - var labels = _labelList[i]; - if (s.Level == 1000) // 艦種の表示 - { - SetShipType(i); - return; - } - labels[0].SetHp(s); - labels[1].SetCond(s); - labels[2].SetLevel(s); - labels[3].SetExpToNext(s); - labels[4].SetName(s, ShipNameWidth.ShipList); - labels[5].SetFleet(s); - lbp.Visible = true; - } - - private void SetShipType(int i) - { - var lbp = _labelPanelList[i]; - if (!lbp.Visible) - lbp.Location = new Point(lbp.Left, (int)lbp.Tag + panelShipList.AutoScrollPosition.Y); - var s = _shipList[i]; - var labels = _labelList[i]; - for (var c = 0; c < 4; c++) - { - labels[c].Text = ""; - labels[c].BackColor = labels[c].PresetColor; - } - labels[4].SetName(""); - labels[5].Text = s.Name; - lbp.Visible = true; + battleResultPanel.Spoilers = _config.Spoilers; + battleResultPanel.UpdateCellInfo(_sniffer.CellInfo); } - private void SetGroupConfig(int i) + private void SetHeaderSortOrder() { - var cbp = _checkBoxPanelList[i]; - var s = _shipList[i]; - if (s.Level == 1000) - { - SetShipType(i); - cbp.Visible = false; - return; - } - if (!cbp.Visible) - cbp.Location = new Point(cbp.Left, (int)cbp.Tag + panelShipList.AutoScrollPosition.Y); - var cfgl = _configLabelList[i]; - cfgl[0].SetLevel(s); - cfgl[1].SetName(s, ShipNameWidth.GroupConfig); - cfgl[2].SetFleet(s); - var cb = _checkBoxesList[i]; - for (var j = 0; j < cb.Length; j++) - cb[j].Checked = _groupSettings[j].Contains(s.Id); - cbp.Visible = true; - } - - private void SetRepairList(int i) - { - var rpp = _repairPanelList[i]; - var s = _shipList[i]; - if (s.Level == 1000) + switch (_config.ShipList.SortOrder) { - SetShipType(i); - rpp.Visible = false; - return; + case SortOrder.None: + labelHeaderCond.Text = "cond"; + labelHeaderExp.Text = "Exp"; + break; + case SortOrder.CondAscend: + labelHeaderCond.Text = "cond▴"; + labelHeaderExp.Text = "Exp"; + break; + case SortOrder.CondDescend: + labelHeaderCond.Text = "cond▾"; + labelHeaderExp.Text = "Exp"; + break; + case SortOrder.ExpToNextAscend: + labelHeaderCond.Text = "cond"; + labelHeaderExp.Text = "Exp▴"; + break; + case SortOrder.ExpToNextDescend: + labelHeaderCond.Text = "cond"; + labelHeaderExp.Text = "Exp▾"; + break; } - if (!rpp.Visible) - rpp.Location = new Point(rpp.Left, (int)rpp.Tag + panelShipList.AutoScrollPosition.Y); - var rpl = _repairLabelList[i]; - rpl[0].SetHp(s); - rpl[1].SetLevel(s); - rpl[2].SetRepairTime(s); - rpl[3].Text = TimeSpan.FromSeconds(s.RepairSecPerHp).ToString(@"mm\:ss"); - rpl[4].SetName(s, ShipNameWidth.RepairListFull); - rpl[5].SetFleet(s); - rpp.Visible = true; } - private bool InShipStatus => Array.Exists(new[] {"全員", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x); + private bool InShipStatus => Array.Exists(new[] {"全艦", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x); private bool InGroupConfig => comboBoxGroup.Text == "分類"; @@ -449,85 +203,135 @@ namespace KancolleSniffer private bool InItemList => comboBoxGroup.Text == "装備"; - private bool InEquip => comboBoxGroup.Text == "艦隊"; + private bool InFleetInfo => comboBoxGroup.Text == "艦隊"; + + private bool InAntiAir => comboBoxGroup.Text == "対空"; + + private bool InBattleResult => comboBoxGroup.Text == "戦況"; private bool InMiscText => comboBoxGroup.Text == "情報"; - private void ShipListForm_Load(object sender, EventArgs e) + private void ListForm_Load(object sender, EventArgs e) { - panelShipList.Width = itemTreeView.Width = equipPanel.Width = - (int)Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 + SystemInformation.VerticalScrollBarWidth; - Width = panelShipList.Width + 12 + (Width - ClientSize.Width); + /* DPIではなくズームしたときにパネルは大きくなるがScrollBarはそのままなので隙間ができる。 + そこでScrollBarの幅に合わせて全体の横幅を設定し直す。*/ + Width = Scaler.ScaleWidth(PanelWidth + 12 /* PanelとFrameの内側 */) + + SystemInformation.VerticalScrollBarWidth + 2 /* 縁の幅 */ + Width - ClientSize.Width; MinimumSize = new Size(Width, 0); MaximumSize = new Size(Width, int.MaxValue); var config = _config.ShipList; - checkBoxShipType.Checked = config.ShipType; - ActiveControl = panelShipList; - for (var i = 0; i < GroupCount; i++) - _groupSettings[i] = i < config.ShipGroup.Count - ? new HashSet(config.ShipGroup[i]) - : new HashSet(); - comboBoxGroup.SelectedIndex = 0; + if (config.ShowHpInPercent) + { + shipListPanel.ToggleHpPercent(); + battleResultPanel.ToggleHpPercent(); + } + LoadShipGroupFromConfig(); + comboBoxGroup.SelectedItem = config.Mode ?? "全艦"; + SetCheckBoxSTypeSate(); if (config.Location.X == int.MinValue) return; var bounds = new Rectangle(config.Location, config.Size); - if (MainForm.IsVisibleOnAnyScreen(bounds)) + if (MainForm.IsTitleBarOnAnyScreen(bounds.Location)) Location = bounds.Location; Height = bounds.Height; } - private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e) + private void LoadShipGroupFromConfig() + { + var group = _config.ShipList.ShipGroup; + for (var i = 0; i < GroupConfigLabels.GroupCount; i++) + shipListPanel.GroupSettings[i] = i < group.Count ? new HashSet(group[i]) : new HashSet(); + } + + private void SetCheckBoxSTypeSate() + { + for (var type = 0; type < _shipTypeCheckBoxes.Length; type++) + _shipTypeCheckBoxes[type].Checked = ((int)_config.ShipList.ShipCategories & (1 << type)) != 0; + checkBoxSTypeAll.Checked = _config.ShipList.ShipCategories == ShipCategory.All; + checkBoxSTypeDetails.Checked = _config.ShipList.ShipType; + } + + private void ListForm_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; - if (!Visible) + if (!Visible) // 非表示のときは保存すべき情報がないのでスキップする return; var config = _config.ShipList; - var all = _sniffer.ShipList.Select(s => s.Id).ToArray(); - config.ShipGroup.Clear(); - for (var i = 0; i < GroupCount; i++) - { - if (all.Length > 0) - _groupSettings[i].IntersectWith(all); - config.ShipGroup.Add(_groupSettings[i].ToList()); - } + StoreShipGroupToConfig(); var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds; config.Location = bounds.Location; config.Size = bounds.Size; + config.Mode = (string)comboBoxGroup.SelectedItem; Hide(); } - public void ShowShip(int id) + public void ChangeWindowState(FormWindowState newState) { - if (InShipStatus) + if (!Visible) + return; + if (newState == FormWindowState.Minimized) { - var i = Array.FindIndex(_shipList, s => s.Id == id); - if (i == -1) - return; - var y = (int)Round(ShipLabel.ScaleFactor.Height * LineHeight * i); - panelShipList.AutoScrollPosition = new Point(0, y); + if (WindowState == FormWindowState.Normal) + WindowState = FormWindowState.Minimized; + if (_config.HideOnMinimized) + ShowInTaskbar = false; } - else if (InEquip) + else { - equipPanel.ShowShip(id); + if (WindowState == FormWindowState.Minimized) + { + Application.DoEvents(); + if (_config.HideOnMinimized) + ShowInTaskbar = true; + WindowState = FormWindowState.Normal; + } } } - private void checkBoxShipType_CheckedChanged(object sender, EventArgs e) + private void ListForm_Activated(object sender, EventArgs e) { - _config.ShipList.ShipType = checkBoxShipType.Checked; - UpdateList(); - SetActiveControl(); + if (_suppressActivate.Check()) + return; + if (WindowState == FormWindowState.Minimized) + return; + RaiseBothWindows(); } - private void checkboxGroup_CheckedChanged(object sender, EventArgs e) + private void RaiseBothWindows() { - var cb = (CheckBox)sender; - var group = (int)cb.Tag % 10; - var idx = (int)cb.Tag / 10; - if (cb.Checked) - _groupSettings[group].Add(_shipList[idx].Id); - else - _groupSettings[group].Remove(_shipList[idx].Id); + _main.Owner = null; + Owner = _main; + BringToFront(); + Owner = null; + } + + private void StoreShipGroupToConfig() + { + var all = _sniffer.ShipList.Select(s => s.Id).ToArray(); + var group = _config.ShipList.ShipGroup; + group.Clear(); + for (var i = 0; i < GroupConfigLabels.GroupCount; i++) + { + if (all.Length > 0) + shipListPanel.GroupSettings[i].IntersectWith(all); + group.Add(shipListPanel.GroupSettings[i].ToList()); + } + } + + public void ShowShip(int id) + { + if (InShipStatus) + { + shipListPanel.ShowShip(id); + } + else if (InFleetInfo) + { + fleetPanel.ShowShip(id); + } + else if (InAntiAir) + { + antiAirPanel.ShowShip(id); + } } private void comboBoxGroup_DropDownClosed(object sender, EventArgs e) @@ -540,11 +344,13 @@ namespace KancolleSniffer UpdateList(); SetActiveControl(); copyToolStripMenuItem.Enabled = InShipStatus | InItemList; + if (!(InShipStatus || InGroupConfig || InRepairList)) + SetPanelSTypeState(false); } - private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e) + private void ListForm_KeyPress(object sender, KeyPressEventArgs e) { - var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'I'}, + var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'Y', 'S', 'I'}, x => x == char.ToUpper(e.KeyChar)); if (g == -1) return; @@ -556,11 +362,21 @@ namespace KancolleSniffer private void SetActiveControl() { if (InItemList) + { ActiveControl = itemTreeView; - else if (InEquip) - ActiveControl = equipPanel; + } + else if (InFleetInfo) + { + ActiveControl = fleetPanel; + } + else if (InAntiAir) + { + ActiveControl = antiAirPanel; + } else - ActiveControl = panelShipList; + { + ActiveControl = shipListPanel; + } } private void copyToolStripMenuItem_Click(object sender, EventArgs e) @@ -580,24 +396,107 @@ namespace KancolleSniffer private void labelHeaderCond_Click(object sender, EventArgs e) { - _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.Cond ? SortOrder.None : SortOrder.Cond; + var sl = _config.ShipList; + switch (sl.SortOrder) + { + case SortOrder.CondAscend: + sl.SortOrder = SortOrder.CondDescend; + break; + case SortOrder.CondDescend: + sl.SortOrder = SortOrder.None; + break; + default: + sl.SortOrder = SortOrder.CondAscend; + break; + } UpdateList(); } private void labelHeaderExp_Click(object sender, EventArgs e) { - _config.ShipList.SortOrder = _config.ShipList.SortOrder == SortOrder.ExpToNext ? SortOrder.None : SortOrder.ExpToNext; + var sl = _config.ShipList; + switch (sl.SortOrder) + { + case SortOrder.ExpToNextAscend: + sl.SortOrder = SortOrder.ExpToNextDescend; + break; + case SortOrder.ExpToNextDescend: + sl.SortOrder = SortOrder.None; + break; + default: + sl.SortOrder = SortOrder.ExpToNextAscend; + break; + } UpdateList(); } private void csvToolStripMenuItem_Click(object sender, EventArgs e) { - Clipboard.SetText(TextGenerator.GenerateShipList(FilterByGroup(_sniffer.ShipList))); + Clipboard.SetText(TextGenerator.GenerateShipList(shipListPanel.CurrentShipList)); } + // ReSharper disable IdentifierTypo private void kantaiSarashiToolStripMenuItem_Click(object sender, EventArgs e) { - Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(FilterByGroup(_sniffer.ShipList))); + Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(shipListPanel.CurrentShipList)); + } + // ReSharper enable IdentifierTypo + + private void labelFleet_Click(object sender, EventArgs e) + { + fleetPanel.ShowFleet(((Label)sender).Text); + } + + private void labelHeaderHp_Click(object sender, EventArgs e) + { + ToggleHpPercent(); + } + + private void ToggleHpPercent() + { + _config.ShipList.ShowHpInPercent = !_config.ShipList.ShowHpInPercent; + shipListPanel.ToggleHpPercent(); + battleResultPanel.ToggleHpPercent(); + } + + private void labelSTypeButton_Click(object sender, EventArgs e) + { + SetPanelSTypeState(!panelSType.Visible); + } + + private void checkBoxSType_Click(object sender, EventArgs e) + { + _config.ShipList.ShipCategories = SelectedShipTypes; + UpdateList(); + SetActiveControl(); + } + + private ShipCategory SelectedShipTypes => + (ShipCategory)_shipTypeCheckBoxes.Select((cb, type) => cb.Checked ? 1 << type : 0).Sum(); + + private void checkBoxSTypeAll_Click(object sender, EventArgs e) + { + foreach (var checkBox in _shipTypeCheckBoxes) + checkBox.Checked = checkBoxSTypeAll.Checked; + checkBoxSType_Click(sender, e); + } + + private void panelSType_Click(object sender, EventArgs e) + { + SetPanelSTypeState(false); + } + + private void SetPanelSTypeState(bool visible) + { + panelSType.Visible = visible; + labelSTypeButton.BackColor = visible ? CustomColors.ActiveButtonColor : DefaultBackColor; + } + + private void checkBoxSTypeDetails_Click(object sender, EventArgs e) + { + _config.ShipList.ShipType = checkBoxSTypeDetails.Checked; + UpdateList(); + SetActiveControl(); } } } \ No newline at end of file