ManaPlus
Public Member Functions | Private Attributes | Friends
MapItem Class Reference

#include <mapitem.h>

Public Member Functions

 MapItem ()
 
 MapItem (const int type)
 
 MapItem (const int type, const std::string &comment)
 
 MapItem (const int type, const std::string &comment, const int x, const int y)
 
 ~MapItem ()
 
int getType () const
 
void setType (const int type)
 
void setPos (const int x, const int y)
 
int getX () const
 
int getY () const
 
const std::string & getComment () const
 
void setComment (const std::string &comment)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
void draw (Graphics *const graphics, const int x, const int y, const int dx, const int dy) const
 

Private Attributes

ImagemImage
 
std::string mComment
 
std::string mName
 
int mType
 
int mX
 
int mY
 

Friends

class Map
 
class MapLayer
 
class SpecialLayer
 

Detailed Description

Definition at line 31 of file mapitem.h.

Constructor & Destructor Documentation

◆ MapItem() [1/4]

MapItem::MapItem ( )

Definition at line 38 of file mapitem.cpp.

References MapItemType::EMPTY, and setType().

38  :
39  mImage(nullptr),
40  mComment(),
41  mName(),
43  mX(-1),
44  mY(-1)
45 {
47 }
int mType
Definition: mapitem.h:87
int mY
Definition: mapitem.h:89
std::string mComment
Definition: mapitem.h:85
std::string mName
Definition: mapitem.h:86
void setType(const int type)
Definition: mapitem.cpp:95
int mX
Definition: mapitem.h:88
Image * mImage
Definition: mapitem.h:84

◆ MapItem() [2/4]

MapItem::MapItem ( const int  type)
explicit

Definition at line 49 of file mapitem.cpp.

References setType().

49  :
50  mImage(nullptr),
51  mComment(),
52  mName(),
53  mType(type),
54  mX(-1),
55  mY(-1)
56 {
57  setType(type);
58 }
int mType
Definition: mapitem.h:87
int mY
Definition: mapitem.h:89
std::string mComment
Definition: mapitem.h:85
std::string mName
Definition: mapitem.h:86
void setType(const int type)
Definition: mapitem.cpp:95
int mX
Definition: mapitem.h:88
Image * mImage
Definition: mapitem.h:84

◆ MapItem() [3/4]

MapItem::MapItem ( const int  type,
const std::string &  comment 
)

Definition at line 60 of file mapitem.cpp.

References setType().

61  :
62  mImage(nullptr),
63  mComment(comment),
64  mName(),
65  mType(type),
66  mX(-1),
67  mY(-1)
68 {
69  setType(type);
70 }
int mType
Definition: mapitem.h:87
int mY
Definition: mapitem.h:89
std::string mComment
Definition: mapitem.h:85
std::string mName
Definition: mapitem.h:86
void setType(const int type)
Definition: mapitem.cpp:95
int mX
Definition: mapitem.h:88
Image * mImage
Definition: mapitem.h:84

◆ MapItem() [4/4]

MapItem::MapItem ( const int  type,
const std::string &  comment,
const int  x,
const int  y 
)

Definition at line 72 of file mapitem.cpp.

References setType().

75  :
76  mImage(nullptr),
77  mComment(comment),
78  mName(),
79  mType(type),
80  mX(x),
81  mY(y)
82 {
83  setType(type);
84 }
int mType
Definition: mapitem.h:87
int mY
Definition: mapitem.h:89
std::string mComment
Definition: mapitem.h:85
std::string mName
Definition: mapitem.h:86
void setType(const int type)
Definition: mapitem.cpp:95
int mX
Definition: mapitem.h:88
Image * mImage
Definition: mapitem.h:84

◆ ~MapItem()

MapItem::~MapItem ( )

Definition at line 86 of file mapitem.cpp.

References Image::decRef(), and mImage.

87 {
88  if (mImage != nullptr)
89  {
90  mImage->decRef();
91  mImage = nullptr;
92  }
93 }
Image * mImage
Definition: mapitem.h:84
void decRef()
Definition: image.cpp:521

Member Function Documentation

◆ draw()

void MapItem::draw ( Graphics *const  graphics,
const int  x,
const int  y,
const int  dx,
const int  dy 
) const

Definition at line 132 of file mapitem.cpp.

References UserColorId::BEING, BLOCK_END, BLOCK_START, MapItemType::CROSS, Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), MapItemType::EMPTY, Graphics::fillRectangle(), ServerCommandType::font, UserPalette::getColor(), UserPalette::getColorWithAlpha(), Gui::getFont(), gui, MapItemType::HOME, UserColorId::HOME_PLACE, UserColorId::HOME_PLACE_BORDER, mImage, mName, mType, MapItemType::PORTAL, MapItemType::ROAD, UserColorId::ROAD_POINT, Graphics::setColor(), and userPalette.

Referenced by SpecialLayer::draw(), MapLayer::drawSpecialLayer(), and setName().

134 {
135  BLOCK_START("MapItem::draw")
136  if (mImage != nullptr)
137  graphics->drawImage(mImage, x, y);
138 
139  switch (mType)
140  {
141  case MapItemType::ROAD:
142  case MapItemType::CROSS:
145  graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
146  dx / 3, dy / 3));
147  break;
148  case MapItemType::HOME:
149  {
152  graphics->fillRectangle(Rect(x, y, dx, dy));
155  graphics->drawRectangle(Rect(x, y, dx, dy));
156  break;
157  }
158  default:
159  break;
160  }
161  if (!mName.empty()
162  && mType != MapItemType::PORTAL
163  && mType != MapItemType::EMPTY)
164  {
165  Font *const font = gui->getFont();
166  const Color &color = userPalette->getColor(UserColorId::BEING);
167  font->drawString(graphics,
168  color,
169  color,
170  mName,
171  x, y);
172  }
173  BLOCK_END("MapItem::draw")
174 }
const Color & getColor(UserColorIdT type, const unsigned int alpha=255U)
Definition: userpalette.h:159
Gui * gui
Definition: gui.cpp:110
Definition: font.h:88
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
int mType
Definition: mapitem.h:87
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Font * getFont() const
Definition: gui.h:159
virtual void drawRectangle(const Rect &rectangle)=0
UserPalette * userPalette
Definition: userpalette.cpp:33
void drawImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
virtual void setColor(const Color &color)
Definition: graphics.h:319
std::string mName
Definition: mapitem.h:86
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
virtual void fillRectangle(const Rect &rectangle)=0
Image * mImage
Definition: mapitem.h:84
Definition: color.h:74

◆ getComment()

const std::string& MapItem::getComment ( ) const
inline

◆ getName()

const std::string& MapItem::getName ( ) const
inline

Definition at line 73 of file mapitem.h.

References mName.

74  { return mName; }
std::string mName
Definition: mapitem.h:86

◆ getType()

int MapItem::getType ( ) const
inline

◆ getX()

int MapItem::getX ( ) const
inline

Definition at line 61 of file mapitem.h.

References mX.

Referenced by PopupMenu::handleLink(), RenameListener::setMapItem(), SocialNavigationTab::updateList(), and SocialNavigationTab::updateNames().

62  { return mX; }
int mX
Definition: mapitem.h:88

◆ getY()

int MapItem::getY ( ) const
inline

Definition at line 64 of file mapitem.h.

References mY.

Referenced by PopupMenu::handleLink(), RenameListener::setMapItem(), SocialNavigationTab::updateList(), and SocialNavigationTab::updateNames().

65  { return mY; }
int mY
Definition: mapitem.h:89

◆ setComment()

void MapItem::setComment ( const std::string &  comment)
inline

Definition at line 70 of file mapitem.h.

References mComment.

Referenced by RenameListener::action().

71  { mComment = comment; }
std::string mComment
Definition: mapitem.h:85

◆ setName()

void MapItem::setName ( const std::string &  name)
inline

Definition at line 76 of file mapitem.h.

References A_NONNULL, draw(), and mName.

Referenced by LocalPlayer::setHome(), and SocialNavigationTab::updateList().

77  { mName = name; }
std::string mName
Definition: mapitem.h:86

◆ setPos()

void MapItem::setPos ( const int  x,
const int  y 
)

Definition at line 126 of file mapitem.cpp.

References mX, mY, x, and y.

Referenced by getType(), and SpecialLayer::setTile().

127 {
128  mX = x;
129  mY = y;
130 }
int mY
Definition: mapitem.h:89
int mX
Definition: mapitem.h:88

◆ setType()

void MapItem::setType ( const int  type)

Definition at line 95 of file mapitem.cpp.

References MapItemType::ARROW_DOWN, MapItemType::ARROW_LEFT, MapItemType::ARROW_RIGHT, MapItemType::ARROW_UP, Image::decRef(), Loader::getImage(), mImage, and mType.

Referenced by SpecialLayer::addRoad(), SpecialLayer::clean(), getType(), MapItem(), and SpecialLayer::setTile().

96 {
97  std::string name;
98  mType = type;
99  if (mImage != nullptr)
100  mImage->decRef();
101 
102  switch (type)
103  {
105  name = "graphics/sprites/arrow_up.png";
106  break;
108  name = "graphics/sprites/arrow_down.png";
109  break;
111  name = "graphics/sprites/arrow_left.png";
112  break;
114  name = "graphics/sprites/arrow_right.png";
115  break;
116  default:
117  break;
118  }
119 
120  if (!name.empty())
121  mImage = Loader::getImage(name);
122  else
123  mImage = nullptr;
124 }
int mType
Definition: mapitem.h:87
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
Image * mImage
Definition: mapitem.h:84
void decRef()
Definition: image.cpp:521

Friends And Related Function Documentation

◆ Map

friend class Map
friend

Definition at line 34 of file mapitem.h.

◆ MapLayer

friend class MapLayer
friend

Definition at line 35 of file mapitem.h.

◆ SpecialLayer

friend class SpecialLayer
friend

Definition at line 36 of file mapitem.h.

Field Documentation

◆ mComment

std::string MapItem::mComment
private

Definition at line 85 of file mapitem.h.

Referenced by getComment(), and setComment().

◆ mImage

Image* MapItem::mImage
private

Definition at line 84 of file mapitem.h.

Referenced by draw(), setType(), and ~MapItem().

◆ mName

std::string MapItem::mName
private

Definition at line 86 of file mapitem.h.

Referenced by draw(), getName(), and setName().

◆ mType

int MapItem::mType
private

◆ mX

int MapItem::mX
private

Definition at line 88 of file mapitem.h.

Referenced by getX(), and setPos().

◆ mY

int MapItem::mY
private

Definition at line 89 of file mapitem.h.

Referenced by getY(), and setPos().


The documentation for this class was generated from the following files: