修订版 | 449ccebc82a489b7fe2561d7592637bddb52f021 (tree) |
---|---|
时间 | 2020-09-16 19:30:12 |
作者 | Kazuhiro Fujieda <fujieda@user...> |
Commiter | Kazuhiro Fujieda |
一覧の艦娘の分類をセカンダリに反映させるのに再起動が必要なのを直す
@@ -103,7 +103,48 @@ namespace KancolleSniffer.Forms | ||
103 | 103 | shipListPanel.ToggleHpPercent(); |
104 | 104 | battleResultPanel.ToggleHpPercent(); |
105 | 105 | } |
106 | - LoadShipGroupFromConfig(); | |
106 | + } | |
107 | + | |
108 | + private ShipListConfig GetConfig() | |
109 | + { | |
110 | + if (_isMaster) | |
111 | + { | |
112 | + SetGroup(); | |
113 | + return _config.ShipList; | |
114 | + } | |
115 | + if (_config.ListFormGroup.Count == 0) | |
116 | + return CreateSecondaryConfig(); | |
117 | + var config = _config.ListFormGroup[0]; | |
118 | + _config.ListFormGroup.RemoveAt(0); | |
119 | + config.ShipGroup = _config.ShipList.ShipGroup; | |
120 | + return config; | |
121 | + } | |
122 | + | |
123 | + private ShipListConfig CreateSecondaryConfig() | |
124 | + { | |
125 | + var src = _config.ShipList; | |
126 | + var config = new ShipListConfig | |
127 | + { | |
128 | + Mode = src.Mode, | |
129 | + ShipCategories = src.ShipCategories, | |
130 | + ShipType = src.ShipType, | |
131 | + ShowHpInPercent = src.ShowHpInPercent, | |
132 | + SortOrder = src.SortOrder, | |
133 | + Location = src.Location, | |
134 | + Size = src.Size, | |
135 | + ShipGroup = src.ShipGroup | |
136 | + }; | |
137 | + if (config.Mode == "分類" || string.IsNullOrEmpty(config.Mode)) | |
138 | + config.Mode = "全艦"; | |
139 | + return config; | |
140 | + } | |
141 | + | |
142 | + private void SetGroup() | |
143 | + { | |
144 | + var groups = _config.ShipList.ShipGroup; | |
145 | + for (var i = groups.Count; i < GroupConfigLabels.GroupCount; i++) | |
146 | + groups.Add(new List<int>()); | |
147 | + shipListPanel.GroupSettings = groups; | |
107 | 148 | } |
108 | 149 | |
109 | 150 | public void UpdateList() |
@@ -135,12 +176,25 @@ namespace KancolleSniffer.Forms | ||
135 | 176 | } |
136 | 177 | if (shipListPanel.GroupUpdated) |
137 | 178 | { |
138 | - StoreShipGroupToConfig(); | |
179 | + PurifyShipGroup(); | |
139 | 180 | _config.Save(); |
140 | 181 | shipListPanel.GroupUpdated = false; |
141 | 182 | } |
142 | 183 | } |
143 | 184 | |
185 | + private void PurifyShipGroup() | |
186 | + { | |
187 | + var all = _sniffer.ShipList.Select(s => s.Id).ToArray(); | |
188 | + if (all.Length == 0) | |
189 | + return; | |
190 | + foreach (var g in _config.ShipList.ShipGroup) | |
191 | + { | |
192 | + var filtered = g.Intersect(all).ToArray(); | |
193 | + g.Clear(); | |
194 | + g.AddRange(filtered); | |
195 | + } | |
196 | + } | |
197 | + | |
144 | 198 | private void SetHeaderVisibility() |
145 | 199 | { |
146 | 200 | static void Set(Control header, bool visible) |
@@ -287,43 +341,8 @@ namespace KancolleSniffer.Forms | ||
287 | 341 | |
288 | 342 | private void SetMinimumSize() |
289 | 343 | { |
290 | - MinimumSize = new Size(Width - Scaler.ScaleWidth(24) - SystemInformation.VerticalScrollBarWidth * (_config.Zoom - 100) / 100, 0); | |
291 | - } | |
292 | - | |
293 | - private ShipListConfig GetConfig() | |
294 | - { | |
295 | - if (_isMaster) | |
296 | - return _config.ShipList; | |
297 | - if (_config.ListFormGroup.Count == 0) | |
298 | - return CreateSecondaryConfig(); | |
299 | - var config = _config.ListFormGroup[0]; | |
300 | - _config.ListFormGroup.RemoveAt(0); | |
301 | - return config; | |
302 | - } | |
303 | - | |
304 | - private ShipListConfig CreateSecondaryConfig() | |
305 | - { | |
306 | - var src = _config.ShipList; | |
307 | - var config = new ShipListConfig | |
308 | - { | |
309 | - Mode = src.Mode, | |
310 | - ShipCategories = src.ShipCategories, | |
311 | - ShipType = src.ShipType, | |
312 | - ShowHpInPercent = src.ShowHpInPercent, | |
313 | - SortOrder = src.SortOrder, | |
314 | - Location = src.Location, | |
315 | - Size = src.Size | |
316 | - }; | |
317 | - if (config.Mode == "分類" || string.IsNullOrEmpty(config.Mode)) | |
318 | - config.Mode = "全艦"; | |
319 | - return config; | |
320 | - } | |
321 | - | |
322 | - private void LoadShipGroupFromConfig() | |
323 | - { | |
324 | - var group = _config.ShipList.ShipGroup; | |
325 | - for (var i = 0; i < GroupConfigLabels.GroupCount; i++) | |
326 | - shipListPanel.GroupSettings[i] = i < group.Count ? new HashSet<int>(group[i]) : new HashSet<int>(); | |
344 | + MinimumSize = new Size(Width - Scaler.ScaleWidth(24) - | |
345 | + SystemInformation.VerticalScrollBarWidth * (_config.Zoom - 100) / 100, 0); | |
327 | 346 | } |
328 | 347 | |
329 | 348 | private void SetCheckBoxSTypeState() |
@@ -354,7 +373,7 @@ namespace KancolleSniffer.Forms | ||
354 | 373 | |
355 | 374 | private void SaveMasterState() |
356 | 375 | { |
357 | - StoreShipGroupToConfig(); | |
376 | + PurifyShipGroup(); | |
358 | 377 | _listConfig.Visible = Visible && WindowState == FormWindowState.Normal; |
359 | 378 | SaveBounds(_listConfig); // 最小化時は以前のサイズを記録する |
360 | 379 | } |
@@ -366,6 +385,7 @@ namespace KancolleSniffer.Forms | ||
366 | 385 | if (WindowState != FormWindowState.Normal) // 最小化時は次回復旧しない |
367 | 386 | return; |
368 | 387 | _listConfig.Visible = true; |
388 | + _listConfig.ShipGroup = null; | |
369 | 389 | _config.ListFormGroup.Add(_listConfig); |
370 | 390 | SaveBounds(_listConfig); |
371 | 391 | } |
@@ -419,19 +439,6 @@ namespace KancolleSniffer.Forms | ||
419 | 439 | Owner = null; |
420 | 440 | } |
421 | 441 | |
422 | - private void StoreShipGroupToConfig() | |
423 | - { | |
424 | - var all = _sniffer.ShipList.Select(s => s.Id).ToArray(); | |
425 | - var group = _config.ShipList.ShipGroup; | |
426 | - group.Clear(); | |
427 | - for (var i = 0; i < GroupConfigLabels.GroupCount; i++) | |
428 | - { | |
429 | - if (all.Length > 0) | |
430 | - shipListPanel.GroupSettings[i].IntersectWith(all); | |
431 | - group.Add(shipListPanel.GroupSettings[i].ToList()); | |
432 | - } | |
433 | - } | |
434 | - | |
435 | 442 | public void ShowShip(int id) |
436 | 443 | { |
437 | 444 | if (!Visible) |
@@ -627,7 +634,8 @@ namespace KancolleSniffer.Forms | ||
627 | 634 | |
628 | 635 | private void ListForm_ResizeEnd(object sender, EventArgs e) |
629 | 636 | { |
630 | - foreach (var panel in new IPanelResize[] {shipListPanel, antiAirPanel, airBattleResultPanel, battleResultPanel, fleetPanel}) | |
637 | + foreach (var panel in new IPanelResize[] | |
638 | + {shipListPanel, antiAirPanel, airBattleResultPanel, battleResultPanel, fleetPanel}) | |
631 | 639 | { |
632 | 640 | if (panel.Visible) |
633 | 641 | panel.ApplyResize(); |
@@ -18,7 +18,6 @@ using System.Drawing; | ||
18 | 18 | using System.Linq; |
19 | 19 | using System.Windows.Forms; |
20 | 20 | using KancolleSniffer.Forms; |
21 | -using KancolleSniffer.Model; | |
22 | 21 | |
23 | 22 | // ReSharper disable CoVariantArrayConversion |
24 | 23 |
@@ -31,7 +30,7 @@ namespace KancolleSniffer.View.ShipListPanel | ||
31 | 30 | private readonly List<ShipLabels> _labelList = new List<ShipLabels>(); |
32 | 31 | |
33 | 32 | public const int GroupCount = 4; |
34 | - public HashSet<int>[] GroupSettings { get; } = new HashSet<int>[GroupCount]; | |
33 | + public List<List<int>> GroupSettings { get; set; } | |
35 | 34 | public bool GroupUpdated { get; set; } |
36 | 35 | |
37 | 36 | public GroupConfigLabels(ShipListPanel shipListPanel) |
@@ -123,13 +122,5 @@ namespace KancolleSniffer.View.ShipListPanel | ||
123 | 122 | { |
124 | 123 | _labelList[i].BackPanel.Visible = false; |
125 | 124 | } |
126 | - | |
127 | - public IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships, string group) | |
128 | - { | |
129 | - var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == group); | |
130 | - if (g == -1) | |
131 | - return ships; | |
132 | - return from s in ships where GroupSettings[g].Contains(s.Id) select s; | |
133 | - } | |
134 | 125 | } |
135 | 126 | } |
\ No newline at end of file |
@@ -37,7 +37,12 @@ namespace KancolleSniffer.View.ShipListPanel | ||
37 | 37 | private string _mode; |
38 | 38 | private bool _hpPercent; |
39 | 39 | |
40 | - public HashSet<int>[] GroupSettings => _groupConfigLabels.GroupSettings; | |
40 | + public List<List<int>> GroupSettings | |
41 | + { | |
42 | + get => _groupConfigLabels.GroupSettings; | |
43 | + set => _groupConfigLabels.GroupSettings = value; | |
44 | + } | |
45 | + | |
41 | 46 | |
42 | 47 | public bool GroupUpdated |
43 | 48 | { |
@@ -118,7 +123,7 @@ namespace KancolleSniffer.View.ShipListPanel | ||
118 | 123 | private void CreateShipList(Sniffer sniffer, ShipListConfig settings) |
119 | 124 | { |
120 | 125 | var ships = FilterByShipTypes( |
121 | - _mode == "修復" ? sniffer.RepairList : _groupConfigLabels.FilterByGroup(sniffer.ShipList, _mode), | |
126 | + _mode == "修復" ? sniffer.RepairList : FilterByGroup(sniffer.ShipList, settings.ShipGroup, _mode), | |
122 | 127 | settings.ShipCategories).ToArray(); |
123 | 128 | var order = _mode == "修復" ? ListForm.SortOrder.Repair : settings.SortOrder; |
124 | 129 | if (!settings.ShipType) |
@@ -134,6 +139,17 @@ namespace KancolleSniffer.View.ShipListPanel | ||
134 | 139 | }).Concat(ships).OrderBy(ship => ship, new CompareShip(true, order)).ToArray(); |
135 | 140 | } |
136 | 141 | |
142 | + private static IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships, | |
143 | + IReadOnlyList<List<int>> groups, string groupName) | |
144 | + { | |
145 | + var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == groupName); | |
146 | + if (g == -1) | |
147 | + return ships; | |
148 | + if (groups.Count == 0) | |
149 | + return new ShipStatus[0]; | |
150 | + return from s in ships where groups[g].Contains(s.Id) select s; | |
151 | + } | |
152 | + | |
137 | 153 | private static readonly int[][] ShipTypeIds = |
138 | 154 | { |
139 | 155 | new[] // 戦艦 |