Skip to content

Commit ef99857

Browse files
Merge pull request MonoGame#55 from AristurtleDev/feedback/chapter-21
Address Chapter 21 Feedback
2 parents 5df0fd7 + 3505c9e commit ef99857

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

articles/tutorials/building_2d_games/21_customizing_gum_ui/index.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,18 @@ The slime and bat sprites are no longer in the same position, and we have some n
132132

133133
[!code-csharp[](./snippets/atlas-definition.xml?highlight=5-16,29-32)]
134134

135+
The same is now true for the tiles in the texture atlas. Since they have been repositioned in the new texture atlas, we need to update the `region` attribute for the tilemap XML configuration file. Open the `tilemap-definition.xml` configuration file and update it to the following:
136+
137+
[!code-csharp[](./snippets/tilemap-definition.xml?highlight=3)]
138+
135139
### Adding Bitmap Fonts
136140

137-
While MonoGame natively uses [**SpriteFont**](xref:Microsoft.Xna.Framework.Graphics.SpriteFont) to draw text, Gum uses the [AngelCode Bitmap Font (.fnt)](https://www.angelcode.com/products/bmfont/) font file format. This means we will need to supply Gum with the *.fnt* file that defines our font.
141+
While MonoGame natively uses [**SpriteFont**](xref:Microsoft.Xna.Framework.Graphics.SpriteFont) to draw text, Gum uses the [AngelCode Bitmap Font (.fnt)](https://www.angelcode.com/products/bmfont/) font file format. This means we will need to supply Gum with the *.fnt* file that defines our font.
142+
143+
> [!NOTE]
144+
> For this tutorial, a pregenerated *.fnt* file is supplied below. For more information on creating *.fnt* files for Gum, see the [Create Fonts with BitmapFontGenerator](https://docs.flatredball.com/gum/gum-tool/gum-elements/text/use-custom-font#creating-fonts-with-bitmapfontgenerator) section of the Gum documentation.
138145
139-
First, download the *.fnt* file by right-clicking the following link and saving it as *04b_30.fnt* in the game project's *Content/fonts* folder:
146+
Download the *.fnt* file below by right-clicking the following link and saving it as *04b_30.fnt* in the game project's *Content/fonts* folder:
140147

141148
- [04b_30.fnt](./files/04b_30.fnt){download}
142149

articles/tutorials/building_2d_games/21_customizing_gum_ui/snippets/animatedbutton.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Gum.DataTypes.Variables;
44
using Gum.Graphics.Animation;
55
using Gum.Managers;
6-
using Gum.Wireframe;
76
using Microsoft.Xna.Framework.Input;
87
using MonoGameGum.Forms.Controls;
98
using MonoGameGum.GueDeriving;
@@ -37,21 +36,21 @@ public AnimatedButton(TextureAtlas atlas)
3736
nineSliceInstance.Height = 0f;
3837
nineSliceInstance.Texture = atlas.Texture;
3938
nineSliceInstance.TextureAddress = TextureAddress.Custom;
40-
nineSliceInstance.Dock(Dock.Fill);
39+
nineSliceInstance.Dock(Gum.Wireframe.Dock.Fill);
4140
topLevelContainer.Children.Add(nineSliceInstance);
4241

4342
// Create the text element that will display the button's label
4443
TextRuntime textInstance = new TextRuntime();
4544
// Name is required so it hooks in to the base Button.Text property
46-
textInstance.Name = nameof(textInstance);
45+
textInstance.Name = "TextInstance";
4746
textInstance.Text = "START";
4847
textInstance.Blue = 130;
4948
textInstance.Green = 86;
5049
textInstance.Red = 70;
5150
textInstance.UseCustomFont = true;
5251
textInstance.CustomFontFile = "fonts/04b_30.fnt";
5352
textInstance.FontScale = 0.25f;
54-
textInstance.Anchor(Anchor.Center);
53+
textInstance.Anchor(Gum.Wireframe.Anchor.Center);
5554
textInstance.Width = 0;
5655
textInstance.WidthUnits = DimensionUnitType.RelativeToChildren;
5756
topLevelContainer.Children.Add(textInstance);

articles/tutorials/building_2d_games/21_customizing_gum_ui/snippets/optionsslider.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Gum.DataTypes;
33
using Gum.DataTypes.Variables;
44
using Gum.Managers;
5-
using Gum.Wireframe;
65
using Microsoft.Xna.Framework;
76
using MonoGameGum.Forms.Controls;
87
using MonoGameGum.GueDeriving;
@@ -41,7 +40,7 @@ public OptionsSlider(TextureAtlas atlas)
4140
topLevelContainer.Height = 55f;
4241
topLevelContainer.Width = 264f;
4342

44-
TextureRegion backgroundRegion = atlas.GetRegion("slider-background");
43+
TextureRegion backgroundRegion = atlas.GetRegion("panel-background");
4544

4645
// Create the background panel that contains everything
4746
NineSliceRuntime background = new NineSliceRuntime();
@@ -51,7 +50,7 @@ public OptionsSlider(TextureAtlas atlas)
5150
background.TextureLeft = backgroundRegion.SourceRectangle.Left;
5251
background.TextureTop = backgroundRegion.SourceRectangle.Top;
5352
background.TextureWidth = backgroundRegion.Width;
54-
background.Dock(Dock.Fill);
53+
background.Dock(Gum.Wireframe.Dock.Fill);
5554
topLevelContainer.AddChild(background);
5655

5756
// Create the title text element
@@ -77,7 +76,7 @@ public OptionsSlider(TextureAtlas atlas)
7776

7877
// Create the "OFF" side of the slider (left end)
7978
NineSliceRuntime offBackground = new NineSliceRuntime();
80-
offBackground.Dock(Dock.Left);
79+
offBackground.Dock(Gum.Wireframe.Dock.Left);
8180
offBackground.Texture = atlas.Texture;
8281
offBackground.TextureAddress = TextureAddress.Custom;
8382
offBackground.TextureHeight = offBackgroundRegion.Height;
@@ -86,14 +85,14 @@ public OptionsSlider(TextureAtlas atlas)
8685
offBackground.TextureWidth = offBackgroundRegion.Width;
8786
offBackground.Width = 28f;
8887
offBackground.WidthUnits = DimensionUnitType.Absolute;
89-
offBackground.Dock(Dock.Left);
88+
offBackground.Dock(Gum.Wireframe.Dock.Left);
9089
innerContainer.AddChild(offBackground);
9190

9291
TextureRegion middleBackgroundRegion = atlas.GetRegion("slider-middle-background");
9392

9493
// Create the middle track portion of the slider
9594
NineSliceRuntime middleBackground = new NineSliceRuntime();
96-
middleBackground.Dock(Dock.FillVertically);
95+
middleBackground.Dock(Gum.Wireframe.Dock.FillVertically);
9796
middleBackground.Texture = middleBackgroundRegion.Texture;
9897
middleBackground.TextureAddress = TextureAddress.Custom;
9998
middleBackground.TextureHeight = middleBackgroundRegion.Height;
@@ -102,7 +101,7 @@ public OptionsSlider(TextureAtlas atlas)
102101
middleBackground.TextureWidth = middleBackgroundRegion.Width;
103102
middleBackground.Width = 179f;
104103
middleBackground.WidthUnits = DimensionUnitType.Absolute;
105-
middleBackground.Dock(Dock.Left);
104+
middleBackground.Dock(Gum.Wireframe.Dock.Left);
106105
middleBackground.X = 27f;
107106
innerContainer.AddChild(middleBackground);
108107

@@ -118,21 +117,21 @@ public OptionsSlider(TextureAtlas atlas)
118117
maxBackground.TextureWidth = maxBackgroundRegion.Width;
119118
maxBackground.Width = 36f;
120119
maxBackground.WidthUnits = DimensionUnitType.Absolute;
121-
maxBackground.Dock(Dock.Right);
120+
maxBackground.Dock(Gum.Wireframe.Dock.Right);
122121
innerContainer.AddChild(maxBackground);
123122

124123
// Create the interactive track that responds to clicks
125124
// The special name "TrackInstance" is required for Slider functionality
126125
ContainerRuntime trackInstance = new ContainerRuntime();
127126
trackInstance.Name = "TrackInstance";
128-
trackInstance.Dock(Dock.Fill);
127+
trackInstance.Dock(Gum.Wireframe.Dock.Fill);
129128
trackInstance.Height = -2f;
130129
trackInstance.Width = -2f;
131130
middleBackground.AddChild(trackInstance);
132131

133132
// Create the fill rectangle that visually displays the current value
134133
_fillRectangle = new ColoredRectangleRuntime();
135-
_fillRectangle.Dock(Dock.Left);
134+
_fillRectangle.Dock(Gum.Wireframe.Dock.Left);
136135
_fillRectangle.Width = 90f; // Default to 90% - will be updated by value changes
137136
_fillRectangle.WidthUnits = DimensionUnitType.PercentageOfParent;
138137
trackInstance.AddChild(_fillRectangle);
@@ -146,7 +145,7 @@ public OptionsSlider(TextureAtlas atlas)
146145
offText.FontScale = 0.25f;
147146
offText.UseCustomFont = true;
148147
offText.Text = "OFF";
149-
offText.Anchor(Anchor.Center);
148+
offText.Anchor(Gum.Wireframe.Anchor.Center);
150149
offBackground.AddChild(offText);
151150

152151
// Add "MAX" text to the right end
@@ -158,7 +157,7 @@ public OptionsSlider(TextureAtlas atlas)
158157
maxText.FontScale = 0.25f;
159158
maxText.UseCustomFont = true;
160159
maxText.Text = "MAX";
161-
maxText.Anchor(Anchor.Center);
160+
maxText.Anchor(Gum.Wireframe.Anchor.Center);
162161
maxBackground.AddChild(maxText);
163162

164163
// Define colors for focused and unfocused states
@@ -251,4 +250,4 @@ private void HandleValueChanged(object sender, EventArgs e)
251250
// _fillRectangle uses percentage width units, so we multiply by 100
252251
_fillRectangle.Width = 100 * (float)ratio;
253252
}
254-
}
253+
}

0 commit comments

Comments
 (0)