OSDN Git Service

一覧ウィンドウで艦娘の装備を確認できるようにする
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Sat, 18 Apr 2015 00:55:29 +0000 (09:55 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Wed, 22 Apr 2015 10:56:22 +0000 (19:56 +0900)
KancolleSniffer/ItemInfo.cs
KancolleSniffer/ShipListForm.Designer.cs
KancolleSniffer/ShipListForm.cs
KancolleSniffer/Sniffer.cs

index d759777..093c680 100644 (file)
@@ -290,16 +290,20 @@ namespace KancolleSniffer
             return _itemSpecs[id];\r
         }\r
 \r
-        public ItemStatus[] GetItemList(ShipInfo ship)\r
+        public Dictionary<int, ItemStatus> ItemDict\r
+        {\r
+            get { return _itemInfo; }\r
+        }\r
+\r
+        public void SetItemOwner(ShipStatus[] shipList)\r
         {\r
             foreach (var e in _itemInfo)\r
                 e.Value.Ship = new ShipStatus();\r
-            foreach (var s in ship.ShipList)\r
+            foreach (var s in shipList)\r
             {\r
                 foreach (var id in s.Slot)\r
                     _itemInfo[id].Ship = s;\r
             }\r
-            return _itemInfo.Where(e => e.Key != -1).Select(e => e.Value).ToArray();\r
         }\r
 \r
         public void SaveState(Status status)\r
index 09a03aa..d0bcba2 100644 (file)
@@ -47,6 +47,7 @@ namespace KancolleSniffer
         {\r
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShipListForm));\r
             this.panelShipList = new System.Windows.Forms.Panel();\r
+            this.treeViewItem = new KancolleSniffer.DbTreeView();\r
             this.label1 = new System.Windows.Forms.Label();\r
             this.label2 = new System.Windows.Forms.Label();\r
             this.label4 = new System.Windows.Forms.Label();\r
@@ -65,7 +66,6 @@ namespace KancolleSniffer
             this.label10 = new System.Windows.Forms.Label();\r
             this.label11 = new System.Windows.Forms.Label();\r
             this.panelItemHeader = new System.Windows.Forms.Panel();\r
-            this.treeViewItem = new KancolleSniffer.DbTreeView();\r
             this.panelShipList.SuspendLayout();\r
             this.panelGroupHeader.SuspendLayout();\r
             this.panelRepairHeader.SuspendLayout();\r
@@ -83,6 +83,14 @@ namespace KancolleSniffer
             this.panelShipList.Size = new System.Drawing.Size(238, 263);\r
             this.panelShipList.TabIndex = 0;\r
             // \r
+            // treeViewItem\r
+            // \r
+            this.treeViewItem.Dock = System.Windows.Forms.DockStyle.Fill;\r
+            this.treeViewItem.Location = new System.Drawing.Point(0, 0);\r
+            this.treeViewItem.Name = "treeViewItem";\r
+            this.treeViewItem.Size = new System.Drawing.Size(236, 261);\r
+            this.treeViewItem.TabIndex = 0;\r
+            // \r
             // label1\r
             // \r
             this.label1.AutoSize = true;\r
@@ -200,7 +208,8 @@ namespace KancolleSniffer
             "D",\r
             "分類",\r
             "修復",\r
-            "装備"});\r
+            "装備",\r
+            "装着"});\r
             this.comboBoxGroup.Location = new System.Drawing.Point(6, 4);\r
             this.comboBoxGroup.Name = "comboBoxGroup";\r
             this.comboBoxGroup.Size = new System.Drawing.Size(48, 20);\r
@@ -262,14 +271,6 @@ namespace KancolleSniffer
             this.panelItemHeader.Size = new System.Drawing.Size(166, 19);\r
             this.panelItemHeader.TabIndex = 0;\r
             // \r
-            // treeViewItem\r
-            // \r
-            this.treeViewItem.Dock = System.Windows.Forms.DockStyle.Fill;\r
-            this.treeViewItem.Location = new System.Drawing.Point(0, 0);\r
-            this.treeViewItem.Name = "treeViewItem";\r
-            this.treeViewItem.Size = new System.Drawing.Size(236, 261);\r
-            this.treeViewItem.TabIndex = 0;\r
-            // \r
             // ShipListForm\r
             // \r
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);\r
index 2526ed2..137891e 100644 (file)
@@ -40,6 +40,8 @@ namespace KancolleSniffer
         private readonly List<Panel> _checkBoxPanelList = new List<Panel>();\r
         private readonly List<ShipLabel[]> _repairLabelList = new List<ShipLabel[]>();\r
         private readonly List<Panel> _repairPanelList = new List<Panel>();\r
+        private readonly List<ShipLabel[]> _equipLabelList = new List<ShipLabel[]>();\r
+        private readonly List<Panel> _equipPanelList = new List<Panel>();\r
         public const int GroupCount = 4;\r
         private readonly HashSet<int>[] _groupSettings = new HashSet<int>[GroupCount];\r
         private TreeNode _itemTreeNode;\r
@@ -59,12 +61,15 @@ namespace KancolleSniffer
             if (InItemList())\r
             {\r
                 HideShipLabels();\r
-                if (CreateItemList())\r
+                if (CreateItemNodes())\r
                     SetTreeViewItem();\r
             }\r
             else\r
             {\r
-                CreateShipList();\r
+                if (InEquip())\r
+                    CreateEquip();\r
+                else\r
+                    CreateShipList();\r
                 CreateListLabels();\r
                 SetShipLabels();\r
             }\r
@@ -89,6 +94,31 @@ namespace KancolleSniffer
             _shipList = ships.Concat(types).OrderBy(s => s, new CompareShip(true, InRepairList())).ToArray();\r
         }\r
 \r
+        private void CreateEquip()\r
+        {\r
+            var list = new List<ShipStatus>();\r
+            var fleet = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
+            for (var i = 0; i < fleet.Length; i++)\r
+            {\r
+                list.Add(new ShipStatus {Spec = new ShipSpec {Name = fleet[i]}, Level = 1000});\r
+                foreach (var s in _sniffer.GetShipStatuses(i))\r
+                {\r
+                    s.Fleet = -1;\r
+                    list.Add(s);\r
+                    list.AddRange(\r
+                        s.Slot.Where(id => id != -1).Select(\r
+                            id => CreateDummyEntry(_sniffer.Item.ItemDict[id].Spec.Name, 500))\r
+                            .DefaultIfEmpty(CreateDummyEntry("なし", 500)));\r
+                }\r
+            }\r
+            _shipList = list.ToArray();\r
+        }\r
+\r
+        private ShipStatus CreateDummyEntry(string name, int level)\r
+        {\r
+            return new ShipStatus {Spec = new ShipSpec {Name = name}, Level = level};\r
+        }\r
+\r
         private IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships)\r
         {\r
             var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == comboBoxGroup.Text);\r
@@ -122,7 +152,7 @@ namespace KancolleSniffer
             }\r
         }\r
 \r
-        private bool CreateItemList()\r
+        private bool CreateItemNodes()\r
         {\r
             var itemList = _sniffer.ItemList;\r
             if (_prevItemList != null && _prevItemList.SequenceEqual(itemList, new ItemStatusComparer()))\r
@@ -196,6 +226,7 @@ namespace KancolleSniffer
                 CreateConfigComponents(i);\r
                 CreateRepairLabels(i);\r
                 CreateShipLabels(i);\r
+                CreateEquipLabels(i);\r
             }\r
             panelShipList.ResumeLayout();\r
         }\r
@@ -343,11 +374,42 @@ namespace KancolleSniffer
             }\r
         }\r
 \r
+        private void CreateEquipLabels(int i)\r
+        {\r
+            var y = 3 + (LineHeight - 2) * i;\r
+            var lbp = new Panel\r
+            {\r
+                Location = new Point(0, y - 2),\r
+                Size = new Size(PanelWidth, LineHeight - 2),\r
+                BackColor = ShipLabels.ColumnColors[(i + 1) % 2],\r
+                Visible = false\r
+            };\r
+            lbp.Scale(ShipLabel.ScaleFactor);\r
+            lbp.Tag = lbp.Location.Y;\r
+            var labels = new[]\r
+            {\r
+                new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
+                new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
+                new ShipLabel {Location = new Point(40, 2), AutoSize = true}\r
+            };\r
+            _equipLabelList.Add(labels);\r
+            _equipPanelList.Add(lbp);\r
+            // ReSharper disable once CoVariantArrayConversion\r
+            lbp.Controls.AddRange(labels);\r
+            panelShipList.Controls.Add(lbp);\r
+            foreach (var label in labels)\r
+            {\r
+                label.Scale();\r
+                label.PresetColor =\r
+                    label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2];\r
+            }\r
+        }\r
+\r
         private void SetShipLabels()\r
         {\r
             panelGroupHeader.Visible = InGroupConfig();\r
             panelRepairHeader.Visible = InRepairList();\r
-            treeViewItem.Visible = InItemList();\r
+            panelItemHeader.Visible = InEquip();\r
             panelShipList.SuspendLayout();\r
             for (var i = 0; i < _shipList.Length; i++)\r
             {\r
@@ -357,6 +419,8 @@ namespace KancolleSniffer
                     _checkBoxPanelList[i].Visible = false;\r
                 if (!InRepairList())\r
                     _repairPanelList[i].Visible = false;\r
+                if (!InEquip())\r
+                    _equipPanelList[i].Visible = false;\r
             }\r
             for (var i = 0; i < _shipList.Length; i++)\r
             {\r
@@ -366,12 +430,13 @@ namespace KancolleSniffer
                     SetGroupConfig(i);\r
                 if (InRepairList())\r
                     SetRepairList(i);\r
+                if (InEquip())\r
+                    SetEquip(i);\r
             }\r
             for (var i = _shipList.Length; i < _labelPanelList.Count; i++)\r
             {\r
-                _labelPanelList[i].Visible = false;\r
-                _checkBoxPanelList[i].Visible = false;\r
-                _repairPanelList[i].Visible = false;\r
+                _labelPanelList[i].Visible = _checkBoxPanelList[i].Visible =\r
+                    _repairPanelList[i].Visible = _equipPanelList[i].Visible = false;\r
             }\r
             panelShipList.ResumeLayout();\r
         }\r
@@ -404,7 +469,7 @@ namespace KancolleSniffer
                 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + panelShipList.AutoScrollPosition.Y);\r
             var s = _shipList[i];\r
             var labels = _labelList[i];\r
-            for (var c = 0; c < 6; c++)\r
+            for (var c = 0; c < 4; c++)\r
             {\r
                 labels[c].Text = "";\r
                 labels[c].BackColor = labels[c].PresetColor;\r
@@ -414,6 +479,33 @@ namespace KancolleSniffer
             lbp.Visible = true;\r
         }\r
 \r
+        private void SetEquip(int i)\r
+        {\r
+            var lbp = _equipPanelList[i];\r
+            if (!lbp.Visible)\r
+                lbp.Location = new Point(lbp.Left, (int)lbp.Tag + panelShipList.AutoScrollPosition.Y);\r
+            var s = _shipList[i];\r
+            var labels = _equipLabelList[i];\r
+            switch (s.Level)\r
+            {\r
+                case 1000:\r
+                    labels[0].Text = s.Name;\r
+                    labels[1].SetName("");\r
+                    labels[2].Text = "";\r
+                    break;\r
+                case 500:\r
+                    labels[2].Text = s.Name;\r
+                    labels[0].Text = "";\r
+                    labels[1].SetName("");\r
+                    break;\r
+                default:\r
+                    labels[1].SetName(s);\r
+                    labels[0].Text = labels[2].Text = "";\r
+                    break;\r
+            }\r
+            lbp.Visible = true;\r
+        }\r
+\r
         private void SetGroupConfig(int i)\r
         {\r
             var cbp = _checkBoxPanelList[i];\r
@@ -460,7 +552,8 @@ namespace KancolleSniffer
         {\r
             panelShipList.SuspendLayout();\r
             for (var i = 0; i < _shipList.Length; i++)\r
-                _labelPanelList[i].Visible = _checkBoxPanelList[i].Visible = _repairPanelList[i].Visible = false;\r
+                _labelPanelList[i].Visible = _checkBoxPanelList[i].Visible =\r
+                    _repairPanelList[i].Visible = _equipPanelList[i].Visible = false;\r
             panelShipList.ResumeLayout();\r
         }\r
 \r
@@ -530,6 +623,11 @@ namespace KancolleSniffer
             return comboBoxGroup.Text == "装備";\r
         }\r
 \r
+        private bool InEquip()\r
+        {\r
+            return comboBoxGroup.Text == "装着";\r
+        }\r
+\r
         private void ShipListForm_Load(object sender, EventArgs e)\r
         {\r
             panelShipList.Width = (int)Math.Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 +\r
@@ -611,7 +709,8 @@ namespace KancolleSniffer
 \r
         private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e)\r
         {\r
-            var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W'}, x => x == char.ToUpper(e.KeyChar));\r
+            var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'Q'},\r
+                x => x == char.ToUpper(e.KeyChar));\r
             if (g == -1)\r
                 return;\r
             comboBoxGroup.SelectedIndex = g;\r
index 6cc34aa..55c643d 100644 (file)
@@ -16,6 +16,7 @@
 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
 \r
 using System;\r
+using System.Linq;\r
 \r
 namespace KancolleSniffer\r
 {\r
@@ -393,7 +394,11 @@ namespace KancolleSniffer
 \r
         public ItemStatus[] ItemList\r
         {\r
-            get { return _itemInfo.GetItemList(_shipInfo); }\r
+            get\r
+            {\r
+                _itemInfo.SetItemOwner(ShipList);\r
+                return (from e in _itemInfo.ItemDict where e.Key != -1 select e.Value).ToArray();\r
+            }\r
         }\r
 \r
         public AkashiTimer.RepairSpan[] GetAkashiTimers(int fleet)\r