Here is the rest of the relevant code.
Its being called from within gsr_Intro, from a pointer to a game_State. I intend to have each game state as a class which inherits from game_State. I doubt this is causing the problem, but I thought I should mention it:
Code: Select all
enum tGUIobjs {
GUI_BTN_QUIT = 101, //quit application
GUI_BTN_NEW, //new game
GUI_BTN_OPTS, //go to options menu
GUI_OBJS_NUM // unused
};
class game_State
{
protected:
IrrlichtDevice *m_device; //irrlicht device pointer
video::IVideoDriver *m_driver; //irrlicht video driver pointer
gui::IGUIEnvironment *m_env; //irrlicht GUI environment ptr
public:
game_State(game_tetris* game); //gets G_T's dv and dr and env
virtual void Render() = 0;
virtual bool onEvent(SEvent event) = 0;
// .... stuff cut
};
class gsr_Intro : public game_State {
bool key;
public:
gsr_Intro(game_tetris *game);
virtual void Render();
virtual bool onEvent(SEvent event);
virtual void Update();
};
//init code:
gsr_Intro :: gsr_Intro (game_tetris) : game_State(game_tetris) {
int btn_x = 200 ;
int btn_y = 200 ;
#define BTN_ROW_SPACING 40
#define BTN_W 90
#define BTN_H 30
key = false;
m_env->addButton( core::rect<s32>(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H), 0, GUI_BTN_QUIT, L"Quit");
btn_y -= BTN_ROW_SPACING; // move up
m_env->addButton(core::rect<s32>(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H), 0, GUI_BTN_NEW, L"New Game");
}
//render code:
void gsr_Intro :: Render() {
m_driver->beginScene(false, false, video::SColor(0,122,65,171));
if(key) DrawRect(video::SColor(100,200,255,255), core::rect<s32>(50, 50, 100, 100));
m_env->drawAll();
m_driver->endScene();
}
Its important to note that the demo #5 _DOES_ work for me! So it must be something I'm doing wrong.. though I dont know what/how/why.
Also, the 'key' variable from above does NOT seem to be affected by button pressed..
EDIT: I just added a 3rd button 'options'. So now they are ordered from top to bottom by: "New Game","Options","Quit".
When I push "New Game", the "Options" button's text dissappears.
When I push "Quit", the "Options" button's text changes to: "lptions"
When I push 'Options', the button depresses and the text stays the same- meaning if its text was already messed up, or missing, it stays that way.
I havent yet added any event handling for the Options button- which is why its not doing anything. I wonder what freaky thing will happen when I do..
EDIT: I've added event handling for the Options button. Now its almost working! I dont know WHY, but its no longer messing up text!!
event handling--
NewGame should make the square dissapear (key=false)
Options should make the square appear (key=true)
Quit should quit the game (game->RequestDestroy() )
what actually happens--
NewGame does nothing (boo)
Options makes the square appear (key is set to true, yay!)
Quit properly exits the game (yay!)
the code:
Code: Select all
case EGET_BUTTON_CLICKED:
if(id == GUI_BTN_QUIT) {
p_game->RequestDestroy();
return true;
}
if(id == GUI_BTN_NEW) {
key = false;
return true;
}
if(id == GUI_BTN_OPTS) {
key = true;
return true;
}
//return true; //if supported button id
break;
}//end switch: type of GUI event