summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-26 21:29:59 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-26 21:29:59 +0300
commita33a8dc48761d7cb2b4c1c468e1e3b188bcbf709 (patch)
tree1b1e98a615e2c03641c99b66cb4667b56f7087c3 /src/gui
parent012a10fd8153f3ddb775dde1e4dba4456f2aa9de (diff)
downloadmanaverse-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.gz
manaverse-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.bz2
manaverse-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.xz
manaverse-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.zip
Add const to some classes.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/beingpopup.cpp2
-rw-r--r--src/gui/beingpopup.h2
-rw-r--r--src/gui/buydialog.cpp17
-rw-r--r--src/gui/buydialog.h7
-rw-r--r--src/gui/buyselldialog.cpp7
-rw-r--r--src/gui/buyselldialog.h2
-rw-r--r--src/gui/changepassworddialog.cpp14
-rw-r--r--src/gui/changepassworddialog.h2
-rw-r--r--src/gui/charcreatedialog.cpp32
-rw-r--r--src/gui/charcreatedialog.h9
-rw-r--r--src/gui/charselectdialog.cpp54
-rw-r--r--src/gui/charselectdialog.h15
12 files changed, 89 insertions, 74 deletions
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp
index 89bc1e084..19c2e0d03 100644
--- a/src/gui/beingpopup.cpp
+++ b/src/gui/beingpopup.cpp
@@ -74,7 +74,7 @@ BeingPopup::~BeingPopup()
{
}
-void BeingPopup::show(int x, int y, Being *b)
+void BeingPopup::show(const int x, const int y, Being *const b)
{
if (!b)
{
diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h
index a029f739a..f58921cf2 100644
--- a/src/gui/beingpopup.h
+++ b/src/gui/beingpopup.h
@@ -46,7 +46,7 @@ class BeingPopup : public Popup
/**
* Sets the info to be displayed given a particular player.
*/
- void show(int x, int y, Being *b);
+ void show(const int x, const int y, Being *const b);
// TODO: Add a version for monsters, NPCs, etc?
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index 2cb24bb13..ffbe042e5 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -50,7 +50,7 @@
BuyDialog::DialogList BuyDialog::instances;
-BuyDialog::BuyDialog(int npcId):
+BuyDialog::BuyDialog(const int npcId):
Window(_("Buy"), false, nullptr, "buy.xml"),
mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), mNick("")
{
@@ -154,7 +154,7 @@ BuyDialog::~BuyDialog()
instances.remove(this);
}
-void BuyDialog::setMoney(int amount)
+void BuyDialog::setMoney(const int amount)
{
mMoney = amount;
mShopItemList->setPlayersMoney(amount);
@@ -174,7 +174,8 @@ void BuyDialog::reset()
setMoney(0);
}
-void BuyDialog::addItem(int id, unsigned char color, int amount, int price)
+void BuyDialog::addItem(const int id, const unsigned char color,
+ const int amount, const int price)
{
mShopItems->addItem(id, color, amount, price);
mShopItemList->adjustSize();
@@ -188,7 +189,7 @@ void BuyDialog::action(const gcn::ActionEvent &event)
return;
}
- int selectedItem = mShopItemList->getSelected();
+ const int selectedItem = mShopItemList->getSelected();
// The following actions require a valid selection
if (selectedItem < 0 ||
@@ -238,7 +239,7 @@ void BuyDialog::action(const gcn::ActionEvent &event)
{
if (mNpcId != -1)
{
- ShopItem *item = mShopItems->at(selectedItem);
+ const ShopItem *const item = mShopItems->at(selectedItem);
Net::getNpcHandler()->buyItem(mNpcId, item->getId(),
item->getColor(), mAmountItems);
@@ -254,7 +255,7 @@ void BuyDialog::action(const gcn::ActionEvent &event)
}
else if (tradeWindow)
{
- ShopItem *item = mShopItems->at(selectedItem);
+ const ShopItem *const item = mShopItems->at(selectedItem);
if (item)
{
Net::getBuySellHandler()->sendBuyRequest(mNick,
@@ -289,10 +290,10 @@ void BuyDialog::updateButtonsAndLabels()
if (selectedItem > -1)
{
- ShopItem * item = mShopItems->at(selectedItem);
+ const ShopItem *const item = mShopItems->at(selectedItem);
if (item)
{
- int itemPrice = item->getPrice();
+ const int itemPrice = item->getPrice();
// Calculate how many the player can afford
if (itemPrice)
diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h
index ea449e06e..50d8a4d0b 100644
--- a/src/gui/buydialog.h
+++ b/src/gui/buydialog.h
@@ -55,7 +55,7 @@ class BuyDialog : public Window, public gcn::ActionListener,
*
* @see Window::Window
*/
- BuyDialog(int npcId);
+ BuyDialog(const int npcId);
/**
* Constructor.
@@ -77,12 +77,13 @@ class BuyDialog : public Window, public gcn::ActionListener,
/**
* Sets the amount of available money.
*/
- void setMoney(int amount);
+ void setMoney(const int amount);
/**
* Adds an item to the shop inventory.
*/
- void addItem(int id, unsigned char color, int amount, int price);
+ void addItem(const int id, const unsigned char color,
+ const int amount, const int price);
/**
* Called when receiving actions from the widgets.
diff --git a/src/gui/buyselldialog.cpp b/src/gui/buyselldialog.cpp
index cdcf90be9..7fff70fc0 100644
--- a/src/gui/buyselldialog.cpp
+++ b/src/gui/buyselldialog.cpp
@@ -34,7 +34,7 @@
BuySellDialog::DialogList BuySellDialog::instances;
-BuySellDialog::BuySellDialog(int npcId):
+BuySellDialog::BuySellDialog(const int npcId):
Window(_("Shop"), false, nullptr, "buysell.xml"),
mNpcId(npcId),
mNick(""),
@@ -63,11 +63,12 @@ void BuySellDialog::init()
N_("Buy"), N_("Sell"), N_("Cancel"), nullptr
};
const int buttonPadding = getOption("buttonpadding", 10);
- int x = buttonPadding, y = buttonPadding;
+ int x = buttonPadding;
+ const int y = buttonPadding;
for (const char **curBtn = buttonNames; *curBtn; curBtn++)
{
- Button *btn = new Button(gettext(*curBtn), *curBtn, this);
+ Button *const btn = new Button(gettext(*curBtn), *curBtn, this);
if (!mBuyButton)
mBuyButton = btn; // For focus request
btn->setPosition(x, y);
diff --git a/src/gui/buyselldialog.h b/src/gui/buyselldialog.h
index 9636f4e0a..dfc59415e 100644
--- a/src/gui/buyselldialog.h
+++ b/src/gui/buyselldialog.h
@@ -46,7 +46,7 @@ class BuySellDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- BuySellDialog(int npcId);
+ BuySellDialog(const int npcId);
BuySellDialog(std::string nick);
diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp
index 5751efba4..0d38bab4e 100644
--- a/src/gui/changepassworddialog.cpp
+++ b/src/gui/changepassworddialog.cpp
@@ -44,13 +44,13 @@
#include "debug.h"
-ChangePasswordDialog::ChangePasswordDialog(LoginData *data):
+ChangePasswordDialog::ChangePasswordDialog(LoginData *const data):
Window(_("Change Password"), true, nullptr, "changepassword.xml"),
mWrongDataNoticeListener(new WrongDataNoticeListener),
mLoginData(data)
{
- gcn::Label *accountLabel = new Label(
- strprintf(_("Account: %s"), mLoginData->username.c_str()));
+ gcn::Label *const accountLabel = new Label(
+ strprintf(_("Account: %s"), mLoginData->username.c_str()));
mOldPassField = new PasswordField;
mFirstPassField = new PasswordField;
mSecondPassField = new PasswordField;
@@ -102,8 +102,10 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event)
std::stringstream errorMsg;
int error = 0;
- unsigned int min = Net::getLoginHandler()->getMinPasswordLength();
- unsigned int max = Net::getLoginHandler()->getMaxPasswordLength();
+ const unsigned int min = Net::getLoginHandler()
+ ->getMinPasswordLength();
+ const unsigned int max = Net::getLoginHandler()
+ ->getMaxPasswordLength();
// Check old Password
if (oldPassword.empty())
@@ -142,7 +144,7 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event)
else if (error == 3)
mWrongDataNoticeListener->setTarget(this->mSecondPassField);
- OkDialog *dlg = new OkDialog(_("Error"),
+ OkDialog *const dlg = new OkDialog(_("Error"),
errorMsg.str(), DIALOG_ERROR);
dlg->addActionListener(mWrongDataNoticeListener);
}
diff --git a/src/gui/changepassworddialog.h b/src/gui/changepassworddialog.h
index a548638a4..e6cb18c7e 100644
--- a/src/gui/changepassworddialog.h
+++ b/src/gui/changepassworddialog.h
@@ -50,7 +50,7 @@ class ChangePasswordDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- ChangePasswordDialog(LoginData *data);
+ ChangePasswordDialog(LoginData *const data);
/**
* Destructor
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index ba2e06661..4c553f5e1 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -64,7 +64,8 @@ static const uint8_t directions[] =
Being::DOWN, Being::RIGHT, Being::UP, Being::LEFT
};
-CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
+CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
+ const int slot) :
Window(_("New Character"), true, parent, "charcreate.xml"),
mCharSelectDialog(parent),
mRace(0),
@@ -152,8 +153,8 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mAttributesLeft = new Label(
strprintf(_("Please distribute %d points"), 99));
- int w = 480;
- int h = 350;
+ const int w = 480;
+ const int h = 350;
setContentSize(w, h);
mPlayerBox->setDimension(gcn::Rectangle(350, 40, 110, 90));
mActionButton->setPosition(375, 140);
@@ -163,10 +164,10 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mNameField->setDimension(
gcn::Rectangle(60, 10, 300, mNameField->getHeight()));
- int leftX = 120;
- int rightX = 300;
- int labelX = 5;
- int nameX = 145;
+ const int leftX = 120;
+ const int rightX = 300;
+ const int labelX = 5;
+ const int nameX = 145;
mPrevHairColorButton->setPosition(leftX, 40);
mNextHairColorButton->setPosition(rightX, 40);
mHairColorLabel->setPosition(labelX, 45);
@@ -270,11 +271,13 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
mAttributeSlider[i]->getValue()));
}
- int characterSlot = mSlot;
#ifdef MANASERV_SUPPORT
+ int characterSlot = mSlot;
// On Manaserv, the slots start at 1, so we offset them.
if (Net::getNetworkType() == ServerInfo::MANASERV)
++characterSlot;
+#else
+ const int characterSlot = mSlot;
#endif
Net::getCharHandler()->newCharacter(getName(), characterSlot,
@@ -367,7 +370,7 @@ void CharCreateDialog::updateSliders()
}
// Update distributed points
- int pointsLeft = mMaxPoints - getDistributedPoints();
+ const int pointsLeft = mMaxPoints - getDistributedPoints();
if (pointsLeft == 0)
{
mAttributesLeft->setCaption(_("Character stats OK"));
@@ -406,7 +409,8 @@ int CharCreateDialog::getDistributedPoints() const
}
void CharCreateDialog::setAttributes(const StringVect &labels,
- int available, int min, int max)
+ const int available,
+ const int min, const int max)
{
mMaxPoints = available;
@@ -427,8 +431,8 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
mAttributeSlider.resize(labels.size());
mAttributeValue.resize(labels.size());
- int w = 480;
- int h = 350;
+ const int w = 480;
+ const int h = 350;
for (unsigned i = 0, sz = static_cast<unsigned>(labels.size());
i < sz; i++)
@@ -462,7 +466,7 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
h - 5 - mCancelButton->getHeight());
}
-void CharCreateDialog::setFixedGender(bool fixed, Gender gender)
+void CharCreateDialog::setFixedGender(const bool fixed, const Gender gender)
{
if (gender == GENDER_FEMALE)
{
@@ -564,7 +568,7 @@ void CharCreateDialog::updatePlayer()
void CharCreateDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
- int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
index c0c1f113a..048363452 100644
--- a/src/gui/charcreatedialog.h
+++ b/src/gui/charcreatedialog.h
@@ -54,7 +54,7 @@ class CharCreateDialog : public Window,
/**
* Constructor.
*/
- CharCreateDialog(CharSelectDialog *parent, int slot);
+ CharCreateDialog(CharSelectDialog *const parent, const int slot);
/**
* Destructor.
@@ -69,10 +69,11 @@ class CharCreateDialog : public Window,
void unlock();
void setAttributes(const StringVect &labels,
- int available,
- int min, int max);
+ const int available,
+ const int min, const int max);
- void setFixedGender(bool fixed, Gender gender = GENDER_FEMALE);
+ void setFixedGender(const bool fixed,
+ const Gender gender = GENDER_FEMALE);
void logic();
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 146e4f290..a22ff6a28 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -94,21 +94,21 @@ class CharDeleteConfirm : public ConfirmDialog
class CharacterDisplay : public Container
{
public:
- CharacterDisplay(CharSelectDialog *charSelectDialog);
+ CharacterDisplay(CharSelectDialog *const charSelectDialog);
- void setCharacter(Net::Character *character);
+ void setCharacter(Net::Character *const character);
Net::Character *getCharacter() const
{ return mCharacter; }
void requestFocus();
- void setActive(bool active);
+ void setActive(const bool active);
- bool isSelectFocused()
+ bool isSelectFocused() const
{ return mButton->isFocused(); }
- bool isDeleteFocused()
+ bool isDeleteFocused() const
{ return mDelete->isFocused(); }
void focusSelect()
@@ -130,7 +130,7 @@ class CharacterDisplay : public Container
Button *mDelete;
};
-CharSelectDialog::CharSelectDialog(LoginData *data):
+CharSelectDialog::CharSelectDialog(LoginData *const data):
Window(_("Account and Character Management"), false, nullptr, "char.xml"),
mLocked(false),
mUnregisterButton(nullptr),
@@ -149,7 +149,8 @@ CharSelectDialog::CharSelectDialog(LoginData *data):
mChangePasswordButton = new Button(_("Change Password"), "change_password",
this);
- int optionalActions = Net::getLoginHandler()->supportedOptionalActions();
+ const int optionalActions = Net::getLoginHandler()
+ ->supportedOptionalActions();
ContainerPlacer placer;
placer = getPlacer(0, 0);
@@ -203,7 +204,7 @@ CharSelectDialog::~CharSelectDialog()
void CharSelectDialog::action(const gcn::ActionEvent &event)
{
// Check if a button of a character was pressed
- const gcn::Widget *sourceParent = event.getSource()->getParent();
+ const gcn::Widget *const sourceParent = event.getSource()->getParent();
int selected = -1;
for (unsigned int i = 0, sz = static_cast<unsigned int>(
mCharacterEntries.size()); i < sz; ++i)
@@ -227,8 +228,8 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
!mCharacterEntries[selected]->getCharacter())
{
// Start new character dialog
- CharCreateDialog *charCreateDialog =
- new CharCreateDialog(this, selected);
+ CharCreateDialog *const charCreateDialog =
+ new CharCreateDialog(this, selected);
mCharHandler->setCharCreateDialog(charCreateDialog);
}
else if (eventId == "delete"
@@ -271,7 +272,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
- int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
@@ -400,11 +401,11 @@ bool CharSelectDialog::getFocusedContainer(int &container, int &idx)
return false;
}
-void CharSelectDialog::setFocusedContainer(int i, int button)
+void CharSelectDialog::setFocusedContainer(const int i, const int button)
{
if (i >= 0 && i < static_cast<int>(mLoginData->characterSlots))
{
- CharacterDisplay *container = mCharacterEntries[i];
+ CharacterDisplay *const container = mCharacterEntries[i];
if (button)
container->focusDelete();
else
@@ -415,7 +416,7 @@ void CharSelectDialog::setFocusedContainer(int i, int button)
/**
* Communicate character deletion to the server.
*/
-void CharSelectDialog::attemptCharacterDelete(int index)
+void CharSelectDialog::attemptCharacterDelete(const int index)
{
if (mLocked)
return;
@@ -424,7 +425,7 @@ void CharSelectDialog::attemptCharacterDelete(int index)
lock();
}
-void CharSelectDialog::askPasswordForDeletion(int index)
+void CharSelectDialog::askPasswordForDeletion(const int index)
{
mDeleteIndex = index;
mDeleteDialog = new TextDialog(
@@ -437,7 +438,7 @@ void CharSelectDialog::askPasswordForDeletion(int index)
/**
* Communicate character selection to the server.
*/
-void CharSelectDialog::attemptCharacterSelect(int index)
+void CharSelectDialog::attemptCharacterSelect(const int index)
{
if (mLocked || !mCharacterEntries[index])
return;
@@ -467,13 +468,15 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters)
if (!*i)
continue;
- Net::Character *character = *i;
+ Net::Character *const character = *i;
// Slots Number start at 1 for Manaserv, so we offset them by one.
- int characterSlot = character->slot;
#ifdef MANASERV_SUPPORT
+ int characterSlot = character->slot;
if (Net::getNetworkType() == ServerInfo::MANASERV && characterSlot > 0)
--characterSlot;
+#else
+ const int characterSlot = character->slot;
#endif
if (characterSlot >= static_cast<int>(mCharacterEntries.size()))
@@ -497,7 +500,7 @@ void CharSelectDialog::unlock()
setLocked(false);
}
-void CharSelectDialog::setLocked(bool locked)
+void CharSelectDialog::setLocked(const bool locked)
{
mLocked = locked;
@@ -518,7 +521,7 @@ void CharSelectDialog::setLocked(bool locked)
}
bool CharSelectDialog::selectByName(const std::string &name,
- SelectAction selAction)
+ const SelectAction selAction)
{
if (mLocked)
return false;
@@ -527,7 +530,8 @@ bool CharSelectDialog::selectByName(const std::string &name,
{
if (mCharacterEntries[i])
{
- Net::Character *character = mCharacterEntries[i]->getCharacter();
+ const Net::Character *const character
+ = mCharacterEntries[i]->getCharacter();
if (character)
{
if (character->dummy && character->dummy->getName() == name)
@@ -546,7 +550,7 @@ bool CharSelectDialog::selectByName(const std::string &name,
}
-CharacterDisplay::CharacterDisplay(CharSelectDialog *charSelectDialog):
+CharacterDisplay::CharacterDisplay(CharSelectDialog *const charSelectDialog) :
mCharacter(nullptr),
mPlayerBox(new PlayerBox(nullptr)),
mName(new Label("wwwwwwwwwwwwwwwwwwwwwwww")),
@@ -584,7 +588,7 @@ CharacterDisplay::CharacterDisplay(CharSelectDialog *charSelectDialog):
setHeight(200);
}
-void CharacterDisplay::setCharacter(Net::Character *character)
+void CharacterDisplay::setCharacter(Net::Character *const character)
{
if (mCharacter == character)
return;
@@ -599,7 +603,7 @@ void CharacterDisplay::requestFocus()
mButton->requestFocus();
}
-void CharacterDisplay::setActive(bool active)
+void CharacterDisplay::setActive(const bool active)
{
mButton->setEnabled(active);
mDelete->setEnabled(active);
@@ -609,7 +613,7 @@ void CharacterDisplay::update()
{
if (mCharacter)
{
- const LocalPlayer *character = mCharacter->dummy;
+ const LocalPlayer *const character = mCharacter->dummy;
mButton->setCaption(_("Choose"));
mButton->setActionEventId("use");
mName->setCaption(strprintf("%s", character->getName().c_str()));
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index fb71b4bf4..0522566f1 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -66,7 +66,7 @@ class CharSelectDialog : public Window,
/**
* Constructor.
*/
- CharSelectDialog(LoginData *data);
+ CharSelectDialog(LoginData *const data);
~CharSelectDialog();
@@ -89,23 +89,24 @@ class CharSelectDialog : public Window,
* character).
*/
bool selectByName(const std::string &name,
- SelectAction action = Focus);
+ const SelectAction action = Focus);
- void askPasswordForDeletion(int index);
+ void askPasswordForDeletion(const int index);
private:
- void attemptCharacterDelete(int index);
- void attemptCharacterSelect(int index);
+ void attemptCharacterDelete(const int index);
+
+ void attemptCharacterSelect(const int index);
void setCharacters(const Net::Characters &characters);
void lock();
void unlock();
- void setLocked(bool locked);
+ void setLocked(const bool locked);
bool getFocusedContainer(int &container, int &idx);
- void setFocusedContainer(int i, int button);
+ void setFocusedContainer(const int i, const int button);
bool mLocked;