Jump to content
  • Advertisement
Sign in to follow this  
Sean_Seanston

Updating Values in Text Menu Interface?

This topic is 2590 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

In my game I'm making a simple menu interface for the player to purchase items, which consists of lists of text options with a movable selection pointer and various other non-selectable bits of text information.

I've got it more or less working, but something that's giving me trouble now is how I should approach text values that aren't constant. The specific example I'm facing now is display the player's current available cash at the top-right of the weapon purchasing screen.

The screen should consist of some non-selectable static text (e.g. the menu page title, column headings etc.), selectable text options (weapon names) and also non-selectable text that changes based on some external value (the player's cash value in this case).

The way I've been doing it so far is to have a Menu class with a list of text and a list of MenuItems, where a MenuItem consists mostly of some text and a boost::function representing the function performed when that item is selected.
Then I have a game state where the menus are populated with information when the state is initialized, and the state handles user input and draws the currently active menu.

However, clearly the player's cash amount is going to vary between activations of the state and also while the state is active if the player purchases something. So clearly, just handling the player cash display the same as other static text isn't going to work.

How then should I deal with text that needs to be updated constantly, while keeping all information about it contained within its appropriate Menu object?
I've thought about creating a 3rd list, this time for dynamic text that needs to be updated. The thing with that then is that each text item will get its information updated from a different source. So given that I'm using boost::function, my current thought is to just pair this text up with a boost::function that returns whatever string value the text needs to show.

Is that a good approach, or am I complicating things needlessly? Maybe there's a more elegant way I haven't seen, or maybe the whole structure of my menu system is very lacking... I dunno, this is the first thing like this I've ever done and it was a bit of a struggle to bring it all together. Is the use of functors one of the better ways of solving a problem like this?

Share this post


Link to post
Share on other sites
Advertisement
Well I implemented what I described and it seems to be working as required.

Would still be interested in any observations people might wanna make though. I suppose there are a lot of things you can do in C++ (which I should've mentioned I was using... sorry, I keep forgetting to mention the language) that may work in a lot of cases or almost all cases that you really shouldn't do despite it apparently working fine.

Share this post


Link to post
Share on other sites
Basically, I'm displaying text for my menu system. To do that, I have a Menu class that I fill with text, then display.

But I need some way of adding text to the Menu that's going to change based on some external factor (keeping track of the player's cash in this case), and let the Menu deal with that itself without having to manually manipulate it from the outside every time it changes.

So to that end, I've thought of:
- Adding the text as usual, except inside an std::pair<> with a functor that returns a string.
- Now, every logic frame of the program, the Menu's update() function is called.
- The update function goes through every item of "dynamic" text and sets its text string to the string returned by whatever its assigned functor is (e.g. Player->getCashString()).
- Now the value gets updated every logic frame according to whatever its functor is returning at that time.

This seems to keep everything neatly encapsulated inside the Menu object after the text is added to the Menu and the outside world doesn't need to know about what text has to change or how to do it.

One reason something like this seemed necessary is that, after adding an item to text to the list, I couldn't refer to it from outside (because it was just a text object like any other in a list) to change it after it was added to the Menu object. I thought about giving them some kind of string identifier, but then that seemed messy because I wanted the Menu to be self-contained and control its own text "automatically". Otherwise, I was clearing and re-filling the Menu every time a value changed.

Clearer now? :D
Maybe I'm not thinking straight...

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!