Unfortunately that's not my problem. I know which button is clicked (using my "clickCheck" function), but in order to assign a function to a button I have to take every single button and put it into an if statement (or switch-case statement like you used). If I had 30-50 buttons spread out across four different GUIs (like, say, inventory, player profile, main menu, combat, etc) I would have a very large section of code that would be a bit out of place.
So I would instead like to know if there is a way to "assign" a function to a button so that I could later just call that function without using a click check. Here's an example of how it is now:
if(aMouse.LeftButton == ButtonState.Pressed) {
// check if FirstButton has been clicked
if(FirstButton.clickCheck(aMouse.X, aMouse.Y) == true) {
this.Quit(); // in this case, FirstButton's function is to quit
}
// check if SecondButton has been clicked
if(SecondButton.clickCheck(aMouse.X, aMouse.Y) == true) {
// something else
}
// check if ThirdButton has been clicked...
if(ThirdButton.clickCheck(...) == true) {
.
.
.
// and so on for all buttons, of which there could be too many
}
The problem with this (or a switch-case) statement is that I have to define my buttons from within the mouse's event check. If I have a lot of buttons that's a very very long set of if statements and isn't a very elegant way of doing things.
Instead I would like something …