summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-29 14:30:20 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-29 14:30:20 +0300
commit0f9ec2061c4ad6157c3186f1cab9c4d8558980b5 (patch)
tree6259593b8436178ad8d981a96a8fd71eab9e04cc /src/gui/windows
parent01773c71a4698c6f01fe70d864f922bda65506cb (diff)
downloadplus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.gz
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.bz2
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.xz
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.zip
Add strong typed int type BeingId.
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/buydialog.cpp22
-rw-r--r--src/gui/windows/buydialog.h5
-rw-r--r--src/gui/windows/buyingstoreselldialog.cpp2
-rw-r--r--src/gui/windows/buyingstoreselldialog.h6
-rw-r--r--src/gui/windows/buyselldialog.cpp8
-rw-r--r--src/gui/windows/buyselldialog.h5
-rw-r--r--src/gui/windows/charcreatedialog.cpp4
-rw-r--r--src/gui/windows/charselectdialog.cpp2
-rw-r--r--src/gui/windows/charselectdialog.h2
-rw-r--r--src/gui/windows/npcdialog.cpp17
-rw-r--r--src/gui/windows/npcdialog.h12
-rw-r--r--src/gui/windows/npcselldialog.cpp2
-rw-r--r--src/gui/windows/npcselldialog.h6
13 files changed, 54 insertions, 39 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 63925ff28..a77eed240 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -179,7 +179,7 @@ BuyDialog::BuyDialog() :
mSortDropDown(nullptr),
mFilterTextField(new TextField(this, "", true, this, "namefilter", true)),
mFilterLabel(nullptr),
- mNpcId(Items),
+ mNpcId(fromInt(Items, BeingId)),
mMoney(0),
mAmountItems(0),
mMaxItems(0),
@@ -188,7 +188,7 @@ BuyDialog::BuyDialog() :
init();
}
-BuyDialog::BuyDialog(const int npcId) :
+BuyDialog::BuyDialog(const BeingId npcId) :
// TRANSLATORS: buy dialog name
Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
ActionListener(),
@@ -216,7 +216,7 @@ BuyDialog::BuyDialog(std::string nick) :
Modal_false, this, "sort")),
mFilterTextField(new TextField(this, "", true, this, "namefilter", true)),
mFilterLabel(nullptr),
- mNpcId(Nick),
+ mNpcId(fromInt(Nick, BeingId)),
mMoney(0),
mAmountItems(0),
mMaxItems(0),
@@ -271,7 +271,7 @@ void BuyDialog::init()
// You may change this symbol if your language uses another.
mDecreaseButton = new Button(this, _("-"), "dec", this);
// TRANSLATORS: buy dialog button
- mBuyButton = new Button(this, mNpcId == Items
+ mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId)
? _("Create") :_("Buy"), "buy", this);
// TRANSLATORS: buy dialog button
mQuitButton = new Button(this, _("Quit"), "quit", this);
@@ -406,7 +406,7 @@ void BuyDialog::sort()
void BuyDialog::close()
{
- switch (mNpcId)
+ switch (toInt(mNpcId, int))
{
case Nick:
case Items:
@@ -488,15 +488,15 @@ void BuyDialog::action(const ActionEvent &event)
else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
{
ShopItem *const item = mShopItems->at(selectedItem);
- if (mNpcId == Items)
+ if (mNpcId == fromInt(Items, BeingId))
{
adminHandler->createItems(item->getId(),
mAmountItems, item->getColor());
}
- else if (mNpcId != Nick)
+ else if (mNpcId != fromInt(Nick, BeingId))
{
#ifdef EATHENA_SUPPORT
- if (mNpcId == Market)
+ if (mNpcId == fromInt(Market, BeingId))
{
marketHandler->buyItem(item->getId(),
item->getType(),
@@ -505,7 +505,7 @@ void BuyDialog::action(const ActionEvent &event)
item->increaseQuantity(-mAmountItems);
item->update();
}
- else if (mNpcId == Cash)
+ else if (mNpcId == fromInt(Cash, BeingId))
{
cashShopHandler->buyItem(item->getPrice(),
item->getId(),
@@ -523,7 +523,7 @@ void BuyDialog::action(const ActionEvent &event)
updateSlider(selectedItem);
}
- else if (mNpcId == Nick)
+ else if (mNpcId == fromInt(Nick, BeingId))
{
#ifdef EATHENA_SUPPORT
if (serverFeatures->haveVending())
@@ -594,7 +594,7 @@ void BuyDialog::updateButtonsAndLabels()
const int itemPrice = item->getPrice();
// Calculate how many the player can afford
- if (mNpcId == Items)
+ if (mNpcId == fromInt(Items, BeingId))
mMaxItems = 100;
else if (itemPrice)
mMaxItems = mMoney / itemPrice;
diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h
index 8dea72886..bef09083e 100644
--- a/src/gui/windows/buydialog.h
+++ b/src/gui/windows/buydialog.h
@@ -23,6 +23,7 @@
#ifndef GUI_WINDOWS_BUYDIALOG_H
#define GUI_WINDOWS_BUYDIALOG_H
+#include "enums/simpletypes/beingid.h"
#include "enums/simpletypes/visible.h"
#include "gui/widgets/window.h"
@@ -64,7 +65,7 @@ class BuyDialog final : public Window,
*
* @see Window::Window
*/
- explicit BuyDialog(const int npcId);
+ explicit BuyDialog(const BeingId npcId);
/**
* Constructor.
@@ -175,7 +176,7 @@ class BuyDialog final : public Window,
TextField *mFilterTextField;
Label *mFilterLabel;
- int mNpcId;
+ BeingId mNpcId;
int mMoney;
int mAmountItems;
int mMaxItems;
diff --git a/src/gui/windows/buyingstoreselldialog.cpp b/src/gui/windows/buyingstoreselldialog.cpp
index 29b24f638..f99251eb0 100644
--- a/src/gui/windows/buyingstoreselldialog.cpp
+++ b/src/gui/windows/buyingstoreselldialog.cpp
@@ -37,7 +37,7 @@
#include "debug.h"
-BuyingStoreSellDialog::BuyingStoreSellDialog(const int accountId,
+BuyingStoreSellDialog::BuyingStoreSellDialog(const BeingId accountId,
const int storeId) :
SellDialog(true),
mAccountId(accountId),
diff --git a/src/gui/windows/buyingstoreselldialog.h b/src/gui/windows/buyingstoreselldialog.h
index 9fb40cba0..ce5c404e4 100644
--- a/src/gui/windows/buyingstoreselldialog.h
+++ b/src/gui/windows/buyingstoreselldialog.h
@@ -25,6 +25,8 @@
#ifdef EATHENA_SUPPORT
+#include "enums/simpletypes/beingid.h"
+
#include "gui/widgets/selldialog.h"
class Being;
@@ -42,7 +44,7 @@ class BuyingStoreSellDialog final : public SellDialog
*
* @see Window::Window
*/
- BuyingStoreSellDialog(const int accountId,
+ BuyingStoreSellDialog(const BeingId accountId,
const int storeId);
A_DELETE_COPY(BuyingStoreSellDialog)
@@ -50,7 +52,7 @@ class BuyingStoreSellDialog final : public SellDialog
protected:
void sellAction(const ActionEvent &event) override final;
- int mAccountId;
+ BeingId mAccountId;
int mStoreId;
};
diff --git a/src/gui/windows/buyselldialog.cpp b/src/gui/windows/buyselldialog.cpp
index 15d4165f3..bdd28b000 100644
--- a/src/gui/windows/buyselldialog.cpp
+++ b/src/gui/windows/buyselldialog.cpp
@@ -35,7 +35,7 @@
BuySellDialog::DialogList BuySellDialog::dialogInstances;
-BuySellDialog::BuySellDialog(const int npcId) :
+BuySellDialog::BuySellDialog(const BeingId npcId) :
// TRANSLATORS: shop window name
Window(_("Shop"), Modal_false, nullptr, "buysell.xml"),
ActionListener(),
@@ -50,7 +50,7 @@ BuySellDialog::BuySellDialog(const std::string &nick) :
// TRANSLATORS: shop window name
Window(_("Shop"), Modal_false, nullptr, "buysell.xml"),
ActionListener(),
- mNpcId(-1),
+ mNpcId(BeingId_negOne),
mNick(nick),
mBuyButton(nullptr)
{
@@ -128,14 +128,14 @@ void BuySellDialog::action(const ActionEvent &event)
const std::string &eventId = event.getId();
if (eventId == "Buy")
{
- if (mNpcId != -1)
+ if (mNpcId != BeingId_negOne)
npcHandler->buy(mNpcId);
else
buySellHandler->requestSellList(mNick);
}
else if (eventId == "Sell")
{
- if (mNpcId != -1)
+ if (mNpcId != BeingId_negOne)
npcHandler->sell(mNpcId);
else
buySellHandler->requestBuyList(mNick);
diff --git a/src/gui/windows/buyselldialog.h b/src/gui/windows/buyselldialog.h
index 573435846..dc7435126 100644
--- a/src/gui/windows/buyselldialog.h
+++ b/src/gui/windows/buyselldialog.h
@@ -23,6 +23,7 @@
#ifndef GUI_WINDOWS_BUYSELLDIALOG_H
#define GUI_WINDOWS_BUYSELLDIALOG_H
+#include "enums/simpletypes/beingid.h"
#include "enums/simpletypes/visible.h"
#include "gui/widgets/window.h"
@@ -46,7 +47,7 @@ class BuySellDialog final : public Window,
*
* @see Window::Window
*/
- explicit BuySellDialog(const int npcId);
+ explicit BuySellDialog(const BeingId npcId);
explicit BuySellDialog(const std::string &nick);
@@ -78,7 +79,7 @@ class BuySellDialog final : public Window,
typedef std::list<BuySellDialog*> DialogList;
static DialogList dialogInstances;
- int mNpcId;
+ BeingId mNpcId;
std::string mNick;
Button *mBuyButton;
};
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index 6ada41158..917cc51fb 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -122,7 +122,9 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
mCreateButton(new Button(this, _("Create"), "create", this)),
// TRANSLATORS: char create dialog button
mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mPlayer(new Being(0, ActorType::Player, static_cast<uint16_t>(0U),
+ mPlayer(new Being(BeingId_zero,
+ ActorType::Player,
+ static_cast<uint16_t>(0U),
nullptr)),
mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
"charcreate_selectedplayerbox.xml")),
diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp
index 5663ab387..bb4eae95e 100644
--- a/src/gui/windows/charselectdialog.cpp
+++ b/src/gui/windows/charselectdialog.cpp
@@ -634,7 +634,7 @@ void CharSelectDialog::updateState()
}
}
-void CharSelectDialog::setName(const int id, const std::string &newName)
+void CharSelectDialog::setName(const BeingId id, const std::string &newName)
{
for (unsigned int i = 0, sz = static_cast<unsigned int>(
mCharacterEntries.size()); i < sz; ++i)
diff --git a/src/gui/windows/charselectdialog.h b/src/gui/windows/charselectdialog.h
index 9e9871c5a..53d41facb 100644
--- a/src/gui/windows/charselectdialog.h
+++ b/src/gui/windows/charselectdialog.h
@@ -89,7 +89,7 @@ class CharSelectDialog final : public Window,
void postInit() override final;
- void setName(const int id, const std::string &newName);
+ void setName(const BeingId id, const std::string &newName);
private:
void attemptCharacterDelete(const int index,
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 2c7c27f57..c8ccd482e 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -81,7 +81,7 @@ NpcDialogs NpcDialog::mNpcDialogs;
typedef std::vector<Image *>::iterator ImageVectorIter;
-NpcDialog::NpcDialog(const int npcId) :
+NpcDialog::NpcDialog(const BeingId npcId) :
// TRANSLATORS: npc dialog name
Window(_("NPC"), Modal_false, nullptr, "npc.xml"),
ActionListener(),
@@ -204,7 +204,8 @@ void NpcDialog::postInit()
const Being *const being = actorManager->findBeing(mNpcId);
if (being)
{
- showAvatar(NPCDB::getAvatarFor(being->getSubType()));
+ showAvatar(NPCDB::getAvatarFor(fromInt(
+ being->getSubType(), BeingId)));
setCaption(being->getName());
}
}
@@ -861,13 +862,16 @@ void NpcDialog::restoreCamera()
mCameraMode = -1;
}
-void NpcDialog::showAvatar(const uint16_t avatarId)
+void NpcDialog::showAvatar(const BeingId avatarId)
{
- const bool needShow = (avatarId != 0);
+ const bool needShow = (avatarId != BeingId_zero);
if (needShow)
{
delete mAvatarBeing;
- mAvatarBeing = new Being(0, ActorType::Avatar, avatarId, nullptr);
+ mAvatarBeing = new Being(BeingId_zero,
+ ActorType::Avatar,
+ toInt(avatarId, uint16_t),
+ nullptr);
mPlayerBox->setPlayer(mAvatarBeing);
if (!mAvatarBeing->empty())
{
@@ -973,7 +977,8 @@ void NpcDialog::mousePressed(MouseEvent &event)
}
}
-void NpcDialog::copyToClipboard(const int npcId, const int x, const int y)
+void NpcDialog::copyToClipboard(const BeingId npcId,
+ const int x, const int y)
{
NpcDialogs::iterator it = mNpcDialogs.find(npcId);
if (it != mNpcDialogs.end())
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index 0ed4096e8..378bbd5e9 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -23,6 +23,7 @@
#ifndef GUI_WINDOWS_NPCDIALOG_H
#define GUI_WINDOWS_NPCDIALOG_H
+#include "enums/simpletypes/beingid.h"
#include "enums/simpletypes/visible.h"
#include "gui/models/extendedlistmodel.h"
@@ -44,7 +45,7 @@ class PlayerBox;
class ScrollArea;
class TextField;
-typedef std::map<int, NpcDialog*> NpcDialogs;
+typedef std::map<BeingId, NpcDialog*> NpcDialogs;
/**
* The npc dialog.
@@ -62,7 +63,7 @@ class NpcDialog final : public Window,
*
* @see Window::Window
*/
- explicit NpcDialog(const int npcId);
+ explicit NpcDialog(const BeingId npcId);
A_DELETE_COPY(NpcDialog)
@@ -196,7 +197,7 @@ class NpcDialog final : public Window,
void refocus();
- void showAvatar(const uint16_t avatarId);
+ void showAvatar(const BeingId avatarId);
void setAvatarDirection(const uint8_t direction);
@@ -211,7 +212,8 @@ class NpcDialog final : public Window,
int isCloseState() const
{ return mActionState == NPC_ACTION_CLOSE; }
- static void copyToClipboard(const int npcId, const int x, const int y);
+ static void copyToClipboard(const BeingId npcId,
+ const int x, const int y);
static NpcDialogs mNpcDialogs;
@@ -233,7 +235,7 @@ class NpcDialog final : public Window,
void placeItemInputControls();
- int mNpcId;
+ BeingId mNpcId;
int mDefaultInt;
std::string mDefaultString;
diff --git a/src/gui/windows/npcselldialog.cpp b/src/gui/windows/npcselldialog.cpp
index 683593deb..c1fdbe259 100644
--- a/src/gui/windows/npcselldialog.cpp
+++ b/src/gui/windows/npcselldialog.cpp
@@ -41,7 +41,7 @@
#include "debug.h"
-NpcSellDialog::NpcSellDialog(const int npcId) :
+NpcSellDialog::NpcSellDialog(const BeingId npcId) :
SellDialog(true),
mNpcId(npcId)
{
diff --git a/src/gui/windows/npcselldialog.h b/src/gui/windows/npcselldialog.h
index 1932ddf42..af611f8f1 100644
--- a/src/gui/windows/npcselldialog.h
+++ b/src/gui/windows/npcselldialog.h
@@ -23,6 +23,8 @@
#ifndef GUI_WINDOWS_NPCSELLDIALOG_H
#define GUI_WINDOWS_NPCSELLDIALOG_H
+#include "enums/simpletypes/beingid.h"
+
#include "gui/widgets/selldialog.h"
/**
@@ -38,7 +40,7 @@ class NpcSellDialog final : public SellDialog
*
* @see Window::Window
*/
- explicit NpcSellDialog(const int npcId);
+ explicit NpcSellDialog(const BeingId npcId);
A_DELETE_COPY(NpcSellDialog)
@@ -47,7 +49,7 @@ class NpcSellDialog final : public SellDialog
protected:
void sellAction(const ActionEvent &event) override final;
- int mNpcId;
+ BeingId mNpcId;
};
#endif // GUI_WINDOWS_NPCSELLDIALOG_H