A. Display a Menu screen
B. Act accordingly to the button you press.
I've gotten the menu screen to show up, but nothing happens when I click the button, and the background image is extremely poor quality. (I've tried adjusting the size, changing the file format, etc).
Code: Select all
IrrlichtDevice *device = 0;
s32 cnt = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
/*
If a button was clicked, it could be one of 'our'
three buttons. If it is the first, we shut down the engine.
If it is the second, we create a little window with some
text on it. We also add a string to the list box to log
what happened. And if it is the third button, we create
a file open dialog, and add also this as string to the list box.
That's all for the event receiver.
*/
case EGET_BUTTON_CLICKED:
if (id == 103)
{
device->closeDevice();
return true;
}
if (id == 102)
{
cnt += 30;
if (cnt > 200)
cnt = 0;
gui::IGUIWindow* window = env->addWindow(
rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
false, // modal?
L"Create-A-Thug");
env->addStaticText(L"Coming Soon",
rect<s32>(35,35,140,50),
true, // border?
false, // wordwrap?
window);
return true;
}
if (id == 101)
{
Render();
return true;
}
break;
}
}
return false;
}
};
void Menu()
{
MyEventReceiver receiver;
IrrlichtDevice *device = createDevice(video::EDT_DIRECTX8,
core::dimension2d<s32>(640, 480),false,false,&receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
gui::ICursorControl* cursor = device->getCursorControl();
IGUIImage* img = env->addImage(rect<int>(0,0,640,480));
img->setImage(driver->getTexture("../../../media/Background.jpg"));
// video::ITexture* images = driver->getTexture("../../../media/Background.jpg");
// video::IImageLoader* image = driver->getTexture("../../../media/Background.jpg");
env->addButton(rect<s32>(260,140,360,180), 0, 101, L"Play");
env->addButton(rect<s32>(260,190,360,230), 0, 102, L"Build a Thug");
env->addButton(rect<s32>(260,240,360,280), 0, 103, L"Quit");
while(device->run())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(0,0,0,0));
env->drawAll();
//driver->draw2DImage(images, core::position2d<s32>(0,0),
//core::rect<s32>(0,0,640,480), 0,
//video::SColor(0,255,255,255), true);
driver->endScene();
}
}