I have a strange problem with my gui buttons.
Despite the button text being black and not grey(I think this means it is enabled) i cannot click them.(and by that I mean the buttons do not go into a pressed state.)
Also: this only occurs after I go off the main menu the first time. Some buttons do work on the 2nd menu and only the exit button on the main.
Gui buttons problems [solved]
Gui buttons problems [solved]
Last edited by Catprog on Mon Sep 17, 2012 11:55 am, edited 1 time in total.
Re: Gui buttons problems
Button Creation:
Switching between menus:
Code: Select all
Menu::Menu(irr::IrrlichtDevice* deviceLink,status* statusLink)
{
device = deviceLink;
statusStore = statusLink;
currentMenu = MainMenu;
fileConfirmation = false;
device->getFileSystem()->addZipFileArchive("menu.mnu",true,false);
IGUIEnvironment* env = device->getGUIEnvironment();
core::dimension2d<u32> ss = device->getVideoDriver()->getScreenSize();
int middleOfScreen = ss.Width / 2;
int left = middleOfScreen-64;
int leftmid = middleOfScreen-32;
int right = middleOfScreen+64;
int rightmid = middleOfScreen+32;
IVideoDriver* driver =device->getVideoDriver();
resTxt = driver->getTexture("menu/resButton.png");
resTxtDisabled = driver->getTexture("menu/resButton-disabled.png");
if (resTxt)driver->makeColorKeyTexture( resTxt, core::position2d<s32>(1,1));
if (resTxtDisabled) driver->makeColorKeyTexture(resTxtDisabled, core::position2d<s32>(1,1));
irr::gui::IGUIButton* but = env->addButton(rect<s32>(left,200,right,200 + 32), 0, GUI_ID_NewGame_BUTTON,
L"", L"Starts a new Game") ;
ITexture* txt = driver->getTexture("menu/newButton.png");
if (txt)
{
but->setImage(txt);
}
else
{
but->setText(L"New Game");
}
buttonMap.set("MainMenu,New",but);
but = env->addButton(rect<s32>(left,240,right,240 + 32), 0, GUI_ID_Resume_BUTTON,
L"", L"Resume your current Game") ;
if (resTxtDisabled)
{
but->setImage(resTxtDisabled);
}
else
{
but->setText(L"Resume Game");
}
buttonMap.set("MainMenu,Res",but);
but = env->addButton(rect<s32>(left,280,right,280 + 32), 0, GUI_ID_SaveGame_BUTTON,
L"", L"Saves the game") ;
sveTxt = driver->getTexture("menu/SveButton.png");
sveTxtDisabled = driver->getTexture("menu/SveButton-disabled.png");
if (sveTxtDisabled)
{
but->setImage(sveTxtDisabled);
}
else
{
but->setText(L"Save Game");
}
buttonMap.set("MainMenu,Save",but);
but = env->addButton(rect<s32>(left,320,right,320 + 32), 0, GUI_ID_LoadGame_BUTTON,
L"", L"Loads the game") ;
txt = driver->getTexture("menu/loadButton.png");
if (txt)
{
but->setImage(txt);
}
else
{
but->setText(L"Load Game");
}
buttonMap.set("MainMenu,Load",but);
but = env->addButton(rect<s32>(left,360,right,360 + 32), 0, GUI_ID_Cal_BUTTON,
L"", L"View the diary of your in game charcter") ;
calTxt = driver->getTexture("menu/calButton.png");
calTxtDisabled = driver->getTexture("menu/calButton-disabled.png");
if (calTxt)
{
but->setImage(calTxtDisabled);
}
else
{
but->setText(L"Calender");
}
buttonMap.set("MainMenu,Cal",but);
but = env->addButton(rect<s32>(left,400,right,400 + 32), 0, GUI_ID_Credits_BUTTON,
L"", L"View who made this game possible") ;
txt = driver->getTexture("menu/crdButton.png");
if ( txt)
{
but->setImage( txt);
}
else
{
but->setText(L"Credits");
}
buttonMap.set("MainMenu,Cre",but);
but = env->addButton(rect<s32>(left,440,right,440 + 32), 0, GUI_ID_Options_BUTTON,
L"", L"Change options") ;
txt = driver->getTexture("menu/OptButton.png");
if (txt)
{
but->setImage(txt);
}
else
{
but->setText(L"options");
}
buttonMap.set("MainMenu,Opt",but);
but = env->addButton(rect<s32>(left,480,right,480 + 32), 0, GUI_ID_Exit_BUTTON,
L"", L"Exit the game") ;
txt = driver->getTexture("menu/ExtButton.png");
if (txt)
{
but->setImage(txt);
}
else
{
but->setText(L"Exit Game");
}
buttonMap.set("MainMenu,Exit",but);
but = env->addButton(rect<s32>(left,480,leftmid,480 + 32), 0, GUI_ID_SaveConfirm_BUTTON,
L"Save", L"Save the game") ;
but->setVisible(false);
buttonMap.set("SaveMenu,Save",but);
but = env->addButton(rect<s32>(left,480,leftmid,480 + 32), 0, GUI_ID_LoadConfirm_BUTTON,
L"Load", L"Load the game") ;
but->setVisible(false);
buttonMap.set("LoadMenu,Load",but);
but = env->addButton(rect<s32>(rightmid,480,right,480 + 32), 0, GUI_ID_SCancel_BUTTON,
L"Cancel", L"Cancel saving") ;
but->setVisible(false);
buttonMap.set("SaveMenu,Cancel",but);
but = env->addButton(rect<s32>(rightmid,480,right,480 + 32), 0, GUI_ID_LCancel_BUTTON,
L"Cancel", L"Cancel Loading") ;
but->setVisible(false);
buttonMap.set("LoadMenu,Cancel",but);
for(int i=1; i<=7; i++)
{
but = env->addButton(rect<s32>(left,160+40*i,rightmid,160+40*i + 32), 0, GUI_ID_S1_BUTTON+i-1,
L"", L"Filename") ;
stringc butName = "SL,";
butName+=i;
buttonMap.set(butName,but);
but->setVisible(false);
but->setEnabled(false);
}
SLScrool=env->addScrollBar(false,rect<s32>(rightmid,200,right,472),0,GUI_ID_SL_Scroll);
SLScrool->setVisible(false);
SLScrool->setEnabled(false);
SLScrool->setLargeStep(7);
saveFileNamebox = env->addEditBox(L"",rect<s32>(left,442,right,472),true,0,0);
saveFileNamebox->setEnabled(false);
saveFileNamebox->setVisible(false);
IGUIFont* fnt = env->getFont("media/fontcourier.bmp");
sveConfirm = env->addStaticText(L"Do you want to\noverwrite the \nexisting game",rect<s32>(left,200,right,472),true,false,0,-1,true);
loadConfirm = env->addStaticText(L"Warning:\n the current game\n will be lost",rect<s32>(left,200,right,472),true,false,0,-1,true);
newSave = env->addStaticText(L"Please type in the\nname for the new file",rect<s32>(left,200,right,432),true,false,0,-1,true);
sveConfirm->setVisible(false);
loadConfirm->setVisible(false);
newSave->setVisible(false);
sveConfirm->setTextAlignment(EGUIA_CENTER,EGUIA_CENTER);
loadConfirm->setTextAlignment(EGUIA_CENTER,EGUIA_CENTER);
newSave->setTextAlignment(EGUIA_CENTER,EGUIA_CENTER);
sveConfirm->setBackgroundColor(SColor(255,128,128,128));
loadConfirm->setBackgroundColor(SColor(255,128,128,128));
newSave->setBackgroundColor(SColor(255,128,128,128));
sveConfirm->setOverrideFont(fnt);
loadConfirm->setOverrideFont(fnt);
newSave->setOverrideFont(fnt);
but = env->addButton(rect<s32>(left,480,leftmid,480 + 32), 0, GUI_ID_OptionsConfirm_BUTTON,
L"Save", L"Save the options") ;
but->setVisible(false);
buttonMap.set("OptionMenu,Confirm",but);
but = env->addButton(rect<s32>(rightmid,480,right,480 + 32), 0, GUI_ID_OptionsCancel_BUTTON,
L"Cancel", L"Cancel the options") ;
but->setVisible(false);
buttonMap.set("OptionMenu,Cancel",but);
quitProgam = false;
changedSettings=false;
hasNotChangedSettings=false;
Code: Select all
void Menu::showMenu(MenuTypes type)
{
printf("menu #%i is active\n",type);
currentMenu = type;
if(currentMenu == OptionMenu)
{
//changedSettings;
changedSettings=false;
hasNotChangedSettings=false;
}
for (irr::core::map<irr::core::stringc , irr::gui::IGUIButton*>::Iterator it = buttonMap.getIterator();
!it.atEnd(); it++)
{
std::vector<irr::core::stringc> arg;
stringc keyName = it->getKey(); // get key
IGUIButton* But = it->getValue(); // get value
keyName.split(arg,",");
But->setVisible(false);
// But->setEnabled(false);
switch(currentMenu)
{
case MainMenu:
if(arg[0].equals_ignore_case("MainMenu"))
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
}
break;
case SaveMenu:
if(arg[0].equals_ignore_case("SaveMenu"))
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
}
else if(arg[0].equals_ignore_case("SL") )
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
But->setToolTipText(L"Save Game");
}
break;
case LoadMenu:
if(arg[0].equals_ignore_case("LoadMenu") )
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
}
else if(arg[0].equals_ignore_case("SL") )
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
But->setToolTipText(L"LoadGame");
}
break;
case OptionMenu:
if(arg[0].equals_ignore_case("OptionMenu") )
{
printf("%s is active\n",keyName.c_str());
But->setVisible(true);
But->setEnabled(true);
}
break;
}
}
if(currentMenu == SaveMenu) buttonMap.find("SaveMenu,Save")->getValue()->setEnabled(fileConfirmation);
if(currentMenu == LoadMenu) buttonMap.find("LoadMenu,Load")->getValue()->setEnabled(fileConfirmation);
saveFileNamebox->setVisible(newFile);
saveFileNamebox->setEnabled(newFile);
sveConfirm->setVisible(fileConfirmation && currentMenu == SaveMenu && !newFile);
loadConfirm->setVisible(fileConfirmation && currentMenu == LoadMenu);
newSave->setVisible(newFile);
if(currentMenu == LoadMenu || currentMenu == SaveMenu )
{
SLScrool->setVisible(true);
SLScrool->setEnabled(true);
fls =fileNames(currentMenu == SaveMenu);
int numOfFiles = fls.size();
numOfFiles -= 7;
if(numOfFiles < 0)
{
SLScrool->setMin(0);
SLScrool->setMax(0);
}
else
{
SLScrool->setMin(0);
SLScrool->setMax(numOfFiles);
}
SetTextOnButton();
}
else
{
SLScrool->setVisible(false);
SLScrool->setEnabled(false);
}
}
Re: Gui buttons problems
Sorry, that's too much code for me to understand what's going on without compiling and trying. And it's not enough code for just compiling and trying...
But the typical reason is that it doesn't get the focus (for example some invisible statictext being in front of it - that happened to me already a few times). So what you can do is check which element has the focus right when you click the mouse-button (IGUIEnvironment::getFocus()).
But the typical reason is that it doesn't get the focus (for example some invisible statictext being in front of it - that happened to me already a few times). So what you can do is check which element has the focus right when you click the mouse-button (IGUIEnvironment::getFocus()).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Gui buttons problems
Yep their is an invisible statictext in front of it. Thanks.CuteAlien wrote:Sorry, that's too much code for me to understand what's going on without compiling and trying. And it's not enough code for just compiling and trying...
But the typical reason is that it doesn't get the focus (for example some invisible statictext being in front of it - that happened to me already a few times). So what you can do is check which element has the focus right when you click the mouse-button (IGUIEnvironment::getFocus()).