Welcome back.
Now our menu is coming along.
We can create new slots.
We can select slots and delete them and restore things to their original state.
And that's great.
But let's say we create a slot, we give it a name and we select it.
We want to be able to play the slot, but in addition to that we should see something here for the map.
This should be something meaningful.
This is going to be the map that we travel to.
And if we just created this slot like I just did here, this needs to be the starting map.
There needs to be a default map.
Well, I'd like to have that map designated.
I'd like to store that somewhere important, like the game mode.
The game mode can determine that rule.
Where do we start when we first start the game?
Provided we don't give that as a choice to the player.
So the game mode needs some kind of variable for this level.
So that's the first thing I'd like to add.
And in addition to that, the game mode also needs to know all of the maps in the game.
Because if we've saved our slot and we travel to some other map, then when we're loading in here in
the menu and we press play, we need to travel to that other map too.
So the game mode needs to know about all the maps and how to identify them, and I'd like to identify
them with their user facing string.
Now, widgets use f text.
A lot of things in the engine use f name.
I'd like to use an F string to store the maps name and identify each map with its map name.
So I'm going to add a variable and I'd like to add it to the game mode.
But notice we have two game modes, right?
If we go into blueprints game, we have a load screen game mode, and we have an aura game mode and
load screen.
Game mode is based on if we look at its class settings, the aura game mode base, and we can add those
maps to Aura Game Mode base and then set them here in the game mode.
Of course, if we need them, set both in the load screen game mode and or a game mode, then we would
have to go in and set them in both blueprints.
So instead what we can do is have load screen game mode based on the BP or game mode blueprint, and
then we can just set those map names in aura game mode and load screen game mode will inherit that.
So I'm going to take Load screen game mode, go to Class Settings and base this.
Now on BP Aura Game mode.
And now we only need to set those maps in or a game mode.
Now, as soon as we did that, we need to make sure that our class defaults are what we want.
HUD class is load screen HUD, which is good, but we don't need our player state to be or a player
state.
It can just be regular player state.
We don't need our player controller set to or a player controller.
It can just be the regular player controller, and we don't want the default pawn class to be our character.
We want it to be default pawn so we don't spawn in aura in the load screen.
And after making that change, we can press play and make sure that we still get the behavior that we
expect here in the load screen.
And we do.
So now all we need to do is add to our aura game mode base, which both of our game mode blueprints
inherit from a starting map, and of course, a list of all the maps which we'll get to.
But for now, we at least need the starting map, and we want it associated with the starting map name.
So let's go into C plus plus and open our aura game mode base.
We're going to need at least an F string for the starting map name.
So let's make an F string called starting map name.
And this can be added defaults only, so we can set that from within our editor.
And our starting map name should be the name of, of course, the starting map.
But we need to keep track of all the maps in some kind of data structure.
I hate to say it, but a map comes to mind.
So a map of maps?
That's confusing, but let's make a t map.
And the t map can map f strings to the maps themselves.
And so what are the maps themselves going to be?
Well, if we want to set these in the editor and the details panel, we can make these t soft object
pointers.
If we choose T soft object pointer we need to choose the type.
This is a template wrapper.
And for maps we need to choose you world.
And these are soft object pointers which is nice because they're not loaded in memory until they're
used.
They're lazily loaded.
So we won't have all of our maps loaded in all at the same time.
Now we can call this maps or levels or whatever we want to call it.
I'm going to call it maps just because I can, and I'm going to make it edit defaults only.
And we'll make sure to fill this in with all of the maps.
And we have to make sure that the default map, whatever it is, is in here.
And it has the same name as our starting map name.
That way we can travel to it.
Now if we want to be absolutely sure that that's the case, that our maps will contain our default map,
and that it has the correct map name, we could create a t soft object pointer of type u world called
default map.
So we'll do that default map and we can make this edit defaults only as well.
And we can make sure that maps has the default map added to it.
We won't add the default map in the editor.
We'll add the default map here in code, just to make sure that it has the correct name and map association.
So we'll go ahead and do this in the game modes begin play I don't think we're overwriting begin play.
So we'll override begin play.
That's a protected function.
Virtual void.
Begin play override.
And here in begin play, after calling super, we're going to take maps and add the default map name.
Which we called starting map name.
Let's call it default map name so as to avoid confusion.
And we're going to add default map name as the key and default map.
As the value.
So now we just need to go into or a game mode base and set the default map name.
And then later when we create more maps, we'll add them to the maps.
So first things first, let's go in to the editor and set these two properties.
So let's open up.
We have our load screen game mode, but I'm going to go into aura game mode and set them all here.
So we have a default map name.
And I'm just going to call this first dungeon.
And the default map itself is going to be that dungeon level.
And as we compile and go back to load screen game mode and scroll down, we see that that first dungeon
is set to dungeon.
So that's great.
Now our game modes.
No, the default map.
Now, what I'd like to see is when I go into the load menu, pressing play, I want to see the default
map.
The starting dungeon right here for the map, and I want to see that as soon as we create a new slot
here, I want to see that starting map.
And it's called First Dungeon.
So we're going to need a field notify in our load slot view model.
So that's our next step.
Let's go ahead and do that.
So we go to mVVM load slot where we have our player name.
We already have a field notify which we made edit anywhere blueprint read write.
And we also created setters and getters for it.
But the thing is that the setters and getters are important because we don't want to set the player
name directly.
We want to make sure that we broadcast the field notify, but we also have to make this edit anywhere
blueprint read write if we want it to be a field notify.
That's because the field notify needs read write access to it in order to change it and to get information
from it on the blueprint side.
So we're in a peculiar situation where it should be private, but it can't be if it's blueprint read
write.
So for that reason, what we can do is we can move it into a private section.
Bring that player name down into here, and we can use a workaround to make it blueprint rewrite, but
still private.
In C plus plus we can use meta equals allow private access.
This will allow us to make it a private variable in C plus plus but exposed in the blueprint.
So now we have player name private.
We just have to make sure we're not setting or getting it directly.
And or a game mode base does do that and save slot data where it's setting the load screen, save game
player name to the player name and the load slot we have to call get player name now.
No big deal.
All right, so back to our task though.
We need a field notify for the map name so that we can bind that in the widget.
So I'm just going to copy player name and paste a new one.
And this one can be map name.
And it's going to also have the same view property.
It's going to be a field notify.
And with getter and setter in the U property we have to add getters and setters here in C plus plus
so we can make a setter void set map name.
It can take an f string called in map name.
And we'll generate a function definition for it because we're going to want to use the set property
value macro.
Let's just do that first thing.
We're going to set that it's our map name.
And we're setting it to in map name.
And that's going to be broadcast to any widgets that bind to this field notify.
And then we can create our getter.
It can return an F string get map name.
It'll be const and simply return map name.
So now we have a field notify.
All we need to do is actually set this map name and then bind to the field notify in our widget.
So when do we set the map name.
Well for starters I'd like to set it to the default map as soon as we've created our first slot.
And we can go back to mVVM, load screen to new slot button pressed, where we're setting our player
name to the entered name we're setting our slot status to taken.
We can also set that map name as well, so we can take our load slots of slot here, and we can set
its map name so we can call Set Map name.
That way we'll be sure to broadcast the field notify.
And what is the map name.
Well we want to get that from our game mode.
So we'll take our game mode.
And we're going to get that default map name.
And we'll set it to that.
And as soon as our player ventures into a new map, well then we need to worry about saving that information
to disk to our slot.
Right.
We'll get to that soon.
But for now, we just need to make sure that at least our map name is correct when we first create a
saved slot.
So we'll do that when a new slot is created.
So with this we just need to bind to our field, notify the map name in our mVVM load slot ViewModel.
Let's go ahead and compile and launch and make sure that our map name is bound to that.
All right.
So back in the editor we're going to get everything back open.
Now our load screen game mode definitely has that default map name.
So what we can do is we can go back into blueprints UI load menu and make sure that our load slot taken,
which is the one that has that map, has this property bound.
So this one we have this text and it's called text underscore map value.
We need to check is variable on that.
And then we can bind this text.
We'll do this just like we did the player name.
We're going to show our view bindings down here.
And we need to add one.
We need to click add widget.
And from the dropdown that says none we need to choose our widget.
And it's called Text Map value.
We're going to click on that and select it.
And we need to choose what property on it that we want to bind.
We want to bind its text.
We'll select that we want this one way to the widget.
And what we need to use is a conversion function.
So we can click on conversion functions.
We need two text from string.
So two text parentheses string.
And then the end string is going to be one of our field notifies the one on our load slot view model.
And it's called map name.
So we're going to select that.
And now we have our binding.
So we can test this.
So we can go back to Maps Load menu.
And playtest this, but we have to keep in mind that any slots that we already had saved, those we
never actually set their field notifies in those mVVM load slot view models.
It's only when we create a new game.
So let's create a new one.
I'll call this one Steven click new slot.
And now we see First Dungeon, because it's only when we create that new slot, when we press our button,
let's just remind ourselves here and load screen new slot button pressed.
This is when we set that slots map name.
That's when we broadcast that field notify.
So it's only because we just created a new one.
If we go ahead and take these slots and delete them.
And we create new slots.
Then they have first dungeon as well.
Now, first dungeon is kind of big.
We sort of need to lower our font size now, don't we?
We can do that.
Or if you like, the way it looks with the select slot button kind of lower.
It's kind of cool.
Let's see what happens when we delete it.
Create a new one.
It doesn't look too bad, but I think that these fonts could be a little bit smaller.
So before we wrap up, I'm just going to take these and make them just a bit smaller, just a tad.
Their size is 24.
We can try 18 and see how that looks.
So same for the map 18.
Dungeon 18.
We can see how that looks.
And I'm going to go ahead and delete these two.
Create new slots.
And those look a little bit better.
Of course, we might have text flow over, right?
Now if I click close and start up again, well, we're not showing that map.
We're not actually saving the map name and we're not updating the map.
We're not loading it.
And that's something that we could easily implement.
We need to save it.
So while we do have the ability to set the map name in our load slot view model and it updates in the
field, notify we're not actually saving it to disk.
And that's going to be our next step is saving the map name to disk.
And we'll do that next.