OSDN Git Service

イベント海域のマップのクリア後に海域選択画面でエラーになるのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ListForm.cs
index 5ad98a9..42ec533 100644 (file)
@@ -17,6 +17,7 @@ using System.Collections.Generic;
 using System.Drawing;\r
 using System.Linq;\r
 using System.Windows.Forms;\r
+using KancolleSniffer.View;\r
 using static System.Math;\r
 \r
 namespace KancolleSniffer\r
@@ -25,6 +26,7 @@ namespace KancolleSniffer
     {\r
         private readonly Sniffer _sniffer;\r
         private readonly Config _config;\r
+        private readonly CheckBox[] _shipTypeCheckBoxes;\r
         public const int PanelWidth = 217;\r
 \r
         public enum SortOrder\r
@@ -44,23 +46,44 @@ namespace KancolleSniffer
             InitializeComponent();\r
             _sniffer = sniffer;\r
             _config = config;\r
+            _shipTypeCheckBoxes = new[]\r
+            {\r
+                checkBoxSTypeBattleShip,\r
+                checkBoxSTypeAircraftCarrier,\r
+                checkBoxSTypeHeavyCruiser,\r
+                checkBoxSTypeLightCruiser,\r
+                checkBoxSTypeDestroyer,\r
+                checkBoxSTypeEscort,\r
+                checkBoxSTypeSubmarine,\r
+                checkBoxSTypeAuxiliary\r
+            };\r
+            battleResultPanel.HpLabelClick += ToggleHpPercent;\r
+            shipListPanel.HpLabelClick += ToggleHpPercent;\r
             var swipe = new SwipeScrollify();\r
             swipe.AddShipListPanel(shipListPanel);\r
             swipe.AddTreeView(itemTreeView);\r
             swipe.AddPanel(fleetPanel);\r
         }\r
 \r
+        /// <summary>\r
+        /// パネルのz-orderがくるうのを避ける\r
+        /// https://stackoverflow.com/a/5777090/1429506\r
+        /// </summary>\r
+        private void ListForm_Shown(object sender, EventArgs e)\r
+        {\r
+            // ReSharper disable once NotAccessedVariable\r
+            IntPtr handle;\r
+            foreach (Control panel in Controls)\r
+                // ReSharper disable once RedundantAssignment\r
+                handle = panel.Handle;\r
+        }\r
+\r
         public void UpdateList()\r
         {\r
             panelItemHeader.Visible = InItemList || InAntiAir || InBattleResult || InMiscText;\r
             panelGroupHeader.Visible = InGroupConfig;\r
             panelRepairHeader.Visible = InRepairList;\r
             panelFleetHeader.Visible = InFleetInfo;\r
-            foreach (var panel in new[]{panelItemHeader, panelGroupHeader, panelRepairHeader, panelFleetHeader})\r
-            {\r
-                if (panel.Visible)\r
-                    panel.BringToFront();\r
-            }\r
             // SwipeScrollifyが誤作動するのでEnabledも切り替える\r
             shipListPanel.Visible = shipListPanel.Enabled = InShipStatus || InGroupConfig || InRepairList;\r
             itemTreeView.Visible = itemTreeView.Enabled = InItemList;\r
@@ -85,25 +108,37 @@ namespace KancolleSniffer
             {\r
                 richTextBoxMiscText.Text = _sniffer.MiscText;\r
             }\r
-            else\r
+            else if (InShipStatus || InGroupConfig || InRepairList)\r
             {\r
                 SetHeaderSortOrder();\r
-                shipListPanel.Update(_sniffer, comboBoxGroup.Text, _config.ShipList.SortOrder, _config.ShipList.ShipType);\r
+                shipListPanel.Update(_sniffer, comboBoxGroup.Text, _config.ShipList);\r
+            }\r
+            if (shipListPanel.GroupUpdated)\r
+            {\r
+                StoreShipGroupToConfig();\r
+                _config.Save();\r
+                shipListPanel.GroupUpdated = false;\r
             }\r
         }\r
 \r
         public void UpdateAirBattleResult()\r
         {\r
-            airBattleResultPanel.ShowResultAutomatic = true;\r
-            airBattleResultPanel.SetResult(_sniffer.Battle.AirBattleResults);\r
+            airBattleResultPanel.ShowResultAutomatic = (_config.Spoilers & Spoiler.AirBattleResult) != 0;\r
+            airBattleResultPanel.SetResult(_sniffer);\r
         }\r
 \r
         public void UpdateBattleResult()\r
         {\r
-            battleResultPanel.SetShowHpPercent(shipListPanel.ShowHpInPercent);\r
+            battleResultPanel.Spoilers = _config.Spoilers;\r
             battleResultPanel.Update(_sniffer);\r
         }\r
 \r
+        public void UpdateCellInfo()\r
+        {\r
+            battleResultPanel.Spoilers = _config.Spoilers;\r
+            battleResultPanel.UpdateCellInfo(_sniffer.CellInfo);\r
+        }\r
+\r
         private void SetHeaderSortOrder()\r
         {\r
             switch (_config.ShipList.SortOrder)\r
@@ -131,7 +166,7 @@ namespace KancolleSniffer
             }\r
         }\r
 \r
-        private bool InShipStatus => Array.Exists(new[] {"全", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x);\r
+        private bool InShipStatus => Array.Exists(new[] {"全", "A", "B", "C", "D"}, x => comboBoxGroup.Text == x);\r
 \r
         private bool InGroupConfig => comboBoxGroup.Text == "分類";\r
 \r
@@ -149,22 +184,21 @@ namespace KancolleSniffer
 \r
         private void ShipListForm_Load(object sender, EventArgs e)\r
         {\r
-            shipListPanel.Width = itemTreeView.Width = fleetPanel.Width =\r
-                (int)Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 + SystemInformation.VerticalScrollBarWidth;\r
-            Width = shipListPanel.Width + 12 + (Width - ClientSize.Width);\r
+            /* DPIではなくズームしたときにパネルは大きくなるがScrollBarはそのままなので隙間ができる。\r
+               そこでScrollBarの幅に合わせて全体の横幅を設定し直す。*/\r
+            Width = (int)Round((PanelWidth + 12 /* PanelとFrameの内側 */) * ShipLabel.ScaleFactor.Width) +\r
+                    SystemInformation.VerticalScrollBarWidth + 2 /* 縁の幅 */ + Width - ClientSize.Width;\r
             MinimumSize = new Size(Width, 0);\r
             MaximumSize = new Size(Width, int.MaxValue);\r
             var config = _config.ShipList;\r
-            checkBoxShipType.Checked = config.ShipType;\r
             if (config.ShowHpInPercent)\r
-                shipListPanel.ToggleHpPercent();\r
-            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
             {\r
-                shipListPanel.GroupSettings[i] = i < config.ShipGroup.Count\r
-                    ? new HashSet<int>(config.ShipGroup[i])\r
-                    : new HashSet<int>();\r
+                shipListPanel.ToggleHpPercent();\r
+                battleResultPanel.ToggleHpPercent();\r
             }\r
-            comboBoxGroup.SelectedItem = config.Mode ?? "全員";\r
+            LoadShipGroupFromConfig();\r
+            comboBoxGroup.SelectedItem = config.Mode ?? "全艦";\r
+            SetCheckBoxSTypeSate();\r
             if (config.Location.X == int.MinValue)\r
                 return;\r
             var bounds = new Rectangle(config.Location, config.Size);\r
@@ -173,27 +207,50 @@ namespace KancolleSniffer
             Height = bounds.Height;\r
         }\r
 \r
+        private void LoadShipGroupFromConfig()\r
+        {\r
+            var group = _config.ShipList.ShipGroup;\r
+            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
+                shipListPanel.GroupSettings[i] = i < group.Count ? new HashSet<int>(group[i]) : new HashSet<int>();\r
+        }\r
+\r
+        private void SetCheckBoxSTypeSate()\r
+        {\r
+            for (var type = 0; type < _shipTypeCheckBoxes.Length; type++)\r
+                _shipTypeCheckBoxes[type].Checked = ((int)_config.ShipList.ShipCategories & (1 << type)) != 0;\r
+            checkBoxSTypeAll.Checked = _config.ShipList.ShipCategories == ShipCategory.All;\r
+            checkBoxSTypeDetails.Checked = _config.ShipList.ShipType;\r
+        }\r
+\r
         private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e)\r
         {\r
             e.Cancel = true;\r
             if (!Visible)\r
                 return;\r
             var config = _config.ShipList;\r
-            config.ShowHpInPercent = shipListPanel.ShowHpInPercent;\r
-            var all = _sniffer.ShipList.Select(s => s.Id).ToArray();\r
-            config.ShipGroup.Clear();\r
-            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
-            {\r
-                if (all.Length > 0)\r
-                    shipListPanel.GroupSettings[i].IntersectWith(all);\r
-                config.ShipGroup.Add(shipListPanel.GroupSettings[i].ToList());\r
-            }\r
+            StoreShipGroupToConfig();\r
             var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;\r
             config.Location = bounds.Location;\r
             config.Size = bounds.Size;\r
             config.Mode = (string)comboBoxGroup.SelectedItem;\r
             if (e.CloseReason != CloseReason.FormOwnerClosing)\r
+            {\r
                 Hide();\r
+                _config.Save();\r
+            }\r
+        }\r
+\r
+        private void StoreShipGroupToConfig()\r
+        {\r
+            var all = _sniffer.ShipList.Select(s => s.Id).ToArray();\r
+            var group = _config.ShipList.ShipGroup;\r
+            group.Clear();\r
+            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
+            {\r
+                if (all.Length > 0)\r
+                    shipListPanel.GroupSettings[i].IntersectWith(all);\r
+                group.Add(shipListPanel.GroupSettings[i].ToList());\r
+            }\r
         }\r
 \r
         public void ShowShip(int id)\r
@@ -212,13 +269,6 @@ namespace KancolleSniffer
             }\r
         }\r
 \r
-        private void checkBoxShipType_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            _config.ShipList.ShipType = checkBoxShipType.Checked;\r
-            UpdateList();\r
-            SetActiveControl();\r
-        }\r
-\r
         private void comboBoxGroup_DropDownClosed(object sender, EventArgs e)\r
         {\r
             SetActiveControl();\r
@@ -229,6 +279,8 @@ namespace KancolleSniffer
             UpdateList();\r
             SetActiveControl();\r
             copyToolStripMenuItem.Enabled = InShipStatus | InItemList;\r
+            if (!(InShipStatus || InGroupConfig || InRepairList))\r
+                SetPanelSTypeState(false);\r
         }\r
 \r
         private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e)\r
@@ -318,10 +370,12 @@ namespace KancolleSniffer
             Clipboard.SetText(TextGenerator.GenerateShipList(shipListPanel.CurrentShipList));\r
         }\r
 \r
+        // ReSharper disable IdentifierTypo\r
         private void kantaiSarashiToolStripMenuItem_Click(object sender, EventArgs e)\r
         {\r
             Clipboard.SetText(TextGenerator.GenerateKantaiSarashiData(shipListPanel.CurrentShipList));\r
         }\r
+        // ReSharper enable IdentifierTypo\r
 \r
         private void labelFleet_Click(object sender, EventArgs e)\r
         {\r
@@ -330,7 +384,54 @@ namespace KancolleSniffer
 \r
         private void labelHeaderHp_Click(object sender, EventArgs e)\r
         {\r
+            ToggleHpPercent();\r
+        }\r
+\r
+        private void ToggleHpPercent()\r
+        {\r
+            _config.ShipList.ShowHpInPercent = !_config.ShipList.ShowHpInPercent;\r
             shipListPanel.ToggleHpPercent();\r
+            battleResultPanel.ToggleHpPercent();\r
+        }\r
+\r
+        private void labelSTypeButton_Click(object sender, EventArgs e)\r
+        {\r
+            SetPanelSTypeState(!panelSType.Visible);\r
+        }\r
+\r
+        private void checkBoxSType_Click(object sender, EventArgs e)\r
+        {\r
+            _config.ShipList.ShipCategories = SelectedShipTypes;\r
+            UpdateList();\r
+            SetActiveControl();\r
+        }\r
+\r
+        private ShipCategory SelectedShipTypes =>\r
+            (ShipCategory)_shipTypeCheckBoxes.Select((cb, type) => cb.Checked ? 1 << type : 0).Sum();\r
+\r
+        private void checkBoxSTypeAll_Click(object sender, EventArgs e)\r
+        {\r
+            foreach (var checkBox in _shipTypeCheckBoxes)\r
+                checkBox.Checked = checkBoxSTypeAll.Checked;\r
+            checkBoxSType_Click(sender, e);\r
+        }\r
+\r
+        private void panelSType_Click(object sender, EventArgs e)\r
+        {\r
+            SetPanelSTypeState(false);\r
+        }\r
+\r
+        private void SetPanelSTypeState(bool visible)\r
+        {\r
+            panelSType.Visible = visible;\r
+            labelSTypeButton.BackColor = visible ? CustomColors.ActiveButtonColor : DefaultBackColor;\r
+        }\r
+\r
+        private void checkBoxSTypeDetails_Click(object sender, EventArgs e)\r
+        {\r
+            _config.ShipList.ShipType = checkBoxSTypeDetails.Checked;\r
+            UpdateList();\r
+            SetActiveControl();\r
         }\r
     }\r
 }
\ No newline at end of file