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) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2009-2021 Andrei Karas
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),
81  mSchool(MagicSchool::SkillMagic),
82  mBaseLvl(0),
83  mSchoolLvl(0),
84  mCommandType(TextCommandType::Text),
85 #endif // TMWA_SUPPORT
86  mImage(nullptr)
87 {
88  loadImage();
89 }
90 
91 TextCommand::TextCommand(const int id) :
92  mCommand(""),
93  mComment(""),
94  mSymbol(""),
95  mTargetType(CommandTarget::NoTarget),
96  mIcon(""),
97  mId(id),
98 #ifdef TMWA_SUPPORT
99  mMana(0U),
100  mSchool(MagicSchool::SkillMagic),
101  mBaseLvl(0),
102  mSchoolLvl(0),
103  mCommandType(TextCommandType::Text),
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()
Image * mImage
Definition: textcommand.h:177
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, const unsigned int schoolLvl, const unsigned int mana)
Definition: textcommand.cpp:40
std::string mIcon
Definition: textcommand.h:167
Definition: text.h:40
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:655
CommandTarget ::T CommandTargetT
Definition: commandtarget.h:33
Configuration paths
#define nullptr
Definition: localconsts.h:45
MagicSchool ::T MagicSchoolT
Definition: magicschool.h:38
bool info(InputEvent &event)
Definition: commands.cpp:57
bool exists(const int id)
Definition: itemdb.cpp:773
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:86
std::string pathJoin(std::string str1, const std::string &str2)
std::string image
Definition: spritedisplay.h:45