Mana
Loading...
Searching...
No Matches
flooritem.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "flooritem.h"
23
24#include "configuration.h"
25
26#include "resources/image.h"
27#include "resources/itemdb.h"
28#include "resources/iteminfo.h"
30#include "resources/theme.h"
31
33 int itemId,
34 const Vector &position,
35 Map *map):
36 ActorSprite(id),
37 mItemId(itemId),
38 mX(0), mY(0)
39{
40 mPos = position;
41
42 setMap(map);
43
44 mX = (int)position.x / map->getTileWidth();
45 mY = (int)position.y / map->getTileHeight();
46
47 // Set up sprites and particle effects
48 auto &info = getInfo();
49 setupSpriteDisplay(info.display, false);
50
51 // If no sprites are defined, fall back to the item icon
52 if (info.display.sprites.empty())
53 {
55 std::string imagePath = paths.getStringValue("itemIcons") + info.display.image;
56
57 mImage = resman->getImage(imagePath);
58 if (!mImage)
60 }
61}
62
63bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
64{
65 if (mImage)
66 {
69 getPixelX() + offsetX - mImage->getWidth() / 2,
70 getPixelY() + offsetY - mImage->getHeight() / 2);
71 }
72
73 return ActorSprite::draw(graphics, offsetX, offsetY);
74}
75
77{
78 return itemDb->get(mItemId);
79}
bool draw(Graphics *graphics, int offsetX, int offsetY) const override
Draws the Actor to the given graphics context.
void setMap(Map *map) override
float getAlpha() const override
Returns the current alpha value used to draw the actor.
void setupSpriteDisplay(const SpriteDisplay &display, bool forceDisplay=true)
int getPixelX() const
Returns the pixels X coordinate of the actor.
Definition actor.h:65
int getPixelY() const
Returns the pixel Y coordinate of the actor.
Definition actor.h:71
Vector mPos
Position in pixels relative to map.
Definition actor.h:114
std::string getStringValue(const std::string &key) const
bool draw(Graphics *graphics, int offsetX, int offsetY) const override
Draws the Actor to the given graphics context.
Definition flooritem.cpp:63
const ItemInfo & getInfo() const
Returns the item info for this floor item.
Definition flooritem.cpp:76
FloorItem(int id, int itemId, const Vector &position, Map *map)
Constructor.
Definition flooritem.cpp:32
ResourceRef< Image > mImage
Definition flooritem.h:68
int mItemId
Definition flooritem.h:66
A central point of control for graphics.
Definition graphics.h:78
bool drawImage(const Image *image, int x, int y)
Blits an image onto the screen.
Definition graphics.cpp:36
int getHeight() const
Returns the height of the image.
Definition image.h:89
int getWidth() const
Returns the width of the image.
Definition image.h:83
void setAlpha(float alpha)
Sets the alpha value of this image.
Definition image.cpp:176
const ItemInfo & get(int id) const
Definition itemdb.cpp:145
Defines a class for storing generic item infos.
Definition iteminfo.h:100
A tile map.
Definition map.h:147
int getTileHeight() const
Returns the tile height used by this map.
Definition map.h:271
int getTileWidth() const
Returns the tile width of this map.
Definition map.h:265
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
static ResourceRef< Image > getImageFromTheme(const std::string &path)
Definition theme.cpp:308
Vector class.
Definition vector.h:33
float y
Definition vector.h:172
float x
Definition vector.h:171
Configuration paths
XML default paths information reader.
Definition client.cpp:99
Graphics * graphics
Definition client.cpp:104
ItemDB * itemDb
Items info database.
Definition client.cpp:106