void MapCanvas::OnMouseActionClick(wxMouseEvent& event)
{
SetFocus();
int mouse_map_x, mouse_map_y;
ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y);
if(event.ControlDown() && event.AltDown()) {
Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor);
if(tile && tile->size() > 0) {
Item* item = tile->getTopItem();
if(item && item->getRAWBrush())
g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW);
}
} else if(g_gui.IsSelectionMode()) {
if(isPasting()) {
// Set paste to false (no rendering etc.)
EndPasting();
// Paste to the map
editor.copybuffer.paste(editor, Position(mouse_map_x, mouse_map_y, floor));
// Start dragging
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else do {
boundbox_selection = false;
if(event.ShiftDown()) {
boundbox_selection = true;
if(!event.ControlDown()) {
editor.selection.start(); // Start selection session
editor.selection.clear(); // Clear out selection
editor.selection.finish(); // End selection session
editor.selection.updateSelectionCount();
}
} else if(event.ControlDown()) {
Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor);
if(tile) {
if(tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
editor.selection.start(); // Start selection session
if(tile->spawn->isSelected()) {
editor.selection.remove(tile, tile->spawn);
} else {
editor.selection.add(tile, tile->spawn);
}
editor.selection.finish(); // Finish selection session
editor.selection.updateSelectionCount();
} else if(tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
editor.selection.start(); // Start selection session
if(tile->creature->isSelected()) {
editor.selection.remove(tile, tile->creature);
} else {
editor.selection.add(tile, tile->creature);
}
editor.selection.finish(); // Finish selection session
editor.selection.updateSelectionCount();
} else {
Item* item = tile->getTopItem();
if(item) {
editor.selection.start(); // Start selection session
if(item->isSelected()) {
editor.selection.remove(tile, item);
} else {
editor.selection.add(tile, item);
}
editor.selection.finish(); // Finish selection session
editor.selection.updateSelectionCount();
}
}
}
} else {
Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor);
if(!tile) {
editor.selection.start(); // Start selection session
editor.selection.clear(); // Clear out selection
editor.selection.finish(); // End selection session
editor.selection.updateSelectionCount();
} else if(tile->isSelected()) {
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else {
editor.selection.start(); // Start a selection session
editor.selection.clear();
editor.selection.commit();
if(tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
editor.selection.add(tile, tile->spawn);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else if(tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
editor.selection.add(tile, tile->creature);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else {
Item* item = tile->getTopItem();
if(item) {
editor.selection.add(tile, item);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
}
}
editor.selection.finish(); // Finish the selection session
editor.selection.updateSelectionCount();
}
}
} while(false);
} else if(g_gui.GetCurrentBrush()) { // Drawing mode
Brush* brush = g_gui.GetCurrentBrush();
if(event.ShiftDown() && brush->canDrag()) {
dragging_draw = true;
} else {
if(g_gui.GetBrushSize() == 0 && !brush->oneSizeFitsAll()) {
drawing = true;
} else {
drawing = g_gui.GetCurrentBrush()->canSmear();
}
if(brush->isWall()) {
if(event.AltDown() && g_gui.GetBrushSize() == 0) {
// z0mg, just clicked a tile, shift variaton.
if(event.ControlDown()) {
editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
} else {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
}
} else {
PositionVector tilestodraw;
PositionVector tilestoborder;
int start_map_x = mouse_map_x - g_gui.GetBrushSize();
int start_map_y = mouse_map_y - g_gui.GetBrushSize();
int end_map_x = mouse_map_x + g_gui.GetBrushSize();
int end_map_y = mouse_map_y + g_gui.GetBrushSize();
for(int y = start_map_y -1; y <= end_map_y + 1; ++y) {
for(int x = start_map_x - 1; x <= end_map_x + 1; ++x) {
if((x <= start_map_x+1 || x >= end_map_x-1) || (y <= start_map_y+1 || y >= end_map_y-1)) {
tilestoborder.push_back(Position(x,y,floor));
}
if(((x == start_map_x || x == end_map_x) || (y == start_map_y || y == end_map_y)) &&
((x >= start_map_x && x <= end_map_x) && (y >= start_map_y && y <= end_map_y))) {
tilestodraw.push_back(Position(x,y,floor));
}
}
}
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
}
} else if(brush->isDoor()) {
PositionVector tilestodraw;
PositionVector tilestoborder;
tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y - 1, floor));
tilestoborder.push_back(Position(mouse_map_x - 1, mouse_map_y , floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y + 1, floor));
tilestoborder.push_back(Position(mouse_map_x + 1, mouse_map_y , floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
} else if(brush->isDoodad() || brush->isSpawn() || brush->isCreature()) {
if(event.ControlDown()) {
if(brush->isDoodad()) {
PositionVector tilestodraw;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr);
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown());
}
} else {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown());
}
} else {
if(brush->isGround() && event.AltDown()) {
replace_dragging = true;
Tile* draw_tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor);
if(draw_tile) {
editor.replace_brush = draw_tile->getGroundBrush();
} else {
editor.replace_brush = nullptr;
}
}
if(brush->needBorders()) {
PositionVector tilestodraw;
PositionVector tilestoborder;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, &tilestoborder);
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
} else if(brush->oneSizeFitsAll()) {
if(brush->isHouseExit() || brush->isWaypoint()) {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
} else {
PositionVector tilestodraw;
tilestodraw.push_back(Position(mouse_map_x,mouse_map_y, floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
}
} else {
PositionVector tilestodraw;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr);
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
}
}
// Change the doodad layout brush
g_gui.FillDoodadPreviewBuffer();
}
}
last_click_x = int(event.GetX()*zoom);
last_click_y = int(event.GetY()*zoom);
int start_x, start_y;
static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y);
last_click_abs_x = last_click_x + start_x;
last_click_abs_y = last_click_y + start_y;
last_click_map_x = mouse_map_x;
last_click_map_y = mouse_map_y;
last_click_map_z = floor;
g_gui.RefreshView();
g_gui.UpdateMinimap();
}