diff options
Diffstat (limited to 'src/gui/widgets')
55 files changed, 679 insertions, 259 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index cc2c7d6a..60837ea1 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -24,10 +24,10 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/theme.h" #include "resources/image.h" #include "resources/resourcemanager.h" +#include "resources/theme.h" #include "utils/stringutils.h" diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index b74e4e0e..d553312b 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -24,10 +24,10 @@ #include "client.h" -#include "gui/theme.h" - #include "gui/widgets/linkhandler.h" +#include "resources/theme.h" + #include <guichan/graphics.hpp> #include <guichan/font.hpp> #include <guichan/cliprectangle.hpp> diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 54a2a8cc..28ec734a 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -72,14 +72,8 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener { public: - /** - * Constructor. - */ BrowserBox(unsigned int mode = AUTO_SIZE, bool opaque = true); - /** - * Destructor. - */ ~BrowserBox(); /** diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 26e0ad90..f072ef61 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -25,9 +25,9 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/theme.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -36,6 +36,7 @@ int Button::mInstances = 0; float Button::mAlpha = 1.0; +ImageRect *Button::mButton; enum{ BUTTON_STANDARD, // 0 @@ -59,22 +60,73 @@ static ButtonData const data[BUTTON_COUNT] = { { "button_disabled.png", 25, 23 } }; -ImageRect Button::button[BUTTON_COUNT]; - -Button::Button() +Button::Button(): + mButtonIcon(0) { init(); + adjustSize(); } Button::Button(const std::string &caption, const std::string &actionEventId, gcn::ActionListener *listener): - gcn::Button(caption) + gcn::Button(caption), + mButtonIcon(0) { init(); setActionEventId(actionEventId); if (listener) addActionListener(listener); + + adjustSize(); +} + +void Button::setButtonIcon(const std::string& iconFile, int frameHeight, + int frameWidth) +{ + // We clean up possible older references. + if (mButtonIcon) + removeButtonIcon(); + + // If nothing relevant was set, we can quit now. + if (iconFile.empty() || !frameWidth || !frameHeight) + return; + + // Load the icon frames. + Image *btnIcons = Theme::getImageFromTheme(iconFile); + if (!btnIcons) + return; + + if (btnIcons->getWidth() > 0 && btnIcons->getHeight() > 0) + { + mButtonIcon = new Image*[BUTTON_COUNT]; + for (int mode = 0; mode < BUTTON_COUNT; ++mode) + { + mButtonIcon[mode] = btnIcons->getSubImage(mode * frameWidth, 0, + frameWidth, frameHeight); + } + + adjustSize(); + } + + btnIcons->decRef(); +} + +void Button::removeButtonIcon() +{ + if (!mButtonIcon) + return; + + // Delete potential button icons + for (int mode = 0; mode < BUTTON_COUNT; ++mode) + { + delete mButtonIcon[mode]; + mButtonIcon[mode] = 0; + } + delete[] mButtonIcon; + mButtonIcon = 0; + + adjustSize(); } void Button::init() @@ -85,10 +137,11 @@ void Button::init() { // Load the skin Image *btn[BUTTON_COUNT]; + mButton = new ImageRect[BUTTON_COUNT]; int a, x, y, mode; - for (mode = 0; mode < BUTTON_COUNT; mode++) + for (mode = 0; mode < BUTTON_COUNT; ++mode) { btn[mode] = Theme::getImageFromTheme(data[mode].file); a = 0; @@ -96,7 +149,7 @@ void Button::init() { for (x = 0; x < 3; x++) { - button[mode].grid[a] = btn[mode]->getSubImage( + mButton[mode].grid[a] = btn[mode]->getSubImage( data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, data[y + 1].gridY - data[y].gridY + 1); @@ -116,27 +169,28 @@ Button::~Button() if (mInstances == 0) { - for (int mode = 0; mode < BUTTON_COUNT; mode++) + for (int mode = 0; mode < BUTTON_COUNT; ++mode) { - for_each(button[mode].grid, button[mode].grid + 9, dtor<Image*>()); + for_each(mButton[mode].grid, mButton[mode].grid + 9, + dtor<Image*>()); } + delete[] mButton; } + removeButtonIcon(); } void Button::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8f), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { mAlpha = alpha; - for (int a = 0; a < 9; a++) + for (int mode = 0; mode < BUTTON_COUNT; ++mode) { - button[BUTTON_DISABLED].grid[a]->setAlpha(mAlpha); - button[BUTTON_PRESSED].grid[a]->setAlpha(mAlpha); - button[BUTTON_HIGHLIGHTED].grid[a]->setAlpha(mAlpha); - button[BUTTON_STANDARD].grid[a]->setAlpha(mAlpha); + for (int a = 0; a < 9; ++a) + mButton[mode].grid[a]->setAlpha(mAlpha); } } } @@ -157,35 +211,93 @@ void Button::draw(gcn::Graphics *graphics) updateAlpha(); static_cast<Graphics*>(graphics)-> - drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); + drawImageRect(0, 0, getWidth(), getHeight(), mButton[mode]); if (mode == BUTTON_DISABLED) graphics->setColor(Theme::getThemeColor(Theme::BUTTON_DISABLED)); else graphics->setColor(Theme::getThemeColor(Theme::BUTTON)); - int textX; + int textX = 0; int textY = getHeight() / 2 - getFont()->getHeight() / 2; + int btnIconX = 0; + int btnIconY = getHeight() / 2 + - ((mButtonIcon && mButtonIcon[mode]) ? + mButtonIcon[mode]->getHeight() / 2 : 0); + + int btnIconWidth = (mButtonIcon && mButtonIcon[mode]) ? + mButtonIcon[mode]->getWidth() : 0; switch (getAlignment()) { case gcn::Graphics::LEFT: - textX = 4; + if (btnIconWidth) + { + btnIconX = 4; + textX = btnIconX + mButtonIcon[mode]->getWidth() + 2; + } + else + { + textX = 4; + } break; case gcn::Graphics::CENTER: - textX = getWidth() / 2; + if (btnIconWidth) + { + btnIconX = getWidth() / 2 - (getFont()->getWidth(mCaption) + + mButtonIcon[mode]->getWidth() + 2) / 2; + textX = getWidth() / 2 + mButtonIcon[mode]->getWidth() / 2 + 2; + } + else + { + textX = getWidth() / 2; + } break; case gcn::Graphics::RIGHT: + if (btnIconWidth) + btnIconX = getWidth() - 4 - getFont()->getWidth(mCaption) - 2; textX = getWidth() - 4; break; default: - throw GCN_EXCEPTION("Button::draw. Unknown alignment."); + throw GCN_EXCEPTION("Button::draw(). Unknown alignment."); } graphics->setFont(getFont()); if (isPressed()) - graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); - else - graphics->drawText(getCaption(), textX, textY, getAlignment()); + { + textX++; textY++; + btnIconX++; btnIconY++; + } + + if (btnIconWidth) + static_cast<Graphics*>(graphics)->drawImage(mButtonIcon[mode], + btnIconX, btnIconY); + graphics->drawText(getCaption(), textX, textY, getAlignment()); +} + +void Button::adjustSize() +{ + // Size of the image button. + int iconWidth = 0, iconHeight = 0; + if (mButtonIcon) + { + for (int mode = 0; mode < BUTTON_COUNT; ++mode) + { + iconWidth = std::max(iconWidth, mButtonIcon[mode] ? + mButtonIcon[mode]->getWidth() + 2 : 0); + iconHeight = std::max(iconHeight, mButtonIcon[mode] ? + mButtonIcon[mode]->getHeight() : 0); + } + } + + setWidth(std::max(getFont()->getWidth(mCaption) + iconWidth + 2, iconWidth) + + 2 * mSpacing); + setHeight(std::max(getFont()->getHeight(), iconHeight) + 2 * mSpacing); +} + +void Button::setCaption(const std::string& caption) +{ + mCaption = caption; + adjustSize(); } diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index aa37261e..6d8f773c 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -25,6 +25,7 @@ #include <guichan/widgets/button.hpp> class ImageRect; +class Image; /** * Button widget. Same as the Guichan button but with custom look. @@ -46,9 +47,6 @@ class Button : public gcn::Button Button(const std::string &caption, const std::string &actionEventId, gcn::ActionListener *listener); - /** - * Destructor. - */ ~Button(); /** @@ -61,12 +59,31 @@ class Button : public gcn::Button */ void updateAlpha(); + void adjustSize(); + + void setCaption(const std::string& caption); + + /** + * Set the icons available next to the text + * + * @note: The image given must be formatted to give horizontally + * frames of the given width and height for the following states: + * Standard, Highlighted, Pressed, and Disabled. + * If the image is too short, the missing states won't be loaded. + */ + void setButtonIcon(const std::string& iconFile = std::string(), + int frameHeight = 0, int frameWidth = 0); + private: void init(); - static ImageRect button[4]; /**< Button state graphics */ - static int mInstances; /**< Number of button instances */ + void removeButtonIcon(); + + static ImageRect* mButton; /**< Button state graphics */ + static int mInstances; /**< Number of button instances */ static float mAlpha; + + Image** mButtonIcon; /**< Button Icons graphics */ }; #endif diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h index 842b80f7..0272655b 100644 --- a/src/gui/widgets/channeltab.h +++ b/src/gui/widgets/channeltab.h @@ -43,14 +43,8 @@ class ChannelTab : public ChatTab protected: friend class Channel; - /** - * Constructor. - */ ChannelTab(Channel *channel); - /** - * Destructor. - */ ~ChannelTab(); void handleInput(const std::string &msg); diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index bbb2b8bb..c86eb2ea 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -21,7 +21,8 @@ #include "gui/widgets/chattab.h" -#include "beingmanager.h" +#include "actorspritemanager.h" +#include "chatlog.h" #include "commandhandler.h" #include "configuration.h" #include "localplayer.h" @@ -51,7 +52,7 @@ ChatTab::ChatTab(const std::string &name) : Tab() mTextOutput = new BrowserBox(BrowserBox::AUTO_WRAP); mTextOutput->setOpaque(false); - mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0)); + mTextOutput->setMaxRow((int) config.getIntValue("ChatLogLength")); mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler); mTextOutput->setAlwaysUpdate(false); @@ -73,7 +74,7 @@ ChatTab::~ChatTab() delete mScrollArea; } -void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) +void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) { // Trim whitespace trim(line); @@ -182,6 +183,9 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) line = lineColor + timeStr.str() + tmp.nick + tmp.text; + if (config.getBoolValue("enableChatLog")) + saveToLogFile(line); + // We look if the Vertical Scroll Bar is set at the max before // adding a row, otherwise the max will always be a row higher // at comparison. @@ -234,7 +238,7 @@ void ChatTab::chatInput(const std::string &message) std::string temp = msg.substr(start + 1, end - start - 1); - const ItemInfo itemInfo = ItemDB::get(temp); + const ItemInfo itemInfo = itemDb->get(temp); if (itemInfo.getId() != 0) { msg.insert(end, "@@"); @@ -279,7 +283,13 @@ void ChatTab::handleCommand(const std::string &msg) void ChatTab::getAutoCompleteList(std::vector<std::string> &names) const { - beingManager->getPlayerNPCNameLister()->getAutoCompleteList(names); + actorSpriteManager->getPlayerNPCNameLister()->getAutoCompleteList(names); +} + +void ChatTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log(msg); } void ChatTab::addRow(std::string &line) diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index c2dfa1c1..6d262e11 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -31,27 +31,12 @@ class BrowserBox; class Recorder; class ScrollArea; -enum -{ - BY_GM, - BY_PLAYER, - BY_OTHER, - BY_SERVER, - BY_CHANNEL, - ACT_WHISPER, // getting whispered at - ACT_IS, // equivalent to "/me" on IRC - BY_LOGGER -}; - /** * A tab for the chat window. This is special to ease chat handling. */ class ChatTab : public Tab, public AutoCompleteLister { public: - /** - * Constructor. - */ ChatTab(const std::string &name); ~ChatTab(); @@ -63,7 +48,8 @@ class ChatTab : public Tab, public AutoCompleteLister * @param channelName which channel to send the message to. * @param ignoreRecord should this not be recorded? */ - void chatLog(std::string line, int own = BY_SERVER, bool ignoreRecord = false); + void chatLog(std::string line, Own own = BY_SERVER, + bool ignoreRecord = false); /** * Adds the text to the message list @@ -112,8 +98,11 @@ class ChatTab : public Tab, public AutoCompleteLister const std::string &args) { return false; } + void getAutoCompleteList(std::vector<std::string> &names) const; + virtual void saveToLogFile(std::string &msg); + protected: friend class ChatWindow; friend class WhisperWindow; diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index f9002166..6a44132d 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -25,9 +25,9 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/theme.h" #include "resources/image.h" +#include "resources/theme.h" int CheckBox::instances = 0; float CheckBox::mAlpha = 1.0; @@ -92,8 +92,8 @@ void CheckBox::draw(gcn::Graphics* graphics) void CheckBox::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8f), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index a7daa52d..27962f72 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -34,14 +34,8 @@ class Image; class CheckBox : public gcn::CheckBox { public: - /** - * Constructor. - */ CheckBox(const std::string &caption, bool selected = false); - /** - * Destructor. - */ ~CheckBox(); /** diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 6c3417e7..ced9c38b 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -26,12 +26,12 @@ #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/theme.h" #include "gui/widgets/listbox.h" #include "gui/widgets/scrollarea.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -110,8 +110,8 @@ DropDown::~DropDown() void DropDown::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8f), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 82fb9f8d..f7a6ca2b 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -20,11 +20,11 @@ #include "gui/widgets/emoteshortcutcontainer.h" -#include "animatedsprite.h" #include "configuration.h" #include "emoteshortcut.h" #include "graphics.h" #include "inventory.h" +#include "imagesprite.h" #include "item.h" #include "itemshortcut.h" #include "keyboardconfig.h" @@ -32,10 +32,10 @@ #include "log.h" #include "gui/palette.h" -#include "gui/theme.h" #include "resources/emotedb.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -51,12 +51,12 @@ EmoteShortcutContainer::EmoteShortcutContainer(): mBackgroundImg = Theme::getImageFromTheme("item_shortcut_bgr.png"); - mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); + mBackgroundImg->setAlpha(config.getFloatValue("guialpha")); // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(EmoteDB::getAnimation(i)); + mEmoteImg.push_back(EmoteDB::get(i)->sprite); } mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS; @@ -72,9 +72,9 @@ EmoteShortcutContainer::~EmoteShortcutContainer() void EmoteShortcutContainer::draw(gcn::Graphics *graphics) { - if (config.getValue("guialpha", 0.8) != mAlpha) + if (config.getFloatValue("guialpha") != mAlpha) { - mAlpha = config.getValue("guialpha", 0.8); + mAlpha = config.getFloatValue("guialpha"); mBackgroundImg->setAlpha(mAlpha); } @@ -106,7 +106,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (mEmoteMoved) { // Draw the emote image being dragged by the cursor. - const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; + const ImageSprite* sprite = mEmoteImg[mEmoteMoved - 1]; if (sprite) { const int tPosX = mCursorPosX - (sprite->getWidth() / 2); diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h index e90612b4..0021d838 100644 --- a/src/gui/widgets/emoteshortcutcontainer.h +++ b/src/gui/widgets/emoteshortcutcontainer.h @@ -25,8 +25,7 @@ #include <vector> -class AnimatedSprite; -class Image; +class ImageSprite; /** * An emote shortcut container. Used to quickly use emoticons. @@ -36,14 +35,8 @@ class Image; class EmoteShortcutContainer : public ShortcutContainer { public: - /** - * Constructor. Initializes the graphic. - */ EmoteShortcutContainer(); - /** - * Destructor. - */ virtual ~EmoteShortcutContainer(); /** @@ -67,7 +60,7 @@ class EmoteShortcutContainer : public ShortcutContainer void mouseReleased(gcn::MouseEvent &event); private: - std::vector<const AnimatedSprite*> mEmoteImg; + std::vector<const ImageSprite*> mEmoteImg; bool mEmoteClicked; int mEmoteMoved; diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h index a0e8dbf5..ee9f634b 100644 --- a/src/gui/widgets/flowcontainer.h +++ b/src/gui/widgets/flowcontainer.h @@ -34,17 +34,9 @@ class FlowContainer : public Container, public gcn::WidgetListener { public: - /** - * Constructor. Initializes the shortcut container. - */ FlowContainer(int boxWidth, int boxHeight); /** - * Destructor. - */ - ~FlowContainer() {} - - /** * Invoked when a widget changes its size. This is used to determine * the new height of the container. */ diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h index 27ed0db8..7b297756 100644 --- a/src/gui/widgets/icon.h +++ b/src/gui/widgets/icon.h @@ -36,6 +36,8 @@ class Icon : public gcn::Widget public: /** * Constructor. + * + * @param filename The file name of the image to display */ Icon(const std::string &filename); @@ -44,7 +46,7 @@ class Icon : public gcn::Widget */ Icon(Image *image); - /** + /** * Gets the current Image. */ Image *getImage() const { return mImage; } diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index fb5105b2..2cd0fa23 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -32,7 +32,6 @@ #include "gui/outfitwindow.h" #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "net/net.h" @@ -40,6 +39,7 @@ #include "resources/image.h" #include "resources/iteminfo.h" +#include "resources/theme.h" #include "utils/stringutils.h" @@ -101,14 +101,38 @@ void ItemContainer::draw(gcn::Graphics *graphics) g->setFont(getFont()); + mFilteredMap.clear(); + int currentIndex = 0; + //Filter checking + for (int i = 0; i < mGridColumns; i++) + { + for (int j = 0; j < mGridRows; j++) + { + int itemIndex = j * mGridColumns + i; + Item *item = mInventory->getItem(itemIndex); + if (!item || item->getId() == 0) + continue; + + if (mFilter.size() > 0) + { + if (normalize(item->getInfo().getName()).find(mFilter) == std::string::npos) + continue; + } + + mFilteredMap[currentIndex] = item; + currentIndex++; + } + } + for (int i = 0; i < mGridColumns; i++) { for (int j = 0; j < mGridRows; j++) { int itemX = i * BOX_WIDTH; int itemY = j * BOX_HEIGHT; - int itemIndex = (j * mGridColumns) + i; - Item *item = mInventory->getItem(itemIndex); + int itemIndex = j * mGridColumns + i; + + Item *item = getItemAt(itemIndex); if (!item || item->getId() == 0) continue; @@ -178,7 +202,18 @@ void ItemContainer::setSelectedIndex(int newIndex) Item *ItemContainer::getSelectedItem() const { - return mInventory->getItem(mSelectedIndex); + return getItemAt(mSelectedIndex); +} + +Item *ItemContainer::getItemAt(int index) const +{ + std::map<int, Item*>::const_iterator i = mFilteredMap.find(index); + return i == mFilteredMap.end() ? 0 : i->second; +} + +void ItemContainer::setFilter(const std::string &filter) +{ + mFilter = normalize(filter); } void ItemContainer::distributeValueChangedEvent() @@ -243,9 +278,19 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) { const int index = getSlotIndex(event.getX(), event.getY()); if (index == Inventory::NO_SLOT_INDEX) + { + mSelectionStatus = SEL_DESELECTING; return; + } + + Item *item = getItemAt(index); + + if (!item) + { + mSelectionStatus = SEL_DESELECTING; + return; + } - Item *item = mInventory->getItem(index); // put item name into chat window if (mDescItems) @@ -255,7 +300,6 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) if (mSelectedIndex == index) { - mSelectionStatus = SEL_DESELECTING; } else if (item && item->getId()) { @@ -263,7 +307,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) mSelectionStatus = SEL_SELECTING; itemShortcut->setItemSelected(item->getId()); - if (item->isEquipment()) + if (item->getInfo().getEquippable()) outfitWindow->setItemSelected(item->getId()); } else @@ -305,7 +349,14 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event) return; if (index == mSelectedIndex || mSelectedIndex == -1) return; - Net::getInventoryHandler()->moveItem(mSelectedIndex, index); + + Item *item = getSelectedItem(); + { + Event event(Event::DoMove); + event.setItem("item", item); + event.setInt("newIndex", index); + event.trigger(Event::ItemChannel); + } selectNone(); } @@ -313,7 +364,7 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event) // Show ItemTooltip void ItemContainer::mouseMoved(gcn::MouseEvent &event) { - Item *item = mInventory->getItem(getSlotIndex(event.getX(), event.getY())); + Item *item = getItemAt(getSlotIndex(event.getX(), event.getY())); if (item) { @@ -372,8 +423,11 @@ void ItemContainer::keyAction() mSelectedIndex != -1 && mHighlightedIndex != -1) { - Net::getInventoryHandler()->moveItem( - mSelectedIndex, mHighlightedIndex); + Item *item = getSelectedItem(); + Event event(Event::DoMove); + event.setItem("item", item); + event.setInt("newIndex", mHighlightedIndex); + event.trigger(Event::ItemChannel); setSelectedIndex(mHighlightedIndex); } // If the highlight is on an item then select it. @@ -385,8 +439,11 @@ void ItemContainer::keyAction() // If the highlight is on a blank space then move it. else if (mSelectedIndex != -1) { - Net::getInventoryHandler()->moveItem( - mSelectedIndex, mHighlightedIndex); + Item *item = getSelectedItem(); + Event event(Event::DoMove); + event.setItem("item", item); + event.setInt("newIndex", mHighlightedIndex); + event.trigger(Event::ItemChannel); selectNone(); } } diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 38ccf9ca..ca21ad3f 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -27,6 +27,7 @@ #include <guichan/widget.hpp> #include <guichan/widgetlistener.hpp> +#include <map> #include <list> class Image; @@ -59,9 +60,6 @@ class ItemContainer : public gcn::Widget, */ ItemContainer(Inventory *inventory, bool forceQuantity = false); - /** - * Destructor. - */ virtual ~ItemContainer(); /** @@ -98,6 +96,12 @@ class ItemContainer : public gcn::Widget, */ void selectNone(); + + /** + * Sets item filter + */ + void setFilter(const std::string &filter); + /** * Adds a listener to the list that's notified each time a change to * the selection occurs. @@ -170,6 +174,8 @@ class ItemContainer : public gcn::Widget, */ int getSlotIndex(int x, int y) const; + Item *getItemAt(int) const; + Inventory *mInventory; int mGridColumns, mGridRows; Image *mSelImg; @@ -181,6 +187,10 @@ class ItemContainer : public gcn::Widget, bool mDescItems; int mDragPosX, mDragPosY; + std::map<int, Item*> mFilteredMap; + + std::string mFilter; + ItemPopup *mItemPopup; typedef std::list<gcn::SelectionListener*> SelectionListenerList; diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index b7341084..8477225f 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -49,7 +49,7 @@ void ItemLinkHandler::handleLink(const std::string &link) if (id > 0) { - const ItemInfo &itemInfo = ItemDB::get(id); + const ItemInfo &itemInfo = itemDb->get(id); mItemPopup->setItem(itemInfo, true); if (mItemPopup->isVisible()) diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 682d71e5..fb4f558f 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -27,16 +27,16 @@ #include "item.h" #include "itemshortcut.h" #include "keyboardconfig.h" -#include "localplayer.h" +#include "playerinfo.h" #include "gui/inventorywindow.h" #include "gui/itempopup.h" #include "gui/palette.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "resources/image.h" #include "resources/iteminfo.h" +#include "resources/theme.h" #include "utils/stringutils.h" @@ -53,7 +53,7 @@ ItemShortcutContainer::ItemShortcutContainer(): mBackgroundImg = Theme::getImageFromTheme("item_shortcut_bgr.png"); mMaxItems = itemShortcut->getItemCount(); - mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); + mBackgroundImg->setAlpha(config.getFloatValue("guialpha")); mBoxHeight = mBackgroundImg->getHeight(); mBoxWidth = mBackgroundImg->getWidth(); @@ -67,9 +67,9 @@ ItemShortcutContainer::~ItemShortcutContainer() void ItemShortcutContainer::draw(gcn::Graphics *graphics) { - if (config.getValue("guialpha", 0.8) != mAlpha) + if (config.getFloatValue("guialpha") != mAlpha) { - mAlpha = config.getValue("guialpha", 0.8); + mAlpha = config.getFloatValue("guialpha"); mBackgroundImg->setAlpha(mAlpha); } @@ -94,7 +94,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) continue; Item *item = - player_node->getInventory()->findItem(itemShortcut->getItem(i)); + PlayerInfo::getInventory()->findItem(itemShortcut->getItem(i)); if (item) { @@ -152,7 +152,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) if (itemId < 0) return; - Item *item = player_node->getInventory()->findItem(itemId); + Item *item = PlayerInfo::getInventory()->findItem(itemId); if (item) { @@ -188,7 +188,7 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) } else if (event.getButton() == gcn::MouseEvent::RIGHT) { - Item *item = player_node->getInventory()-> + Item *item = PlayerInfo::getInventory()-> findItem(itemShortcut->getItem(index)); if (!item) @@ -241,7 +241,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) if (itemId < 0) return; - Item *item = player_node->getInventory()->findItem(itemId); + Item *item = PlayerInfo::getInventory()->findItem(itemId); if (item) { diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h index 9ec3f4c1..80f29c7b 100644 --- a/src/gui/widgets/itemshortcutcontainer.h +++ b/src/gui/widgets/itemshortcutcontainer.h @@ -38,14 +38,8 @@ class ItemPopup; class ItemShortcutContainer : public ShortcutContainer { public: - /** - * Constructor. Initializes the graphic. - */ ItemShortcutContainer(); - /** - * Destructor. - */ virtual ~ItemShortcutContainer(); /** diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 4c607edf..939e9fc0 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -20,19 +20,20 @@ #include "gui/widgets/label.h" -#include "gui/theme.h" +#include "resources/theme.h" Label::Label() { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } Label::Label(const std::string &caption) : gcn::Label(caption) { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } void Label::draw(gcn::Graphics *graphics) { - setForegroundColor(Theme::getThemeColor(Theme::TEXT)); gcn::Label::draw(static_cast<gcn::Graphics*>(graphics)); } diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h index 2dfa254c..6b9cd2a8 100644 --- a/src/gui/widgets/label.h +++ b/src/gui/widgets/label.h @@ -1,6 +1,6 @@ /* * The Mana Client - * Copyright (c) 2009 Aethyra Development Team + * Copyright (c) 2009 Aethyra Development Team * * This file is part of The Mana Client. * @@ -32,9 +32,6 @@ class Label : public gcn::Label { public: - /** - * Constructor. - */ Label(); /** diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h index cf966029..0aeabb0d 100644 --- a/src/gui/widgets/layouthelper.h +++ b/src/gui/widgets/layouthelper.h @@ -34,14 +34,8 @@ class LayoutHelper : public gcn::WidgetListener { public: - /** - * Constructor. - */ LayoutHelper(gcn::Container *container); - /** - * Destructor. - */ ~LayoutHelper(); /** diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index ef591023..a3dafe72 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -25,7 +25,8 @@ #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/theme.h" + +#include "resources/theme.h" #include <guichan/font.hpp> #include <guichan/graphics.hpp> @@ -45,8 +46,8 @@ ListBox::~ListBox() void ListBox::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) mAlpha = alpha; @@ -117,14 +118,31 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } } -// Don't do anything on scrollwheel. ScrollArea will deal with that. +void ListBox::mousePressed(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() != gcn::MouseEvent::LEFT) + return; + + int y = std::max(0, mouseEvent.getY()); + if (y / (int)getRowHeight() < getListModel()->getNumberOfElements()) + { + setSelected(y / getRowHeight()); + distributeActionEvent(); + } + else + { + setSelected(-1); + } +} void ListBox::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) { + // Don't do anything on scrollwheel. ScrollArea will deal with that. } void ListBox::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) { + // Don't do anything on scrollwheel. ScrollArea will deal with that. } void ListBox::mouseDragged(gcn::MouseEvent &event) @@ -134,5 +152,6 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) // Make list selection update on drag, but guard against negative y int y = std::max(0, event.getY()); - setSelected(y / getRowHeight()); + if (y / (int)getRowHeight() < getListModel()->getNumberOfElements()) + setSelected(y / getRowHeight()); } diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 8b8c8b54..61c564bb 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -36,14 +36,21 @@ class SelectionListener; class ListBox : public gcn::ListBox { public: - /** - * Constructor. - */ ListBox(gcn::ListModel *listModel); ~ListBox(); /** + * Sets the font to render the text in. + * + * @param font the font to use. + */ + inline void setFont(gcn::Font *font) + { + mFont = font; + } + + /** * Draws the list box. */ void draw(gcn::Graphics *graphics); @@ -59,12 +66,17 @@ class ListBox : public gcn::ListBox // Inherited from MouseListener + void mousePressed(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); void mouseDragged(gcn::MouseEvent &event); + private: + gcn::Font *mFont; + protected: static float mAlpha; }; diff --git a/src/gui/widgets/passwordfield.h b/src/gui/widgets/passwordfield.h index 619cd842..0058233c 100644 --- a/src/gui/widgets/passwordfield.h +++ b/src/gui/widgets/passwordfield.h @@ -35,7 +35,7 @@ class PasswordField : public TextField /** * Constructor, initializes the password field with the given string. */ - PasswordField(const std::string &text = ""); + PasswordField(const std::string &text = std::string()); /** * Draws the password field. diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 57cbec6f..f71889bb 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -22,13 +22,12 @@ #include "gui/widgets/playerbox.h" #include "animatedsprite.h" +#include "being.h" #include "configuration.h" #include "graphics.h" -#include "player.h" - -#include "gui/theme.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -36,8 +35,8 @@ int PlayerBox::instances = 0; float PlayerBox::mAlpha = 1.0; ImageRect PlayerBox::background; -PlayerBox::PlayerBox(const Player *player): - mPlayer(player) +PlayerBox::PlayerBox(const Being *being): + mBeing(being) { setFrameSize(2); @@ -57,7 +56,7 @@ PlayerBox::PlayerBox(const Player *player): bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, bggridy[y + 1] - bggridy[y] + 1); - background.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + background.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } @@ -72,7 +71,7 @@ PlayerBox::~PlayerBox() { instances--; - mPlayer = 0; + mBeing = 0; if (instances == 0) { @@ -82,20 +81,20 @@ PlayerBox::~PlayerBox() void PlayerBox::draw(gcn::Graphics *graphics) { - if (mPlayer) + if (mBeing) { // Draw character const int bs = getFrameSize(); const int x = getWidth() / 2 + bs; const int y = getHeight() - bs; - mPlayer->drawSpriteAt(static_cast<Graphics*>(graphics), x, y); + mBeing->drawSpriteAt(static_cast<Graphics*>(graphics), x, y); } - if (config.getValue("guialpha", 0.8) != mAlpha) + if (config.getFloatValue("guialpha") != mAlpha) { for (int a = 0; a < 9; a++) { - background.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + background.grid[a]->setAlpha(config.getFloatValue("guialpha")); } } } diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 33b4a628..f6e70ef7 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -24,8 +24,8 @@ #include <guichan/widgets/scrollarea.hpp> +class Being; class ImageRect; -class Player; /** * A box showing a player character. @@ -39,11 +39,8 @@ class PlayerBox : public gcn::ScrollArea * Constructor. Takes the initial player character that this box should * display, which defaults to <code>NULL</code>. */ - PlayerBox(const Player *player = 0); + PlayerBox(const Being *being = 0); - /** - * Destructor. - */ ~PlayerBox(); /** @@ -51,7 +48,8 @@ class PlayerBox : public gcn::ScrollArea * player to <code>NULL</code> causes the box not to draw any * character. */ - void setPlayer(const Player *player) { mPlayer = player; } + void setPlayer(const Being *being) + { mBeing = being; } /** * Draws the scroll area. @@ -64,7 +62,7 @@ class PlayerBox : public gcn::ScrollArea void drawFrame(gcn::Graphics *graphics); private: - const Player *mPlayer; /**< The character used for display */ + const Being *mBeing; /**< The character used for display */ static float mAlpha; static int instances; diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 4dc58f72..e242bcf4 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -26,12 +26,12 @@ #include "graphics.h" #include "log.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/windowcontainer.h" #include "resources/image.h" +#include "resources/theme.h" #include <guichan/exception.hpp> diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 028658ab..15838952 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -27,9 +27,9 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/theme.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -123,8 +123,8 @@ void ProgressBar::logic() void ProgressBar::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index 6bda617f..91b40751 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -23,11 +23,10 @@ #include "graphics.h" #include "simpleanimation.h" -#include "gui/theme.h" - #include "resources/animation.h" #include "resources/imageset.h" #include "resources/resourcemanager.h" +#include "resources/theme.h" #include <guichan/widgets/label.hpp> diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 96797225..1296feb6 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -24,9 +24,8 @@ #include "configuration.h" #include "graphics.h" -#include "gui/theme.h" - #include "resources/image.h" +#include "resources/theme.h" int RadioButton::instances = 0; float RadioButton::mAlpha = 1.0; @@ -78,9 +77,9 @@ RadioButton::~RadioButton() void RadioButton::drawBox(gcn::Graphics* graphics) { - if (config.getValue("guialpha", 0.8) != mAlpha) + if (config.getFloatValue("guialpha") != mAlpha) { - mAlpha = config.getValue("guialpha", 0.8); + mAlpha = config.getFloatValue("guialpha"); radioNormal->setAlpha(mAlpha); radioChecked->setAlpha(mAlpha); radioDisabled->setAlpha(mAlpha); diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h index 7f839ea5..f8aa40f1 100644 --- a/src/gui/widgets/radiobutton.h +++ b/src/gui/widgets/radiobutton.h @@ -32,15 +32,9 @@ class Image; class RadioButton : public gcn::RadioButton { public: - /** - * Constructor. - */ RadioButton(const std::string &caption,const std::string &group, bool marked = false); - /** - * Destructor. - */ ~RadioButton(); /** diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index f0c3691c..7850643f 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -24,9 +24,8 @@ #include "configuration.h" #include "graphics.h" -#include "gui/theme.h" - #include "resources/image.h" +#include "resources/theme.h" #include <guichan/graphics.hpp> @@ -59,9 +58,9 @@ ResizeGrip::~ResizeGrip() void ResizeGrip::draw(gcn::Graphics *graphics) { - if (config.getValue("guialpha", 0.8) != mAlpha) + if (config.getFloatValue("guialpha") != mAlpha) { - mAlpha = config.getValue("guialpha", 0.8); + mAlpha = config.getFloatValue("guialpha"); gripImage->setAlpha(mAlpha); } diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h index 5ef93f29..319b574f 100644 --- a/src/gui/widgets/resizegrip.h +++ b/src/gui/widgets/resizegrip.h @@ -36,14 +36,8 @@ class Image; class ResizeGrip : public gcn::Widget { public: - /** - * Constructor. - */ ResizeGrip(const std::string &image = "resize.png"); - /** - * Destructor. - */ ~ResizeGrip(); /** diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 0c7f4d7d..7d42883a 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -24,9 +24,8 @@ #include "configuration.h" #include "graphics.h" -#include "gui/theme.h" - #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -108,7 +107,7 @@ void ScrollArea::init() bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, bggridy[y + 1] - bggridy[y] + 1); - background.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + background.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } @@ -135,8 +134,8 @@ void ScrollArea::init() vsgridx[x], vsgridy[y], vsgridx[x + 1] - vsgridx[x], vsgridy[y + 1] - vsgridy[y]); - vMarker.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); - vMarkerHi.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + vMarker.grid[a]->setAlpha(config.getFloatValue("guialpha")); + vMarkerHi.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } @@ -213,8 +212,8 @@ void ScrollArea::logic() void ScrollArea::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index a5033570..2d25185a 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -26,18 +26,16 @@ #include "shopitem.h" #include "gui/itempopup.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/shopitems.h" #include "resources/image.h" +#include "resources/theme.h" #include <guichan/font.hpp> #include <guichan/listmodel.hpp> -const int ITEM_ICON_SIZE = 32; - float ShopListBox::mAlpha = 1.0; ShopListBox::ShopListBox(gcn::ListModel *listModel): @@ -76,8 +74,8 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (!mListModel) return; - if (config.getValue("guialpha", 0.8) != mAlpha) - mAlpha = config.getValue("guialpha", 0.8); + if (config.getFloatValue("guialpha") != mAlpha) + mAlpha = config.getFloatValue("guialpha"); int alpha = (int)(mAlpha * 255.0f); const gcn::Color* highlightColor = diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h index 087bdd53..325cb562 100644 --- a/src/gui/widgets/shoplistbox.h +++ b/src/gui/widgets/shoplistbox.h @@ -37,9 +37,6 @@ class ItemPopup; class ShopListBox : public ListBox { public: - /** - * Constructor. - */ ShopListBox(gcn::ListModel *listModel); /** @@ -47,9 +44,6 @@ class ShopListBox : public ListBox */ ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel); - /** - * Destructor - */ ~ShopListBox(); /** diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h index 9404ffd2..e511d7f9 100644 --- a/src/gui/widgets/shortcutcontainer.h +++ b/src/gui/widgets/shortcutcontainer.h @@ -38,14 +38,8 @@ class ShortcutContainer : public gcn::Widget, public gcn::MouseListener { public: - /** - * Constructor. Initializes the shortcut container. - */ ShortcutContainer(); - /** - * Destructor. - */ ~ShortcutContainer() {} /** diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 6a9a5c7c..c044d55d 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -24,9 +24,8 @@ #include "configuration.h" #include "graphics.h" -#include "gui/theme.h" - #include "resources/image.h" +#include "resources/theme.h" Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip; Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip; @@ -126,8 +125,8 @@ void Slider::init() void Slider::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index 9b26e404..408210ac 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -31,7 +31,8 @@ class Image; * * \ingroup GUI */ -class Slider : public gcn::Slider { +class Slider : public gcn::Slider +{ public: /** * Constructor with scale start equal to 0. @@ -40,12 +41,12 @@ class Slider : public gcn::Slider { /** * Constructor. + * + * @param scaleStart The minimum value of the slider + * @param scaleEnd The maximum value of the slider */ Slider(double scaleStart, double scaleEnd); - /** - * Destructor. - */ ~Slider(); /** diff --git a/src/gui/widgets/spacer.cpp b/src/gui/widgets/spacer.cpp new file mode 100644 index 00000000..725d2b45 --- /dev/null +++ b/src/gui/widgets/spacer.cpp @@ -0,0 +1,28 @@ +/* + * The Mana Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/spacer.h" + +Spacer::Spacer(int w, int h) +{ + setWidth(w); + setHeight(h); +} diff --git a/src/gui/widgets/spacer.h b/src/gui/widgets/spacer.h new file mode 100644 index 00000000..cc171890 --- /dev/null +++ b/src/gui/widgets/spacer.h @@ -0,0 +1,53 @@ +/* + * The Mana Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPACER_H +#define SPACER_H + +#include "guichan/graphics.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +/** + * A space. + * + * \ingroup GUI + */ +class Spacer : public gcn::Widget +{ + public: + /** + * Constructor. + * + * @note Can be called empty, will default to a 5x5 px space + * + * @param w - width in px. + * @param h - height in px. + */ + Spacer(int x = 5, int y = 5); + + /** + * Draws the Space. + */ + void draw(gcn::Graphics *g){} +}; + +#endif // SPACER_H diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 2ab126dd..10a51afe 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -25,11 +25,11 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/theme.h" #include "gui/widgets/tabbedarea.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/dtor.h" @@ -118,8 +118,8 @@ void Tab::init() void Tab::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); // TODO We don't need to do this for every tab on every draw // Maybe use a config listener to do it as the value changes. diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 101c9546..412d3ddc 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -25,11 +25,20 @@ #include <guichan/widgets/container.hpp> -TabbedArea::TabbedArea() : gcn::TabbedArea() +TabbedArea::TabbedArea() : gcn::TabbedArea(), + mTabsWidth(0), + mVisibleTabsWidth(0), + mTabScrollIndex(0) { mWidgetContainer->setOpaque(false); addWidgetListener(this); + mArrowButton[0] = new Button("<", "shift_left", this); + mArrowButton[1] = new Button(">", "shift_right", this); + + add(mArrowButton[0]); + add(mArrowButton[1]); + widgetResized(NULL); } @@ -90,6 +99,9 @@ void TabbedArea::addTab(gcn::Tab* tab, gcn::Widget* widget) int width = getWidth() - 2 * getFrameSize(); int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight(); widget->setSize(width, height); + + updateTabsWidth(); + updateArrowEnableState(); } void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget) @@ -134,6 +146,7 @@ void TabbedArea::removeTab(Tab *tab) } adjustSize(); + updateTabsWidth(); adjustTabPositions(); } @@ -184,4 +197,136 @@ void TabbedArea::widgetResized(const gcn::Event &event) gcn::Widget *w = getCurrentWidget(); if (w) w->setSize(width, height); + + // Check whether there is room to show more tabs now. + int innerWidth = getWidth() - 4 - mArrowButton[0]->getWidth() + - mArrowButton[1]->getWidth(); + int newWidth = mVisibleTabsWidth; + while (mTabScrollIndex && newWidth < innerWidth) + { + newWidth += mTabs[mTabScrollIndex - 1].first->getWidth(); + if (newWidth < innerWidth) + --mTabScrollIndex; + } + + // Move the right arrow to fit the windows content. + mArrowButton[1]->setPosition(width - mArrowButton[1]->getWidth(), 0); + + updateArrowEnableState(); + adjustTabPositions(); +} + +void TabbedArea::updateTabsWidth() +{ + mTabsWidth = 0; + for (TabContainer::const_iterator itr = mTabs.begin(), itr_end = mTabs.end(); + itr != itr_end; ++itr) + { + mTabsWidth += (*itr).first->getWidth(); + } + updateVisibleTabsWidth(); +} + +void TabbedArea::updateVisibleTabsWidth() +{ + mVisibleTabsWidth = 0; + for (unsigned int i = mTabScrollIndex; i < mTabs.size(); ++i) + { + mVisibleTabsWidth += mTabs[i].first->getWidth(); + } +} + +void TabbedArea::adjustTabPositions() +{ + int maxTabHeight = 0; + for (unsigned i = 0; i < mTabs.size(); ++i) + { + if (mTabs[i].first->getHeight() > maxTabHeight) + { + maxTabHeight = mTabs[i].first->getHeight(); + } + } + + int x = mArrowButton[0]->isVisible() ? mArrowButton[0]->getWidth() : 0; + for (unsigned i = mTabScrollIndex; i < mTabs.size(); ++i) + { + gcn::Tab* tab = mTabs[i].first; + tab->setPosition(x, maxTabHeight - tab->getHeight()); + x += tab->getWidth(); + } + + // If the tabs are scrolled, we hide them away. + if (mTabScrollIndex > 0) + { + x = 0; + for (unsigned i = 0; i < mTabScrollIndex; ++i) + { + gcn::Tab* tab = mTabs[i].first; + x -= tab->getWidth(); + tab->setPosition(x, maxTabHeight - tab->getHeight()); + } + } +} + +void TabbedArea::action(const gcn::ActionEvent& actionEvent) +{ + Widget* source = actionEvent.getSource(); + Tab* tab = dynamic_cast<Tab*>(source); + + if (tab) + { + setSelectedTab(tab); + } + else + { + if (actionEvent.getId() == "shift_left") + { + if (mTabScrollIndex) + --mTabScrollIndex; + } + else if (actionEvent.getId() == "shift_right") + { + if (mTabScrollIndex < mTabs.size() - 1) + ++mTabScrollIndex; + } + adjustTabPositions(); + + updateArrowEnableState(); + } +} + +void TabbedArea::updateArrowEnableState() +{ + updateTabsWidth(); + if (mTabsWidth > getWidth() - 4 + - mArrowButton[0]->getWidth() + - mArrowButton[1]->getWidth()) + { + mArrowButton[0]->setVisible(true); + mArrowButton[1]->setVisible(true); + } + else + { + mArrowButton[0]->setVisible(false); + mArrowButton[1]->setVisible(false); + mTabScrollIndex = 0; + } + + // Left arrow consistency check + if (!mTabScrollIndex) + mArrowButton[0]->setEnabled(false); + else + mArrowButton[0]->setEnabled(true); + + // Right arrow consistency check + if (mVisibleTabsWidth < getWidth() - 4 + - mArrowButton[0]->getWidth() + - mArrowButton[1]->getWidth()) + { + mArrowButton[1]->setEnabled(false); + } + else + { + mArrowButton[1]->setEnabled(true); + } } diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 925da2de..d364eac5 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -27,6 +27,8 @@ #include <guichan/widgets/container.hpp> #include <guichan/widgets/tabbedarea.hpp> +#include "gui/widgets/button.h" + #include <string> class Tab; @@ -37,9 +39,6 @@ class Tab; class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener { public: - /** - * Constructor. - */ TabbedArea(); /** @@ -107,11 +106,52 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener void widgetResized(const gcn::Event &event); + void adjustTabPositions(); + + void action(const gcn::ActionEvent& actionEvent); + // Inherited from MouseListener void mousePressed(gcn::MouseEvent &mouseEvent); private: typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer; + + /** The tab arrows */ + gcn::Button *mArrowButton[2]; + + /** Check whether the arrow should be clickable */ + void updateArrowEnableState(); + + /** + * Update the overall width of all tab. Used to know whether the arrows + * have to be drawn or not. + */ + void updateTabsWidth(); + + /** + * The overall width of all tab. + */ + int mTabsWidth; + + /** + * Update the overall width of visible tab. Used to know whether + * the arrows have to be enable or not. + */ + void updateVisibleTabsWidth(); + + /** + * The overall width of visible tab. + */ + int mVisibleTabsWidth; + + + /** + * The tab scroll index. When scrolling with the arrows, the tabs + * must be displayed according to the current index. + * So the first tab displayed may not be the first in the list. + * @note the index must start at 0. + */ + unsigned mTabScrollIndex; }; #endif diff --git a/src/gui/widgets/table.cpp b/src/gui/widgets/table.cpp index f0887ed7..3d8680ce 100644 --- a/src/gui/widgets/table.cpp +++ b/src/gui/widgets/table.cpp @@ -24,7 +24,8 @@ #include "configuration.h" #include "gui/sdlinput.h" -#include "gui/theme.h" + +#include "resources/theme.h" #include "utils/dtor.h" @@ -270,8 +271,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (!mModel) return; - if (config.getValue("guialpha", 0.8) != mAlpha) - mAlpha = config.getValue("guialpha", 0.8); + if (config.getFloatValue("guialpha") != mAlpha) + mAlpha = config.getFloatValue("guialpha"); if (mOpaque) { diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index b4bbb409..477b35c0 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -56,7 +56,7 @@ StaticTableModel::StaticTableModel(int row, int column) : mColumns(column), mHeight(1) { - mTableModel.resize(row * column, NULL); + mTableModel.resize(row * column); mWidths.resize(column, 1); } @@ -69,7 +69,7 @@ void StaticTableModel::resize() { mRows = getRows(); mColumns = getColumns(); - mTableModel.resize(mRows * mColumns, NULL); + mTableModel.resize(mRows * mColumns); } void StaticTableModel::set(int row, int column, gcn::Widget *widget) diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index f248f35d..5b112e54 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -21,7 +21,7 @@ #include "gui/widgets/textbox.h" -#include "gui/theme.h" +#include "resources/theme.h" #include <guichan/font.hpp> diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h index 3b6778d2..6b947e0b 100644 --- a/src/gui/widgets/textbox.h +++ b/src/gui/widgets/textbox.h @@ -34,9 +34,6 @@ class TextBox : public gcn::TextBox { public: - /** - * Constructor. - */ TextBox(); inline void setTextColor(const gcn::Color *color) diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 4989ae83..d06df376 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -21,15 +21,14 @@ #include "gui/widgets/textfield.h" -#include "beingmanager.h" #include "configuration.h" #include "graphics.h" #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/theme.h" #include "resources/image.h" +#include "resources/theme.h" #include "utils/copynpaste.h" #include "utils/dtor.h" @@ -69,7 +68,7 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab): gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1); - skin.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + skin.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } @@ -90,8 +89,8 @@ TextField::~TextField() void TextField::updateAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 10426d7c..869ebd35 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -45,8 +45,8 @@ TextPreview::TextPreview(const std::string &text): void TextPreview::draw(gcn::Graphics* graphics) { - if (config.getValue("guialpha", 0.8) != mAlpha) - mAlpha = config.getValue("guialpha", 0.8); + if (config.getFloatValue("guialpha") != mAlpha) + mAlpha = config.getFloatValue("guialpha"); int alpha = (int) (mAlpha * 255.0f); diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 7542e251..864f1f51 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -21,14 +21,15 @@ #include "whispertab.h" +#include "chatlog.h" #include "commandhandler.h" #include "localplayer.h" -#include "gui/theme.h" - #include "net/chathandler.h" #include "net/net.h" +#include "resources/theme.h" + #include "utils/gettext.h" #include "utils/stringutils.h" @@ -115,3 +116,9 @@ bool WhisperTab::handleCommand(const std::string &type, return true; } + +void WhisperTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log(getNick(), msg); +} diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h index 447a8fe0..20a07449 100644 --- a/src/gui/widgets/whispertab.h +++ b/src/gui/widgets/whispertab.h @@ -39,6 +39,8 @@ class WhisperTab : public ChatTab bool handleCommand(const std::string &type, const std::string &args); + void saveToLogFile(std::string &msg); + protected: friend class ChatWindow; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 118ee7c0..aa8e6df3 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -26,7 +26,6 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/layout.h" @@ -34,6 +33,7 @@ #include "gui/widgets/windowcontainer.h" #include "resources/image.h" +#include "resources/theme.h" #include <guichan/exception.hpp> #include <guichan/focushandler.hpp> @@ -697,8 +697,8 @@ int Window::getResizeHandles(gcn::MouseEvent &event) int Window::getGuiAlpha() { - float alpha = std::max(config.getValue("guialpha", 0.8), - (double) Theme::instance()->getMinimumOpacity()); + float alpha = std::max(config.getFloatValue("guialpha"), + Theme::instance()->getMinimumOpacity()); return (int) (alpha * 255.0f); } |