Browse Source

Updated post article review.

Simon Jackson 9 years ago
parent
commit
8b60bc9d0c

+ 60 - 0
MonoGameSamples/LocalizationSample/Content/BasicSpriteFont.spritefont

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This file contains an xml description of a font, and will be read by the XNA
+Framework Content Pipeline. Follow the comments to customize the appearance
+of the font in your game, and to change the characters which are available to draw
+with.
+-->
+<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
+  <Asset Type="Graphics:FontDescription">
+
+    <!--
+    Modify this string to change the font that will be imported.
+    -->
+    <FontName>Arial</FontName>
+
+    <!--
+    Size is a float value, measured in points. Modify this value to change
+    the size of the font.
+    -->
+    <Size>12</Size>
+
+    <!--
+    Spacing is a float value, measured in pixels. Modify this value to change
+    the amount of spacing in between characters.
+    -->
+    <Spacing>0</Spacing>
+
+    <!--
+    UseKerning controls the layout of the font. If this value is true, kerning information
+    will be used when placing characters.
+    -->
+    <UseKerning>true</UseKerning>
+
+    <!--
+    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
+    and "Bold, Italic", and are case sensitive.
+    -->
+    <Style>Regular</Style>
+
+    <!--
+    If you uncomment this line, the default character will be substituted if you draw
+    or measure text that contains characters which were not included in the font.
+    -->
+    <!-- <DefaultCharacter>*</DefaultCharacter> -->
+
+    <!--
+    CharacterRegions control what letters are available in the font. Every
+    character from Start to End will be built and made available for drawing. The
+    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
+    character set. The characters are ordered according to the Unicode standard.
+    See the documentation for more information.
+    -->
+    <CharacterRegions>
+      <CharacterRegion>
+        <Start>&#32;</Start>
+        <End>&#126;</End>
+      </CharacterRegion>
+    </CharacterRegions>
+  </Asset>
+</XnaContent>

+ 6 - 0
MonoGameSamples/LocalizationSample/Content/Content.mgcb

@@ -129,3 +129,9 @@
 /processorParam:TextureFormat=Auto
 /processorParam:TextureFormat=Auto
 /build:WPFFont.spritefont
 /build:WPFFont.spritefont
 
 
+#begin BasicSpriteFont.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:TextureFormat=Compressed
+/build:BasicSpriteFont.spritefont
+

+ 0 - 1
MonoGameSamples/LocalizationSample/LocalizationWindows/LocalizationWindows.csproj

@@ -49,7 +49,6 @@
     </Compile>
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <None Include="Resources\Strings.Designer.cs" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="MonoGame.Framework">
     <Reference Include="MonoGame.Framework">

+ 4 - 1
MonoGameSamples/LocalizationSample/LocalizationWindows/Properties/AssemblyInfo.cs

@@ -1,4 +1,5 @@
-using System.Reflection;
+using System.Resources;
+using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 
 
 // General Information about an assembly is controlled through the following 
 // General Information about an assembly is controlled through the following 
@@ -33,3 +34,5 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.0.*")]
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: NeutralResourcesLanguage("en")]
+

+ 0 - 90
MonoGameSamples/LocalizationSample/LocalizationWindows/Resources/Strings.Designer.cs

@@ -1,90 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
-//
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace LocalizationSample {
-    using System;
-    
-    
-    /// <summary>
-    ///   A strongly-typed resource class, for looking up localized strings, etc.
-    /// </summary>
-    // This class was auto-generated by the StronglyTypedResourceBuilder
-    // class via a tool like ResGen or Visual Studio.
-    // To add or remove a member, edit your .ResX file then rerun ResGen
-    // with the /str option, or rebuild your VS project.
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
-    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    internal class Strings {
-        
-        private static global::System.Resources.ResourceManager resourceMan;
-        
-        private static global::System.Globalization.CultureInfo resourceCulture;
-        
-        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
-        internal Strings() {
-        }
-        
-        /// <summary>
-        ///   Returns the cached ResourceManager instance used by this class.
-        /// </summary>
-        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Resources.ResourceManager ResourceManager {
-            get {
-                if (object.ReferenceEquals(resourceMan, null)) {
-                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LocalizationSample.Strings", typeof(Strings).Assembly);
-                    resourceMan = temp;
-                }
-                return resourceMan;
-            }
-        }
-        
-        /// <summary>
-        ///   Overrides the current thread's CurrentUICulture property for all
-        ///   resource lookups using this strongly typed resource class.
-        /// </summary>
-        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Globalization.CultureInfo Culture {
-            get {
-                return resourceCulture;
-            }
-            set {
-                resourceCulture = value;
-            }
-        }
-        
-        /// <summary>
-        ///   Looks up a localized string similar to Current culture: {0}.
-        /// </summary>
-        internal static string CurrentLocale {
-            get {
-                return ResourceManager.GetString("CurrentLocale", resourceCulture);
-            }
-        }
-        
-        /// <summary>
-        ///   Looks up a localized string similar to To change this, alter your system settings, then restart the sample.
-        /// </summary>
-        internal static string HowToChange {
-            get {
-                return ResourceManager.GetString("HowToChange", resourceCulture);
-            }
-        }
-        
-        /// <summary>
-        ///   Looks up a localized string similar to Welcome to the localization sample!.
-        /// </summary>
-        internal static string Welcome {
-            get {
-                return ResourceManager.GetString("Welcome", resourceCulture);
-            }
-        }
-    }
-}

+ 4 - 0
MonoGameSamples/LocalizationSample/SampleCode/Game1.cs

@@ -15,6 +15,7 @@ namespace LocalizationSample
 
 
         GraphicsDeviceManager graphics;
         GraphicsDeviceManager graphics;
         SpriteBatch spriteBatch;
         SpriteBatch spriteBatch;
+        SpriteFont MyFont;
         SpriteFont LocalizedFont;
         SpriteFont LocalizedFont;
         SpriteFont WPFFont;
         SpriteFont WPFFont;
         Texture2D currentFlag;
         Texture2D currentFlag;
@@ -42,6 +43,8 @@ namespace LocalizationSample
         {
         {
             spriteBatch = new SpriteBatch(GraphicsDevice);
             spriteBatch = new SpriteBatch(GraphicsDevice);
 
 
+            MyFont = Content.Load<SpriteFont>("BasicSpriteFont");
+
             LocalizedFont = Content.Load<SpriteFont>("LocalizedFont");
             LocalizedFont = Content.Load<SpriteFont>("LocalizedFont");
             WPFFont = Content.Load<SpriteFont>("WPFFont");
             WPFFont = Content.Load<SpriteFont>("WPFFont");
 
 
@@ -125,6 +128,7 @@ namespace LocalizationSample
             GraphicsDevice.Clear(Color.CornflowerBlue);
             GraphicsDevice.Clear(Color.CornflowerBlue);
 
 
             spriteBatch.Begin();
             spriteBatch.Begin();
+            spriteBatch.DrawString(MyFont, "Welcome to the localization sample!",Vector2.One,Color.White);
 
 
             spriteBatch.DrawString(LocalizedFont, "Default font Drawing", new Vector2(100, 70), Color.White);
             spriteBatch.DrawString(LocalizedFont, "Default font Drawing", new Vector2(100, 70), Color.White);
             spriteBatch.DrawString(LocalizedFont, string1, new Vector2(100, 100), Color.White);
             spriteBatch.DrawString(LocalizedFont, string1, new Vector2(100, 100), Color.White);

+ 22 - 22
MonoGameSamples/LocalizationSample/WpfFontPipeline/WpfFontDescriptionProcessor.cs

@@ -266,7 +266,9 @@ namespace WpfFontPipeline
             this.input = input;
             this.input = input;
 
 
             // 出力先のFontContentの生成
             // 出力先のFontContentの生成
-            fontContnet = new WpfSpriteFontContent();
+            fontContent = new WpfSpriteFontContent();
+
+            GetLocalisedResX(input, context);
 
 
             // 文字の追加
             // 文字の追加
             AddExtraCharacters(context);
             AddExtraCharacters(context);
@@ -280,13 +282,11 @@ namespace WpfFontPipeline
             context.Logger.LogImportantMessage("処理文字数 {0}", input.Characters.Count);
             context.Logger.LogImportantMessage("処理文字数 {0}", input.Characters.Count);
 
 
             // その他の情報の設定
             // その他の情報の設定
-            fontContnet.LineSpacing = (int)(glyphTypeface.Height * fontSize);
-            fontContnet.Spacing = input.Spacing;
-            fontContnet.DefaultCharacter = input.DefaultCharacter;
-
-            GetLocalisedResX(input, context);
+            fontContent.LineSpacing = (int)(glyphTypeface.Height * fontSize);
+            fontContent.Spacing = input.Spacing;
+            fontContent.DefaultCharacter = input.DefaultCharacter;
 
 
-            return fontContnet;
+            return fontContent;
         }
         }
 
 
         private static void GetLocalisedResX(LocalizedFontDescription input, ContentProcessorContext context)
         private static void GetLocalisedResX(LocalizedFontDescription input, ContentProcessorContext context)
@@ -518,11 +518,11 @@ namespace WpfFontPipeline
                 var kerning = GetKerning(c, blackBox);
                 var kerning = GetKerning(c, blackBox);
 
 
                 // FontContentへの設定
                 // FontContentへの設定
-                fontContnet.CharacterMap.Add(c);
-                fontContnet.Kerning.Add(kerning);
-                fontContnet.Glyphs.Add(new Rectangle(
+                fontContent.CharacterMap.Add(c);
+                fontContent.Kerning.Add(kerning);
+                fontContent.Glyphs.Add(new Rectangle(
                     0, 0, blackBox.Width, blackBox.Height));
                     0, 0, blackBox.Width, blackBox.Height));
-                fontContnet.Cropping.Add(new Rectangle(
+                fontContent.Cropping.Add(new Rectangle(
                     blackBox.X - glyphBounds.X,
                     blackBox.X - glyphBounds.X,
                     blackBox.Y - glyphBounds.Y,
                     blackBox.Y - glyphBounds.Y,
                     glyphBounds.Width, glyphBounds.Height));
                     glyphBounds.Width, glyphBounds.Height));
@@ -550,10 +550,10 @@ namespace WpfFontPipeline
             for (int i = 0; i < layouter.Items.Count; ++i)
             for (int i = 0; i < layouter.Items.Count; ++i)
             {
             {
                 // グリフ位置情報の追加
                 // グリフ位置情報の追加
-                var rc = fontContnet.Glyphs[i];
+                var rc = fontContent.Glyphs[i];
                 rc.X = layouter.Items[i].Bounds.X;
                 rc.X = layouter.Items[i].Bounds.X;
                 rc.Y = layouter.Items[i].Bounds.Y;
                 rc.Y = layouter.Items[i].Bounds.Y;
-                fontContnet.Glyphs[i] = rc;
+                fontContent.Glyphs[i] = rc;
 
 
                 // 個々のグリフ画像をひとつの画像へ追加する
                 // 個々のグリフ画像をひとつの画像へ追加する
                 var pixels = layouter.Items[i].Tag as uint[];
                 var pixels = layouter.Items[i].Tag as uint[];
@@ -573,36 +573,36 @@ namespace WpfFontPipeline
             }
             }
 
 
             // 文字画像をまとめた画像をテクスチャへ変換する
             // 文字画像をまとめた画像をテクスチャへ変換する
-            fontContnet.Texture = new Texture2DContent();
+            fontContent.Texture = new Texture2DContent();
             switch(TextureFormat)
             switch(TextureFormat)
             {
             {
                 case WpfTextureFormat.Auto:
                 case WpfTextureFormat.Auto:
                     if (UseGradient)
                     if (UseGradient)
                     {
                     {
                         // グラデーション使用していればColorフォーマット
                         // グラデーション使用していればColorフォーマット
-                        fontContnet.Texture.Mipmaps = bitmap;
+                        fontContent.Texture.Mipmaps = bitmap;
                     }
                     }
                     else if (OutlineThickness > 0)
                     else if (OutlineThickness > 0)
                     {
                     {
                         // アウトラインのみ使用していればBgra4444フォーマット
                         // アウトラインのみ使用していればBgra4444フォーマット
-                        fontContnet.Texture.Mipmaps = bitmap;
-                        fontContnet.Texture.ConvertBitmapType(
+                        fontContent.Texture.Mipmaps = bitmap;
+                        fontContent.Texture.ConvertBitmapType(
                                     typeof(PixelBitmapContent<Bgra4444>));
                                     typeof(PixelBitmapContent<Bgra4444>));
                     }
                     }
                     else
                     else
                     {
                     {
                         // それ以外の単色フォントであれば単色に特化したDXT3圧縮をする
                         // それ以外の単色フォントであれば単色に特化したDXT3圧縮をする
-                        fontContnet.Texture.Mipmaps =
+                        fontContent.Texture.Mipmaps =
                             SingleColorDxtCompressor.Compress(bitmap, FontColor);
                             SingleColorDxtCompressor.Compress(bitmap, FontColor);
                     }
                     }
                     break;
                     break;
                 case WpfTextureFormat.Bgra4444:
                 case WpfTextureFormat.Bgra4444:
-                    fontContnet.Texture.Mipmaps = bitmap;
-                    fontContnet.Texture.ConvertBitmapType(
+                    fontContent.Texture.Mipmaps = bitmap;
+                    fontContent.Texture.ConvertBitmapType(
                                 typeof(PixelBitmapContent<Bgra4444>));
                                 typeof(PixelBitmapContent<Bgra4444>));
                     break;
                     break;
                 case WpfTextureFormat.Color:
                 case WpfTextureFormat.Color:
-                    fontContnet.Texture.Mipmaps = bitmap;
+                    fontContent.Texture.Mipmaps = bitmap;
                     break;
                     break;
             }
             }
 
 
@@ -893,7 +893,7 @@ namespace WpfFontPipeline
         FontDescription input;
         FontDescription input;
 
 
         // 出力先
         // 出力先
-        WpfSpriteFontContent fontContnet;
+        WpfSpriteFontContent fontContent;
 
 
         // フォントサイズ(DIU)
         // フォントサイズ(DIU)
         float fontSize;
         float fontSize;