Welcome back.
So we've made an are you sure widget.
So we can select a slot.
We can hit delete.
And we have the ability to back out.
We can cancel.
And then we can hit delete again and it pops up again.
So this gives us a nice early exit.
But once we actually hit delete we want something to happen.
Right.
So we need something to happen in response to clicking on delete.
Now are you sure needs to bind something to that delete button.
I'm going to delete event tick and get it out of the way.
And we're going to get that button delete.
We're going to get its button widget.
And we're going to assign to Onclicked.
And we need to do something.
Now.
We could try to get that load screen view model and call a blueprint callable function on it to delete
something.
I don't want to do that, because this is kind of a generic widget that could be used as an rusher for
anything, especially if we make that message a variable that we can set anywhere.
So for that reason, I'm just going to broadcast a generic delegate, just like we did for our cancel
button clicked.
We're going to have another event dispatcher.
Let's add one and this will be our delete button clicked.
And we can simply broadcast that before calling remove from parent.
So let's broadcast delete button clicked.
We'll call that and we'll call remove from parent after that.
And that is going to remove this widget.
But also inform whoever subscribes to this delete button.
Clicked delegate that the delete button has been clicked.
And our load screen widget is going to subscribe to that.
So it's going to subscribe to another delegate on the rusher widget.
So let's take that rusher widget and let's assign something to delete button clicked.
So when the delete button has been clicked, we're going to do something.
Well, the delete button has been clicked.
So what we can do is we need to actually delete that slot because we're deleting the selected slot.
Now we don't know anything about what slot has been selected from the C plus plus side.
In our load screen view model, we need to know as soon as we've selected a slot which slot is currently
selected.
So that's something we should keep track of.
And as soon as we click on delete.
And not this one, but this one here, the real delete.
Well, we need to tell the ViewModel hey, something has been deleted, right?
So if we click on delete here, we do want that widget to go away.
And perhaps we still want these two buttons Play and delete to be disabled.
Because at this point the selected slot should no longer exist.
So we really shouldn't have a selected slot.
But the ViewModel needs to have the concept of a selected slot.
So what we need to do is every time we select a slot, we need to tell the ViewModel, hey, remember
which slot is selected, right?
So a couple of things.
We need our load screen widget to call a blueprint callable function.
On the load screen view model a delete button clicked or delete button pressed.
Right.
So let's go ahead and close out.
Save everything here and go to our load screen ViewModel.
That's mVVM load screen.
And we're going to need a delete button pressed function.
And it's going to need to know which slot is selected.
So two things we're going to first of all create that blueprint callable function void delete button
pressed.
And I'm not going to pass anything into it from the widget because our load screen widget doesn't really
know what is selected.
It just knows that the delete button has been pressed.
So this will be blueprint callable.
Let's generate a definition.
And what do we want to do?
Well, we need to know which slot is currently selected.
Well that means when we select a slot with select slot button pressed we need to know which slot we're
selecting.
So we should save this.
We should at least save the slot index or save the actual pointer to the slot the load slot.
Either one of those is fine, but we need a selected slot to save.
This can be a private variable.
It can be a um VM load slot pointer or it could be an integer.
It doesn't matter.
I'm just going to store a pointer to the load slot.
And we're going to call this selected slot.
And it's going to get a U property.
And our selected slot is going to be set as soon as we've called select slot button pressed.
So right here we're going to say selected slot equals.
And it's going to be the slot with this particular slot index.
It's going to be load slots.
Of slot.
So now we have the selected slot stored in this selected slot pointer.
And now when the delete button is actually pressed now we can decide how to delete that slot.
And then of course update the widget switcher as well.
So how are we going to delete a slot.
We need to delete that slot from memory.
We've already seen how we can do that.
If we look at our A game mode base.
If we go to save slot data, we've seen that we can call delete game in slot, and it's a good idea
to check if that slot exists first.
This is something we can create a function for on the game mode, so that we don't have to handle deleting
slots from a ViewModel.
We can let the very important game mode handle that for us.
So this right here could be refactored into a nice game mode function delete slot.
Let's do that.
Let's make an aura game mode base function called delete slot.
It can be void.
We'll call it delete slot, and it can take in the slot name and the slot index.
We'll pass those both in here.
Alternatively, we could even just pass in a mVVM load slot if we wanted to do that.
But I'm going to pass in the slot name and the slot index, and we'll just have this delete slot function.
We'll generate the definition and it's going to do this.
So we'll copy those lines there, check to see if it exists, and then we'll use the slot name.
And the slot index.
To delete the slot.
We can even have a boolean that returns the success or failure.
But for now, I'm fine with this.
Now this could be a static function as we're only calling a static functions in it.
So let's go ahead and make that static.
So that makes things even easier because now we can just call the static function directly here in load
screen.
Our view model.
So what we can do is say a or a game mode base delete slot.
But we need to know what slot.
Right?
So we have to get that slot.
Well we know it's our selected slot and this could be null at any point in time.
So we're going to say if selected slot.
We'll wrap it in an is valid.
And then we can call our or a game mode based static function delete slot passing in selected slot,
and we'll get its slot name, the load slot name, and the index.
So selected slot slot index.
Now we get red squiggles.
Says cannot convert f string to parameter type int 32.
Uh oh.
That doesn't sound good.
Let's go back and look.
Delete slot does take an INT 32 called slot index and an f string called slot name.
So the function signature is correct.
Slot index looks like it's an F string.
Interesting.
Let's go to mVVM load slot.
And take a look at that slot.
Index is an F string.
This should be an int 32 shouldn't it?
And we should be setting this slot index.
Let's make sure that we're actually setting that.
It should be set really as soon as we create it up here, as soon as we set our load slot name, we
should also set that index as well.
Otherwise it won't have any meaning.
So let's do it.
Load slot underscore zero.
We're going to take its slot index.
And we can set that.
It's going to be zero for slot zero.
And we'll set it for one and two as well.
So load slot one can be set to one and load slot two.
Can be set to two.
Now they're identifiable.
And then when delete button is pressed, we can now call delete slot and pass in that slot index.
Now that's great.
We're actually deleting the slot, but how are we going to update our HUD?
Well, for one that slot has a status right?
We have selected slot and we have a slot status not a slot index a slot status.
Now that it's going to have its slot deleted, it can be vacant.
We can set that to vacant, and we can tell it to go ahead and broadcast its delegate using the function
initialize slot.
Now it's going to be updated.
So this should effectively delete that slot.
Let's test that out.
We'll go ahead and run in debug mode.
All right.
So we're going to go ahead and open up those widgets we had open.
We can go into the load menu map.
Now we also need to make sure that our delete button here when it's pressed.
That our load screen widget knows about it.
So here in our load screen widget we know about it.
But we also want to call that blueprint callable function we created.
That's on BP load screen ViewModel.
And what's that function called?
It's called delete button pressed.
Let's call that delete button pressed.
There we go.
Let's just see what happens.
See if we've forgotten about anything that we haven't taken into account.
We'll select a slot, we'll hit delete.
And instead of hitting cancel.
We'll hit the delete button and there we go.
Now this is great because now we can press plus and we can enter a new name.
Let's call it John.
Click on new slot.
And now we have a new slot.
Now, just a couple issues that we're going to clean up.
Before we wrap up, let's go ahead and delete those slots and press play and click on New Game.
And the first issue that we need to take care of is as soon as we enter a name, let's say Joe.
Then this editable text block here is going to retain Joe.
So even though we click on new slot, we're switching to a different widget that says Joe.
That old widget with the editable text still has Joe, and we'll know that as soon as we select the
slot, delete it, confirm that deletion, and click on plus for a new game.
Joe is still there.
That's in that editable text, so we need to clear that out as soon as we leave this widget.
Well, that's pretty easy.
As soon as we click on new slot we can do that.
So if we go into our enter name widget and click on new slot, we'll go into our graph as soon as this
is clicked.
Well we know that we're calling a blueprint callable function new slot button pressed.
This will inevitably end up in our widget switcher switching to a different widget.
So since we're leaving this widget behind, we can take its editable text and we can set the text on
it.
We can call set text the function.
And we can set it to an empty string.
Now, if we press play and press new, I'll go to this one here.
We'll enter some text, make a new slot, we'll select that slot and delete that slot.
And if we click plus then it's empty again because we cleared it as soon as we clicked on new slot.
Now here's another issue I clicked on new slot and select slot is now disabled.
That's because we disabled it and then switched away from that widget and never set that back to enabled.
Now that's a problem.
If we don't have any other slots, let's say we click on this one, create a new slot and select that
slot and then come back.
We can now select this one because only when we select another slot are the select slot buttons for
the other widgets enabled again.
So that's a problem.
Whoops I accidentally clicked on quit.
Let's go back to play.
That's a problem right?
We need to actually enable this button again.
And when do we enable the button.
Well if I press plus here and create a new slot right.
And select it and delete it and click on delete right now as soon as I hit delete would be a great time
to re-enable that button.
So in other words, in the delete button pressed for this slot, we might as well go ahead and re-enable
that select slot button, because then next time we come back to it, when we create a new slot again,
it'll be enabled again.
So let's make sure that that happens when we delete a slot.
I'm going to go ahead and close down the editor and we'll go into our load screen view model into delete
button pressed.
Here's a good place to do it.
And our load slots have that delegate enable select slot button.
We can broadcast that delegate right here for this given slot.
So as we're deleting the slots we can go ahead and enable it.
Select slot button for the next time we get back to that widget.
So we're going to take our selected slot.
We'll get its enable select slot button delegate and we'll broadcast true.
So that should enable that button and we won't see that button get enabled as we're switching away from
that widget.
But next time we get to it we'll be actually able to select it.
So let's test this out.
So back in the editor let's go into maps load menu press play.
Now all of these have slots in them.
So I'm going to go ahead and just delete those slots and our save game folder.
Press play.
Now we're starting anew.
Now I'm going to click plus here and enter a name Stephen and click New Slot.
Now we have a slot I'm going to select that slot and hit delete and confirm that deletion and click
plus again.
Now I can enter a name.
Again I'm just going to enter S click on new slot.
And now I see that I can select that slot and I can play delete quit whatever.
Now so far we can't play but we can delete that slot.
We can cancel deletion, we can confirm deletion.
And now we know that that slot will be deleted.
And we can even check our save games.
That slot actually gets deleted from here if we create a new slot.
It comes back to our savegames.
If we select it and delete it and confirm it's gone from our Savegames pretty nice right?
Okay, so we're now able to delete slots, which is great.
That's an important feature.
But now it's time to actually play the game.
Which means well, we need some kind of level to go to.
Once we have a valid slot, we select it.
We click on play.
What are we going to do?
In that case, we're going to want to travel to a dungeon or a level of some kind.
And we need a default level to go to first.
And so we'll take care of doing that in the next video.
I'll see you soon.