summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/guildwindow.cpp56
-rw-r--r--src/gui/guildwindow.h27
-rw-r--r--src/net/chatserver/guild.cpp26
-rw-r--r--src/net/chatserver/guild.h11
-rw-r--r--src/net/guildhandler.cpp14
-rw-r--r--src/net/guildhandler.h2
6 files changed, 102 insertions, 34 deletions
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
index 30305ca4..f81d9209 100644
--- a/src/gui/guildwindow.cpp
+++ b/src/gui/guildwindow.cpp
@@ -33,12 +33,15 @@
#include "textdialog.h"
#include "windowcontainer.h"
+#include "widgets/layout.h"
+
#include "../guild.h"
#include "../log.h"
#include "../localplayer.h"
#include "../net/chatserver/guild.h"
#include "../utils/dtor.h"
+#include "../utils/gettext.h"
GuildWindow::GuildWindow(LocalPlayer *player):
Window(player->getName()),
@@ -53,19 +56,23 @@ GuildWindow::GuildWindow(LocalPlayer *player):
setDefaultSize(124, 41, 288, 330);
// Set button events Id
- mGuildButton[0] = new Button("Create Guild", "CREATE_GUILD", this);
- mGuildButton[1] = new Button("Invite User", "INVITE_USER", this);
- mGuildButton[0]->setPosition(15,10);
- mGuildButton[1]->setPosition(115,10);
+ 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);
mGuildsContainer = new TabbedContainer();
mGuildsContainer->setOpaque(false);
- add(mGuildButton[0]);
- add(mGuildButton[1]);
- add(mGuildsContainer);
+ place(0, 0, mGuildButton[0]);
+ place(1, 0, mGuildButton[1]);
+ place(2, 0, mGuildButton[2]);
+ place(0, 1, mGuildsContainer);
+ Layout &layout = getLayout();
+ layout.setColWidth(0, 48);
+ layout.setColWidth(1, 65);
loadWindowState(player->getName());
}
@@ -94,6 +101,13 @@ void GuildWindow::action(const gcn::ActionEvent &event)
// Stats Part
if (eventId == "CREATE_GUILD")
{
+ if (mGuildsContainer->getNumberOfTabs() > 1)
+ {
+ // This is just to limit the number of guild tabs that are created
+ // TODO: Either limit this server side, or fix the interface issue
+ chatWindow->chatLog("Current maximum number of guilds ownable is 2", BY_SERVER);
+ return;
+ }
// 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);
@@ -108,6 +122,15 @@ void GuildWindow::action(const gcn::ActionEvent &event)
inviteDialog->setOKButtonActionId("INVITE_USER_OK");
inviteDialog->addActionListener(this);
}
+ else if (eventId == "QUIT_GUILD")
+ {
+ short guild = getSelectedGuild();
+ if (guild)
+ {
+ Net::ChatServer::Guild::quitGuild(guild);
+ chatWindow->chatLog("Guild " + mGuildsContainer->getActiveWidget() + " quit", BY_SERVER);
+ }
+ }
else if (eventId == "CREATE_GUILD_OK")
{
std::string name = guildDialog->getText();
@@ -153,7 +176,7 @@ void GuildWindow::newGuildTab(const std::string &guildName)
tab->setHeight(getHeight() - 2 * tab->getBorderSize());
tab->setOpaque(false);
ListBox *list = new ListBox();
- list->setListModel(player_node->getGuild(guildName));
+ list->setListModel(mPlayer->getGuild(guildName));
ScrollArea *sa = new ScrollArea(list);
sa->setDimension(gcn::Rectangle(5, 5, 135, 250));
tab->add(sa);
@@ -173,7 +196,6 @@ void GuildWindow::updateTab()
void GuildWindow::setTab(const std::string &guildName)
{
-
// Only enable invite button if user has rights
if(mPlayer->checkInviteRights(guildName))
{
@@ -183,6 +205,8 @@ void GuildWindow::setTab(const std::string &guildName)
{
mGuildButton[1]->setEnabled(false);
}
+
+ mGuildButton[2]->setEnabled(true);
}
bool GuildWindow::isFocused()
@@ -192,7 +216,13 @@ bool GuildWindow::isFocused()
short GuildWindow::getSelectedGuild()
{
- return mPlayer->getGuild(mGuildsContainer->getActiveWidget())->getId();
+ Guild *guild = mPlayer->getGuild(mGuildsContainer->getActiveWidget());
+ if (guild)
+ {
+ return guild->getId();
+ }
+
+ return 0;
}
void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName)
@@ -211,3 +241,9 @@ void GuildWindow::requestMemberList(short guildId)
// Get the list of members for displaying in the guild window.
Net::ChatServer::Guild::getGuildMembers(guildId);
}
+
+void GuildWindow::removeTab()
+{
+ mGuildsContainer->removeTab(mGuildsContainer->getActiveWidget());
+ mGuildsContainer->logic();
+}
diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h
index 2f494a9a..e40727b6 100644
--- a/src/gui/guildwindow.h
+++ b/src/gui/guildwindow.h
@@ -3,7 +3,7 @@
* A file part of The Mana World
*
* Created by David Athay on 06/03/2007.
- *
+ *
* Copyright (c) 2007, The Mana World Development Team
* All rights reserved.
*
@@ -56,7 +56,7 @@ public:
* Constructor.
*/
GuildWindow(LocalPlayer *player);
-
+
/**
* Destructor.
*/
@@ -76,47 +76,52 @@ public:
* 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 isFocused();
-
+
/**
* Create a dialog for accepting an invite
*/
void openAcceptDialog(const std::string &inviterName, const std::string &guildName);
-
+
/**
* Request member list
*/
void requestMemberList(short guildId);
-
+
+ /**
+ * Removes the selected tab
+ */
+ void removeTab();
+
protected:
/**
* Get selected guild tab
* @return Returns selected guild
*/
short getSelectedGuild();
-
+
private:
LocalPlayer *mPlayer;
- gcn::Button *mGuildButton[2];
+ gcn::Button *mGuildButton[3];
TextDialog *guildDialog;
TextDialog *inviteDialog;
ConfirmDialog *acceptDialog;
diff --git a/src/net/chatserver/guild.cpp b/src/net/chatserver/guild.cpp
index 441a52c2..c1114065 100644
--- a/src/net/chatserver/guild.cpp
+++ b/src/net/chatserver/guild.cpp
@@ -36,9 +36,9 @@ void Net::ChatServer::Guild::createGuild(const std::string &name)
{
logger->log("Sending PCMSG_GUILD_CREATE");
MessageOut msg(PCMSG_GUILD_CREATE);
-
+
msg.writeString(name);
-
+
Net::ChatServer::connection->send(msg);
}
@@ -46,10 +46,10 @@ void Net::ChatServer::Guild::invitePlayer(const std::string &name, short guildId
{
logger->log("Sending PCMSG_GUILD_INVITE");
MessageOut msg(PCMSG_GUILD_INVITE);
-
+
msg.writeInt16(guildId);
msg.writeString(name);
-
+
Net::ChatServer::connection->send(msg);
}
@@ -57,9 +57,9 @@ void Net::ChatServer::Guild::acceptInvite(const std::string &name)
{
logger->log("Sending PCMSG_GUILD_ACCEPT");
MessageOut msg(PCMSG_GUILD_ACCEPT);
-
+
msg.writeString(name);
-
+
Net::ChatServer::connection->send(msg);
}
@@ -67,8 +67,18 @@ void Net::ChatServer::Guild::getGuildMembers(short guildId)
{
logger->log("Sending PCMSG_GUILD_GET_MEMBERS");
MessageOut msg(PCMSG_GUILD_GET_MEMBERS);
-
+
msg.writeInt16(guildId);
-
+
+ Net::ChatServer::connection->send(msg);
+}
+
+void Net::ChatServer::Guild::quitGuild(short guildId)
+{
+ logger->log("Sending PCMSG_GUILD_QUIT");
+ MessageOut msg(PCMSG_GUILD_QUIT);
+
+ msg.writeInt16(guildId);
+
Net::ChatServer::connection->send(msg);
}
diff --git a/src/net/chatserver/guild.h b/src/net/chatserver/guild.h
index 849cd0a4..5800c738 100644
--- a/src/net/chatserver/guild.h
+++ b/src/net/chatserver/guild.h
@@ -37,21 +37,26 @@ namespace Net
* Create guild.
*/
void createGuild(const std::string &name);
-
+
/**
* Invite a player to your guild.
*/
void invitePlayer(const std::string &name, short guildId);
-
+
/**
* Accept an invite another player has sent to join their guild.
*/
void acceptInvite(const std::string &name);
-
+
/**
* Get a list of members in a guild.
*/
void getGuildMembers(short guildId);
+
+ /**
+ * Quit guild.
+ */
+ void quitGuild(short guildId);
}
}
}
diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp
index 88528584..0b36f8e4 100644
--- a/src/net/guildhandler.cpp
+++ b/src/net/guildhandler.cpp
@@ -25,8 +25,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
- * $Id$
+ * $Id:$
*/
+
#include <iostream>
#include "guildhandler.h"
@@ -53,6 +54,7 @@ GuildHandler::GuildHandler()
CPMSG_GUILD_LEFT,
CPMSG_GUILD_INVITED,
CPMSG_GUILD_REJOIN,
+ CPMSG_GUILD_QUIT_RESPONSE,
0
};
handledMessages = _messages;
@@ -131,6 +133,16 @@ void GuildHandler::handleMessage(MessageIn &msg)
joinedGuild(msg);
} break;
+
+ case CPMSG_GUILD_QUIT_RESPONSE:
+ {
+ logger->log("Received CPMSG_GUILD_QUIT_RESPONSE");
+
+ if (msg.readInt8() == ERRMSG_OK)
+ {
+ guildWindow->removeTab();
+ }
+ } break;
}
}
diff --git a/src/net/guildhandler.h b/src/net/guildhandler.h
index 5ac0a52e..ec5780fc 100644
--- a/src/net/guildhandler.h
+++ b/src/net/guildhandler.h
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
- * $Id$
+ * $Id:$
*/
#ifndef _TMW_NET_GUILDHANDLER_H