include EventReceiver hpp EventReceiver EventReceiver gui IGUIEnvironm

  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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "EventReceiver.hpp"
EventReceiver::EventReceiver(gui::IGUIEnvironment* env, scene::ISceneManager* smgr){
this->om = ObjectManager::getInstance();
this->cm = ChunkManager::getInstance();
this->weather = WeatherManager::getInstance();
this->env = env;
this->smgr = smgr;
this->config = ConfigurationManager::getInstance();
this->centrex = config->getInt("GlobalConfig", "wwidth")/2;
this->centrey = config->getInt("GlobalConfig", "wheight")/2;
//this->centrex = 250;
//this->centrey = 250;
mclass = 0;
g=1;
listbox = env->addListBox(core::rect<s32>(10, 100, 630, 428));
listbox->setDrawBackground(true);
window = env->addWindow(core::rect< s32 >(centrex-100,centrey-100,centrex+100, centrey+100 ),false, L"Menu");
window->setVisible(0);
env->addButton(core::rect< s32 >(20,20,250,40), window, 101,L"Quit", L"Exits Program");
currentItem = env->addStaticText (L"No item selected", core::rect< s32 >(0, 0, 200, 100));
currentItem->setVisible(1);
updateLB();
listbox-> setSelected(0);
listbox->setVisible(0);
}
void EventReceiver::updateLB() {
listbox->clear ();
std::map< uint16_t , Model > objects = om->getModelList();
for(std::map< uint16_t , Model >::iterator i = objects.begin(); i!=objects.end(); i++) {
std::string str = std::to_string(i->first) + i->second.modelName;
listbox->addItem(StringToWString(str).c_str());
}
}
void EventReceiver::addObject() {
if(listbox->getItemCount ()>0 && listbox-> getSelected()>=0) {
std::cout<<"Try to set object!"<<std::endl;
Object obj;
obj.classId = listbox-> getSelected();
obj.inScene = 0;
obj.scale = core::vector3df(0, 0, 0);
obj.pos = cm->getTerraPos();
om->addObject(obj);
}
}
void EventReceiver::nextItemSwitch() {
mclass = listbox-> getSelected()+1;
if(mclass > listbox->getItemCount()-1) mclass=listbox->getItemCount () -1;
listbox-> setSelected(mclass);
currentItem->setText(listbox-> getListItem (mclass));
}
void EventReceiver::prevItemSwitch() {
mclass = listbox-> getSelected()-1;
if(mclass<0) mclass=0;
listbox-> setSelected(mclass);
currentItem->setText(listbox-> getListItem (mclass));
}
bool EventReceiver::OnEvent(const SEvent& event) {
if(event.EventType == irr::EET_GUI_EVENT){
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType){
case irr::gui::EGET_BUTTON_CLICKED:
switch(id){
case 101:
window->setVisible(0);
env->removeFocus(window);
smgr->getActiveCamera()->setInputReceiverEnabled(true);
break;
}
break;
}
}
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
switch(event.MouseInput.Event&&!window->isVisible()) {
case EMIE_LMOUSE_PRESSED_DOWN:
//listbox->setVisible(0);
//env->removeFocus(listbox);
addObject();
break;
}
}
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
if( event.MouseInput.Wheel>0) {
prevItemSwitch();
}
if(event.MouseInput.Wheel<0) {
nextItemSwitch();
}
}
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) {
switch (event.KeyInput.Key) {
case irr::KEY_TAB:
if(!listbox->isVisible()) {
listbox->setVisible(1);
smgr->getActiveCamera()->setInputReceiverEnabled(false);
env->setFocus(listbox);
std::cout<<"Show menu"<<std::endl;
}
else {
smgr->getActiveCamera()->setInputReceiverEnabled(true);
listbox->setVisible(0);
env->removeFocus(listbox);
std::cout<<"Hide menu"<<std::endl;
}
break;
case irr::KEY_KEY_Q:
prevItemSwitch();
break;
case KEY_OEM_3:
break;
case irr::KEY_KEY_W:
nextItemSwitch();
break;
case irr::KEY_KEY_L:
om->load();
updateLB();
break;
case irr::KEY_KEY_S:
om->save();
break;
case irr::KEY_KEY_M:
om->loadModelList();
updateLB();
break;
case irr::KEY_KEY_G:
g=!g;
cm->setGravitation( g );
break;
case irr::KEY_KEY_F:
weather->enableFlashlight=!weather->enableFlashlight;
break;
case irr::KEY_KEY_I:
//gui::IGUIContextMenu* Menu = env->addContextMenu(core::rect< s32 >(100,100,300, 200 ),o,1);
if(!window->isVisible()){
window->setVisible(1);
env->setFocus(window);
smgr->getActiveCamera()->setInputReceiverEnabled(false);
}
else
{
window->setVisible(0);
env->removeFocus(window);
smgr->getActiveCamera()->setInputReceiverEnabled(true);
}
break;
}
}
return false;
}