Hello and welcome.
In this lecture we are going to be hooking up an ad button.
So if I go in click and you see that we are getting new paintings being added in just as we would like
it to happen so this is going to require us to pass around a few references because the Adding is being
done from the painting picture the whole actor where as the ad button is getting triggered obviously
from this ad widget so we gonna have to figure out how to pass around the calls that need to happen.
So let's dive in and find out how to do it.
Okay so we've got to the stage where and button and that delete button are both calling back to you
functions that we've created in C++.
Now this is not actually where we want to handle the creation and reloading of our menus.
If you have a look at where we're currently doing the reloading of the menu it's over in the painting
picker c p p and in begin play we basically load up or the slots right here.
Now what we want to do is do this after we have created a new painting.
So it would make sense that the creation code actually happens here in the painting picture.
Now the painting picker is a parent of the action bar it has a reference to the action bar so maybe
we can do something with that.
You'd think maybe we can from the action bar find the parent.
Well actually we can't.
Not very easily.
We have to go ahead and set up our own referencing system.
By this I mean that they're painting peca is going to have to set itself as the parent of the action.
It's got the action by in here.
And that set itself as a parent.
So that's what we're going to do.
We're going to go over to the action bardolph h and we're going to create our selves first of all a
private pointer to point up to the painting picker.
It's going to be a new property but I'm not going to expose it in any way.
And I'm going to include here the painting picker.
Todd H.
Like so.
So that then we can use the a painting pick her as the pointer type and we'll call this the parent picture
like so.
And I am going to make a public function called.
Which can take return void called set.
Parent.
And it's going to take that type.
And we can even define it in line.
Because what it's going to do um take in the new parent pick up and it's going to make the parent picture
equal to the new parent picker.
Simple setter there.
Okay.
And I've noticed I still got this test variable here from before we don't need that.
We can go ahead and build it shouldn't have changed very much because we're not calling it or setting
it and doing anything with it.
But we do want to set it we do want to pass that reference down all the way down so we're going to go
to the painting picker P P and in begin play is probably a good logical place to do this.
We're going to go ahead and get hold of in the same way as we were getting hold of the widget for the
painting grid.
We're going have to do a hash include.
For the action bardolph H.
And then what we can do is instead of the painting grid we can do the action bar.
So we're going to do action barc get use a widget going to cancel it to the new action bar then we're
going to put it into a variable called Action bar widget type you action bar and then we're going to
do a nold check at the end of that.
And if we have actually got is this correct.
No this is not quite correct because I'm interleaving with some other functionality here now to stop
me from making this mistake again.
I'm actually going extract this other functionality into its own method it really shouldn't be in begin
play like this.
So let's see if we can use the extract functionality quick actions extract function and I am going to
it's gonna be a member function What's it going to be called I and we'll have a refresh.
Slots has the name and it has a boolean return type.
I don't think we're going to need that.
We might have to go and change the arguments in just a second.
Let's let it do the extract.
Okay now I can see why it wanted that bullion return type because it thought that we wanted to keep
the exact same execution flow.
So I'm just going to tidy up a little bit remove the if statement remove the return flag from the refresh
slots and remove it from the definition in the C++ and the header.
Sometimes using these automatic tools is more trouble than it's actually worth.
So okay that's what we're going to do the early return was really just there so that we didn't execute
the rest so we don't care that it really returns at exactly that point.
So and we don't necessarily need to return out a big in play so that's just tidy things up a little
bit and we'll need that refresh slots later on.
And let's just check.
Is this is in the protected section.
I actually want it to be a private function not protected to refresh the slots.
Okay.
So that works now with this action bar.
I'm glad you make this and if we have an action bar rather than an early return and say if we have the
action bar then go ahead with the action by which it pointer arrow set parent peca to this.
So we've got a reference in the action bar widget at this point.
So what do we do next.
Well we want to call back up to painting picker.
When the button is pressed this is also fairly straightforward.
We do have to have a function on painting picker for us to call.
So we're going to create a new public function.
It's going to be called ad painting.
And return void.
And that's what we're going to call.
So we're going to go over to the action boss E P P.
Note the actual body.
H.
Actually because what we've got is this in line at the moment and button clicked.
I'm going to keep it in line because it's going to be very very simple indeed it's going to be an if
we have a parent picker because we might not have it yet and remember it's only set and begin play or
so my forgotten to set it so we can't rely on it.
But if we have this parent picker then we're going to go ahead and call the what did we call it and.
Painting on that occasion.
So it's passing up the add button clicked to the parent picker.
And I can actually do this all on one line.
Notice I'm not using khali brackets in this particular If statement that it could to one liner you can
do that.
And I tend to be okay with that as long as you're doing it on the same line if you split it out onto
a separate line.
Then I always put the curly brackets even though it's not strictly necessary.
Just because someone might add a second line and think that is going to do that do something and it
doesn't.
K. So that should have passed the call all the way up to the parent where it will then call into ad
painting which we can double check just by doing you a log.
Painting.
So.
And just finish off.
The curly brackets and build and see whether that is going to work as we expect.
Okay so now that compile has finished Let's go over to unreel hit play and see where we're at.
So let's go ahead and hit the button a couple of times then go and take a look at the output log.
They go ad painting has been called on the painting pic.
So our convolution of setting the pointer and then going back up has worked wonderfully.
So here is your time to do an actual challenge to create the painting and reload.
So create a new painting is the challenger going to hook up the delete function as well as a bonus.
You going to call that function on paining because something like enabled delete mode because you're
not going to instantly delete you're actually going to go into delete mode.
Then we're going to implement the add a painting function and remember that you'll need to reload after
adding a painting so that it shows up in the UI and then go ahead and test it out.
You may need to have deleted some paintings.
Otherwise you will see anything more than your adding stuff so pause a video and have a go.
How k.
Welcome back.
So let's go ahead and delete the paintings from our savegame folder to save to save games.
Delete all the paintings that are currently in there.
So we've got somewhere to start with.
I can remember how to delete things in Windows Explorer go and then we are going to go ahead and draw
some inspiration from the code we've actually deleted already.
So in initialised begin play for widgets.
I think we got rid of a load of code in the VR porn which was already doing a create for us and in fact
all we need to do is this new painting save game colon on Create so we can easily do that.
We can just go ahead and implement ad painting.
I'm going to do it into the C++ even though it's a one liner.
It has got a bit of implementation functionality and we need to include in the head of files so it makes
sense for this to go over into the C++ So let's copy its signature and go just above.
I think I may have made just below refresh slots because refresh slots is quite important.
And then we're going to have to hash include the saving system we've already got the savegame index
in here are also going to add the saving cut forward slash pain to save game.
Don H.
And in creation we're going to do a you create you pain to save.
Gain colon colon create.
Remember this also saves it so it creates it saves it.
And that will be enough.
And then after we've created want to make sure we do a refresh.
Of the slots.
So.
And let's see if that builds and works.
And while it's building in fact and when to go and go to the action bar Don H and do the similar hook-up
for add delete button clicked.
So we need another public function that's going to be void enable or in fact like have it toggle delete
mode.
Like so.
And that's what we're going to call let's call that over in the action.
DON H.
So go and do it with the same kind of if God protection.
And it is going to be taller than just a call to toggle delete mode instead of ad painting.
And that should do the trick.
And we want to just check it by putting in sign inline definition with a unique log of like so and that
you log is simply going to say toggle delete mode.
So that's the second thing to check.
Go ahead and build that too.
Okay so let's give this a shot go to the editor hit play.
Take a look at our UI which has got nothing on it at the moment.
Hit the add button and something appears horray it works.
But one thing I want to show you now is if I hit the add button again.
Keeps working more or less.
So okay that seems good.
But one thing that will happen is that at the moment we're going to be having multiple widgets at any
point here.
I wonder if there's a way I can actually show you this in the hierarchy so you can go have a look at
our painting peca.
In their heart out world out lynna Let's have a look then at the painting grid.
Not particularly obvious.
Maybe if we go to the blue print for the painting grid and debug filter there you go we can select the
painting grid that's actually in the world.
Let's see whether there's any way of actually seeing what's in the hierarchy maybe with the graph.
No not particularly obvious we'd have to we'd struggle.
But basically when we're doing this refresh we aren't clearing out the slots.
We're going to deal with that in the next lecture though so don't worry about it for now let's check
and delete button.
Going to hit the delete button a couple of times.
Go over in to my log.
And sure enough trouble delete mode is also hooked up and working great stuff.
We have hooked up our button and made it actually do what it needs to do which is adding some new games.
Let me just show you that you can go into these games you can load them up.
Start drawing exit and the games are still there.
No more have been added because we've removed that adding functionality from our big in play.
And I can go to a new game which is empty.
I can go to the same game again and it's got the same old squiggle.
So that is fantastic.
We have hooked up adding functionality and as saving is working and the next lecture will do a little
bit of cleanup around those double added items.