summaryrefslogtreecommitdiff
path: root/src/gui/shortcut
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-08 21:20:53 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-08 21:20:53 +0300
commit64887d7ee931fa8426d25c4aaf0ee1a767d4a761 (patch)
tree038eb18058213ccbde5296686d3d687df610aac5 /src/gui/shortcut
parent91e74d8f1dc3f1fe01cb65822913488f5cbc5657 (diff)
downloadmv-64887d7ee931fa8426d25c4aaf0ee1a767d4a761.tar.gz
mv-64887d7ee931fa8426d25c4aaf0ee1a767d4a761.tar.bz2
mv-64887d7ee931fa8426d25c4aaf0ee1a767d4a761.tar.xz
mv-64887d7ee931fa8426d25c4aaf0ee1a767d4a761.zip
Use size_t type for index in other shortcut classes.
Diffstat (limited to 'src/gui/shortcut')
-rw-r--r--src/gui/shortcut/emoteshortcut.cpp10
-rw-r--r--src/gui/shortcut/emoteshortcut.h15
-rw-r--r--src/gui/shortcut/shortcutbase.cpp12
-rw-r--r--src/gui/shortcut/shortcutbase.h16
-rw-r--r--src/gui/shortcut/spellshortcut.h2
5 files changed, 28 insertions, 27 deletions
diff --git a/src/gui/shortcut/emoteshortcut.cpp b/src/gui/shortcut/emoteshortcut.cpp
index 0fcf4abaf..81b0e2b19 100644
--- a/src/gui/shortcut/emoteshortcut.cpp
+++ b/src/gui/shortcut/emoteshortcut.cpp
@@ -75,26 +75,24 @@ void EmoteShortcut::save() const
}
}
-void EmoteShortcut::useEmotePlayer(const int index) const
+void EmoteShortcut::useEmotePlayer(const size_t index) const
{
if (localPlayer == nullptr)
return;
- if (index > 0 &&
- index <= SHORTCUT_EMOTES)
+ if (index <= SHORTCUT_EMOTES)
{
if (mEmotes[index - 1] > 0)
localPlayer->emote(mEmotes[index - 1]);
}
}
-void EmoteShortcut::useEmote(const int index) const
+void EmoteShortcut::useEmote(const size_t index) const
{
if (localPlayer == nullptr)
return;
- if (index > 0 &&
- index <= SHORTCUT_EMOTES)
+ if (index <= SHORTCUT_EMOTES)
{
if (mEmotes[index - 1] > 0)
{
diff --git a/src/gui/shortcut/emoteshortcut.h b/src/gui/shortcut/emoteshortcut.h
index 14d68fbc6..282f12943 100644
--- a/src/gui/shortcut/emoteshortcut.h
+++ b/src/gui/shortcut/emoteshortcut.h
@@ -54,7 +54,7 @@ class EmoteShortcut final
*
* @param index Index of the shortcut Emote.
*/
- unsigned char getEmote(const int index) const A_WARN_UNUSED
+ unsigned char getEmote(const size_t index) const A_WARN_UNUSED
{ return mEmotes[index]; }
/**
@@ -74,7 +74,7 @@ class EmoteShortcut final
*
* @param index Index of the emotes.
*/
- void setEmote(const int index)
+ void setEmote(const size_t index)
{ mEmotes[index] = mEmoteSelected; }
/**
@@ -83,7 +83,8 @@ class EmoteShortcut final
* @param index Index of the emote.
* @param emoteId ID of the emote.
*/
- void setEmotes(const int index, const unsigned char emoteId)
+ void setEmotes(const size_t index,
+ const unsigned char emoteId)
{ mEmotes[index] = emoteId; }
/**
@@ -103,17 +104,17 @@ class EmoteShortcut final
/**
* Remove a Emote from the shortcut.
*/
- void removeEmote(const int index)
- { if (index >= 0 && index < SHORTCUT_EMOTES) mEmotes[index] = 0; }
+ void removeEmote(const size_t index)
+ { if (index < SHORTCUT_EMOTES) mEmotes[index] = 0; }
/**
* Try to use the Emote specified by the index.
*
* @param index Index of the emote shortcut.
*/
- void useEmote(const int index) const;
+ void useEmote(const size_t index) const;
- void useEmotePlayer(const int index) const;
+ void useEmotePlayer(const size_t index) const;
private:
/**
diff --git a/src/gui/shortcut/shortcutbase.cpp b/src/gui/shortcut/shortcutbase.cpp
index 8b7bf80c3..7bb11a8df 100644
--- a/src/gui/shortcut/shortcutbase.cpp
+++ b/src/gui/shortcut/shortcutbase.cpp
@@ -35,8 +35,8 @@ ShortcutBase::ShortcutBase(const std::string &itemName,
mItemColors(new ItemColor[maxSize]),
mItemName(itemName),
mColorName(colorName),
- mItemSelected(-1),
mMaxSize(maxSize),
+ mItemSelected(-1),
mItemColorSelected(ItemColor_one)
{
clear(false);
@@ -55,7 +55,7 @@ void ShortcutBase::load()
{
const Configuration *cfg = &serverConfig;
- for (int i = 0; i < mMaxSize; i++)
+ for (size_t i = 0; i < mMaxSize; i++)
{
const int itemId = cfg->getValue(mItemName + toString(i), -1);
const ItemColor itemColor = fromInt(
@@ -72,7 +72,7 @@ void ShortcutBase::load()
void ShortcutBase::save() const
{
- for (int i = 0; i < mMaxSize; i++)
+ for (size_t i = 0; i < mMaxSize; i++)
{
const int itemId = mItems[i] != 0 ? mItems[i] : -1;
const int itemColor = (mItemColors[i] != ItemColor_zero)
@@ -104,9 +104,9 @@ void ShortcutBase::setItemSelected(const Item *const item)
}
}
-void ShortcutBase::setItem(const int index)
+void ShortcutBase::setItem(const size_t index)
{
- if (index < 0 || index >= mMaxSize)
+ if (index >= mMaxSize)
return;
mItems[index] = mItemSelected;
@@ -116,7 +116,7 @@ void ShortcutBase::setItem(const int index)
void ShortcutBase::clear(const bool isSave)
{
- for (int i = 0; i < mMaxSize; i++)
+ for (size_t i = 0; i < mMaxSize; i++)
{
mItems[i] = -1;
mItemColors[i] = ItemColor_one;
diff --git a/src/gui/shortcut/shortcutbase.h b/src/gui/shortcut/shortcutbase.h
index 7fb656dbf..90ca41ee7 100644
--- a/src/gui/shortcut/shortcutbase.h
+++ b/src/gui/shortcut/shortcutbase.h
@@ -25,6 +25,8 @@
#include "enums/simpletypes/itemcolor.h"
+#include "utils/cast.h"
+
#include <string>
#include "localconsts.h"
@@ -66,17 +68,17 @@ class ShortcutBase notfinal
*
* @param index Index of the shortcut item.
*/
- int getItem(const int index) const A_WARN_UNUSED
+ int getItem(const size_t index) const A_WARN_UNUSED
{ return mItems[index]; }
- ItemColor getItemColor(const int index) const A_WARN_UNUSED
+ ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
{ return mItemColors[index]; }
/**
* Returns the amount of shortcut items.
*/
int getItemCount() const noexcept2 A_WARN_UNUSED
- { return mMaxSize; }
+ { return CAST_S32(mMaxSize); }
/**
* Returns the item ID that is currently selected.
@@ -89,7 +91,7 @@ class ShortcutBase notfinal
*
* @param index Index of the items.
*/
- void setItem(const int index);
+ void setItem(const size_t index);
/**
* Adds an item to the items store specified by the index.
@@ -97,7 +99,7 @@ class ShortcutBase notfinal
* @param index Index of the item.
* @param itemId ID of the item.
*/
- void setItems(const int index,
+ void setItems(const size_t index,
const int itemId,
const ItemColor color)
{ mItems[index] = itemId; mItemColors[index] = color; save(); }
@@ -121,7 +123,7 @@ class ShortcutBase notfinal
/**
* Remove a item from the shortcut.
*/
- void removeItem(const int index)
+ void removeItem(const size_t index)
{ mItems[index] = -1; save(); }
void clear(const bool isSave = true);
@@ -131,8 +133,8 @@ class ShortcutBase notfinal
ItemColor *mItemColors A_NONNULLPOINTER;
std::string mItemName;
std::string mColorName;
+ size_t mMaxSize;
int mItemSelected;
- int mMaxSize;
ItemColor mItemColorSelected;
};
diff --git a/src/gui/shortcut/spellshortcut.h b/src/gui/shortcut/spellshortcut.h
index 45fe6d252..4eab518a6 100644
--- a/src/gui/shortcut/spellshortcut.h
+++ b/src/gui/shortcut/spellshortcut.h
@@ -75,7 +75,7 @@ class SpellShortcut final
*
* @param index Index of the shortcut item.
*/
- int getItem(const int index) const
+ int getItem(const size_t index) const
{ return mItems[index]; }
private: