OSDN Git Service

DPX→PX変換に失敗していたミスを修正。
[strokestylet/CsWin10Desktop3.git] / StrokeStyleT / ステージ / 演奏 / ヒット判定文字列.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Linq;
5 using FDK.メディア;
6
7 namespace SST.ステージ.演奏
8 {
9         class ヒット判定文字列 : FDK.Activity
10         {
11                 public ヒット判定文字列()
12                 {
13                         // すべての文字列画像を子リストに追加。
14                         foreach( var kvp in this.文字列画像 )
15                                 this.子リスト.Add( kvp.Value );
16                 }
17                 public void 表示開始( ヒットレーン種別 レーン種別, ヒット判定種別 ヒット判定種別 )
18                 {
19                         if( レーン種別 == ヒットレーン種別.Unknown )
20                                 return;
21
22                         // レーンに対応する進行描画コンテキストを更新し、表示を開始するためのパラメータを設定する。
23                         if( this.ヒット判定レーンto進行描画コンテキスト.ContainsKey( レーン種別 ) ) // すでにあったら、
24                                 this.ヒット判定レーンto進行描画コンテキスト.Remove( レーン種別 );       // 削除してから、
25                         this.ヒット判定レーンto進行描画コンテキスト.Add(                           // 追加。
26                                 レーン種別,
27                                 new 進行描画コンテキスト() {
28                                         ヒット判定種別 = ヒット判定種別,
29                                         進行カウンタ = new FDK.カウンタ.単純増加後不変カウンタ( 最初の値: 0, 最後の値: 300, 値をひとつ増加させるのにかける時間ms: 1 ),    // カウント開始(=表示開始)
30                                         X方向拡大率 = 1f,
31                                         Y方向拡大率 = 1f,
32                                         相対X座標dpx = 0,
33                                         相対Y座標dpx = 0,
34                                         透明度0to1 = 1f,
35                                 } );
36                 }
37                 public void 表示開始( SSTFormat.チップ種別 チップ種別, ヒット判定種別 ヒット判定種別 )
38                 {
39                         var レーン種別 = チップ種別.対応するヒットレーン種別を返す();
40                         this.表示開始( レーン種別, ヒット判定種別 );
41                 }
42
43                 protected override void On活性化( デバイスリソース dr )
44                 {
45                         // すべてのヒット判定レーンに対する進行描画コンテキストを生成する。
46                         this.ヒット判定レーンto進行描画コンテキスト = new Dictionary<ヒットレーン種別, 進行描画コンテキスト>();
47                         foreach( var judgeType in typeof( ヒットレーン種別 ).GetEnumValues() )
48                                 this.ヒット判定レーンto進行描画コンテキスト.Add( (ヒットレーン種別) judgeType, new 進行描画コンテキスト() );
49                 }
50                 protected override void On非活性化( デバイスリソース dr )
51                 {
52                         this.ヒット判定レーンto進行描画コンテキスト.Clear();
53                 }
54                 public void 進行描画する( デバイスリソース dr )
55                 {
56                         // すべての ヒットレーン種別 について、進行描画する。
57                         foreach( var lane_object in typeof( ヒットレーン種別 ).GetEnumValues() )
58                         {
59                                 var lane = (ヒットレーン種別) lane_object;
60                                 var context = this.ヒット判定レーンto進行描画コンテキスト[ lane ];
61
62                                 if( context.進行カウンタ.停止中である )
63                                         continue;   // カウンタが停止中 → このレーンについては何もしない。
64
65                                 // 進行。
66
67                                 #region " 進行カウンタが終了値に達したら停止 → 表示完了。"
68                                 //----------------
69                                 if( context.進行カウンタ.終了値に達した )
70                                 {
71                                         context.進行カウンタ.一時停止する();
72                                         continue;
73                                 }
74                                 //----------------
75                                 #endregion
76
77                                 if( context.ヒット判定種別 != ヒット判定種別.MISS )
78                                 {
79                                         #region " (A) Perfect, Great, Good, Poor, Auto のアニメーション進行。"
80                                         //-----------------
81                                         if( context.進行カウンタ.現在値 < 50 )
82                                         {
83                                                 // (B-a) 0~49
84                                                 context.X方向拡大率 = 1.0f + ( 1.0f * ( 1.0f - ( context.進行カウンタ.現在値 / 50.0f ) ) );
85                                                 context.Y方向拡大率 = context.進行カウンタ.現在値 / 50.0f;
86                                                 context.相対X座標dpx = 0;
87                                                 context.相対Y座標dpx = 0;
88                                                 context.透明度0to1 = 1.0f;
89                                         }
90                                         else if( context.進行カウンタ.現在値 < 130 )
91                                         {
92                                                 // (B-b) 50~129
93                                                 context.X方向拡大率 = 1.0f;
94                                                 context.Y方向拡大率 = 1.0f;
95                                                 context.相対X座標dpx = 0;
96                                                 context.相対Y座標dpx = ( ( context.進行カウンタ.現在値 % 6 ) == 0 ) ? ( StrokeStyleT.乱数.Next( 6 ) - 3 ) : context.相対Y座標dpx;
97                                                 context.透明度0to1 = 1.0f;
98                                         }
99                                         else if( context.進行カウンタ.現在値 < 240 )
100                                         {
101                                                 // (B-c) 130~239
102                                                 context.X方向拡大率 = 1.0f;
103                                                 context.Y方向拡大率 = 1.0f;
104                                                 context.相対X座標dpx = 0;
105                                                 context.相対Y座標dpx = 0;
106                                                 context.透明度0to1 = 1.0f;
107                                         }
108                                         else
109                                         {
110                                                 // (B-d) 240~300
111                                                 context.X方向拡大率 = 1.0f;
112                                                 context.Y方向拡大率 = 1.0f - ( ( 1.0f * ( context.進行カウンタ.現在値 - 240 ) ) / 60.0f );
113                                                 context.相対X座標dpx = 0;
114                                                 context.相対Y座標dpx = 0;
115                                                 context.透明度0to1 = 1.0f;
116                                         }
117                                         //-----------------
118                                         #endregion
119                                 }
120                                 else
121                                 {
122                                         #region " (B) Miss のアニメーション進行だけ他とは違ってたり。"
123                                         //-----------------
124                                         if( context.進行カウンタ.現在値 < 50 )
125                                         {
126                                                 // (A-a) 0~49
127                                                 context.X方向拡大率 = 1.0f;
128                                                 context.Y方向拡大率 = context.進行カウンタ.現在値 / 50.0f;
129                                                 context.相対X座標dpx = 0;
130                                                 context.相対Y座標dpx = 0;
131                                                 context.透明度0to1 = 1.0f;
132                                         }
133                                         else if( context.進行カウンタ.現在値 < 200 )
134                                         {
135                                                 // (A-b) 50~199
136                                                 context.X方向拡大率 = 1.0f;
137                                                 context.Y方向拡大率 = 1.0f;
138                                                 context.相対X座標dpx = 0;
139                                                 context.相対Y座標dpx = 0;
140                                                 context.透明度0to1 = 1.0f;
141                                         }
142                                         else
143                                         {
144                                                 // (A-c) 200~300
145                                                 context.X方向拡大率 = 1.0f - ( ( context.進行カウンタ.現在値 - 200 ) / 100.0f );
146                                                 context.Y方向拡大率 = 1.0f - ( ( context.進行カウンタ.現在値 - 200 ) / 100.0f );
147                                                 context.相対X座標dpx = 0;
148                                                 context.相対Y座標dpx = 0;
149                                                 context.透明度0to1 = 1.0f;
150                                         }
151                                         //-----------------
152                                         #endregion
153                                 }
154
155                                 // 描画。
156
157                                 var 判定文字列の画像 = this.文字列画像[ context.ヒット判定種別 ];
158                                 if( 判定文字列の画像.生成失敗 )
159                                         return;
160
161                                 var 判定文字列の左上端位置 =
162                                         new SharpDX.Vector2( context.相対X座標dpx, context.相対Y座標dpx )
163                                         + new SharpDX.Vector2( lane.レーンの中央X位置dpx(), lane.ヒット文字列の中央Y位置dpx() )
164                                         + new SharpDX.Vector2(
165                                                 -( ( 判定文字列の画像.サイズdpx.Width * context.X方向拡大率 ) / 2f ),
166                                                 -( ( 判定文字列の画像.サイズdpx.Height * context.Y方向拡大率 ) / 2f ) );
167
168                                 判定文字列の画像?.描画する(
169                                         dr,
170                                         左位置dpx: 判定文字列の左上端位置.X,
171                                         上位置dpx: 判定文字列の左上端位置.Y,
172                                         不透明度0to1: context.透明度0to1,
173                                         X方向拡大率: context.X方向拡大率,
174                                         Y方向拡大率: context.Y方向拡大率 );
175                         }
176                 }
177
178                 /// <summary>
179                 /// ヒット判定レーンには、それぞれに1つずつの進行描画コンテキストを用意する。
180                 /// </summary>
181                 protected class 進行描画コンテキスト
182                 {
183                         /// <summary>
184                         /// ヒット判定文字列のアニメ進行用カウンタ。
185                         /// このカウンタが動作中のときのみ、ヒット判定文字列が描画される。
186                         /// </summary>
187                         public FDK.カウンタ.単純増加後不変カウンタ 進行カウンタ;
188
189                         /// <summary>
190                         /// 現在表示中のヒット判定種別。
191                         /// 進行カウンタが動作中のときのみ有効。
192                         /// </summary>
193                         public ヒット判定種別 ヒット判定種別;
194
195                         public bool 判定対象である;
196                         public float 中央Y位置dpx;
197
198                         public float X方向拡大率;
199                         public float Y方向拡大率;
200                         public float 相対X座標dpx;
201                         public float 相対Y座標dpx;
202                         public float 透明度0to1;
203
204                         public 進行描画コンテキスト()
205                         {
206                                 this.初期化する();
207                         }
208                         public void 初期化する()
209                         {
210                                 this.進行カウンタ = new FDK.カウンタ.単純増加後不変カウンタ();
211                                 this.ヒット判定種別 = ヒット判定種別.AUTO;
212
213                                 this.判定対象である = true;
214                                 this.中央Y位置dpx = 0.0f;
215
216                                 this.X方向拡大率 = 1.0f;
217                                 this.Y方向拡大率 = 1.0f;
218                                 this.相対X座標dpx = 0.0f;
219                                 this.相対Y座標dpx = 0.0f;
220                                 this.透明度0to1 = 1.0f;
221                         }
222                 }
223                 protected Dictionary<ヒットレーン種別, 進行描画コンテキスト> ヒット判定レーンto進行描画コンテキスト = null;
224                 protected readonly Dictionary<ヒット判定種別, FDK.メディア.画像> 文字列画像 = new Dictionary<ヒット判定種別, 画像>() {
225                         { ヒット判定種別.PERFECT, new 画像( @"$(Static)\images\Judge Perfect.png" ) },
226                         { ヒット判定種別.GREAT, new 画像( @"$(Static)\images\Judge Great.png" ) },
227                         { ヒット判定種別.GOOD, new 画像( @"$(Static)\images\Judge Good.png" ) },
228                         { ヒット判定種別.POOR, new 画像( @"$(Static)\images\Judge Poor.png" ) },
229                         { ヒット判定種別.MISS, new 画像( @"$(Static)\images\Judge Miss.png" ) },
230                         { ヒット判定種別.AUTO, new 画像( @"$(Static)\images\Judge Auto.png" ) },
231                 };
232         }
233 }