Sign in to follow this  
Eralp

Again GUI

Recommended Posts

Hey, nowadays I've been searching information about the game-gui's. I learned "at least" how to make a custom button.But my question is.. Which objects or items belong to gui? For example buttons, textboxes, checkboxes obviously belong to gui but for example when I want to make a hp bar or inventory, they are complicated things :S Hp bar is easier but lets take inventory in the account, how would you design it? I mean you can't derive it from the basebutton or baselabel or any other classes that I know for now. I learned the basics and I think I can do a main menu or launcher for my game but I wanted to ask you how to approach to more complicated things.As inventory I meant the basic rpg inventory like diablo. Also I had a look at the Crazy Eddie's GUI System but didn't test it yet and I have never used a gui library before, What do they offer? And how much flexible things you can create with them?(I can't surf through it's website cuz one page takes 10 minutes to open and I have to refresh 50 times, some kind of host problem maybe) edit:I am using SDL + OpenGL if that changes something.

Share this post


Link to post
Share on other sites
You're half-missing an important distinction.

You are seeing it with the 'HP bar', but not with the 'inventory': the HP is a conceptually separate entity from its visualisation (a 'view' you have of the HP), and so you have HP represented in one way (probably just an int somewhere) and the HP bar in another (probably more complex). This means that, for example, you can have a view of the HP that involves displaying a green bar that fills up as HP increases, and I can have a view of the HP that involves increasing the tempo of the background music as the HP decreases.

Equally, an 'inventory' is not the same as a 'view of the inventory'. To get the idea, you might want to take a look at the Model-View-Controller design pattern (it may or may not be overkill, but it makes the semantic difference clear).

So, yes, an HP bar (potentially a specialization of a more general 'bar') and a scrollable inventory index (or whatever) would be part of the GUI, but the HP and inventory themselves would not be. If you're asking how to design an inventory, it would depend on exactly how you were presenting it, as to what it would make sense for it to be a specialization of (IMHO, an 'inventory' is a reasonably abstract concept, so it could probably be reasonably high up in the hierarchy).

I may be missing the point entirely here (you may be looking for more practical advice, in terms of implementation details), and I'm by no means a design guru, but I hope my view will help.

Share this post


Link to post
Share on other sites
Something like an inventory is a component, just like button and label etc, it derrives from say UIComponent, just like they do. However most of it's functionality will be linking up other components. It will have quite alot of children.

Share this post


Link to post
Share on other sites
Thanks for your fast answers but for example if I was programming my own GUI would I create classes called hp bar? and inventory? or is it up to me?

Will something like that be the proper way;
(constructor)
MyHpBar(int x,int y,int maxhp,bool vertical(orhorizontal),int filledcolor,int unfilledcolor,int regenrate....)

and it will have functions like;
MyHpBar::Refresh(int decreasedorincreasedhp)


And when I want to add mycustom bar..
MyHpBar* ex = new MyHpBar(coordinates, parameters..);

and later in the game..
ex->Refresh(damage);

Am I on the right way?If so I'll try to do the same thing with inventory and will ask you again..

Share this post


Link to post
Share on other sites
I'm new at game development but I'd like to offer an idea to see if it would make sense since I'm going to have to deal with a similar situation soon.

Would it make sense to do this:
Have a HPBar class that takes a reference to the character sprite that it is monitoring the HP for. So every game loop you'd call HPBar->Refresh() or something, and it looks at the character sprite's HP, compares it against the character sprites max HP, and then draws the bar based on the current hp / max hp * maxBarWidth.

The thing I'm not seeing with the way mentioned above was he used a regeneration rate which seems weird since the HP regeneration, and max HP is part of the game character rather than the HP bar itself right? Shouldn't all the HP bar be is a view that is completely independent of the specifics of the character?

Share this post


Link to post
Share on other sites
Quote:
Original post by iamspecial
can you please paste your code for making a button here..it would be a great help .....thanks


I didn't do any buttons yet but I have the idea only


Quote:
Original post by Mr_Threepwood
I'm new at game development but I'd like to offer an idea to see if it would make sense since I'm going to have to deal with a similar situation soon.

Would it make sense to do this:
Have a HPBar class that takes a reference to the character sprite that it is monitoring the HP for. So every game loop you'd call HPBar->Refresh() or something, and it looks at the character sprite's HP, compares it against the character sprites max HP, and then draws the bar based on the current hp / max hp * maxBarWidth.

The thing I'm not seeing with the way mentioned above was he used a regeneration rate which seems weird since the HP regeneration, and max HP is part of the game character rather than the HP bar itself right? Shouldn't all the HP bar be is a view that is completely independent of the specifics of the character?


yes I wrote it very fast so I didn't think that much but you ideas seem to be more proper.OOP is confusing lol :)


Inventory(I will need help with this!)
I think I will have a linked list that contains the items in the inventory..
and inventory will be a sdl surface and it will have for example 10*10 grid.
I will loop through the linked list and draw each object seperatly to the grids.
and when a player clicks on the inventory and if the grid that he clicked contains an item than I'll fire a function like Item->Clicked(bool leftbutton);






Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this