menu problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

menu problems

Post by [dx/x]=HUNT3R »

I've got a problem creating the menu for a game. I have 6 options on the main menu: New game, save game, load game, options, credits, and exit. I can't figure out how to have only the 6 buttons on the main menu show up and then, for example, in the options menu have those main menu buttons dissappear and have only 2 scrollbars for volume and 1 button to return to the main menu. I dont know of any way to delete a button after adding it to the menu, I've tried creating separate menus, one for main menu and one for options menu which are in separate functions in the program and separate game states, but for some reason the drawall() function draws both menus at once so my main menu page shows up with overlapping buttons. Anyone got any ideas?
Caecus
Posts: 36
Joined: Fri Aug 22, 2003 6:33 am
Location: California, USA

Post by Caecus »

I believe that almost every object (including gui objects) in irrlicht has a setVisible() method. You should use this to hide the buttons not shown by the current state.
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Caecus wrote:I believe that almost every object (including gui objects) in irrlicht has a setVisible() method. You should use this to hide the buttons not shown by the current state.
Thats a good idea, but if it's not visible does that also mean that it is disabled and cannot be clicked on? Or will I also have to do a setEnabled(true / false)? Maybe I could just use the remove() function and remove main menu buttons then add them again when the user returns to the main menu? I'm not exactly sure how that will work though. These are all members of IGUIElement and I'm working with IGUIEnvironment. Got any ideas how that will work? I'll just have to play with it some I guess...
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

If they are not visible, you cannot click them. A setEnabled(false) is not necessary. The decision if you use setVisible() or remove() and recreate them is left by you. :)
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Does anyone know how I can use that setVisible() property of IGUIElement to make my main menu buttons go away when switching between different sub-menus on my main menu? I've been trying a couple of different things and have not gotten it to work yet. Here's how I'm setting up my menu:

gui::IGUIEnvironment* mainMenu = device->getGUIEnvironment(); //this is declared globally

void Main_Menu(){

driver->draw2DImage(menuBackground, core::position2d<s32>(0,0), core::rect<s32>(0,0, 800,600), 0, video::SColor(255,255,255,255), true);
mainMenu->addButton(core::rect<s32>(50,40, 160,80), 0, 1, L"New Game");
mainMenu->addButton(core::rect<s32>(50,90, 160,130), 0, 2, L"Load Game");
mainMenu->addButton(core::rect<s32>(50,140, 160,180), 0, 3, L"Save Game");
mainMenu->addButton(core::rect<s32>(50,190, 160,230), 0, 4, L"Options");
mainMenu->addButton(core::rect<s32>(50,240, 160,280), 0, 5, L"Credits");
mainMenu->addButton(core::rect<s32>(50,290, 160,330), 0, 6, L"Exit");
mainMenu->drawAll();

return;

} // end Main_Menu

And then when the Options button gets clicked it does this:

if (id == 4){

musicVolumeScrollbar = mainMenu->addScrollBar(true, core::rect<s32>(250, 45, 450, 60), 0, 8);
musicVolumeScrollbar->setMax(100);
mainMenu->addButton(core::rect<s32>(50,40, 160,80), 0, 9, L"Return to Main Menu");
gameState = GAME_STATE_OPTIONS;
return true;

} // end if

As of now, the Return to Main Menu button just appears on top of the New Game button and all other buttons stay there. I need to make them dissappear and have only the scrollbar and return button show up plus whatever else I add in to the options menu. Can anyone explain to me how to do this as well as a simple way to set the transparency of the menu buttons. I tried to get that from the GUI tutorial but my code doesn't work right:

menuSkin = mainMenu->getSkin();

for (s32 i=0; i<gui::EGDC_COUNT ; ++i){
video::SColor col = mainMenu->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
col.setAlpha(1);
mainMenu->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col);
}

By mistake that code makes the buttons fade in when the menu appears which looks cool but I would like to understand how to set the transparency correctly.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

I've done a similar thing for my menu. First i create every gui element the menu's need in one block before the main device loop. At this time i also set the visibility for the first menu items. This way when i select a different sub menu i'm not recreating buttons. In the event handler i then set the visbility options for the selected menu. using

guielementname->setVisible(true or flase)

here's a dump from a older version of my menu

img1 = guienv->addImage(core::rect<int>(50,150,390,950));
img1->setImage(driver->getTexture("..\\media\\menu1280x1024.psd"));//place menu image
img2 = guienv->addImage(core::rect<int>(400,150,1250,950));
img2->setImage(driver->getTexture("..\\media\\window1280x1024.psd"));//pace main window

//add buttons
NewGame = guienv->addADButton(core::rect<int>(x,y,x+227,y+57), 0, 1, L"NEW GAME","..\\media\\button.psd","..\\media\\buttonM.psd");//add new game button
LoadGame = guienv->addADButton(core::rect<int>(x,y+77,x+227,y+134), 0, 2, L"LOAD GAME","..\\media\\button.psd","..\\media\\buttonM.psd");
Options = guienv->addADButton(core::rect<int>(x,y+154,x+227,y+211), 0, 3, L"OPTIONS","..\\media\\button.psd","..\\media\\buttonM.psd");
Encyclopedia = guienv->addADButton(core::rect<int>(x,y+231,x+227,y+288), 0, 4, L"ENCYCOPEDIA","..\\media\\button.psd","..\\media\\buttonM.psd");
Quit = guienv->addADButton(core::rect<int>(x,y+318,x+227,y+375), 0, 5, L"QUIT TO WINDOWS","..\\media\\button.psd","..\\media\\buttonM.psd");
Back = guienv->addADButton(core::rect<int>(x,y+318,x+227,y+375), 0, 6,L"BACK","..\\media\\button.psd","..\\media\\buttonM.psd");
BaseMenu();//set visible and enables to the base menu

while(device->run() && driver)
{
if (device->isWindowActive())
{
guienv->drawAll();
smgr->drawAll();
driver->endScene();
}
}



device->drop();
return start;

}

bool MainMenu::OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)//if gui event
{
s32 id = event.GUIEvent.Caller->getID(); //get id of gui element

switch(id)
{
case 1: //if start button is pressed close menu and set start to true to trigger the engine
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{
device->closeDevice();
start = true;
}
break;
case 2:
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{

}
break;
case 3:
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{
OptionsMenu();
}
break;
case 4:
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{

}
break;
case 5: // if exit is pressed
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{
device->closeDevice();
}
break;

case 6:
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED )
{
BaseMenu();
}
break;


}
}

return false;
}

void MainMenu::BaseMenu()
{
img2->setVisible(false);
Back->setVisible(false);
NewGame->setVisible(true);
LoadGame->setVisible(true);
Options->setVisible(true);
Encyclopedia->setVisible(true);
Quit->setVisible(true);
}

void MainMenu::OptionsMenu()
{
img2->setVisible(true);
Back->setVisible(true);
NewGame->setVisible(false);
LoadGame->setVisible(false);
Options->setVisible(false);
Encyclopedia->setVisible(false);
Quit->setVisible(false);
}




This shows a simple way of swapping between two menus.
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Thats not working for me. What is addADButton? That is not in my documentation anywhere and will not compile when I changed mine from addButton, it says thats not a member. But I declared all my buttons globally like this:

gui::IGUIElement* NewGame;
gui::IGUIElement* LoadGame;
gui::IGUIElement* SaveGame;
gui::IGUIElement* Options;
gui::IGUIElement* Credits;
gui::IGUIElement* Exit;
gui::IGUIElement* Return;

and then moved all the initialization to a separate menu initialization function like this:

NewGame = mainMenu->addButton(core::rect<s32>(50,40, 160,80), 0, 1, L"New Game");
LoadGame = mainMenu->addButton(core::rect<s32>(50,90, 160,130), 0, 2, L"Load Game");
SaveGame = mainMenu->addButton(core::rect<s32>(50,140, 160,180), 0, 3, L"Save Game");
Options = mainMenu->addButton(core::rect<s32>(50,190, 160,230), 0, 4, L"Options");
Credits = mainMenu->addButton(core::rect<s32>(50,240, 160,280), 0, 5, L"Credits");
Exit = mainMenu->addButton(core::rect<s32>(50,290, 160,330), 0, 6, L"Exit");
Return = mainMenu->addButton(core::rect<s32>(50,40, 160,80), 0, 7, L"Return to Main Menu");
Return->setVisible(false);

and then I just tested it with one of the submenus by using for example, LoadGame->setVisible(false), when going into the submenu and the Return button never shows up and the other buttons never go away. Is this how you declared all of your buttons? As an IGUIElement*? Did that code from your last post really work? Maybe thats an older version of Irrlicht with the addADButton function?
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

It works!!! :!: Thanks 4 the help Masdus :D I just had to play around with it 4 a while and it works now. But seriously... where did you get that addADButton from? :?:
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

sorry for that i forgot that i had used addADButton. That's a class i defined to allow for buttons with images. It fuctionality is the same as addButton so you should have no trouble substituing the engines defualt buttons
Guest

Post by Guest »

Hi Masdus,

can you send me you're source file of the engine with the addADButton fuction please, bacause i need it ?

Thanks if you send me the file.

Greetings,
Niko (Horn)
GameProgrammer
Posts: 1
Joined: Tue Dec 16, 2003 1:43 pm
Location: Germany

Post by GameProgrammer »

Hi Masdus,

can you send me you're source file of the engine with the addADButton fuction please, bacause i need it ?

Thanks if you send me the file.

P.S Sorry for the double post....

P.P.S My e-mail adress is niko_horn@yahoo.de
Greetings,
Niko (Horn)
Post Reply