OSDN Git Service

#36057 コンフィグまわりのリファクタ(リソース不完全なので注意)
[dtxmania/dtxmania.git] / DTXManiaプロジェクト / コード / スコア、曲 / CSetDef.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Drawing;\r
5 using System.IO;\r
6 using System.Diagnostics;\r
7 \r
8 namespace DTXMania\r
9 {\r
10         public class CSetDef\r
11         {\r
12                 // プロパティ\r
13 \r
14                 public List<CBlock> blocks;\r
15                 public class CBlock\r
16                 {\r
17                         /// <summary>\r
18                         /// このブロックが有効である(何かのプロパティがセットされた)場合、true を示す。\r
19                         /// </summary>\r
20                         public bool b使用中 { get; set; }\r
21 \r
22                         /// <summary>\r
23                         /// スコアファイル名(#LxFILE)を保持する。配列は [0~4] で、存在しないレベルは null となる。\r
24                         /// </summary>\r
25                         public string[] File\r
26                         {\r
27                                 get\r
28                                 {\r
29                                         return this._file;\r
30                                 }\r
31                                 set           // ここには来ない( Label[xx] にsetすると、結局Labelのgetが呼ばれるだけで、Labelのsetは呼ばれない)\r
32                                 {\r
33                                         this._file = value;\r
34                                         this.b使用中 = true;\r
35                                 }\r
36                         }\r
37 \r
38                         /// <summary>\r
39                         /// スコアのフォント色(#FONTCOLOR)を保持する。\r
40                         /// </summary>\r
41                         public Color FontColor\r
42                         {\r
43                                 get\r
44                                 {\r
45                                         return this._fontcolor;\r
46                                 }\r
47                                 set\r
48                                 {\r
49                                         this._fontcolor = value;\r
50                                         this.b使用中 = true;\r
51                                 }\r
52                         }\r
53 \r
54                         /// <summary>\r
55                         /// スコアのジャンル名を保持する。(現在は使われていない。)\r
56                         /// </summary>\r
57                         public string Genre\r
58                         {\r
59                                 get\r
60                                 {\r
61                                         return this._genre;\r
62                                 }\r
63                                 set\r
64                                 {\r
65                                         this._genre = value;\r
66                                         this.b使用中 = true;\r
67                                 }\r
68                         }\r
69 \r
70                         /// <summary>\r
71                         /// スコアのラベル(#LxLABEL)を保持する。配列は[0~4] で、存在しないレベルは null となる。\r
72                         /// </summary>\r
73                         public string[] Label\r
74                         {\r
75                                 get\r
76                                 {\r
77                                         return this._label;\r
78                                 }\r
79                                 set           // ここには来ない( Label[xx] にsetすると、結局Labelのgetが呼ばれるだけで、Labelのsetは呼ばれない)\r
80                                 {\r
81                                         this._label = value;\r
82                                         this.b使用中 = true;\r
83                                 }\r
84                         }\r
85 \r
86                         /// <summary>\r
87                         /// スコアのタイトル(#TITLE)を保持する。\r
88                         /// </summary>\r
89                         public string Title\r
90                         {\r
91                                 get\r
92                                 {\r
93                                         return this._title;\r
94                                 }\r
95                                 set\r
96                                 {\r
97                                         this._title = value;\r
98                                         this.b使用中 = true;\r
99                                 }\r
100                         }\r
101 \r
102                         #region [ private ]\r
103                         //-----------------\r
104                         private string[] _file = new string[5];\r
105                         private Color _fontcolor = Color.White;\r
106                         private string _genre = "";\r
107                         private string[] _label = new string[5];\r
108                         private string _title = "";\r
109                         //-----------------\r
110                         #endregion\r
111                 }\r
112 \r
113 \r
114                 // コンストラクタ\r
115 \r
116                 public CSetDef()\r
117                 {\r
118                         this.blocks = new List<CBlock>();\r
119                 }\r
120                 public CSetDef(string setdefファイル名)\r
121                         : this()\r
122                 {\r
123                         this.t読み込み(setdefファイル名);\r
124                 }\r
125 \r
126 \r
127                 // メソッド\r
128 \r
129                 public void t読み込み(string setdefファイル名)\r
130                 {\r
131                         var reader = new StreamReader(setdefファイル名, Encoding.GetEncoding("Shift_JIS"));\r
132                         CBlock block = new CBlock();\r
133                         string str = null;\r
134                         while ((str = reader.ReadLine()) != null)\r
135                         {\r
136                                 if (str.Length != 0)\r
137                                 {\r
138                                         try\r
139                                         {\r
140                                                 str = str.TrimStart(new char[] { ' ', '\t' });\r
141                                                 if ((str.Length > 0) && (str[0] == '#') && (str[0] != ';'))\r
142                                                 {\r
143                                                         if (str.IndexOf(';') != -1)\r
144                                                         {\r
145                                                                 str = str.Substring(0, str.IndexOf(';'));\r
146                                                         }\r
147                                                         if (str.StartsWith("#TITLE", StringComparison.OrdinalIgnoreCase))\r
148                                                         {\r
149                                                                 if (block.b使用中)\r
150                                                                 {\r
151                                                                         this.tFILEの指定があるのにLxLABELが省略されているときはデフォルトの名前をセットする(block);\r
152                                                                         this.tLxLABELの指定があるのにFILEが省略されているときはなかったものとする(block);\r
153                                                                         this.blocks.Add(block);\r
154                                                                         block = new CBlock();\r
155                                                                 }\r
156                                                                 block.Title = str.Substring(6).TrimStart(new char[] { ':', ' ', '\t' });\r
157                                                         }\r
158                                                         else if (str.StartsWith("#FONTCOLOR", StringComparison.OrdinalIgnoreCase))\r
159                                                         {\r
160                                                                 block.FontColor = ColorTranslator.FromHtml("#" + str.Substring(10).Trim(new char[] { ':', '#', ' ', '\t' }));\r
161                                                         }\r
162                                                         else if (str.StartsWith("#L1FILE", StringComparison.OrdinalIgnoreCase))\r
163                                                         {\r
164                                                                 block.File[0] = str.Substring(7).Trim(new char[] { ':', ' ', '\t' });\r
165                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
166                                                         }\r
167                                                         else if (str.StartsWith("#L2FILE", StringComparison.OrdinalIgnoreCase))\r
168                                                         {\r
169                                                                 block.File[1] = str.Substring(7).Trim(new char[] { ':', ' ', '\t' });\r
170                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
171                                                         }\r
172                                                         else if (str.StartsWith("#L3FILE", StringComparison.OrdinalIgnoreCase))\r
173                                                         {\r
174                                                                 block.File[2] = str.Substring(7).Trim(new char[] { ':', ' ', '\t' });\r
175                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
176                                                         }\r
177                                                         else if (str.StartsWith("#L4FILE", StringComparison.OrdinalIgnoreCase))\r
178                                                         {\r
179                                                                 block.File[3] = str.Substring(7).Trim(new char[] { ':', ' ', '\t' });\r
180                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
181                                                         }\r
182                                                         else if (str.StartsWith("#L5FILE", StringComparison.OrdinalIgnoreCase))\r
183                                                         {\r
184                                                                 block.File[4] = str.Substring(7).Trim(new char[] { ':', ' ', '\t' });\r
185                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
186                                                         }\r
187                                                         else if (str.StartsWith("#L1LABEL", StringComparison.OrdinalIgnoreCase))\r
188                                                         {\r
189                                                                 block.Label[0] = str.Substring(8).Trim(new char[] { ':', ' ', '\t' });\r
190                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
191                                                         }\r
192                                                         else if (str.StartsWith("#L2LABEL", StringComparison.OrdinalIgnoreCase))\r
193                                                         {\r
194                                                                 block.Label[1] = str.Substring(8).Trim(new char[] { ':', ' ', '\t' });\r
195                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
196                                                         }\r
197                                                         else if (str.StartsWith("#L3LABEL", StringComparison.OrdinalIgnoreCase))\r
198                                                         {\r
199                                                                 block.Label[2] = str.Substring(8).Trim(new char[] { ':', ' ', '\t' });\r
200                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
201                                                         }\r
202                                                         else if (str.StartsWith("#L4LABEL", StringComparison.OrdinalIgnoreCase))\r
203                                                         {\r
204                                                                 block.Label[3] = str.Substring(8).Trim(new char[] { ':', ' ', '\t' });\r
205                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
206                                                         }\r
207                                                         else if (str.StartsWith("#L5LABEL", StringComparison.OrdinalIgnoreCase))\r
208                                                         {\r
209                                                                 block.Label[4] = str.Substring(8).Trim(new char[] { ':', ' ', '\t' });\r
210                                                                 block.b使用中 = true;    // #28937 2012.7.7 yyagi; "get" accessor is called for T[] property. So b使用中 is not modified to set the property. I need to update it myself.\r
211                                                         }\r
212                                                 }\r
213                                                 continue;\r
214                                         }\r
215                                         catch\r
216                                         {\r
217                                                 continue;\r
218                                         }\r
219                                 }\r
220                         }\r
221                         reader.Close();\r
222                         if (block.b使用中)\r
223                         {\r
224                                 this.tFILEの指定があるのにLxLABELが省略されているときはデフォルトの名前をセットする(block);\r
225                                 this.tLxLABELの指定があるのにFILEが省略されているときはなかったものとする(block);\r
226                                 this.blocks.Add(block);\r
227                         }\r
228                 }\r
229 \r
230 \r
231                 // その他\r
232 \r
233                 #region [ private ]\r
234                 //-----------------\r
235                 private void tFILEの指定があるのにLxLABELが省略されているときはデフォルトの名前をセットする(CBlock block)\r
236                 {\r
237                         string[] strArray = new string[] { "BASIC", "ADVANCED", "EXTREME", "HYPER", "ULTIMATE" };\r
238                         for (int i = 0; i < 5; i++)\r
239                         {\r
240                                 if (((block.File[i] != null) && (block.File[i].Length > 0)) && string.IsNullOrEmpty(block.Label[i]))\r
241                                 {\r
242                                         block.Label[i] = strArray[i];\r
243                                 }\r
244                         }\r
245                 }\r
246                 private void tLxLABELの指定があるのにFILEが省略されているときはなかったものとする(CBlock block)\r
247                 {\r
248                         for (int i = 0; i < 5; i++)\r
249                         {\r
250                                 if (((block.Label[i] != null) && (block.Label[i].Length > 0)) && string.IsNullOrEmpty(block.File[i]))\r
251                                 {\r
252                                         block.Label[i] = "";\r
253                                 }\r
254                         }\r
255                 }\r
256                 //-----------------\r
257                 #endregion\r
258         }\r
259 }\r