summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-29 20:35:19 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-29 20:36:58 -0600
commitbbf4d657e77fd39887b9941af1fe75a5ec27d988 (patch)
treed03c2973cff4d11e2eddbb856483369255ee40af /src/gui
parent985e65f31b9cc06f13b733ddd5c7a9daa1331e21 (diff)
downloadmana-client-bbf4d657e77fd39887b9941af1fe75a5ec27d988.tar.gz
mana-client-bbf4d657e77fd39887b9941af1fe75a5ec27d988.tar.bz2
mana-client-bbf4d657e77fd39887b9941af1fe75a5ec27d988.tar.xz
mana-client-bbf4d657e77fd39887b9941af1fe75a5ec27d988.zip
Fix up eAthena party handling some more
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp10
-rw-r--r--src/gui/chat.h9
-rw-r--r--src/gui/partywindow.cpp86
-rw-r--r--src/gui/partywindow.h48
-rw-r--r--src/gui/popupmenu.cpp5
-rw-r--r--src/gui/widgets/avatar.cpp48
-rw-r--r--src/gui/widgets/avatar.h16
-rw-r--r--src/gui/widgets/chattab.cpp27
-rw-r--r--src/gui/widgets/chattab.h5
9 files changed, 144 insertions, 110 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 10993027..014ac8b5 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -68,12 +68,9 @@ ChatWindow::ChatWindow():
mChatInput->addKeyListener(this);
mCurHist = mHistory.end();
-#ifdef EATHENA_SUPPORT
- // Read the party prefix
- std::string partyPrefix = config.getValue("PartyPrefix", "$");
- mPartyPrefix = (partyPrefix.empty() ? '$' : partyPrefix.at(0));
mReturnToggles = config.getValue("ReturnToggles", "0") == "1";
+#ifdef EATHENA_SUPPORT
// If the player had @assert on in the last session, ask the server to
// run the @assert command for the player again. Convenience for GMs.
if (config.getValue(player_node->getName() + "GMassert", 0)) {
@@ -86,13 +83,8 @@ ChatWindow::ChatWindow():
ChatWindow::~ChatWindow()
{
-#ifdef EATHENA_SUPPORT
- char partyPrefix[2] = ".";
- *partyPrefix = mPartyPrefix;
- config.setValue("PartyPrefix", partyPrefix);
config.setValue("ReturnToggles", mReturnToggles ? "1" : "0");
delete mRecorder;
-#endif
delete_all(mWhispers);
delete mItemLinkHandler;
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 3a2f7fdb..3cf2a738 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -159,11 +159,6 @@ class ChatWindow : public Window,
*/
void scroll(int amount);
-#ifdef EATHENA_SUPPORT
- char getPartyPrefix() const { return mPartyPrefix; }
- void setPartyPrefix(char prefix) { mPartyPrefix = prefix; }
-#endif
-
/**
* Sets the file being recorded to
*
@@ -192,10 +187,6 @@ class ChatWindow : public Window,
void adjustTabSize();
-#ifdef EATHENA_SUPPORT
- char mPartyPrefix; /**< Messages beginning with the prefix are sent to
- the party */
-#endif
/** Used for showing item popup on clicking links **/
ItemLinkHandler *mItemLinkHandler;
Recorder *mRecorder;
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index f5cebdfd..d2fd7173 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -21,7 +21,6 @@
#include "gui/partywindow.h"
-#include "gui/widgets/avatar.h"
#include "gui/widgets/chattab.h"
#ifdef TMWSERV_SUPPORT
@@ -49,7 +48,7 @@ PartyWindow::PartyWindow() : Window(_("Party"))
PartyWindow::~PartyWindow()
{
- mPartyMembers.clear();
+ mMembers.clear();
}
void PartyWindow::draw(gcn::Graphics *graphics)
@@ -57,61 +56,84 @@ void PartyWindow::draw(gcn::Graphics *graphics)
Window::draw(graphics);
}
-void PartyWindow::addPartyMember(const std::string &memberName)
+PartyMember *PartyWindow::findMember2(int id)
{
- // check to see if player is already in the party
- PartyList::iterator itr = mPartyMembers.begin(),
- itr_end = mPartyMembers.end();
+ PartyMember *member = findMember(id);
+
+ if (!member)
+ {
+ member = new PartyMember;
+ member->avatar = new Avatar("");
+ add(member->avatar, 0, (mMembers.size() - 1) * 14);
+ mMembers[id] = member;
+ }
+
+ return member;
+}
+
+int PartyWindow::findMember(const std::string &name)
+{
+ PartyList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr).name == memberName)
+ if ((*itr).second->name == name)
{
- // already in the party, dont add
- return;
+ return (*itr).first;
}
++itr;
}
- // create new party member
- PartyMember player;
- player.name = memberName;
- mPartyMembers.push_back(player);
+ return -1;
+}
- // add avatar of the new member to window
- Avatar *avatar = new Avatar(memberName);
- add(avatar, 0, (mPartyMembers.size() - 1)*14);
+void PartyWindow::updateMember(int id, const std::string &memberName,
+ bool leader, bool online)
+{
+ // create new party member
+ PartyMember *player = findMember2(id);
+ player->id = id;
+ player->name = memberName;
+ player->leader = leader;
+ player->online = online;
+ player->avatar->setName(memberName);
+ player->avatar->setOnline(online);
// show the window
- if (mPartyMembers.size() > 0)
+ if (mMembers.size() > 0)
{
setVisible(true);
}
}
-void PartyWindow::removePartyMember(const std::string &memberName)
+void PartyWindow::removeMember(int id)
{
- // remove the party member
- PartyList::iterator itr = mPartyMembers.begin(),
- itr_end = mPartyMembers.end();
-
- while (itr != itr_end)
- {
- if ((*itr).name == memberName)
- {
- mPartyMembers.erase(itr);
- break;
- }
- ++itr;
- }
+ mMembers.erase(id);
// if no-one left, remove the party window
- if (mPartyMembers.size() < 1)
+ if (mMembers.size() < 1)
{
setVisible(false);
}
}
+void PartyWindow::removeMember(const std::string &name)
+{
+ removeMember(findMember(name));
+}
+
+void PartyWindow::updateOnlne(int id, bool online)
+{
+ PartyMember *player = findMember(id);
+
+ if (!player)
+ return;
+
+ player->online = online;
+ player->avatar->setOnline(online);
+}
+
void PartyWindow::showPartyInvite(const std::string &inviter,
const std::string &partyName)
{
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
index 64cfb582..049030e5 100644
--- a/src/gui/partywindow.h
+++ b/src/gui/partywindow.h
@@ -25,8 +25,10 @@
#include "window.h"
#include "confirm_dialog.h"
+#include "gui/widgets/avatar.h"
+
#include <string>
-#include <vector>
+#include <map>
#include <guichan/actionevent.hpp>
#include <guichan/actionlistener.hpp>
@@ -37,8 +39,13 @@
*/
struct PartyMember
{
+ int id;
std::string name;
- int vitality;
+ int health;
+ int healthMax;
+ bool leader;
+ bool online;
+ Avatar *avatar;
};
/**
@@ -65,14 +72,41 @@ class PartyWindow : public Window, gcn::ActionListener
void draw(gcn::Graphics *graphics);
/**
- * Add party member
+ * Find a party member based on ID
+ */
+ PartyMember *findMember(int id) { return mMembers[id]; }
+
+ /**
+ * Find a party member based on ID. Creates if it doesn't already exist.
+ */
+ PartyMember *findMember2(int id);
+
+ /**
+ * 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);
+
+ /**
+ * Update/add a party member
+ */
+ void updateMember(int id, const std::string &memberName,
+ bool leader = false, bool online = true);
+
+ /**
+ * Remove party member
+ */
+ void removeMember(int id);
+
+ /**
+ * Remove party member
*/
- void addPartyMember(const std::string &memberName);
+ void removeMember(const std::string &name);
/**
* Remove party member
*/
- void removePartyMember(const std::string &memberName);
+ void updateOnlne(int id, bool online);
/**
* Show party invite
@@ -86,8 +120,8 @@ class PartyWindow : public Window, gcn::ActionListener
void action(const gcn::ActionEvent &event);
private:
- typedef std::vector<PartyMember> PartyList;
- PartyList mPartyMembers;
+ typedef std::map<int, PartyMember*> PartyList;
+ PartyList mMembers;
std::string mPartyInviter;
ConfirmDialog *acceptDialog;
};
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 1f36ef45..d0281c1f 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -215,13 +215,12 @@ void PopupMenu::handleLink(const std::string &link)
{
player_node->inviteToGuild(being);
}
-
+#endif
// Add player to your party
else if (link == "party")
{
- player_node->inviteToParty(being->getName());
+ player_node->inviteToParty(dynamic_cast<Player*>(being));
}
-#endif
/*
// Follow Player action
else if (link == "follow")
diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp
index a36c0302..2603e3ae 100644
--- a/src/gui/widgets/avatar.cpp
+++ b/src/gui/widgets/avatar.cpp
@@ -28,28 +28,52 @@
#include <guichan/widgets/label.hpp>
+namespace {
+ Image *avatarStatusOffline;
+ Image *avatarStatusOnline;
+ int avatarCount = 0;
+}
+
Avatar::Avatar(const std::string &name):
mName(name)
{
+ setOpaque(false);
setSize(110, 12);
+
+ 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();
+
+ mStatus = new Icon(avatarStatusOffline);
+ mStatus->setSize(12, 12);
+ add(mStatus, 1, 0);
+
mLabel = new gcn::Label(name);
mLabel->setSize(85, 12);
- mLabel->setPosition(25, 0);
- ResourceManager *resman = ResourceManager::getInstance();
- mStatusOffline = resman->getImage("graphics/gui/circle-gray.png");
- mStatusOnline = resman->getImage("graphics/gui/circle-green.png");
- mStatus = new Icon(mStatusOffline);
- mStatus->setSize(25, 12);
- mStatus->setPosition(0, 0);
+ add(mLabel, 14, 0);
}
-void Avatar::setOnline(bool online)
+Avatar::~Avatar()
{
- mStatus->setImage(online ? mStatusOnline : mStatusOffline);
+ avatarCount--;
+
+ avatarStatusOffline->decRef();
+ avatarStatusOnline->decRef();
}
-void Avatar::draw(gcn::Graphics *g)
+void Avatar::setName(const std::string &name)
+{
+ mName = name;
+ mLabel->setCaption(name);
+}
+
+void Avatar::setOnline(bool online)
{
- mLabel->draw(g);
- mStatus->draw(g);
+ mStatus->setImage(online ? avatarStatusOnline : avatarStatusOffline);
}
diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h
index 16972104..026a3581 100644
--- a/src/gui/widgets/avatar.h
+++ b/src/gui/widgets/avatar.h
@@ -24,14 +24,14 @@
#include "guichanfwd.h"
-#include <guichan/widget.hpp>
+#include "gui/gccontainer.h"
#include <string>
class Image;
class Icon;
-class Avatar : public gcn::Widget
+class Avatar : public GCContainer
{
public:
/**
@@ -40,21 +40,21 @@ public:
*/
Avatar(const std::string &name);
+ ~Avatar();
+
/**
- * Set the avatar online status.
+ * Set the avatar's name.
*/
- void setOnline(bool online);
+ void setName(const std::string &name);
/**
- * Draws the avatar.
+ * Set the avatar's online status.
*/
- void draw(gcn::Graphics *g);
+ void setOnline(bool online);
private:
std::string mName;
Icon *mStatus;
- Image *mStatusOnline;
- Image *mStatusOffline;
gcn::Label *mLabel;
};
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index c4563cc9..4a63bbcd 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -150,12 +150,6 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
// TODO: Use a predefined color
lineColor = "##2"; // Equiv. to BrowserBox::GREEN
break;
-#ifdef EATHENA_SUPPORT
- case BY_PARTY:
- tmp.nick += CAT_NORMAL;
- lineColor = "##P";
- break;
-#endif
case ACT_WHISPER:
// Resend whisper through normal mechanism
chatWindow->whisper(tmp.nick, tmp.text);
@@ -215,7 +209,7 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
chatWindow->mRecorder->record(line.substr(3));
}
-void ChatTab::chatLog(std::string &nick, std::string &msg)
+void ChatTab::chatLog(const std::string &nick, const std::string &msg)
{
chatLog(nick + CAT_NORMAL + msg, nick == player_node->getName() ?
BY_PLAYER : BY_OTHER, false);
@@ -227,25 +221,6 @@ void ChatTab::chatInput(std::string &msg)
if (msg.empty()) return;
-#ifdef EATHENA_SUPPORT
- // Send party message
- if (msg.at(0) == chatWindow->mPartyPrefix)
- {
- msg.erase(0, 1);
- std::size_t length = msg.length() + 1;
-
- if (length == 0)
- {
- chatLog(_("Trying to send a blank party message."), BY_SERVER, true);
- return;
- }
- MessageOut outMsg(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(length + 4);
- outMsg.writeString(msg, length);
- return;
- }
-#endif
-
// Check for item link
std::string::size_type start = msg.find('[');
while (start != std::string::npos && msg[start+1] != '@')
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 52449f6f..76b33011 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -34,9 +34,6 @@ class ScrollArea;
enum
{
BY_GM,
-#ifdef EATHENA_SUPPORT
- BY_PARTY,
-#endif
BY_PLAYER,
BY_OTHER,
BY_SERVER,
@@ -86,7 +83,7 @@ class ChatTab : public Tab
* @param msg The message text which is to be sent.
*
*/
- void chatLog(std::string &nick, std::string &msg);
+ void chatLog(const std::string &nick, const std::string &msg);
/**
* Determines whether the message is a command or message, then