I created a Toolbar, and map in my program.
I would like select button of Toolbar or mesh of map, but select both. How repair it ?
https://www.youtube.com/watch?v=zXnCM_n0RzI
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
bool KeyIsDown[KEY_KEY_CODES_COUNT];
MyEventReceiver();
virtual bool OnEvent(const SEvent&);
virtual bool IsKeyDown(EKEY_CODE);
bool OnMenuItemSelected(IGUIContextMenu* menu);
};
Code: Select all
bool MyEventReceiver::OnEvent(const SEvent& event)
{
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;
/*
case EMIE_MOUSE_MOVED:
MouseState.Position.X = event.MouseInput.X;
MouseState.Position.Y = event.MouseInput.Y;
break;
*/
default:
// We won't use the wheel
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;
}
if (event.EventType == EET_GUI_EVENT)
{
switch (event.GUIEvent.EventType)
{
// ...
case EGET_BUTTON_CLICKED:
{
s32 id = event.GUIEvent.Caller->getID();
if (id == BAR_BUTTON_WATER)
{
brushTerrain = terrainType::water;
std::cout << "setted a water to paint" << std::endl;
}
if (id == BAR_BUTTON_BEACH)
{
brushTerrain = terrainType::beach;
std::cout << "setted a beach to paint" << std::endl;
}
if (id == BAR_BUTTON_GRASS)
{
brushTerrain = terrainType::grass;
std::cout << "setted a grass to paint" << std::endl;
}
if (id == BAR_BUTTON_ROCKS)
{
brushTerrain = terrainType::rocks;
std::cout << "setted a rocks to paint" << std::endl;
}
if (id == BAR_BUTTON_HIGHLANDS)
{
brushTerrain = terrainType::highlands;
std::cout << "setted a highlands to paint" << std::endl;
}
if (id == BAR_BUTTON_DARKNESS)
{
brushTerrain = terrainType::darkness;
std::cout << "setted a darkness to paint" << std::endl;
}
if (id == BAR_BUTTON_SWAMP)
{
brushTerrain = terrainType::swamp;
std::cout << "setted a swamp to paint" << std::endl;
}
if (id == BAR_BUTTON_DESERT)
{
brushTerrain = terrainType::desert;
std::cout << "setted a desert to paint" << std::endl;
}
if (id == BAR_BUTTON_INCREASE)
{
if (brushSize < maxBrushSize)
brushSize++;
}
if (id == BAR_BUTTON_DECREASE)
{
if (brushSize > 0)
brushSize--;
}
}
break;
default:
break;
}
}
return false;
}
Code: Select all
void highlightingtHexTiles()
{
// GET THE MOUSE POSITION
position2d < s32 > mousePos = device->getCursorControl()->getPosition();
// CALCULATE THE RAY TO COLLISION
core::line3d<f32> ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(mousePos, cam);
// COLLISION
core::vector3df intersection;
core::triangle3df hitTriangle;
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
scene::ISceneNode* selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(ray, intersection, hitTriangle);
// CLEAR OLD HIGHLIGHTED HEX TILES
for (auto& t : highlightedHexTiles)
t->meshBuffer->Material.MaterialType = EMT_SOLID;
if (selectedSceneNode != nullptr)
{
vector2di tilePos = globalToHex(selectedSceneNode->getPosition().X, selectedSceneNode->getPosition().Z);
highlightedHexTiles.clear();
getNeighbours(highlightedHexTiles, hexMap->getHexTile(tilePos.X, tilePos.Y), brushSize);
for (auto& t : highlightedHexTiles)
t->meshBuffer->Material.MaterialType = EMT_TRANSPARENT_ADD_COLOR;
}
}
void editHexTiles()
{
for (auto& t : highlightedHexTiles)
t->setTerrainType(brushTerrain);
}
Code: Select all
// ...
// UPDATE
// CAMERA POSITIONING
cam->setPosition(vector3df(cam_x, cam_y, cam_z));
cam->setTarget(vector3df(cam_x, 30, cam_z+50));
highlightingtHexTiles();
if(mousePress)
editHexTiles();
// ...