Welcome back.
Now if we load up our menu here, as you can see I have three slots saved just from playing around entering
in a name no name and saving.
We have these slots saved and as we've seen we can go in and delete any of these from our save games.
I can delete the third one there and it won't show up anymore because it no longer exists.
But as soon as we do enter something in here, now we have a select slot button.
This one's up a little bit.
It's raised because with no text there, well it sort of collapses that text box there.
But either way we have a select slot button which is not implemented.
And we want to be able to select a slot.
Now, what that means is as soon as we have a slot selected, we should remember that somehow, somewhere.
And that should affect what happens if we press our play or delete buttons.
So we need a way to know which slot is selected.
First of all, and as soon as we do select a slot, if any of the other two are selected, we need to
update those as well.
If we select a slot, how are we going to know it's selected?
Well, a good way is to disable the button, right?
So we need a way to first of all disable the button and then respond to knowing which slot is selected.
Now if we go into our widgets.
And UI load menu and take a look at the take in widget.
Our select slot button if we go to the graph.
Has its onClick event and it's calling select slot button pressed, letting the mVVM load screen view
model know which button has been pressed.
Another thing we can do is we can disable the button itself.
We can take our select slot button.
And with its button we can call set is enabled.
And we can set it to not enabled, we can disable the button.
Now all that's going to do is if we click on it, it'll be disabled.
If we click on any of them, they'll all be disabled.
And when that happens, we should probably go and enable all the other buttons if they are disabled
already.
So that very basic task we can handle.
We know that our load screen view model is going to know which button was just selected, and it can
set the others to be enabled.
So how is it going to do that if it doesn't know anything about the actual widget blueprints themselves?
Well, it has a reference to the other view models, the load screen view models.
Those load screen view models are capable of broadcasting data, and we can easily broadcast data up
to their widgets.
For example, if we go to our load slot view model, we've already made a delegate to broadcast the
widget switcher index.
We can make another one to broadcast whether or not to enable the select slot button, right.
So we can make a new delegate called F enable select slot button.
And this can broadcast a boolean and it can be called be enable.
So we can have a blueprint assignable delegate here.
And we can call it enable select slot button.
And it can be of course blueprint assignable.
Right.
And we can broadcast a value for this.
So we need to bind to this in our load slot taken.
And we're going to have to compile to do that.
But before we go about doing that we can also realize that as soon as select slot button pressed is
called, we can then tell those slots to broadcast that delegate.
So here in our load screen ViewModel and select slot button pressed, the first thing we can do is we
can access our load slots, and we can broadcast that delegate with a boolean based on which slot there
is.
So we can loop through those slots.
Here's a loop in load data where we're doing just that.
We can copy that.
And we can have a for loop here where we're looping over each of our load slots, and we can even tell
each of the load slots to broadcast that delegate.
We can take that load slot and we have to get value from it.
That gives us the load slot.
We can access that enable select slot button delegate and we can broadcast.
Now as long as they bind some event to this delegate in those widgets, then they can respond by enabling
or disabling the button.
But if we just selected a button with this slot, the slot that's passed in, we only want to disable
that one and enable the others.
So what we can do is we can check the key here and see if it's equal to that slot.
So we can say if load slot dot key is equal to slot in that case then this is the button that we should
disable.
So really if we go back into blueprint we don't really even have to disable anything here as long as
we bind to a delegate.
Because that delegate can be broadcast and we can respond to it and disable the button there, we can
simply get our load slot dot value.
And broadcast, and we want to disable the button so we can pass false in here.
Now for all the others.
In other words, there's an else case here we can broadcast true to enable those buttons.
So what we'll do is paste this line and change this from false to true.
And now all we need to do is make sure that those widgets bind to enable select slot button.
So we can save all here and close the editor.
And we can compile and relaunch and bind to enable select slot button.
Let's try that.
So back here in the editor, here's our load slot taken.
We can have this widget bind a callback as soon as we know that it has a valid load slot view model.
Now in event blueprint initialize widget we know that it does.
Because if we remind ourselves by going back to our widget switcher and our widget switcher and initialize
slot.
Here's where it's finding the load screen view model.
It's finding the specific load slot view model based on the slot index.
It's setting its own member variable, and then it's going through each of its three children and setting
each of their BP load slot view models to the load slot view model here, because those view models
are set to be assigned manually, and only after assigning that view model does it call blueprint initialize
widget.
So we know that in blueprint initialize widget those view models are set.
It's a lot like widget controller is set in the system we created using MVC.
So because of that, we know that it's safe to bind to our load slot view model.
If we search for BP load slot view model we can get that get BP load slot view model and we can drag
off of it and assign enable select slot button.
Now we're going to hook this up straight from the other bind.
Not the event but the bind.
As this is only fired off when clicking the button.
This is as soon as that ViewModel is valid.
And as soon as we get the broadcast here, we can take our button, the select slot button.
Grab that, get the button from it and call set is enabled.
And we'll pass in the boolean enable.
Now let's test this out.
We'll go back to our maps.
Go to load menu.
We'll save all press play.
And if we select a slot it becomes disabled.
Now because of that delegate broadcast.
And if we select another slot, all the others become enabled.
Now it's clear which one is selected, at least visually.
But we also need to know which one is selected in code.
We should have some load slot designated as the selected slot, and we're going to handle that next.
We'll do that in the next video.
For now we know that we can affect the other widgets whenever we select one of them.
Pretty cool.
Great job.
We'll continue with this in the next video.
I'll see you soon.