Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to offer attribute overwrites dependent on the state of my custom button class in C#
    text
    copied!<p>I am working on a custom button class for my XNA game. Consequently I am developing the game in C#. </p> <p>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.</p> <p>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". </p> <p>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&lt;->property combination.</p> <p>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.</p> <p>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. </p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload