ManaPlus
textcommand.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 Andrei Karas
5  * Copyright (C) 2011-2017 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "textcommand.h"
24 
25 #include "configuration.h"
26 
27 #include "gui/theme.h"
28 
29 #include "resources/iteminfo.h"
30 
31 #include "resources/db/itemdb.h"
32 
33 #include "resources/image/image.h"
34 
36 
37 #include "debug.h"
38 
39 #ifdef TMWA_SUPPORT
41  const std::string &symbol,
42  const std::string &command,
43  const std::string &comment,
44  const CommandTargetT type,
45  const std::string &icon,
46  const unsigned int basicLvl,
47  const MagicSchoolT school,
48  const unsigned int schoolLvl,
49  const unsigned int mana) :
50  mCommand(command),
51  mComment(comment),
52  mSymbol(symbol),
53  mTargetType(type),
54  mIcon(icon),
55  mId(id),
56  mMana(mana),
57  mSchool(school),
58  mBaseLvl(basicLvl),
59  mSchoolLvl(schoolLvl),
60  mCommandType(TextCommandType::Magic),
61  mImage(nullptr)
62 {
63  loadImage();
64 }
65 #endif // TMWA_SUPPORT
66 
68  const std::string &symbol,
69  const std::string &command,
70  const std::string &comment,
71  const CommandTargetT type,
72  const std::string &icon) :
73  mCommand(command),
74  mComment(comment),
75  mSymbol(symbol),
76  mTargetType(type),
77  mIcon(icon),
78  mId(id),
79 #ifdef TMWA_SUPPORT
80  mMana(0U),
82  mBaseLvl(0),
83  mSchoolLvl(0),
85 #endif // TMWA_SUPPORT
87 {
88  loadImage();
89 }
90 
91 TextCommand::TextCommand(const int id) :
92  mCommand(""),
93  mComment(""),
94  mSymbol(""),
96  mIcon(""),
97  mId(id),
98 #ifdef TMWA_SUPPORT
99  mMana(0U),
101  mBaseLvl(0),
102  mSchoolLvl(0),
104 #endif // TMWA_SUPPORT
105  mImage(nullptr)
106 {
107  loadImage();
108 }
109 
110 
112 {
113  if (mImage != nullptr)
114  {
115  mImage->decRef();
116  mImage = nullptr;
117  }
118 }
119 
121 {
122  if (mImage != nullptr)
123  {
124  mImage->decRef();
125  mImage = nullptr;
126  }
127 
128  if (mIcon.empty() ||
130  {
131  return;
132  }
133 
134  const ItemInfo &info = ItemDB::get(mIcon);
135  const SpriteDisplay &display = info.getDisplay();
137  display.image));
138 
139  if (mImage == nullptr)
140  mImage = Theme::getImageFromTheme("unknown-item.png");
141 }
std::string getStringValue(const std::string &key) const
void loadImage()
const ItemInfo & get(const int id)
Definition: itemdb.cpp:814
TextCommand(const int id, const std::string &symbol, const std::string &command, const std::string &comment, const CommandTargetT type, const std::string &icon, const unsigned int basicLvl, const MagicSchoolT school=MagicSchool::SkillMagic, const unsigned int schoolLvl=0U, const unsigned int mana=0U)
Definition: textcommand.cpp:40
std::string pathJoin(std::string str1, const std::string &str2)
unsigned mSchoolLvl
Definition: textcommand.h:173
bool exists(const int id)
Definition: itemdb.cpp:795
Image * mImage
Definition: textcommand.h:177
CommandTarget ::T CommandTargetT
Definition: commandtarget.h:32
unsigned mBaseLvl
Definition: textcommand.h:172
std::string mCommand
Definition: textcommand.h:163
MagicSchool ::T MagicSchoolT
Definition: magicschool.h:37
std::string mIcon
Definition: textcommand.h:167
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
bool info(InputEvent &event)
Definition: commands.cpp:56
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:654
MagicSchoolT mSchool
Definition: textcommand.h:171
#define nullptr
Definition: localconsts.h:44
const SpriteDisplay & getDisplay() const
Definition: iteminfo.h:93
TextCommandTypeT mCommandType
Definition: textcommand.h:174
unsigned int mMana
Definition: textcommand.h:170
Configuration paths
std::string mComment
Definition: textcommand.h:164
std::string mSymbol
Definition: textcommand.h:165
void decRef()
Definition: image.cpp:521
CommandTargetT mTargetType
Definition: textcommand.h:166
std::string image
Definition: spritedisplay.h:44
Definition: text.h:38