diff options
author | Lloyd Bryant <lloyd_bryant@netzero.net> | 2008-07-18 00:48:14 +0000 |
---|---|---|
committer | Lloyd Bryant <lloyd_bryant@netzero.net> | 2008-07-18 00:48:14 +0000 |
commit | 159285c5aa24611ceee7e3847a87bf9ea5f7fb7a (patch) | |
tree | fa48eb8bb8ed1e62ede1e7a2f95632c2243facab /src/gui | |
parent | 4dbc9b7af344d3ff006a40e3e0c06ce160f365f9 (diff) | |
download | mana-client-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.gz mana-client-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.bz2 mana-client-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.xz mana-client-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.zip |
Import of client tree
Diffstat (limited to 'src/gui')
128 files changed, 1654 insertions, 767 deletions
diff --git a/src/gui/box.cpp b/src/gui/box.cpp index 6af3ae3e..f53bc18e 100644 --- a/src/gui/box.cpp +++ b/src/gui/box.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: box.cpp 1456 2005-07-15 23:17:00Z b_lindeijer $ */ #include "box.h" diff --git a/src/gui/box.h b/src/gui/box.h index ed1a7163..280fd3e2 100644 --- a/src/gui/box.h +++ b/src/gui/box.h @@ -18,7 +18,7 @@ * 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$ + * $Id: box.h 2529 2006-08-13 10:20:19Z b_lindeijer $ */ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index bc76335f..4f771a7e 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: browserbox.cpp 4348 2008-06-14 12:42:49Z the_enemy $ */ #include <algorithm> diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 9c0e8ef1..636fe5a0 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: browserbox.h 3687 2007-10-26 00:22:12Z crush_tmw $ */ #ifndef __TMW_BROWSERBOX_H__ diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp deleted file mode 100644 index 0ed383ce..00000000 --- a/src/gui/buddywindow.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 "buddywindow.h" - -#include <guichan/widgets/listbox.hpp> - -#include "button.h" -#include "chat.h" -#include "scrollarea.h" - -#include "../resources/buddylist.h" - -extern ChatWindow *chatWindow; - -BuddyWindow::BuddyWindow(): - Window("Buddy") -{ - setContentSize(124, 202); - - mBuddyList = new BuddyList(); - - mListbox = new gcn::ListBox(); - mListbox->setListModel(mBuddyList); - - ScrollArea *scrollArea = new ScrollArea(mListbox); - scrollArea->setDimension(gcn::Rectangle( - 7, 5, 110, 170)); - add(scrollArea); - - Button *talk = new Button("Talk", "Talk", this); - Button *remove = new Button("Remove", "Remove", this); - Button *cancel = new Button("Cancel", "Cancel", this); - - talk->setPosition(2,180); - remove->setPosition(talk->getWidth()+2,180); - cancel->setPosition(talk->getWidth()+remove->getWidth()+2,180); - - add(talk); - add(remove); - add(cancel); -} - -void BuddyWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "Talk") { - int selected = mListbox->getSelected(); - if ( selected > -1 ) - { - std::string who = mBuddyList->getElementAt(selected); - chatWindow->setInputText(who +": "); - } - } - else if (event.getId() == "Remove") { - int selected = mListbox->getSelected(); - if ( selected > -1 ) - { - std::string who = mBuddyList->getElementAt(selected); - mBuddyList->removeBuddy(who); - } - } - else if (event.getId() == "Cancel") { - setVisible(false); - } -} diff --git a/src/gui/button.cpp b/src/gui/button.cpp index c6bc4ccb..1243d798 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: button.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/button.h b/src/gui/button.h index d12173b2..8e045a74 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -18,7 +18,7 @@ * 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$ + * $Id: button.h 3606 2007-09-27 14:54:09Z b_lindeijer $ */ #ifndef _TMW_BUTTON_H diff --git a/src/gui/buddywindow.h b/src/gui/buttonbox.cpp index a3ca4de2..592cb92a 100644 --- a/src/gui/buddywindow.h +++ b/src/gui/buttonbox.cpp @@ -18,41 +18,30 @@ * 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$ + * $Id: buttonbox.cpp */ -#ifndef _TMW_BUDDYWINDOW_H -#define _TMW_BUDDYWINDOW_H +#include "buttonbox.h" -#include <guichan/actionlistener.hpp> +#include "button.h" -#include "window.h" - -#include "../guichanfwd.h" - -class BuddyList; - -/** - * Window showing buddy list. - * - * \ingroup Interface - */ -class BuddyWindow : public Window, public gcn::ActionListener +ButtonBox::ButtonBox(const std::string &title, const std::string &buttonTxt, + ButtonBoxListener *listener) : + Window(title), + mListener(listener) { - public: - /** - * Constructor. - */ - BuddyWindow(); - - /** - * Performs action. - */ - void action(const gcn::ActionEvent &event); - - private: - BuddyList *mBuddyList; - gcn::ListBox *mListbox; -}; - -#endif /* _TMW_BUDDYWINDOW_H */ + Button *button = new Button(buttonTxt, "activate", this); + setContentSize(button->getWidth() + 10, + button->getHeight() + 10); + button->setPosition(5, 5); + add(button); +} + +void +ButtonBox::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "activate") + { + mListener->buttonBoxRespond(); + } +} diff --git a/src/gui/buttonbox.h b/src/gui/buttonbox.h new file mode 100644 index 00000000..1b76e619 --- /dev/null +++ b/src/gui/buttonbox.h @@ -0,0 +1,70 @@ +/* + * 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: buttonbox.h + */ + +#ifndef _TMW_BUTTONBOX_H +#define _TMW_BUTTONBOX_H + +#include <string> + +#include <guichan/actionlistener.hpp> + +#include "window.h" + +class ButtonBoxListener +{ + public: + + /* + * function that ButtonBox calls when the button has been pressed + */ + virtual void buttonBoxRespond() = 0; +}; + +class ButtonBox : public Window, public gcn::ActionListener +{ + public: + + /* + * Constructor + * + * @param title is the text that appears at the top of the box + * @param buttonTxt is the text that appears on the button + * @param listener points to the class that should respond to the + * button press + */ + ButtonBox(const std::string &title, const std::string &buttonTxt, + ButtonBoxListener *listener); + + /* + * called when the button is pressed + * + * @param event is the event that is generated + */ + void + action(const gcn::ActionEvent &event); + + private: + + ButtonBoxListener *mListener; +}; +#endif diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 259fcfd9..24acf2d1 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: buy.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "buy.h" diff --git a/src/gui/buy.h b/src/gui/buy.h index 3a9ea3c5..6f75cab5 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -18,7 +18,7 @@ * 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$ + * $Id: buy.h 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #ifndef _TMW_BUY_H diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index ae5c7358..9cc3b297 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: buysell.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "buysell.h" diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 97caf34b..64c37e39 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -18,7 +18,7 @@ * 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$ + * $Id: buysell.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_BUYSELL_H diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 8ab3b879..c4b1d89e 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: char_select.cpp 3760 2007-11-21 19:43:11Z b_lindeijer $ */ #include "char_select.h" diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 283ecf42..182600d1 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -18,7 +18,7 @@ * 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$ + * $Id: char_select.h 3752 2007-11-20 10:50:00Z b_lindeijer $ */ #ifndef _CHAR_SELECT_H diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 638c05a6..3465fb69 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: char_server.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "char_server.h" @@ -105,10 +105,11 @@ ServerSelectDialog::action(const gcn::ActionEvent &event) const SERVER_INFO *si = server_info[mServerList->getSelected()]; mLoginData->hostname = iptostring(si->address); mLoginData->port = si->port; - state = CHAR_CONNECT_STATE; + mLoginData->updateHost = si->updateHost; + state = UPDATE_STATE; } else if (event.getId() == "cancel") { - state = LOADDATA_STATE; + state = LOGIN_STATE; } } diff --git a/src/gui/char_server.h b/src/gui/char_server.h index 26e723f9..32a0645f 100644 --- a/src/gui/char_server.h +++ b/src/gui/char_server.h @@ -18,7 +18,7 @@ * 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$ + * $Id: char_server.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _CHAR_SEL_SERVER_H diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5e3aaf60..7b69ec1c 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -18,12 +18,11 @@ * 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$ + * $Id: chat.cpp 4227 2008-05-08 00:39:29Z peaveydk $ */ #include <algorithm> -#include <sstream> - +#include <fstream> #include <guichan/focushandler.hpp> #include <guichan/key.hpp> @@ -37,6 +36,9 @@ #include "../configuration.h" #include "../game.h" #include "../localplayer.h" +#include "../beingmanager.h" +#include "../recorder.h" +#include "../party.h" #include "../net/messageout.h" #include "../net/protocol.h" @@ -64,9 +66,9 @@ ChatWindow::ChatWindow(Network *network): mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0)); mScrollArea = new ScrollArea(mTextOutput); mScrollArea->setPosition( - mScrollArea->getFrameSize(), mScrollArea->getFrameSize()); + mScrollArea->getFrameSize(), mScrollArea->getFrameSize()); mScrollArea->setScrollPolicy( - gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); + gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); mScrollArea->setOpaque(false); add(mScrollArea); @@ -75,6 +77,22 @@ ChatWindow::ChatWindow(Network *network): // Add key listener to chat input to be able to respond to up/down mChatInput->addKeyListener(this); mCurHist = mHistory.end(); + + // Read the party prefix + std::string partyPrefix = config.getValue("PartyPrefix", "$"); + mPartyPrefix = (partyPrefix == "" ? '$' : partyPrefix.at(0)); + mReturnToggles = config.getValue("ReturnToggles", "0") == "1"; + mRecorder = new Recorder(this); + mParty = new Party(this, mNetwork); +} + +ChatWindow::~ChatWindow() +{ + char partyPrefix[2] = "."; + *partyPrefix = mPartyPrefix; + config.setValue("PartyPrefix", partyPrefix); + config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); + delete mRecorder; } void @@ -85,17 +103,17 @@ ChatWindow::logic() const gcn::Rectangle area = getChildrenArea(); mChatInput->setPosition(mChatInput->getFrameSize(), - area.height - mChatInput->getHeight() - - mChatInput->getFrameSize()); + area.height - mChatInput->getHeight() - + mChatInput->getFrameSize()); mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize()); mScrollArea->setWidth(area.width - 2 * mScrollArea->getFrameSize()); mScrollArea->setHeight(area.height - 2 * mScrollArea->getFrameSize() - - mChatInput->getHeight() - 5); + mChatInput->getHeight() - 5); mScrollArea->logic(); } void -ChatWindow::chatLog(std::string line, int own) +ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) { // Trim whitespace trim(line); @@ -108,47 +126,51 @@ ChatWindow::chatLog(std::string line, int own) // Fix the owner of welcome message. if (line.substr(0, 7) == "Welcome") { - own = BY_SERVER; + own = BY_SERVER; } std::string::size_type pos = line.find(" : "); if (pos != std::string::npos) { - tmp.nick = line.substr(0, pos); - tmp.text = line.substr(pos + 3); + tmp.nick = line.substr(0, pos); + tmp.text = line.substr(pos + 3); } std::string lineColor = "##0"; // Equiv. to BrowserBox::BLACK switch (own) { - case BY_GM: - tmp.nick += std::string("Global announcement: "); - lineColor = "##1"; // Equiv. to BrowserBox::RED - break; - case BY_PLAYER: - tmp.nick += CAT_NORMAL; - lineColor = "##2"; // Equiv. to BrowserBox::GREEN - break; - case BY_OTHER: - tmp.nick += CAT_NORMAL; - lineColor = "##0"; // Equiv. to BrowserBox::BLACK - break; - case BY_SERVER: - tmp.nick = "Server: "; - tmp.text = line; - lineColor = "##7"; // Equiv. to BrowserBox::PINK - break; - case ACT_WHISPER: - tmp.nick += CAT_WHISPER; - lineColor = "##3"; // Equiv. to BrowserBox::BLUE - break; - case ACT_IS: - tmp.nick += CAT_IS; - lineColor = "##5"; // Equiv. to BrowserBox::YELLOW - break; - case BY_LOGGER: - tmp.nick = ""; - tmp.text = line; - lineColor = "##8"; // Equiv. to BrowserBox::GREY - break; + case BY_GM: + tmp.nick += std::string("Global announcement: "); + lineColor = "##1"; // Equiv. to BrowserBox::RED + break; + case BY_PLAYER: + tmp.nick += CAT_NORMAL; + lineColor = "##2"; // Equiv. to BrowserBox::GREEN + break; + case BY_OTHER: + tmp.nick += CAT_NORMAL; + lineColor = "##0"; // Equiv. to BrowserBox::BLACK + break; + case BY_SERVER: + tmp.nick = "Server: "; + tmp.text = line; + lineColor = "##7"; // Equiv. to BrowserBox::PURPLE + break; + case BY_PARTY: + tmp.nick += CAT_NORMAL; + lineColor = "##6"; // Equiv. to BrowserBox::PINK + break; + case ACT_WHISPER: + tmp.nick += CAT_WHISPER; + lineColor = "##3"; // Equiv. to BrowserBox::BLUE + break; + case ACT_IS: + tmp.nick += CAT_IS; + lineColor = "##5"; // Equiv. to BrowserBox::YELLOW + break; + case BY_LOGGER: + tmp.nick = ""; + tmp.text = line; + lineColor = "##8"; // Equiv. to BrowserBox::GRAY + break; } // Get the current system time @@ -158,12 +180,12 @@ ChatWindow::chatLog(std::string line, int own) // Format the time string properly std::stringstream timeStr; timeStr << "[" - << ((((t / 60) / 60) % 24 < 10) ? "0" : "") - << (int)(((t / 60) / 60) % 24) - << ":" - << (((t / 60) % 60 < 10) ? "0" : "") - << (int)((t / 60) % 60) - << "] "; + << ((((t / 60) / 60) % 24 < 10) ? "0" : "") + << (int)(((t / 60) / 60) % 24) + << ":" + << (((t / 60) % 60 < 10) ? "0" : "") + << (int)((t / 60) % 60) + << "] "; line = lineColor + timeStr.str() + tmp.nick + tmp.text; @@ -172,13 +194,15 @@ ChatWindow::chatLog(std::string line, int own) // at comparison. if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll()) { - mTextOutput->addRow(line); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); + mTextOutput->addRow(line); + mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); } else { - mTextOutput->addRow(line); + mTextOutput->addRow(line); } + + mRecorder->record(line.substr(3)); } void @@ -192,32 +216,35 @@ ChatWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "chatinput") { - std::string message = mChatInput->getText(); - - if (!message.empty()) { - // If message different from previous, put it in the history - if (mHistory.empty() || message != mHistory.back()) { - mHistory.push_back(message); - } - - // Reset history iterator - mCurHist = mHistory.end(); - - // Send the message to the server - chatSend(player_node->getName(), message); - - // Clear the text from the chat input - mChatInput->setText(""); - } - - // Remove focus and hide input - mFocusHandler->focusNone(); - - // If the chatWindow is shown up because you want to send a message - // It should hide now - if (mTmpVisible) { - setVisible(false); - } + std::string message = mChatInput->getText(); + + if (!message.empty()) { + // If message different from previous, put it in the history + if (mHistory.empty() || message != mHistory.back()) { + mHistory.push_back(message); + } + + // Reset history iterator + mCurHist = mHistory.end(); + + // Send the message to the server + chatSend(player_node->getName(), message); + + // Clear the text from the chat input + mChatInput->setText(""); + } + if (message.empty() || !mReturnToggles) + { + // Remove focus and hide input + mFocusHandler->focusNone(); + + // If the chatWindow is shown up because you want to send a message + // It should hide now + if (mTmpVisible) + { + setVisible(false); + } + } } } @@ -227,14 +254,14 @@ ChatWindow::requestChatFocus() // Make sure chatWindow is visible if (!isVisible()) { - setVisible(true); - - /* - * This is used to hide chatWindow after sending the message. There is - * a trick here, because setVisible will set mTmpVisible to false, you - * have to put this sentence *after* setVisible, not before it - */ - mTmpVisible = true; + setVisible(true); + + /* + * This is used to hide chatWindow after sending the message. There is + * a trick here, because setVisible will set mTmpVisible to false, you + * have to put this sentence *after* setVisible, not before it + */ + mTmpVisible = true; } // Give focus to the chat input @@ -255,81 +282,224 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) * require server handling by proper packet. Probably * those if elses should be replaced by protocol calls */ + // Send party message + if (msg.at(0) == 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); + return; + } + MessageOut outMsg(mNetwork); + + outMsg.writeInt16(CMSG_PARTY_MESSAGE); + outMsg.writeInt16(length + 4); + outMsg.writeString(msg, length); + return; + } // Prepare ordinary message if (msg.substr(0, 1) != "/") { - msg = nick + " : " + msg; + msg = nick + " : " + msg; + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CHAT_MESSAGE); + // Added + 1 in order to let eAthena parse admin commands correctly + outMsg.writeInt16(msg.length() + 4 + 1); + outMsg.writeString(msg, msg.length() + 1); + return; + } + msg.erase(0, 1); + trim(msg); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_CHAT_MESSAGE); - // Added + 1 in order to let eAthena parse admin commands correctly - outMsg.writeInt16(msg.length() + 4 + 1); - outMsg.writeString(msg, msg.length() + 1); + std::size_t space = msg.find(" "); + std::string command = msg.substr(0, space); + if (space == std::string::npos) + { + msg = ""; } - else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) + else { - msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0099); - outMsg.writeInt16(msg.length() + 4); - outMsg.writeString(msg, msg.length()); + msg = msg.substr(space); + trim(msg); } - else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) + + if (command == "announce") { - chatLog("-- Help --", BY_SERVER); - chatLog("/help: Display this help.", BY_SERVER); - chatLog("/announce: Global announcement (GM only)", BY_SERVER); - chatLog("/where: Display map name", BY_SERVER); - chatLog("/who: Display number of online users", BY_SERVER); - chatLog("/clear: Clears this window", BY_SERVER); - chatLog("/whisper <nick> <message>: Sends a private <message> to <nick>", BY_SERVER); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0099); + outMsg.writeInt16(msg.length() + 4); + outMsg.writeString(msg, msg.length()); + return; } - else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) + if (command == "help") { - chatLog(map_path, BY_SERVER); + std::size_t space = msg.find(" "); + std::string msg1; + if (space == std::string::npos) + { + msg1 = ""; + } + else + { + msg1 = msg.substr(space + 1, msg.length()); + msg = msg.substr(0, space); + } + if (msg != "" && msg.at(0) == '/') + { + msg.erase(0, 1); + } + while (msg1 != "" && msg1.at(0) == ' ') + { + msg1.erase(0, 1); + } + help(msg, msg1); + return; } - else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) + if (command == "where") { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00c1); + chatLog(map_path, BY_SERVER); + return; } - else if (msg.substr(0, IS_CLEAR_LENGTH) == IS_CLEAR) + if (command == "who") { - mTextOutput->clearRows(); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x00c1); + return; } - else if (msg.substr(0, IS_WHISPER_LENGTH) == IS_WHISPER) + if (command == "clear") { - std::string recvnick = ""; - msg.erase(0, IS_WHISPER_LENGTH + 1); - - if (msg.substr(0,1) == "\"") - { - const std::string::size_type pos = msg.find('"', 1); - if (pos != std::string::npos) { - recvnick = msg.substr(1, pos - 1); - msg.erase(0, pos + 2); - } - } - else - { - const std::string::size_type pos = msg.find(" "); - if (pos != std::string::npos) { - recvnick = msg.substr(0, pos); - msg.erase(0, pos + 1); - } - } - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_CHAT_WHISPER); - outMsg.writeInt16(msg.length() + 28); - outMsg.writeString(recvnick, 24); - outMsg.writeString(msg, msg.length()); - - chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER); + mTextOutput->clearRows(); + return; } - else + if (command == "whisper") + { + std::string recvnick = ""; + + if (msg.substr(0,1) == "\"") + { + const std::string::size_type pos = msg.find('"', 1); + if (pos != std::string::npos) { + recvnick = msg.substr(1, pos - 1); + msg.erase(0, pos + 2); + } + } + else + { + const std::string::size_type pos = msg.find(" "); + if (pos != std::string::npos) { + recvnick = msg.substr(0, pos); + msg.erase(0, pos + 1); + } + } + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CHAT_WHISPER); + outMsg.writeInt16(msg.length() + 28); + outMsg.writeString(recvnick, 24); + outMsg.writeString(msg, msg.length()); + + chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER); + return; + } + if (command == "record") { - chatLog("Unknown command", BY_SERVER); + mRecorder->respond(msg); + return; } + if (command == "toggle") + { + if (msg == "") + { + chatLog(mReturnToggles ? "Return toggles chat." + : "Message closes chat.", BY_SERVER); + return; + } + msg = msg.substr(0, 1); + if (msg == "1" || msg == "y" || msg == "t" || msg == "Y" || msg == "T") + { + chatLog("Return now toggles chat.", BY_SERVER); + mReturnToggles = true; + return; + } + if (msg == "0" || msg == "n" || msg == "f" || msg == "N" || msg == "F") + { + chatLog("Message now closes chat.", BY_SERVER); + mReturnToggles = false; + return; + } + chatLog("Options to /toggle are \"yes\", \"no\", \"true\", \"false\", " + "\"1\", \"0\".", BY_SERVER); + return; + } + if (command == "party") + { + if (msg == "") + { + chatLog("Unknown party command... Type \"/help\" party for more " + "information.", BY_SERVER); + return; + } + const std::string::size_type space = msg.find(" "); + std::string rest = (space == std::string::npos ? "" + : msg.substr(space + 1, msg.length())); + if (rest != "") + { + msg = msg.substr(0, space); + while (msg != "" && msg[0] == ' ') + { + msg = msg.substr(1, msg.length()); + } + } + party(msg, rest); + return; + } + if (command == "present") + { + Beings &beings = beingManager->getAll(); + std::string response = ""; + for (BeingIterator bi = beings.begin(), be = beings.end(); + bi != be; + ++bi) + { + if ((*bi)->getType() == Being::PLAYER) + { + if (response != "") + { + response += ", "; + } + response += (*bi)->getName(); + } + } + if (mRecorder->isRecording()) + { + // Get the current system time + time_t t; + time(&t); + + // Format the time string properly + std::stringstream timeStr; + timeStr << "[" + << ((((t / 60) / 60) % 24 < 10) ? "0" : "") + << (int)(((t / 60) / 60) % 24) + << ":" + << (((t / 60) % 60 < 10) ? "0" : "") + << (int)((t / 60) % 60) + << "] "; + + + mRecorder->record(timeStr.str() + "Present: " + response + "."); + chatLog("Attendance written to record log.", BY_SERVER, true); + } + else + { + chatLog("Present: " + response, BY_SERVER); + } + return; + } + chatLog("Unknown command", BY_SERVER); } std::string @@ -337,76 +507,75 @@ ChatWindow::const_msg(CHATSKILL act) { std::string msg; if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) { - switch (act.bskill) { - case BSKILL_TRADE : - msg = "Trade failed!"; - break; - case BSKILL_EMOTE : - msg = "Emote failed!"; - break; - case BSKILL_SIT : - msg = "Sit failed!"; - break; - case BSKILL_CREATECHAT : - msg = "Chat creating failed!"; - break; - case BSKILL_JOINPARTY : - msg = "Could not join party!"; - break; - case BSKILL_SHOUT : - msg = "Cannot shout!"; - break; - } - - switch (act.reason) { - case RFAIL_SKILLDEP : - msg += " You have not yet reached a high enough lvl!"; - break; - case RFAIL_INSUFHP : - msg += " Insufficient HP!"; - break; - case RFAIL_INSUFSP : - msg += " Insufficient SP!"; - break; - case RFAIL_NOMEMO : - msg += " You have no memos!"; - break; - case RFAIL_SKILLDELAY : - msg += " You cannot do that right now!"; - break; - case RFAIL_ZENY : - msg += " Seems you need more Zeny... ;-)"; - break; - case RFAIL_WEAPON : - msg += " You cannot use this skill with that kind of weapon!"; - break; - case RFAIL_REDGEM : - msg += " You need another red gem!"; - break; - case RFAIL_BLUEGEM : - msg += " You need another blue gem!"; - break; - case RFAIL_OVERWEIGHT : - msg += " You're carrying to much to do this!"; - break; - default : - msg += " Huh? What's that?"; - break; - } + switch (act.bskill) { + case BSKILL_TRADE : + msg = "Trade failed!"; + break; + case BSKILL_EMOTE : + msg = "Emote failed!"; + break; + case BSKILL_SIT : + msg = "Sit failed!"; + break; + case BSKILL_CREATECHAT : + msg = "Chat creating failed!"; + break; + case BSKILL_JOINPARTY : + msg = "Could not join party!"; + break; + case BSKILL_SHOUT : + msg = "Cannot shout!"; + break; + } + + switch (act.reason) { + case RFAIL_SKILLDEP : + msg += " You have not yet reached a high enough level!"; + break; + case RFAIL_INSUFHP : + msg += " Insufficient HP!"; + break; + case RFAIL_INSUFSP : + msg += " Insufficient SP!"; + break; + case RFAIL_NOMEMO : + msg += " You have no memos!"; + break; + case RFAIL_SKILLDELAY : + msg += " You cannot do that right now!"; + break; + case RFAIL_ZENY : + msg += " Seems you need more Zeny... ;-)"; + break; + case RFAIL_WEAPON : + msg += " You cannot use this skill with that kind of weapon!"; + break; + case RFAIL_REDGEM : + msg += " You need another red gem!"; + break; + case RFAIL_BLUEGEM : + msg += " You need another blue gem!"; + break; + case RFAIL_OVERWEIGHT : + msg += " You're carrying to much to do this!"; + break; + default : + msg += " Huh? What's that?"; + break; + } } else { - switch(act.skill) { - case SKILL_WARP : - msg = "Warp failed..."; - break; - case SKILL_STEAL : - msg = "Could not steal anything..."; - break; - case SKILL_ENVENOM : - msg = "Poison had no effect..."; - break; - } + switch(act.skill) { + case SKILL_WARP : + msg = "Warp failed..."; + break; + case SKILL_STEAL : + msg = "Could not steal anything..."; + break; + case SKILL_ENVENOM : + msg = "Poison had no effect..."; + break; + } } - return msg; } @@ -414,7 +583,7 @@ void ChatWindow::scroll(int amount) { if (!isVisible()) - return; + return; int range = mScrollArea->getHeight() / 8 * amount; gcn::Rectangle scr; @@ -427,25 +596,25 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) { if (event.getKey().getValue() == gcn::Key::DOWN && - mCurHist != mHistory.end()) - { - // Move forward through the history - HistoryIterator prevHist = mCurHist++; - if (mCurHist != mHistory.end()) { - mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(mChatInput->getText().length()); - } - else { - mCurHist = prevHist; - } + mCurHist != mHistory.end()) + { + // Move forward through the history + HistoryIterator prevHist = mCurHist++; + if (mCurHist != mHistory.end()) { + mChatInput->setText(*mCurHist); + mChatInput->setCaretPosition(mChatInput->getText().length()); + } + else { + mCurHist = prevHist; + } } else if (event.getKey().getValue() == gcn::Key::UP && - mCurHist != mHistory.begin() && mHistory.size() > 0) + mCurHist != mHistory.begin() && mHistory.size() > 0) { - // Move backward through the history - mCurHist--; - mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(mChatInput->getText().length()); + // Move backward through the history + mCurHist--; + mChatInput->setText(*mCurHist); + mChatInput->setCaretPosition(mChatInput->getText().length()); } } @@ -469,3 +638,138 @@ ChatWindow::setVisible(bool isVisible) mTmpVisible = false; } +void +ChatWindow::party(const std::string &command, const std::string &rest) +{ + if (command == "prefix") + { + if (rest == "") + { + char temp[2] = "."; + *temp = mPartyPrefix; + chatLog("The current party prefix is " + std::string(temp), + BY_SERVER); + return; + } + if (rest.length() != 1) + { + chatLog("Party prefix must be one character long.", BY_SERVER); + } + else + { + if (rest == "/") + { + chatLog("Cannot use a '/' as the prefix.", BY_SERVER); + } + else + { + mPartyPrefix = rest.at(0); + chatLog("Changing prefix to " + rest, BY_SERVER); + } + } + return; + } + mParty->respond(command, rest); +} + +void +ChatWindow::help(const std::string &msg1, const std::string &msg2) +{ + chatLog("-- Help --", BY_SERVER); + if (msg1 == "") + { + chatLog("/announce: Global announcement (GM only)", BY_SERVER); + chatLog("/clear: Clears this window", BY_SERVER); + chatLog("/help: Display this help.", BY_SERVER); + mParty->help(); + chatLog("/present: Get list of players present", BY_SERVER); + mRecorder->help(); + chatLog("/toggle: Determine whether <return> toggles the chat log.", + BY_SERVER); + chatLog("/where: Display map name", BY_SERVER); + chatLog("/whisper <nick> <message>: Sends a private <message>" + " to <nick>", BY_SERVER); + chatLog("/who: Display number of online users", BY_SERVER); + chatLog("For more information, type /help <command>", BY_SERVER); + return; + } + if (msg1 == "announce") + { + chatLog("Command: /announce <msg>", BY_SERVER); + chatLog("*** only available to a GM ***", BY_SERVER); + chatLog("This command sends the message <msg> to " + "all players currently online.", BY_SERVER); + return; + } + if (msg1 == "clear") + { + chatLog("Command: /clear", BY_SERVER); + chatLog("This command clears the chat log of previous chat.", + BY_SERVER); + return; + } + if (msg1 == "help") + { + chatLog("Command: /help", BY_SERVER); + chatLog("This command displays a list of all commands available.", + BY_SERVER); + chatLog("Command: /help <command>", BY_SERVER); + chatLog("This command displays help on <command>.", BY_SERVER); + return; + } + if (msg1 == "party") + { + mParty->help(msg2); + return; + } + if (msg1 == "present") + { + chatLog("Command: /present", BY_SERVER); + chatLog("This command gets a list of players within hearing " + "and sends it to either the record log if recording, or the " + "chat log otherwise.", BY_SERVER); + return; + } + if (msg1 == "record") + { + mRecorder->help(msg2); + return; + } + if (msg1 == "toggle") + { + chatLog("Command: /toggle <state>", BY_SERVER); + chatLog("This command sets whether the return key should toggle the " + "chat log, or whether the chat log turns off automatically.", + BY_SERVER); + chatLog("<state> can be one of \"1\", \"yes\", \"true\" to turn " + "the toggle on, or \"0\", \"no\", \"false\" to turn the " + "toggle off.", BY_SERVER); + chatLog("Command: /toggle", BY_SERVER); + chatLog("This command displays the return toggle status.", BY_SERVER); + return; + } + if (msg1 == "where") + { + chatLog("Command: /where", BY_SERVER); + chatLog("This command displays the name of the current map.", + BY_SERVER); + return; + } + if (msg1 == "whisper") + { + chatLog("Command: /whisper <nick> <msg>", BY_SERVER); + chatLog("This command sends the message <msg> to <nick.", BY_SERVER); + chatLog("If the <nick> has spaces in it, enclose it in " + "double quotes (\").", BY_SERVER); + return; + } + if (msg1 == "who") + { + chatLog("Command: /who", BY_SERVER); + chatLog("This command displays the number of players currently " + "online.", BY_SERVER); + return; + } + chatLog("Unknown command.", BY_SERVER); + chatLog("Type /help for a list of commands.", BY_SERVER); +} diff --git a/src/gui/chat.h b/src/gui/chat.h index 0bdc76f1..5e5ca110 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -18,7 +18,7 @@ * 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$ + * $Id: chat.h 4227 2008-05-08 00:39:29Z peaveydk $ */ #ifndef _TMW_CHAT_H @@ -26,6 +26,7 @@ #include <list> #include <string> +#include <fstream> #include <guichan/actionlistener.hpp> #include <guichan/keylistener.hpp> @@ -37,29 +38,19 @@ class BrowserBox; class Network; class ScrollArea; +class Recorder; +class Party; #define BY_GM 0 // those should be self-explanatory =) #define BY_PLAYER 1 #define BY_OTHER 2 #define BY_SERVER 3 +#define BY_PARTY 4 -#define ACT_WHISPER 4 // getting whispered at -#define ACT_IS 5 // equivalent to "/me" on IRC +#define ACT_WHISPER 5 // getting whispered at +#define ACT_IS 6 // equivalent to "/me" on IRC -#define BY_LOGGER 6 - -#define IS_ANNOUNCE "/announce " -#define IS_ANNOUNCE_LENGTH 10 -#define IS_HELP "/help" -#define IS_HELP_LENGTH 5 -#define IS_WHERE "/where" -#define IS_WHERE_LENGTH 6 -#define IS_WHO "/who" -#define IS_WHO_LENGTH 4 -#define IS_CLEAR "/clear" -#define IS_CLEAR_LENGTH 6 -#define IS_WHISPER "/whisper" -#define IS_WHISPER_LENGTH 8 +#define BY_LOGGER 7 /** * gets in between usernick and message text depending on @@ -118,121 +109,150 @@ struct CHATSKILL * \ingroup Interface */ class ChatWindow : public Window, public gcn::ActionListener, - public gcn::KeyListener + public gcn::KeyListener { public: - /** - * Constructor. - */ - ChatWindow(Network *network); - - /** - * Logic (updates components' size) - */ - void logic(); - - /* - * Adds a line of text to our message list. Parameters: - * - * @param line Text message. - * @parem own Type of message (usually the owner-type). - */ - void chatLog(std::string line, int own); - - /* - * Calls original chat_log() after processing the packet. - */ - void chatLog(CHATSKILL); - - /** - * Performs action. - */ - void action(const gcn::ActionEvent &event); - - /** - * Request focus for typing chat message. - */ - void requestChatFocus(); - - /** - * Checks whether ChatWindow is Focused or not. - */ - bool isInputFocused(); - - /** - * Determines whether to send a command or an ordinary message, then - * contructs packets & sends them. - * - * @param nick The character's name to display in front. - * @param msg The message text which is to be send. - * - * NOTE: - * The nickname is required by the server, if not specified - * the message may not be sent unless a command was intended - * which requires another packet to be constructed! you can - * achieve this by putting a slash ("/") infront of the - * message followed by the command name and the message. - * of course all slash-commands need implemented handler- - * routines. ;-) - * remember, a line starting with "@" is not a command that needs - * to be parsed rather is sent using the normal chat-packet. - * - * EXAMPLE: - * // for an global announcement /- command - * chatlog.chat_send("", "/announce Hello to all logged in users!"); - * // for simple message by a user /- message - * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); - */ - void - chatSend(const std::string &nick, std::string msg); - - /** Called when key is pressed */ - void - keyPressed(gcn::KeyEvent &event); - - /** Called to set current text */ - void - setInputText(std::string input_str); - - /** Override to reset mTmpVisible */ - void - setVisible(bool visible); + /** + * Constructor. + */ + ChatWindow(Network *network); + + /** + * Destructor: used to write back values to the config file + */ + ~ChatWindow(); + + /** + * Logic (updates components' size) + */ + void logic(); + + /** + * Adds a line of text to our message list. Parameters: + * + * @param line Text message. + * @parem own Type of message (usually the owner-type). + */ + void chatLog(std::string line, int own, bool ignoreRecord = false); + + /** + * Calls original chat_log() after processing the packet. + */ + void chatLog(CHATSKILL); + + /** + * Performs action. + */ + void action(const gcn::ActionEvent &event); + + /** + * Request focus for typing chat message. + */ + void requestChatFocus(); + + /** + * Checks whether ChatWindow is Focused or not. + */ + bool isInputFocused(); + + /** + * Determines whether to send a command or an ordinary message, then + * contructs packets & sends them. + * + * @param nick The character's name to display in front. + * @param msg The message text which is to be send. + * + * NOTE: + * The nickname is required by the server, if not specified + * the message may not be sent unless a command was intended + * which requires another packet to be constructed! you can + * achieve this by putting a slash ("/") infront of the + * message followed by the command name and the message. + * of course all slash-commands need implemented handler- + * routines. ;-) + * remember, a line starting with "@" is not a command that needs + * to be parsed rather is sent using the normal chat-packet. + * + * EXAMPLE: + * // for an global announcement /- command + * chatlog.chat_send("", "/announce Hello to all logged in users!"); + * // for simple message by a user /- message + * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); + */ + void + chatSend(const std::string &nick, std::string msg); + + /** Called when key is pressed */ + void + keyPressed(gcn::KeyEvent &event); + + /** Called to set current text */ + void + setInputText(std::string input_str); + + /** Override to reset mTmpVisible */ + void + setVisible(bool visible); /** - * Scrolls the chat window - * - * @param amount direction and amount to scroll. Negative numbers scroll - * up, positive numbers scroll down. The absolute amount indicates the - * amount of 1/8ths of chat window real estate that should be scrolled. - */ - void - scroll(int amount); + * Scrolls the chat window + * + * @param amount direction and amount to scroll. Negative numbers scroll + * up, positive numbers scroll down. The absolute amount indicates the + * amount of 1/8ths of chat window real estate that should be scrolled. + */ + void + scroll(int amount); + + /** + * party implements the partying chat commands + * + * @param command is the party command to perform + * @param msg is the remainder of the message + */ + void + party(const std::string &command, const std::string &msg); + + /** + * help implements the /help command + * + * @param msg1 is the command that the player needs help on + * @param msg2 is the sub-command relating to the command + */ + void + help(const std::string &msg1, const std::string &msg2); private: - Network *mNetwork; - bool mTmpVisible; - - /** One item in the chat log */ - struct CHATLOG - { - std::string nick; - std::string text; - int own; - }; - - /** Constructs failed messages for actions */ - std::string const_msg(CHATSKILL); - - gcn::TextField *mChatInput; /**< Input box for typing chat messages */ - BrowserBox *mTextOutput; /**< Text box for displaying chat history */ - ScrollArea *mScrollArea; /**< Scroll area around text output */ - - typedef std::list<std::string> History; - typedef History::iterator HistoryIterator; - History mHistory; /**< Command history */ - HistoryIterator mCurHist; /**< History iterator */ -}; + Network *mNetwork; + bool mTmpVisible; + + /** One item in the chat log */ + struct CHATLOG + { + std::string nick; + std::string text; + int own; + }; + + /** Constructs failed messages for actions */ + std::string const_msg(CHATSKILL); + + gcn::TextField *mChatInput; /**< Input box for typing chat messages */ + BrowserBox *mTextOutput; /**< Text box for displaying chat history */ + ScrollArea *mScrollArea; /**< Scroll area around text output */ + + typedef std::list<std::string> History; + typedef History::iterator HistoryIterator; + History mHistory; /**< Command history */ + HistoryIterator mCurHist; /**< History iterator */ + Recorder *mRecorder; /**< Recording class */ + char mPartyPrefix; /**< Messages beginning with the prefix are sent to + the party */ + bool mReturnToggles; /**< Marks whether <Return> toggles the chat log + or not */ + Party *mParty; +}; extern ChatWindow *chatWindow; #endif diff --git a/src/gui/chatinput.cpp b/src/gui/chatinput.cpp index fc5d6aab..b403a03e 100644 --- a/src/gui/chatinput.cpp +++ b/src/gui/chatinput.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: chatinput.cpp 3361 2007-07-07 20:12:58Z b_lindeijer $ */ #include "chatinput.h" diff --git a/src/gui/chatinput.h b/src/gui/chatinput.h index da2342ae..6ac8c1a5 100644 --- a/src/gui/chatinput.h +++ b/src/gui/chatinput.h @@ -18,7 +18,7 @@ * 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$ + * $Id: chatinput.h 3361 2007-07-07 20:12:58Z b_lindeijer $ */ #ifndef _TMW_CHATINPUT_H diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index 5b300d33..b530bbea 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: checkbox.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "checkbox.h" diff --git a/src/gui/checkbox.h b/src/gui/checkbox.h index 262e63ae..36083390 100644 --- a/src/gui/checkbox.h +++ b/src/gui/checkbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: checkbox.h 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #ifndef _TMW_CHECKBOX_H diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 0ff8be17..5b700831 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: confirm_dialog.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "confirm_dialog.h" diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h index 8728f83f..3115485d 100644 --- a/src/gui/confirm_dialog.h +++ b/src/gui/confirm_dialog.h @@ -18,7 +18,7 @@ * 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$ + * $Id: confirm_dialog.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_OPTION_DIALOG_H diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index baa1ea34..0b62ca3c 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: connection.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "connection.h" diff --git a/src/gui/connection.h b/src/gui/connection.h index 7a072d2e..86b688a3 100644 --- a/src/gui/connection.h +++ b/src/gui/connection.h @@ -18,7 +18,7 @@ * 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$ + * $Id: connection.h 2112 2006-01-22 13:31:13Z der_doener $ */ #ifndef _TMW_CONNECTION_H diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index d6d99307..1e7d5b35 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: debugwindow.cpp 3509 2007-08-23 13:43:17Z b_lindeijer $ */ #include "debugwindow.h" diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 9b6f2017..59ae765c 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: debugwindow.h 3509 2007-08-23 13:43:17Z b_lindeijer $ */ #ifndef _TMW_DEBUGWINDOW_H diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 93b9ea37..564486aa 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: equipmentwindow.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "equipmentwindow.h" diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 99a3cc60..0cb5cb24 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: equipmentwindow.h 2545 2006-08-17 19:11:28Z crush_tmw $ */ #ifndef _TMW_EQUIPMENT_H diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp index ffdb7896..966d2013 100644 --- a/src/gui/focushandler.cpp +++ b/src/gui/focushandler.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: focushandler.cpp 2239 2006-03-09 05:16:27Z der_doener $ */ #include "focushandler.h" diff --git a/src/gui/focushandler.h b/src/gui/focushandler.h index 252fdd9d..5fde09f1 100644 --- a/src/gui/focushandler.h +++ b/src/gui/focushandler.h @@ -18,7 +18,7 @@ * 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$ + * $Id: focushandler.h 2239 2006-03-09 05:16:27Z der_doener $ */ #ifndef _TMW_FOCUSHANDLER_H diff --git a/src/gui/gccontainer.cpp b/src/gui/gccontainer.cpp index 1edb4daf..8095be61 100644 --- a/src/gui/gccontainer.cpp +++ b/src/gui/gccontainer.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: gccontainer.cpp 4208 2008-04-29 11:25:26Z b_lindeijer $ */ #include "gccontainer.h" diff --git a/src/gui/gccontainer.h b/src/gui/gccontainer.h index 8b8a7ffe..6c6bee80 100644 --- a/src/gui/gccontainer.h +++ b/src/gui/gccontainer.h @@ -18,7 +18,7 @@ * 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$ + * $Id: gccontainer.h 4208 2008-04-29 11:25:26Z b_lindeijer $ */ #ifndef _TMW_GUI_GCCONTAINER_H diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index db0b9f80..e56afc76 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: gui.cpp 3628 2007-10-18 18:39:48Z b_lindeijer $ */ #include "gui.h" diff --git a/src/gui/gui.h b/src/gui/gui.h index 1e4b9348..d2a832c7 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -18,7 +18,7 @@ * 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$ + * $Id: gui.h 3628 2007-10-18 18:39:48Z b_lindeijer $ */ #ifndef _TMW_GUI diff --git a/src/gui/hbox.cpp b/src/gui/hbox.cpp index 69564fbb..dc909195 100644 --- a/src/gui/hbox.cpp +++ b/src/gui/hbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: hbox.cpp 1881 2005-10-18 21:40:25Z der_doener $ */ #include "hbox.h" diff --git a/src/gui/hbox.h b/src/gui/hbox.h index 560b1a29..99364866 100644 --- a/src/gui/hbox.h +++ b/src/gui/hbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: hbox.h 1881 2005-10-18 21:40:25Z der_doener $ */ #ifndef HBOX_H diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 0b010253..56a5e70e 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: help.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "help.h" diff --git a/src/gui/help.h b/src/gui/help.h index 3c3715a0..3b45283c 100644 --- a/src/gui/help.h +++ b/src/gui/help.h @@ -18,7 +18,7 @@ * 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$ + * $Id: help.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_HELP_H diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp index 2a09f255..7a39c2df 100644 --- a/src/gui/inttextbox.cpp +++ b/src/gui/inttextbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: inttextbox.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "inttextbox.h" diff --git a/src/gui/inttextbox.h b/src/gui/inttextbox.h index b5d339ac..64351f48 100644 --- a/src/gui/inttextbox.h +++ b/src/gui/inttextbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: inttextbox.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef INTTEXTBOX_H diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index fcc602f9..b53fa43b 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: inventorywindow.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "inventorywindow.h" diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index d45602d2..4793069c 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: inventorywindow.h 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #ifndef _TMW_INVENTORYWINDOW_H diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index f72462f9..40e2e121 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: item_amount.cpp 3718 2007-11-11 14:46:33Z b_lindeijer $ */ #include "item_amount.h" diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 67002703..668dfe3b 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -18,7 +18,7 @@ * 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$ + * $Id: item_amount.h 3718 2007-11-11 14:46:33Z b_lindeijer $ */ #ifndef _TMW_ITEM_AMOUNT_WINDOW_H diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index cf5dcb92..ce7337d2 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: itemcontainer.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "itemcontainer.h" diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index db8c6f3d..353ac51d 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -18,7 +18,7 @@ * 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$ + * $Id: itemcontainer.h 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #ifndef _TMW_ITEMCONTAINER_H__ diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 0ce4f6b7..5899abd1 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: itemshortcutcontainer.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "itemshortcutcontainer.h" diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h index 58f0aea7..7698755b 100644 --- a/src/gui/itemshortcutcontainer.h +++ b/src/gui/itemshortcutcontainer.h @@ -18,7 +18,7 @@ * 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$ + * $Id: itemshortcutcontainer.h 4076 2008-04-12 18:36:15Z b_lindeijer $ */ #ifndef _TMW_ITEMSHORTCUTCONTAINER_H__ diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp index 3724516a..31f3bf4e 100644 --- a/src/gui/itemshortcutwindow.cpp +++ b/src/gui/itemshortcutwindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: itemshortcutwindow.cpp 4076 2008-04-12 18:36:15Z b_lindeijer $ */ #include "itemshortcutwindow.h" diff --git a/src/gui/itemshortcutwindow.h b/src/gui/itemshortcutwindow.h index 9742abdc..5f7ba3d7 100644 --- a/src/gui/itemshortcutwindow.h +++ b/src/gui/itemshortcutwindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: itemshortcutwindow.h 4076 2008-04-12 18:36:15Z b_lindeijer $ */ #ifndef _TMW_ITEMSHORTCUTWINDOW_H diff --git a/src/gui/linkhandler.h b/src/gui/linkhandler.h index 3a32f825..93a8c000 100644 --- a/src/gui/linkhandler.h +++ b/src/gui/linkhandler.h @@ -18,7 +18,7 @@ * 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$ + * $Id: linkhandler.h 3606 2007-09-27 14:54:09Z b_lindeijer $ */ #ifndef _TMW_LINK_HANDLER_H_ diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 634afa07..cf941be1 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: listbox.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "listbox.h" diff --git a/src/gui/listbox.h b/src/gui/listbox.h index b226a11e..ec95734d 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: listbox.h 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #ifndef _TMW_LISTBOX_H diff --git a/src/gui/login.cpp b/src/gui/login.cpp index d85f4e83..526a8e8f 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: login.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "login.h" @@ -29,12 +29,19 @@ #include "../main.h" #include "../logindata.h" +#include "../configuration.h" #include "button.h" #include "checkbox.h" #include "ok_dialog.h" #include "passwordfield.h" #include "textfield.h" +#include "../utils/tostring.h" + +static const int MAX_SERVER_LIST_SIZE = 5; +static const int LOGIN_DIALOG_WIDTH = 220; +static const int LOGIN_DIALOG_HEIGHT = 140; +static const int FIELD_WIDTH = LOGIN_DIALOG_WIDTH - 70; LoginDialog::LoginDialog(LoginData *loginData): Window("Login"), mLoginData(loginData) @@ -42,59 +49,89 @@ LoginDialog::LoginDialog(LoginData *loginData): gcn::Label *userLabel = new gcn::Label("Name:"); gcn::Label *passLabel = new gcn::Label("Password:"); gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *portLabel = new gcn::Label("Port:"); + mServerList = new DropDownList("MostRecent00", + "216.139.126.36", + "6901", + MAX_SERVER_LIST_SIZE); + mServerListBox = new gcn::ListBox(mServerList); + mServerScrollArea = new ScrollArea(); + mUserField = new TextField(mLoginData->username); mPassField = new PasswordField(mLoginData->password); - mServerField = new TextField(mLoginData->hostname); + mServerField = new TextField(mServerList->getServerAt(0)); + mPortField = new TextField(mServerList->getPortAt(0)); + mServerDropDown = new DropDown(mServerList, + mServerScrollArea, + mServerListBox); + mKeepCheck = new CheckBox("Keep", mLoginData->remember); mOkButton = new Button("OK", "ok", this); mCancelButton = new Button("Cancel", "cancel", this); mRegisterButton = new Button("Register", "register", this); - const int width = 220; - const int height = 100; - - setContentSize(width, height); - - userLabel->setPosition(5, 5); - passLabel->setPosition(5, 14 + userLabel->getHeight()); - serverLabel->setPosition( - 5, 23 + userLabel->getHeight() + passLabel->getHeight()); - mUserField->setPosition(65, 5); - mPassField->setPosition(65, 14 + userLabel->getHeight()); - mServerField->setPosition( - 65, 23 + userLabel->getHeight() + passLabel->getHeight()); - mUserField->setWidth(width - 70); - mPassField->setWidth(width - 70); - mServerField->setWidth(width - 70); - mKeepCheck->setPosition(4, 77); + setContentSize(LOGIN_DIALOG_WIDTH, LOGIN_DIALOG_HEIGHT); + + const int USER_TOP = 5; + userLabel->setPosition(5, USER_TOP); + mUserField->setPosition(65, USER_TOP); + mUserField->setWidth(FIELD_WIDTH); + + const int PASS_TOP = 9 + USER_TOP + userLabel->getHeight(); + passLabel->setPosition(5, PASS_TOP); + mPassField->setPosition(65, PASS_TOP); + mPassField->setWidth(FIELD_WIDTH); + + const int SERVER_TOP = 9 + PASS_TOP + passLabel->getHeight(); + serverLabel->setPosition(5, SERVER_TOP); + mServerField->setPosition(65, SERVER_TOP); + mServerField->setWidth(FIELD_WIDTH); + + const int PORT_TOP = 9 + SERVER_TOP + serverLabel->getHeight(); + portLabel->setPosition(5, PORT_TOP); + mPortField->setPosition(65, PORT_TOP); + mPortField->setWidth(FIELD_WIDTH); + + const int DROP_DOWN_TOP = 9 + PORT_TOP + serverLabel->getHeight(); + mServerDropDown->setPosition(5, DROP_DOWN_TOP); + mServerDropDown->setWidth(FIELD_WIDTH); + + const int REST_TOP = LOGIN_DIALOG_HEIGHT - mCancelButton->getHeight() - 5; + + mKeepCheck->setPosition(4, REST_TOP); mCancelButton->setPosition( - width - mCancelButton->getWidth() - 5, - height - mCancelButton->getHeight() - 5); + LOGIN_DIALOG_WIDTH - mCancelButton->getWidth() - 5, REST_TOP); mOkButton->setPosition( - mCancelButton->getX() - mOkButton->getWidth() - 5, - height - mOkButton->getHeight() - 5); + mCancelButton->getX() - mOkButton->getWidth() - 5, REST_TOP); mRegisterButton->setPosition( - mKeepCheck->getX() + mKeepCheck->getWidth() + 10, - height - mRegisterButton->getHeight() - 5); + mKeepCheck->getX() + mKeepCheck->getWidth() + 10, REST_TOP); mUserField->setActionEventId("ok"); mPassField->setActionEventId("ok"); mServerField->setActionEventId("ok"); + mServerDropDown->setActionEventId("changeSelection"); mUserField->addKeyListener(this); mPassField->addKeyListener(this); mServerField->addKeyListener(this); + mPortField->addKeyListener(this); + mServerDropDown->addKeyListener(this); mUserField->addActionListener(this); mPassField->addActionListener(this); mServerField->addActionListener(this); + mPortField->addActionListener(this); + mServerDropDown->addActionListener(this); mKeepCheck->addActionListener(this); add(userLabel); add(passLabel); add(serverLabel); + add(portLabel); add(mUserField); add(mPassField); add(mServerField); + add(mPortField); + add(mServerDropDown); add(mKeepCheck); add(mOkButton); add(mCancelButton); @@ -114,6 +151,9 @@ LoginDialog::LoginDialog(LoginData *loginData): LoginDialog::~LoginDialog() { + delete mServerList; + delete mServerListBox; + delete mServerScrollArea; } void @@ -122,6 +162,7 @@ LoginDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok" && canSubmit()) { mLoginData->hostname = mServerField->getText(); + mLoginData->port = getUShort(mPortField->getText()); mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); mLoginData->remember = mKeepCheck->isSelected(); @@ -129,9 +170,15 @@ LoginDialog::action(const gcn::ActionEvent &event) mOkButton->setEnabled(false); mRegisterButton->setEnabled(false); - + mServerList->save(mServerField->getText(), mPortField->getText()); state = ACCOUNT_STATE; } + else if (event.getId() == "changeSelection") + { + int selected = mServerListBox->getSelected(); + mServerField->setText(mServerList->getServerAt(selected)); + mPortField->setText(mServerList->getPortAt(selected)); + } else if (event.getId() == "cancel") { state = EXIT_STATE; @@ -140,6 +187,14 @@ LoginDialog::action(const gcn::ActionEvent &event) { // Transfer these fields on to the register dialog mLoginData->hostname = mServerField->getText(); + if (isUShort(mPortField->getText())) + { + mLoginData->port = getUShort(mPortField->getText()); + } + else + { + mLoginData->port = 6901; + } mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); @@ -159,5 +214,148 @@ LoginDialog::canSubmit() return !mUserField->getText().empty() && !mPassField->getText().empty() && !mServerField->getText().empty() && + isUShort(mPortField->getText()) && state == LOGIN_STATE; } + +bool +LoginDialog::isUShort(const std::string &str) +{ + if (str == "") + { + return false; + } + unsigned long l = 0; + for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end(); + strPtr != strEnd; ++strPtr) + { + if (*strPtr < '0' || *strPtr > '9') + { + return false; + } + l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative + if (l > 65535) + { + return false; + } + } + return true; +} + +unsigned short +LoginDialog::getUShort(const std::string &str) +{ + unsigned long l = 0; + for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end(); + strPtr != strEnd; ++strPtr) + { + l = l * 10 + (*strPtr - '0'); + } + return static_cast<unsigned short>(l); +} + +/** + * LoginDialog::DropDownList + */ + +void +LoginDialog::DropDownList::saveEntry(const std::string &server, + const std::string &port, int &saved) +{ + if (saved < MAX_SERVER_LIST_SIZE && server != "") + { + config.setValue(mConfigPrefix + "Server" + toString(saved), server); + config.setValue(mConfigPrefix + "Port" + toString(saved), port); + ++saved; + } +} + +LoginDialog::DropDownList::DropDownList(std::string prefix, + std::string dflt, + std::string dfltPort, + int maxEntries) : + mConfigPrefix(prefix), + mMaxEntries(maxEntries) +{ + for (int i = 0; i < maxEntries; ++i) + { + std::string server = config.getValue(mConfigPrefix + "Server" + + toString(i), ""); + if (server == "") // Just in case had original config entries + { + server = config.getValue(mConfigPrefix + "ServerList" + + toString(i), ""); + } + std::string port = config.getValue(mConfigPrefix + "Port" + + toString(i), dfltPort); + + if (server != "") + { + mServers.push_back(server); + mPorts.push_back(port); + } + } + if (mServers.size() == 0) + { + mServers.push_back(dflt); + mPorts.push_back(dfltPort); + } + +} + +void +LoginDialog::DropDownList::save(const std::string &server, + const std::string &port) +{ + int position = 0; + saveEntry(server, port, position); + for (std::vector<std::string>::const_iterator sPtr = mServers.begin(), + sEnd = mServers.end(), + pPtr = mPorts.begin(), + pEnd = mPorts.end(); + sPtr != sEnd && pPtr != pEnd; + ++sPtr, ++pPtr) + { + if (*sPtr != server || *pPtr != port) + { + saveEntry(*sPtr, *pPtr, position); + } + } +} + +int +LoginDialog::DropDownList::getNumberOfElements() +{ + return mServers.size(); +} + +std::string +LoginDialog::DropDownList::getElementAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return getServerAt(i) + ":" + getPortAt(i); +} + +std::string +LoginDialog::DropDownList::getServerAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mServers.at(i); +} + + +std::string +LoginDialog::DropDownList::getPortAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mPorts.at(i); +} diff --git a/src/gui/login.h b/src/gui/login.h index e08120cb..8a228b5f 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -18,18 +18,23 @@ * 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$ + * $Id: login.h 3234 2007-03-24 13:05:27Z b_lindeijer $ */ #ifndef _TMW_LOGIN_H #define _TMW_LOGIN_H #include <iosfwd> +#include <vector> +#include <string> + #include <guichan/actionlistener.hpp> #include <guichan/keylistener.hpp> #include "window.h" #include "../guichanfwd.h" +#include "widgets/dropdown.h" +#include "scrollarea.h" class LoginData; @@ -72,15 +77,66 @@ class LoginDialog : public Window, public gcn::ActionListener, bool canSubmit(); + /** + * Function to decide whether string is an unsigned short or not + * + * @param str the string to parse + * + * @return true is str is an unsigned short, false otherwise + */ + static bool + isUShort(const std::string &str); + + /** + * Converts string to an unsigned short (undefined if invalid) + * + * @param str the string to parse + * + * @return the value str represents + */ + static unsigned short + getUShort(const std::string &str); + + DropDown *mServerDropDown; gcn::TextField *mUserField; gcn::TextField *mPassField; gcn::TextField *mServerField; + gcn::TextField *mPortField; gcn::CheckBox *mKeepCheck; gcn::Button *mOkButton; gcn::Button *mCancelButton; gcn::Button *mRegisterButton; LoginData *mLoginData; + + /** + * Helper class to keep a list of all the recent entries for the + * dropdown + */ + class DropDownList : public gcn::ListModel + { + private: + std::vector<std::string> mServers; + std::vector<std::string> mPorts; + std::string mConfigPrefix; + int mMaxEntries; + void saveEntry(const std::string &server, + const std::string &port, int &saved); + public: + DropDownList(std::string prefix, + std::string dfltServer, + std::string dfltPort, + int maxEntries); + void save(const std::string &server, const std::string &port); + int getNumberOfElements(); + std::string getElementAt(int i); + std::string getServerAt(int i); + std::string getPortAt(int i); + }; + DropDownList *mServerList; + gcn::ListBox *mServerListBox; + ScrollArea *mServerScrollArea; + }; #endif diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 2043b7d1..c3af6896 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: menuwindow.cpp 4060 2008-04-09 14:49:07Z b_lindeijer $ */ #include "menuwindow.h" diff --git a/src/gui/menuwindow.h b/src/gui/menuwindow.h index f43b9921..add04095 100644 --- a/src/gui/menuwindow.h +++ b/src/gui/menuwindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: menuwindow.h 2417 2006-07-19 15:12:06Z umperio $ */ #ifndef _TMW_MENU_H diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index c17fa06b..dc7df9b9 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: minimap.cpp 4116 2008-04-17 12:48:43Z peaveydk $ */ #include "minimap.h" diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 5e9458bf..d2640caa 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -18,7 +18,7 @@ * 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$ + * $Id: minimap.h 2417 2006-07-19 15:12:06Z umperio $ */ #ifndef _TMW_MINIMAP_H diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 8f121368..3a7e7bf0 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: ministatus.cpp 3753 2007-11-20 12:27:56Z b_lindeijer $ */ #include "ministatus.h" diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 718fe140..d4002d93 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -18,7 +18,7 @@ * 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$ + * $Id: ministatus.h 2581 2006-08-25 22:04:17Z b_lindeijer $ */ #ifndef _TMW_MINISTATUS_H diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index 6783a546..c2088e75 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: newskill.cpp 3587 2007-09-20 13:24:20Z b_lindeijer $ */ /* This file implements the new skill dialog for use under the latest diff --git a/src/gui/newskill.h b/src/gui/newskill.h index 6e12169f..c553ab1d 100644 --- a/src/gui/newskill.h +++ b/src/gui/newskill.h @@ -18,7 +18,7 @@ * 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$ + * $Id: newskill.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_NSKILL_H diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 7b4fc634..52f35a88 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: npc_text.cpp 4096 2008-04-16 08:39:59Z b_lindeijer $ */ #include "npc_text.h" diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 0ef1b938..9e2b4ecd 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -18,7 +18,7 @@ * 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$ + * $Id: npc_text.h 4096 2008-04-16 08:39:59Z b_lindeijer $ */ #ifndef _TMW_NPC_TEXT_H diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 1bcdc8ff..e6523583 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: npclistdialog.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "npclistdialog.h" diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index c09b0a8c..a96fd766 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -18,7 +18,7 @@ * 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$ + * $Id: npclistdialog.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_GUI_NPCLISTDIALOG_H diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index ca9d2a7b..c49bb6bb 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: ok_dialog.cpp 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #include "ok_dialog.h" diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h index a7b24a90..1c8e0c18 100644 --- a/src/gui/ok_dialog.h +++ b/src/gui/ok_dialog.h @@ -18,7 +18,7 @@ * 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$ + * $Id: ok_dialog.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _OK_DIALOG_H diff --git a/src/gui/passwordfield.cpp b/src/gui/passwordfield.cpp index 533f54fb..710eb767 100644 --- a/src/gui/passwordfield.cpp +++ b/src/gui/passwordfield.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: passwordfield.cpp 2132 2006-02-01 14:53:10Z der_doener $ */ #include "passwordfield.h" diff --git a/src/gui/passwordfield.h b/src/gui/passwordfield.h index cae1f92e..725bfbcf 100644 --- a/src/gui/passwordfield.h +++ b/src/gui/passwordfield.h @@ -18,7 +18,7 @@ * 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$ + * $Id: passwordfield.h 2895 2006-12-09 01:44:18Z b_lindeijer $ */ #ifndef _TMW_PASSWORDFIELD_H_ diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 2c633b72..6d39ce05 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: playerbox.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h index c226e750..0aa48a2c 100644 --- a/src/gui/playerbox.h +++ b/src/gui/playerbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: playerbox.h 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #ifndef __TMW_PLAYERBOX_H__ diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index cdc998e0..7e40abed 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: popupmenu.cpp 4243 2008-05-16 15:48:52Z the_enemy $ */ #include "popupmenu.h" @@ -40,6 +40,9 @@ #include "../npc.h" #include "../player_relations.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../resources/iteminfo.h" #include "../resources/itemdb.h" @@ -70,49 +73,53 @@ void PopupMenu::showPopup(int x, int y, Being *being) switch (mBeing->getType()) { - case Being::PLAYER: - { - // Players can be traded with. Later also attack, follow and - // add as buddy will be options in this menu. - const std::string &name = mBeing->getName(); - mBrowserBox->addRow("@@trade|Trade With " + name + "@@"); - mBrowserBox->addRow("@@attack|Attack " + name + "@@"); - - mBrowserBox->addRow("##3---"); - - switch (player_relations.getRelation(name)) { - case PlayerRelation::NEUTRAL: - mBrowserBox->addRow("@@friend|Befriend " + name + "@@"); - - case PlayerRelation::FRIEND: - mBrowserBox->addRow("@@disregard|Disregard " + name + "@@"); - mBrowserBox->addRow("@@ignore|Ignore " + name + "@@"); - break; - - case PlayerRelation::DISREGARDED: - mBrowserBox->addRow("@@unignore|Un-Ignore " + name + "@@"); - mBrowserBox->addRow("@@ignore|Completely ignore " + name + "@@"); - break; - - case PlayerRelation::IGNORED: - mBrowserBox->addRow("@@unignore|Un-Ignore " + name + "@@"); - break; - } - - //mBrowserBox->addRow("@@follow|Follow " + name + "@@"); - //mBrowserBox->addRow("@@buddy|Add " + name + " to Buddy List@@"); - } - break; - - case Being::NPC: - // NPCs can be talked to (single option, candidate for removal - // unless more options would be added) - mBrowserBox->addRow("@@talk|Talk To NPC@@"); - break; - - default: - /* Other beings aren't interesting... */ - break; + case Being::PLAYER: + { + // Players can be traded with. Later also attack, follow and + // add as buddy will be options in this menu. + const std::string &name = mBeing->getName(); + mBrowserBox->addRow("@@trade|Trade With " + name + "@@"); + mBrowserBox->addRow("@@attack|Attack " + name + "@@"); + + mBrowserBox->addRow("##3---"); + + switch (player_relations.getRelation(name)) { + case PlayerRelation::NEUTRAL: + mBrowserBox->addRow("@@friend|Befriend " + name + "@@"); + + case PlayerRelation::FRIEND: + mBrowserBox->addRow("@@disregard|Disregard " + name + "@@"); + mBrowserBox->addRow("@@ignore|Ignore " + name + "@@"); + break; + + case PlayerRelation::DISREGARDED: + mBrowserBox->addRow("@@unignore|Un-Ignore " + name + "@@"); + mBrowserBox->addRow("@@ignore|Completely ignore " + name + "@@"); + break; + + case PlayerRelation::IGNORED: + mBrowserBox->addRow("@@unignore|Un-Ignore " + name + "@@"); + break; + } + + //mBrowserBox->addRow("@@follow|Follow " + name + "@@"); + //mBrowserBox->addRow("@@buddy|Add " + name + " to Buddy List@@"); + + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow("@@party-invite|Invite " + name + + " to party@@"); + } + break; + + case Being::NPC: + // NPCs can be talked to (single option, candidate for removal + // unless more options would be added) + mBrowserBox->addRow("@@talk|Talk To NPC@@"); + break; + + default: + /* Other beings aren't interesting... */ + break; } //browserBox->addRow("@@look|Look To@@"); @@ -142,56 +149,56 @@ void PopupMenu::handleLink(const std::string& link) { // Talk To action if (link == "talk" && - mBeing != NULL && - mBeing->getType() == Being::NPC && - current_npc == 0) + mBeing != NULL && + mBeing->getType() == Being::NPC && + current_npc == 0) { - dynamic_cast<NPC*>(mBeing)->talk(); + dynamic_cast<NPC*>(mBeing)->talk(); } // Trade action else if (link == "trade" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_node->trade(mBeing); - tradePartnerName = mBeing->getName(); + player_node->trade(mBeing); + tradePartnerName = mBeing->getName(); } // Attack action else if (link == "attack" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_node->attack(mBeing, true); + player_node->attack(mBeing, true); } else if (link == "unignore" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::NEUTRAL); + player_relations.setRelation(mBeing->getName(), PlayerRelation::NEUTRAL); } else if (link == "ignore" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::IGNORED); + player_relations.setRelation(mBeing->getName(), PlayerRelation::IGNORED); } else if (link == "disregard" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::DISREGARDED); + player_relations.setRelation(mBeing->getName(), PlayerRelation::DISREGARDED); } else if (link == "friend" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) + mBeing != NULL && + mBeing->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::FRIEND); + player_relations.setRelation(mBeing->getName(), PlayerRelation::FRIEND); } /* @@ -204,16 +211,16 @@ void PopupMenu::handleLink(const std::string& link) // Add Buddy action else if ((link == "buddy") && mBeing != NULL && mBeing->isPlayer()) { - if (!buddyWindow->isVisible()) - buddyWindow->setVisible(true); + if (!buddyWindow->isVisible()) + buddyWindow->setVisible(true); - buddyWindow->addBuddy(mBeing->getName()); + buddyWindow->addBuddy(mBeing->getName()); }*/ // Pick Up Floor Item action else if ((link == "pickup") && mFloorItem != NULL) { - player_node->pickUp(mFloorItem); + player_node->pickUp(mFloorItem); } // Look To action @@ -223,39 +230,47 @@ void PopupMenu::handleLink(const std::string& link) else if (link == "use") { - assert(mItem); - if (mItem->isEquipment()) - { - if (mItem->isEquipped()) - { - player_node->unequipItem(mItem); - } - else - { - player_node->equipItem(mItem); - } - } - else - { - player_node->useItem(mItem); - } + assert(mItem); + if (mItem->isEquipment()) + { + if (mItem->isEquipped()) + { + player_node->unequipItem(mItem); + } + else + { + player_node->equipItem(mItem); + } + } + else + { + player_node->useItem(mItem); + } } else if (link == "drop") { - new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem); + new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem); } else if (link == "description") { - // do nothing for now, I need to write - // a window for the description first + // do nothing for now, I need to write + // a window for the description first + } + else if (link == "party-invite" && + mBeing != NULL && + mBeing->getType() == Being::PLAYER) + { + MessageOut outMsg(player_node->getNetwork()); + outMsg.writeInt16(CMSG_PARTY_INVITE); + outMsg.writeInt32(mBeing->getId()); } // Unknown actions else { - std::cout << link << std::endl; + std::cout << link << std::endl; } setVisible(false); @@ -273,13 +288,13 @@ void PopupMenu::showPopup(int x, int y, Item *item) if (item->isEquipment()) { - if (item->isEquipped()) - mBrowserBox->addRow("@@use|Unequip@@"); - else - mBrowserBox->addRow("@@use|Equip@@"); + if (item->isEquipped()) + mBrowserBox->addRow("@@use|Unequip@@"); + else + mBrowserBox->addRow("@@use|Equip@@"); } else - mBrowserBox->addRow("@@use|Use@@"); + mBrowserBox->addRow("@@use|Use@@"); mBrowserBox->addRow("@@drop|Drop@@"); mBrowserBox->addRow("@@description|Description@@"); @@ -293,9 +308,9 @@ void PopupMenu::showPopup(int x, int y) { setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); + x = windowContainer->getWidth() - getWidth(); if (windowContainer->getHeight() < (y + getHeight() + 5)) - y = windowContainer->getHeight() - getHeight(); + y = windowContainer->getHeight() - getHeight(); setPosition(x, y); setVisible(true); requestMoveToTop(); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 9fe9f866..601fa2ae 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -18,7 +18,7 @@ * 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$ + * $Id: popupmenu.h 2239 2006-03-09 05:16:27Z der_doener $ */ #ifndef _TMW_POPUP_MENU_H diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 6d18b2f7..6dbc3b85 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: progressbar.cpp 4008 2008-03-27 14:51:10Z b_lindeijer $ */ #include "progressbar.h" diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index 3e58f14e..ed8eace4 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -18,7 +18,7 @@ * 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$ + * $Id: progressbar.h 2240 2006-03-09 12:24:36Z der_doener $ */ #ifndef _TMW_PROGRESSBAR_H diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index 0ac4dea8..cbab4d2d 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: radiobutton.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "radiobutton.h" diff --git a/src/gui/radiobutton.h b/src/gui/radiobutton.h index 4f868fdb..bab4a9dc 100644 --- a/src/gui/radiobutton.h +++ b/src/gui/radiobutton.h @@ -18,7 +18,7 @@ * 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$ + * $Id: radiobutton.h 1584 2005-08-13 12:49:52Z der_doener $ */ #ifndef _TMW_RADIOBUTTON_H diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 9496da93..e0b663b8 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: register.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "register.h" @@ -41,6 +41,8 @@ #include "textfield.h" #include "ok_dialog.h" +#include "../utils/tostring.h" + void WrongDataNoticeListener::setTarget(gcn::TextField *textField) { @@ -65,53 +67,65 @@ RegisterDialog::RegisterDialog(LoginData *loginData): gcn::Label *passwordLabel = new gcn::Label("Password:"); gcn::Label *confirmLabel = new gcn::Label("Confirm:"); gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *portLabel = new gcn::Label("Port:"); + mUserField = new TextField(loginData->username); mPasswordField = new PasswordField(loginData->password); mConfirmField = new PasswordField(); mServerField = new TextField(loginData->hostname); + mPortField = new TextField(toString(loginData->port)); mMaleButton = new RadioButton("Male", "sex", true); mFemaleButton = new RadioButton("Female", "sex", false); mRegisterButton = new Button("Register", "register", this); mCancelButton = new Button("Cancel", "cancel", this); - const int width = 220; - const int height = 150; - setContentSize(width, height); - - mUserField->setPosition(65, 5); - mUserField->setWidth(width - 70); - mPasswordField->setPosition( - 65, mUserField->getY() + mUserField->getHeight() + 7); - mPasswordField->setWidth(mUserField->getWidth()); - mConfirmField->setPosition( - 65, mPasswordField->getY() + mPasswordField->getHeight() + 7); - mConfirmField->setWidth(mUserField->getWidth()); - mServerField->setPosition( - 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7); - mServerField->setWidth(mUserField->getWidth()); - - userLabel->setPosition(5, mUserField->getY() + 1); - passwordLabel->setPosition(5, mPasswordField->getY() + 1); - confirmLabel->setPosition(5, mConfirmField->getY() + 1); - serverLabel->setPosition(5, mServerField->getY() + 1); - - mMaleButton->setPosition( - 70, mConfirmField->getY() + mConfirmField->getHeight() + 7); - mFemaleButton->setPosition( - 70 + 10 + mMaleButton->getWidth(), - mMaleButton->getY()); + const int WIDTH = 220; + const int HEIGHT = 170; + const int FIELD_WIDTH = WIDTH - 70; + + setContentSize(WIDTH, HEIGHT); + + const int USER_TOP = 5; + userLabel->setPosition(5, USER_TOP); + mUserField->setPosition(65, USER_TOP); + mUserField->setWidth(FIELD_WIDTH); + + const int PASS_TOP = 9 + USER_TOP + userLabel->getHeight(); + passwordLabel->setPosition(5, PASS_TOP); + mPasswordField->setPosition(65, PASS_TOP); + mPasswordField->setWidth(FIELD_WIDTH); + + const int CONFIRM_TOP = 9 + PASS_TOP + passwordLabel->getHeight(); + confirmLabel->setPosition(5, CONFIRM_TOP); + mConfirmField->setPosition(65, CONFIRM_TOP); + mConfirmField->setWidth(FIELD_WIDTH); + + const int SEX_TOP = 9 + CONFIRM_TOP + confirmLabel->getHeight(); + mMaleButton->setPosition(70, SEX_TOP); + mFemaleButton->setPosition(80 + mMaleButton->getWidth(), SEX_TOP); + + const int SERVER_TOP = 9 + SEX_TOP + mMaleButton->getHeight() + 5; + serverLabel->setPosition(5, SERVER_TOP); + mServerField->setPosition(65, SERVER_TOP); + mServerField->setWidth(FIELD_WIDTH); + + const int PORT_TOP = 9 + SERVER_TOP + serverLabel->getHeight(); + portLabel->setPosition(5, PORT_TOP); + mPortField->setPosition(65, PORT_TOP); + mPortField->setWidth(FIELD_WIDTH); mCancelButton->setPosition( - width - mCancelButton->getWidth() - 5, - height - mCancelButton->getHeight() - 5); + WIDTH - mCancelButton->getWidth() - 5, + HEIGHT - mCancelButton->getHeight() - 5); mRegisterButton->setPosition( mCancelButton->getX() - mRegisterButton->getWidth() - 5, - height - mRegisterButton->getHeight() - 5); + HEIGHT - mRegisterButton->getHeight() - 5); mUserField->addKeyListener(this); mPasswordField->addKeyListener(this); mConfirmField->addKeyListener(this); mServerField->addKeyListener(this); + mPortField->addKeyListener(this); /* TODO: * This is a quick and dirty way to respond to the ENTER key, regardless of @@ -122,19 +136,26 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mPasswordField->setActionEventId("register"); mConfirmField->setActionEventId("register"); mServerField->setActionEventId("register"); + mPortField->setActionEventId("register"); + mUserField->addActionListener(this); mPasswordField->addActionListener(this); mConfirmField->addActionListener(this); mServerField->addActionListener(this); + mPortField->addActionListener(this); add(userLabel); add(passwordLabel); - add(serverLabel); add(confirmLabel); + add(serverLabel); + add(portLabel); + add(mUserField); add(mPasswordField); add(mConfirmField); add(mServerField); + add(mPortField); + add(mMaleButton); add(mFemaleButton); add(mRegisterButton); @@ -232,7 +253,7 @@ RegisterDialog::action(const gcn::ActionEvent &event) mRegisterButton->setEnabled(false); mLoginData->hostname = mServerField->getText(); - mLoginData->port = (short) config.getValue("port", 0); + mLoginData->port = getUShort(mPortField->getText()); mLoginData->username = mUserField->getText(); mLoginData->password = mPasswordField->getText(); mLoginData->username += mFemaleButton->isSelected() ? "_F" : "_M"; @@ -256,5 +277,42 @@ RegisterDialog::canSubmit() !mPasswordField->getText().empty() && !mConfirmField->getText().empty() && !mServerField->getText().empty() && + isUShort(mPortField->getText()) && state == REGISTER_STATE; } + +bool +RegisterDialog::isUShort(const std::string &str) +{ + if (str == "") + { + return false; + } + unsigned long l = 0; + for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end(); + strPtr != strEnd; ++strPtr) + { + if (*strPtr < '0' || *strPtr > '9') + { + return false; + } + l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative + if (l > 65535) + { + return false; + } + } + return true; +} + +unsigned short +RegisterDialog::getUShort(const std::string &str) +{ + unsigned long l = 0; + for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end(); + strPtr != strEnd; ++strPtr) + { + l = l * 10 + (*strPtr - '0'); + } + return static_cast<unsigned short>(l); +} diff --git a/src/gui/register.h b/src/gui/register.h index a80594af..6f997b75 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -18,7 +18,7 @@ * 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$ + * $Id: register.h 3234 2007-03-24 13:05:27Z b_lindeijer $ */ #ifndef _TMW_REGISTER_H @@ -87,10 +87,31 @@ class RegisterDialog : public Window, public gcn::ActionListener, bool canSubmit(); + /** + * Function to decide whether string is an unsigned short or not + * + * @param str the string to parse + * + * @return true if str is an unsigned short, false otherwise + */ + static bool + isUShort(const std::string &str); + + /** + * Converts string to an unsigned short (undefined if invalid) + * + * @param str the string to parse + * + * @return the value str represents + */ + static unsigned short + getUShort(const std::string &str); + gcn::TextField *mUserField; gcn::TextField *mPasswordField; gcn::TextField *mConfirmField; gcn::TextField *mServerField; + gcn::TextField *mPortField; gcn::Button *mRegisterButton; gcn::Button *mCancelButton; diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 255aa2d8..a3aef702 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: scrollarea.cpp 4204 2008-04-28 18:29:04Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index be361f68..b3fa17f3 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -18,7 +18,7 @@ * 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$ + * $Id: scrollarea.h 4204 2008-04-28 18:29:04Z b_lindeijer $ */ #ifndef __TMW_SCROLLAREA_H__ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 82d340fb..5f64fcea 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: sell.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #include "sell.h" diff --git a/src/gui/sell.h b/src/gui/sell.h index 0c1a2007..11528f89 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -18,7 +18,7 @@ * 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$ + * $Id: sell.h 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #ifndef _TMW_SELL_H diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index c895d166..ce843452 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup.cpp 4306 2008-05-28 20:22:37Z crush_tmw $ */ #include <algorithm> diff --git a/src/gui/setup.h b/src/gui/setup.h index 543cab2c..d4f0857b 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setup.h 4237 2008-05-14 18:57:32Z b_lindeijer $ */ #ifndef _TMW_SETUP_H diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 4227b5ca..09357cce 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_audio.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "setup_audio.h" diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index 6e722f74..76420101 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_audio.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_GUI_SETUP_AUDIO_H diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index a501298e..41e91595 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_joystick.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "setup_joystick.h" diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index 6d3ad129..399156d8 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_joystick.h 3035 2007-01-14 14:54:39Z b_lindeijer $ */ #ifndef _TMW_GUI_SETUP_JOYSTICK_H diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index e88080b5..704fc691 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_keyboard.cpp 4255 2008-05-21 21:44:27Z crush_tmw $ */ #include "setup_keyboard.h" diff --git a/src/gui/setup_keyboard.h b/src/gui/setup_keyboard.h index b72e8746..7f945181 100644 --- a/src/gui/setup_keyboard.h +++ b/src/gui/setup_keyboard.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_keyboard.h 4255 2008-05-21 21:44:27Z crush_tmw $ */ #ifndef _TMW_GUI_SETUP_KEYBOARD_H diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 24b559da..809364ea 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_players.cpp 4353 2008-06-16 07:04:46Z b_lindeijer $ */ #include "setup_players.h" diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 97e4cdd6..bc38f1f9 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_video.cpp 4338 2008-06-05 18:41:39Z crush_tmw $ */ #include "setup_video.h" diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index a0701a3c..0d7ea700 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setup_video.h 4306 2008-05-28 20:22:37Z crush_tmw $ */ #ifndef _TMW_GUI_SETUP_VIDEO_H diff --git a/src/gui/setuptab.h b/src/gui/setuptab.h index a7d45b9a..bbfe4fac 100644 --- a/src/gui/setuptab.h +++ b/src/gui/setuptab.h @@ -18,7 +18,7 @@ * 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$ + * $Id: setuptab.h 2273 2006-03-19 00:48:10Z der_doener $ */ #ifndef _TMW_GUI_SETUPTAB_H diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 62d18769..015e70d5 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: shop.cpp 4348 2008-06-14 12:42:49Z the_enemy $ */ #include "shop.h" diff --git a/src/gui/shop.h b/src/gui/shop.h index 22e715c9..78276610 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -18,7 +18,7 @@ * 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$ + * $Id: shop.h 4347 2008-06-12 09:06:01Z b_lindeijer $ */ #ifndef _SHOP_H diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 3ab40c9a..e70fb3ef 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: skill.cpp 3754 2007-11-20 15:19:50Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/skill.h b/src/gui/skill.h index 6879640c..6bd6c51b 100644 --- a/src/gui/skill.h +++ b/src/gui/skill.h @@ -18,7 +18,7 @@ * 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$ + * $Id: skill.h 3494 2007-08-20 05:29:12Z joshlangley $ */ #ifndef _TMW_SKILL_H diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index c94c7bfb..a1ae6acc 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: slider.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include "slider.h" diff --git a/src/gui/slider.h b/src/gui/slider.h index dc38b738..524d8799 100644 --- a/src/gui/slider.h +++ b/src/gui/slider.h @@ -18,7 +18,7 @@ * 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$ + * $Id: slider.h 1584 2005-08-13 12:49:52Z der_doener $ */ #ifndef _TMW_SLIDER_H diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 927b3554..cba815b5 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: status.cpp 3510 2007-08-23 14:14:51Z b_lindeijer $ */ #include "status.h" diff --git a/src/gui/status.h b/src/gui/status.h index 10773e10..4d082148 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -18,7 +18,7 @@ * 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$ + * $Id: status.h 3538 2007-08-28 00:01:38Z b_lindeijer $ */ #ifndef _TMW_STATUS_H diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index d6267e65..71e0f3c4 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: tabbedcontainer.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h index 7f8deef9..14f27aba 100644 --- a/src/gui/tabbedcontainer.h +++ b/src/gui/tabbedcontainer.h @@ -18,7 +18,7 @@ * 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$ + * $Id: tabbedcontainer.h 3152 2007-02-27 16:31:34Z crush_tmw $ */ #ifndef _TMW_TABPANE_H diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 8d16dc46..743d88b6 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: textbox.cpp 4096 2008-04-16 08:39:59Z b_lindeijer $ */ #include "textbox.h" diff --git a/src/gui/textbox.h b/src/gui/textbox.h index f06f98ec..7df30fd9 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: textbox.h 4096 2008-04-16 08:39:59Z b_lindeijer $ */ #ifndef __TMW_TEXTBOX_H__ diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 8db720cf..95291267 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: textfield.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/textfield.h b/src/gui/textfield.h index bc47d501..39bcbf85 100644 --- a/src/gui/textfield.h +++ b/src/gui/textfield.h @@ -18,7 +18,7 @@ * 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$ + * $Id: textfield.h 4045 2008-04-07 15:23:07Z b_lindeijer $ */ #ifndef __TMW_TEXTFIELD_H__ diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 42b6e9bc..d8f23171 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: updatewindow.cpp 4332 2008-06-05 07:33:12Z b_lindeijer $ */ #include "updatewindow.h" diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 61ea4a27..b669f829 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -18,7 +18,7 @@ * 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$ + * $Id: updatewindow.h 4332 2008-06-05 07:33:12Z b_lindeijer $ */ #ifndef _UPDATERWINDOW_H diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp index b503508e..6f36dc9c 100644 --- a/src/gui/vbox.cpp +++ b/src/gui/vbox.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: vbox.cpp 3587 2007-09-20 13:24:20Z b_lindeijer $ */ #include "vbox.h" diff --git a/src/gui/vbox.h b/src/gui/vbox.h index 06a270ef..ff52717b 100644 --- a/src/gui/vbox.h +++ b/src/gui/vbox.h @@ -18,7 +18,7 @@ * 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$ + * $Id: vbox.h 1881 2005-10-18 21:40:25Z der_doener $ */ #ifndef VBOX_H diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 01324a47..e7fdb522 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: viewport.cpp 4098 2008-04-16 11:36:41Z b_lindeijer $ */ #include "viewport.h" @@ -37,6 +37,7 @@ #include "../map.h" #include "../monster.h" #include "../npc.h" +#include "../textmanager.h" #include "../resources/animation.h" #include "../resources/monsterinfo.h" @@ -228,7 +229,6 @@ Viewport::draw(gcn::Graphics *gcnGraphics) mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY, 2); mMap->drawOverlay(graphics, mPixelViewX, mPixelViewY, (int) config.getValue("OverlayDetail", 2)); - drawTargetName(graphics); } // Find a path from the player to the mouse, and draw it. This is for debug @@ -259,12 +259,16 @@ Viewport::draw(gcn::Graphics *gcnGraphics) } } + // Draw text + if (textManager) + { + textManager->draw(graphics, mPixelViewX, mPixelViewY); + } + // Draw player nickname, speech, and emotion sprite as needed Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) { - (*i)->drawSpeech(graphics, -(int) mPixelViewX, -(int) mPixelViewY); - (*i)->drawName(graphics, -(int) mPixelViewX, -(int) mPixelViewY); (*i)->drawEmotion(graphics, -(int) mPixelViewX, -(int) mPixelViewY); } @@ -332,24 +336,6 @@ Viewport::drawTargetCursor(Graphics *graphics) } void -Viewport::drawTargetName(Graphics *graphics) -{ - // Draw target marker if needed - Being *target = player_node->getTarget(); - if (target && target->getType() == Being::MONSTER) - { - graphics->setFont(speechFont); - graphics->setColor(gcn::Color(255, 32, 32)); - - const MonsterInfo &mi = static_cast<Monster*>(target)->getInfo(); - int posX = target->getPixelX() + 16 - (int)mPixelViewX; - int posY = target->getPixelY() + 16 - target->getHeight() - (int)mPixelViewY; - - graphics->drawText(mi.getName(), posX, posY, gcn::Graphics::CENTER); - } -} - -void Viewport::mousePressed(gcn::MouseEvent &event) { // Check if we are alive and kickin' diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 8d3fbd3c..44a877a6 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -18,7 +18,7 @@ * 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$ + * $Id: viewport.h 4247 2008-05-19 10:48:18Z b_lindeijer $ */ #ifndef _TMW_VIEWPORT_H_ diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp new file mode 100644 index 00000000..b33a55cf --- /dev/null +++ b/src/gui/widgets/dropdown.cpp @@ -0,0 +1,169 @@ +/* + * 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 <algorithm> + +#include "dropdown.h" + +#include "../../graphics.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +#include "../../utils/dtor.h" + +int DropDown::instances = 0; +Image *DropDown::buttons[2][2]; +ImageRect DropDown::skin; + +DropDown::DropDown(gcn::ListModel *listModel, + gcn::ScrollArea *scrollArea, + gcn::ListBox *listBox): + gcn::DropDown::DropDown(listModel, + scrollArea, listBox) +{ + setFrameSize(2); + + // Initialize graphics + if (instances == 0) + { + // Load the background skin + ResourceManager *resman = ResourceManager::getInstance(); + + // Get the button skin + buttons[1][0] = + resman->getImage("graphics/gui/vscroll_up_default.png"); + buttons[0][0] = + resman->getImage("graphics/gui/vscroll_down_default.png"); + buttons[1][1] = + resman->getImage("graphics/gui/vscroll_up_pressed.png"); + buttons[0][1] = + resman->getImage("graphics/gui/vscroll_down_pressed.png"); + + // get the border skin + Image *boxBorder = resman->getImage("graphics/gui/deepbox.png"); + int gridx[4] = {0, 3, 28, 31}; + int gridy[4] = {0, 3, 28, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + skin.grid[a] = boxBorder->getSubImage( + gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, + gridy[y + 1] - gridy[y] + 1); + a++; + } + } + + boxBorder->decRef(); + } + + instances++; +} + +DropDown::~DropDown() +{ + instances--; + // Free images memory + if (instances == 0) + { + buttons[0][0]->decRef(); + buttons[0][1]->decRef(); + buttons[1][0]->decRef(); + buttons[1][1]->decRef(); + + for_each(skin.grid, skin.grid + 9, dtor<Image*>()); + } +} + +void DropDown::draw(gcn::Graphics* graphics) +{ + int h; + + if (mDroppedDown) + { + h = mFoldedUpHeight; + } + else + { + h = getHeight(); + } + + int alpha = getBaseColor().a; + gcn::Color faceColor = getBaseColor(); + faceColor.a = alpha; + gcn::Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + gcn::Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + if (mListBox->getListModel() && mListBox->getSelected() >= 0) + { + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + } + + if (isFocused()) + { + graphics->setColor(highlightColor); + graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); + } + + drawButton(graphics); + + if (mDroppedDown) + { + drawChildren(graphics); + + // Draw two lines separating the ListBox with se selected + // element view. + graphics->setColor(highlightColor); + graphics->drawLine(0, h, getWidth(), h); + graphics->setColor(shadowColor); + graphics->drawLine(0, h + 1, getWidth(), h + 1); + } +} + +void DropDown::drawFrame(gcn::Graphics *graphics) +{ + const int bs = getFrameSize(); + const int w = getWidth() + bs * 2; + const int h = getHeight() + bs * 2; + + static_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, skin); +} + +void DropDown::drawButton(gcn::Graphics *graphics) +{ + int height = mDroppedDown ? mFoldedUpHeight : getHeight(); + + static_cast<Graphics*>(graphics)-> + drawImage(buttons[mDroppedDown][mPushed], getWidth() - height, 1); +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h new file mode 100644 index 00000000..d0dab7d2 --- /dev/null +++ b/src/gui/widgets/dropdown.h @@ -0,0 +1,85 @@ +/* + * 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 DROPDOWN_H +#define DROPDOWN_H + +#include <iosfwd> + +#include <guichan/widgets/dropdown.hpp> +#include "../scrollarea.h" +#include "../listbox.h" + +class Image; +class ImageRect; + + /** + * A drop down box from which you can select different values. It is one of + * the most complicated Widgets you will find in Guichan. For drawing the + * DroppedDown box it uses one ScrollArea and one ListBox. It also uses an + * internal FocusHandler to handle the focus of the internal ScollArea and + * ListBox. DropDown uses a ListModel to handle the list. To be able to use + * DropDown you must give DropDown an implemented ListModel which represents + * your list. + */ +class DropDown : public gcn::DropDown +{ + public: + /** + * Contructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(gcn::ListModel *listModel = NULL, + gcn::ScrollArea *scrollArea = NULL, + gcn::ListBox *listBox = NULL); + + /** + * Destructor. + */ + ~DropDown(); + + void draw(gcn::Graphics* graphics); + + void drawFrame(gcn::Graphics* graphics); + + + protected: + /** + * Draws the button with the little down arrow. + * + * @param graphics a Graphics object to draw with. + */ + void drawButton(gcn::Graphics *graphics); + + // Add own Images. + static int instances; + static Image *buttons[2][2]; + static ImageRect skin; +}; + +#endif // end DROPDOWN_H + diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index 6be50f2c..e13493bb 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: resizegrip.cpp 3587 2007-09-20 13:24:20Z b_lindeijer $ */ #include "resizegrip.h" diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h index 04be3db3..dab720dd 100644 --- a/src/gui/widgets/resizegrip.h +++ b/src/gui/widgets/resizegrip.h @@ -18,7 +18,7 @@ * 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$ + * $Id: resizegrip.h 3270 2007-04-15 01:22:17Z b_lindeijer $ */ #ifndef _TMW_RESIZEGRIP_H diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 4ce167cd..4f94b3fb 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: window.cpp 4207 2008-04-29 09:10:43Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/window.h b/src/gui/window.h index f88e5c01..8f288991 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -18,7 +18,7 @@ * 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$ + * $Id: window.h 4207 2008-04-29 09:10:43Z b_lindeijer $ */ #ifndef _TMW_WINDOW_H__ diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index d10c519c..0a0a0a55 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -18,7 +18,7 @@ * 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$ + * $Id: windowcontainer.cpp 3754 2007-11-20 15:19:50Z b_lindeijer $ */ #include <algorithm> diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h index df255f84..294c855b 100644 --- a/src/gui/windowcontainer.h +++ b/src/gui/windowcontainer.h @@ -18,7 +18,7 @@ * 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$ + * $Id: windowcontainer.h 2884 2006-12-04 11:20:54Z b_lindeijer $ */ #ifndef _TMW_WINDOWCONTAINER_H_ |