Editable pathfile in Open Dialog Box

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
tBane
Posts: 33
Joined: Wed Feb 21, 2024 2:25 pm
Location: Poland

Editable pathfile in Open Dialog Box

Post by tBane »

Hi!
I cant edit pathfile in Dialog Box in my program. What could be the cause of this?

Code: Select all

IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editable pathfile in Open Dialog Box

Post by CuteAlien »

You already mentioned this in your other thread. And after my answer you just wrote "Correctly" and posted some code which didn't seem related to the problem. So I thought it works now.

My guess is still that you catch the key-input in your event-handler (by returning true), so it's no longer passed on the gui system. But I can't tell you more without seeing your event-handler.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
tBane
Posts: 33
Joined: Wed Feb 21, 2024 2:25 pm
Location: Poland

Re: Editable pathfile in Open Dialog Box

Post by tBane »

This is my eventReceiver. I don't know if I wrote it correctly

Code: Select all

bool MyEventReceiver::OnEvent(const SEvent& event)
{

	if (event.EventType == EET_GUI_EVENT)
	{
		switch (event.GUIEvent.EventType)
		{
		case EGET_FILE_CHOOSE_DIALOG_CANCELLED:
			openDialog = nullptr;
			openDialogState = openDialogStates::none;
			break;

		case EGET_FILE_SELECTED:			// open dialog box
		{

			if (openDialogState == openDialogStates::load)
			{

				IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
				
				io::path extension;
				core::getFileNameExtension(extension, dialog->getFileName());
				extension.make_lower();

				if (extension == ".hexmap")
				{
					hexMap->destroy();
					hexMap->loadFromFile(stringc(dialog->getFileName()).c_str());
				}
			}

			if (openDialogState == openDialogStates::save)
			{
				IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;

				std::string filename = stringc(dialog->getFileName()).c_str();
				io::path extension;
				core::getFileNameExtension(extension, dialog->getFileName());
				extension.make_lower();

				if (extension != ".hexmap")
					filename = filename + ".hexmap";

				hexMap->saveAsFile(filename);
			}

			openDialogState = openDialogStates::none;
			openDialog = nullptr;

		}
		break;

		case EGET_MENU_ITEM_SELECTED:		// main menu events
		{
			IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
			s32 id = menu->getItemCommandId(menu->getSelectedItem());
			switch (id)
			{
			case GUI_CREATEWORLD:
				if (hexMap != nullptr)
					hexMap->destroy();
				hexMap->createEmpty(40, 40);
				std::cout << "created new Empty world" << std::endl;
				break;

			case GUI_LOADWORLD:
				openDialog = GUI->addFileOpenDialog(L"Please select a map file to open");
				openDialogState = openDialogStates::load;
				break;

			case GUI_SAVEWORLD:
				openDialog = GUI->addFileOpenDialog(L"Please select a map file to save");
				openDialogState = openDialogStates::save;
				break;

			case GUI_GENERATEWORLD:
				generateWorld();
				break;

			case GUI_TUTORIAL:
				tutorial();
				break;

			case GUI_INFO:
				info();
				break;

			}	// switch(id)

		}
		break;

		case EGET_BUTTON_CLICKED:			// buttons: terrain etc .. 
		{
			s32 buttonID = event.GUIEvent.Caller->getID();

			switch (buttonID)
			{

			case BUTTON_DARKNESS:
				brushTerrain = terrainType::darkness;
				std::cout << "setted a darkness to paint" << std::endl;
				break;

			case BUTTON_BEACH:
				brushTerrain = terrainType::beach;
				std::cout << "setted a beach to paint" << std::endl;
				break;

			case BUTTON_LOWLANDS:
				brushTerrain = terrainType::lowlands;
				std::cout << "setted a grass to paint" << std::endl;
				break;

			case BUTTON_STEPS:
				brushTerrain = terrainType::steps;
				std::cout << "setted a steps to paint" << std::endl;
				break;

			case BUTTON_HIGHLANDS:
				brushTerrain = terrainType::highlands;
				std::cout << "setted a highlands to paint" << std::endl;
				break;

			case BUTTON_ROCKS:
				brushTerrain = terrainType::rocks;
				std::cout << "setted a rocks to paint" << std::endl;
				break;

			case BUTTON_SWAMP:
				brushTerrain = terrainType::swamp;
				std::cout << "setted a swamp to paint" << std::endl;
				break;

			case BUTTON_DESERT:
				brushTerrain = terrainType::desert;
				std::cout << "setted a desert to paint" << std::endl;
				break;

			case BUTTON_PERMAFROST:
				brushTerrain = terrainType::permafrost;
				std::cout << "setted a permafrost to paint" << std::endl;
				break;

			case BUTTON_INCREASE:
				if (brushSize < maxBrushSize)
					brushSize++;
				break;

			case BUTTON_DECREASE:
				if (brushSize > 0)
					brushSize--;
				break;

			case BUTTON_RISE:
				if (brushHeight < maxBrushHeight)
					brushHeight++;
				break;

			case BUTTON_FALL:
				if (brushHeight > 0)
					brushHeight--;
				break;
			} // buttonID

		}
			break;

		default:
			break;

		}
	}

	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
	{
		switch (event.MouseInput.Event)
		{
		case EMIE_LMOUSE_PRESSED_DOWN:
			mousePress = true;
			break;

		case EMIE_LMOUSE_LEFT_UP:
			mousePress = false;
			break;

		}
	}

	// Remember whether each key is down or up
	if (event.EventType == irr::EET_KEY_INPUT_EVENT)
	{
		KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
		return true;
	}

	return false;
}

bool MyEventReceiver::IsKeyDown(EKEY_CODE keyCode)
{
	return KeyIsDown[keyCode];
}
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editable pathfile in Open Dialog Box

Post by CuteAlien »

The problem is you return always true for event.EventType == irr::EET_KEY_INPUT_EVENT.
"true" means: this event is handled and Irrlicht shouldn't use it any further. So you prevent any key input to reach the gui.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
tBane
Posts: 33
Joined: Wed Feb 21, 2024 2:25 pm
Location: Poland

Re: Editable pathfile in Open Dialog Box

Post by tBane »

ok. now I use this code. Now I have this problem. I would like to save a new file using DialogBox. Now not save as a new file "../testmap.hexmap".

Code: Select all

if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{
	KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
}

Code: Select all

// UPDATE

if (openDialog == nullptr)
{
	if (receiver.IsKeyDown(irr::KEY_KEY_A))
		cam_x -= cameraMovementSpeed;
	if (receiver.IsKeyDown(irr::KEY_KEY_D))
		cam_x += cameraMovementSpeed;
	if (receiver.IsKeyDown(irr::KEY_KEY_W))
		cam_z += cameraMovementSpeed;
	if (receiver.IsKeyDown(irr::KEY_KEY_S))
		cam_z -= cameraMovementSpeed;
}
[code]
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editable pathfile in Open Dialog Box

Post by CuteAlien »

Yeah, that's a problem. Irrlicht has no file-save dialog so far. I've searched around the forum a bit and it seems someone had written one in the past: viewtopic.php?p=151961
But can't tell you much about it, I haven't really checked it out.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
tBane
Posts: 33
Joined: Wed Feb 21, 2024 2:25 pm
Location: Poland

Re: Editable pathfile in Open Dialog Box

Post by tBane »

ok thanks for your help
Post Reply