Hi!
This is my initial Menu class.
#include <irrlicht.h>
#include "../include/InitMenu.h"
#include "../include/OptionsMenu.h"
#include <stdio.h>
#include <stdlib.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace io;
using namespace scene;
class COptionsMenu;
InitEventReceiver::InitEventReceiver(SInitMenuContext &context):initMenuContext(context)
{
}
bool InitEventReceiver::OnEvent(const irr::SEvent& event)
{
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
{
s32 idBtn = event.GUIEvent.Caller->getID();
switch(idBtn)
{
case PLAY_BUTTON:
return true;
break;
case OPTIONS_BUTTON:
{
COptionsMenu *optMNU = new COptionsMenu();
optMNU->runGame();
initMenuContext.device->closeDevice();
return true;
break;
}
case CREDITS_BUTTON:
return true;
break;
case EXIT_BUTTON:
initMenuContext.device->closeDevice();
break;
return true;
default:
return false;
}
return true;
}
return false;
}
CInitMenu::CInitMenu()
{
IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<u32>(640,480),16,false,false,false,0);
dev = device;
int width = 180;
int height = 50;
int x = (device->getVideoDriver()->getScreenSize().Width - 200)/2;
int y = 100;
SColor WHITE = video::SColor(255,255,255,255);
SColor BLUE = video::SColor(255,0,0,255);
gui::IGUISkin* skin = device->getGUIEnvironment()->createSkin(EGUI_SKIN_TYPE::EGST_WINDOWS_METALLIC);
skin->setColor(gui::EGDC_BUTTON_TEXT,WHITE);
skin->setColor(gui::EGDC_WINDOW,BLUE);
device->getGUIEnvironment()->setSkin(skin);
device->getSceneManager()->loadScene("Data/experimentalMenuSystem/Shop.irr");
device->getSceneManager()->addCameraSceneNode(0,core::vector3df(0,100,0),core::vector3df(0,0,100),-1,true);
m_pPlayButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,PLAY_BUTTON,L"Play");
y = y+height;
m_pOptionsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,OPTIONS_BUTTON,L"Options");
y = y+height;
m_pCreditsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,CREDITS_BUTTON,L"Credits");
y = y+height;
m_pExitButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,EXIT_BUTTON,L"Exit");
initMnuContext.device = device;
initMnuContext.m_pPlayButton = m_pPlayButton;
initMnuContext.m_pOptionsButton = m_pOptionsButton;
initMnuContext.m_pCreditsButton = m_pCreditsButton;
initMnuContext.m_pExitButton = m_pExitButton;
}
int main(int argc, char **argv)
{
CInitMenu* cIMNU = new CInitMenu();
cIMNU->runGame();
}
void CInitMenu::runGame()
{
InitEventReceiver initReceiver(initMnuContext);
dev->setEventReceiver(&initReceiver);
while(dev->run())
{
if (dev->isWindowActive())
{
dev->getVideoDriver()->beginScene(true, true, video::SColor(0,200,200,200));
dev->getSceneManager()->drawAll();
dev->getGUIEnvironment()->drawAll();
dev->getVideoDriver()->endScene();
}
}
dev->drop();
}
This is Options Menu class:
#include <irrlicht.h>
#include "../include/OptionsMenu.h"
#include "../include/InitMenu.h"
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace io;
using namespace scene;
OptionsEventReceiver::OptionsEventReceiver(SOptionsContext &optionsContext):OptionsContext(optionsContext)
{
}
bool OptionsEventReceiver::OnEvent(const irr::SEvent& event)
{
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
{
s32 idBtn = event.GUIEvent.Caller->getID();
printf("Button Clicked: %d \n",idBtn);
switch(idBtn)
{
case PROFILE_BUTTON:
return true;
break;
case FAVOURITES_BUTTON:
return true;
break;
case MATCH_RESULT_BUTTON:
return true;
break;
case OPTIONS_BACK_BUTTON:
{
CInitMenu *cInitMNU = new CInitMenu();
cInitMNU->runGame();
OptionsContext.device->closeDevice();
return true;
break;
}
default:
return false;
}
return false;
}
}
COptionsMenu::COptionsMenu()
{
IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<u32>(640,480),16,false,false,false,0);
dev = device;
int width = 180;
int height = 50;
int x = (device->getVideoDriver()->getScreenSize().Width - 200)/2;
int y = 100;
SColor WHITE = video::SColor(255,255,255,255);
SColor BLUE = video::SColor(255,0,0,255);
gui::IGUISkin* skin = device->getGUIEnvironment()->createSkin(EGUI_SKIN_TYPE::EGST_WINDOWS_METALLIC);
skin->setColor(gui::EGDC_BUTTON_TEXT,WHITE);
skin->setColor(gui::EGDC_WINDOW,BLUE);
device->getGUIEnvironment()->setSkin(skin);
device->getSceneManager()->loadScene("Data/experimentalMenuSystem/Shop.irr");
device->getSceneManager()->addCameraSceneNode(0,core::vector3df(0,100,0),core::vector3df(0,0,100),-1,true);
m_pPlayerProfileButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,PROFILE_BUTTON,L"Player Profile");
y = y+height;
m_pFavouritesButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,FAVOURITES_BUTTON,L"Favorites");
y = y+height;
m_pMatchResultButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,MATCH_RESULT_BUTTON,L"Match Result");
m_pOptionsBackButton = device->getGUIEnvironment()->addButton(recti(0,400,192,458),0,OPTIONS_BACK_BUTTON,L"Back");
optionsContext.device = device;
optionsContext.m_pPlayerProfileButton = m_pPlayerProfileButton;
optionsContext.m_pFavouritesButton = m_pFavouritesButton;
optionsContext.m_pMatchResultButton = m_pMatchResultButton;
optionsContext.m_pOptionsBackButton = m_pOptionsBackButton;
}
void COptionsMenu::runGame()
{
OptionsEventReceiver optReceiver(optionsContext);
dev->setEventReceiver(&optReceiver);
while(dev->run())
{
if (dev->isWindowActive())
{
dev->getVideoDriver()->beginScene(true, true, video::SColor(0,200,200,200));
dev->getSceneManager()->drawAll();
dev->getGUIEnvironment()->drawAll();
dev->getVideoDriver()->endScene();
}
}
dev->drop();
}
|