Jump to content
  • Advertisement
Sign in to follow this  
SolarChronus

Question on my interface setup for my UI classes.

This topic is 2142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm onto rolling my own classes for UI use for fun and learning. I've create a bunch of interfaces to manage the UI widgets but I'm at a fork in the road on the more complex widgets I want to create.

 

Right now my UI code consists of the following:

// Interfaces
IGUIWidget {}
IReactsToClick {}
IReactsToHover {}
IProgressBar : IUIWidget {}
IImage : IUIWidget {}
IButton : IUIWidget, IReactsToClick, IReactsToHover {}
ILabel : IUIWidget {}

// Concrete
Label : ILabel {}
Image : IImage {}
ProgressBar : IProgressBar {}
Button : IButton {}
ImageButton : IImage, IButton {}
LabelButton : ILabel, IButton {}

Now for the 'complex' widget.

 

I have an object that has the following properties:

- Acts like a button

- Has a background image

- Has a content specific image

- Has multiple smaller images that change (can be any number).

- Has a label

- Has a progress bar 

 

Here is the interface and concrete class I've come up with: 

public interface IComplexWidget : IGUIWidget
{
    IButton button { get; }
    IImage background { get; }
    IImage contextImage { get; }
    IList<IImage> multiImages { get; }
    ILabel label { get; }
    IProgressBar progressBar { get; }
}

public class ComplexWidget : IComplexWidget
{
    public ComplexWidget()
    { }
   
    public Button button { get; protected set; }
    public Image background { get; protected set; }
    public Image contextImage { get; protected set; }
    public IList<Image> multiImages { get; protected set; }
    public Label label { get; protected set; }
    public ProgressBar progressBar { get; protected set; }
}

Would this be the correct path for creating more complex widgets? 

Share this post


Link to post
Share on other sites
Advertisement

Looking from a very abstract point of view here you could say that a screen is nothing more then a container of items, where each item on the screen is a container of behaviours. Now this property of UI corresponds with a component-entity approach, where each item on the screen is an entity and the role it needs to achieve is done through the components attached to it.

 

From your description that approach is easiest with a component-entity structure because if you have another widget that doesn't need the button you can just leave that behaviour out. UI's in general are highly changeable and as such really don't fit inheritance hierarchies that well. You will also want to data drive most of this so that you can construct your screens and items outside of the code, for faster iteration.

Share this post


Link to post
Share on other sites

Yeah, for example it seems like your ComplexWidget could be boiled down to just having a IList<IUIWidget>(), or possibly broken into a list of all UIWidgets, a list of all IReactsToClick, IReactToHover.  

 

When the mouse moves over the complex widget, you iterate over every IReactToHover and see if the mouse is over it and then call it's react function or whatever it needs to do.  The Screen/complex widget doesn't need to know whether it's hovering over a button or a progress bar or whatever this way.

Edited by ferrous

Share this post


Link to post
Share on other sites

And keep in mind to separate the UI-View-Logic like Clicked-State-Rendering from the game-logic like fireing an event into your game-application. You can declare a bundle of trigegrs to start an action like starting a new game from the view-state-handling in your ui-code and this make it much more mantable if you want to rework your ui-elements. 

 

Kim

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!