summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-25 19:14:04 -0600
committerIra Rice <irarice@gmail.com>2009-03-25 19:14:04 -0600
commitbfa4a2e11e0c31418d21a91eca7495589c50c11e (patch)
tree8f5202581b2877018dd0fc6c7b3529572dcae0dd
parent34b7a86d06eba936c0642bc66ba104e4669d6b01 (diff)
downloadmana-client-bfa4a2e11e0c31418d21a91eca7495589c50c11e.tar.gz
mana-client-bfa4a2e11e0c31418d21a91eca7495589c50c11e.tar.bz2
mana-client-bfa4a2e11e0c31418d21a91eca7495589c50c11e.tar.xz
mana-client-bfa4a2e11e0c31418d21a91eca7495589c50c11e.zip
Merged relevent changes from TMW commit
dfcc6397848d4597b386b688f689352de6c19ae2 Signed-off-by: Ira Rice <irarice@gmail.com>
-rw-r--r--src/being.cpp25
-rw-r--r--src/gui/inventorywindow.cpp40
-rw-r--r--src/gui/inventorywindow.h6
-rw-r--r--src/gui/widgets/resizegrip.cpp2
-rw-r--r--src/gui/widgets/resizegrip.h2
-rw-r--r--src/localplayer.h2
-rw-r--r--src/main.cpp54
7 files changed, 62 insertions, 69 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 3a772fbd..61826089 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -534,32 +534,18 @@ int Being::getOffset(char pos, char neg) const
int Being::getWidth() const
{
- if (mSprites[BASE_SPRITE])
- {
- const int width = mSprites[BASE_SPRITE]->getWidth() > DEFAULT_WIDTH ?
- mSprites[BASE_SPRITE]->getWidth() :
- DEFAULT_WIDTH;
- return width;
- }
+ if (AnimatedSprite *base = mSprites[BASE_SPRITE])
+ return std::max(base->getWidth(), DEFAULT_WIDTH);
else
- {
return DEFAULT_WIDTH;
- }
}
int Being::getHeight() const
{
- if (mSprites[BASE_SPRITE])
- {
- const int height = mSprites[BASE_SPRITE]->getHeight() > DEFAULT_HEIGHT ?
- mSprites[BASE_SPRITE]->getHeight() :
- DEFAULT_HEIGHT;
- return height;
- }
+ if (AnimatedSprite *base = mSprites[BASE_SPRITE])
+ return std::max(base->getHeight(), DEFAULT_HEIGHT);
else
- {
return DEFAULT_HEIGHT;
- }
}
void Being::setTargetAnimation(SimpleAnimation* animation)
@@ -575,9 +561,8 @@ void Being::load()
int hairstyles = 1;
while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml")
- {
hairstyles++;
- }
+
mNumberOfHairstyles = hairstyles;
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index f6e81fc5..b72a6ff0 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -44,7 +44,6 @@
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
-#include "../utils/stringutils.h"
InventoryWindow::InventoryWindow(int invSize):
Window(_("Inventory")),
@@ -77,9 +76,9 @@ InventoryWindow::InventoryWindow(int invSize):
mInvenScroll = new ScrollArea(mItems);
mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mTotalWeight = toString(player_node->mTotalWeight);
- mMaxWeight = toString(player_node->mMaxWeight);
- mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
+ mTotalWeight = player_node->mTotalWeight;
+ mMaxWeight = player_node->mMaxWeight;
+ mUsedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
mSlotsLabel = new Label(_("Slots: "));
mWeightLabel = new Label(_("Weight: "));
@@ -120,21 +119,22 @@ void InventoryWindow::logic()
// redesign of InventoryWindow and ItemContainer probably.
updateButtons();
- if ((mMaxWeight != toString(player_node->mMaxWeight)) ||
- mTotalWeight != toString(player_node->mTotalWeight) ||
- mUsedSlots != toString(player_node->getInventory()->getNumberOfSlotsUsed()))
+ const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
+
+ if (mMaxWeight != player_node->mMaxWeight ||
+ mTotalWeight != player_node->mTotalWeight ||
+ mUsedSlots != usedSlots)
{
- mTotalWeight = toString(player_node->mTotalWeight);
- mMaxWeight = toString(player_node->mMaxWeight);
- mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
+ mTotalWeight = player_node->mTotalWeight;
+ mMaxWeight = player_node->mMaxWeight;
+ mUsedSlots = usedSlots;
// Weight Bar coloration
- if (int(player_node->mTotalWeight) < int(player_node->mMaxWeight / 3))
+ if (mTotalWeight < (mMaxWeight / 3))
{
mWeightBar->setColor(0, 0, 255); // Blue
}
- else if (int(player_node->mTotalWeight) <
- int((player_node->mMaxWeight / 3) * 2))
+ else if (mTotalWeight < ((mMaxWeight / 3) * 2))
{
mWeightBar->setColor(255, 255, 0); // Yellow
}
@@ -144,14 +144,12 @@ void InventoryWindow::logic()
}
// Adjust progress bars
- mSlotsBar->setProgress((float)
- player_node->getInventory()->getNumberOfSlotsUsed() / mMaxSlots);
- mWeightBar->setProgress((float) player_node->mTotalWeight /
- player_node->mMaxWeight);
-
- mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
- mWeightBar->setText(strprintf("%sg/%sg", mTotalWeight.c_str(),
- mMaxWeight.c_str()));
+ mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots);
+ mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
+
+ mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots));
+ mWeightBar->setText(strprintf("%dg/%dg", mTotalWeight,
+ mMaxWeight));
}
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 83e98687..5035bf1c 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -78,9 +78,9 @@ class InventoryWindow : public Window, gcn::ActionListener,
std::string mWeight;
std::string mSlots;
- std::string mUsedSlots;
- std::string mTotalWeight;
- std::string mMaxWeight;
+ int mUsedSlots;
+ int mTotalWeight;
+ int mMaxWeight;
gcn::Button *mUseButton, *mDropButton;
gcn::ScrollArea *mInvenScroll;
diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp
index f3cc4f83..3dbf6d1a 100644
--- a/src/gui/widgets/resizegrip.cpp
+++ b/src/gui/widgets/resizegrip.cpp
@@ -34,7 +34,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 7c96af45..83af24da 100644
--- a/src/gui/widgets/resizegrip.h
+++ b/src/gui/widgets/resizegrip.h
@@ -40,7 +40,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.
diff --git a/src/localplayer.h b/src/localplayer.h
index 16e7c124..bd59462e 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -220,7 +220,7 @@ class LocalPlayer : public Player
Uint16 mAttackRange;
- Uint32 mTotalWeight, mMaxWeight;
+ int mTotalWeight, mMaxWeight;
Uint8 mAttr[6];
Uint8 mAttrUp[6];
diff --git a/src/main.cpp b/src/main.cpp
index 2ecde05d..014154e2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -179,7 +179,7 @@ struct Options
* Parse the update host and determine the updates directory
* Then verify that the directory exists (creating if needed).
*/
-void setUpdatesDir()
+static void setUpdatesDir()
{
std::stringstream updates;
@@ -257,7 +257,7 @@ void setUpdatesDir()
/**
* Do all initialization stuff
*/
-void init_engine(const Options &options)
+static void init_engine(const Options &options)
{
homeDir = std::string(PHYSFS_getUserDir()) + "/.aethyra";
#if defined WIN32
@@ -463,7 +463,7 @@ void init_engine(const Options &options)
}
/** Clear the engine */
-void exit_engine()
+static void exit_engine()
{
// Before config.write() since it writes the shortcuts to the config
delete itemShortcut;
@@ -493,7 +493,7 @@ void exit_engine()
SDL_FreeSurface(icon);
}
-void printHelp()
+static void printHelp()
{
std::cout
<< _("aethyra") << std::endl << std::endl
@@ -511,7 +511,7 @@ void printHelp()
<< _(" -v --version : Display the version") << std::endl;
}
-void printVersion()
+static void printVersion()
{
#ifdef PACKAGE_VERSION
std::cout << _("Aethyra version ") << PACKAGE_VERSION <<
@@ -522,7 +522,7 @@ void printVersion()
#endif
}
-void parseOptions(int argc, char *argv[], Options &options)
+static void parseOptions(int argc, char *argv[], Options &options)
{
const char *optstring = "hvud:U:P:Dp:C:H:";
@@ -540,14 +540,16 @@ void parseOptions(int argc, char *argv[], Options &options)
{ 0 }
};
- while (optind < argc) {
+ while (optind < argc)
+ {
int result = getopt_long(argc, argv, optstring, long_options, NULL);
if (result == -1)
break;
- switch (result) {
+ switch (result)
+ {
case 'C':
options.configPath = optarg;
break;
@@ -587,7 +589,7 @@ void parseOptions(int argc, char *argv[], Options &options)
* Reads the file "{Updates Directory}/resources2.txt" and attempts to load
* each update mentioned in it.
*/
-void loadUpdates()
+static void loadUpdates()
{
if (updatesDir.empty()) return;
const std::string updatesFile = "/" + updatesDir + "/resources2.txt";
@@ -613,7 +615,7 @@ struct ErrorListener : public gcn::ActionListener
} errorListener;
// TODO Find some nice place for these functions
-void accountLogin(Network *network, LoginData *loginData)
+static void accountLogin(Network *network, LoginData *loginData)
{
logger->log("Trying to connect to account server...");
logger->log("Username is %s", loginData->username.c_str());
@@ -661,14 +663,14 @@ inline int MIN(int x, int y)
return x < y ? x : y;
}
-void positionDialog(Window *dialog, int screenWidth, int screenHeight)
+static void positionDialog(Window *dialog, int screenWidth, int screenHeight)
{
dialog->setPosition(
MIN(screenWidth * 5 / 8, screenWidth - dialog->getWidth()),
MIN(screenHeight * 5 / 8, screenHeight - dialog->getHeight()));
}
-void charLogin(Network *network, LoginData *loginData)
+static void charLogin(Network *network, LoginData *loginData)
{
logger->log("Trying to connect to char server...");
network->connect(loginData->hostname, loginData->port);
@@ -691,7 +693,7 @@ void charLogin(Network *network, LoginData *loginData)
network->skip(4);
}
-void mapLogin(Network *network, LoginData *loginData)
+static void mapLogin(Network *network, LoginData *loginData)
{
logger->log("Memorizing selected character %s",
player_node->getName().c_str());
@@ -719,6 +721,22 @@ void mapLogin(Network *network, LoginData *loginData)
} // namespace
+static void initInternationalization()
+{
+#if ENABLE_NLS
+#ifdef WIN32
+ putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
+ // mingw doesn't like LOCALEDIR to be defined for some reason
+ bindtextdomain("tmw", "translations/");
+#else
+ bindtextdomain("tmw", LOCALEDIR);
+#endif
+ setlocale(LC_MESSAGES, "");
+ bind_textdomain_codeset("tmw", "UTF-8");
+ textdomain("tmw");
+#endif
+}
+
extern "C" char const *_nl_locale_name_default(void);
/** Main */
@@ -741,15 +759,7 @@ int main(int argc, char *argv[])
return 0;
}
-#if ENABLE_NLS
-#ifdef WIN32
- putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
-#endif
- setlocale(LC_MESSAGES, "");
- bindtextdomain("aethyra", LOCALEDIR);
- bind_textdomain_codeset("aethyra", "UTF-8");
- textdomain("aethyra");
-#endif
+ initInternationalization();
// Initialize libxml2 and check for potential ABI mismatches between
// compiled version and the shared library actually used.