ManaPlus
castingeffect.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus 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 "being/castingeffect.h"
23 
24 #include "configuration.h"
25 
27 
28 #include "gui/userpalette.h"
29 
30 #include "render/graphics.h"
31 
33 
34 #include "utils/checkutils.h"
35 #include "utils/delete2.h"
36 
37 #include "debug.h"
38 
39 CastingEffect::CastingEffect(const int skillId,
40  const int skillLevel,
41  const std::string &animation,
42  const int x,
43  const int y,
44  const int range) :
45  Actor(),
46  mSprite(animation.empty() ? nullptr :
47  AnimatedSprite::load(paths.getStringValue("sprites") + animation, 0)),
48  mRectX((x - range) * mapTileSize),
49  mRectY((y - range) * mapTileSize),
50  mRectSize(range * mapTileSize * 2 + mapTileSize),
51  mAnimationX(mRectX + (mRectSize - (mSprite != nullptr ?
52  mSprite->getWidth() : 0)) / 2),
53  mAnimationY(mRectY + (mRectSize - (mSprite != nullptr ?
54  mSprite->getHeight() : 0)) / 2)
55 {
56  mPixelX = x * mapTileSize;
57  mPixelY = y * mapTileSize;
58  mYDiff = range * mapTileSize + 31;
59  if (mSprite == nullptr)
60  {
61  reportAlways("Skill %d/%d casting animation '%s' load failed",
62  skillId,
63  skillLevel,
64  animation.c_str())
65  }
66 }
67 
69 {
71 }
72 
73 void CastingEffect::draw(Graphics *const graphics,
74  const int offsetX,
75  const int offsetY) const
76 {
79 
80  graphics->drawRectangle(Rect(
81  mRectX + offsetX,
82  mRectY + offsetY,
83  mRectSize,
84  mRectSize));
85  if (mSprite != nullptr)
86  {
87  mSprite->drawRescaled(graphics,
88  mRectX + offsetX,
89  mRectY + offsetY,
90  mRectSize,
91  mRectSize);
92  }
93 }
94 
95 void CastingEffect::update(const int time)
96 {
97  if (mSprite != nullptr)
98  mSprite->update(time);
99 }
100 
102 {
103  if (mSprite != nullptr)
104  return mSprite->isTerminated();
105  return false;
106 }
#define reportAlways(...)
Definition: checkutils.h:253
Definition: actor.h:42
int mPixelX
Definition: actor.h:133
int mYDiff
Definition: actor.h:141
int mPixelY
Definition: actor.h:134
void drawRescaled(Graphics *const graphics, const int posX, const int posY, const int dx, const int dy) const
bool isTerminated() const
bool update(const int time)
void update(const int time)
CastingEffect(const int skillId, const int skillLevel, const std::string &animation, const int x, const int y, const int range)
AnimatedSprite * mSprite
Definition: castingeffect.h:68
bool isTerminated() const
void draw(Graphics *const graphics, const int offsetX, const int offsetY) const
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRectangle(const Rect &rectangle)=0
Definition: rect.h:74
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:200
Configuration paths
static const int mapTileSize
Definition: map.h:27
#define delete2(var)
Definition: delete2.h:25
#define nullptr
Definition: localconsts.h:45
void load()
Definition: avatardb.cpp:46
@ ATTACK_RANGE_BORDER
Definition: usercolorid.h:89
std::string empty
Definition: podict.cpp:26
UserPalette * userPalette
Definition: userpalette.cpp:34