OSDN Git Service

0cb956cb4988e8d93ca715e2f2b7537e1b07b65f
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Forms / ListFormGroup.cs
1 // Copyright (C) 2020 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.Collections.Generic;\r
17 using System.Drawing;\r
18 using System.Linq;\r
19 using System.Windows.Forms;\r
20 \r
21 namespace KancolleSniffer.Forms\r
22 {\r
23     public class ListFormGroup\r
24     {\r
25         private readonly MainWindow _mainWindow;\r
26         private readonly List<ListForm> _listForms = new List<ListForm>();\r
27 \r
28         public ListForm Main => _listForms[0];\r
29 \r
30         public ListFormGroup(MainWindow main)\r
31         {\r
32             _mainWindow = main;\r
33             _listForms.Add(new ListForm(main, true));\r
34             while (main.Config.ListFormGroup.Count > 0)\r
35                 _listForms.Add(new ListForm(main) {Owner = Main});\r
36         }\r
37 \r
38         public void ShowOrCreate()\r
39         {\r
40             var listForm = _listForms.FirstOrDefault(f => f.WindowState == FormWindowState.Minimized || !f.Visible);\r
41             if (listForm == null)\r
42             {\r
43                 listForm = new ListForm(_mainWindow) { Owner = Main, TopMost = Main.TopMost, Font = Main.Font };\r
44                 _listForms.Add(listForm);\r
45             }\r
46             listForm.Show();\r
47             if (listForm.WindowState == FormWindowState.Minimized)\r
48                 listForm.WindowState = FormWindowState.Normal;\r
49         }\r
50 \r
51         public void UpdateList()\r
52         {\r
53             InvokeAll(listForm => listForm.UpdateList());\r
54         }\r
55 \r
56         public void UpdateAirBattleResult()\r
57         {\r
58             InvokeAll(listForm => listForm.UpdateAirBattleResult());\r
59         }\r
60 \r
61         public void UpdateBattleResult()\r
62         {\r
63             InvokeAll(listForm => listForm.UpdateBattleResult());\r
64         }\r
65 \r
66         public void UpdateCellInfo()\r
67         {\r
68             InvokeAll(listForm => listForm.UpdateCellInfo());\r
69         }\r
70 \r
71         public bool TopMost\r
72         {\r
73             set { InvokeAll(listFrom => { listFrom.TopMost = value; }); }\r
74         }\r
75 \r
76         public Font Font\r
77         {\r
78             get => _listForms[0].Font;\r
79             set { InvokeAll(listForm => { listForm.Font = value; }); }\r
80         }\r
81 \r
82         public void ShowShip(int id)\r
83         {\r
84             InvokeAll(listForm => listForm.ShowShip(id));\r
85         }\r
86 \r
87         public void Show()\r
88         {\r
89             InvokeAll(listForm => listForm.Show());\r
90         }\r
91 \r
92         public void Close()\r
93         {\r
94             InvokeAll(listForm => listForm.SaveConfig());\r
95             InvokeAll(listForm => listForm.Close());\r
96         }\r
97 \r
98         private void InvokeAll(Action<ListForm> action)\r
99         {\r
100             foreach (var listForm in _listForms)\r
101                 action(listForm);\r
102         }\r
103     }\r
104 }