修订版 | e39163e66599edc62a3de6d712d40d6d4f2d073c (tree) |
---|---|
时间 | 2020-09-16 18:06:13 |
作者 | Kazuhiro Fujieda <fujieda@user...> |
Commiter | Kazuhiro Fujieda |
Settingsクラスを廃止する
@@ -33,47 +33,17 @@ namespace KancolleSniffer.Forms | ||
33 | 33 | private readonly MainWindow.TimeOutChecker _suppressActivate; |
34 | 34 | private readonly CheckBox[] _shipTypeCheckBoxes; |
35 | 35 | private bool _isMaster; |
36 | - private Settings _settings; | |
36 | + private ShipListConfig _listConfig; | |
37 | 37 | private FormWindowState _windowState = FormWindowState.Minimized; |
38 | 38 | public const int PanelWidth = 215; |
39 | 39 | |
40 | - public class Settings | |
41 | - { | |
42 | - public string Mode { get; set; } | |
43 | - public ShipCategory ShipCategories { get; set; } | |
44 | - public bool ShipType { get; set; } | |
45 | - public bool ShowHpInPercent { get; set; } | |
46 | - public SortOrder SortOrder { get; set; } | |
47 | - | |
48 | - public static Settings FromShipListConfig(ShipListConfig config) | |
49 | - { | |
50 | - return new Settings | |
51 | - { | |
52 | - Mode = config.Mode ?? "全艦", | |
53 | - ShipCategories = config.ShipCategories, | |
54 | - ShipType = config.ShipType, | |
55 | - ShowHpInPercent = config.ShowHpInPercent, | |
56 | - SortOrder = config.SortOrder | |
57 | - }; | |
58 | - } | |
59 | - | |
60 | - public void SetToShipListConfig(ShipListConfig config) | |
61 | - { | |
62 | - config.Mode = Mode; | |
63 | - config.ShipCategories = ShipCategories; | |
64 | - config.ShipType = ShipType; | |
65 | - config.ShowHpInPercent = ShowHpInPercent; | |
66 | - config.SortOrder = SortOrder; | |
67 | - } | |
68 | - } | |
69 | - | |
70 | 40 | private object[] PanelNames => new object[] {"全艦", "A", "B", "C", "D", "分類", "修復", "装備", "艦隊", "対空", "戦況", "情報"} |
71 | 41 | .Where(n => IsMaster || (string)n != "分類").ToArray(); |
72 | 42 | |
73 | 43 | private char[] PanelKeys => new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W', 'X', 'Y', 'S', 'I'} |
74 | 44 | .Where(key => IsMaster || key != 'G').ToArray(); |
75 | 45 | |
76 | - public bool IsMaster | |
46 | + private bool IsMaster | |
77 | 47 | { |
78 | 48 | get => _isMaster; |
79 | 49 | set |
@@ -97,10 +67,10 @@ namespace KancolleSniffer.Forms | ||
97 | 67 | Repair |
98 | 68 | } |
99 | 69 | |
100 | - public ListForm(MainWindow main) | |
70 | + public ListForm(MainWindow main, bool isMaster = false) | |
101 | 71 | { |
102 | 72 | InitializeComponent(); |
103 | - IsMaster = false; | |
73 | + IsMaster = isMaster; | |
104 | 74 | _form = main.Form; |
105 | 75 | _sniffer = main.Sniffer; |
106 | 76 | _config = main.Config; |
@@ -122,6 +92,18 @@ namespace KancolleSniffer.Forms | ||
122 | 92 | swipe.AddShipListPanel(shipListPanel); |
123 | 93 | swipe.AddTreeView(itemTreeView); |
124 | 94 | swipe.AddPanel(fleetPanel); |
95 | + SetupSettings(); | |
96 | + } | |
97 | + | |
98 | + private void SetupSettings() | |
99 | + { | |
100 | + _listConfig = GetConfig(); | |
101 | + if (_listConfig.ShowHpInPercent) | |
102 | + { | |
103 | + shipListPanel.ToggleHpPercent(); | |
104 | + battleResultPanel.ToggleHpPercent(); | |
105 | + } | |
106 | + LoadShipGroupFromConfig(); | |
125 | 107 | } |
126 | 108 | |
127 | 109 | public void UpdateList() |
@@ -149,7 +131,7 @@ namespace KancolleSniffer.Forms | ||
149 | 131 | else if (InShipStatus || InGroupConfig || InRepairList) |
150 | 132 | { |
151 | 133 | SetHeaderSortOrder(); |
152 | - shipListPanel.Update(_sniffer, comboBoxGroup.Text, _settings); | |
134 | + shipListPanel.Update(_sniffer, comboBoxGroup.Text, _listConfig); | |
153 | 135 | } |
154 | 136 | if (shipListPanel.GroupUpdated) |
155 | 137 | { |
@@ -235,7 +217,7 @@ namespace KancolleSniffer.Forms | ||
235 | 217 | |
236 | 218 | private void SetHeaderSortOrder() |
237 | 219 | { |
238 | - switch (_settings.SortOrder) | |
220 | + switch (_listConfig.SortOrder) | |
239 | 221 | { |
240 | 222 | case SortOrder.None: |
241 | 223 | labelHeaderCond.Text = "cond"; |
@@ -260,39 +242,31 @@ namespace KancolleSniffer.Forms | ||
260 | 242 | } |
261 | 243 | } |
262 | 244 | |
263 | - private bool InShipStatus => Array.Exists(new[] {"全艦", "A", "B", "C", "D"}, x => _settings.Mode == x); | |
245 | + private bool InShipStatus => Array.Exists(new[] {"全艦", "A", "B", "C", "D"}, x => _listConfig.Mode == x); | |
264 | 246 | |
265 | - private bool InGroupConfig => _settings.Mode == "分類"; | |
247 | + private bool InGroupConfig => _listConfig.Mode == "分類"; | |
266 | 248 | |
267 | - private bool InRepairList => _settings.Mode == "修復"; | |
249 | + private bool InRepairList => _listConfig.Mode == "修復"; | |
268 | 250 | |
269 | - private bool InItemList => _settings.Mode == "装備"; | |
251 | + private bool InItemList => _listConfig.Mode == "装備"; | |
270 | 252 | |
271 | - private bool InFleetInfo => _settings.Mode == "艦隊"; | |
253 | + private bool InFleetInfo => _listConfig.Mode == "艦隊"; | |
272 | 254 | |
273 | - private bool InAntiAir => _settings.Mode == "対空"; | |
255 | + private bool InAntiAir => _listConfig.Mode == "対空"; | |
274 | 256 | |
275 | - private bool InBattleResult => _settings.Mode == "戦況"; | |
257 | + private bool InBattleResult => _listConfig.Mode == "戦況"; | |
276 | 258 | |
277 | - private bool InMiscText => _settings.Mode == "情報"; | |
259 | + private bool InMiscText => _listConfig.Mode == "情報"; | |
278 | 260 | |
279 | 261 | private void ListForm_Load(object sender, EventArgs e) |
280 | 262 | { |
281 | 263 | AdjustHeader(); |
282 | 264 | SetMinimumSize(); |
283 | - var config = GetConfig(); | |
284 | - _settings = Settings.FromShipListConfig(config); | |
285 | - if (_settings.ShowHpInPercent) | |
286 | - { | |
287 | - shipListPanel.ToggleHpPercent(); | |
288 | - battleResultPanel.ToggleHpPercent(); | |
289 | - } | |
290 | - LoadShipGroupFromConfig(); | |
291 | - comboBoxGroup.SelectedItem = _settings.Mode; | |
265 | + comboBoxGroup.SelectedItem = _listConfig.Mode; | |
292 | 266 | SetCheckBoxSTypeState(); |
293 | - if (config.Location.X == int.MinValue) | |
267 | + if (_listConfig.Location.X == int.MinValue) | |
294 | 268 | return; |
295 | - var bounds = new Rectangle(config.Location, config.Size); | |
269 | + var bounds = new Rectangle(_listConfig.Location, _listConfig.Size); | |
296 | 270 | if (MainWindow.IsTitleBarOnAnyScreen(bounds.Location)) |
297 | 271 | Location = bounds.Location; |
298 | 272 | Size = bounds.Size; |
@@ -318,11 +292,29 @@ namespace KancolleSniffer.Forms | ||
318 | 292 | |
319 | 293 | private ShipListConfig GetConfig() |
320 | 294 | { |
321 | - if (_isMaster || _config.ListFormGroup.Count == 0) | |
295 | + if (_isMaster) | |
322 | 296 | return _config.ShipList; |
297 | + if (_config.ListFormGroup.Count == 0) | |
298 | + return CreateSecondaryConfig(); | |
323 | 299 | var config = _config.ListFormGroup[0]; |
324 | 300 | _config.ListFormGroup.RemoveAt(0); |
325 | - if (config.Mode == "分類") | |
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)) | |
326 | 318 | config.Mode = "全艦"; |
327 | 319 | return config; |
328 | 320 | } |
@@ -337,9 +329,9 @@ namespace KancolleSniffer.Forms | ||
337 | 329 | private void SetCheckBoxSTypeState() |
338 | 330 | { |
339 | 331 | for (var type = 0; type < _shipTypeCheckBoxes.Length; type++) |
340 | - _shipTypeCheckBoxes[type].Checked = ((int)_settings.ShipCategories & (1 << type)) != 0; | |
341 | - checkBoxSTypeAll.Checked = _settings.ShipCategories == ShipCategory.All; | |
342 | - checkBoxSTypeDetails.Checked = _settings.ShipType; | |
332 | + _shipTypeCheckBoxes[type].Checked = ((int)_listConfig.ShipCategories & (1 << type)) != 0; | |
333 | + checkBoxSTypeAll.Checked = _listConfig.ShipCategories == ShipCategory.All; | |
334 | + checkBoxSTypeDetails.Checked = _listConfig.ShipType; | |
343 | 335 | } |
344 | 336 | |
345 | 337 | private void ListForm_FormClosing(object sender, FormClosingEventArgs e) |
@@ -350,8 +342,6 @@ namespace KancolleSniffer.Forms | ||
350 | 342 | |
351 | 343 | public void SaveConfig() |
352 | 344 | { |
353 | - if (_settings == null) | |
354 | - return; | |
355 | 345 | if (_isMaster) |
356 | 346 | { |
357 | 347 | SaveMasterState(); |
@@ -365,10 +355,8 @@ namespace KancolleSniffer.Forms | ||
365 | 355 | private void SaveMasterState() |
366 | 356 | { |
367 | 357 | StoreShipGroupToConfig(); |
368 | - var config = _config.ShipList; | |
369 | - config.Visible = Visible && WindowState == FormWindowState.Normal; | |
370 | - _settings.SetToShipListConfig(config); | |
371 | - SaveBounds(config); // 最小化時は以前のサイズを記録する | |
358 | + _listConfig.Visible = Visible && WindowState == FormWindowState.Normal; | |
359 | + SaveBounds(_listConfig); // 最小化時は以前のサイズを記録する | |
372 | 360 | } |
373 | 361 | |
374 | 362 | private void SaveSlaveState() |
@@ -377,10 +365,9 @@ namespace KancolleSniffer.Forms | ||
377 | 365 | return; |
378 | 366 | if (WindowState != FormWindowState.Normal) // 最小化時は次回復旧しない |
379 | 367 | return; |
380 | - var config = new ShipListConfig {Visible = true}; | |
381 | - _settings.SetToShipListConfig(config); | |
382 | - _config.ListFormGroup.Add(config); | |
383 | - SaveBounds(config); | |
368 | + _listConfig.Visible = true; | |
369 | + _config.ListFormGroup.Add(_listConfig); | |
370 | + SaveBounds(_listConfig); | |
384 | 371 | } |
385 | 372 | |
386 | 373 | private void SaveBounds(ShipListConfig config) |
@@ -470,9 +457,7 @@ namespace KancolleSniffer.Forms | ||
470 | 457 | |
471 | 458 | private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) |
472 | 459 | { |
473 | - if (_settings == null) | |
474 | - return; | |
475 | - _settings.Mode = comboBoxGroup.Text; | |
460 | + _listConfig.Mode = comboBoxGroup.Text; | |
476 | 461 | UpdateList(); |
477 | 462 | SetActiveControl(); |
478 | 463 | if (!(InShipStatus || InGroupConfig || InRepairList)) |
@@ -531,16 +516,16 @@ namespace KancolleSniffer.Forms | ||
531 | 516 | |
532 | 517 | private void labelHeaderCond_Click(object sender, EventArgs e) |
533 | 518 | { |
534 | - switch (_settings.SortOrder) | |
519 | + switch (_listConfig.SortOrder) | |
535 | 520 | { |
536 | 521 | case SortOrder.CondAscend: |
537 | - _settings.SortOrder = SortOrder.CondDescend; | |
522 | + _listConfig.SortOrder = SortOrder.CondDescend; | |
538 | 523 | break; |
539 | 524 | case SortOrder.CondDescend: |
540 | - _settings.SortOrder = SortOrder.None; | |
525 | + _listConfig.SortOrder = SortOrder.None; | |
541 | 526 | break; |
542 | 527 | default: |
543 | - _settings.SortOrder = SortOrder.CondAscend; | |
528 | + _listConfig.SortOrder = SortOrder.CondAscend; | |
544 | 529 | break; |
545 | 530 | } |
546 | 531 | UpdateList(); |
@@ -548,16 +533,16 @@ namespace KancolleSniffer.Forms | ||
548 | 533 | |
549 | 534 | private void labelHeaderExp_Click(object sender, EventArgs e) |
550 | 535 | { |
551 | - switch (_settings.SortOrder) | |
536 | + switch (_listConfig.SortOrder) | |
552 | 537 | { |
553 | 538 | case SortOrder.ExpToNextAscend: |
554 | - _settings.SortOrder = SortOrder.ExpToNextDescend; | |
539 | + _listConfig.SortOrder = SortOrder.ExpToNextDescend; | |
555 | 540 | break; |
556 | 541 | case SortOrder.ExpToNextDescend: |
557 | - _settings.SortOrder = SortOrder.None; | |
542 | + _listConfig.SortOrder = SortOrder.None; | |
558 | 543 | break; |
559 | 544 | default: |
560 | - _settings.SortOrder = SortOrder.ExpToNextAscend; | |
545 | + _listConfig.SortOrder = SortOrder.ExpToNextAscend; | |
561 | 546 | break; |
562 | 547 | } |
563 | 548 | UpdateList(); |
@@ -585,7 +570,7 @@ namespace KancolleSniffer.Forms | ||
585 | 570 | |
586 | 571 | private void ToggleHpPercent() |
587 | 572 | { |
588 | - _settings.ShowHpInPercent = !_settings.ShowHpInPercent; | |
573 | + _listConfig.ShowHpInPercent = !_listConfig.ShowHpInPercent; | |
589 | 574 | shipListPanel.ToggleHpPercent(); |
590 | 575 | battleResultPanel.ToggleHpPercent(); |
591 | 576 | } |
@@ -605,7 +590,7 @@ namespace KancolleSniffer.Forms | ||
605 | 590 | |
606 | 591 | private void checkBoxSType_Click(object sender, EventArgs e) |
607 | 592 | { |
608 | - _settings.ShipCategories = SelectedShipTypes; | |
593 | + _listConfig.ShipCategories = SelectedShipTypes; | |
609 | 594 | UpdateList(); |
610 | 595 | SetActiveControl(); |
611 | 596 | } |
@@ -635,7 +620,7 @@ namespace KancolleSniffer.Forms | ||
635 | 620 | |
636 | 621 | private void checkBoxSTypeDetails_Click(object sender, EventArgs e) |
637 | 622 | { |
638 | - _settings.ShipType = checkBoxSTypeDetails.Checked; | |
623 | + _listConfig.ShipType = checkBoxSTypeDetails.Checked; | |
639 | 624 | UpdateList(); |
640 | 625 | SetActiveControl(); |
641 | 626 | } |
@@ -30,7 +30,7 @@ namespace KancolleSniffer.Forms | ||
30 | 30 | public ListFormGroup(MainWindow main) |
31 | 31 | { |
32 | 32 | _mainWindow = main; |
33 | - _listForms.Add(new ListForm(main) {IsMaster = true}); | |
33 | + _listForms.Add(new ListForm(main, true)); | |
34 | 34 | for (var i = 0; i < main.Config.ListFormGroup.Count; i++) |
35 | 35 | _listForms.Add(new ListForm(main) {Owner = Main}); |
36 | 36 | } |
@@ -88,7 +88,7 @@ namespace KancolleSniffer.View.ShipListPanel | ||
88 | 88 | ScrollBar.Value - e.Delta * SystemInformation.MouseWheelScrollLines / 120)); |
89 | 89 | } |
90 | 90 | |
91 | - public void Update(Sniffer sniffer, string mode, ListForm.Settings settings) | |
91 | + public void Update(Sniffer sniffer, string mode, ShipListConfig settings) | |
92 | 92 | { |
93 | 93 | _mode = mode; |
94 | 94 | CreateShipList(sniffer, settings); |
@@ -115,7 +115,7 @@ namespace KancolleSniffer.View.ShipListPanel | ||
115 | 115 | Refresh(); |
116 | 116 | } |
117 | 117 | |
118 | - private void CreateShipList(Sniffer sniffer, ListForm.Settings settings) | |
118 | + private void CreateShipList(Sniffer sniffer, ShipListConfig settings) | |
119 | 119 | { |
120 | 120 | var ships = FilterByShipTypes( |
121 | 121 | _mode == "修復" ? sniffer.RepairList : _groupConfigLabels.FilterByGroup(sniffer.ShipList, _mode), |