diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-02-08 14:40:04 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-02-08 14:43:51 -0700 |
commit | 8a31e96d8534d402db9cd48183c0b15732f7d95e (patch) | |
tree | 885d83febf301c1289c3bf7f83bf9dca89e0347c /src/gui/widgets | |
parent | bc5c031e43eff506c925682349dd2a52b89d6565 (diff) | |
download | mana-8a31e96d8534d402db9cd48183c0b15732f7d95e.tar.gz mana-8a31e96d8534d402db9cd48183c0b15732f7d95e.tar.bz2 mana-8a31e96d8534d402db9cd48183c0b15732f7d95e.tar.xz mana-8a31e96d8534d402db9cd48183c0b15732f7d95e.zip |
Merge PartyWindow and GuildWindow into SocialWindow
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/avatar.cpp | 122 | ||||
-rw-r--r-- | src/gui/widgets/avatar.h | 84 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.cpp | 133 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.h (renamed from src/gui/widgets/guildlistbox.h) | 40 | ||||
-rw-r--r-- | src/gui/widgets/guildlistbox.cpp | 131 | ||||
-rw-r--r-- | src/gui/widgets/listbox.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 3 |
8 files changed, 158 insertions, 360 deletions
diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp deleted file mode 100644 index 7102fe4f..00000000 --- a/src/gui/widgets/avatar.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana World. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/widgets/avatar.h" - -#include "localplayer.h" - -#include "gui/gui.h" - -#include "gui/widgets/icon.h" -#include "gui/widgets/label.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" - -#include <sstream> - -namespace { - Image *avatarStatusOffline; - Image *avatarStatusOnline; - int avatarCount = 0; -} - -Avatar::Avatar(): - mHp(0), - mMaxHp(0), - mDisplayBold(false) -{ - setOpaque(false); - - if (avatarCount == 0) - { - ResourceManager *resman = ResourceManager::getInstance(); - avatarStatusOffline = resman->getImage("graphics/gui/circle-gray.png"); - avatarStatusOnline = resman->getImage("graphics/gui/circle-green.png"); - } - avatarCount++; - avatarStatusOffline->incRef(); - avatarStatusOnline->incRef(); - - mLabel = new Label; - mLabel->adjustSize(); - - mStatus = new Icon(avatarStatusOffline); - mStatus->setSize(10, 10); - - add(mStatus, 4, (mLabel->getHeight() - 10) / 2); - add(mLabel, 18, 0); - - setSize(250, mLabel->getHeight()); - -} - -Avatar::~Avatar() -{ - avatarCount--; - - avatarStatusOffline->decRef(); - avatarStatusOnline->decRef(); -} - -void Avatar::setName(const std::string &name) -{ - mName = name; - updateAvatarLabel(); -} - -void Avatar::setOnline(bool online) -{ - mOnline = online; - mStatus->setImage(online ? avatarStatusOnline : avatarStatusOffline); -} - -void Avatar::setHp(int hp) -{ - if (hp == mHp) - return; - - mHp = hp; - updateAvatarLabel(); -} - -void Avatar::setMaxHp(int maxHp) -{ - if (maxHp == mMaxHp) - return; - - mMaxHp = maxHp; - updateAvatarLabel(); -} - -void Avatar::updateAvatarLabel() -{ - std::ostringstream ss; - ss << mName; - - if (mName != player_node->getName() && mMaxHp != 0) - ss << " (" << mHp << "/" << mMaxHp << ")"; - - if (mDisplayBold) - mLabel->setFont(boldFont); - mLabel->setCaption(ss.str()); - mLabel->adjustSize(); -} diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h deleted file mode 100644 index 8d6dd928..00000000 --- a/src/gui/widgets/avatar.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana World. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef AVATAR_H -#define AVATAR_H - -#include "guichanfwd.h" - -#include "gui/widgets/container.h" - -#include <string> - -class Image; -class Icon; - -class Avatar : public Container -{ -public: - Avatar(); - ~Avatar(); - - /** - * Returns the avatar's name. - */ - std::string getName() const { return mName; }; - - /** - * Set the avatar's name. - */ - void setName(const std::string &name); - - /** - * Returns the avatar's online status. - */ - bool getOnline() const { return mOnline; } - - /** - * Set the avatar's online status. - */ - void setOnline(bool online); - - int getHp() const { return mHp; } - - void setHp(int hp); - - int getMaxHp() const { return mMaxHp; } - - void setMaxHp(int maxHp); - - bool getDisplayBold() const { return mDisplayBold; } - - void setDisplayBold(bool displayBold) { mDisplayBold = displayBold; updateAvatarLabel(); } - -private: - void updateAvatarLabel(); - - std::string mName; - int mHp; - int mMaxHp; - Icon *mStatus; - gcn::Label *mLabel; - bool mOnline; - bool mDisplayBold; -}; - -#endif // AVATAR_H diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp new file mode 100644 index 00000000..566cd9de --- /dev/null +++ b/src/gui/widgets/avatarlistbox.cpp @@ -0,0 +1,133 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/widgets/avatarlistbox.h" + +#include "graphics.h" + +#include "gui/gui.h" +#include "gui/palette.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" + +#include <guichan/font.hpp> + +int AvatarListBox::instances = 0; +Image *AvatarListBox::onlineIcon = 0; +Image *AvatarListBox::offlineIcon = 0; + +AvatarListBox::AvatarListBox(AvatarListModel *model): + ListBox(model) +{ + instances++; + + if (instances == 1) + { + onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); + offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); + } + + setWidth(200); +} + +AvatarListBox::~AvatarListBox() +{ + instances--; + + if (instances == 0) + { + onlineIcon->decRef(); + offlineIcon->decRef(); + } +} + +void AvatarListBox::draw(gcn::Graphics *gcnGraphics) +{ + AvatarListModel* model = dynamic_cast<AvatarListModel*>(mListModel); + + if (!model) + return; + + updateAlpha(); + + Graphics *graphics = static_cast<Graphics*>(gcnGraphics); + + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); + graphics->setFont(getFont()); + + const int fontHeight = getFont()->getHeight(); + + // Draw filled rectangle around the selected list element + if (mSelected >= 0) + graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, + getWidth(), fontHeight)); + + int newWidth = 0; + int width = 0; + + // Draw the list elements + graphics->setColor(guiPalette->getColor(Palette::TEXT)); + for (int i = 0, y = 0; + i < model->getNumberOfElements(); + ++i, y += fontHeight) + { + Avatar *a = model->getAvatarAt(i); + // Draw online status + Image *icon = a->getOnline() ? onlineIcon : offlineIcon; + if (icon) + graphics->drawImage(icon, 2, y + 1); + + if (a->getDisplayBold()) + graphics->setFont(boldFont); + + // Draw Name + graphics->drawText(a->getName(), 15, y); + + width = getFont()->getWidth(a->getName()) + 17; // Extra right padding + + if (width > newWidth) + { + newWidth = width; + } + + if (a->getDisplayBold()) + graphics->setFont(getFont()); + } + + setWidth(newWidth); +} + +void AvatarListBox::mousePressed(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT) + { + int y = event.getY(); + setSelected(y / getFont()->getHeight()); + distributeActionEvent(); + } + // TODO: Add support for context menu + else if (event.getButton() == gcn::MouseEvent::RIGHT) + { + // Show context menu + } +} diff --git a/src/gui/widgets/guildlistbox.h b/src/gui/widgets/avatarlistbox.h index 387b2a7a..5c05cae6 100644 --- a/src/gui/widgets/guildlistbox.h +++ b/src/gui/widgets/avatarlistbox.h @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright (C) 2008-2010 The Mana World Development Team + * Copyright (C) 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -22,6 +22,8 @@ #ifndef GUI_GUILDLISTBOX_H #define GUI_GUILDLISTBOX_H +#include "avatar.h" + #include "gui/widgets/listbox.h" #include <map> @@ -30,13 +32,21 @@ class Image; -class GuildListBox : public ListBox +class AvatarListModel : public gcn::ListModel { public: - /** - * Constructor - */ - GuildListBox(); + virtual Avatar *getAvatarAt(int i) = 0; + + std::string getElementAt(int i) + { return getAvatarAt(i)->getName(); } +}; + +class AvatarListBox : public ListBox +{ +public: + AvatarListBox(AvatarListModel *model); + + ~AvatarListBox(); /** * Draws the list box. @@ -45,21 +55,11 @@ public: void mousePressed(gcn::MouseEvent &event); - /** - * Sets the index of the selected element. - */ -// void setSelected(int selected); - - /** - * Set whether a member is online or offline - */ - void setOnlineStatus(const std::string &user, bool online); - private: - Image *onlineIcon; - Image *offlineIcon; - typedef std::map<std::string, bool> UserMap; - UserMap mUsers; + static int instances; + static Image *onlineIcon; + static Image *offlineIcon; + }; #endif diff --git a/src/gui/widgets/guildlistbox.cpp b/src/gui/widgets/guildlistbox.cpp deleted file mode 100644 index 362e79d1..00000000 --- a/src/gui/widgets/guildlistbox.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana World. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/widgets/guildlistbox.h" - -#include "graphics.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" - -#include <guichan/font.hpp> - -GuildListBox::GuildListBox(): - ListBox(NULL) -{ - onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); - offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); -} - -void GuildListBox::draw(gcn::Graphics *gcnGraphics) -{ - if (!mListModel) - return; - - Graphics *graphics = static_cast<Graphics*>(gcnGraphics); - - graphics->setColor(gcn::Color(110, 160, 255)); - graphics->setFont(getFont()); - - int fontHeight = getFont()->getHeight(); - - // Draw rectangle below the selected list element - if (mSelected >= 0) - { - graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, - getWidth(), fontHeight)); - } - - // Draw the list elements - for (int i = 0, y = 0; - i < mListModel->getNumberOfElements(); - ++i, y += fontHeight) - { - // Draw online status - bool online = false; - UserMap::iterator itr = mUsers.find(mListModel->getElementAt(i)); - if (itr != mUsers.end()) - { - online = itr->second; - } - Image *icon = online ? onlineIcon : offlineIcon; - if (icon) - graphics->drawImage(icon, 1, y); - // Draw Name - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mListModel->getElementAt(i), 33, y); - } -} -/* -void GuildListBox::setSelected(int selected) -{ - if (!mListModel) - { - mSelected = -1; - } - else - { - // Update mSelected with bounds checking - mSelected = std::min(mListModel->getNumberOfElements() - 1, - std::max(-1, selected)); - - gcn::Widget *parent; - parent = (gcn::Widget*)getParent(); - if (parent) - { - gcn::Rectangle scroll; - scroll.y = (mSelected < 0) ? 0 : getFont()->getHeight() * mSelected; - scroll.height = getFont()->getHeight(); - parent->showWidgetPart(this, scroll); - } - } - - distributeValueChangedEvent(); -} -*/ -void GuildListBox::mousePressed(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::LEFT) - { - int y = event.getY(); - setSelected(y / getFont()->getHeight()); - distributeActionEvent(); - } - // TODO: Add guild functions, ie private messaging - if (event.getButton() == gcn::MouseEvent::RIGHT) - { - // Show context menu - } -} - -void GuildListBox::setOnlineStatus(const std::string &user, bool online) -{ - UserMap::iterator itr = mUsers.find(user); - if (itr == mUsers.end()) - { - mUsers.insert(std::pair<std::string, bool>(user, online)); - } - else - { - itr->second = online; - } - adjustSize(); -} diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index ed17c6ad..9110e71c 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -65,7 +65,7 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); - private: + protected: static float mAlpha; }; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index abcb858a..71f1a1a8 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -42,6 +42,7 @@ ScrollArea::ScrollArea(): gcn::ScrollArea(), mX(0), mY(0), + mHasMouse(false), mOpaque(true) { addWidgetListener(this); @@ -50,6 +51,8 @@ ScrollArea::ScrollArea(): ScrollArea::ScrollArea(gcn::Widget *widget): gcn::ScrollArea(widget), + mX(0), + mY(0), mHasMouse(false), mOpaque(true) { diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index b5c1eb9f..c0d070cf 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -178,6 +178,5 @@ void TabbedArea::widgetResized(const gcn::Event &event) gcn::Widget *w = getCurrentWidget(); if (w) - w->setSize(width, - height); + w->setSize(width, height); } |