summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-10 23:29:40 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-10 23:29:40 +0300
commit356d04e46ea5f4ddd8545f61e598a25dc611a609 (patch)
tree18a6c6c715b8e32c5a4b1b34d8c278a05ec451ac
parent02374ec05756cc7d60220fa43da8eb5ba60a274d (diff)
downloadManaVerse-356d04e46ea5f4ddd8545f61e598a25dc611a609.tar.gz
ManaVerse-356d04e46ea5f4ddd8545f61e598a25dc611a609.tar.bz2
ManaVerse-356d04e46ea5f4ddd8545f61e598a25dc611a609.tar.xz
ManaVerse-356d04e46ea5f4ddd8545f61e598a25dc611a609.zip
In DropShortcut use ShortcutBase.
-rw-r--r--src/dropshortcut.cpp82
-rw-r--r--src/dropshortcut.h102
2 files changed, 6 insertions, 178 deletions
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp
index 1972f037d..5f9492b7b 100644
--- a/src/dropshortcut.cpp
+++ b/src/dropshortcut.cpp
@@ -34,11 +34,12 @@
#include "debug.h"
+static const int DROP_SHORTCUT_ITEMS = 16;
+
DropShortcut *dropShortcut = nullptr;
DropShortcut::DropShortcut() :
- mItemSelected(-1),
- mItemColorSelected(1),
+ ShortcutBase("drop", "dropColor", DROP_SHORTCUT_ITEMS),
mLastDropIndex(0)
{
clear(false);
@@ -47,48 +48,6 @@ DropShortcut::DropShortcut() :
DropShortcut::~DropShortcut()
{
-// save();
-}
-
-void DropShortcut::load(const bool oldConfig)
-{
- const Configuration *cfg;
- if (oldConfig)
- cfg = &config;
- else
- cfg = &serverConfig;
-
- for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
- {
- const int itemId = cfg->getValue("drop" + toString(i), -1);
- const unsigned char itemColor = static_cast<const unsigned char>(
- cfg->getValue("dropColor" + toString(i), -1));
-
- if (itemId != -1)
- {
- mItems[i] = itemId;
- mItemColors[i] = itemColor;
- }
- }
-}
-
-void DropShortcut::save() const
-{
- for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
- {
- const int itemId = mItems[i] ? mItems[i] : -1;
- const int itemColor = mItemColors[i] ? mItemColors[i] : 1;
- if (itemId != -1)
- {
- serverConfig.setValue("drop" + toString(i), itemId);
- serverConfig.setValue("dropColor" + toString(i), itemColor);
- }
- else
- {
- serverConfig.deleteKey("drop" + toString(i));
- serverConfig.deleteKey("dropColor" + toString(i));
- }
- }
}
void DropShortcut::dropFirst() const
@@ -206,38 +165,3 @@ bool DropShortcut::dropItem(const int cnt)
}
return false;
}
-
-void DropShortcut::setItemSelected(const Item *const item)
-{
- if (item)
- {
- mItemSelected = item->getId();
- mItemColorSelected = item->getColor();
- }
- else
- {
- mItemSelected = -1;
- mItemColorSelected = 1;
- }
-}
-
-void DropShortcut::setItem(const int index)
-{
- if (index < 0 || index >= DROP_SHORTCUT_ITEMS)
- return;
-
- mItems[index] = mItemSelected;
- mItemColors[index] = mItemColorSelected;
- save();
-}
-
-void DropShortcut::clear(const bool isSave)
-{
- for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
- {
- mItems[i] = -1;
- mItemColors[i] = 1;
- }
- if (isSave)
- save();
-}
diff --git a/src/dropshortcut.h b/src/dropshortcut.h
index 85c0b6620..5b2080b7f 100644
--- a/src/dropshortcut.h
+++ b/src/dropshortcut.h
@@ -23,16 +23,16 @@
#ifndef DROPSHORTCUT_H
#define DROPSHORTCUT_H
-#include "localconsts.h"
+#include "shortcutbase.h"
-static const int DROP_SHORTCUT_ITEMS = 16;
+#include "localconsts.h"
class Item;
/**
* The class which keeps track of the item shortcuts.
*/
-class DropShortcut final
+class DropShortcut final : public ShortcutBase
{
public:
/**
@@ -48,95 +48,6 @@ class DropShortcut final
~DropShortcut();
/**
- * Load the configuration information.
- */
- void load(const bool oldConfig = false);
-
- /**
- * Save the configuration information.
- */
- void save() const;
-
- /**
- * Returns the shortcut item ID specified by the index.
- *
- * @param index Index of the shortcut item.
- */
- int getItem(const int index) const A_WARN_UNUSED
- { return mItems[index]; }
-
- unsigned char getItemColor(const int index) const A_WARN_UNUSED
- { return mItemColors[index]; }
-
- /**
- * Returns the amount of shortcut items.
- */
- static int getItemCount() A_WARN_UNUSED
- { return DROP_SHORTCUT_ITEMS; }
-
- /**
- * Returns the item ID that is currently selected.
- */
- int getItemSelected() const A_WARN_UNUSED
- { return mItemSelected; }
-
- /**
- * Adds the selected item ID to the items specified by the index.
- *
- * @param index Index of the items.
- */
- void setItem(const int index);
-
- /**
- * Adds an item to the items store specified by the index.
- *
- * @param index Index of the item.
- * @param itemId ID of the item.
- */
- void setItems(const int index, const int itemId,
- const unsigned char color)
- { mItems[index] = itemId; mItemColors[index] = color; save(); }
-
- /**
- * Set the item that is selected.
- *
- * @param itemId The ID of the item that is to be assigned.
- */
- void setItemSelected(const int itemId)
- { mItemSelected = itemId; }
-
- void setItemSelected(const Item *const item);
-
- /**
- * A flag to check if the item is selected.
- */
- bool isItemSelected() const A_WARN_UNUSED
- { return mItemSelected > -1; }
-
- /**
- * Remove a item from the shortcut.
- */
- void removeItem(const int index)
- { mItems[index] = -1; save(); }
-
- /**
- * Try to use the item specified by the index.
- *
- * @param index Index of the item shortcut.
- */
- void useItem(int index);
-
- /**
- * Equip a item from the shortcut.
- */
- void equipItem(int index);
-
- /**
- * UnEquip a item from the shortcut.
- */
- void unequipItem(int index);
-
- /**
* Drop first item.
*/
void dropFirst() const;
@@ -146,19 +57,12 @@ class DropShortcut final
*/
void dropItems(const int cnt = 1);
- void clear(const bool isSave = true);
-
private:
/**
* Drop item in cicle.
*/
bool dropItem(const int cnt = 1);
- int mItems[DROP_SHORTCUT_ITEMS];
- unsigned char mItemColors[DROP_SHORTCUT_ITEMS];
- int mItemSelected;
- unsigned char mItemColorSelected;
-
int mLastDropIndex;
};