Welcome back.
Now in our load menu we have three widget switchers.
Really there are own custom widget blueprints that have a widget switcher.
But we need a way to switch those widget switchers and we need an easy way to do so from C plus.
Plus as we have view models that we wish to do so with.
So I'm going to close the editor and go to my load slot view model, which is going to control those
widgets that have their view model set to it.
Now I'm actually done with my load screen HUD.
I'm going to close that.
I'm done with my load screen widget as well.
I'm going to close that and I'm going to get my mVVM load slot.
Both the header file and the cpp file.
Now load slot is going to want to somehow tell that widget switcher which of its three children to switch
to by index.
Now the widget switcher doesn't have its view model set to this load slot view model, but it does have
access to it at one point in time when it sets the view model for its children.
At that point, it can bind to a delegate.
So I'm going to declare one.
I'm going to declare a dynamic multicast delegate that broadcasts a single integer, so one per Ram,
and it's going to broadcast an index.
So I'm going to call this f set widget switcher index.
And it's going to pass an int 32.
We'll call this widget switcher index.
And then it can choose from among its child widgets which one to switch to.
Now that means we need one of these as a public member variable.
It's going to be an f set widget switcher index called set widget switcher index.
And it's going to be a U property with blueprint assignable.
Now which index we switch to, that's going to depend.
It's going to depend on data that we may have saved already and what we're loading.
Now we're not saving or loading anything yet, so we really don't have a meaningful index to broadcast.
But once we do, we can broadcast this, and I'd like to broadcast it by having a function on this view
model, we can call to initialize the slot on it.
So we can make a public function here called void initialize slot.
And this can basically have this class broadcast its slot index based on whatever its status is from
when we've loaded in data.
So we're not loading anything yet.
For now, all we can do is just create the definition and broadcast the delegate.
We can just try to broadcast something right.
We can call set widget switcher, index dot broadcast and just pass something in like one.
But we're going to have to make sure that we check our slot status based on loaded data.
So we're going to say to do check slot status based on loaded data.
And whenever we actually load data, we'll call initialize slot.
Okay.
So that's set up for when we're ready to use it.
Now in addition, our load screen view model is going to need some blueprint callable functions for
when some of our widget buttons are pressed.
We know we have three types of widgets which have buttons.
Some of them.
Let's go into the editor and see what buttons we have.
So we can go into blueprints UI load menu and we can look at our three widgets.
We have the take in which has a select slot button.
We also have vacant, which has its own button.
It's the vacant button we can call it.
And then we have Enter Name, which has a new slot button.
So we have three buttons and we need to handle those somehow.
Now we know that the view models for these are the load slot view model.
But when we press these buttons we actually need our load screen view model, the overarching one to
know about it.
Why?
Because it needs to check conditions.
It needs to update the other slots.
It has access to the other view models for the other slots, so it needs a function to call for each
of these, which means each of these also needs access to that other view model, not just BP load slot
view model.
Well, this system is flexible enough to allow for that.
You see we can take each of these three and we can click plus view model and we can add another one.
We can add a BP load screen view model.
We can select that in fact we know that we can have it search for its own view model by setting its
creation type to property path and setting this view model property path to find load screen view model.
And if we can compile without errors, we didn't have a typo.
Now let's do that for all three.
We can add that view model.
The BP load screen view model and set the creation type to property path and set that property path.
We'll do that for all three here.
BP load screen view model.
Property path.
And there we go.
So now each of these has two view models.
And that load screen view model is going to be set automatically via the property path.
Now this allows us to call blueprint callable functions on it because we have those getters.
Now for the load screen view model.
So the load screen view model can now have blueprint callable functions for select slot for the vacant
button or new game button, whatever we want to call that.
And for the new slot button.
So let's call these select slot new game.
And new slot buttons.
So I'm going to take select slot and call this button.
Select slot and check is variable.
We'll go to the vacant.
We'll take this button and call it button.
New game and check is variable.
And we'll go to enter name.
We'll take this button and call it.
Button new slot and check his variable and we can make blueprint callable functions in our load screen
view model for all of them.
We'll start with select slot and when we click select slot we need to tell that view model what our
index is, which we know we've already set.
So we're going to go to mVVM load screen.
We'll make a new function.
This can be void and we'll call it new slot button pressed.
And it'll take an INT 32 called slot.
And not only that, but what else are we entering for.
New slot.
Looks like we started with new slot right.
New slot button pressed.
That's actually this one.
Well what are we doing when we click new slot.
We're entering a name.
So we should enter a name.
So this function can also take an f string called.
Entered name and we can pass it in by const reference.
Sure.
I know that was the first question that came to your mind.
And this can be blueprint callable.
So you function.
Blueprint callable, not blueprint pure.
It's going to do too many side effects for that.
So we have this function now we'll hold off on implementing it.
We'll just need to make sure that we're calling it when we click the button.
Right now what else do we have.
We also have the new game button.
Button new game.
Let's implement that one.
And when we click this we need to pass in the index as well.
So we're going to make a new game button pressed void new game button pressed which will take it in
32.
We'll call it slot.
And this will also be blueprint callable.
Now.
In addition, we have a Taycan which is a select slot button, and this one should also pass in the
index as well.
We don't need to pass in any player name or level or anything.
This is all going to be populated from our view model.
So we're going to make a select slot button, pressed void select slot button pressed which will take
an int 32 for the slot.
And this also gets blueprint callable.
So let's go ahead and generate these definitions for both functions.
And we can compile just to call these blueprint callable functions.
But there is one thing we can test.
We can test our new game button pressed.
Why?
Because as soon as we click that plus icon, all we want to do is switch the widget.
We want to switch it to enter name widget.
So we can get our map called load slots.
We can take the index with slots, because this is the index of whatever widget we're clicking on.
And from this map we're getting our view model, the load slot view model, which has that delegate
we can broadcast set widget switcher index.
We can broadcast that passing in the next index.
Now for now we're just going to hard code.
We're going to try a one here because a one is the second widget.
So it should go from the vacant to the next one.
So we can compile and launch.
And we can test out this broadcast of the delegate, which we do need to still bind to.
So back in the editor we can call these blueprint callable functions.
Now we do need to make sure though that we take timing into account.
We need to know that at least our view model is valid before we try to bind callbacks to it.
Well, we know exactly when that happens, because if we go to our widget switcher.
We know right here in the graph exactly when our load screen view model is valid and our load slot view
model is valid, it's valid here.
And we have a blueprint callable function.
We can call on each of these child widgets.
We added that to the C plus plus base class load screen widget.
So if we take each of these widgets.
We can call after setting their load slot widget, we can call.
Blueprint initialize widget on them.
And we know that they will have their own load screen view model set by this time, so we can call that
on all three of them.
Here's load slot taken.
Here's load slot vacant.
And on each of them we'll call blueprint.
Initialize.
Widget.
And that's how we'll know the correct time.
To bind.
To assign our onclicked.
Functions.
So now that we're calling those and each of these three, we'll go into our graph and we'll implement
blueprint initialize widget.
This is kind of like our widget controller set functions we've used before.
I'm going to delete those three nodes.
And here I'm going to get BP load screen view model.
And I'm going to call for this one.
It's going to be the select slot blueprint callable function select slot button pressed.
And when am I going to call it.
I'm going to call it when this buttons on clicked event is fired.
So I'm going to get button select slot.
And it's a wide button.
So we're going to get the button.
Widget from it.
Type on clicked and a sign on clicked.
And when this button is clicked, we're going to call the view model blueprint callable function select
slot button pressed.
So that takes care of this widget.
Let's go to load slot.
And this is the new game button.
So here we're going to do the same thing.
We're going to implement blueprint initialize widget.
We're going to get BP load screen view model.
We're also going to get our button new game.
Now this is not a wide button.
It's just a regular button.
So we can just directly assign on clicked.
And when it's clicked, we're going to take our view model and call that new game button pressed.
Now, these do require some inputs, don't they?
Let's go back to the other one.
Yes.
This one needs a slot, doesn't it?
We can pass in our slot index.
We'll do that here as well.
Pass in the slot index.
You probably noticed that.
And we're headed over to the questions section to tell me.
Now we've taken care of this one.
Now for load slot and this one has this enter name.
We need to enter a name in here.
So this is an editable text right.
Let's give this a valid name.
Editable text underscore enter name and check is variable and we can always get the text from it.
So here we're going to say blueprint initialize widget.
We're going to get BP load screen view model.
And we're going to call the new slot button pressed.
So this is the new slot button pressed that we need to call here.
So we're going to get our button new slot.
It's a wide button, so we're going to get the button from it and call sign on clicked.
We're going to call this function passing in the slot index.
And we need the name that's been entered.
Now we have this editable text.
Enter name and we can call get text from it.
And we want to get text editable text.
And we can hook that in.
And this takes a string.
So we'll just convert it to a string.
And there we go.
Now when we click this the blueprint callable function will receive the slot and the entered name.
Now this is cool, but the only thing we can test is new game button pressed and this broadcast the
set widget switcher index.
But our widget switcher needs to respond to that.
So here's our widget switcher.
It needs to respond, and we can't assign here in a function.
We can't assign a event to a callback here.
We can only do it in the event graph.
But as soon as initialized slot has been called, we can call the blueprint callable function.
Blueprint.
Initialize widget.
Right here on itself.
It can call its own blueprint initialize widget.
And that's going to result in its event blueprint initialize widget being called.
And here it can get its own view model.
We've stored that variable right here for the load slot view model.
The load slot view model is who has the delegate where broadcasting.
Yes, we're doing it in load screen, but we're broadcasting it on the object of a load slot type.
So really this load slot view model shouldn't be a local variable but a member variable.
So here's what I'm going to do.
I'm just going to promote it to a variable and I'll just call it load slot view model.
We know it's the blueprint version, but I'm just going to use this instead of this local variable.
And I'll replace it.
I'll replace the local variable with the member variable.
And then I can delete BP, load slot ViewModel, and then I can rename this one to BP load slot ViewModel.
So now this is not a local variable but a member variable.
And now in our event graph we can access BP load slot ViewModel, and we can assign an event to widget
switcher.
And it's called Assign set widget switcher index.
We can assign an event to this.
And what do we want to do.
We want to switch our widget.
And we have a widget switcher right here.
It's not a variable we can check is variable.
It's called widget switcher 36.
We're going to call it widget switcher route.
And we're going to take that widget switcher route and switch its index.
So here it is.
And how do we switch it.
Well all widget switchers have set active widget index.
The function is what we want and we'll pass in widget switcher index.
And then it'll switch its widget based on that index passed in so we can save all.
Now we can go to our load menu and press play.
And if we click on one of these then we switch the widget.
So that delegate broadcast is working.
And now these buttons are calling blueprint callable functions.
But they're empty.
All of them are empty except for this one.
That we see is working.
So with that, we now have some more things set up.
But really, the only way that we can progress with this is by starting to save things.
Because the only way we can test out the rest of our mechanics and continue developing the rest of our
mechanics here is if we can enter a name such as Stephen here and click New Slot and actually save that
info.
And that way if we close down and open back up, next time we open this, we should see a different
widget.
Here we should see the taken widget that shows the name that's been saved, and perhaps some default
values or saved values.
So that means we need to start saving things to disk.
And that's what we're going to get started on in the next video.
I'll see you soon.