OSDN Git Service

#36057 コンフィグまわりのリファクタ(リソース不完全なので注意)
[dtxmania/dtxmania.git] / DTXManiaプロジェクト / コード / ステージ / 05.選曲 / CActSelectArtistComment.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Drawing;\r
5 using System.Diagnostics;\r
6 using SlimDX;\r
7 using FDK;\r
8 \r
9 namespace DTXMania\r
10 {\r
11         internal class CActSelectArtistComment : CActivity\r
12         {\r
13                 // メソッド\r
14 \r
15                 public CActSelectArtistComment()\r
16                 {\r
17                         base.b活性化してない = true;\r
18                 }\r
19                 public void t選択曲が変更された()\r
20                 {\r
21                         Cスコア cスコア = CDTXMania.Instance.stage選曲.r現在選択中のスコア;\r
22                         if (cスコア != null)\r
23                         {\r
24                                 Bitmap image = new Bitmap(1, 1);\r
25                                 TextureFactory.tテクスチャの解放(ref this.txArtist);\r
26                                 this.strArtist = cスコア.譜面情報.アーティスト名;\r
27                                 if ((this.strArtist != null) && (this.strArtist.Length > 0))\r
28                                 {\r
29                                         Graphics graphics = Graphics.FromImage(image);\r
30                                         graphics.PageUnit = GraphicsUnit.Pixel;\r
31                                         SizeF ef = graphics.MeasureString(this.strArtist, this.ft描画用フォント);\r
32                                         graphics.Dispose();\r
33                                         if (ef.Width > SampleFramework.GameWindowSize.Width)\r
34                                         {\r
35                                                 ef.Width = SampleFramework.GameWindowSize.Width;\r
36                                         }\r
37                                         try\r
38                                         {\r
39                                                 Bitmap bitmap2 = new Bitmap((int)Math.Ceiling((double)ef.Width), (int)Math.Ceiling((double)this.ft描画用フォント.Size));\r
40                                                 graphics = Graphics.FromImage(bitmap2);\r
41                                                 graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;\r
42                                                 graphics.DrawString(this.strArtist, this.ft描画用フォント, Brushes.White, (float)0f, (float)0f);\r
43                                                 graphics.Dispose();\r
44                                                 this.txArtist = new CTexture(CDTXMania.Instance.Device, bitmap2, CDTXMania.Instance.TextureFormat);\r
45                                                 this.txArtist.vc拡大縮小倍率 = new Vector3(0.5f, 0.5f, 1f);\r
46                                                 bitmap2.Dispose();\r
47                                         }\r
48                                         catch (CTextureCreateFailedException)\r
49                                         {\r
50                                                 Trace.TraceError("ARTISTテクスチャの生成に失敗しました。");\r
51                                                 this.txArtist = null;\r
52                                         }\r
53                                 }\r
54                                 TextureFactory.tテクスチャの解放(ref this.txComment);\r
55                                 this.strComment = cスコア.譜面情報.コメント;\r
56                                 if ((this.strComment != null) && (this.strComment.Length > 0))\r
57                                 {\r
58                                         Graphics graphics2 = Graphics.FromImage(image);\r
59                                         graphics2.PageUnit = GraphicsUnit.Pixel;\r
60                                         SizeF ef2 = graphics2.MeasureString(this.strComment, this.ft描画用フォント);\r
61                                         Size size = new Size((int)Math.Ceiling((double)ef2.Width), (int)Math.Ceiling((double)ef2.Height));\r
62                                         graphics2.Dispose();\r
63                                         this.nテクスチャの最大幅 = CDTXMania.Instance.Device.Capabilities.MaxTextureWidth;\r
64                                         int maxTextureHeight = CDTXMania.Instance.Device.Capabilities.MaxTextureHeight;\r
65                                         Bitmap bitmap3 = new Bitmap(size.Width, (int)Math.Ceiling((double)this.ft描画用フォント.Size));\r
66                                         graphics2 = Graphics.FromImage(bitmap3);\r
67                                         graphics2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;\r
68                                         graphics2.DrawString(this.strComment, this.ft描画用フォント, Brushes.White, (float)0f, (float)0f);\r
69                                         graphics2.Dispose();\r
70                                         this.nComment行数 = 1;\r
71                                         this.nComment最終行の幅 = size.Width;\r
72                                         while (this.nComment最終行の幅 > this.nテクスチャの最大幅)\r
73                                         {\r
74                                                 this.nComment行数++;\r
75                                                 this.nComment最終行の幅 -= this.nテクスチャの最大幅;\r
76                                         }\r
77                                         while ((this.nComment行数 * ((int)Math.Ceiling((double)this.ft描画用フォント.Size))) > maxTextureHeight)\r
78                                         {\r
79                                                 this.nComment行数--;\r
80                                                 this.nComment最終行の幅 = this.nテクスチャの最大幅;\r
81                                         }\r
82                                         Bitmap bitmap4 = new Bitmap((this.nComment行数 > 1) ? this.nテクスチャの最大幅 : this.nComment最終行の幅, this.nComment行数 * ((int)Math.Ceiling((double)this.ft描画用フォント.Size)));\r
83                                         graphics2 = Graphics.FromImage(bitmap4);\r
84                                         Rectangle srcRect = new Rectangle();\r
85                                         Rectangle destRect = new Rectangle();\r
86                                         for (int i = 0; i < this.nComment行数; i++)\r
87                                         {\r
88                                                 srcRect.X = i * this.nテクスチャの最大幅;\r
89                                                 srcRect.Y = 0;\r
90                                                 srcRect.Width = ((i + 1) == this.nComment行数) ? this.nComment最終行の幅 : this.nテクスチャの最大幅;\r
91                                                 srcRect.Height = bitmap3.Height;\r
92                                                 destRect.X = 0;\r
93                                                 destRect.Y = i * bitmap3.Height;\r
94                                                 destRect.Width = srcRect.Width;\r
95                                                 destRect.Height = srcRect.Height;\r
96                                                 graphics2.DrawImage(bitmap3, destRect, srcRect, GraphicsUnit.Pixel);\r
97                                         }\r
98                                         graphics2.Dispose();\r
99                                         try\r
100                                         {\r
101                                                 this.txComment = new CTexture(CDTXMania.Instance.Device, bitmap4, CDTXMania.Instance.TextureFormat);\r
102                                                 this.txComment.vc拡大縮小倍率 = new Vector3(0.5f, 0.5f, 1f);\r
103                                         }\r
104                                         catch (CTextureCreateFailedException)\r
105                                         {\r
106                                                 Trace.TraceError("COMMENTテクスチャの生成に失敗しました。");\r
107                                                 this.txComment = null;\r
108                                         }\r
109                                         bitmap4.Dispose();\r
110                                         bitmap3.Dispose();\r
111                                 }\r
112                                 image.Dispose();\r
113                                 if (this.txComment != null)\r
114                                 {\r
115                                         this.ctComment = new CCounter(\r
116                                                 -nComment表示幅,\r
117                                                 (int)((((this.nComment行数 - 1) * this.nテクスチャの最大幅) + this.nComment最終行の幅) * this.txComment.vc拡大縮小倍率.X),\r
118                                                 unchecked((int)(10 * 2 / Scale.X)),\r
119                                                 CDTXMania.Instance.Timer\r
120                                         );\r
121                                 }\r
122                         }\r
123                 }\r
124 \r
125 \r
126                 // CActivity 実装\r
127 \r
128                 public override void On活性化()\r
129                 {\r
130                         this.ft描画用フォント = new Font("MS PGothic", 26f * Scale.Y, GraphicsUnit.Pixel);\r
131                         this.txArtist = null;\r
132                         this.txComment = null;\r
133                         this.strArtist = "";\r
134                         this.strComment = "";\r
135                         this.nComment最終行の幅 = 0;\r
136                         this.nComment行数 = 0;\r
137                         this.nテクスチャの最大幅 = 0;\r
138                         this.ctComment = new CCounter();\r
139                         base.On活性化();\r
140                 }\r
141                 public override void On非活性化()\r
142                 {\r
143                         TextureFactory.tテクスチャの解放(ref this.txArtist);\r
144                         TextureFactory.tテクスチャの解放(ref this.txComment);\r
145                         if (this.ft描画用フォント != null)\r
146                         {\r
147                                 this.ft描画用フォント.Dispose();\r
148                                 this.ft描画用フォント = null;\r
149                         }\r
150                         this.ctComment = null;\r
151                         base.On非活性化();\r
152                 }\r
153                 public override void OnManagedリソースの作成()\r
154                 {\r
155                         if (!base.b活性化してない)\r
156                         {\r
157                                 this.t選択曲が変更された();\r
158                                 base.OnManagedリソースの作成();\r
159                         }\r
160                 }\r
161                 public override void OnManagedリソースの解放()\r
162                 {\r
163                         if (!base.b活性化してない)\r
164                         {\r
165                                 TextureFactory.tテクスチャの解放(ref this.txArtist);\r
166                                 TextureFactory.tテクスチャの解放(ref this.txComment);\r
167                                 base.OnManagedリソースの解放();\r
168                         }\r
169                 }\r
170                 public override int On進行描画()\r
171                 {\r
172                         if (!base.b活性化してない)\r
173                         {\r
174                                 if (this.ctComment.b進行中)\r
175                                 {\r
176                                         this.ctComment.t進行Loop();\r
177                                 }\r
178                                 if (this.txArtist != null)\r
179                                 {\r
180                                         int x = (int)(SampleFramework.GameWindowSize.Width - (6 + 12) * Scale.X) - ((int)(this.txArtist.szテクスチャサイズ.Width * this.txArtist.vc拡大縮小倍率.X));    // #27648 2012.3.14 yyagi: -12 for scrollbar\r
181                                         int y = (int)(231 * Scale.Y);\r
182                                         this.txArtist.t2D描画(CDTXMania.Instance.Device, x, y);\r
183                                 }\r
184                                 if ((this.txComment != null) && ((this.ctComment.n現在の値 + nComment表示幅) >= 0))\r
185                                 {\r
186                                         int num3 = (int)(0xf8 * Scale.X);\r
187                                         int num4 = (int)(0xf5 * Scale.Y);\r
188                                         Rectangle rectangle = new Rectangle(this.ctComment.n現在の値, 0, nComment表示幅, (int)this.ft描画用フォント.Size);\r
189                                         if (rectangle.X < 0)\r
190                                         {\r
191                                                 num3 += -rectangle.X;\r
192                                                 rectangle.Width -= -rectangle.X;\r
193                                                 rectangle.X = 0;\r
194                                         }\r
195                                         int num5 = ((int)(((float)rectangle.X) / this.txComment.vc拡大縮小倍率.X)) / this.nテクスチャの最大幅;\r
196                                         Rectangle rectangle2 = new Rectangle();\r
197                                         while (rectangle.Width > 0)\r
198                                         {\r
199                                                 rectangle2.X = ((int)(((float)rectangle.X) / this.txComment.vc拡大縮小倍率.X)) % this.nテクスチャの最大幅;\r
200                                                 rectangle2.Y = num5 * ((int)this.ft描画用フォント.Size);\r
201                                                 int num6 = ((num5 + 1) == this.nComment行数) ? this.nComment最終行の幅 : this.nテクスチャの最大幅;\r
202                                                 int num7 = num6 - rectangle2.X;\r
203                                                 rectangle2.Width = num7;\r
204                                                 rectangle2.Height = (int)this.ft描画用フォント.Size;\r
205                                                 this.txComment.t2D描画(CDTXMania.Instance.Device, num3, num4, rectangle2);\r
206                                                 if (++num5 == this.nComment行数)\r
207                                                 {\r
208                                                         break;\r
209                                                 }\r
210                                                 int num8 = (int)(rectangle2.Width * this.txComment.vc拡大縮小倍率.X);\r
211                                                 rectangle.X += num8;\r
212                                                 rectangle.Width -= num8;\r
213                                                 num3 += num8;\r
214                                         }\r
215                                 }\r
216                         }\r
217                         return 0;\r
218                 }\r
219 \r
220 \r
221                 // その他\r
222 \r
223                 #region [ private ]\r
224                 //-----------------\r
225                 private CCounter ctComment;\r
226                 private Font ft描画用フォント;\r
227                 private int nComment行数;\r
228                 private int nComment最終行の幅;\r
229                 private const int nComment表示幅 = (int)(0x182 * Scale.X);\r
230                 private int nテクスチャの最大幅;\r
231                 private string strArtist;\r
232                 private string strComment;\r
233                 private CTexture txArtist;\r
234                 private CTexture txComment;\r
235                 //-----------------\r
236                 #endregion\r
237         }\r
238 }\r