Hi.
I'm currently messing around with C# and decided to write a small game. One of the first things I am doing is setting up the game's GUI, which I am designing myself with help from XNA (but not Windows Forms).
I've already made proof-of-concept buttons that can be placed, scaled, given multiple images (default, clicked, hovered, and disabled), as well as a "GUI" element that can hold sets of buttons and handle their enabled/disabled state en-masse (for switching between menus).
My problem is with the function of the buttons themselves. Right now, when the mouse is clicked, it runs through the current GUI's buttons using a function of my Button class called "clickCheck" to see if the mouse has been clicked within a specific button. This works great when I have only a few buttons, but it seems like it will get out of control if I ever get a "game" going as there will be many buttons.
The reason is that in the "foreach" statement, where I run all the clickChecks, I have to put in if statements for every button, for every GUI. So right now it is something like:
if(aButton.clickCheck == true) {
...whatever it does...
}
if(bButton.clickCheck == true) {
...whatever it does...
}
if(cButton.clickCheck == true) {
.
.
.
}
So my question is this: is there a way to define a function that each individual button will perform when clicked. This way I could, say, set up each GUI in its own source file. In that source file I would create each button (and its function when clicked) individually and put them into the GUI's button list. Then, when running the foreach clickCheck I can just use something like:
foreach(Button aButton in gui.buttonList) {
if(aButton.clickCheck == true) {
[B]aButton.function()[/B];
}
}
Where each individual button has its own function when clicked. In other words the bolded part is what I'm looking for. Is there a way to set this up? I mean other than creating an inherited class for every button...