From 3fc81e3ad181f6904277e73d99d753a8b7498bf0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 22 Mar 2009 15:25:22 -0600 Subject: Fixed map name saving in the engine class. Somehow, the const gets overridden after map_path, so the saved map path needs to get saved before that. Signed-off-by: Ira Rice --- src/beingmanager.cpp | 6 +++--- src/engine.cpp | 3 ++- src/net/playerhandler.cpp | 5 ++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e5836aa7..a3fb14ff 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -107,9 +107,8 @@ Being *BeingManager::findBeing(int id) for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); - if (being->getId() == id) { + if (being->getId() == id) return being; - } } return NULL; } @@ -182,7 +181,8 @@ void BeingManager::logic() delete being; i = mBeings.erase(i); } - else { + else + { i++; } } diff --git a/src/engine.cpp b/src/engine.cpp index cc19bd72..8ef2b9c6 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -66,6 +66,8 @@ void Engine::changeMap(const std::string &mapPath) particleEngine->clear(); + mMapName = mapPath; + // Store full map path in global var map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx"; ResourceManager *resman = ResourceManager::getInstance(); @@ -128,7 +130,6 @@ void Engine::changeMap(const std::string &mapPath) sound.playMusic(newMusic, -1); mCurrentMap = newMap; - mMapName = mapPath; // Send "map loaded" MessageOut outMsg(mNetwork); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 60d58a37..9afbc5f0 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -164,9 +164,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mX = x; player_node->mY = y; - logger->log("Adjust scrolling by %d:%d", - (int) scrollOffsetX, - (int) scrollOffsetY); + logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } -- cgit v1.2.3-70-g09d2 From 46a368e2f6fd8fcc30949c6676045e2005bd5bfa Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 22 Mar 2009 20:27:48 +0100 Subject: Fixed some compiler warnings Superfluous semicolons, initialization order and signed/unsigned mismatches. --- src/gui/palette.cpp | 10 +++++----- src/gui/palette.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index d3e06902..d3655e04 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -45,12 +45,12 @@ const gcn::Color Palette::RAINBOW_COLORS[7] = { /** Number of Elemets of RAINBOW_COLORS */ const int Palette::RAINBOW_COLOR_COUNT = 7; -std::string Palette::getConfigName(const std::string& typeName) +std::string Palette::getConfigName(const std::string &typeName) { std::string res = "Color" + typeName; int pos = 5; - for (unsigned int i = 0; i < typeName.length(); i++) + for (size_t i = 0; i < typeName.length(); i++) { if (i == 0 || typeName[i] == '_') { @@ -70,7 +70,7 @@ std::string Palette::getConfigName(const std::string& typeName) return res; } -DEFENUMNAMES(ColorType, COLOR_TYPE); +DEFENUMNAMES(ColorType, COLOR_TYPE) const int Palette::GRADIENT_DELAY = 40; @@ -177,7 +177,7 @@ void Palette::setGradient(ColorType type, GradientType grad) ColorElem *elem = &mColVector[type]; if (elem->grad != STATIC && grad == STATIC) { - for (unsigned int i = 0; i < mGradVector.size(); i++) + for (size_t i = 0; i < mGradVector.size(); i++) { if (mGradVector[i] == elem) { @@ -278,7 +278,7 @@ void Palette::advanceGradient () int advance = get_elapsed_time(mRainbowTime) / 5; double startColVal, destColVal; - for (unsigned int i = 0; i < mGradVector.size(); i++) + for (size_t i = 0; i < mGradVector.size(); i++) { mGradVector[i]->gradientIndex = (mGradVector[i]->gradientIndex + advance) % diff --git a/src/gui/palette.h b/src/gui/palette.h index ccef231e..cdeaa48d 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -93,7 +93,7 @@ class Palette : public gcn::ListModel ENTRY(MISS)\ ENTRY(TYPE_COUNT)\ - TEXTENUM(ColorType, COLOR_TYPE); + TEXTENUM(ColorType, COLOR_TYPE) /** Colors can be static or can alter over time. */ enum GradientType { -- cgit v1.2.3-70-g09d2 From f6e7a477681109aea040456e3f4ebd0f65645ecc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 09:55:44 -0600 Subject: Moved the responsibility for skin alpha adjustment to the Skin class. This fixes a break that occured where skins wouldn't update in real time in the client, due to being passed a reference, rather than getting the skin itself. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 48 ------------------------------------------------ src/gui/popup.h | 13 +------------ src/gui/skin.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- src/gui/skin.h | 18 ++++++++++++++++++ src/gui/window.cpp | 41 ----------------------------------------- src/gui/window.h | 12 +----------- 6 files changed, 63 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 17d299a5..d44dbc93 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 -#include #include #include @@ -38,17 +36,7 @@ #include "../resources/image.h" -ConfigListener *Popup::popupConfigListener = 0; int Popup::instances = 0; -bool Popup::mAlphaChanged = false; - -class PopupConfigListener : public ConfigListener -{ - void optionChanged(const std::string &) - { - Popup::mAlphaChanged = true; - } -}; Popup::Popup(const std::string& name, Window *parent, const std::string& skin): @@ -64,14 +52,6 @@ Popup::Popup(const std::string& name, Window *parent, if (!windowContainer) throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); - if (instances == 0) - { - popupConfigListener = new PopupConfigListener(); - // Send GUI alpha changed for initialization - popupConfigListener->optionChanged("guialpha"); - config.addListener("guialpha", popupConfigListener); - } - setPadding(3); instances++; @@ -79,8 +59,6 @@ Popup::Popup(const std::string& name, Window *parent, // Loads the skin mSkin = skinLoader->load(skin); - setGuiAlpha(); - // Add this window to the window container windowContainer->add(this); @@ -102,13 +80,6 @@ Popup::~Popup() instances--; mSkin->instances--; - - if (instances == 0) - { - config.removeListener("guialpha", popupConfigListener); - delete popupConfigListener; - popupConfigListener = NULL; - } } void Popup::setWindowContainer(WindowContainer *wc) @@ -125,13 +96,6 @@ void Popup::draw(gcn::Graphics *graphics) g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); - // Update Popup alpha values - if (mAlphaChanged) - { - for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, - std::bind2nd(std::mem_fun(&Image::setAlpha), - config.getValue("guialpha", 0.8))); - } drawChildren(graphics); } @@ -195,15 +159,3 @@ void Popup::scheduleDelete() windowContainer->scheduleDelete(this); } -void Popup::setGuiAlpha() -{ - //logger->log("Popup::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); - for (int i = 0; i < 9; i++) - { - //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); - mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); - } - - mAlphaChanged = false; -} - diff --git a/src/gui/popup.h b/src/gui/popup.h index bfe8d7e9..3e3ff5ad 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -28,7 +28,6 @@ #include "../graphics.h" #include "../guichanfwd.h" -class ConfigListener; class Skin; class SkinLoader; class Window; @@ -43,8 +42,6 @@ class WindowContainer; class Popup : public gcn::Container { public: - friend class PopupConfigListener; - /** * Constructor. Initializes the title to the given text and hooks * itself into the popup container. @@ -170,21 +167,13 @@ class Popup : public gcn::Container virtual gcn::Rectangle getChildrenArea(); private: - void setGuiAlpha(); - Window *mParent; /**< The parent Window (if there is one) */ std::string mPopupName; /**< Name of the Popup */ - static bool mAlphaChanged; /**< Whether the alpha percent was changed */ int mMinWidth; /**< Minimum Popup width */ int mMinHeight; /**< Minimum Popup height */ int mMaxWidth; /**< Maximum Popup width */ int mMaxHeight; /**< Maximum Popup height */ - unsigned int mPadding; /**< Holds the padding of the window. */ - - /** - * The config listener that listens to changes relevant to all Popups. - */ - static ConfigListener *popupConfigListener; + unsigned int mPadding; /**< Holds the padding of the window. */ static int instances; /**< Number of Popup instances */ diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index d44c54a8..ac258175 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -19,8 +19,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "skin.h" +#include "../configuration.h" +#include "../configlistener.h" #include "../log.h" #include "../resources/image.h" @@ -30,6 +34,16 @@ #include "../utils/xml.h" SkinLoader* skinLoader = NULL; +ConfigListener *SkinLoader::skinConfigListener = NULL; + +class SkinConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + if (skinLoader) + skinLoader->updateAlpha(); + } +}; Skin::Skin(ImageRect skin, Image* close, std::string name): instances(0), @@ -51,6 +65,15 @@ Skin::~Skin() closeImage->decRef(); } +void Skin::updateAlpha() +{ + const float alpha = config.getValue("guialpha", 0.8); + + for_each(border.grid, border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), alpha)); + closeImage->setAlpha(alpha); +} + unsigned int Skin::getMinWidth() { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + @@ -177,15 +200,34 @@ Skin* SkinLoader::load(const std::string &filename) Skin* skin = new Skin(border, closeImage); mSkins[filename] = skin; + + updateAlpha(); + return skin; } -SkinLoader::SkinLoader() +SkinLoader::SkinLoader() : + mSkins() { + skinConfigListener = new SkinConfigListener(); + // Send GUI alpha changed for initialization + skinConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", skinConfigListener); } SkinLoader::~SkinLoader() { delete_all(mSkins); + config.removeListener("guialpha", skinConfigListener); + delete skinConfigListener; + skinConfigListener = NULL; +} + +void SkinLoader::updateAlpha() +{ + for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) + { + iter->second->updateAlpha(); + } } diff --git a/src/gui/skin.h b/src/gui/skin.h index b8a1242e..c90952e3 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -27,6 +27,7 @@ #include "../graphics.h" +class ConfigListener; class Image; class Skin @@ -67,6 +68,11 @@ class Skin */ unsigned int getMinHeight(); + /** + * Updates the alpha value of the skin + */ + void updateAlpha(); + int instances; private: @@ -84,6 +90,8 @@ typedef Skins::iterator SkinIterator; class SkinLoader { public: + friend class SkinConfigListener; + SkinLoader(); ~SkinLoader(); @@ -92,8 +100,18 @@ class SkinLoader */ Skin* load(const std::string &filename); + /** + * Updates the alpha values of all of the skins + */ + void updateAlpha(); + private: Skins mSkins; + + /** + * The config listener that listens to changes relevant to all skins. + */ + static ConfigListener *skinConfigListener; }; extern SkinLoader* skinLoader; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 13c8f4ce..75820521 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -20,7 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include #include @@ -35,24 +34,13 @@ #include "widgets/layout.h" #include "widgets/resizegrip.h" -#include "../configlistener.h" #include "../configuration.h" #include "../log.h" #include "../resources/image.h" -ConfigListener *Window::windowConfigListener = 0; int Window::instances = 0; int Window::mouseResize = 0; -bool Window::mAlphaChanged = false; - -class WindowConfigListener : public ConfigListener -{ - void optionChanged(const std::string &) - { - Window::mAlphaChanged = true; - } -}; Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), @@ -77,10 +65,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std if (instances == 0) { skinLoader = new SkinLoader(); - windowConfigListener = new WindowConfigListener(); - // Send GUI alpha changed for initialization - windowConfigListener->optionChanged("guialpha"); - config.addListener("guialpha", windowConfigListener); } instances++; @@ -92,8 +76,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std // Loads the skin mSkin = skinLoader->load(skin); - setGuiAlpha(); - // Add this window to the window container windowContainer->add(this); @@ -133,9 +115,6 @@ Window::~Window() if (instances == 0) { delete skinLoader; - config.removeListener("guialpha", windowConfigListener); - delete windowConfigListener; - windowConfigListener = NULL; } } @@ -170,14 +149,6 @@ void Window::draw(gcn::Graphics *graphics) ); } - // Update window alpha values - if (mAlphaChanged) - { - for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, - std::bind2nd(std::mem_fun(&Image::setAlpha), - config.getValue("guialpha", 0.8))); - mSkin->getCloseImage()->setAlpha(config.getValue("guialpha", 0.8)); - } drawChildren(graphics); } @@ -665,18 +636,6 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } -void Window::setGuiAlpha() -{ - //logger->log("Window::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); - for (int i = 0; i < 9; i++) - { - //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); - } - - mAlphaChanged = false; -} - int Window::getGuiAlpha() { float alpha = config.getValue("guialpha", 0.8); diff --git a/src/gui/window.h b/src/gui/window.h index 518e1ec2..b0b67ad8 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -30,7 +30,6 @@ #include "../graphics.h" #include "../guichanfwd.h" -class ConfigListener; class GCContainer; class ContainerPlacer; class Layout; @@ -49,8 +48,6 @@ class WindowContainer; class Window : public gcn::Window, gcn::WidgetListener { public: - friend class WindowConfigListener; - /** * Constructor. Initializes the title to the given text and hooks * itself into the window container. @@ -323,8 +320,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); - void setGuiAlpha(); - GCContainer *mChrome; /**< Contained container */ ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ @@ -334,7 +329,7 @@ class Window : public gcn::Window, gcn::WidgetListener bool mModal; /**< Window is modal */ bool mCloseButton; /**< Window has a close button */ bool mSticky; /**< Window resists minimization */ - static bool mAlphaChanged; /**< Whether the alpha percent was changed */ + bool mAlphaChanged; /**< Whether the alpha percent was changed */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ @@ -344,11 +339,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - /** - * The config listener that listens to changes relevant to all windows. - */ - static ConfigListener *windowConfigListener; - static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ -- cgit v1.2.3-70-g09d2 From e0be7afc936c39e2b0e1db84a13653cfd78a6035 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 11:31:02 -0600 Subject: Modified skin loading to save and load a skin's XML path, as well as modified the skin loading method to take a default value, in case the value in the configuration file fails to load for one reason or another. While this doesn't directly expose skinning on a per window basis to the user at the moment, it does allow people to change what skins get loaded with which windows now without needing to modify the code. TODO: Determine a decent approach to allowing the user to change their window skins in game, as well as moving all widget skin loading to the skin class (for instance, the button skins, progressbar skins, etc.) so that different skin configurations can use different widget skins. Signed-off-by: Ira Rice --- src/gui/itempopup.cpp | 4 +++- src/gui/popup.cpp | 33 +++++++++++++++++++++++++++++- src/gui/popup.h | 35 ++++++++++++++++++++++---------- src/gui/popupmenu.cpp | 4 +++- src/gui/skin.cpp | 53 ++++++++++++++++++++++++++++++++---------------- src/gui/skin.h | 11 ++++++++-- src/gui/speechbubble.cpp | 2 ++ src/gui/window.cpp | 12 ++++++++++- src/gui/window.h | 46 ++++++++++++++++++++--------------------- 9 files changed, 142 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index a4042ae2..2ebe6645 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -39,7 +39,7 @@ #include "../utils/stringutils.h" ItemPopup::ItemPopup(): - Popup() + Popup("ItemPopup") { mItemType = ""; @@ -85,6 +85,8 @@ ItemPopup::ItemPopup(): add(mItemDescScroll); add(mItemEffectScroll); add(mItemWeightScroll); + + loadPopupConfiguration(); } ItemPopup::~ItemPopup() diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index d44dbc93..6d57081f 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -42,6 +42,7 @@ Popup::Popup(const std::string& name, Window *parent, const std::string& skin): mParent(parent), mPopupName(name), + mDefaultSkinPath(skin), mMinWidth(100), mMinHeight(40), mMaxWidth(INT_MAX), @@ -57,7 +58,7 @@ Popup::Popup(const std::string& name, Window *parent, instances++; // Loads the skin - mSkin = skinLoader->load(skin); + mSkin = skinLoader->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -70,6 +71,8 @@ Popup::~Popup() { logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + savePopupConfiguration(); + while (!mWidgets.empty()) { gcn::Widget *w = mWidgets.front(); @@ -87,6 +90,34 @@ void Popup::setWindowContainer(WindowContainer *wc) windowContainer = wc; } +void Popup::loadPopupConfiguration() +{ + if (mPopupName.empty()) + return; + + const std::string &name = mPopupName; + const std::string &skinName = config.getValue(name + "Skin", + mSkin->getFilePath()); + + if (skinName.compare(mSkin->getFilePath()) != 0) + { + mSkin->instances--; + mSkin = skinLoader->load(skinName, mDefaultSkinPath); + } +} + +void Popup::savePopupConfiguration() +{ + if (mPopupName.empty()) + return; + + const std::string &name = mPopupName; + + // Saves the skin path in a config file (which allows for skins to be + // changed from the default path) + config.setValue(name + "Skin", mSkin->getFilePath()); +} + void Popup::draw(gcn::Graphics *graphics) { if (!isVisible()) diff --git a/src/gui/popup.h b/src/gui/popup.h index 3e3ff5ad..868f2a2b 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -66,6 +66,18 @@ class Popup : public gcn::Container */ static void setWindowContainer(WindowContainer *windowContainer); + /** + * Changes the popup's skin to use the skin defined in the saved + * configuration file. + */ + void loadPopupConfiguration(); + + /** + * Currently only saves the skin used by the popup so that when the + * client is reloaded, it can use the saved skin. + */ + void savePopupConfiguration(); + /** * Draws the popup. */ @@ -167,17 +179,18 @@ class Popup : public gcn::Container virtual gcn::Rectangle getChildrenArea(); private: - Window *mParent; /**< The parent Window (if there is one) */ - std::string mPopupName; /**< Name of the Popup */ - int mMinWidth; /**< Minimum Popup width */ - int mMinHeight; /**< Minimum Popup height */ - int mMaxWidth; /**< Maximum Popup width */ - int mMaxHeight; /**< Maximum Popup height */ - unsigned int mPadding; /**< Holds the padding of the window. */ - - static int instances; /**< Number of Popup instances */ - - Skin* mSkin; /**< Skin in use by this Popup */ + Window *mParent; /**< The parent Window (if there is one) */ + std::string mPopupName; /**< Name of the popup */ + std::string mDefaultSkinPath; /**< Default skin path for this popup */ + int mMinWidth; /**< Minimum popup width */ + int mMinHeight; /**< Minimum popup height */ + int mMaxWidth; /**< Maximum popup width */ + int mMaxHeight; /**< Maximum popup height */ + unsigned int mPadding; /**< Holds the padding of the popup. */ + + static int instances; /**< Number of popup instances */ + + Skin* mSkin; /**< Skin in use by this popup */ }; #endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 02be3055..fd2a0361 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -61,8 +61,10 @@ PopupMenu::PopupMenu(): mBrowserBox->setPosition(4, 4); mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND); mBrowserBox->setOpaque(false); - add(mBrowserBox); mBrowserBox->setLinkHandler(this); + add(mBrowserBox); + + loadWindowState(); } void PopupMenu::showPopup(int x, int y, Being *being) diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index ac258175..515ef01b 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,6 +31,7 @@ #include "../resources/resourcemanager.h" #include "../utils/dtor.h" +#include "../utils/strprintf.h" #include "../utils/xml.h" SkinLoader* skinLoader = NULL; @@ -45,8 +46,9 @@ class SkinConfigListener : public ConfigListener } }; -Skin::Skin(ImageRect skin, Image* close, std::string name): +Skin::Skin(ImageRect skin, Image* close, std::string filePath, std::string name): instances(0), + mFilePath(filePath), mName(name), border(skin), closeImage(close) @@ -86,32 +88,47 @@ unsigned int Skin::getMinHeight() border.grid[6]->getHeight(); } -Skin* SkinLoader::load(const std::string &filename) +Skin* SkinLoader::load(const std::string &filename, + const std::string &defaultPath) { - SkinIterator skinIterator = mSkins.find(filename); - - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - return skinIterator->second; - } + std::string filePath = filename; ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Skin '%s'.", filename.c_str()); - if (filename.empty()) + if (filename.empty() && defaultPath.empty()) logger->error("SkinLoader::load(): Invalid File Name."); - // TODO: - // If there is an error loading the specified file, we should try to revert - // to a 'default' skin file. Only if the 'default' skin file can't be loaded - // should we have a terminating error. - XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); + XML::Document *doc = new XML::Document(filePath); + xmlNodePtr rootNode = doc->rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - logger->error("Widget Skinning error"); + { + filePath = defaultPath; + + logger->log("Widget Skinning error. Loading '%s' instead.", + filePath.c_str()); + + delete doc; + + doc = new XML::Document(filePath); + rootNode = doc->rootNode(); + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + { + logger->error(strprintf("Skinning failed. Check this skin file " + "to make sure it's valid: %s", + filePath.c_str())); + } + } + + SkinIterator skinIterator = mSkins.find(filePath); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); @@ -197,7 +214,7 @@ Skin* SkinLoader::load(const std::string &filename) // Hard-coded for now until we update the above code to look for window buttons. Image* closeImage = resman->getImage("graphics/gui/close_button.png"); - Skin* skin = new Skin(border, closeImage); + Skin* skin = new Skin(border, closeImage, filename); mSkins[filename] = skin; diff --git a/src/gui/skin.h b/src/gui/skin.h index c90952e3..b7e2c29f 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -33,7 +33,8 @@ class Image; class Skin { public: - Skin(ImageRect skin, Image* close, std::string name = ""); + Skin(ImageRect skin, Image* close, std::string filePath, + std::string name = ""); ~Skin(); /** @@ -43,6 +44,11 @@ class Skin */ std::string getName() { return mName; } + /** + * Returns the skin's xml file path. + */ + std::string getFilePath() { return mFilePath; } + /** * Returns the background skin. */ @@ -76,6 +82,7 @@ class Skin int instances; private: + std::string mFilePath; /**< File name path for the skin */ std::string mName; /**< Name of the skin to use */ ImageRect border; /**< The window border and background */ Image *closeImage; /**< Close Button Image */ @@ -98,7 +105,7 @@ class SkinLoader /** * Loads a skin */ - Skin* load(const std::string &filename); + Skin* load(const std::string &filename, const std::string &defaultPath); /** * Updates the alpha values of all of the skins diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 9e4c9234..ca771fce 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -60,6 +60,8 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); + + loadPopupConfiguration(); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 75820521..642fdeb8 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -48,6 +48,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mParent(parent), mLayout(NULL), mWindowName("window"), + mDefaultSkinPath(skin), mShowTitle(true), mModal(modal), mCloseButton(false), @@ -74,7 +75,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std setTitleBarHeight(20); // Loads the skin - mSkin = skinLoader->load(skin); + mSkin = skinLoader->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -476,12 +477,20 @@ void Window::mouseDragged(gcn::MouseEvent &event) void Window::loadWindowState() { const std::string &name = mWindowName; + const std::string skinName = config.getValue(name + "Skin", + mSkin->getFilePath()); assert(!name.empty()); setPosition((int) config.getValue(name + "WinX", mDefaultX), (int) config.getValue(name + "WinY", mDefaultY)); setVisible((bool) config.getValue(name + "Visible", false)); + if (skinName.compare(mSkin->getFilePath()) != 0) + { + mSkin->instances--; + mSkin = skinLoader->load(skinName, mDefaultSkinPath); + } + if (mGrip) { int width = (int) config.getValue(name + "WinWidth", mDefaultWidth); @@ -512,6 +521,7 @@ void Window::saveWindowState() config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); config.setValue(mWindowName + "Visible", isVisible()); + config.setValue(mWindowName + "Skin", mSkin->getFilePath()); if (mGrip) { diff --git a/src/gui/window.h b/src/gui/window.h index b0b67ad8..66e73e12 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -320,29 +320,29 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); - GCContainer *mChrome; /**< Contained container */ - ResizeGrip *mGrip; /**< Resize grip */ - Window *mParent; /**< The parent window */ - Layout *mLayout; /**< Layout handler */ - std::string mWindowName; /**< Name of the window */ - bool mShowTitle; /**< Window has a title bar */ - bool mModal; /**< Window is modal */ - bool mCloseButton; /**< Window has a close button */ - bool mSticky; /**< Window resists minimization */ - bool mAlphaChanged; /**< Whether the alpha percent was changed */ - int mMinWinWidth; /**< Minimum window width */ - int mMinWinHeight; /**< Minimum window height */ - int mMaxWinWidth; /**< Maximum window width */ - int mMaxWinHeight; /**< Maximum window height */ - int mDefaultX; /**< Default window X position */ - int mDefaultY; /**< Default window Y position */ - int mDefaultWidth; /**< Default window width */ - int mDefaultHeight; /**< Default window height */ - - static int mouseResize; /**< Active resize handles */ - static int instances; /**< Number of Window instances */ - - Skin* mSkin; /**< Skin in use by this window */ + GCContainer *mChrome; /**< Contained container */ + ResizeGrip *mGrip; /**< Resize grip */ + Window *mParent; /**< The parent window */ + Layout *mLayout; /**< Layout handler */ + std::string mWindowName; /**< Name of the window */ + std::string mDefaultSkinPath; /**< Default skin path for this window */ + bool mShowTitle; /**< Window has a title bar */ + bool mModal; /**< Window is modal */ + bool mCloseButton; /**< Window has a close button */ + bool mSticky; /**< Window resists minimization */ + int mMinWinWidth; /**< Minimum window width */ + int mMinWinHeight; /**< Minimum window height */ + int mMaxWinWidth; /**< Maximum window width */ + int mMaxWinHeight; /**< Maximum window height */ + int mDefaultX; /**< Default window X position */ + int mDefaultY; /**< Default window Y position */ + int mDefaultWidth; /**< Default window width */ + int mDefaultHeight; /**< Default window height */ + + static int mouseResize; /**< Active resize handles */ + static int instances; /**< Number of Window instances */ + + Skin* mSkin; /**< Skin in use by this window */ /** * The width of the resize border. Is independent of the actual window -- cgit v1.2.3-70-g09d2 From 79b6dfb373e3a7165ff2dfa5563d73560b15212d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 11:55:32 -0600 Subject: Relaxed collision and fringe naming slightly so that they just need to start with collision or fringe, instead of being required to be the same case throughout the beginning of the layer name. Also made a default name for popup menus so that their skins can also be changed by users. Signed-off-by: Ira Rice --- src/gui/popupmenu.cpp | 2 +- src/resources/mapreader.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index fd2a0361..13adf827 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -48,7 +48,7 @@ extern std::string tradePartnerName; PopupMenu::PopupMenu(): - Window(), + Window("PopupMenu"), mBeingId(0), mFloorItem(NULL), mItem(NULL) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 901a2561..e40acd77 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -322,10 +322,11 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) const int h = XML::getProperty(node, "height", map->getHeight()); const int offsetX = XML::getProperty(node, "x", 0); const int offsetY = XML::getProperty(node, "y", 0); - const std::string name = XML::getProperty(node, "name", ""); + std::string name = XML::getProperty(node, "name", ""); + name = toLower(name); - const bool isFringeLayer = (name.substr(0,6) == "Fringe"); - const bool isCollisionLayer = (name.substr(0,9) == "Collision"); + const bool isFringeLayer = (name.substr(0,6) == "fringe"); + const bool isCollisionLayer = (name.substr(0,9) == "collision"); MapLayer *layer = 0; -- cgit v1.2.3-70-g09d2 From 5be896d25adc77aedd4a5261277e690a34a64697 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 12:27:12 -0600 Subject: Fixed a static leak in skin loading. Signed-off-by: Ira Rice --- src/gui/skin.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index 515ef01b..e87f6761 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -211,6 +211,8 @@ Skin* SkinLoader::load(const std::string &filename, logger->log("Finished loading Skin."); + delete doc; + // Hard-coded for now until we update the above code to look for window buttons. Image* closeImage = resman->getImage("graphics/gui/close_button.png"); -- cgit v1.2.3-70-g09d2 From 34b7a86d06eba936c0642bc66ba104e4669d6b01 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 25 Mar 2009 22:53:23 +0100 Subject: Don't crash cause of deleting a model twice This reverts commit c2e4a7a70971355f1446bb01053af8a1da8c98e1. --- src/gui/widgets/dropdown.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 0015beed..21fee368 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -108,9 +108,6 @@ DropDown::~DropDown() for_each(skin.grid, skin.grid + 9, dtor()); } - - gcn::ListModel *listModel = getListModel(); - if (listModel) delete listModel; } void DropDown::draw(gcn::Graphics* graphics) -- cgit v1.2.3-70-g09d2 From bfa4a2e11e0c31418d21a91eca7495589c50c11e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 19:14:04 -0600 Subject: Merged relevent changes from TMW commit dfcc6397848d4597b386b688f689352de6c19ae2 Signed-off-by: Ira Rice --- src/being.cpp | 25 ++++--------------- src/gui/inventorywindow.cpp | 40 +++++++++++++++---------------- src/gui/inventorywindow.h | 6 ++--- src/gui/widgets/resizegrip.cpp | 2 +- src/gui/widgets/resizegrip.h | 2 +- src/localplayer.h | 2 +- src/main.cpp | 54 +++++++++++++++++++++++++----------------- 7 files changed, 62 insertions(+), 69 deletions(-) (limited to 'src') 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. -- cgit v1.2.3-70-g09d2 From 58eb615a589cd6444092f9c928f26210087aa78b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 21:49:10 -0600 Subject: Make sure the correct color for the pulse gradient shows up on the slider as well, rather than just in the preview, on startup. Signed-off-by: Ira Rice --- src/gui/palette.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/palette.h b/src/gui/palette.h index cdeaa48d..16c9338c 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -291,6 +291,7 @@ class Palette : public gcn::ListModel { ColorElem::type = type; ColorElem::color = color; + ColorElem::testColor = color; ColorElem::text = text; ColorElem::ch = c; ColorElem::grad = grad; -- cgit v1.2.3-70-g09d2 From f883ad28b77a499fa66497158db425ce1db50f78 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 09:55:21 -0600 Subject: 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 --- src/gui/confirm_dialog.cpp | 53 +++++++++++++++++++-------------------------- src/gui/equipmentwindow.cpp | 11 +++------- src/gui/inventorywindow.cpp | 12 ++-------- src/gui/itempopup.cpp | 47 ++++++++++++++++++---------------------- src/gui/label.cpp | 1 - src/gui/label.h | 1 - src/gui/ok_dialog.cpp | 38 ++++++++++++++------------------ src/gui/ok_dialog.h | 3 ++- src/gui/popup.cpp | 6 ++--- src/gui/storagewindow.cpp | 17 ++++++++------- src/gui/storagewindow.h | 4 ++-- src/gui/window.cpp | 11 ++-------- src/net/playerhandler.cpp | 6 ++--- 13 files changed, 84 insertions(+), 126 deletions(-) (limited to 'src') 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 - #include #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 -#include - #include #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 " -- cgit v1.2.3-70-g09d2 From d26a7795fa90c6e26f5302db4a470321bce4a5cb Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Fri, 27 Mar 2009 00:04:04 +0100 Subject: Fix the ColorTypes Macro --- src/gui/palette.cpp | 4 ++-- src/gui/palette.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index d3655e04..2efc60be 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -70,11 +70,11 @@ std::string Palette::getConfigName(const std::string &typeName) return res; } -DEFENUMNAMES(ColorType, COLOR_TYPE) +DEFENUMNAMES(ColorType, COLOR_TYPE); const int Palette::GRADIENT_DELAY = 40; -Palette::Palette() : +Palette::Palette() : mRainbowTime(tick_time), mColVector(ColVector(TYPE_COUNT)), mGradVector() diff --git a/src/gui/palette.h b/src/gui/palette.h index 16c9338c..e894ba74 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -32,13 +32,15 @@ // Generate strings from an enum ... some preprocessor fun. #define EDEF(a) a, +#define LASTEDEF(a) a #define ECONFIGSTR(a) Palette::getConfigName(#a), +#define LASTECONFIGSTR(a) Palette::getConfigName(#a) #define TEXTENUM(name,def)\ - enum name { def(EDEF) };\ - static const std::string name ## Names[]; + enum name { def(EDEF,LASTEDEF) };\ + static const std::string name ## Names[] #define DEFENUMNAMES(name,def)\ - const std::string Palette::name ## Names[] = { def(ECONFIGSTR) "" }; + const std::string Palette::name ## Names[] = { def(ECONFIGSTR,ECONFIGSTR) "" } /** * Class controlling the game's color palette. @@ -47,7 +49,7 @@ class Palette : public gcn::ListModel { public: /** List of all colors that are configurable. */ - #define COLOR_TYPE(ENTRY)\ + #define COLOR_TYPE(ENTRY,LASTENTRY)\ ENTRY(TEXT)\ ENTRY(SHADOW)\ ENTRY(OUTLINE)\ @@ -91,9 +93,9 @@ class Palette : public gcn::ListModel ENTRY(HIT_MONSTER_PLAYER)\ ENTRY(HIT_CRITICAL)\ ENTRY(MISS)\ - ENTRY(TYPE_COUNT)\ + LASTENTRY(TYPE_COUNT) - TEXTENUM(ColorType, COLOR_TYPE) + TEXTENUM(ColorType, COLOR_TYPE); /** Colors can be static or can alter over time. */ enum GradientType { -- cgit v1.2.3-70-g09d2 From 22974109dd0e9ae2b915cc2c258df1f01a65b729 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 Mar 2009 00:01:39 +0100 Subject: Fixed duplicate check for item names --- src/being.cpp | 2 +- src/resources/itemdb.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 61826089..8f00fd3c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -203,7 +203,7 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) - { + { if (attacker == player_node) { // This is intended to be the wrong direction to visually diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 2b94bd61..49913300 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -125,12 +125,12 @@ void ItemDB::load() mItemInfos[id] = itemInfo; if (!name.empty()) { - NamedItemInfoIterator itr = mNamedItemInfos.find(name); + std::string temp = name; + toLower(trim(temp)); + + NamedItemInfoIterator itr = mNamedItemInfos.find(temp); if (itr == mNamedItemInfos.end()) { - std::string temp = name; - toLower(trim(temp)); - mNamedItemInfos[temp] = itemInfo; } else -- cgit v1.2.3-70-g09d2 From 2ec46b9a6e5ca1beb043da00cf2bb9d34722ec72 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 Mar 2009 00:17:27 +0100 Subject: Compile warning fixes Mostly unsigned/signed mismatches and an unused variable. --- src/gui/popup.cpp | 8 ++++---- src/gui/popup.h | 20 ++++++++++---------- src/gui/skin.cpp | 4 ++-- src/gui/skin.h | 4 ++-- src/gui/window.cpp | 13 ++++--------- src/gui/window.h | 21 +++++++++++---------- 6 files changed, 33 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 85ba3b7a..8dfc3c61 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -163,22 +163,22 @@ void Popup::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } -void Popup::setMinWidth(unsigned int width) +void Popup::setMinWidth(int width) { mMinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } -void Popup::setMinHeight(unsigned int height) +void Popup::setMinHeight(int height) { mMinHeight = height > mSkin->getMinHeight() ? height : mSkin->getMinHeight(); } -void Popup::setMaxWidth(unsigned int width) +void Popup::setMaxWidth(int width) { mMaxWidth = width; } -void Popup::setMaxHeight(unsigned int height) +void Popup::setMaxHeight(int height) { mMaxHeight = height; } diff --git a/src/gui/popup.h b/src/gui/popup.h index 868f2a2b..37c99ded 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -96,42 +96,42 @@ class Popup : public gcn::Container /** * Sets the minimum width of the popup. */ - void setMinWidth(unsigned int width); + void setMinWidth(int width); /** * Sets the minimum height of the popup. */ - void setMinHeight(unsigned int height); + void setMinHeight(int height); /** * Sets the maximum width of the popup. */ - void setMaxWidth(unsigned int width); + void setMaxWidth(int width); /** * Sets the minimum height of the popup. */ - void setMaxHeight(unsigned int height); + void setMaxHeight(int height); /** * Gets the minimum width of the popup. */ - int getMinWidth() { return mMinWidth; } + int getMinWidth() const { return mMinWidth; } /** * Gets the minimum height of the popup. */ - int getMinHeight() { return mMinHeight; } + int getMinHeight() const { return mMinHeight; } /** * Gets the maximum width of the popup. */ - int getMaxWidth() { return mMaxWidth; } + int getMaxWidth() const { return mMaxWidth; } /** * Gets the minimum height of the popup. */ - int getMaxHeight() { return mMaxHeight; } + int getMaxHeight() const { return mMaxHeight; } /** * Gets the padding of the popup. The padding is the distance between @@ -149,7 +149,7 @@ class Popup : public gcn::Container * @param padding The padding of the popup. * @see getPadding */ - void setPadding(unsigned int padding) { mPadding = padding; } + void setPadding(int padding) { mPadding = padding; } /** * Returns the parent Window. @@ -186,7 +186,7 @@ class Popup : public gcn::Container int mMinHeight; /**< Minimum popup height */ int mMaxWidth; /**< Maximum popup width */ int mMaxHeight; /**< Maximum popup height */ - unsigned int mPadding; /**< Holds the padding of the popup. */ + int mPadding; /**< Holds the padding of the popup. */ static int instances; /**< Number of popup instances */ diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index e87f6761..10b9885a 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -76,13 +76,13 @@ void Skin::updateAlpha() closeImage->setAlpha(alpha); } -unsigned int Skin::getMinWidth() +int Skin::getMinWidth() const { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + border.grid[2]->getWidth(); } -unsigned int Skin::getMinHeight() +int Skin::getMinHeight() const { return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + border.grid[6]->getHeight(); diff --git a/src/gui/skin.h b/src/gui/skin.h index b7e2c29f..1a603e29 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -67,12 +67,12 @@ class Skin /** * Returns the minimum width which can be used with this skin. */ - unsigned int getMinWidth(); + int getMinWidth() const; /** * Returns the minimum height which can be used with this skin. */ - unsigned int getMinHeight(); + int getMinHeight() const; /** * Updates the alpha value of the skin diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f64f1caf..476dcd7e 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -221,23 +221,23 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, setPosition(offsetX, offsetY); } -void Window::setMinWidth(unsigned int width) +void Window::setMinWidth(int width) { mMinWinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } -void Window::setMinHeight(unsigned int height) +void Window::setMinHeight(int height) { mMinWinHeight = height > mSkin->getMinHeight() ? height : mSkin->getMinHeight(); } -void Window::setMaxWidth(unsigned int width) +void Window::setMaxWidth(int width) { mMaxWinWidth = width; } -void Window::setMaxHeight(unsigned int height) +void Window::setMaxHeight(int height) { mMaxWinHeight = height; } @@ -292,11 +292,6 @@ void Window::setSticky(bool sticky) mSticky = sticky; } -bool Window::isSticky() -{ - return mSticky; -} - void Window::setVisible(bool visible) { gcn::Window::setVisible(isSticky() || visible); diff --git a/src/gui/window.h b/src/gui/window.h index 66e73e12..8907ead4 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -116,42 +116,42 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the minimum width of the window. */ - void setMinWidth(unsigned int width); + void setMinWidth(int width); /** * Sets the minimum height of the window. */ - void setMinHeight(unsigned int height); + void setMinHeight(int height); /** * Sets the maximum width of the window. */ - void setMaxWidth(unsigned int width); + void setMaxWidth(int width); /** * Sets the minimum height of the window. */ - void setMaxHeight(unsigned int height); + void setMaxHeight(int height); /** * Gets the minimum width of the window. */ - int getMinWidth() { return mMinWinWidth; } + int getMinWidth() const { return mMinWinWidth; } /** * Gets the minimum height of the window. */ - int getMinHeight() { return mMinWinHeight; } + int getMinHeight() const { return mMinWinHeight; } /** * Gets the maximum width of the window. */ - int getMaxWidth() { return mMaxWinWidth; } + int getMaxWidth() const { return mMaxWinWidth; } /** * Gets the minimum height of the window. */ - int getMaxHeight() { return mMaxWinHeight; } + int getMaxHeight() const { return mMaxWinHeight; } /** * Sets flag to show a title or not. @@ -167,7 +167,8 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Returns whether the window is sticky. */ - bool isSticky(); + bool isSticky() const + { return mSticky; } /** * Overloads window setVisible by Guichan to allow sticky window @@ -180,7 +181,7 @@ class Window : public gcn::Window, gcn::WidgetListener * * @return The parent window or NULL if there is none. */ - Window* getParentWindow() { return mParent; } + Window *getParentWindow() const { return mParent; } /** * Schedule this window for deletion. It will be deleted at the start -- cgit v1.2.3-70-g09d2 From 1a9d402bec2fd8166ce50e30a71ba0cf2f27281a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 19:09:31 -0600 Subject: Some code style commits influenced by TMW commit 1715d0afe44a282a356ca88e47c92ec556f094dd Signed-off-by: Ira Rice --- src/gui/scrollarea.cpp | 17 ++++--------- src/resources/action.cpp | 2 -- src/resources/ambientoverlay.h | 9 +++++-- src/resources/colordb.cpp | 2 -- src/resources/dye.cpp | 54 +++++++++++++++++++++++++++++------------- src/resources/imagewriter.cpp | 3 +-- src/shopitem.cpp | 3 ++- 7 files changed, 53 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 43b27f23..156ff054 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -217,12 +217,12 @@ void ScrollArea::draw(gcn::Graphics *graphics) void ScrollArea::drawFrame(gcn::Graphics *graphics) { - int bs = getFrameSize(); - int w = getWidth() + bs * 2; - int h = getHeight() + bs * 2; - if (mOpaque) { + const int bs = getFrameSize(); + const int w = getWidth() + bs * 2; + const int h = getHeight() + bs * 2; + static_cast(graphics)-> drawImageRect(0, 0, w, h, background); } @@ -232,14 +232,7 @@ void ScrollArea::setOpaque(bool opaque) { mOpaque = opaque; - if (mOpaque) - { - setFrameSize(2); - } - else - { - setFrameSize(0); - } + setFrameSize(mOpaque ? 2 : 0); } void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir) diff --git a/src/resources/action.cpp b/src/resources/action.cpp index 67acf1b1..27369def 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -41,9 +41,7 @@ Animation *Action::getAnimation(int direction) const // When the given direction is not available, return the first one. // (either DEFAULT, or more usually DOWN). if (i == mAnimations.end()) - { i = mAnimations.begin(); - } return (i == mAnimations.end()) ? NULL : i->second; } diff --git a/src/resources/ambientoverlay.h b/src/resources/ambientoverlay.h index bb61f826..142dfd2f 100644 --- a/src/resources/ambientoverlay.h +++ b/src/resources/ambientoverlay.h @@ -31,6 +31,11 @@ class AmbientOverlay public: /** * Constructor. + * + * @param img the image this overlay displays + * @param parallax scroll factor based on camera position + * @param speedX scrolling speed in x-direction + * @param speedY scrolling speed in y-direction */ AmbientOverlay(Image *img, float parallax, float speedX, float speedY); @@ -49,8 +54,8 @@ class AmbientOverlay float mParallax; float mPosX; /**< Current layer X position. */ float mPosY; /**< Current layer Y position. */ - float mSpeedX; /**< Scroll speed in X direction. */ - float mSpeedY; /**< Scroll speed in Y direction. */ + float mSpeedX; /**< Scrolling speed in X direction. */ + float mSpeedY; /**< Scrolling speed in Y direction. */ }; #endif diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index b53798bb..c9252a8a 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -40,9 +40,7 @@ namespace void ColorDB::load() { if (mLoaded) - { return; - } XML::Document *doc = new XML::Document(HAIR_COLOR_FILE); xmlNodePtr root = doc->rootNode(); diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 38249ddb..35a8ca89 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -29,33 +29,42 @@ DyePalette::DyePalette(const std::string &description) { int size = description.length(); - if (size == 0) return; - if (description[0] != '#') - { + if (size == 0 || description[0] != '#') // TODO: load palette from file. return; - } int pos = 1; for (;;) { - if (pos + 6 > size) break; + if (pos + 6 > size) + break; + int v = 0; for (int i = 0; i < 6; ++i) { char c = description[pos + i]; int n; - if ('0' <= c && c <= '9') n = c - '0'; - else if ('A' <= c && c <= 'F') n = c - 'A' + 10; - else if ('a' <= c && c <= 'f') n = c - 'a' + 10; - else goto error; + + if ('0' <= c && c <= '9') + n = c - '0'; + else if ('A' <= c && c <= 'F') + n = c - 'A' + 10; + else if ('a' <= c && c <= 'f') + n = c - 'a' + 10; + else + goto error; + v = (v << 4) | n; } Color c = { { v >> 16, v >> 8, v } }; mColors.push_back(c); pos += 6; - if (pos == size) return; - if (description[pos] != ',') break; + + if (pos == size) + return; + if (description[pos] != ',') + break; + ++pos; } @@ -114,21 +123,26 @@ Dye::Dye(const std::string &description) for (int i = 0; i < 7; ++i) mDyePalettes[i] = 0; - if (description.empty()) return; + if (description.empty()) + return; std::string::size_type next_pos = 0, length = description.length(); do { std::string::size_type pos = next_pos; next_pos = description.find(';', pos); + if (next_pos == std::string::npos) next_pos = length; + if (next_pos <= pos + 3 || description[pos + 1] != ':') { logger->log("Error, invalid dye: %s", description.c_str()); return; } + int i = 0; + switch (description[pos]) { case 'R': i = 0; break; @@ -142,7 +156,8 @@ Dye::Dye(const std::string &description) logger->log("Error, invalid dye: %s", description.c_str()); return; } - mDyePalettes[i] = new DyePalette(description.substr(pos + 2, next_pos - pos - 2)); + mDyePalettes[i] = new DyePalette(description.substr(pos + 2, + next_pos - pos - 2)); ++next_pos; } while (next_pos < length); @@ -157,7 +172,8 @@ Dye::~Dye() void Dye::update(int color[3]) const { int cmax = std::max(color[0], std::max(color[1], color[2])); - if (cmax == 0) return; + if (cmax == 0) + return; int cmin = std::min(color[0], std::min(color[1], color[2])); int intensity = color[0] + color[1] + color[2]; @@ -178,7 +194,10 @@ void Dye::update(int color[3]) const void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type next_pos = target.find('|'); - if (next_pos == std::string::npos || palettes.empty()) return; + + if (next_pos == std::string::npos || palettes.empty()) + return; + ++next_pos; std::ostringstream s; @@ -188,7 +207,10 @@ void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type pos = next_pos; next_pos = target.find(';', pos); - if (next_pos == std::string::npos) next_pos = last_pos; + + if (next_pos == std::string::npos) + next_pos = last_pos; + if (next_pos == pos + 1 && pal_pos != std::string::npos) { std::string::size_type pal_next_pos = palettes.find(';', pal_pos); diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 5ddd24e3..854753c1 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -28,8 +28,7 @@ #include "../log.h" -bool ImageWriter::writePNG(SDL_Surface *surface, - const std::string &filename) +bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) { // TODO Maybe someone can make this look nice? FILE *fp = fopen(filename.c_str(), "wb"); diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 00875a2d..f1ef3dad 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -25,7 +25,8 @@ #include "utils/stringutils.h" ShopItem::ShopItem (int inventoryIndex, int id, int quantity, int price) : - Item (id, 0), mPrice(price) + Item (id, 0), + mPrice(price) { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; setInvIndex(inventoryIndex); -- cgit v1.2.3-70-g09d2 From 798e9a37aff31dad38f48ea051322b978fcf849b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 19:18:08 -0600 Subject: Fixed popup comment. This got chopped off some time when it was first created. Signed-off-by: Ira Rice --- src/gui/popup.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/popup.h b/src/gui/popup.h index 37c99ded..639f2cc9 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -35,7 +35,11 @@ class WindowContainer; /** * A rather reduced down version of the Window class that is particularly suited - * for + * for popup type functionality that doesn't need to be resized or moved around + * by the mouse once created, but only needs to display some simple content, + * like a static message. Popups, in general, shouldn't also need to update + * their content once created, although this is not an explicit requirement to + * use the popup class. * * \ingroup GUI */ @@ -140,7 +144,7 @@ class Popup : public gcn::Container * @return The padding of the popup. * @see setPadding */ - unsigned int getPadding() const { return mPadding; } + int getPadding() const { return mPadding; } /** * Sets the padding of the popup. The padding is the distance between the -- cgit v1.2.3-70-g09d2 From 5561f4355ae1b1c167cd19575527ae0eae24e029 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 19:38:10 -0600 Subject: Removed getting and setting a parent window from the popup class, since this currently does not provide any useful functionality to popups, as well as doing anything for that matter. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 5 +---- src/gui/popup.h | 14 +------------- src/gui/speechbubble.cpp | 2 +- 3 files changed, 3 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 8dfc3c61..a27b1d90 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -25,7 +25,6 @@ #include "gui.h" #include "skin.h" #include "popup.h" -#include "window.h" #include "windowcontainer.h" #include "../configlistener.h" @@ -36,9 +35,7 @@ int Popup::instances = 0; -Popup::Popup(const std::string& name, Window *parent, - const std::string& skin): - mParent(parent), +Popup::Popup(const std::string& name, const std::string& skin): mPopupName(name), mDefaultSkinPath(skin), mMinWidth(100), diff --git a/src/gui/popup.h b/src/gui/popup.h index 639f2cc9..58ccd16e 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -30,7 +30,6 @@ class Skin; class SkinLoader; -class Window; class WindowContainer; /** @@ -52,12 +51,9 @@ class Popup : public gcn::Container * * @param name A human readable name for the popup. Only useful for * debugging purposes. - * @param parent The parent Window. This is the Window standing above - * this one in the Window hiearchy. When reordering, - * a Popup will never go below its parent Window. * @param skin The location where the Popup's skin XML can be found. */ - Popup(const std::string& name = "", Window *parent = NULL, + Popup(const std::string& name = "", const std::string &skin = "graphics/gui/gui.xml"); /** @@ -155,13 +151,6 @@ class Popup : public gcn::Container */ void setPadding(int padding) { mPadding = padding; } - /** - * Returns the parent Window. - * - * @return The parent Window or NULL if there is none. - */ - Window* getParentWindow() { return mParent; } - /** * Sets the name of the popup. This is only useful for debug purposes. */ @@ -183,7 +172,6 @@ class Popup : public gcn::Container virtual gcn::Rectangle getChildrenArea(); private: - Window *mParent; /**< The parent Window (if there is one) */ std::string mPopupName; /**< Name of the popup */ std::string mDefaultSkinPath; /**< Default skin path for this popup */ int mMinWidth; /**< Minimum popup width */ diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index ca771fce..cd483c30 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -34,7 +34,7 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Popup("Speech", NULL, "graphics/gui/speechbubble.xml"), + Popup("Speech", "graphics/gui/speechbubble.xml"), mText("") { setContentSize(140, 46); -- cgit v1.2.3-70-g09d2 From 2aab736bc5d77ffda789d7de56cef100fac207e1 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 19:50:12 -0600 Subject: Removed setting and getting parent windows for popup classes, as this wasn't really useful or used at all. Also removed some unneeded includes in the popup class. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 9 +-------- src/gui/popup.h | 3 --- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index a27b1d90..f4c7d4a3 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -22,19 +22,16 @@ #include -#include "gui.h" #include "skin.h" #include "popup.h" #include "windowcontainer.h" -#include "../configlistener.h" #include "../configuration.h" +#include "../graphics.h" #include "../log.h" #include "../resources/image.h" -int Popup::instances = 0; - Popup::Popup(const std::string& name, const std::string& skin): mPopupName(name), mDefaultSkinPath(skin), @@ -50,8 +47,6 @@ Popup::Popup(const std::string& name, const std::string& skin): setPadding(3); - instances++; - // Loads the skin mSkin = skinLoader->load(skin, mDefaultSkinPath); @@ -75,8 +70,6 @@ Popup::~Popup() delete(w); } - instances--; - mSkin->instances--; } diff --git a/src/gui/popup.h b/src/gui/popup.h index 58ccd16e..c68c2098 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -25,7 +25,6 @@ #include -#include "../graphics.h" #include "../guichanfwd.h" class Skin; @@ -180,8 +179,6 @@ class Popup : public gcn::Container int mMaxHeight; /**< Maximum popup height */ int mPadding; /**< Holds the padding of the popup. */ - static int instances; /**< Number of popup instances */ - Skin* mSkin; /**< Skin in use by this popup */ }; -- cgit v1.2.3-70-g09d2