www.pudn.com > ICE_1.4.zip > gs_intro.cpp
// Class automatically generated by Dev-C++ New Class wizard
#include "gs_intro.h" // class's header file
#define BTN_ROW_SPACING 40
#define BTN_W 90
#define BTN_H 30
//buttons are static so initialize them like this
irr::gui::IGUIButton* gs_Intro::m_btn_quit = NULL;
irr::gui::IGUIButton* gs_Intro::m_btn_new = NULL;
irr::gui::IGUIButton* gs_Intro::m_btn_opts = NULL;
irr::gui::IGUIStaticText* gs_Intro::m_txt_title = NULL;
// class constructor
//gsr_Intro::gs_Intro(IrrlichtDevice* dv, video::IVideoDriver *dr) : game_State(dv, dr)
gs_Intro::gs_Intro(game_StateHandler*handler) : game_State(handler)
{
using namespace irr;
//TODO: get resolution from device, and set pos according to that
int btn_x = 200 ;
int btn_y = 200 ;
//buttons are static so only init them if they werent already created
if(!m_btn_quit) {
m_btn_quit = m_env->addButton(core::rect(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H), 0,
GSI_GUI_BTN_QUIT, L"Quit");
btn_y -= BTN_ROW_SPACING; // move up
m_btn_opts = m_env->addButton(core::rect(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H), 0,
GSI_GUI_BTN_OPTS, L"Options");
btn_y -= BTN_ROW_SPACING; // move up
m_btn_new = m_env->addButton(core::rect(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H), 0,
GSI_GUI_BTN_NEW, L"New Game");
btn_y -= BTN_ROW_SPACING; // move up
m_txt_title = m_env->addStaticText ( INTRO_TEXT, true,
core::rect(btn_x, btn_y, btn_x + BTN_W, btn_y + BTN_H) ) ;
}else{
//otherwise, make them visible again
m_btn_quit->setVisible(true);
m_btn_opts->setVisible(true);
m_btn_new->setVisible(true);
m_txt_title->setVisible(true);
}//end if-else: if not initialized already OR make visible
}
// class destructor
gs_Intro::~gs_Intro()
{
//we dont delet our buttons, we just make them invisible
if(m_btn_quit) {
m_btn_quit->setVisible(false);
m_btn_opts->setVisible(false);
m_btn_new->setVisible(false);
m_txt_title->setVisible(false);
}//set invisible
}
void gs_Intro::Render() {
using namespace irr;
m_driver->beginScene(true, true, video::SColor(0,122,65,171));
//TODO: replace this with a title splash screen
DrawRect(video::SColor(100,200,255,255), core::rect(50, 50, 100, 100));
m_env->drawAll();
m_driver->endScene();
}
bool gs_Intro::onEvent(irr::SEvent event) {
using namespace irr;
using namespace gui;
if (event.EventType == EET_GUI_EVENT) {
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType) {
case EGET_BUTTON_CLICKED:
if(id == GSI_GUI_BTN_QUIT) {
m_handler->RequestDestroy();
return true;
}
if(id == GSI_GUI_BTN_NEW) {
m_handler->RequestStateChange(GS_MAIN);
return true;
}
if(id == GSI_GUI_BTN_OPTS) {
m_handler->RequestStateChange(GS_OPTS);
return true;
}
//return true; //if supported button id
break;
}//end switch: type of GUI event
}//end if: GUI event
return false;
}
void gs_Intro::Update() {
}