summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-02-28 12:31:04 +0000
committerDavid Athay <ko2fan@gmail.com>2008-02-28 12:31:04 +0000
commitfb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f (patch)
tree65e3086f341bb92154e99806f3b6255d9696ed4b /src/gui
parentac2de5e0bd7dfc79e344b6724ee6a13db9994aa4 (diff)
downloadmana-client-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.gz
mana-client-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.bz2
mana-client-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.tar.xz
mana-client-fb3cbeddd6f5d59e3f83da059b2a1d4bed2cb80f.zip
Work in Progress commit of guilds.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp4
-rw-r--r--src/gui/guildlistbox.cpp98
-rw-r--r--src/gui/guildlistbox.h76
-rw-r--r--src/gui/guildwindow.cpp223
-rw-r--r--src/gui/guildwindow.h133
-rw-r--r--src/gui/listbox.cpp6
-rw-r--r--src/gui/listbox.h1
-rw-r--r--src/gui/menuwindow.cpp6
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/textdialog.cpp93
-rw-r--r--src/gui/textdialog.h67
-rw-r--r--src/gui/truetypefont.h4
12 files changed, 713 insertions, 0 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 8f5ffd50..2ef7aba3 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,7 +26,11 @@
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
#include <guichan/imagefont.hpp>
+#ifdef __APPLE__
+#include <SDL_ttf/SDL_ttf.h>
+#else
#include <SDL/SDL_ttf.h>
+#endif
#include "focushandler.h"
#include "sdlinput.h"
diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp
new file mode 100644
index 00000000..1a392d2d
--- /dev/null
+++ b/src/gui/guildlistbox.cpp
@@ -0,0 +1,98 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "guildlistbox.h"
+
+#include "../graphics.h"
+
+#include <guichan/font.hpp>
+
+GuildListBox::GuildListBox():
+ ListBox(NULL)
+{
+
+}
+
+void GuildListBox::draw(gcn::Graphics *graphics)
+{
+ if (!mListModel)
+ return;
+
+ 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));
+ }
+
+ // TODO: Add online status image
+
+ // Draw the list elements
+ for (int i = 0, y = 0;
+ i < mListModel->getNumberOfElements();
+ ++i, y += fontHeight)
+ {
+ graphics->drawText(mListModel->getElementAt(i), 1, 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);
+ }
+ }
+
+ fireSelectionChangedEvent();
+}
+
+void GuildListBox::mousePressed(gcn::MouseEvent &event)
+{
+ if (event.getButton() == gcn::MouseEvent::LEFT)
+ {
+ // TODO: Add guild functions, ie private messaging
+ int y = event.getY();
+ setSelected(y / getFont()->getHeight());
+ generateAction();
+ }
+}
diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h
new file mode 100644
index 00000000..befaef1f
--- /dev/null
+++ b/src/gui/guildlistbox.h
@@ -0,0 +1,76 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_GUI_GUILDLISTBOX_H
+#define _TMW_GUI_GUILDLISTBOX_H
+
+#include <string>
+#include <vector>
+
+#include "listbox.h"
+
+class GuildListBox : public ListBox
+{
+public:
+ /**
+ * Constructor
+ */
+ GuildListBox();
+
+ /**
+ * Set ListModel
+ */
+ void setList(gcn::ListModel *listModel);
+
+ /**
+ * Draws the list box.
+ */
+ void draw(gcn::Graphics *graphics);
+
+ void mousePressed(gcn::MouseEvent &event);
+
+ /**
+ * Adds a listener to the list that's notified each time a change to
+ * the selection occurs.
+ */
+ void addSelectionListener(SelectionListener *listener)
+ {
+ mListeners.push_back(listener);
+ }
+
+ /**
+ * Removes a listener from the list that's notified each time a change
+ * to the selection occurs.
+ */
+ void removeSelectionListener(SelectionListener *listener)
+ {
+ mListeners.remove(listener);
+ }
+
+ /**
+ * Sets the index of the selected element.
+ */
+ void setSelected(int selected);
+};
+
+#endif
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
new file mode 100644
index 00000000..a3d46ff5
--- /dev/null
+++ b/src/gui/guildwindow.cpp
@@ -0,0 +1,223 @@
+/*
+ * guildwindow.cpp
+ * A file part of The Mana World
+ *
+ * Created by David Athay on 06/03/2007.
+ *
+ * Copyright (c) 2007, David Athay
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * My name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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$
+ */
+
+#include "guildwindow.h"
+
+#include "button.h"
+#include "chat.h"
+#include "confirm_dialog.h"
+#include "gccontainer.h"
+#include "guildlistbox.h"
+#include "scrollarea.h"
+#include "tabbedcontainer.h"
+#include "textdialog.h"
+#include "windowcontainer.h"
+
+#include "../guild.h"
+#include "../log.h"
+#include "../localplayer.h"
+
+#include "../net/chatserver/guild.h"
+#include "../utils/dtor.h"
+
+GuildWindow::GuildWindow(LocalPlayer *player):
+ Window(player->getName()),
+ mPlayer(player),
+ mFocus(false)
+{
+ setCaption("Guild");
+ setResizable(true);
+ setCloseButton(true);
+ setMinWidth(200);
+ setMinHeight(280);
+ 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[1]->setEnabled(false);
+
+ mGuildsContainer = new TabbedContainer();
+
+ mGuildsContainer->setOpaque(false);
+
+ add(mGuildButton[0]);
+ add(mGuildButton[1]);
+ add(mGuildsContainer);
+
+ loadWindowState(player->getName());
+}
+
+GuildWindow::~GuildWindow()
+{
+ for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs));
+}
+
+void GuildWindow::update()
+{
+
+}
+
+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 - Process Invite User button clicked
+ 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 == "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::ChatServer::Guild::createGuild(name);
+
+ // Defocus dialog
+ mFocus = false;
+ chatWindow->chatLog("Creating Guild called " + name, 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::ChatServer::Guild::invitePlayer(name, selectedGuild);
+
+ // Defocus dialog
+ mFocus = false;
+ chatWindow->chatLog("Invited user " + name, BY_SERVER);
+ inviteDialog->scheduleDelete();
+ }
+ else if (eventId == "yes")
+ {
+ logger->log("Sending invitation acceptance.");
+ Net::ChatServer::Guild::acceptInvite(invitedGuild);
+ }
+}
+
+void GuildWindow::newGuildTab(const std::string &guildName)
+{
+
+ // Create new tab
+ GCContainer *tab = new GCContainer();
+ tab->setWidth(getWidth() - 2 * tab->getBorderSize());
+ tab->setHeight(getHeight() - 2 * tab->getBorderSize());
+ tab->setOpaque(false);
+ ListBox *list = new ListBox();
+ list->setListModel(player_node->findGuildByName(guildName));
+ ScrollArea *sa = new ScrollArea(list);
+ sa->setDimension(gcn::Rectangle(5, 5, 135, 250));
+ tab->add(sa);
+
+ mGuildsContainer->addTab(tab, guildName);
+ mGuildsContainer->setDimension(gcn::Rectangle(28,35,280,250));
+
+ mTabs.push_back(tab);
+
+ updateTab();
+}
+
+void GuildWindow::updateTab()
+{
+ setTab(mGuildsContainer->getActiveWidget());
+}
+
+void GuildWindow::setTab(const std::string &guildName)
+{
+
+ // Only enable invite button if user has rights
+ if(mPlayer->checkInviteRights(guildName))
+ {
+ mGuildButton[1]->setEnabled(true);
+ }
+ else
+ {
+ mGuildButton[1]->setEnabled(false);
+ }
+}
+
+bool GuildWindow::isFocused()
+{
+ return mFocus;
+}
+
+short GuildWindow::getSelectedGuild()
+{
+ return mPlayer->findGuildByName(mGuildsContainer->getActiveWidget())->getId();
+}
+
+void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName)
+{
+ std::string msg = inviterName + " has invited you to join the guild " + guildName;
+ chatWindow->chatLog(msg, BY_SERVER);
+
+ acceptDialog = new ConfirmDialog("Accept Guild Invite", msg, this);
+ acceptDialog->addActionListener(this);
+
+ invitedGuild = guildName;
+}
+
+void GuildWindow::requestMemberList(short guildId)
+{
+ // Get the list of members for displaying in the guild window.
+ Net::ChatServer::Guild::getGuildMembers(guildId);
+}
diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h
new file mode 100644
index 00000000..2f494a9a
--- /dev/null
+++ b/src/gui/guildwindow.h
@@ -0,0 +1,133 @@
+/*
+ * guildwindow.h
+ * 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.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * My name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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$
+ */
+
+#ifndef _TMW_GUI_GUILDWINDOW_H
+#define _TMW_GUI_GUILDWINDOW_H
+
+#include <iosfwd>
+#include <vector>
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/widgets/listbox.hpp>
+
+#include "window.h"
+
+#include "../guichanfwd.h"
+
+class LocalPlayer;
+class TextDialog;
+class ConfirmDialog;
+class GuildListBox;
+class TabbedContainer;
+class ScrollArea;
+class GCContainer;
+
+class GuildWindow : public Window, public gcn::ActionListener
+{
+public:
+ /**
+ * Constructor.
+ */
+ GuildWindow(LocalPlayer *player);
+
+ /**
+ * Destructor.
+ */
+ ~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 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);
+
+protected:
+ /**
+ * Get selected guild tab
+ * @return Returns selected guild
+ */
+ short getSelectedGuild();
+
+private:
+ LocalPlayer *mPlayer;
+ gcn::Button *mGuildButton[2];
+ TextDialog *guildDialog;
+ TextDialog *inviteDialog;
+ ConfirmDialog *acceptDialog;
+ TabbedContainer *mGuildsContainer;
+ GuildListBox *mGuildMembersList;
+ ScrollArea *mScrollArea;
+ std::vector<GCContainer*> mTabs;
+ bool mFocus;
+ std::string invitedGuild;
+};
+
+extern GuildWindow *guildWindow;
+
+#endif
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 94e8b38c..61c7e078 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -35,6 +35,12 @@ ListBox::ListBox(gcn::ListModel *listModel):
{
}
+ListBox::ListBox():
+ gcn::ListBox()
+{
+
+}
+
void ListBox::draw(gcn::Graphics *graphics)
{
if (!mListModel)
diff --git a/src/gui/listbox.h b/src/gui/listbox.h
index 1d480eb1..21172a22 100644
--- a/src/gui/listbox.h
+++ b/src/gui/listbox.h
@@ -42,6 +42,7 @@ class ListBox : public gcn::ListBox
* Constructor.
*/
ListBox(gcn::ListModel *listModel);
+ ListBox();
/**
* Draws the list box.
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 560ec40a..84340fc4 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -37,6 +37,7 @@ extern Window *inventoryWindow;
extern Window *equipmentWindow;
extern Window *skillDialog;
extern Window *statusWindow;
+extern Window *guildWindow;
extern Window *itemShortcutWindow;
namespace {
@@ -63,6 +64,7 @@ MenuWindow::MenuWindow():
N_("Equipment"),
N_("Inventory"),
N_("Skills"),
+ N_("Guilds"),
N_("Shortcut"),
N_("Setup"),
0
@@ -108,6 +110,10 @@ void MenuWindowListener::action(const gcn::ActionEvent &event)
{
window = skillDialog;
}
+ else if (event.getId() == "Guilds")
+ {
+ window = guildWindow;
+ }
else if (event.getId() == "Shortcut")
{
window = itemShortcutWindow;
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 821e9da6..b69cb9f1 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -42,6 +42,7 @@ extern Window *inventoryWindow;
extern Window *equipmentWindow;
extern Window *helpWindow;
extern Window *skillDialog;
+extern Window *guildWindow;
Setup::Setup():
Window(_("Setup"))
@@ -115,5 +116,6 @@ void Setup::action(const gcn::ActionEvent &event)
equipmentWindow->resetToDefaultSize();
helpWindow->resetToDefaultSize();
skillDialog->resetToDefaultSize();
+ guildWindow->resetToDefaultSize();
}
}
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
new file mode 100644
index 00000000..202838f0
--- /dev/null
+++ b/src/gui/textdialog.cpp
@@ -0,0 +1,93 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "textdialog.h"
+
+#include <guichan/widgets/label.hpp>
+#include <guichan/widgets/textfield.hpp>
+
+#include "button.h"
+
+TextDialog::TextDialog(const std::string &title, const std::string &msg,
+ Window *parent):
+ Window(title, true, parent),
+ textField(new gcn::TextField(""))
+{
+ gcn::Label *textLabel = new gcn::Label(msg);
+ okButton = new Button("OK", "OK", this);
+ gcn::Button *cancelButton = new Button("Cancel", "CANCEL", this);
+
+ int w = textLabel->getWidth() + 20;
+ int inWidth = okButton->getWidth() + cancelButton->getWidth() + 5;
+ int h = textLabel->getHeight() + 25 + okButton->getHeight() + textField->getHeight();
+
+ if (w < inWidth + 10) {
+ w = inWidth + 10;
+ }
+
+ setContentSize(w, h);
+ textLabel->setPosition(10, 10);
+ textField->setWidth(85);
+ textField->setPosition(10,20 + textLabel->getHeight());
+ okButton->setPosition((w - inWidth) / 2,
+ h - 5 - cancelButton->getHeight());
+ cancelButton->setPosition(okButton->getX() + okButton->getWidth() + 5,
+ h - 5 - cancelButton->getHeight());
+
+ add(textLabel);
+ add(textField);
+ add(okButton);
+ add(cancelButton);
+
+ if (getParent()) {
+ setLocationRelativeTo(getParent());
+ getParent()->moveToTop(this);
+ }
+ setVisible(true);
+ textField->requestFocus();
+}
+
+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);
+ }
+
+ if(event.getId() == "CANCEL" || event.getId() == "OK")
+ {
+ scheduleDelete();
+ }
+}
+
+const std::string& TextDialog::getText() const
+{
+ return textField->getText();
+}
+
+void TextDialog::setOKButtonActionId(const std::string &name)
+{
+ okButton->setActionEventId(name);
+}
diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h
new file mode 100644
index 00000000..f8ec0172
--- /dev/null
+++ b/src/gui/textdialog.h
@@ -0,0 +1,67 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_GUI_GUILD_DIALOG_H
+#define _TMW_GUI_GUILD_DIALOG_H
+
+#include <guichan/actionlistener.hpp>
+
+#include "window.h"
+
+
+/**
+* An option dialog.
+ *
+ * \ingroup GUI
+ */
+class TextDialog : public Window, public gcn::ActionListener {
+public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ TextDialog(const std::string &title, const std::string &msg,
+ Window *parent = NULL);
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Get the text in the textfield
+ */
+ const std::string& getText() const;
+
+ /**
+ * Set the OK button action id
+ */
+ void setOKButtonActionId(const std::string &name);
+
+private:
+ gcn::TextField *textField;
+ gcn::Button *okButton;
+};
+
+#endif
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
index 7a4ee9ac..6dbc6634 100644
--- a/src/gui/truetypefont.h
+++ b/src/gui/truetypefont.h
@@ -28,7 +28,11 @@
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
+#ifdef __APPLE__
+#include <SDL_ttf/SDL_ttf.h>
+#else
#include <SDL/SDL_ttf.h>
+#endif
/**
* A wrapper around SDL_ttf for allowing the use of TrueType fonts.