Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case gui::EGET_BUTTON_CLICKED:
if (id == 3) // load game
{
gui::IGUIWindow* window = env->addWindow(
core::rect<s32>(screen.Width/2 - 100, screen.Height - 150,
screen.Width/2 + 100 , screen.Height - 10 ),
false, // modal?
L"How many teams?");
file = env->addFileOpenDialog(L"Please choose a file.");
input = env->addEditBox(L"", core::rect<s32>(50, 60, 150, 80), true, window);
env->addButton(core::rect<s32>(
80,
90,
120,
120 ),
window,
30,
L"Play",
L"");
return true;
}
else if (id == 30) // load a board
{
core::stringw text = input->getText();
ifstream book;
core::stringc charFile = file->getFileName();
book.open( core::stringc(file->getFileName()).c_str() );
more code here....
return true;
}
break;
default:
break;
}
}
return false;
}
private:
gui::IGUIEditBox* input;
gui::IGUIEditBox* input2;
gui::IGUIFileOpenDialog* file;
};
core::stringc charFile = file->getFileName();
I imagine 'file' is getting corrupted, but I don't know how.
A side question: if I try to make 'file' a child of 'window' the gui freezes and I can't see the open file dialogue. What's up with that?