summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-26 09:55:21 -0600
committerIra Rice <irarice@gmail.com>2009-03-26 09:55:21 -0600
commitf883ad28b77a499fa66497158db425ce1db50f78 (patch)
tree47156bc38c68130d1fb83f8d83b2543375d17d1a
parent58eb615a589cd6444092f9c928f26210087aa78b (diff)
downloadmana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.gz
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.bz2
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.xz
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.zip
Some code cleanups (mostly reducing how many calculations need to be
done in certain statements, rearranging arguements to make them look cleaner, or overall making the code slightly more flexible) Signed-off-by: Ira Rice <irarice@gmail.com>
-rw-r--r--src/gui/confirm_dialog.cpp53
-rw-r--r--src/gui/equipmentwindow.cpp11
-rw-r--r--src/gui/inventorywindow.cpp12
-rw-r--r--src/gui/itempopup.cpp47
-rw-r--r--src/gui/label.cpp1
-rw-r--r--src/gui/label.h1
-rw-r--r--src/gui/ok_dialog.cpp38
-rw-r--r--src/gui/ok_dialog.h3
-rw-r--r--src/gui/popup.cpp6
-rw-r--r--src/gui/storagewindow.cpp17
-rw-r--r--src/gui/storagewindow.h4
-rw-r--r--src/gui/window.cpp11
-rw-r--r--src/net/playerhandler.cpp6
13 files changed, 84 insertions, 126 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index f4b49251..4c08eb73 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -48,47 +48,38 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
mTextBox->setTextWrapped(msg, 260);
- int numRows = mTextBox->getNumberOfRows();
- int width = getFont()->getWidth(title);
- int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
+ const int numRows = mTextBox->getNumberOfRows();
+ const int inWidth = yesButton->getWidth() + noButton->getWidth() +
+ (2 * getPadding());
const int fontHeight = getFont()->getHeight();
+ const int height = numRows * fontHeight;
+ int width = getFont()->getWidth(title);
- if (numRows > 1)
- {
- // fontHeight == height of each line of text (based on font heights)
- // 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
- fontHeight) + noButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
- 3 + (numRows * fontHeight)));
- }
- else
- {
- if (width < getFont()->getWidth(msg))
- width = getFont()->getWidth(msg);
- if (width < inWidth)
- width = inWidth;
- setContentSize(width + fontHeight, (2 * fontHeight) +
- noButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
- }
+ if (width < mTextBox->getMinWidth())
+ width = mTextBox->getMinWidth();
+ if (width < inWidth)
+ width = inWidth;
- yesButton->setPosition(
- (mTextBox->getMinWidth() - inWidth) / 2,
- ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
- noButton->setPosition(
- yesButton->getX() + yesButton->getWidth() + 5,
- ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
+ setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight +
+ noButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 2 * getPadding(),
+ height + getPadding()));
+
+ // 8 is the padding that GUIChan adds to button widgets
+ // (top and bottom combined)
+ yesButton->setPosition((width - inWidth) / 2, height + 8);
+ noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(),
+ height + 8);
add(mTextArea);
add(yesButton);
add(noButton);
+ setLocationRelativeTo(getParent());
+
if (getParent())
- {
- setLocationRelativeTo(getParent());
getParent()->moveToTop(this);
- }
+
setVisible(true);
yesButton->requestFocus();
}
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 31fe3b8b..168ae22f 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -122,7 +122,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
// Set color to the highligh color
g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
- BOX_WIDTH, BOX_HEIGHT));
+ BOX_WIDTH, BOX_HEIGHT));
}
// Set color black.
@@ -200,13 +200,8 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
BOX_WIDTH, BOX_HEIGHT);
- if (tRect.isPointInRect(x, y))
- {
- if (item)
- {
- mSelected = i;
- }
- }
+ if (tRect.isPointInRect(x, y) && item)
+ mSelected = i;
}
}
else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index b72a6ff0..fef55b6c 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -122,8 +122,7 @@ void InventoryWindow::logic()
const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
if (mMaxWeight != player_node->mMaxWeight ||
- mTotalWeight != player_node->mTotalWeight ||
- mUsedSlots != usedSlots)
+ mTotalWeight != player_node->mTotalWeight || mUsedSlots != usedSlots)
{
mTotalWeight = player_node->mTotalWeight;
mMaxWeight = player_node->mMaxWeight;
@@ -131,25 +130,18 @@ void InventoryWindow::logic()
// Weight Bar coloration
if (mTotalWeight < (mMaxWeight / 3))
- {
mWeightBar->setColor(0, 0, 255); // Blue
- }
else if (mTotalWeight < ((mMaxWeight / 3) * 2))
- {
mWeightBar->setColor(255, 255, 0); // Yellow
- }
else
- {
mWeightBar->setColor(255, 0, 0); // Red
- }
// Adjust progress bars
mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
- mWeightBar->setText(strprintf("%dg/%dg", mTotalWeight,
- mMaxWeight));
+ mWeightBar->setText(strprintf("%dg/%dg", mTotalWeight, mMaxWeight));
}
}
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 2ebe6645..f2ac374a 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -68,7 +68,8 @@ ItemPopup::ItemPopup():
mItemEffectScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mItemEffectScroll->setDimension(gcn::Rectangle(0, 0, 196, getFont()->getHeight()));
mItemEffectScroll->setOpaque(false);
- mItemEffectScroll->setPosition(2, (2 * getFont()->getHeight()) + 5);
+ mItemEffectScroll->setPosition(2, (2 * getFont()->getHeight()) +
+ (2 * getPadding()));
// Item Weight
mItemWeight = new TextBox();
@@ -79,7 +80,8 @@ ItemPopup::ItemPopup():
mItemWeightScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mItemWeightScroll->setDimension(gcn::Rectangle(0, 0, 196, getFont()->getHeight()));
mItemWeightScroll->setOpaque(false);
- mItemWeightScroll->setPosition(2, (3 * getFont()->getHeight()) + 10);
+ mItemWeightScroll->setPosition(2, (3 * getFont()->getHeight()) +
+ (4 * getPadding()));
add(mItemName);
add(mItemDescScroll);
@@ -125,43 +127,36 @@ void ItemPopup::setItem(const ItemInfo &item)
minWidth += 8;
setWidth(minWidth);
- int numRowsDesc = mItemDesc->getNumberOfRows();
- int numRowsEffect = mItemEffect->getNumberOfRows();
- int numRowsWeight = mItemWeight->getNumberOfRows();
+ const int numRowsDesc = mItemDesc->getNumberOfRows();
+ const int numRowsEffect = mItemEffect->getNumberOfRows();
+ const int numRowsWeight = mItemWeight->getNumberOfRows();
+ const int height = getFont()->getHeight();
- mItemDescScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
- numRowsDesc * getFont()->getHeight()));
+ mItemDescScroll->setDimension(gcn::Rectangle(2, 0, minWidth, numRowsDesc *
+ height));
- mItemEffectScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
- numRowsEffect * getFont()->getHeight()));
+ mItemEffectScroll->setDimension(gcn::Rectangle(2, 0, minWidth, numRowsEffect
+ * height));
- mItemWeightScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
- numRowsWeight * getFont()->getHeight()));
+ mItemWeightScroll->setDimension(gcn::Rectangle(2, 0, minWidth, numRowsWeight
+ * height));
if (item.getEffect().empty())
{
- setContentSize(minWidth, (numRowsDesc * getFont()->getHeight() +
- (3 * getFont()->getHeight())));
+ setContentSize(minWidth, (numRowsDesc + 3) * height);
- mItemWeightScroll->setPosition(2,
- (numRowsDesc * getFont()->getHeight()) +
- (2 * getFont()->getHeight()));
+ mItemWeightScroll->setPosition(2, (numRowsDesc + 2) * height);
}
else
{
- setContentSize(minWidth, (numRowsDesc * getFont()->getHeight()) +
- (numRowsEffect * getFont()->getHeight()) +
- (3 * getFont()->getHeight()));
-
- mItemWeightScroll->setPosition(2,
- (numRowsDesc * getFont()->getHeight()) +
- (numRowsEffect * getFont()->getHeight()) +
- (2 * getFont()->getHeight()));
+ setContentSize(minWidth, (numRowsDesc + numRowsEffect + 3) * height);
+
+ mItemWeightScroll->setPosition(2, (numRowsDesc + numRowsEffect + 2) *
+ height);
}
mItemDescScroll->setPosition(2, 20);
- mItemEffectScroll->setPosition(2, (numRowsDesc * getFont()->getHeight()) +
- (2 * getFont()->getHeight()));
+ mItemEffectScroll->setPosition(2, (numRowsDesc + 2) * height);
}
void ItemPopup::updateColors()
diff --git a/src/gui/label.cpp b/src/gui/label.cpp
index e8d72ace..f3e7bd04 100644
--- a/src/gui/label.cpp
+++ b/src/gui/label.cpp
@@ -1,6 +1,5 @@
/*
* Aethyra
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
* Copyright (c) 2009 Aethyra Development Team
*
* This file is part of Aethyra based on original code
diff --git a/src/gui/label.h b/src/gui/label.h
index 961286e0..4a9bb805 100644
--- a/src/gui/label.h
+++ b/src/gui/label.h
@@ -1,6 +1,5 @@
/*
* Aethyra
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
* Copyright (c) 2009 Aethyra Development Team
*
* This file is part of Aethyra based on original code
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index d3e7bec6..84fa20ea 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -31,7 +31,7 @@
#include "../utils/gettext.h"
OkDialog::OkDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ Window *parent):
Window(title, true, parent)
{
mTextBox = new TextBox();
@@ -47,30 +47,24 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
mTextBox->setTextWrapped(msg, 260);
- int numRows = mTextBox->getNumberOfRows();
+ const int numRows = mTextBox->getNumberOfRows();
const int fontHeight = getFont()->getHeight();
+ const int height = numRows * fontHeight;
+ int width = getFont()->getWidth(title);
- if (numRows > 1)
- {
- // 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
- fontHeight) + okButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5,
- mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight)));
- }
- else
- {
- int width = getFont()->getWidth(title);
- if (width < getFont()->getWidth(msg))
- width = getFont()->getWidth(msg);
- if (width < okButton->getWidth())
- width = okButton->getWidth();
- setContentSize(width + fontHeight, 30 + okButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
- }
+ if (width < mTextBox->getMinWidth())
+ width = mTextBox->getMinWidth();
+ if (width < okButton->getWidth())
+ width = okButton->getWidth();
+
+ setContentSize(mTextBox->getMinWidth() + fontHeight, height +
+ fontHeight + okButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 2 * getPadding(),
+ height + getPadding()));
- okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2,
- ((numRows - 1) * fontHeight) + okButton->getHeight() + 2);
+ // 8 is the padding that GUIChan adds to button widgets
+ // (top and bottom combined)
+ okButton->setPosition((width - okButton->getWidth()) / 2, height + 8);
add(mTextArea);
add(okButton);
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index c84cf4c4..6cfe0798 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -35,7 +35,8 @@ class TextBox;
*
* \ingroup GUI
*/
-class OkDialog : public Window, public gcn::ActionListener {
+class OkDialog : public Window, public gcn::ActionListener
+{
public:
/**
* Constructor.
diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp
index 6d57081f..85ba3b7a 100644
--- a/src/gui/popup.cpp
+++ b/src/gui/popup.cpp
@@ -20,8 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <climits>
-
#include <guichan/exception.hpp>
#include "gui.h"
@@ -45,8 +43,8 @@ Popup::Popup(const std::string& name, Window *parent,
mDefaultSkinPath(skin),
mMinWidth(100),
mMinHeight(40),
- mMaxWidth(INT_MAX),
- mMaxHeight(INT_MAX)
+ mMaxWidth(graphics->getWidth()),
+ mMaxHeight(graphics->getHeight())
{
logger->log("Popup::Popup(\"%s\")", name.c_str());
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index 5036fc15..eb0cbc12 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -48,7 +48,6 @@
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
-#include "../utils/stringutils.h"
StorageWindow::StorageWindow(Network *network, int invSize):
Window(_("Storage")),
@@ -72,7 +71,7 @@ StorageWindow::StorageWindow(Network *network, int invSize):
mInvenScroll = new ScrollArea(mItems);
mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed());
+ mUsedSlots = player_node->getStorage()->getNumberOfSlotsUsed();
mSlotsLabel = new Label(_("Slots: "));
@@ -105,14 +104,15 @@ void StorageWindow::logic()
Window::logic();
- if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed()))
+ const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
+
+ if (mUsedSlots != usedSlots)
{
- mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed());
+ mUsedSlots = usedSlots;
- mSlotsBar->setProgress((float)
- player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots);
+ mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
- mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
+ mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
}
}
@@ -164,7 +164,8 @@ void StorageWindow::mouseClicked(gcn::MouseEvent &event)
{
Item *item = mItems->getSelectedItem();
- if (!item) {
+ if (!item)
+ {
mRetrieveButton->setEnabled(false);
return;
}
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
index 8f02a618..6a1c2cdb 100644
--- a/src/gui/storagewindow.h
+++ b/src/gui/storagewindow.h
@@ -90,8 +90,8 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener
Network *mNetwork;
ItemContainer *mItems;
- std::string mSlots;
- std::string mUsedSlots;
+ int mSlots;
+ int mUsedSlots;
gcn::Button *mStoreButton, *mRetrieveButton;
gcn::ScrollArea *mInvenScroll;
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 642fdeb8..f64f1caf 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -20,9 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <cassert>
-#include <climits>
-
#include <guichan/exception.hpp>
#include "gui.h"
@@ -55,8 +52,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
mSticky(false),
mMinWinWidth(100),
mMinWinHeight(40),
- mMaxWinWidth(INT_MAX),
- mMaxWinHeight(INT_MAX)
+ mMaxWinWidth(graphics->getWidth()),
+ mMaxWinHeight(graphics->getHeight())
{
logger->log("Window::Window(\"%s\")", caption.c_str());
@@ -64,9 +61,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
if (instances == 0)
- {
skinLoader = new SkinLoader();
- }
instances++;
@@ -114,9 +109,7 @@ Window::~Window()
mSkin->instances--;
if (instances == 0)
- {
delete skinLoader;
- }
}
void Window::setWindowContainer(WindowContainer *wc)
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 9afbc5f0..3dd2bad2 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -174,7 +174,7 @@ void PlayerHandler::handleMessage(MessageIn *msg)
case SMSG_PLAYER_STAT_UPDATE_1:
{
int type = msg->readInt16();
- Uint32 value = msg->readInt32();
+ int value = msg->readInt32();
switch (type)
{
@@ -195,8 +195,8 @@ void PlayerHandler::handleMessage(MessageIn *msg)
break;
case 0x0018:
if (value >= player_node->mMaxWeight / 2 &&
- player_node->mTotalWeight <
- player_node->mMaxWeight / 2)
+ player_node->mTotalWeight <
+ player_node->mMaxWeight / 2)
{
weightNotice = new OkDialog(_("Message"),
_("You are carrying more than "