#include "main.h"
MainMenu::MainMenu() {
settings = new CSettings();
//Mapowanie klawiszy:
settings->AddKeyMap(EKA_MOVE_FORWARD, KEY_UP);
settings->AddKeyMap(EKA_MOVE_FORWARD, KEY_KEY_W);
settings->AddKeyMap(EKA_MOVE_BACKWARD, KEY_DOWN);
settings->AddKeyMap(EKA_MOVE_BACKWARD, KEY_KEY_S);
settings->AddKeyMap(EKA_STRAFE_LEFT, KEY_LEFT);
settings->AddKeyMap(EKA_STRAFE_LEFT, KEY_KEY_A);
settings->AddKeyMap(EKA_STRAFE_RIGHT, KEY_RIGHT);
settings->AddKeyMap(EKA_STRAFE_RIGHT, KEY_KEY_D);
settings->AddKeyMap(EKA_JUMP_UP, KEY_SPACE);
settings->AddKeyMap(EKA_CROUCH, KEY_KEY_C);
//Ustawianie w menu juz wkrotce!
start = false;
}
MainMenu::~MainMenu() {
}
int MainMenu::show() {
device = createDevice(EDT_SOFTWARE, dimension2d<u32>(640, 480), 16, false, false, false, 0);
if (device == 0) return 1;
device->setWindowCaption(L"Colonization - Settings");
video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON, L"Quit", L"Quit the Game");
env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_START_BUTTON, L"Start", L"Starts the Game");
env->addStaticText(L"Choose the driver:", rect<s32>(50,110,250,130), true);
listbox = env->addListBox(rect<s32>(50, 140, 250, 210));
const wchar_t* const names[] = {L"NullDriver",L"Software Renderer",L"Burning's Video",L"Direct3D 8.1",L"Direct3D 9.0c",L"OpenGL 1.x/2.x/3.x"};
irr::u32 i=0;
for (i=irr::video::EDT_COUNT; i>0; --i)
{
if ((irr::IrrlichtDevice::isDriverSupported(irr::video::E_DRIVER_TYPE(i-1))))
driver_items[i-1] = listbox->addItem(names[i-1]);
}
// And tell the device to use our custom event receiver.
device->setEventReceiver(this);
while(device->run() && driver)
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
env->drawAll();
driver->endScene();
}
device->drop();
}
bool MainMenu::OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
switch(id)
{
case GUI_ID_QUIT_BUTTON:
device->closeDevice();
return true;
case GUI_ID_START_BUTTON:
start = true;
device->closeDevice();
return true;
default:
return false;
}
break;
case EGET_LISTBOX_CHANGED:
if(event.GUIEvent.Caller == listbox) {
u32 sel = ((IGUIListBox*)(event.GUIEvent.Caller))->getSelected();
E_DRIVER_TYPE driv=EDT_COUNT;
for (u32 i = 1; i<EDT_COUNT; i++)
{
if(driver_items[i] == sel) driv = (E_DRIVER_TYPE)i;
}
settings->DriverType = driv;
return true;
} else return false;
break;
default:
break;
}
}
return false;
}