I am working on a custom button class for my XNA game. Consequently I am developing the game in C#.
My button class is very basic, it provides the obligatory events like MouseOver, MouseOut, MouseDown etc… Furthermore it has some public properties which influence the overall appearance like Text, TextAlign, BackgroundColor, TextColor and Font.
Every button can be in 4 different states: Normal, Hovered, Pressed and Inactive. I would like to give the developers of my game the possibility to specify certain “overwrites” which will control the appearance of the button on a “per state basis”.
Unfortunately I can not come up with a fancy solution. Currently I simply create an array which can hold a separate Button instance for every state. Now if the user wants to create an overwrite for lets say the Hovered-state he simply has to create a new Button instance at the corresponding index position of the button array (I used an Enumeration for that mapping which will be cast to a byte value to retrieve the proper index position). Now a user is able to define an overwrite for every possible state<->property combination.
In the draw method I finally check what the currently active state of my button is and draw the proper button instance from my array collection.
This is not a very clean solution though, as it creates a lot of overhead in case I only want to overwrite the TextColor for a single state. I was wondering how this is generally solved in more professional solutions.
Does anyone have a few tips on design patterns which might be useful in that domain? I had problems searching for a solution as I was missing meaningful keywords.
you can try to implement your own settings class
EDIT
and use it at your button class
now the user can use your custombutton and change the settings
hope this helps