Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Menu System

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

Any suggestions on how to design a menu system? I was trying to think of it in terms of like a tree control. Main Select 1 Function Select 2 Another Select 1 Select ... Select 3 Function Something like that. I thought maybe a linked list would work but Im not sure it would work with menu items that are linked to functions. Hopefully someone understood what I tried to explain. Zorb

Share this post

Link to post
Share on other sites
I''m working on the same stuff but a little further along. You could use arrays of pointers for your menu list but really a linked list is better.

You should create a set of class objects for this.

Here is a very basic one:
class CMenuItem
CMenuItem* m_pPrev;
CMenuItem* m_pNext;
CMenuItem* m_pFirstChild;
CMenuItem* m_pSelectedChild;
CMenuItem* m_pLastChild;

DWORD m_dwNumChildren;
DWORD m_dwActionID;

CMenuItem(DWORD dwActionID, TCHAR pString);

CMenuItem* AddChild(CMenuItem* pChild);
DWORD GetMenuAction();
DWORD HandleInput(INPUT* pInput);
void Draw(D3DDEVICE* pd3d);

Each menu item can be a child or a parent. Your base menu item would be the Main Menu. You would enumerate a bunch of ActionID''s (aka Menu ID''s) like MENU_EXIT, and MENU_DISPLAY_SETTINGS, and MENU_CONTROL_SETUP and so on.

When a menu item is created, you pass in its action ID (what it will do when it is selected with ''Enter'' or what it is like MENU_MAIN. You will also pass in a string for its title like "Main Menu".

You will call Draw on the main menu if it is open. I suggest a m_pCurrentMenu that points to the main menu or a sub menu when the menu is up. Then you can just do an if(m_pCurrentMenu != NULL) m_pCurrentMenu->Draw(pd3dDevice); in your draw loop. Also, in your update loop do an if(m_pCurrentMenu != NULL) m_pCurrentMenu->HandleInput(pInput); where pInput is the pointer to your input object (like an array of currently pressed keys or whatever). Then in your HandleInput() function on each menu item you just have it check for 3 buttons (up, down and enter). If it is the up key then the menu item goes if(m_pSelectedChild->m_pPrev != NULL) m_pSelectedChild = m_pSelectedChild->m_pPrev; And the same for down but with m_pNext. If it is the enter key then you say, if(m_pSelectedChild != NULL) return m_pSelectedChild->dwActionID; Then wherever you have called HandleInput from you handle the return from that with a case statement that does various things based on whatever the enumerated action ID is returned from m_pCurrentMenu->HandleInput(pInput);

Does this make any sense? :o| Hopefully this is enough to get you started and you will be able to dope it out on your own from here. Check out the menu code in the Donuts3D demo in the DX8 SDK if you want to see a basic implementation of this. Mine is a little more extensive than theirs.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!