So good news, the design for the inventory is practically done! After having finished the design of the inventory we begun the production phase where we created the functionality for the inventory. Being familiar with Adobe Flash and creating user interface with it, I knew this would be fairly simple, seeing there were similarities between flash and widget blueprints. The only worries I had were well basically getting the item to drag and drop upon pressing a button. So taking from what we know and had to be done we begun creating logic in the event graph of the inventory. To make this fairly easy and dynamic I created a function called
Drop Item with the parameters of
Class Actor and a
array of Image.
|
DropItem Function |
With these parameters I would be able to plug them into statements that would allow me to spawn an actor of type class and changed the opacity of an array texture 2D image. To begin the function we said if
button is click is false,
play a sound. Afterwards
spawn an actor of type class and the parameter we will put in for this is our input parameter
Actor. Still in the same statement we spawn this actor at a
Vector MousePos. The point of
MousePos is to hold the position of the mouse's X,Y coordinates. So upon clicking the button, spawn an actor at mouse position. To add onto this function we set the return value of spawn actor to
Target actor and then
set the opacity of the input image to
fifty percent. So upon clicking the button we want to give that look that hey... We pressed a button so all other buttons are disable, visually speaking. To continue this we set button is click value to true at the end of the function. Thus ending the function of
Drop Item. Now if we were to test this out in the game nothing really would happen because we never called the function. To actually make something happen in game we added four given functions into the event graph. These functions were
OnPress for IS1, IS2, IS3 and IS4. What we basically said was on each button press, call the
DropItem function. For each of these methods we made sure to assign two parameters in the DropItem function. In
IS1 we assigned the
board,
IS2 we assign the
Duct tape,
IS3 we assigned the
lock and
IS4 we assign the
gate actors. For each of these methods we also made sure in the array parameter to set all four images in there.
|
Button Click Events |
So now in the game world upon clicking on a button something would actually happen. Upon click, a mesh will spawn on the mouse position and all four images of the button would be somewhat translucent. Now if the player were to move the mouse, well the mesh wouldn't move. Why? The answer for that came from the game loop. We never stated in the game loop to dynamically set the mouse position at every tick. Before continuing on I wanted to say, me and my partner spent a while figuring out how to get the inventory to drop while dragging. The logic is pretty simple and fairly easy however it became difficult after finding out on UE4 with widget blueprints, you can't specify
On Release events for buttons. Which is odd because you can specify On Release events for actors in a scene. With knowing this though, we still were able to add this functionality in the game loop using two tests. So if button is click is true and left mouse button is not down, at every tick set the
MousePos to the actual mouse position on screen and then set the actor location. If left mouse button was down, don't do this but instead set button is click to true. Having this logic will allow us to basically drag and drop.
|
Event Tick Event |
Upon playing the game now if I were to hit any of the buttons what will happen is a mesh would be spawned at the location of the mouse position and at every second the mesh will follow the mouses position until I click again. Having completed this logic was very satisfying mainly because, in Max Proof it isn't just the inventory where you can drag and drop items, but items in the game world too. So you can probably assume, creating the logic for the actors in the game world was fairly easy! In all honesty, the drag and drop functionality in the game world looks way more clean than the inventory mainly because I can actually do On Release events! Now enough about that, that will be for another blog. From looking above your probably wondering why I never mention about the hover button function as well as the refresh button function. My goal is to actually go over that in the next blog as I finish up polishing the inventory in Max Proof. Stay tune!
No comments:
Post a Comment