[go: up one dir, main page]

Menu

[r7]: / MainMenu.cpp  Maximize  Restore  History

Download this file

110 lines (87 with data), 3.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#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;
}