summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-26 00:27:05 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-26 00:32:19 +0100
commitdfcc6397848d4597b386b688f689352de6c19ae2 (patch)
treea6e8c9afd6a49ea96e4498080a96d3e06ecaebd7 /src/gui
parentcd20fb3432498b8871401bdd65a143197e2a6538 (diff)
downloadMana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.gz
Mana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.bz2
Mana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.xz
Mana-dfcc6397848d4597b386b688f689352de6c19ae2.zip
Remove redundancy, fix variable names and other code cleanups
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/changeemaildialog.h3
-rw-r--r--src/gui/icon.h6
-rw-r--r--src/gui/inventorywindow.cpp24
-rw-r--r--src/gui/itempopup.cpp4
-rw-r--r--src/gui/serverdialog.h4
-rw-r--r--src/gui/skilldialog.cpp57
-rw-r--r--src/gui/skilldialog.h62
-rw-r--r--src/gui/speechbubble.cpp5
-rw-r--r--src/gui/textdialog.cpp40
-rw-r--r--src/gui/textdialog.h8
-rw-r--r--src/gui/trade.cpp23
-rw-r--r--src/gui/widgets/resizegrip.cpp2
-rw-r--r--src/gui/widgets/resizegrip.h2
13 files changed, 114 insertions, 126 deletions
diff --git a/src/gui/changeemaildialog.h b/src/gui/changeemaildialog.h
index 8ec3705d..c39c6b50 100644
--- a/src/gui/changeemaildialog.h
+++ b/src/gui/changeemaildialog.h
@@ -37,7 +37,8 @@ class WrongDataNoticeListener;
*
* \ingroup Interface
*/
-class ChangeEmailDialog : public Window, public gcn::ActionListener {
+class ChangeEmailDialog : public Window, public gcn::ActionListener
+{
public:
/**
* Constructor.
diff --git a/src/gui/icon.h b/src/gui/icon.h
index 9baf1a99..7435a6e7 100644
--- a/src/gui/icon.h
+++ b/src/gui/icon.h
@@ -27,13 +27,13 @@
class Image;
-
/**
* An icon.
*
* \ingroup GUI
*/
-class Icon : public gcn::Widget {
+class Icon : public gcn::Widget
+{
public:
/**
* Constructor.
@@ -48,7 +48,7 @@ class Icon : public gcn::Widget {
/**
* Gets the current Image.
*/
- Image* getImage() { return mImage; }
+ Image *getImage() const { return mImage; }
/**
* Sets the image to display.
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 0b554469..5a5d8db6 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -136,34 +136,28 @@ void InventoryWindow::logic()
// redesign of InventoryWindow and ItemContainer probably.
updateButtons();
+ const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
+ const std::string usedSlotsStr = toString(usedSlots);
+
if (mMaxWeight != player_node->getMaxWeight() ||
mTotalWeight != player_node->getTotalWeight() ||
- mUsedSlots != toString(player_node->getInventory()->getNumberOfSlotsUsed()))
+ mUsedSlots != usedSlotsStr)
{
mTotalWeight = player_node->getTotalWeight();
mMaxWeight = player_node->getMaxWeight();
- mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
+ mUsedSlots = usedSlotsStr;
// Weight Bar coloration
- if (int(player_node->getTotalWeight()) < int(player_node->getMaxWeight() / 3))
- {
+ if (mTotalWeight < (int) (mMaxWeight / 3))
mWeightBar->setColor(0, 0, 255); // Blue
- }
- else if (int(player_node->getTotalWeight()) <
- int((player_node->getMaxWeight() / 3) * 2))
- {
+ else if (mTotalWeight < (int) ((mMaxWeight * 2) / 3))
mWeightBar->setColor(255, 255, 0); // Yellow
- }
else
- {
mWeightBar->setColor(255, 0, 0); // Red
- }
// Adjust progress bars
- mSlotsBar->setProgress((float)
- player_node->getInventory()->getNumberOfSlotsUsed() / mMaxSlots);
- mWeightBar->setProgress((float) player_node->getTotalWeight() /
- player_node->getMaxWeight());
+ mSlotsBar->setProgress((float) usedSlots / mMaxSlots);
+ mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
mWeightBar->setText(strprintf("%s/%s",
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 8023f0c2..379e6029 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -42,10 +42,8 @@
ItemPopup::ItemPopup():
Popup()
{
- mItemType = "";
-
// Item Name
- mItemName = new gcn::Label("");
+ mItemName = new gcn::Label;
mItemName->setFont(boldFont);
mItemName->setPosition(2, 2);
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 16965571..dd4f369f 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -43,8 +43,8 @@ class LoginData;
*/
struct Server {
Server():
- serverName(""),
- port(0) {};
+ port(0)
+ {}
std::string serverName;
short port;
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 22d1db60..9506e7f8 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -40,6 +40,61 @@
#include "../utils/gettext.h"
#include "../utils/stringutils.h"
+class Skill_Tab : public GCContainer, public gcn::ActionListener
+{
+ public:
+ /**
+ * The type of this skill tab
+ */
+ const std::string type;
+
+ /**
+ * Constructor
+ */
+ Skill_Tab(const std::string &type);
+
+ /**
+ * Update this tab
+ */
+ void update();
+
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const gcn::ActionEvent &event) {}
+
+ private:
+ /**
+ * Update the information of a skill at
+ * the given index
+ */
+ void updateSkill(int index);
+
+ /**
+ * Gets the number of skills in this particular
+ * type of tab.
+ */
+ int getSkillNum();
+
+ /**
+ * Get the first enumeration of this skill tab's
+ * skill type.
+ */
+ int getSkillBegin();
+
+ /**
+ * Get the icon associated with the given index
+ */
+ Icon* getIcon(int index);
+
+ std::vector<Icon *> mSkillIcons;
+ std::vector<gcn::Label *> mSkillNameLabels;
+ std::vector<gcn::Label *> mSkillLevelLabels;
+ std::vector<gcn::Label *> mSkillExpLabels;
+ std::vector<ProgressBar *> mSkillProgress;
+};
+
+
SkillDialog::SkillDialog():
Window(_("Skills"))
{
@@ -50,7 +105,7 @@ SkillDialog::SkillDialog():
TabbedArea *panel = new TabbedArea();
panel->setDimension(gcn::Rectangle(5, 5, 270, 420));
- Skill_Tab* tab;
+ Skill_Tab *tab;
// Add each type of skill tab to the panel
tab = new Skill_Tab("Weapon");
diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h
index 3d010daa..64fd800a 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -35,61 +35,7 @@
class ProgressBar;
class Icon;
-
-class Skill_Tab : public GCContainer, public gcn::ActionListener
-{
- public:
- /**
- * The type of this skill tab
- */
- const std::string type;
-
- /**
- * Constructor
- */
- Skill_Tab(const std::string &type);
-
- /**
- * Update this tab
- */
- void update();
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const gcn::ActionEvent &event) {}
-
- private:
- /**
- * Update the information of a skill at
- * the given index
- */
- void updateSkill(int index);
-
- /**
- * Gets the number of skills in this particular
- * type of tab.
- */
- int getSkillNum();
-
- /**
- * Get the first enumeration of this skill tab's
- * skill type.
- */
- int getSkillBegin();
-
- /**
- * Get the icon associated with the given index
- */
- Icon* getIcon(int index);
-
- std::vector<Icon *> mSkillIcons;
- std::vector<gcn::Label *> mSkillNameLabels;
- std::vector<gcn::Label *> mSkillLevelLabels;
- std::vector<gcn::Label *> mSkillExpLabels;
- std::vector<ProgressBar *> mSkillProgress;
-};
-
+class Skill_Tab;
/**
* The skill dialog.
@@ -125,15 +71,9 @@ class SkillDialog : public Window, public gcn::ActionListener
void draw(gcn::Graphics *g);
private:
-
-
std::list<Skill_Tab*> mTabs;
-
};
-
-
-
extern SkillDialog *skillDialog;
#endif
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 73ada2e1..b191ba77 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -34,14 +34,13 @@
#include "../utils/gettext.h"
SpeechBubble::SpeechBubble():
- Popup("Speech", NULL, "graphics/gui/speechbubble.xml"),
- mText("")
+ Popup("Speech", NULL, "graphics/gui/speechbubble.xml")
{
setContentSize(140, 46);
setMinWidth(29);
setMinHeight(29);
- mCaption = new gcn::Label("");
+ mCaption = new gcn::Label;
mCaption->setFont(boldFont);
mCaption->setPosition(5, 3);
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
index 68a6f502..6163fa36 100644
--- a/src/gui/textdialog.cpp
+++ b/src/gui/textdialog.cpp
@@ -20,41 +20,41 @@
*/
#include "textdialog.h"
+#include "button.h"
+
+#include "../utils/gettext.h"
#include <guichan/widgets/label.hpp>
#include <guichan/widgets/textfield.hpp>
-#include "button.h"
-
TextDialog::TextDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ Window *parent):
Window(title, true, parent),
- textField(new TextField(""))
+ mTextField(new TextField)
{
gcn::Label *textLabel = new gcn::Label(msg);
- okButton = new Button("OK", "OK", this);
- gcn::Button *cancelButton = new Button("Cancel", "CANCEL", this);
+ mOkButton = new Button(_("OK"), "OK", this);
+ gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this);
int w = textLabel->getWidth() + 20;
- int inWidth = okButton->getWidth() + cancelButton->getWidth() + 5;
- int h = textLabel->getHeight() + 25 + okButton->getHeight() + textField->getHeight();
+ int inWidth = mOkButton->getWidth() + cancelButton->getWidth() + 5;
+ int h = textLabel->getHeight() + 25 + mOkButton->getHeight() + mTextField->getHeight();
- if (w < inWidth + 10) {
+ if (w < inWidth + 10)
w = inWidth + 10;
- }
setContentSize(w, h);
textLabel->setPosition(10, 10);
- textField->setWidth(85);
- textField->setPosition(10,20 + textLabel->getHeight());
- okButton->setPosition((w - inWidth) / 2,
+ mTextField->setWidth(85);
+ mTextField->setPosition(10,20 + textLabel->getHeight());
+ mOkButton->setPosition((w - inWidth) / 2,
h - 5 - cancelButton->getHeight());
- cancelButton->setPosition(okButton->getX() + okButton->getWidth() + 5,
+ cancelButton->setPosition(mOkButton->getX() + mOkButton->getWidth() + 5,
h - 5 - cancelButton->getHeight());
add(textLabel);
- add(textField);
- add(okButton);
+ add(mTextField);
+ add(mOkButton);
add(cancelButton);
if (getParent()) {
@@ -62,7 +62,7 @@ TextDialog::TextDialog(const std::string &title, const std::string &msg,
getParent()->moveToTop(this);
}
setVisible(true);
- textField->requestFocus();
+ mTextField->requestFocus();
}
void TextDialog::action(const gcn::ActionEvent &event)
@@ -74,7 +74,7 @@ void TextDialog::action(const gcn::ActionEvent &event)
(*i)->action(event);
}
- if(event.getId() == "CANCEL" || event.getId() == "OK")
+ if (event.getId() == "CANCEL" || event.getId() == "OK")
{
scheduleDelete();
}
@@ -82,10 +82,10 @@ void TextDialog::action(const gcn::ActionEvent &event)
const std::string &TextDialog::getText() const
{
- return textField->getText();
+ return mTextField->getText();
}
void TextDialog::setOKButtonActionId(const std::string &name)
{
- okButton->setActionEventId(name);
+ mOkButton->setActionEventId(name);
}
diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h
index 5583e189..3e544fb4 100644
--- a/src/gui/textdialog.h
+++ b/src/gui/textdialog.h
@@ -27,13 +27,13 @@
#include "window.h"
-
/**
* An option dialog.
*
* \ingroup GUI
*/
-class TextDialog : public Window, public gcn::ActionListener {
+class TextDialog : public Window, public gcn::ActionListener
+{
public:
/**
* Constructor.
@@ -59,8 +59,8 @@ public:
void setOKButtonActionId(const std::string &name);
private:
- TextField *textField;
- gcn::Button *okButton;
+ TextField *mTextField;
+ gcn::Button *mOkButton;
};
#endif
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 5be71a6f..2ba076a3 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -79,11 +79,12 @@ TradeWindow::TradeWindow(Network *network):
getFont()->getWidth(_("Trade")) ?
_("OK") : _("Trade");
- Button *mAddButton = new Button(_("Add"), "add", this);
+ Button *addButton = new Button(_("Add"), "add", this);
#ifdef EATHENA_SUPPORT
mOkButton = new Button(longestName, "ok", this);
+#else
+ Button *cancelButton = new Button(_("Cancel"), "cancel", this);
#endif
- Button *mCancelButton = new Button(_("Cancel"), "cancel", this);
mTradeButton = new Button(_("Propose trade"), "trade", this);
mTradeButton->setWidth(8 + std::max(
mTradeButton->getFont()->getWidth(_("Propose trade")),
@@ -96,7 +97,7 @@ TradeWindow::TradeWindow(Network *network):
#endif
mMyItemContainer->addSelectionListener(this);
- ScrollArea *mMyScroll = new ScrollArea(mMyItemContainer);
+ ScrollArea *myScroll = new ScrollArea(mMyItemContainer);
#ifdef TMWSERV_SUPPORT
mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 4, 3, 0);
@@ -105,30 +106,30 @@ TradeWindow::TradeWindow(Network *network):
#endif
mPartnerItemContainer->addSelectionListener(this);
- ScrollArea *mPartnerScroll = new ScrollArea(mPartnerItemContainer);
+ ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer);
mMoneyLabel = new Label(strprintf(_("You get %s."), ""));
gcn::Label *mMoneyLabel2 = new Label(_("You give:"));
mMoneyField = new TextField;
mMoneyField->setWidth(40);
- Button *mMoneyChange = new Button(_("Change"), "money", this);
+ Button *moneyChange = new Button(_("Change"), "money", this);
place(1, 0, mMoneyLabel);
- place(0, 1, mMyScroll).setPadding(3);
- place(1, 1, mPartnerScroll).setPadding(3);
+ place(0, 1, myScroll).setPadding(3);
+ place(1, 1, partnerScroll).setPadding(3);
ContainerPlacer place;
place = getPlacer(0, 0);
place(0, 0, mMoneyLabel2);
place(1, 0, mMoneyField);
- place(2, 0, mMoneyChange).setHAlign(LayoutCell::LEFT);
+ place(2, 0, moneyChange).setHAlign(LayoutCell::LEFT);
place = getPlacer(0, 2);
- place(0, 0, mAddButton);
+ place(0, 0, addButton);
#ifdef EATHENA_SUPPORT
place(1, 0, mOkButton);
#else
place(2, 0, mTradeButton);
- place(3, 0, mCancelButton);
+ place(3, 0, cancelButton);
#endif
Layout &layout = getLayout();
layout.extend(0, 2, 2, 1);
@@ -276,7 +277,7 @@ void TradeWindow::valueChanged(const gcn::SelectionEvent &event)
if (event.getSource() == mMyItemContainer &&
(item = mMyItemContainer->getSelectedItem()))
mPartnerItemContainer->selectNone();
- else if ((item = mPartnerItemContainer->getSelectedItem()))
+ else if (item = mPartnerItemContainer->getSelectedItem())
mMyItemContainer->selectNone();
}
diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp
index fa264e37..172d4d7e 100644
--- a/src/gui/widgets/resizegrip.cpp
+++ b/src/gui/widgets/resizegrip.cpp
@@ -33,7 +33,7 @@ Image *ResizeGrip::gripImage = 0;
int ResizeGrip::mInstances = 0;
float ResizeGrip::mAlpha = config.getValue("guialpha", 0.8);
-ResizeGrip::ResizeGrip(std::string image)
+ResizeGrip::ResizeGrip(const std::string &image)
{
if (mInstances == 0)
{
diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h
index 620c133f..40a40a0f 100644
--- a/src/gui/widgets/resizegrip.h
+++ b/src/gui/widgets/resizegrip.h
@@ -39,7 +39,7 @@ class ResizeGrip : public gcn::Widget
/**
* Constructor.
*/
- ResizeGrip(std::string image = "graphics/gui/resize.png");
+ ResizeGrip(const std::string &image = "graphics/gui/resize.png");
/**
* Destructor.