summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-02-28 21:37:19 +0300
committerAndrei Karas <akaras@inbox.ru>2013-02-28 21:37:19 +0300
commit03bfe2db420e0b219451590e14bb34c03c71f03c (patch)
treec3cb081449261b51f1ffefa2da4ba39fa5645888
parentc47ef8b3f2ec6ea0e26748af17cb12b7f9cd20c9 (diff)
downloadmv-03bfe2db420e0b219451590e14bb34c03c71f03c.tar.gz
mv-03bfe2db420e0b219451590e14bb34c03c71f03c.tar.bz2
mv-03bfe2db420e0b219451590e14bb34c03c71f03c.tar.xz
mv-03bfe2db420e0b219451590e14bb34c03c71f03c.zip
improve some other files.
-rw-r--r--src/item.cpp14
-rw-r--r--src/itemshortcut.cpp24
-rw-r--r--src/joystick.cpp7
-rw-r--r--src/keyboardconfig.cpp11
-rw-r--r--src/keyboardconfig.h8
5 files changed, 32 insertions, 32 deletions
diff --git a/src/item.cpp b/src/item.cpp
index 261279002..aa58b4167 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -70,7 +70,6 @@ void Item::setId(const int id, const unsigned char color)
// Types 0 and 1 are not equippable items.
mEquipment = id && getInfo().getType() >= 2;
- // Load the associated image
if (mImage)
mImage->decRef();
@@ -81,10 +80,9 @@ void Item::setId(const int id, const unsigned char color)
const ItemInfo &info = getInfo();
mTags = info.getTags();
- SpriteDisplay display = info.getDisplay();
- std::string imagePath = paths.getStringValue(
- "itemIcons").append(display.image);
- std::string dye = combineDye2(imagePath, info.getDyeColorsString(color));
+ const std::string dye = combineDye2(paths.getStringValue(
+ "itemIcons").append(info.getDisplay().image),
+ info.getDyeColorsString(color));
mImage = resman->getImage(dye);
mDrawImage = resman->getImage(dye);
@@ -112,10 +110,8 @@ Image *Item::getImage(const int id, const unsigned char color)
{
ResourceManager *const resman = ResourceManager::getInstance();
const ItemInfo &info = ItemDB::get(id);
- SpriteDisplay display = info.getDisplay();
- std::string imagePath = paths.getStringValue(
- "itemIcons").append(display.image);
- Image *image = resman->getImage(combineDye2(imagePath,
+ Image *image = resman->getImage(combineDye2(paths.getStringValue(
+ "itemIcons").append(info.getDisplay().image),
info.getDyeColorsString(color)));
if (!image)
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index 03efa63c3..499b8e5b8 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -120,7 +120,8 @@ void ItemShortcut::save() const
void ItemShortcut::useItem(const int index) const
{
- if (!PlayerInfo::getInventory())
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
return;
const int itemId = mItems[index];
@@ -129,8 +130,7 @@ void ItemShortcut::useItem(const int index) const
{
if (itemId < SPELL_MIN_ID)
{
- const Item *const item = PlayerInfo::getInventory()->findItem(
- itemId, itemColor);
+ const Item *const item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity())
{
if (item->isEquipment())
@@ -159,13 +159,14 @@ void ItemShortcut::useItem(const int index) const
void ItemShortcut::equipItem(const int index) const
{
- if (!PlayerInfo::getInventory())
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
return;
- if (mItems[index])
+ const int itemId = mItems[index];
+ if (itemId)
{
- const Item *const item = PlayerInfo::getInventory()->findItem(
- mItems[index], mItemColors[index]);
+ const Item *const item = inv->findItem(itemId, mItemColors[index]);
if (item && item->getQuantity())
{
if (item->isEquipment())
@@ -178,13 +179,14 @@ void ItemShortcut::equipItem(const int index) const
}
void ItemShortcut::unequipItem(const int index) const
{
- if (!PlayerInfo::getInventory())
+ const Inventory *const inv = PlayerInfo::getInventory();
+ if (!inv)
return;
- if (mItems[index])
+ const int itemId = mItems[index];
+ if (itemId)
{
- const Item *const item = PlayerInfo::getInventory()->findItem(
- mItems[index], mItemColors[index]);
+ const Item *const item = inv->findItem(itemId, mItemColors[index]);
if (item && item->getQuantity())
{
if (item->isEquipment())
diff --git a/src/joystick.cpp b/src/joystick.cpp
index 42dd14bd1..1e5d5e5f9 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -80,7 +80,7 @@ bool Joystick::open()
mNumber = joystickCount - 1;
if (mNumber < 0)
{
- logger->log("error: incorrect joystick selection");
+ logger->log1("error: incorrect joystick selection");
return false;
}
logger->log("open joystick %d", mNumber);
@@ -312,9 +312,10 @@ bool Joystick::isActionActive(const int index) const
const KeyFunction &key = inputManager.getKey(index);
for (size_t i = 0; i < KeyFunctionSize; i ++)
{
- if (key.values[i].type != INPUT_JOYSTICK)
+ const KeyItem &val = key.values[i];
+ if (val.type != INPUT_JOYSTICK)
continue;
- const int value = key.values[i].value;
+ const int value = val.value;
if (value >= 0 && value < mButtonsNumber)
{
if (mActiveButtons[value])
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index 33c1e3237..1bdc8f7ff 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -75,7 +75,7 @@ void KeyboardConfig::refreshActiveKeys()
mActiveKeys = SDL_GetKeyState(nullptr);
}
-std::string KeyboardConfig::getKeyName(const int key) const
+std::string KeyboardConfig::getKeyName(const int key)
{
if (key == Input::KEY_NO_VALUE)
return "";
@@ -85,7 +85,7 @@ std::string KeyboardConfig::getKeyName(const int key) const
return strprintf(_("key_%d"), key);
}
-std::string KeyboardConfig::getKeyShortString(const std::string &key) const
+std::string KeyboardConfig::getKeyShortString(const std::string &key)
{
if (key == "backspace")
{
@@ -99,7 +99,7 @@ std::string KeyboardConfig::getKeyShortString(const std::string &key) const
return key;
}
-SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event) const
+SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event)
{
return event.key.keysym.sym;
}
@@ -138,10 +138,11 @@ bool KeyboardConfig::isActionActive(const int index) const
const KeyFunction &key = inputManager.getKey(index);
for (size_t i = 0; i < KeyFunctionSize; i ++)
{
- if (key.values[i].type != INPUT_KEYBOARD)
+ const KeyItem &val = key.values[i];
+ if (val.type != INPUT_KEYBOARD)
continue;
- const int value = key.values[i].value;
+ const int value = val.value;
if (value >= 0)
{
if (mActiveKeys[value])
diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h
index 26b080fc4..cbadbbd33 100644
--- a/src/keyboardconfig.h
+++ b/src/keyboardconfig.h
@@ -71,10 +71,10 @@ class KeyboardConfig final
*/
void refreshActiveKeys();
- std::string getKeyShortString(const std::string &key)
- const A_WARN_UNUSED;
+ static std::string getKeyShortString(const std::string &key)
+ A_WARN_UNUSED;
- SDLKey getKeyFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
+ static SDLKey getKeyFromEvent(const SDL_Event &event) A_WARN_UNUSED;
int getKeyValueFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
@@ -82,7 +82,7 @@ class KeyboardConfig final
KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
- std::string getKeyName(const int key) const A_WARN_UNUSED;
+ static std::string getKeyName(const int key)A_WARN_UNUSED;
bool isActionActive(const int index) const A_WARN_UNUSED;