OSDN Git Service

ユーザ管理クラスの、ユーザ選択の方法を変更。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Fri, 21 Oct 2016 05:36:55 +0000 (14:36 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Fri, 21 Oct 2016 05:36:55 +0000 (14:36 +0900)
次のユーザを選択(), 前のユーザを選択() を導入。

StrokeStyleT.sln
StrokeStyleT/StrokeStyleT.cs
StrokeStyleT/ステージ/ログイン/ログインステージ.cs
StrokeStyleT/ユーザ/ユーザ管理.cs

index 062fc83..eff2a4d 100644 (file)
@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 14
-VisualStudioVersion = 14.0.25402.0
+VisualStudioVersion = 14.0.25420.1
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StrokeStyleT", "StrokeStyleT\StrokeStyleT.csproj", "{ED72FD06-C276-42DC-9301-83DE699BDF4C}"
 EndProject
@@ -16,6 +16,9 @@ EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SSTFEditor", "SSTFEditor\SSTFEditor.csproj", "{487B9AFD-05D4-41AE-9800-21E16B382BB7}"
 EndProject
 Global
+       GlobalSection(Performance) = preSolution
+               HasPerformanceSessions = true
+       EndGlobalSection
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
                Release|Any CPU = Release|Any CPU
index 8203e70..bd07d55 100644 (file)
@@ -304,14 +304,15 @@ namespace SST
                                                        //---------------
                                                        if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
                                                        {
-                                                               this.ログインする( this.ログインステージ.ユーザインデックス );
-
                                                                var user = StrokeStyleT.ユーザ管理.現在選択されているユーザ;
 
-                                                               foreach( var path in user.曲の検索元フォルダパスのリスト )
-                                                                       SST.曲.曲ツリー管理.フォルダから曲を再帰的に検索して子ノードリストに追加する( user.曲ツリーのルートノード, path );
+                                                               if( null != user )
+                                                               {
+                                                                       foreach( var path in user.曲の検索元フォルダパスのリスト )
+                                                                               SST.曲.曲ツリー管理.フォルダから曲を再帰的に検索して子ノードリストに追加する( user.曲ツリーのルートノード, path );
 
-                                                               StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
+                                                                       StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
+                                                               }
 
                                                                this.現在のステージ.非活性化する( this.デバイスリソース );
                                                                this.現在のステージ = this.選曲ステージ;
@@ -578,21 +579,11 @@ namespace SST
                        }
                }
 
-               private void ログインする( SST.ユーザ.ユーザ ユーザ )
-               {
-                       StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ );
-                       FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
-               }
                private void ログインする( string ユーザ名 )
                {
                        StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ名 );
                        FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
                }
-               private void ログインする( int ユーザリストのインデックス番号 )
-               {
-                       StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザリストのインデックス番号 );
-                       FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
-               }
 
                #region " Win32 API "
                //-----------------
index 8aab83d..6da49d2 100644 (file)
@@ -13,7 +13,6 @@ namespace SST.ステージ.ログイン
        /// 出力:
        ///  (A) ユーザが選択された場合
        ///    this.現在のフェーズ                                                         ← 確定
-       ///    this.ユーザインデックス                                                   ← ログインしたユーザのインデックス(StrokeStyleT.ユーザ管理.ユーザリスト[])。
        ///    StrokeStyleT.ユーザ管理.現在選択されているユーザ  ← ログインしたユーザのユーザオブジェクト
        ///    
        ///  (B) キャンセルされた場合
@@ -31,11 +30,6 @@ namespace SST.ステージ.ログイン
                }
                public フェーズ 現在のフェーズ { get; protected set; } = フェーズ.初期状態;
 
-               /// <summary>
-               /// ログインしたユーザの、ユーザリストにおけるインデックス番号。
-               /// </summary>
-               public int ユーザインデックス { get; protected set; } = 0;
-
                public ログインステージ()
                {
                        this.子リスト.Add( this.ログイン画面見出し = new 文字列画像( "ユーザ選択" ) );
@@ -57,9 +51,7 @@ namespace SST.ステージ.ログイン
                                this.子リスト.Add( panel ); // 子リストに追加
                        }
 
-                       // 最初のユーザを選択する。
-                       this.ユーザインデックス = 0;
-                       StrokeStyleT.ユーザ管理.ユーザを選択する( this.ユーザインデックス );
+                       StrokeStyleT.ユーザ管理.最初のユーザを選択する();
                }
                protected override void On非活性化( デバイスリソース dr )
                {
@@ -120,8 +112,7 @@ namespace SST.ステージ.ログイン
                        }
 #else
 #warning ユーザ選択画面が完成するまでは、AutoPlayer で自動的にログインするようにする。
-                       this.ユーザインデックス = StrokeStyleT.ユーザ管理.ユーザのインデックスを返す( Properties.Resources.AUTOPLAYER );
-                       Trace.Assert( 0 <= this.ユーザインデックス, "[バグあり] AutoPlayer ユーザが存在しません。" );
+                       StrokeStyleT.ユーザ管理.ユーザを選択する( Properties.Resources.AUTOPLAYER );
                        this.現在のフェーズ = フェーズ.確定;
                        return;
 #endif
index 482df14..bf68be2 100644 (file)
@@ -9,32 +9,17 @@ namespace SST.ユーザ
 {
        public class ユーザ管理
        {
-               public IReadOnlyList<ユーザ> ユーザリスト => ( this.bs_ユーザリスト );
+               public List<ユーザ> ユーザリスト { get; protected set; } = new List<ユーザ>();
                public ユーザ 現在選択されているユーザ { get; protected set; } = null;   // 外から設定するにはメソッドを使う。
 
                public ユーザ管理()
                {
                        this.初期化する();
-                       this.bs_ユーザリスト.Add( new ユーザ( Properties.Resources.AUTOPLAYER ) );  // 既定ユーザ
-               }
-               public void ユーザを選択する( ユーザ 選択対象ユーザ )
-               {
-                       if( null != 選択対象ユーザ )   // null でもエラーじゃない
-                       {
-                               if( null == this.bs_ユーザリスト.Find( user => user == 選択対象ユーザ ) )
-                               {
-                                       var msg = "存在しないユーザを選択しようとしました。";
-                                       FDK.Log.ERROR( msg );
-                                       throw new SSTException( msg );
-                               }
-                       }
-
-                       // 選択ユーザを変更する。
-                       this.現在選択されているユーザ = 選択対象ユーザ;
+                       this.AutoPlayerを追加する();
                }
                public void ユーザを選択する( string ユーザ名 )
                {
-                       var 名前に該当するユーザ = this.bs_ユーザリスト.Find( user => user.名前 == ユーザ名 );
+                       var 名前に該当するユーザ = this.ユーザリスト.Find( ( user ) => ( user.名前 == ユーザ名 ) );
                        if( null == 名前に該当するユーザ )
                        {
                                var msg = $"存在しない名前「{ユーザ名}」のユーザを選択しようとしました。";
@@ -43,19 +28,49 @@ namespace SST.ユーザ
                        }
 
                        // 選択ユーザを変更する。
-                       this.ユーザを選択する( 名前に該当するユーザ );
+                       this.現在選択されているユーザ = 名前に該当するユーザ;
                }
-               public void ユーザを選択する( int index )
+               public void 最初のユーザを選択する()
                {
-                       this.ユーザを選択する( this.ユーザリスト[ index ] );
+                       this.現在選択されているユーザ = ( 0 < this.ユーザリスト.Count ) ? this.ユーザリスト[ this.ユーザリスト.Count - 1 ] : null;
                }
-               /// <remarks>
-               /// IReadOnlyList には FindIndex() がないので、このクラスでその機能を提供する。
-               /// </remarks>
-               /// <returns>存在しなかったら -1 を返す。</returns>
-               public int ユーザのインデックスを返す( string ユーザ名 )
+               public void 前のユーザを選択する()
                {
-                       return this.bs_ユーザリスト.FindIndex( ( user ) => ( user.名前 == ユーザ名 ) );
+                       if( ( null == this.現在選択されているユーザ ) || ( 0 == this.ユーザリスト.Count ) )
+                       {
+                               this.現在選択されているユーザ = ( 0 < this.ユーザリスト.Count ) ? this.ユーザリスト[ this.ユーザリスト.Count - 1 ] : null;
+                       }
+                       else
+                       {
+                               int index = this.ユーザリスト.FindIndex( ( user ) => ( user == this.現在選択されているユーザ ) );
+
+                               if( -1 == index )
+                                       throw new SSTException( "ユーザリストに存在しないユーザが選択されています。" );
+
+                               if( --index < 0 )
+                                       index = this.ユーザリスト.Count - 1;
+
+                               this.現在選択されているユーザ = this.ユーザリスト[ index ];
+                       }
+               }
+               public void 次のユーザを選択する()
+               {
+                       if( ( null == this.現在選択されているユーザ ) || ( 0 == this.ユーザリスト.Count ) )
+                       {
+                               this.現在選択されているユーザ = ( 0 < this.ユーザリスト.Count ) ? this.ユーザリスト[ 0 ] : null;
+                       }
+                       else
+                       {
+                               int index = this.ユーザリスト.FindIndex( ( user ) => ( user == this.現在選択されているユーザ ) );
+
+                               if( -1 == index )
+                                       throw new SSTException( "ユーザリストに存在しないユーザが選択されています。" );
+
+                               if( ++index >= this.ユーザリスト.Count )
+                                       index = 0;
+
+                               this.現在選択されているユーザ = this.ユーザリスト[ index ];
+                       }
                }
 
                public void UsersXmlを保存する()
@@ -123,12 +138,12 @@ namespace SST.ユーザ
                                                        if( false == string.IsNullOrEmpty( 新ユーザ.名前 ) )
                                                        {
                                                                // すでに同じ名前が存在するなら削除する。
-                                                               var 同名ユーザ = this.bs_ユーザリスト.FindIndex( user => user.名前 == 新ユーザ.名前 );
+                                                               var 同名ユーザ = this.ユーザリスト.FindIndex( ( user ) => ( user.名前 == 新ユーザ.名前 ) );
                                                                if( 0 <= 同名ユーザ )
-                                                                       this.bs_ユーザリスト.RemoveAt( 同名ユーザ );
+                                                                       this.ユーザリスト.RemoveAt( 同名ユーザ );
 
                                                                // リストに追加する。
-                                                               this.bs_ユーザリスト.Add( 新ユーザ );
+                                                               this.ユーザリスト.Add( 新ユーザ );
                                                        }
                                                }
                                        }
@@ -140,7 +155,7 @@ namespace SST.ユーザ
                        }
 
                        // AutoPlayer が存在しないなら、追加する。
-                       if( -1 == this.bs_ユーザリスト.FindIndex( ( user ) => user.名前 == Properties.Resources.AUTOPLAYER ) )
+                       if( -1 == this.ユーザリスト.FindIndex( ( user ) => user.名前 == Properties.Resources.AUTOPLAYER ) )
                        {
                                this.AutoPlayerを追加する();       // 追加して
                                this.UsersXmlを保存する();   // 保存。
@@ -150,20 +165,14 @@ namespace SST.ユーザ
 
                private void 初期化する()
                {
-                       this.bs_ユーザリスト.Clear();
+                       this.ユーザリスト.Clear();
                        this.現在選択されているユーザ = null;
                }
                private void AutoPlayerを追加する()
                {
                        var autoPlayer = new ユーザ( Properties.Resources.AUTOPLAYER );
                        autoPlayer.チップの自動演奏を一括設定する( true );
-                       this.bs_ユーザリスト.Add( autoPlayer );
+                       this.ユーザリスト.Add( autoPlayer );
                }
-
-               #region " バックストア。"
-               //----------------
-               private List<ユーザ> bs_ユーザリスト = new List<ユーザ>();
-               //----------------
-               #endregion
        }
 }