 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file.
20 #include "imgui_impl_sdl.h"
22 #include "../game/ui/PauseMenu.hxx"
24 #ifdef MICROPROFILE_ENABLED
25 #include "microprofile/microprofile.h"
47 Layer topMostActiveLayer;
48 std::vector<MapNodeData> mapNodeData;
56 switch (topMostActiveLayer)
75 tileToPlace = mapNodeData[topMostActiveLayer].tileID;
81 #ifdef MICROPROFILE_ENABLED
82 MICROPROFILE_SCOPEI(
"EventManager",
"checkEvents", MP_BEIGE);
85 SDL_Point mouseScreenCoords;
86 Point mouseIsoCoords{};
89 while (SDL_PollEvent(&event))
91 ImGui_ImplSDL2_ProcessEvent(&event);
100 switch (event.key.keysym.sym)
105 uiManager.closeOpenMenus();
111 uiManager.closeOpenMenus();
113 if (uiManager.isAnyMenuOpen())
114 uiManager.closeMenu();
134 uiManager.toggleDebugMenu();
206 switch (event.key.keysym.sym)
223 case SDL_MULTIGESTURE:
224 if (event.mgesture.numFingers == 2)
228 if (event.mgesture.dDist != 0)
249 case SDL_MOUSEMOTION:
262 if ((event.motion.xrel == 0) && (event.motion.yrel == 0))
271 mouseScreenCoords = {
event.button.x,
event.button.y};
275 Point origCornerPoint =
280 origCornerPoint = mouseIsoCoords;
310 if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
338 std::vector<Point> nodesToAdd;
346 if (
demolishMode || (tileToPlaceData && tileToPlaceData->
tileType == +TileType::GROUNDDECORATION))
357 for (
auto &foundNode :
TileManager::instance().getTargetCoordsOfTileID(currentOriginPoint, currentTileID))
362 nodesToAdd.push_back(foundNode);
370 if (tileToPlaceData && tileToPlaceData->
tileType == +TileType::GROUNDDECORATION)
391 const Point &buildingCoordinates =
394 auto transparentBuildingIt =
399 if (tileData && tileData->
category !=
"Flora")
409 case SDL_MOUSEBUTTONDOWN:
412 if (event.button.button == SDL_BUTTON_RIGHT)
417 else if (event.button.button == SDL_BUTTON_LEFT)
420 mouseScreenCoords = {
event.button.x,
event.button.y};
425 bool canPlaceTileID =
false;
426 if (mouseIsoCoords.isWithinMapBoundaries())
428 canPlaceTileID =
true;
429 for (
auto coordinate : targetObjectNodes)
431 if (!coordinate.isWithinMapBoundaries())
433 canPlaceTileID =
false;
455 case SDL_MOUSEBUTTONUP:
459 uiManager.closeOpenMenus();
472 mouseScreenCoords = {
event.button.
x,
event.button.y};
477 if (event.button.button == SDL_BUTTON_LEFT)
525 if (!uiManager.isMouseHovered() && !
tileToPlace.empty() &&
void getNodeInformation(const Point &isoCoordinates) const
Debug MapNodeData to Console.
bool m_cancelTileSelection
determines if a right click should cancel tile selection
TerrainEdit terrainEditMode
@ DE_ZONE
Remove only zones.
PlacementMode placementMode
Specifies the placement mode when holding down the mouse.
void moveCamera(int xOffset, int yOffset)
Move the camera in the given direction.
void demolishNode(const std::vector< Point > &isoCoordinates, bool updateNeighboringTiles=false, Layer layer=Layer::NONE)
Demolish a node.
Point getNodeOrigCornerPoint(const Point &isoCoordinates, Layer layer=Layer::NONE)
Get original corner point of given point within building borders.
std::vector< Point > getTargetCoordsOfTileID(const Point &targetCoordinates, const std::string &tileID)
Return a vector of Points on a target node (origin corner) that would be occupied by a given tileID i...
std::string category
The category this item resides in. Categories are used for the building menu in-game and for sorting ...
ScreenDimension screenHeight
the screen height
@ POWERLINES
9- Powerlines
std::vector< Point > m_transparentBuildings
std::vector< Point > m_nodesToPlace
Layer getTopMostActiveLayer() const
return topmost active layer.
@ NONE
0- this must be FIRST !!!
Point m_pinchCenterCoords
@ GROUND_DECORATION
Remove only ground decoration.
static std::vector< Point > getArea(const Point &isoCoordinatesStart, const Point &isoCoordinatesEnd)
Gets all nodes in a rectangular area between start and end point.
const TileData * getTileData(Layer layer) const
void highlightNode(const Point &isoCoordinates, const SpriteRGBColor &rgbColor)
Sets a node to be highlighted.
const std::vector< MapNodeData > & getMapNodeData() const
void changeZoomLevel(bool inc)
void levelHeight(const Point &startCoordinate, const std::vector< Point > levelArea)
level area of map nodes.
static void toggleLayer(unsigned int layer)
Toggle Drawing Layer.
bool isPlacementOnAreaAllowed(const std::vector< Point > &targetCoordinates, const std::string &tileID) const
check if Tile can be placed in an area
void setPinchDistance(float pinchDistance, int isoX, int isoY)
Sets the pinch distance for touch screens.
Point convertScreenToIsoCoordinates(const SDL_Point &screenCoordinates)
converts screen space coordinates to isometric space coordinates.
ScreenDimension screenWidth
the screen width
Class that holds map nodes.
void pickTileUnderCursor(Point mouseIsoCoords)
@ STRAIGHT_LINE
Place tiles in a straight, rectangular line.
static std::vector< Point > getLine(Point isoCoordinatesStart, Point isoCoordinatesEnd)
Creates a line between two points using the Bresenham Line algorithm.
std::string getTileID(const Point &isoCoordinates, Layer layer)
get Tile ID of specific layer of specific iso coordinates
static std::vector< Point > getStraightLine(const Point &isoCoordinatesStart, const Point &isoCoordinatesEnd)
Gets all nodes in a straight line from start and end point.
@ ZONE
4- Optional layer, zones(Industrial/Residential/Commercial).
@ BLUEPRINT
1- Optional layer - Map Blueprint
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
Layer getTileLayer(const std::string &tileID) const
Get the Layer that is associated with a tileID. The Tile will be placed on this layer.
static constexpr Point INVALID()
@ LINE
Place tiles in a line from start to end point.
void unHighlightNode(const Point &isoCoordinates)
Sets a node to be unhighlighred.
@ SINGLE
Place tiles on a single spot.
bool rectangularRoads
place rectangular road tiles instead of diagonal tiles
DemolishMode demolishMode
void checkEvents(SDL_Event &event)
TileData * getTileData(const std::string &id) noexcept
Get the TileData struct for this tileID and all information associated with it.
bool m_placementAllowed
remember if placement is allowed from mousemove to mousedown
@ DEFAULT
Demolish everything, but not.
@ TERRAIN
3- Terrain tiles, decorations, ... - must always be a "full" tile
@ RECTANGLE
draw a rectangle between start and end point
void setNodeTransparency(const float transparencyFactor, const Layer &layer) const
Sets a node to be Transparent.
void unHighlightNodes()
Unhighlight highlighted Nodes.
Point findNodeInMap(const SDL_Point &screenCoordinates, const Layer &layer=Layer::NONE)
Returns the node at given screen coordinates.
@ ROAD
5- Optional layer, roads.
MapNode & getMapNode(Point isoCoords)
Get pointer to a single mapNode at specific iso coordinates.
@ GROUND_DECORATION
13- Decoration to place beneath buildings. Like concrete or grass
static MapFunctions & instance(void)
Get an instance of the singleton.
bool drawUI
Draw UI. This is a temporary variable until the new UI has been implemented.
std::vector< Point > m_nodesToHighlight
bool setTileID(const std::string &tileID, Point coordinate)
Set the Tile ID Of Node object.
void toggleFullScreen() const
@ UNDERGROUND
2- Optional layer - Pipes, Subway-pipes and so onn
bool m_isPuttingTile
determines if putting tile action is being performed
void changeHeight(const Point &isoCoordinates, const bool elevate)
Change map node height.
SDL_Point convertIsoToScreenCoordinates(const Point &isoCoordinates, bool calcWithoutOffset)
converts coordinates from isometric to screen space
Holds all releavted information to this specific tile.