diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:04 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:24 +0100 |
commit | dd05447445dc1766e532130318af2cb6bb72a994 (patch) | |
tree | c8b2cbac64ccf9545a39c143088b57fe2cb8e678 /src/gui | |
parent | 05e753294c1a603252d2eed4b1731c3f50543a7e (diff) | |
parent | 2aab736bc5d77ffda789d7de56cef100fac207e1 (diff) | |
download | mana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.gz mana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.bz2 mana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.xz mana-client-dd05447445dc1766e532130318af2cb6bb72a994.zip |
Merge branch 'aethyra/master'
Conflicts:
src/beingmanager.cpp
src/gui/confirm_dialog.cpp
src/gui/inventorywindow.cpp
src/gui/inventorywindow.h
src/gui/label.cpp
src/gui/label.h
src/gui/popup.cpp
src/gui/popup.h
src/gui/scrollarea.cpp
src/gui/skin.cpp
src/gui/skin.h
src/gui/speechbubble.cpp
src/gui/window.cpp
src/gui/window.h
src/localplayer.h
src/main.cpp
src/net/ea/playerhandler.cpp
src/resources/ambientoverlay.h
src/resources/dye.cpp
src/resources/imagewriter.cpp
src/resources/itemdb.cpp
src/shopitem.cpp
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/confirm_dialog.cpp | 47 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 11 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 18 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 5 | ||||
-rw-r--r-- | src/gui/itempopup.cpp | 51 | ||||
-rw-r--r-- | src/gui/ministatus.h | 1 | ||||
-rw-r--r-- | src/gui/ok_dialog.cpp | 38 | ||||
-rw-r--r-- | src/gui/ok_dialog.h | 3 | ||||
-rw-r--r-- | src/gui/palette.h | 1 | ||||
-rw-r--r-- | src/gui/popup.cpp | 98 | ||||
-rw-r--r-- | src/gui/popup.h | 65 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 6 | ||||
-rw-r--r-- | src/gui/scrollarea.cpp | 6 | ||||
-rw-r--r-- | src/gui/skin.cpp | 99 | ||||
-rw-r--r-- | src/gui/skin.h | 29 | ||||
-rw-r--r-- | src/gui/speechbubble.cpp | 4 | ||||
-rw-r--r-- | src/gui/storagewindow.cpp | 17 | ||||
-rw-r--r-- | src/gui/storagewindow.h | 4 | ||||
-rw-r--r-- | src/gui/window.cpp | 64 | ||||
-rw-r--r-- | src/gui/window.h | 54 |
20 files changed, 303 insertions, 318 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index a40593e3..e1c32759 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -47,37 +47,28 @@ 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; + + setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight + + noButton->getHeight()); + mTextArea->setDimension(gcn::Rectangle(4, 5, width + 2 * getPadding(), + height + getPadding())); - 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); + // 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); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 7ac9051f..96500e88 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -144,7 +144,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. @@ -248,13 +248,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 5a5d8db6..21d2df3f 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -44,7 +44,6 @@ #include "../resources/iteminfo.h" #include "../utils/gettext.h" -#include "../utils/stringutils.h" #include "../utils/strprintf.h" InventoryWindow::InventoryWindow(int invSize): @@ -92,7 +91,7 @@ InventoryWindow::InventoryWindow(int invSize): mTotalWeight = -1; mMaxWeight = -1; - mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed()); + mUsedSlots = -1; mSlotsLabel = new Label(_("Slots: ")); mWeightLabel = new Label(_("Weight: ")); @@ -137,29 +136,28 @@ void InventoryWindow::logic() updateButtons(); const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed(); - const std::string usedSlotsStr = toString(usedSlots); if (mMaxWeight != player_node->getMaxWeight() || - mTotalWeight != player_node->getTotalWeight() || - mUsedSlots != usedSlotsStr) + mTotalWeight != player_node->getTotalWeight() || + mUsedSlots != usedSlots) { mTotalWeight = player_node->getTotalWeight(); mMaxWeight = player_node->getMaxWeight(); - mUsedSlots = usedSlotsStr; + mUsedSlots = usedSlots; // Weight Bar coloration - if (mTotalWeight < (int) (mMaxWeight / 3)) + if (mTotalWeight < (mMaxWeight / 3)) mWeightBar->setColor(0, 0, 255); // Blue - else if (mTotalWeight < (int) ((mMaxWeight * 2) / 3)) + else if (mTotalWeight < ((mMaxWeight * 2) / 3)) mWeightBar->setColor(255, 255, 0); // Yellow else mWeightBar->setColor(255, 0, 0); // Red // Adjust progress bars - mSlotsBar->setProgress((float) usedSlots / mMaxSlots); + mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots); mWeightBar->setProgress((float) mTotalWeight / mMaxWeight); - mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots)); + mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots)); mWeightBar->setText(strprintf("%s/%s", Units::formatWeight(mTotalWeight).c_str(), Units::formatWeight(mMaxWeight).c_str())); diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 95a47bdb..0bdc8809 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -104,8 +104,9 @@ class InventoryWindow : public Window, std::string mWeight; std::string mSlots; - std::string mUsedSlots; - int mTotalWeight, mMaxWeight; + int mUsedSlots; + int mTotalWeight; + int mMaxWeight; gcn::Button *mUseButton; gcn::Button *mDropButton; #ifdef TMWSERV_SUPPORT diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 379e6029..66729605 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -40,7 +40,7 @@ #include "../utils/stringutils.h" ItemPopup::ItemPopup(): - Popup() + Popup("ItemPopup") { // Item Name mItemName = new gcn::Label; @@ -67,7 +67,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; @@ -78,12 +79,15 @@ 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); add(mItemEffectScroll); add(mItemWeightScroll); + + loadPopupConfiguration(); } ItemPopup::~ItemPopup() @@ -124,43 +128,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/ministatus.h b/src/gui/ministatus.h index f6d80ca7..fd5a4e53 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -27,6 +27,7 @@ #include <vector> class AnimatedSprite; +class Graphics; class ProgressBar; /** diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index f1a97b49..24ffa80c 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -30,7 +30,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; @@ -46,30 +46,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 24325c2f..46dd4db0 100644 --- a/src/gui/ok_dialog.h +++ b/src/gui/ok_dialog.h @@ -34,7 +34,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/palette.h b/src/gui/palette.h index a7172ce0..b2994351 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -307,6 +307,7 @@ class Palette : public gcn::ListModel { ColorElem::type = type; ColorElem::color = color; + ColorElem::testColor = color; ColorElem::text = text; ColorElem::ch = c; ColorElem::grad = grad; diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 47c3c43c..648a9d6a 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -20,66 +20,35 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <algorithm> -#include <cassert> -#include <climits> - #include <guichan/exception.hpp> -#include "gui.h" #include "skin.h" #include "popup.h" -#include "window.h" #include "windowcontainer.h" -#include "../configlistener.h" #include "../configuration.h" +#include "../graphics.h" #include "../log.h" #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): - mParent(parent), +Popup::Popup(const std::string &name, const std::string &skin): mPopupName(name), + 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()); 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++; - // Loads the skin - mSkin = skinLoader->load(skin); - - setGuiAlpha(); + mSkin = skinLoader->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -92,6 +61,8 @@ Popup::~Popup() { logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + savePopupConfiguration(); + while (!mWidgets.empty()) { gcn::Widget *w = mWidgets.front(); @@ -99,21 +70,40 @@ Popup::~Popup() delete(w); } - instances--; - mSkin->instances--; +} - if (instances == 0) +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) { - config.removeListener("guialpha", popupConfigListener); - delete popupConfigListener; - popupConfigListener = NULL; + mSkin->instances--; + mSkin = skinLoader->load(skinName, mDefaultSkinPath); } } -void Popup::setWindowContainer(WindowContainer *wc) +void Popup::savePopupConfiguration() { - windowContainer = wc; + 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) @@ -125,13 +115,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,14 +178,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 a0a64069..6fbe796c 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -25,38 +25,34 @@ #include <guichan/widgets/container.hpp> -#include "../graphics.h" #include "../guichanfwd.h" -class ConfigListener; class Skin; class SkinLoader; -class Window; class WindowContainer; /** - * A rather reduced down version of the Window class that is particularly - * suited for ... + * A rather reduced down version of the Window class that is particularly suited + * 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 */ class Popup : public gcn::Container { public: - friend class PopupConfigListener; - /** * Constructor. Initializes the title to the given text and hooks * itself into the popup 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"); /** @@ -70,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. */ void draw(gcn::Graphics *graphics); @@ -124,13 +132,6 @@ class Popup : public gcn::Container void setPadding(int padding) { mPadding = padding; } /** - * Returns the parent Window. - * - * @return The parent Window or <code>NULL</code> if there is none. - */ - Window *getParentWindow() const { return mParent; } - - /** * Sets the name of the popup. This is only useful for debug purposes. */ void setPopupName(const std::string &name) @@ -150,25 +151,15 @@ 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 */ - int mPadding; /**< Holds the padding of the window. */ - - /** - * The config listener that listens to changes relevant to all Popups. - */ - static ConfigListener *popupConfigListener; - - static int instances; /**< Number of Popup instances */ - - Skin *mSkin; /**< Skin in use by this Popup */ + 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 */ + int mPadding; /**< Holds the padding of the popup. */ + + Skin *mSkin; /**< Skin in use by this popup */ }; #endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index a99a14a1..0b019fef 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -51,7 +51,7 @@ extern std::string tradePartnerName; PopupMenu::PopupMenu(): - Window(), + Window("PopupMenu"), mBeingId(0), mFloorItem(NULL), mItem(NULL) @@ -64,8 +64,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/scrollarea.cpp b/src/gui/scrollarea.cpp index 834a7f3a..92bb94b8 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -215,9 +215,9 @@ void ScrollArea::drawFrame(gcn::Graphics *graphics) { if (mOpaque) { - int bs = getFrameSize(); - int w = getWidth() + bs * 2; - int h = getHeight() + bs * 2; + const int bs = getFrameSize(); + const int w = getWidth() + bs * 2; + const int h = getHeight() + bs * 2; static_cast<Graphics*>(graphics)-> drawImageRect(0, 0, w, h, background); diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index f7cc8ba1..0d62fea5 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -19,20 +19,36 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <algorithm> + #include "skin.h" +#include "../configuration.h" +#include "../configlistener.h" #include "../log.h" #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../utils/dtor.h" +#include "../utils/strprintf.h" #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): +Skin::Skin(ImageRect skin, Image *close, std::string filePath, std::string name): instances(0), + mFilePath(filePath), mName(name), border(skin), closeImage(close) @@ -51,6 +67,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); +} + int Skin::getMinWidth() const { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + @@ -63,32 +88,47 @@ int Skin::getMinHeight() const 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", ""); @@ -171,21 +211,42 @@ 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"); - Skin *skin = new Skin(border, closeImage); + Skin *skin = new Skin(border, closeImage, filename); 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 21bd84f2..1a603e29 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -27,12 +27,14 @@ #include "../graphics.h" +class ConfigListener; 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 +45,11 @@ class Skin std::string getName() { return mName; } /** + * Returns the skin's xml file path. + */ + std::string getFilePath() { return mFilePath; } + + /** * Returns the background skin. */ ImageRect getBorder() { return border; } @@ -67,9 +74,15 @@ class Skin */ int getMinHeight() const; + /** + * Updates the alpha value of the skin + */ + void updateAlpha(); + 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 */ @@ -84,16 +97,28 @@ typedef Skins::iterator SkinIterator; class SkinLoader { public: + friend class SkinConfigListener; + SkinLoader(); ~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 + */ + 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/speechbubble.cpp b/src/gui/speechbubble.cpp index b191ba77..4fb3409c 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") { setContentSize(140, 46); setMinWidth(29); @@ -59,6 +59,8 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); + + loadPopupConfiguration(); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 81212ae8..479348aa 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -50,7 +50,6 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/stringutils.h" StorageWindow::StorageWindow(Network *network, int invSize): Window(_("Storage")), @@ -74,7 +73,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: ")); @@ -107,14 +106,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)); } } @@ -166,7 +166,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 c78d33a7..cc0df2af 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -91,8 +91,8 @@ class StorageWindow : public Window, gcn::ActionListener, 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 b3b675e7..3bc03fb8 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -19,10 +19,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <algorithm> -#include <cassert> -#include <climits> - #include <guichan/exception.hpp> #include "gui.h" @@ -34,24 +30,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), @@ -59,14 +44,15 @@ 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), 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()); @@ -74,13 +60,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(); - windowConfigListener = new WindowConfigListener; - // Send GUI alpha changed for initialization - windowConfigListener->optionChanged("guialpha"); - config.addListener("guialpha", windowConfigListener); - } instances++; @@ -89,9 +69,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, const std setTitleBarHeight(20); // Loads the skin - mSkin = skinLoader->load(skin); - - setGuiAlpha(); + mSkin = skinLoader->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -130,12 +108,7 @@ Window::~Window() mSkin->instances--; if (instances == 0) - { delete skinLoader; - config.removeListener("guialpha", windowConfigListener); - delete windowConfigListener; - windowConfigListener = NULL; - } } void Window::setWindowContainer(WindowContainer *wc) @@ -169,14 +142,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); } @@ -499,12 +464,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); @@ -535,6 +508,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) { @@ -667,18 +641,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 46744699..c41a4221 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -29,7 +29,6 @@ #include "../graphics.h" #include "../guichanfwd.h" -class ConfigListener; class ContainerPlacer; class Layout; class LayoutCell; @@ -47,8 +46,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. @@ -320,35 +317,28 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); - void setGuiAlpha(); - - 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 */ - static 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 */ - - /** - * 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 */ - - Skin* mSkin; /**< Skin in use by this window */ + 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 |