Beispiel #1
0
 static void SetFontHandler( Player player, Command cmd )
 {
     string Param = cmd.Next();
     if ( Param == null ) {
         CdSetFont.PrintUsage( player );
         return;
     }
     if ( Param.ToLower() == "reset" ) {
         player.font = new Font( "Times New Roman", 20, FontStyle.Regular );
         player.Message( "SetFont: Font reverted back to default ({0} size {1})",
             player.font.FontFamily.Name, player.font.Size );
         return;
     }
     if ( Param.ToLower() == "font" ) {
         string sectionName = cmd.NextAll();
         if ( !Directory.Exists( Paths.FontsPath ) ) {
             Directory.CreateDirectory( Paths.FontsPath );
             player.Message( "There are no fonts available for this server. Font is set to default: {0}", player.font.FontFamily.Name );
             return;
         }
         string fontFileName = null;
         string[] sectionFiles = Directory.GetFiles( Paths.FontsPath, "*.ttf", SearchOption.TopDirectoryOnly );
         if ( sectionName.Length < 1 ) {
             var sectionList = GetFontSectionList();
             player.Message( "{0} fonts Available: {1}", sectionList.Length, sectionList.JoinToString() ); //print the folder contents
             return;
         }
         for ( int i = 0; i < sectionFiles.Length; i++ ) {
             string sectionFullName = Path.GetFileNameWithoutExtension( sectionFiles[i] );
             if ( sectionFullName == null ) continue;
             if ( sectionFullName.StartsWith( sectionName, StringComparison.OrdinalIgnoreCase ) ) {
                 if ( sectionFullName.Equals( sectionName, StringComparison.OrdinalIgnoreCase ) ) {
                     fontFileName = sectionFiles[i];
                     break;
                 } else if ( fontFileName == null ) {
                     fontFileName = sectionFiles[i];
                 } else {
                     var matches = sectionFiles.Select( f => Path.GetFileNameWithoutExtension( f ) )
                                               .Where( sn => sn != null && sn.StartsWith( sectionName, StringComparison.OrdinalIgnoreCase ) );
                     player.Message( "Multiple font files matched \"{0}\": {1}",
                                     sectionName, matches.JoinToString() );
                     return;
                 }
             }
         }
         if ( fontFileName != null ) {
             string sectionFullName = Path.GetFileNameWithoutExtension( fontFileName );
             player.Message( "Your font has changed to \"{0}\":", sectionFullName );
             //change font here
             player.font = new System.Drawing.Font( player.LoadFontFamily( fontFileName ), player.font.Size );
             return;
         } else {
             var sectionList = GetFontSectionList();
             if ( sectionList == null ) {
                 player.Message( "No fonts have been found." );
             } else {
                 player.Message( "No fonts found for \"{0}\". Available fonts: {1}",
                                 sectionName, sectionList.JoinToString() );
             }
         }
     }
     if ( Param.ToLower() == "size" ) {
         int Size = -1;
         if ( cmd.NextInt( out Size ) ) {
             if ( Size > 48 || Size < 10 ) {
                 player.Message( "&WIncorrect font size ({0}): Size needs to be between 10 and 48", Size );
                 return;
             }
             player.Message( "SetFont: Size changed from {0} to {1} ({2})", player.font.Size, Size, player.font.FontFamily.Name );
             player.font = new System.Drawing.Font( player.font.FontFamily, Size );
         } else {
             player.Message( "&WInvalid size, use /SetFont Size FontSize. Example: /SetFont Size 14" );
             return;
         }
         return;
     } else {
         CdSetFont.PrintUsage( player );
         return;
     }
 }