hey guys welcome back to the second tutorial that we're doing on menus so this time we're going to be drawing our menu to the screen and actually I might be moving through this pretty fast because I don't really want to concentrate on the drawing elements themselves this isn't really a series on how to design how to draw menus it's more about accessing all of our data from the grits so we're probably going to pick up the pace a little bit here let's go into the draw a GUI event and draw our menus and let's just
lay out the elements that we need to draw so I'm gonna split this up into four parts so first we'll and draw the back of the menu I'm just gonna draw a black rectangle but if you have a nice UI you will want to draw that here then we're going to draw the elements on the left side so remember those are the elements that we were storing as strings in the first columns of all of our grids then I'm just going to draw a dividing line and then I'm gonna draw any of the visual elements
themselves so for example with the audio sliders we're just going to draw some lines and knobs so those will be the elements on the right side alright now firstly let's do the setup I'm actually just going to add a line right here that's going to stop us from drawing if we're not currently paused and if you remember in the create event we had set up a variable called global pause and we'd set this to true and we're gonna toggle this whenever we want the pause menu to come up which means we don't want any of
this drawing if it is false so let's put if so not global pause so this is saying if Global at pause is false then exit and then it's not going to run any of this now a lot of my menu is going to be relative to the size of the view currently and I was storing at what size the view was in a couple other global variables these two right here and I'm probably going to be referencing these a lot throughout this draw event so I'm actually going to make some local variables that shortens these
words so let's do so G width for the global view width and G height of the global view height all right now the pause menu so this one's gonna be easy so we're in a draw rectangle color so the first two coordinates I'm going to give it is the top-left corner of the screen which is the reserved and then whatever the year view width and height is now for the color I'm actually just make another variable and make that equal to black so that I don't have to keep writing out see black and then the
last argument is if it's an outline or a filled in rectangle so we put false because we want it filled in all right so that will draw a black rectangle now we draw the elements on the left side so if you remember in the preview my elements on the left side they're centered in this screen and then they're offset slightly to the left and they're actually right justified text all right so I'm going to change a couple of the alignments here we're gonna draw a set V align to be the middle so that's the vertical
alignment and then draw a set H line to the right so we will get it anchored in the middle and on the right all right next I need a few more variables and I'm actually going to put them up here because they're going to be used for all of our drawing events so the first one is the grid itself so remember we only want to be drawing one page at a time so we only need access to one of these pages that we've set up because we're going to want to be drawing those elements for
that page and we had set up a menu pages array that is storing all of the IDs for the grits so we need to pull out whatever page we're on that entry in the array so let's do that I'm gonna make a variable called dear screwed equal to the menu pages page entry and I'm also just gonna get the height of the grid because that will get us the number of elements in the grid sir if it's the main menu there are three entries but if it's the settings there are five and that's because we're
gonna want to draw them centralized and depending on how many elements there are we're gonna have to bump them up or down to get where we should start drawing the elements from all right so a few more variables first a y-buffer and X buffer and these are gonna be how far away our elements are from each other or from the defining line so the Y buffer is how far they are vertically from each other and the X buffer is how far they are from the dividing line so you can play with those variables if you
want next is a start y and this is where I'm gonna start drawing the elements from because the first element isn't going to be drawing right in the center it's gonna be drawing in the center and then up a little bit and that little bit specifically is going to be half the amount of space that all of the entries are taking up so let's get that point so that's going to be so half of the view width is going to get us to the center of the screen and now we have to move up a
little bit so we know the number of elements is equal to the DS height and we actually have to put minus 1 here because I want the very first entry to not be affected by the Y buffer I know that sounds very strange in the abstract but in the end you'll see that all this math is going to work out so we have that and then we multiply this by the Y buffer because each entry is going to take up kind of one Y buffer all right so that is the start Y and that's also
get to start X and I'm just going to put this as half of the turtle width all right good so that is our set up these are variables that are going to be used by all of these sections now for the specific ones in here so for the left side so my first element so for example for the main menu that would be the resume that is going to start drawing itself at this start Y location that we've worked out and then the next one is going to add a y-buffer to that and draw it
at the next slot and for the start X this is just the middle of the screen so we're gonna actually have to bump this over for the left side so another variable and when call this LTX for left text exposition is just the start X minus the X buffer all right now we're gonna have to loop through the elements that we've got from this grid so we want to pull out this one then this one and then this one and we're going to draw these strings to the screen so we're going to have to use
another repeat loop and we're going to need a variable that we are incrementing to loop through the Y positions of the grid so we use YY again and the number of times we're repeating is the number of elements in the grid which we have gotten here so we used es height I remember to increment that y-variable alright so like I said while this start y-value is okay for the first string that we're drawing every subsequent one is going to have to be adding the Y buffer to its position so I'm going to set up another
variable and I might just add it here so we haven't actually set a value we've just declared it and then we'll set it in here so this will be equal to the start Y and then times whatever YY is by the Y buffer so it starts off at 0 so this is going to be 0 for the first one so it's just gonna start its at Y and then for the next one which is going to equal Y we get plus 1 Y buffer and it's gonna keep looping through like that so I've got Y
position now let's draw the actual text so we start off at the LT x LT Y and now we actually have to pull the value out of the grid so we're accessing the grid and the coordinates that we give it right so it was the first row so our X X is going to be 0 and then Y y is going to be whatever row we're on alright so that is it for the strings now let's just draw the dividing line so this one should be pretty easy I'm just going to use the function draw
line so it's going to start right in the middle at start X same position that the elements are drawing from and then it will go down to where the elements finish which is just going to be LT Y right this thing that is going to keep incrementing through the loop we can use that to get the final position of the elements all right so let's run and see what that looks like so far okay there we are so we have the elements drawing themselves and you might want to add a y-buffer to the ends of
this to get the line drawing to either side but that's just aesthetics right and before we go any further I'm actually going to add a way for us to move through the inventory so if you remember we started setting this up with our menu options so right now we set that to be at the very top and then whenever we alter this value we should change the thing that we're currently selecting so right now it should just be on the first one so let's get it to draw the thing differently if we are selecting it
so let's add a highlight to it so all we have to do is in here instead of draw texts just like this let's draw text color and I'm going to reuse this C value from before by default this is going to be white but if we find that our current YY value is equal to whatever row that were on so if it finds that the row that we're currently selecting is the one that we are currently drawing in our repeat loop then let's change this scene to be different color and if you want we can
even just alter its x-value a little bit so I might add another variable called X offset again by default this is gonna be 0 but here I'm going to minus half of the X buffer so I'm just going to move the one that was selecting over a little bit so all we have to do now is add XR to the horizontal position so generally this is just going to be zero so it's gonna be adding zero but if we're selecting it it's gonna move it over a little bit and we have to fill in there's
additional arguments for the color and we also need an alpha value let's just put one okay let's run the game and see that okay good so this is coming up as orange and it's been shifted over now we should add a way to change our selection so let's come into the step event and add some inputs and just like the drawer event I'm actually just going to grab this exact same line because we don't want to be doing any of this if we're not actually paused so let's add that and now I'm just gonna copy
in some inputs you've probably seen these before I don't really want to spend too much time on this I'm basically just getting the key presses of whatever key I have set in these variables so remember we were declaring those up here so at the moment I've just got this set to the keyboard presses so I've just gotten the up/down and enter because that's all we're going to be using for today all right and I'm also just going to grab this because we are also going to be needing access to the grid in the step event
all right and now let's detect whether we have gotten any change in the input so I'm going to make a variable called go change for option change so this is if we're changing the option that we're on and I'm just going to make this a sum so that if we happen to be pressing these down at the exact same time they're gonna cancel out so now I know that if our change is not equal to zero then we've either press down or we press up so let's go like that then we know that now it
is time to change what menu option that we're on so we can go menu option for the specific page that we're on remember that we had menu options for all of the different pages and all we have to do is just add whatever this sum equates to so this is our they're gonna be 1 or minus 1 plus equals option change all right but we're probably going to want to clamp this to be between only however many options that we have and again the number of elements that we have is just the DS height so
if I I'm on the third option and then I press down again I don't want us to keep going down I want it to loop back to the start so if the menu option of whatever page were on is larger than the total heights of the elements which is just the number of elements and then we have to put minus 1 because remember 0 it's gonna be counted as an entry that's the first entry so if that is the case then we know we have reached the very bottom entry and let's loop back to the
very top which is going to be entry 0 all right and similarly if we're up the very top and then we hit up again and we go into a negative then we're going to want to loop back to the bottom all right so if we'd run that okay so we can change the option all right cool now let's add a way for us to change what page that were on so what this is gonna do is we're gonna start setting up our ability to execute whatever kind of element it is so how I'm going to
do it is when I'm on an element and I hit enter I'm going to go and do whatever that element is for so if I hit enter on resume I'm gonna resume the game and if I hit enter on a page transfer element so if I hit enter on settings then I'm going to go to the settings page and for today's tutorial we're only gonna set up that page transfer one but as you'll see it's just going to be adding cases to a switch statement so let's get whether we have pressed enter so if input
enter P then what we're gonna do is use a switch statement and what we're switching is actually the contents of what type of element that we are on so let's just write this out dears grid so we're getting the types those are in column one the second column so we put one and then the row that we're on it's actually going to be whatever menu option is currently equal to so whatever option we're currently selecting is going to be the element that we want to access so we put like that and now what's your brackets
here because we're actually inside two square brackets all right so now what we're saying is whatever this is equal to now this is going to get one of those element types so one of these so depending on what this is we're going to do different things and now let's just do the page transfer one so in the case that it is equal to menu element type dot page transfer then we do what a page transfer does so we are changing the page and now we put the page that we want it to direct us to
so where were we storing that again right here in the second column of whatever grid it is so we get from column 2 menu of whatever option we're selecting and don't forget the break alright and in future tutorials we literally just add all the different cases for all the different elements but we'll just stay with this one for now and what you could also do is add some kind of audio if you want if you want to play a sound when you transition throughout the menu you put it here alright but that should do us
so let's run the game so if we hit enter on resume or exit it shouldn't do anything because it's not the type page transfer but if we do it on settings it should take us to another page and same for any of these all right good now finally let's draw those elements on the right side if we find if you're on a page that actually has them so if we're on a page for example like the audio that has those volume sliders let's come over to the draw GUI this will be the last thing we
do today down to here now remember we are still shifting the alignment over from the left side so because we're now drawing on the right side I'm going to align everything back to the left so let's change this and let's also add back just so that we don't forget because you want to change this back once we're done with everything so down here just make sure that you're changing the vertical alignment back the default value is just the top okay and just like we did for the left I'm gonna have an RT X so the
right position that we're going to start drawing it from which is going to be basically the same as this and it's also set up the Y position because we're also going to have a loop where we are adding the Y buffer all right except now instead of just drawing text we're going to be drawing different things again depending on what type of element it is so similar to our step event we can actually just grab this but instead of the y-coordinate being the option that we're on because we're just looping through the entire grid this
is just going to be whatever YY is equal to so let's also remember to increment our Y value here okay so what we also need to do just like before is set the Y position for we're currently drawing and that is going to be RT y time's the white buf up all right so now when we're going through the switch statement we're going to be checking to see if any of the element types that we're on is a shift or a slider or a toggle or an input and if it finds any of those then
we will draw them so they start with the shift type so for this one we are going to want to pull out one of these values right so this is the current value of Oberon and this is the entry in the array here that we want to access and draw so if it's currently set to zero then we want to pull out harmless and we want to draw that so we need access to both these columns and that is going to be column three and four so let's grab those just like that and then I'm
just gonna make a color here let's just make it white and then let's draw the text to RTX rty and now we have to get so this value the entry in this array so current array like that all right so that's just going to draw the string but I'm also actually going to draw a left shift and a right shift either side and we can just add strings together like this so now it will draw this whole string so it's going to draw this thing and then one of these entries and then this string but
I only want to draw them as a visual indicator to the player if they can actually shift to the left or right so if I'm on entry number zero then actually I can't shift any more to the left so I don't want to draw it then and if I'm at the very end of this array then I can't shift any more to the right so let's check before we go and draw it if our current value is equal to zero I'm just gonna make left shift now an empty string so then when it goes and
adds it here it's not going to make any visual difference and same for the other side just like that all right so let's run that and test that one oops looks like I put a - or it should have been a plus yep right hand this should be a plus right there we go and you can see that left shifts are working because we are not drawing that left most shift because we are on entry number zero all right and we'll get to actually altering these values in another tutorial but for now let's keep going
and draw next stop is the sliders all right so remember these have a couple of elements to them we have a line a circle and also a percent or at least I'm going to draw it as a percent so let's just do a set up as usual so I'm gonna have a variable called Lin and this is going to be the length of the line that we draw I'm just to set this to 64 we will grab the current value of what the slider is on and remember you can see right here it is in
column zero one two three I'm also just gonna set the color to whites so first up let's draw the line so when you draw a line width again we use our TX not CY and then the second x coordinate is out here X plus whatever you said is the length don't change the Y have it at a width of 2 alright next a circle now it's position is going to depend on whatever current value is so we kind of wanted as a ratio between whatever values that you set in here or again this is just
how I'm displaying it so you might want to alter this a little bit so I'm going to set up another variable called circle position we are also going to need access to the array and now this is gonna be a bit of ugly maths here but just bear with me so we're getting the current value right so this is either going to be 0 or 1 and then we take this away from whatever the first value in your little array is here and this is just I've done this in case you have different numbers here
so if you have a number that's like 2 or 5 and you're going between values of 2 & 5 and then we divide this by the bottom so that we get kind of a ratio of where this is between the two entries here so now we just put our TX + and we're going to do so we'll pause times the length because this is gonna be a decimal number if we times that by the length so for example if this works out to be 0.5 if the volume is in the middle then if we times
that by the length then that's gonna get us right to the center of the line which is where we want the slider to appear so we might even test this let's change this to some different variables 0.5 0.2 and I'll keep that one as one and finally the actual text itself and I'm just gonna do this at length times 1.2 just so that's a little bit over to the right of whatever the length is and now I'm actually gonna use this value here because I know this is gonna be some decimal number all right so
if we use this and then times it by 100 we can get the percent and what I'm gonna do is firstly because this is a number I'm going to convert this to a string because we have to be drawing a string here and I'm also going to floor it and then I'm going to add a scent sign so that it looks like we're drawing a percent alright let's run that there we go so that's worked perfectly all right let's keep going next case is the toggle so two things to draw here on and off and
I'm basically just going to draw it so that whatever value that it currently is so if the toggle is on zero so if it's currently on then I'm going to draw the on string completely filled in and if it is on the other side then I'm going to draw it kind of gray so let me just set up the strings but now for their colors so I'm actually gonna have two colors and depending on what the current value is right which is stored in the third column as you can see here for our toggle type
here so it's also stored in that column so you might want to draw actually these values but this is just a suggestion for what you can do so if current value is equal to zero but I'm going to set color one which is going to be the color for this one to be C which I'm just gonna set as white and in this case C two we know is going to be that darker gray otherwise is just going to be the L way around all right so now we can color them just like that this
one let's move it over I'll just do 32 there you go so we can see that it is currently off just like I said it here alright next one and this is the last one the input now just like before we're going to get the current value of the input which are stored in the fourth column which is column zero one two three so let's get it and now depending on what the value is we're gonna want to draw different things now I'm just gonna keep this simple and do this as a switch statement because
while this is fairly easy for characters we're gonna have to manually set up the strings for virtual keyboard because the actual value of this is just a bunch of numbers but we have to translate this into something that's going to be meaningful to the player so we're gonna check if whatever this thing is which is gonna be a bunch of numbers so if this is equal to whatever the bunch of numbers that VK up is I'm going to change a variable that I'm just gonna pull string Val let's just declare that yeah it's gonna make
this equal to up key alright and let's do this for a punch for them and then finally it's a little easier if it's just any of the letter keys what we can do is say if it's not any of these we can just go set the default case as so we can use this function CHR to get the character that this is alright and now we just draw whatever string values so again we set a color to white drill the text like that all right let's run the game so everything that we're drawing in the
menu should be set up now all right good so we're done now in the next tutorial we'll get to actually changing and in putting things into our menu so I just like to thank everyone on patreon who is supporting me to create these tutorials and I'd like to give a special shout out to Danielle Hargrave maximal and our ethyl Ian XT game studio the great poultry Stewart wells 172 and Hunter T thanks for watching guys I hope you're well and I'll see you next time