Welcome back.
Now things are looking good in the spell menu hood.
If we click on a spell globe, we can see the descriptions and everything, but it'd be kind of nice
if we could deselect by clicking on it again.
So if it's already selected and we click on it, we should deselect it.
That would be nice.
And then we can just broadcast something to clear out the descriptions and set that selected ability
in the widget controller to none.
Right?
So let's make a function on the widget controller class for Deselecting one of our spell globes.
So I'm going to go to public UI widget controller, spell menu, widget controller and we'll make a
function that's blueprint callable.
For this, it'll be void and we'll call this Globe Deselect.
It'll take a const gameplay tag reference called ability tag.
And what should we do?
We should first of all set our selected ability so we can say selected ability equals for a gameplay
tags get dot abilities.
None.
And we can set the status to locked as well.
And it's actually selected ability, ability and the status for selected ability.
So selected ability status can be for a gameplay tags dot get dot ability status locked.
Now, we don't really need to know which Globe has deselected itself, do we?
All we need to do is just clear things out.
So I'm going to remove that input parameter.
We actually don't need to know.
So Globe Deselect is just going to set the selected ability to none.
And then we can broadcast spell globe selected delegate.
Only we can pass in false for both booleans to disable both buttons and the two description strings
can be the empty string.
F string loop autocomplete sometimes can get out of hand.
F string.
And F string.
So with this, we should see those buttons be disabled.
Let's give this a try.
Oh, before we give it a try.
This has to be blueprint callable, so I'm going to hit cancel there and make this a blueprint callable
function like so.
And we can test this.
Now, there's something we have to do when we select a globe.
The globe itself needs to know if it's already selected.
So a globe should have a boolean so it knows if it's selected already or not.
Okay.
So what we need to do is go into our spell globe button and right here, as soon as we're clicking,
what we need to do is check to see if we're already selected.
Well, that means we need a boolean.
So let's add a variable called selected and selected is going to be set whenever we actually select
that should be in the select function because that's when we actually show our selection circle texture.
So we'll set it here to true.
When selected and when deselected.
Whenever deselect gets called, we'll set it back to false.
So we'll set it to false right here.
Now when we are clicking on a spell globe, we should check to see if we're already selected.
If we are.
If selected is true.
Well, if that's the case, we're going to do something entirely different, and only if selected is
false are we going to go through what we were doing before.
But if selected is already true.
Well, what I'd like to do is first of all deselect.
So we're going to call deselect, it'll set render opacity to zero and set selected back to false so
we can call deselect here.
But we can also get the widget controller and call the new blueprint callable function globe Deselect.
And this will handle things on the plus side, such as setting the current selected ability to none
and broadcasting the delegate that our spell menu needs to receive to disable its buttons and empty
out the description strings.
Let's try it.
We click.
We click again.
We click.
We click again.
It works.
And if we click on one, then click another.
It works as expected.
It's only if we click on one that's already currently selected.
Pretty nice.
Now.
It should make a sound when we deselect it.
So we'll just play a sound right here.
And that sound doesn't necessarily have to be the same sound that we've been using.
So let's do a play sound.
To D And why don't we just take a look at the sounds we have content, assets, sounds, UI.
We have a cancel.
Let's try one of these cancels and see how it sounds.
So listening.
Close.
That one's okay.
Let's try a different cancel.
Okay.
I'm going to try the third one.
Those sound pretty good, but I'm going to try.
I'm going to try one of the hover sounds.
Yeah, I like that.
Perfect.
Now we can deselect.
And I can just test my other stuff.
So I'm going to go ahead and upgrade this one and deselect it.
Look at that.
Cool.
Excellent.
Okay, so there's an edge case I want to check, and that's when I level up with nothing selected.
Let's go ahead and just level up.
All right.
So just as I suspected, we get this spell locked into level one.
Now, as soon as we level up with nothing selected, we shouldn't really see anything.
So I'm going to want to find out why we see that.
Now we get a spell description whenever spell points change and when the ability status changes and
both of those get the description from the ability system component.
So if we go to the aura ability system component into get descriptions by ability tag, then when we
don't have anything selected, the ability tag should be abilities none.
And what we're doing is we're checking if the ability info has that tag and we're checking the level
requirement for a real ability that exists in ability info.
But if it's abilities none or an invalid tag, then our description should be an empty string.
So I'd like to check.
I'd like to say first of all, if ability tag is valid and we'll just have a not as valid here and we'll
have an Or and say or ability tag dot matches tag we'll say matches tag exact abilities none so or ability
tags get abilities none.
And either of those cases we have a non valid tag or the tag is abilities.
None.
In that case I'm going to set out description to the empty string so equals just f string.
And then we'll have an else case.
And in the else case, we'll set out description to get locked.
Description.
So we'll have the lock description if it's a valid tag, if it's not a valid tag, we're not going to
show anything because there's no point in showing the level requirement in a message if there's no valid
tag there and there won't be a valid tag if we deselect because our spell menu widget controller now
has a globe deselect which will set that ability to abilities none.
So with that we should be able to test this out.
And we'll go ahead and press play.
We'll level up.
All right.
And we don't see anything there.
And I'm going to also test if I've already selected something and deselected.
Let's level up again.
And we don't see anything.
It's not until we have something selected that we see something.
And don't worry about this ability showing the lower ipsum that is the default description right in
or a gameplay ability.
And that's just there to tell us that this ability doesn't have a valid description.
And then these don't have any valid gameplay ability tags set to them, so we shouldn't see anything
for them.
Perfect.
So that concludes this video.
I'll see you in the next one.