summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-02-08 14:40:04 -0700
committerJared Adams <jaxad0127@gmail.com>2010-02-08 14:43:51 -0700
commit8a31e96d8534d402db9cd48183c0b15732f7d95e (patch)
tree885d83febf301c1289c3bf7f83bf9dca89e0347c /src/gui
parentbc5c031e43eff506c925682349dd2a52b89d6565 (diff)
downloadmana-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')
-rw-r--r--src/gui/chat.cpp22
-rw-r--r--src/gui/chat.h3
-rw-r--r--src/gui/confirmdialog.cpp8
-rw-r--r--src/gui/guildwindow.cpp284
-rw-r--r--src/gui/guildwindow.h129
-rw-r--r--src/gui/okdialog.cpp8
-rw-r--r--src/gui/partywindow.cpp274
-rw-r--r--src/gui/partywindow.h149
-rw-r--r--src/gui/socialwindow.cpp570
-rw-r--r--src/gui/socialwindow.h105
-rw-r--r--src/gui/textdialog.cpp11
-rw-r--r--src/gui/widgets/avatar.cpp122
-rw-r--r--src/gui/widgets/avatar.h84
-rw-r--r--src/gui/widgets/avatarlistbox.cpp133
-rw-r--r--src/gui/widgets/avatarlistbox.h (renamed from src/gui/widgets/guildlistbox.h)40
-rw-r--r--src/gui/widgets/guildlistbox.cpp131
-rw-r--r--src/gui/widgets/listbox.h2
-rw-r--r--src/gui/widgets/scrollarea.cpp3
-rw-r--r--src/gui/widgets/tabbedarea.cpp3
-rw-r--r--src/gui/windowmenu.cpp8
20 files changed, 853 insertions, 1236 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 1c18a438..0377dbf8 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -24,11 +24,11 @@
#include "beingmanager.h"
#include "configuration.h"
#include "localplayer.h"
+#include "party.h"
#include "gui/recorder.h"
#include "gui/setup.h"
#include "gui/sdlinput.h"
-#include "gui/partywindow.h"
#include "gui/widgets/chattab.h"
#include "gui/widgets/itemlinkhandler.h"
@@ -75,8 +75,7 @@ class ChatInput : public TextField, public gcn::FocusListener
ChatWindow::ChatWindow():
Window(_("Chat")),
- mTmpVisible(false),
- mCurrentTab(NULL)
+ mTmpVisible(false)
{
setWindowName("Chat");
@@ -128,15 +127,6 @@ void ChatWindow::resetToDefaultSize()
Window::resetToDefaultSize();
}
-void ChatWindow::logic()
-{
- Window::logic();
-
- Tab *tab = getFocused();
- if (tab != mCurrentTab)
- mCurrentTab = tab;
-}
-
ChatTab *ChatWindow::getFocused() const
{
return dynamic_cast<ChatTab*>(mChatTabs->getSelectedTab());
@@ -338,7 +328,7 @@ void ChatWindow::mousePressed(gcn::MouseEvent &event)
if (event.isConsumed())
return;
- mMoved = event.getY() <= mCurrentTab->getHeight();
+ mMoved = event.getY() <= getFocused()->getHeight();
mDragOffsetX = event.getX();
mDragOffsetY = event.getY();
@@ -533,7 +523,11 @@ void ChatWindow::autoComplete()
std::vector<std::string> nameList;
if (cTab && cTab->getType() == ChatTab::PARTY)
{
- partyWindow->getNames(nameList);
+ Party *p = player_node->getParty();
+
+ if (p) // Shouldn't be needed, but lets be safe
+ p->getNames(nameList);
+
newName = autoComplete(nameList, name);
}
if (newName == "")
diff --git a/src/gui/chat.h b/src/gui/chat.h
index cd9b6170..cc48b78a 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -75,8 +75,6 @@ class ChatWindow : public Window,
*/
~ChatWindow();
- void logic();
-
/**
* Reset the chat window and recorder window attached to it to their
* default positions.
@@ -207,7 +205,6 @@ class ChatWindow : public Window,
/** Tabbed area for holding each channel. */
TabbedArea *mChatTabs;
- Tab *mCurrentTab;
typedef std::map<const std::string, ChatTab*> TabMap;
/** Manage whisper tabs */
diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp
index b38e801b..79e3bec1 100644
--- a/src/gui/confirmdialog.cpp
+++ b/src/gui/confirmdialog.cpp
@@ -79,12 +79,8 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
void ConfirmDialog::action(const gcn::ActionEvent &event)
{
- // Proxy button events to our listeners
- ActionListenerIterator i;
- for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
- {
- (*i)->action(event);
- }
+ setActionEventId(event.getId());
+ distributeActionEvent();
// Can we receive anything else anyway?
if (event.getId() == "yes" || event.getId() == "no")
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
deleted file mode 100644
index 94646261..00000000
--- a/src/gui/guildwindow.cpp
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004-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/guildwindow.h"
-
-#include "guild.h"
-#include "log.h"
-#include "localplayer.h"
-
-#include "gui/confirmdialog.h"
-#include "gui/setup.h"
-#include "gui/textdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/chattab.h"
-#include "gui/widgets/guildlistbox.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabbedarea.h"
-#include "gui/widgets/windowcontainer.h"
-
-#include "net/guildhandler.h"
-#include "net/net.h"
-
-#include "utils/dtor.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include <guichan/widgets/tab.hpp>
-
-#include <algorithm>
-
-GuildWindow::GuildWindow():
- Window(_("Guild")),
- mFocus(false)
-{
- setWindowName("Guild");
- setCaption(_("Guild"));
- setResizable(false);
- setCloseButton(true);
- setSaveVisible(true);
- setMinWidth(200);
- setMinHeight(280);
- setDefaultSize(124, 41, 288, 330);
- setupWindow->registerWindowForReset(this);
-
- // Set button events Id
- mGuildButton[0] = new Button(_("Create Guild"), "CREATE_GUILD", this);
- mGuildButton[1] = new Button(_("Invite User"), "INVITE_USER", this);
- mGuildButton[2] = new Button(_("Quit Guild"), "QUIT_GUILD", this);
- mGuildButton[1]->setEnabled(false);
- mGuildButton[2]->setEnabled(false);
-
- mGuildTabs = new TabbedArea;
-
- place(0, 0, mGuildButton[0]);
- place(1, 0, mGuildButton[1]);
- place(2, 0, mGuildButton[2]);
- place(0, 1, mGuildTabs);
- Layout &layout = getLayout();
- layout.setColWidth(0, 48);
- layout.setColWidth(1, 65);
-
- loadWindowState();
-}
-
-GuildWindow::~GuildWindow()
-{
-}
-
-void GuildWindow::update()
-{
- updateTab();
-
- if (mGuildButton[2]->isEnabled() && mGuildTabs->getNumberOfTabs() <= 0)
- {
- mGuildButton[2]->setEnabled(false);
- mGuildButton[1]->setEnabled(false);
- }
-}
-
-void GuildWindow::draw(gcn::Graphics *g)
-{
- update();
-
- Window::draw(g);
-}
-
-void GuildWindow::action(const gcn::ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- // Stats Part
- if (eventId == "CREATE_GUILD")
- {
- // Set focus so that guild name to be created can be typed.
- mFocus = true;
- guildDialog = new TextDialog(_("Guild Name"),
- _("Choose your guild's name."), this);
- guildDialog->setOKButtonActionId("CREATE_GUILD_OK");
- guildDialog->addActionListener(this);
- }
- else if (eventId == "INVITE_USER")
- {
- // TODO - Give feedback on whether the invite succeeded
- mFocus = true;
- inviteDialog = new TextDialog(_("Member Invite"),
- _("Who would you like to invite?"), this);
- inviteDialog->setOKButtonActionId("INVITE_USER_OK");
- inviteDialog->addActionListener(this);
- }
- else if (eventId == "QUIT_GUILD")
- {
- short guild = getSelectedGuild();
- if (guild)
- {
- Net::getGuildHandler()->leave(guild);
- localChatTab->chatLog(strprintf(_("Guild %s quit."),
- mGuildTabs->getSelectedTab()->getCaption().c_str()), BY_SERVER);
- }
- }
- else if (eventId == "CREATE_GUILD_OK")
- {
- std::string name = guildDialog->getText();
- if (name.size() > 16)
- {
- // TODO : State too many characters in input.
- return;
- }
- // Process guild name to be created, and unfocus.
- Net::getGuildHandler()->create(name);
-
- // Defocus dialog
- mFocus = false;
- localChatTab->chatLog(strprintf(_("Creating guild called %s."),
- name.c_str()), BY_SERVER);
- guildDialog->scheduleDelete();
- }
- else if (eventId == "INVITE_USER_OK")
- {
- std::string name = inviteDialog->getText();
- short selectedGuild = getSelectedGuild();
-
- // Process invited user to be created and unfocus.
- Net::getGuildHandler()->invite(selectedGuild, name);
-
- // Defocus dialog
- mFocus = false;
- localChatTab->chatLog(strprintf(_("Invited user %s."), name.c_str()), BY_SERVER);
- inviteDialog->scheduleDelete();
- }
- else if (eventId == "yes")
- {
- logger->log("Sending invitation acceptance.");
- Net::getGuildHandler()->inviteResponse(invitedGuildId, true);
- }
-}
-
-void GuildWindow::newGuildTab(const std::string &guildName)
-{
- // Create new tab
- GuildListBox *list = new GuildListBox;
- list->setListModel(player_node->getGuild(guildName));
- ScrollArea *sa = new ScrollArea(list);
- sa->setDimension(gcn::Rectangle(5, 5, 135, 250));
-
- // Add the listbox to the map
- mGuildLists.insert(std::pair<std::string, GuildListBox*>(guildName, list));
-
- mGuildTabs->addTab(guildName, sa);
- mGuildTabs->setDimension(gcn::Rectangle(28,35,140,250));
-
- updateTab();
-}
-
-void GuildWindow::updateTab()
-{
- gcn::Tab *tab = mGuildTabs->getSelectedTab();
- if (tab)
- {
- setTab(tab->getCaption());
- }
- mGuildTabs->logic();
-}
-
-void GuildWindow::setTab(const std::string &guildName)
-{
- // Only enable invite button if user has rights
- if (player_node->checkInviteRights(guildName))
- {
- mGuildButton[1]->setEnabled(true);
- }
- else
- {
- mGuildButton[1]->setEnabled(false);
- }
-
- mGuildButton[2]->setEnabled(true);
-}
-
-bool GuildWindow::isWindowFocused()
-{
- return mFocus;
-}
-
-short GuildWindow::getSelectedGuild()
-{
- if (mGuildTabs->getNumberOfTabs() > 0)
- {
-
- Guild *guild = player_node->getGuild(mGuildTabs->getSelectedTab()->getCaption());
-
- if (guild)
- {
- return guild->getId();
- }
- }
-
- return 0;
-}
-
-void GuildWindow::openAcceptDialog(const std::string &inviterName,
- const std::string &guildName,
- const int guildId)
-{
- std::string msg = strprintf(_("%s has invited you to join the guild %s."),
- inviterName.c_str(), guildName.c_str());
- localChatTab->chatLog(msg, BY_SERVER);
-
- acceptDialog = new ConfirmDialog(_("Accept Guild Invite"), msg, this);
- acceptDialog->addActionListener(this);
-
- invitedGuildId = guildId;
-}
-
-void GuildWindow::requestMemberList(short guildId)
-{
- // Get the list of members for displaying in the guild window.
- Net::getGuildHandler()->memberList(guildId);
-}
-
-void GuildWindow::removeTab(int guildId)
-{
- Guild* guild = player_node->getGuild(guildId);
- if (guild)
- {
- Tab *tab = mGuildTabs->getTab(guild->getName());
- if (tab)
- {
- mGuildTabs->removeTab(tab);
- }
- updateTab();
- }
- mGuildTabs->logic();
-}
-
-void GuildWindow::setOnline(const std::string &guildName, const std::string &member,
- bool online)
-{
- GuildListMap::iterator itr = mGuildLists.find(guildName);
- if (itr != mGuildLists.end())
- {
- itr->second->setOnlineStatus(member, online);
- }
-}
diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h
deleted file mode 100644
index e0a28694..00000000
--- a/src/gui/guildwindow.h
+++ /dev/null
@@ -1,129 +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 GUI_GUILDWINDOW_H
-#define GUI_GUILDWINDOW_H
-
-#include "guichanfwd.h"
-
-#include "gui/widgets/window.h"
-
-#include <guichan/actionlistener.hpp>
-
-#include <guichan/widgets/listbox.hpp>
-
-#include <iosfwd>
-#include <map>
-#include <vector>
-
-class LocalPlayer;
-class TextDialog;
-class ConfirmDialog;
-class GuildListBox;
-class ScrollArea;
-class TabbedArea;
-
-class GuildWindow : public Window, public gcn::ActionListener
-{
-public:
- GuildWindow();
- ~GuildWindow();
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const gcn::ActionEvent &event);
-
- /**
- * Draw this window.
- */
- void draw(gcn::Graphics *graphics);
-
- /**
- * Updates this dialog.
- */
- void update();
-
- /**
- * Create a new tab for a guild list.
- */
- void newGuildTab(const std::string &guildName);
-
- /**
- * Display guild's member list to active tab
- */
- void setTab(const std::string &guildName);
-
- /**
- * Update the contents of the active tab
- */
- void updateTab();
-
- /**
- * Check if the window is in focus.
- */
- bool isWindowFocused();
-
- /**
- * Create a dialog for accepting an invite
- */
- void openAcceptDialog(const std::string &inviterName,
- const std::string &guildName, const int guildId);
-
- /**
- * Request member list
- */
- void requestMemberList(short guildId);
-
- /**
- * Removes the selected tab
- */
- void removeTab(int guildId);
-
- /**
- * Set guild member status in userlist
- */
- void setOnline(const std::string &guildName, const std::string &member,
- bool online);
-
-protected:
- /**
- * Get selected guild tab
- * @return Returns selected guild
- */
- short getSelectedGuild();
-
-private:
- gcn::Button *mGuildButton[3];
- TextDialog *guildDialog;
- TextDialog *inviteDialog;
- ConfirmDialog *acceptDialog;
- TabbedArea *mGuildTabs;
- ScrollArea *mScrollArea;
- bool mFocus;
- int invitedGuildId;
- typedef std::map<std::string, GuildListBox*> GuildListMap;
- GuildListMap mGuildLists;
-};
-
-extern GuildWindow *guildWindow;
-
-#endif
diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp
index 512a9994..3693f3e9 100644
--- a/src/gui/okdialog.cpp
+++ b/src/gui/okdialog.cpp
@@ -69,12 +69,8 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
void OkDialog::action(const gcn::ActionEvent &event)
{
- // Proxy button events to our listeners
- ActionListenerIterator i;
- for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
- {
- (*i)->action(event);
- }
+ setActionEventId(event.getId());
+ distributeActionEvent();
// Can we receive anything else anyway?
if (event.getId() == "ok")
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
deleted file mode 100644
index e5cac08f..00000000
--- a/src/gui/partywindow.cpp
+++ /dev/null
@@ -1,274 +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/partywindow.h"
-
-#include "beingmanager.h"
-#include "player.h"
-
-#include "gui/setup.h"
-
-#include "gui/widgets/chattab.h"
-
-#include "net/net.h"
-#include "net/partyhandler.h"
-
-#include "utils/dtor.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-PartyMember::PartyMember():
- mAvatar(new Avatar)
-{
-}
-
-PartyMember::~PartyMember()
-{
- delete mAvatar;
-}
-
-void PartyMember::setLeader(bool leader)
-{
- if (mLeader != leader)
- {
- mLeader = leader;
- mAvatar->setDisplayBold(leader);
- }
-}
-
-
-PartyWindow::PartyWindow() :
- Window(_("Party"))
-{
- setWindowName("Party");
- setVisible(false);
- setSaveVisible(true);
- setResizable(true);
- setSaveVisible(true);
- setCloseButton(true);
- setMinWidth(120);
- setMinHeight(55);
- setDefaultSize(590, 200, 150, 60);
- setupWindow->registerWindowForReset(this);
-
- loadWindowState();
-}
-
-PartyWindow::~PartyWindow()
-{
- delete_all(mMembers);
-}
-
-void PartyWindow::setPartyName(const std::string &name)
-{
- setCaption(strprintf(_("Party (%s)"), name.c_str()));
-}
-
-void PartyWindow::clearPartyName()
-{
- setCaption(_("Party"));
-}
-
-PartyMember *PartyWindow::findMember(int id) const
-{
- PartyList::const_iterator it = mMembers.find(id);
- if (it == mMembers.end())
- return NULL;
- else
- return it->second;
-}
-
-PartyMember *PartyWindow::findOrCreateMember(int id)
-{
- PartyMember *member = findMember(id);
-
- if (!member)
- {
- member = new PartyMember;
- mMembers[id] = member;
- }
-
- buildLayout();
-
- return member;
-}
-
-int PartyWindow::findMember(const std::string &name) const
-{
- PartyList::const_iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
-
- while (itr != itr_end)
- {
- if ((*itr).second->mAvatar->getName() == name)
- {
- return (*itr).first;
- }
- ++itr;
- }
-
- return -1;
-}
-
-void PartyWindow::updateMember(int id, const std::string &memberName,
- bool leader, bool online)
-{
- PartyMember *member = findOrCreateMember(id);
- member->mAvatar->setName(memberName);
- member->setLeader(leader);
- member->mAvatar->setOnline(online);
-
- Player *player = dynamic_cast<Player*>(beingManager->findBeing(id));
- if (player && online)
- player->setInParty(true);
-}
-
-void PartyWindow::updateMemberHP(int id, int hp, int maxhp)
-{
- PartyMember *player = findOrCreateMember(id);
- player->mAvatar->setHp(hp);
- player->mAvatar->setMaxHp(maxhp);
-}
-
-void PartyWindow::removeMember(int id)
-{
- mMembers.erase(id);
-
- if (Player *player = dynamic_cast<Player*>(beingManager->findBeing(id)))
- player->setInParty(false);
-}
-
-void PartyWindow::removeMember(const std::string &name)
-{
- removeMember(findMember(name));
-
- buildLayout();
-}
-
-void PartyWindow::updateOnlne(int id, bool online)
-{
- PartyMember *player = findMember(id);
-
- if (!player)
- return;
-
- player->mAvatar->setOnline(online);
-}
-
-void PartyWindow::showPartyInvite(const std::string &inviter,
- const std::string &partyName)
-{
- // check there isnt already an invite showing
- if (mPartyInviter != "")
- {
- localChatTab->chatLog(_("Received party request, but one already "
- "exists."), BY_SERVER);
- return;
- }
-
- std::string msg;
- // log invite
- if (partyName.empty())
- msg = strprintf(N_("%s has invited you to join their party."),
- inviter.c_str());
- else
- msg = strprintf(N_("%s has invited you to join the %s party."),
- inviter.c_str(), partyName.c_str());
-
- localChatTab->chatLog(msg, BY_SERVER);
-
- // show invite
- acceptDialog = new ConfirmDialog(_("Accept Party Invite"), msg, this);
- acceptDialog->addActionListener(this);
-
- mPartyInviter = inviter;
-}
-
-void PartyWindow::action(const gcn::ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- // check if they accepted the invite
- if (eventId == "yes")
- {
- localChatTab->chatLog(strprintf(_("Accepted invite from %s."),
- mPartyInviter.c_str()));
- Net::getPartyHandler()->inviteResponse(mPartyInviter, true);
- mPartyInviter = "";
- }
- else if (eventId == "no")
- {
- localChatTab->chatLog(strprintf(_("Rejected invite from %s."),
- mPartyInviter.c_str()));
- Net::getPartyHandler()->inviteResponse(mPartyInviter, false);
- mPartyInviter = "";
- }
-}
-
-void clearMembersSub(const std::pair<int, PartyMember*> &p)
-{
- Player *player = dynamic_cast<Player*>(beingManager->findBeing(p.first));
- if (player)
- player->setInParty(false);
-}
-
-void PartyWindow::clearMembers()
-{
- clearLayout();
-
- std::for_each(mMembers.begin(), mMembers.end(), clearMembersSub);
-
- delete_all(mMembers);
- mMembers.clear();
-}
-
-void PartyWindow::buildLayout()
-{
- clearLayout();
- int lastPos = 0;
-
- PartyList::iterator it;
- PartyMember *member;
-
- for (it = mMembers.begin(); it != mMembers.end(); it++)
- {
- member = (*it).second;
- add(member->mAvatar, 0, lastPos);
- lastPos += member->mAvatar->getHeight() + 2;
- }
-}
-
-void PartyWindow::getNames(std::vector<std::string> &names)
-{
- PartyList::iterator i = mMembers.begin();
- names.clear();
-
- while (i != mMembers.end())
- {
- PartyMember *member = (*i).second;
- if (member->getAvatar() && member->getAvatar()->getName() != "")
- {
- std::string name = member->getAvatar()->getName();
- names.push_back(name);
- }
- ++i;
- }
-}
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
deleted file mode 100644
index 4a423f8b..00000000
--- a/src/gui/partywindow.h
+++ /dev/null
@@ -1,149 +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 PARTYWINDOW_H
-#define PARTYWINDOW_H
-
-#include "gui/confirmdialog.h"
-
-#include "gui/widgets/avatar.h"
-#include "gui/widgets/window.h"
-
-#include <guichan/actionevent.hpp>
-#include <guichan/actionlistener.hpp>
-
-#include <string>
-#include <map>
-#include <vector>
-
-class PartyWindow;
-
-/**
- * Party Member
- * Used for storing players in the party
- */
-class PartyMember
-{
- public:
- PartyMember();
- ~PartyMember();
-
- Avatar *getAvatar() const { return mAvatar; }
-
- bool getLeader() const { return mLeader; }
-
- void setLeader(bool leader);
-
- private:
- friend class PartyWindow;
- bool mLeader;
- Avatar *mAvatar;
-};
-
-
-/**
- * Party window.
- *
- * \ingroup Interface
- */
-class PartyWindow : public Window, gcn::ActionListener
-{
- public:
- PartyWindow();
-
- /**
- * Release all the players created.
- */
- ~PartyWindow();
-
- void setPartyName(const std::string &name);
-
- void clearPartyName();
-
- /**
- * Find a party member based on ID. Returns NULL if not found.
- */
- PartyMember *findMember(int id) const;
-
- /**
- * Returns the id of the first member found with the given name or -1
- * if it isn't found.
- */
- int findMember(const std::string &name) const;
-
- /**
- * Update/add a party member.
- */
- void updateMember(int id, const std::string &memberName,
- bool leader = false, bool online = true);
-
- /**
- * Update a member's HP and Max HP
- */
- void updateMemberHP(int id, int hp, int maxhp);
-
- /**
- * Remove party member with the given id.
- */
- void removeMember(int id);
-
- /**
- * Remove party member with the given name.
- */
- void removeMember(const std::string &name);
-
- /**
- * Updates the online state of the member with the given id.
- */
- void updateOnlne(int id, bool online);
-
- /**
- * Show party invite.
- */
- void showPartyInvite(const std::string &inviter,
- const std::string &partyName = "");
-
- /**
- * Handle events.
- */
- void action(const gcn::ActionEvent &event);
-
- void clearMembers();
-
- void getNames(std::vector<std::string> &names);
-
- private:
- /**
- * Find a party member based on ID. Creates if not found.
- */
- PartyMember *findOrCreateMember(int id);
-
- void buildLayout();
-
- typedef std::map<int, PartyMember*> PartyList;
- PartyList mMembers;
- std::string mPartyInviter;
- ConfirmDialog *acceptDialog;
-};
-
-extern PartyWindow *partyWindow;
-
-#endif
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
new file mode 100644
index 00000000..67a9474a
--- /dev/null
+++ b/src/gui/socialwindow.cpp
@@ -0,0 +1,570 @@
+/*
+ * The Mana World
+ * Copyright (C) 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/socialwindow.h"
+
+#include "beingmanager.h"
+#include "guild.h"
+#include "localplayer.h"
+#include "party.h"
+#include "player.h"
+
+#include "gui/confirmdialog.h"
+#include "gui/okdialog.h"
+#include "gui/setup.h"
+#include "gui/textdialog.h"
+
+#include "gui/widgets/avatarlistbox.h"
+#include "gui/widgets/browserbox.h"
+#include "gui/widgets/button.h"
+#include "gui/widgets/chattab.h"
+#include "gui/widgets/container.h"
+#include "gui/widgets/label.h"
+#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/linkhandler.h"
+#include "gui/widgets/popup.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/tab.h"
+#include "gui/widgets/tabbedarea.h"
+
+#include "net/net.h"
+#include "net/guildhandler.h"
+#include "net/partyhandler.h"
+
+#include "utils/dtor.h"
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+class SocialTab : public Tab
+{
+protected:
+ friend class SocialWindow;
+
+ SocialTab():
+ mInviteDialog(NULL),
+ mConfirmDialog(NULL)
+ {}
+
+ ~SocialTab()
+ {
+ // Cleanup dialogs
+ if (mInviteDialog)
+ {
+ mInviteDialog->close();
+ mInviteDialog->scheduleDelete();
+ mInviteDialog = NULL;
+ }
+
+ if (mConfirmDialog)
+ {
+ mConfirmDialog->close();
+ mConfirmDialog->scheduleDelete();
+ mConfirmDialog = NULL;
+ }
+ }
+
+ virtual void invite() = 0;
+
+ virtual void leave() = 0;
+
+ TextDialog *mInviteDialog;
+ ConfirmDialog *mConfirmDialog;
+ ScrollArea *mScroll;
+ AvatarListBox *mList;
+};
+
+class GuildTab : public SocialTab, public gcn::ActionListener
+{
+public:
+ GuildTab(Guild *guild):
+ mGuild(guild)
+ {
+ setCaption(guild->getName());
+
+ mList = new AvatarListBox(guild);
+ mScroll = new ScrollArea(mList);
+
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
+ mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
+ }
+
+ void action(const gcn::ActionEvent &event)
+ {
+ if (event.getId() == "do invite")
+ {
+ std::string name = mInviteDialog->getText();
+ Net::getGuildHandler()->invite(mGuild->getId(), name);
+
+ localChatTab->chatLog(strprintf(_("Invited user %s to guild %s."),
+ name.c_str(),
+ mGuild->getName().c_str()),
+ BY_SERVER);
+ mInviteDialog = NULL;
+ }
+ else if (event.getId() == "yes")
+ {
+ Net::getGuildHandler()->leave(mGuild->getId());
+ localChatTab->chatLog(strprintf(_("Guild %s quit requested."),
+ mGuild->getName().c_str()), BY_SERVER);
+ mConfirmDialog = NULL;
+ }
+ }
+
+protected:
+ void invite()
+ {
+ // TODO - Give feedback on whether the invite succeeded
+ mInviteDialog = new TextDialog(_("Member Invite to Guild"),
+ strprintf(_("Who would you like to invite to guild %s?"),
+ mGuild->getName().c_str()),
+ socialWindow);
+ mInviteDialog->setOKButtonActionId("do invite");
+ mInviteDialog->addActionListener(this);
+ }
+
+ void leave()
+ {
+ mConfirmDialog = new ConfirmDialog(_("Leave Guild?"),
+ strprintf(_("Are you sure you want to leave guild %s?"),
+ mGuild->getName().c_str()),
+ socialWindow);
+
+ mConfirmDialog->addActionListener(this);
+ }
+
+private:
+ Guild *mGuild;
+};
+
+class PartyTab : public SocialTab, public gcn::ActionListener
+{
+public:
+ PartyTab(Party *party):
+ mParty(party)
+ {
+ setCaption(party->getName());
+
+ mList = new AvatarListBox(party);
+ mScroll = new ScrollArea(mList);
+
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
+ mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
+ }
+
+ void action(const gcn::ActionEvent &event)
+ {
+ if (event.getId() == "do invite")
+ {
+ std::string name = mInviteDialog->getText();
+ Net::getPartyHandler()->invite(name);
+
+ localChatTab->chatLog(strprintf(_("Invited user %s to party."),
+ name.c_str()), BY_SERVER);
+ mInviteDialog = NULL;
+ }
+ else if (event.getId() == "yes")
+ {
+ Net::getPartyHandler()->leave();
+ localChatTab->chatLog(strprintf(_("Party %s quit requested."),
+ mParty->getName().c_str()), BY_SERVER);
+ mConfirmDialog = NULL;
+ }
+ }
+
+protected:
+ void invite()
+ {
+ // TODO - Give feedback on whether the invite succeeded
+ mInviteDialog = new TextDialog(_("Member Invite to Party"),
+ strprintf(_("Who would you like to invite to party %s?"),
+ mParty->getName().c_str()),
+ socialWindow);
+ mInviteDialog->setOKButtonActionId("do invite");
+ mInviteDialog->addActionListener(this);
+ }
+
+ void leave()
+ {
+ mConfirmDialog = new ConfirmDialog(_("Leave Party?"),
+ strprintf(_("Are you sure you want to leave party %s?"),
+ mParty->getName().c_str()),
+ socialWindow);
+
+ mConfirmDialog->addActionListener(this);
+ }
+
+private:
+ Party *mParty;
+};
+
+/*class BuddyTab : public SocialTab
+{
+ // TODO?
+};*/
+
+class CreatePopup : public Popup, public LinkHandler
+{
+public:
+ CreatePopup():
+ Popup("SocialCreatePopup")
+ {
+ mBrowserBox = new BrowserBox;
+ mBrowserBox->setPosition(4, 4);
+ mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND);
+ mBrowserBox->setOpaque(false);
+ mBrowserBox->setLinkHandler(this);
+
+ mBrowserBox->addRow(strprintf("@@guild|%s@@", _("Create Guild")));
+ mBrowserBox->addRow(strprintf("@@party|%s@@", _("Create Party")));
+ mBrowserBox->addRow("##3---");
+ mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel")));
+
+ add(mBrowserBox);
+
+ setContentSize(mBrowserBox->getWidth() + 8,
+ mBrowserBox->getHeight() + 8);
+ }
+
+ void handleLink(const std::string &link)
+ {
+ if (link == "guild")
+ {
+ socialWindow->showGuildCreate();
+ }
+ else if (link == "party")
+ {
+ socialWindow->showPartyCreate();
+ // TODO
+
+ printf("Create party\n");
+ }
+
+ setVisible(false);
+ }
+
+ void show(gcn::Widget *parent)
+ {
+ int x, y;
+ parent->getAbsolutePosition(x, y);
+ y += parent->getHeight();
+ setPosition(x, y);
+ setVisible(true);
+ requestMoveToTop();
+ }
+
+private:
+ BrowserBox* mBrowserBox;
+};
+
+SocialWindow::SocialWindow() :
+ Window(_("Social")),
+ mGuildAcceptDialog(NULL),
+ mPartyAcceptDialog(NULL)
+{
+ setWindowName("Social");
+ setVisible(false);
+ setSaveVisible(true);
+ setResizable(true);
+ setSaveVisible(true);
+ setCloseButton(true);
+ setMinWidth(120);
+ setMinHeight(55);
+ setDefaultSize(590, 200, 150, 60);
+ setupWindow->registerWindowForReset(this);
+
+ loadWindowState();
+
+ mCreateButton = new Button(_("Create"), "create", this);
+ mInviteButton = new Button(_("Invite"), "invite", this);
+ mLeaveButton = new Button(_("Leave"), "leave", this);
+ mTabs = new TabbedArea;
+
+ place(0, 0, mCreateButton);
+ place(1, 0, mInviteButton);
+ place(2, 0, mLeaveButton);
+ place(0, 1, mTabs, 4, 4);
+
+ widgetResized(NULL);
+
+ mCreatePopup = new CreatePopup();
+}
+
+SocialWindow::~SocialWindow()
+{
+ // Cleanup invites
+ if (mGuildAcceptDialog)
+ {
+ mGuildAcceptDialog->close();
+ mGuildAcceptDialog->scheduleDelete();
+ mGuildAcceptDialog = NULL;
+
+ mGuildInvited = 0;
+ }
+
+ if (mPartyAcceptDialog)
+ {
+ mPartyAcceptDialog->close();
+ mPartyAcceptDialog->scheduleDelete();
+ mPartyAcceptDialog = NULL;
+
+ mPartyInviter = "";
+ }
+}
+
+bool SocialWindow::addTab(Guild *guild)
+{
+ if (mGuilds.find(guild) != mGuilds.end())
+ return false;
+
+ GuildTab *tab = new GuildTab(guild);
+ mGuilds[guild] = tab;
+
+ mTabs->addTab(tab, tab->mScroll);
+
+ return true;
+}
+
+bool SocialWindow::removeTab(Guild *guild)
+{
+ GuildMap::iterator it = mGuilds.find(guild);
+ if (it == mGuilds.end())
+ return false;
+
+ mTabs->removeTab(it->second);
+ delete it->second;
+ mGuilds.erase(it);
+
+ return true;
+}
+
+bool SocialWindow::addTab(Party *party)
+{
+ if (mParties.find(party) != mParties.end())
+ return false;
+
+ PartyTab *tab = new PartyTab(party);
+ mParties[party] = tab;
+
+ mTabs->addTab(tab, tab->mScroll);
+
+ return true;
+}
+
+bool SocialWindow::removeTab(Party *party)
+{
+ PartyMap::iterator it = mParties.find(party);
+ if (it == mParties.end())
+ return false;
+
+ mTabs->removeTab(it->second);
+ delete it->second;
+ mParties.erase(it);
+
+ return true;
+}
+
+void SocialWindow::action(const gcn::ActionEvent &event)
+{
+ const std::string &eventId = event.getId();
+
+ if (event.getSource() == mPartyAcceptDialog)
+ {
+ // check if they accepted the invite
+ if (eventId == "yes")
+ {
+ localChatTab->chatLog(strprintf(_("Accepted party invite from %s."),
+ mPartyInviter.c_str()));
+ Net::getPartyHandler()->inviteResponse(mPartyInviter, true);
+ }
+ else if (eventId == "no")
+ {
+ localChatTab->chatLog(strprintf(_("Rejected party invite from %s."),
+ mPartyInviter.c_str()));
+ Net::getPartyHandler()->inviteResponse(mPartyInviter, false);
+ }
+
+ mPartyInviter = "";
+ mPartyAcceptDialog = NULL;
+ }
+ else if (event.getSource() == mGuildAcceptDialog)
+ {
+ // check if they accepted the invite
+ if (eventId == "yes")
+ {
+ localChatTab->chatLog(strprintf(_("Accepted guild invite from %s."),
+ mPartyInviter.c_str()));
+ Net::getGuildHandler()->inviteResponse(mGuildInvited, true);
+ }
+ else if (eventId == "no")
+ {
+ localChatTab->chatLog(strprintf(_("Rejected guild invite from %s."),
+ mPartyInviter.c_str()));
+ Net::getGuildHandler()->inviteResponse(mGuildInvited, false);
+ }
+
+ mGuildInvited = 0;
+ mGuildAcceptDialog = NULL;
+ }
+ else if (event.getId() == "create")
+ {
+ mCreatePopup->show(mCreateButton);
+ }
+ else if (event.getId() == "invite")
+ {
+ SocialTab *tab = dynamic_cast<SocialTab*>(mTabs->getSelectedTab());
+
+ if (tab)
+ {
+ tab->invite();
+ }
+ }
+ else if (event.getId() == "leave")
+ {
+ SocialTab *tab = dynamic_cast<SocialTab*>(mTabs->getSelectedTab());
+
+ if (tab)
+ {
+ tab->leave();
+ }
+ }
+ else if (event.getId() == "create guild")
+ {
+ std::string name = mGuildCreateDialog->getText();
+
+ if (name.size() > 16)
+ {
+ // TODO : State too many characters in input.
+ return;
+ }
+
+ Net::getGuildHandler()->create(name);
+ localChatTab->chatLog(strprintf(_("Creating guild called %s."),
+ name.c_str()), BY_SERVER);
+ }
+ else if (event.getId() == "create party")
+ {
+ std::string name = mPartyCreateDialog->getText();
+
+ if (name.size() > 16)
+ {
+ // TODO : State too many characters in input.
+ return;
+ }
+
+ Net::getPartyHandler()->create(name);
+ localChatTab->chatLog(strprintf(_("Creating party called %s."),
+ name.c_str()), BY_SERVER);
+ }
+}
+
+void SocialWindow::showGuildCreate()
+{
+ mGuildCreateDialog = new TextDialog(_("Guild Name"),
+ _("Choose your guild's name."), this);
+ mGuildCreateDialog->setOKButtonActionId("create guild");
+ mGuildCreateDialog->addActionListener(this);
+}
+
+void SocialWindow::showGuildInvite(const std::string &guildName,
+ const int guildId,
+ const std::string &inviterName)
+{
+ // check there isnt already an invite showing
+ if (mGuildInvited != 0)
+ {
+ localChatTab->chatLog(_("Received guild request, but one already "
+ "exists."), BY_SERVER);
+ return;
+ }
+
+ std::string msg = strprintf(_("%s has invited you to join the guild %s."),
+ inviterName.c_str(), guildName.c_str());
+ localChatTab->chatLog(msg, BY_SERVER);
+
+ // show invite
+ mGuildAcceptDialog = new ConfirmDialog(_("Accept Guild Invite"), msg, this);
+ mGuildAcceptDialog->addActionListener(this);
+
+ mGuildInvited = guildId;
+}
+
+void SocialWindow::showPartyInvite(const std::string &partyName,
+ const std::string &inviter)
+{
+ // check there isnt already an invite showing
+ if (mPartyInviter != "")
+ {
+ localChatTab->chatLog(_("Received party request, but one already "
+ "exists."), BY_SERVER);
+ return;
+ }
+
+ std::string msg;
+ if (inviter.empty())
+ {
+ if (partyName.empty())
+ {
+ msg = _("You have been invited you to join a party.");
+ }
+ else
+ {
+ msg = strprintf(_("You have been invited to join the %s party."),
+ partyName.c_str());
+ }
+ }
+ else
+ {
+ if (partyName.empty())
+ {
+ msg = strprintf(_("%s has invited you to join their party."),
+ inviter.c_str());
+ }
+ else
+ {
+ msg = strprintf(_("%s has invited you to join the %s party."),
+ inviter.c_str(), partyName.c_str());
+ }
+ }
+
+ localChatTab->chatLog(msg, BY_SERVER);
+
+ // show invite
+ mPartyAcceptDialog = new ConfirmDialog(_("Accept Party Invite"), msg, this);
+ mPartyAcceptDialog->addActionListener(this);
+
+ mPartyInviter = inviter;
+}
+
+void SocialWindow::showPartyCreate()
+{
+ if (player_node->getParty())
+ {
+ new OkDialog(_("Create Party"),
+ _("Cannot create party. You are already in a party"),
+ this);
+ return;
+ }
+
+ mPartyCreateDialog = new TextDialog(_("Party Name"),
+ _("Choose your part's name."), this);
+ mPartyCreateDialog->setOKButtonActionId("create party");
+ mPartyCreateDialog->addActionListener(this);
+}
diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h
new file mode 100644
index 00000000..56460230
--- /dev/null
+++ b/src/gui/socialwindow.h
@@ -0,0 +1,105 @@
+/*
+ * The Mana World
+ * Copyright (C) 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 SOCIALWINDOW_H
+#define SOCIALWINDOW_H
+
+#include "gui/widgets/window.h"
+
+#include <guichan/actionevent.hpp>
+#include <guichan/actionlistener.hpp>
+
+#include <string>
+#include <map>
+
+class Button;
+class ConfirmDialog;
+class CreatePopup;
+class Guild;
+class Party;
+class SocialTab;
+class Tab;
+class TabbedArea;
+class TextDialog;
+
+/**
+ * Party window.
+ *
+ * \ingroup Interface
+ */
+class SocialWindow : public Window, gcn::ActionListener
+{
+public:
+ SocialWindow();
+
+ ~SocialWindow();
+
+ bool addTab(Guild *guild);
+
+ bool removeTab(Guild *guild);
+
+ bool addTab(Party *party);
+
+ bool removeTab(Party *party);
+
+ /**
+ * Handle events.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ void showGuildInvite(const std::string &guildName, const int guildId,
+ const std::string &inviterName);
+
+ void showGuildCreate();
+
+ void showPartyInvite(const std::string &partyName,
+ const std::string &inviter = "");
+
+ void showPartyCreate();
+
+protected:
+ friend class SocialTab;
+
+ int mGuildInvited;
+ ConfirmDialog *mGuildAcceptDialog;
+ TextDialog *mGuildCreateDialog;
+
+ std::string mPartyInviter;
+ ConfirmDialog *mPartyAcceptDialog;
+ TextDialog *mPartyCreateDialog;
+
+ typedef std::map<Guild*, SocialTab*> GuildMap;
+ GuildMap mGuilds;
+
+ typedef std::map<Party*, SocialTab*> PartyMap;
+ PartyMap mParties;
+
+ CreatePopup *mCreatePopup;
+
+ Button *mCreateButton;
+ Button *mInviteButton;
+ Button *mLeaveButton;
+ TabbedArea *mTabs;
+};
+
+extern SocialWindow *socialWindow;
+
+#endif // SOCIALWINDOW_H
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
index 0bdd6030..3e8af7e8 100644
--- a/src/gui/textdialog.cpp
+++ b/src/gui/textdialog.cpp
@@ -65,6 +65,7 @@ TextDialog::TextDialog(const std::string &title, const std::string &msg,
getParent()->moveToTop(this);
}
setVisible(true);
+ requestModalFocus();
mTextField->requestFocus();
instances++;
@@ -77,14 +78,10 @@ TextDialog::~TextDialog()
void TextDialog::action(const gcn::ActionEvent &event)
{
- // Proxy button events to our listeners
- ActionListenerIterator i;
- for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
- {
- (*i)->action(event);
- }
+ setActionEventId(event.getId());
+ distributeActionEvent();
- if (event.getId() == "CANCEL" || event.getId() == "OK")
+ if (event.getId() == "CANCEL" || event.getSource() == mOkButton)
{
scheduleDelete();
}
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);
}
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 460d12b4..e57f35fa 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -43,7 +43,7 @@ extern Window *setupWindow;
extern Window *skillDialog;
extern Window *specialsWindow;
extern Window *statusWindow;
-extern Window *guildWindow;
+extern Window *socialWindow;
WindowMenu::WindowMenu():
mEmotePopup(0)
@@ -57,7 +57,7 @@ WindowMenu::WindowMenu():
N_("Inventory"),
N_("Skills"),
N_("Specials"),
- N_("Guilds"),
+ N_("Social"),
N_("Shortcut"),
N_("Setup"),
0
@@ -127,9 +127,9 @@ void WindowMenu::action(const gcn::ActionEvent &event)
{
window = specialsWindow;
}
- else if (event.getId() == "Guilds")
+ else if (event.getId() == "Social")
{
- window = guildWindow;
+ window = socialWindow;
}
else if (event.getId() == "Shortcut")
{