diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-05-01 14:35:41 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-05-01 14:35:41 -0600 |
commit | 6a7d3f9343f29bd9b46f3bbac917aa190b42b14d (patch) | |
tree | 6de65bfdc540ea9ea1a065b013179f02a968d35d /src | |
parent | b6fb2326ffa687f6028d991e2d6203b3f2a92c5a (diff) | |
download | mana-6a7d3f9343f29bd9b46f3bbac917aa190b42b14d.tar.gz mana-6a7d3f9343f29bd9b46f3bbac917aa190b42b14d.tar.bz2 mana-6a7d3f9343f29bd9b46f3bbac917aa190b42b14d.tar.xz mana-6a7d3f9343f29bd9b46f3bbac917aa190b42b14d.zip |
Merge the NPC dialogs into one
Also add support for the new TMWServ NPC packets
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/Makefile.am | 10 | ||||
-rw-r--r-- | src/game.cpp | 44 | ||||
-rw-r--r-- | src/gui/npcintegerdialog.cpp | 150 | ||||
-rw-r--r-- | src/gui/npcintegerdialog.h | 96 | ||||
-rw-r--r-- | src/gui/npclistdialog.cpp | 150 | ||||
-rw-r--r-- | src/gui/npclistdialog.h | 96 | ||||
-rw-r--r-- | src/gui/npcstringdialog.cpp | 110 | ||||
-rw-r--r-- | src/gui/npcstringdialog.h | 80 | ||||
-rw-r--r-- | src/gui/npctextdialog.cpp | 138 | ||||
-rw-r--r-- | src/gui/npctextdialog.h | 113 | ||||
-rw-r--r-- | src/gui/setup.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 24 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 7 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 7 | ||||
-rw-r--r-- | src/net/ea/npchandler.cpp | 49 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 12 | ||||
-rw-r--r-- | src/net/tmwserv/npchandler.cpp | 48 | ||||
-rw-r--r-- | src/net/tmwserv/npchandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwserv/playerhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/tmwserv/protocol.h | 5 | ||||
-rw-r--r-- | src/npc.cpp | 1 |
22 files changed, 111 insertions, 1049 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c59388b..dd96abf6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -161,16 +161,10 @@ SET(SRCS gui/minimap.h gui/ministatus.cpp gui/ministatus.h - gui/npcintegerdialog.cpp - gui/npcintegerdialog.h - gui/npclistdialog.cpp - gui/npclistdialog.h + gui/npcdialog.cpp + gui/npcdialog.h gui/npcpostdialog.cpp gui/npcpostdialog.h - gui/npcstringdialog.cpp - gui/npcstringdialog.h - gui/npctextdialog.cpp - gui/npctextdialog.h gui/okdialog.cpp gui/okdialog.h gui/palette.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c22fd91d..aa6753f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,16 +114,10 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/minimap.h \ gui/ministatus.cpp \ gui/ministatus.h \ - gui/npctextdialog.cpp \ - gui/npctextdialog.h \ - gui/npcintegerdialog.cpp \ - gui/npcintegerdialog.h \ - gui/npclistdialog.cpp \ - gui/npclistdialog.h \ + gui/npcdialog.cpp \ + gui/npcdialog.h \ gui/npcpostdialog.cpp \ gui/npcpostdialog.h \ - gui/npcstringdialog.cpp \ - gui/npcstringdialog.h \ gui/okdialog.cpp \ gui/okdialog.h \ gui/palette.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 1ccc46e7..4cbab23b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -56,10 +56,7 @@ #include "gui/menuwindow.h" #include "gui/minimap.h" #include "gui/ministatus.h" -#include "gui/npcintegerdialog.h" -#include "gui/npclistdialog.h" -#include "gui/npcstringdialog.h" -#include "gui/npctextdialog.h" +#include "gui/npcdialog.h" #include "gui/okdialog.h" #include "gui/sdlinput.h" #include "gui/sell.h" @@ -125,10 +122,6 @@ BuySellDialog *buySellDialog; #endif InventoryWindow *inventoryWindow; EmoteWindow *emoteWindow; -NpcIntegerDialog *npcIntegerDialog; -NpcListDialog *npcListDialog; -NpcTextDialog *npcTextDialog; -NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; PartyWindow *partyWindow; #ifdef TMWSERV_SUPPORT @@ -136,6 +129,7 @@ BuddyWindow *buddyWindow; GuildWindow *guildWindow; MagicDialog *magicDialog; #endif +NpcDialog *npcDialog; NpcPostDialog *npcPostDialog; StorageWindow *storageWindow; Minimap *minimap; @@ -215,10 +209,6 @@ static void createGuiWindows() buyDialog = new BuyDialog; sellDialog = new SellDialog; tradeWindow = new TradeWindow; - npcTextDialog = new NpcTextDialog; - npcIntegerDialog = new NpcIntegerDialog; - npcListDialog = new NpcListDialog; - npcStringDialog = new NpcStringDialog; partyWindow = new PartyWindow; #ifdef TMWSERV_SUPPORT magicDialog = new MagicDialog; @@ -229,6 +219,7 @@ static void createGuiWindows() buySellDialog = new BuySellDialog; equipmentWindow = new EquipmentWindow; #endif + npcDialog = new NpcDialog; npcPostDialog = new NpcPostDialog; storageWindow = new StorageWindow; menuWindow = new MenuWindow; @@ -274,11 +265,8 @@ static void destroyGuiWindows() #endif delete inventoryWindow; delete emoteWindow; - delete npcIntegerDialog; - delete npcListDialog; - delete npcTextDialog; - delete npcStringDialog; delete partyWindow; + delete npcDialog; delete npcPostDialog; #ifdef TMWSERV_SUPPORT delete magicDialog; @@ -573,22 +561,9 @@ void Game::handleInput() else if (setupWindow->isVisible() && keyboard.isKeyActive(keyboard.KEY_OK)) setupWindow->action(gcn::ActionEvent(NULL, "cancel")); - // Submits the text and proceeds to the next dialog - else if (npcStringDialog->isVisible() && + else if (npcDialog->isVisible() && keyboard.isKeyActive(keyboard.KEY_OK)) - npcStringDialog->action(gcn::ActionEvent(NULL, "ok")); - // Proceed to the next dialog option, or close the window - else if (npcTextDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) - npcTextDialog->action(gcn::ActionEvent(NULL, "ok")); - // Choose the currently highlighted dialogue option - else if (npcListDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) - npcListDialog->action(gcn::ActionEvent(NULL, "ok")); - // Submits the text and proceeds to the next dialog - else if (npcIntegerDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) - npcIntegerDialog->action(gcn::ActionEvent(NULL, "ok")); + npcDialog->action(gcn::ActionEvent(NULL, "ok")); /* else if (guildWindow->isVisible()) { @@ -676,8 +651,8 @@ void Game::handleInput() default: break; } - if (keyboard.isEnabled() && !chatWindow->isInputFocused() - && !npcStringDialog->isInputFocused()) + if (keyboard.isEnabled() && + !chatWindow->isInputFocused() && !npcDialog->isInputFocused()) { const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); @@ -995,8 +970,7 @@ void Game::handleInput() // Talk to the nearest NPC if 't' pressed if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) { - if (!npcTextDialog->isVisible() && !npcListDialog->isVisible() && - !npcStringDialog->isVisible() && !npcIntegerDialog->isVisible()) + if (!npcDialog->isVisible()) { Being *target = player_node->getTarget(); diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp deleted file mode 100644 index 41b6985c..00000000 --- a/src/gui/npcintegerdialog.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/npcintegerdialog.h" - -#include "gui/npctextdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/inttextfield.h" -#include "gui/widgets/layout.h" - -#include "npc.h" - -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" - -NpcIntegerDialog::NpcIntegerDialog() - : Window(_("NPC Number Request")) -{ - setWindowName("NPCInteger"); - mValueField = new IntTextField; - - setDefaultSize(175, 75, ImageRect::CENTER); - - mDecButton = new Button("-", "decvalue", this); - mIncButton = new Button("+", "incvalue", this); - gcn::Button *okButton = new Button(_("OK"), "ok", this); - gcn::Button *cancelButton = new Button(_("Cancel"), "cancel", this); - gcn::Button *resetButton = new Button(_("Reset"), "reset", this); - - mDecButton->adjustSize(); - mDecButton->setWidth(mIncButton->getWidth()); - - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, mDecButton); - place(1, 0, mValueField, 3); - place(4, 0, mIncButton); - place.getCell().matchColWidth(1, 0); - place = getPlacer(0, 1); - place(0, 0, resetButton); - place(2, 0, cancelButton); - place(3, 0, okButton); - reflowLayout(175, 0); - - center(); - setDefaultSize(); - loadWindowState(); -} - -void NpcIntegerDialog::setRange(int min, int max) -{ - mValueField->setRange(min, max); -} - -int NpcIntegerDialog::getValue() -{ - return mValueField->getValue(); -} - -void NpcIntegerDialog::reset() -{ - mValueField->reset(); -} - -void NpcIntegerDialog::action(const gcn::ActionEvent &event) -{ - bool finish = false; - - if (event.getId() == "ok") - { - finish = true; - npcTextDialog->addText(strprintf("\n> %d\n", mValueField->getValue())); - } - else if (event.getId() == "cancel") - { - finish = true; - mValueField->reset(); - npcTextDialog->addText(_("\n> Cancel\n")); - } - else if (event.getId() == "decvalue") - { - mValueField->setValue(mValueField->getValue() - 1); - } - else if (event.getId() == "incvalue") - { - mValueField->setValue(mValueField->getValue() + 1); - } - else if (event.getId() == "reset") - { - mValueField->reset(); - } - - if (finish) - { - setVisible(false); - NPC::isTalking = false; - - Net::getNpcHandler()->integerInput(current_npc, mValueField->getValue()); - - mValueField->reset(); - } -} - -void NpcIntegerDialog::setDefaultValue(int value) -{ - mValueField->setDefaultValue(value); -} - -bool NpcIntegerDialog::isInputFocused() -{ - return mValueField->isFocused(); -} - -void NpcIntegerDialog::requestFocus() -{ - mValueField->requestFocus(); -} - -void NpcIntegerDialog::setVisible(bool visible) -{ - if (visible) { - npcTextDialog->setVisible(true); - requestFocus(); - } - - Window::setVisible(visible); -} diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h deleted file mode 100644 index 835372f7..00000000 --- a/src/gui/npcintegerdialog.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef GUI_NPCINTEGERDIALOG_H -#define GUI_NPCINTEGERDIALOG_H - -#include "gui/widgets/window.h" - -#include <guichan/actionlistener.hpp> - -class IntTextField; - -/** - * The npc integer input dialog. - * - * \ingroup Interface - */ -class NpcIntegerDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - NpcIntegerDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Returns the current value. - */ - int getValue(); - - /** - * Resets the integer input field. - */ - void reset(); - - /** - * Prepares the NPC dialog. - * - * @param min The minimum value to allow - * @param max The maximum value to allow - */ - void setRange(int min, int max); - - /** - * Sets the default value. - * - * @param value The new default value - */ - void setDefaultValue(int value); - - /** - * Checks whether NpcStringDialog is Focused or not. - */ - bool isInputFocused(); - - /** - * Requests the textfield to take focus for input. - */ - void requestFocus(); - - void setVisible(bool visible); - - private: - gcn::Button *mDecButton; - gcn::Button *mIncButton; - IntTextField *mValueField; -}; - -extern NpcIntegerDialog *npcIntegerDialog; - -#endif // GUI_NPCINTEGERDIALOG_H diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp deleted file mode 100644 index 65e4263e..00000000 --- a/src/gui/npclistdialog.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/npclistdialog.h" - -#include "gui/npctextdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/listbox.h" -#include "gui/widgets/scrollarea.h" - -#include "npc.h" - -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" - -#include <sstream> - -NpcListDialog::NpcListDialog() - : Window("NPC") -{ - setWindowName("NPCList"); - setResizable(true); - - setMinWidth(200); - setMinHeight(150); - - setDefaultSize(260, 200, ImageRect::CENTER); - - mItemList = new ListBox(this); - mItemList->setWrappingEnabled(true); - - gcn::ScrollArea *scrollArea = new ScrollArea(mItemList); - - gcn::Button *okButton = new Button(_("OK"), "ok", this); - gcn::Button *cancelButton = new Button(_("Cancel"), "cancel", this); - - setContentSize(260, 175); - scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - - place(0, 0, scrollArea, 5).setPadding(3); - place(3, 1, cancelButton); - place(4, 1, okButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - center(); - loadWindowState(); -} - -int NpcListDialog::getNumberOfElements() -{ - return mItems.size(); -} - -std::string NpcListDialog::getElementAt(int i) -{ - return mItems[i]; -} - -void NpcListDialog::addItem(const std::string &item) -{ - mItems.push_back(item); -} - -void NpcListDialog::parseItems(const std::string &itemString) -{ - std::istringstream iss(itemString); - - std::string tmp; - while (getline(iss, tmp, ':')) - mItems.push_back(tmp); -} - -void NpcListDialog::reset() -{ - NPC::isTalking = false; - mItemList->setSelected(-1); - mItems.clear(); -} - -void NpcListDialog::action(const gcn::ActionEvent &event) -{ - int choice = 0; - if (event.getId() == "ok") - { - // Send the selected index back to the server - int selectedIndex = mItemList->getSelected(); - - if (selectedIndex > -1) - { - choice = selectedIndex + 1; - npcTextDialog->addText(strprintf("\n> \"%s\"\n", - mItems[selectedIndex].c_str())); - } - } - else if (event.getId() == "cancel") - { - choice = 0xff; // 0xff means cancel - npcTextDialog->addText(_("\n> Cancel\n")); - npcTextDialog->showCloseButton(); - } - - if (choice) - { - setVisible(false); - saveWindowState(); - reset(); - - Net::getNpcHandler()->listInput(current_npc, choice); - } -} - -void NpcListDialog::setVisible(bool visible) -{ - if (visible) { - npcTextDialog->setVisible(true); - } - - Window::setVisible(visible); -} - -void NpcListDialog::requestFocus() -{ - mItemList->requestFocus(); - mItemList->setSelected(0); -} diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h deleted file mode 100644 index b0279e11..00000000 --- a/src/gui/npclistdialog.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef GUI_NPCLISTDIALOG_H -#define GUI_NPCLISTDIALOG_H - -#include "gui/widgets/window.h" - -#include <guichan/actionlistener.hpp> -#include <guichan/listmodel.hpp> - -#include <vector> - -/** - * The npc list dialog. - * - * \ingroup Interface - */ -class NpcListDialog : public Window, public gcn::ActionListener, - public gcn::ListModel -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - NpcListDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Returns the number of items in the choices list. - */ - int getNumberOfElements(); - - /** - * Returns the name of item number i of the choices list. - */ - std::string getElementAt(int i); - - /** - * Adds an item to the option list. - */ - void addItem(const std::string &); - - /** - * Fills the options list for an NPC dialog. - * - * @param itemString A string with the options separated with colons. - */ - void parseItems(const std::string &itemString); - - /** - * Resets the list by removing all items. - */ - void reset(); - - void setVisible(bool visible); - - /** - * Requests the listbox to take focus for input and sets window width - * to the last known setting. - */ - void requestFocus(); - - private: - gcn::ListBox *mItemList; - - std::vector<std::string> mItems; -}; - -extern NpcListDialog *npcListDialog; - -#endif // GUI_NPCLISTDIALOG_H diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp deleted file mode 100644 index e5767c5f..00000000 --- a/src/gui/npcstringdialog.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/npcstringdialog.h" - -#include "gui/npctextdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/textfield.h" - -#include "npc.h" - -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" - -NpcStringDialog::NpcStringDialog() - : Window(_("NPC Text Request")) -{ - setWindowName("NPCString"); - mValueField = new TextField(""); - - setDefaultSize(175, 75, ImageRect::CENTER); - - gcn::Button *okButton = new Button(_("OK"), "ok", this); - gcn::Button *cancelButton = new Button(_("Cancel"), "cancel", this); - - place(0, 0, mValueField, 3); - place(1, 1, cancelButton); - place(2, 1, okButton); - reflowLayout(175, 0); - - center(); - setDefaultSize(); - loadWindowState(); -} - -std::string NpcStringDialog::getValue() -{ - return mValueField->getText(); -} - -void NpcStringDialog::setValue(const std::string &value) -{ - mValueField->setText(value); - mDefault = value; -} - -void NpcStringDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "cancel") - { - mValueField->setText(mDefault); - npcTextDialog->addText(_("\n> Cancel\n")); - } - else - { - npcTextDialog->addText(strprintf("\n> \"%s\"\n", - mValueField->getText().c_str())); - } - - setVisible(false); - NPC::isTalking = false; - - std::string text = mValueField->getText(); - mValueField->setText(""); - - Net::getNpcHandler()->stringInput(current_npc, text); -} - -bool NpcStringDialog::isInputFocused() -{ - return mValueField->isFocused(); -} - -void NpcStringDialog::requestFocus() -{ - mValueField->requestFocus(); -} - -void NpcStringDialog::setVisible(bool visible) -{ - if (visible) { - npcTextDialog->setVisible(true); - requestFocus(); - } - - Window::setVisible(visible); -} diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h deleted file mode 100644 index e6bbd7ba..00000000 --- a/src/gui/npcstringdialog.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef GUI_NPCSTRINGDIALOG_H -#define GUI_NPCSTRINGDIALOG_H - -#include "gui/widgets/window.h" - -#include <guichan/actionlistener.hpp> - -/** - * The npc integer input dialog. - * - * \ingroup Interface - */ -class NpcStringDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - NpcStringDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Returns the current value. - */ - std::string getValue(); - - /** - * Chnages the current value. - * - * @param value The new value - */ - void setValue(const std::string &value); - - /** - * Checks whether NpcStringDialog is Focused or not. - */ - bool isInputFocused(); - - /** - * Requests the textfield to take focus for input. - */ - void requestFocus(); - - void setVisible(bool visible); - - private: - gcn::TextField *mValueField; - std::string mDefault; -}; - -extern NpcStringDialog *npcStringDialog; - -#endif // GUI_NPCSTRINGDIALOG_H diff --git a/src/gui/npctextdialog.cpp b/src/gui/npctextdialog.cpp deleted file mode 100644 index 849c94ec..00000000 --- a/src/gui/npctextdialog.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/npctextdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/textbox.h" - -#include "npc.h" - -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" - -NpcTextDialog::NpcTextDialog() - : Window(_("NPC")) - , mState(NPC_TEXT_STATE_WAITING) -{ - setWindowName("NPCText"); - setResizable(true); - - setMinWidth(200); - setMinHeight(150); - - setDefaultSize(260, 200, ImageRect::CENTER); - - mTextBox = new TextBox; - mTextBox->setEditable(false); - mTextBox->setOpaque(false); - - mScrollArea = new ScrollArea(mTextBox); - mButton = new Button(_("Waiting for server"), "ok", this); - - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); - - place(0, 0, mScrollArea, 5).setPadding(3); - place(4, 1, mButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - center(); - loadWindowState(); -} - -void NpcTextDialog::clearText() -{ - NPC::isTalking = false; - setText(""); -} - -void NpcTextDialog::setText(const std::string &text) -{ - mText = text; - mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15); -} - -void NpcTextDialog::addText(const std::string &text) -{ - setText(mText + text + "\n"); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); -} - -void NpcTextDialog::showNextButton() -{ - mButton->setCaption(_("Next")); - mState = NPC_TEXT_STATE_NEXT; - mButton->setEnabled(true); -} - -void NpcTextDialog::showCloseButton() -{ - mButton->setCaption(_("Close")); - mState = NPC_TEXT_STATE_CLOSE; - mButton->setEnabled(true); -} - -void NpcTextDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "ok") - { - if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - nextDialog(); - addText("\n> Next\n"); - } else if (mState == NPC_TEXT_STATE_CLOSE || - (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { - setText(""); - if (current_npc) nextDialog(); - setVisible(false); - current_npc = 0; - NPC::isTalking = false; - } else return; - } - else return; - - mButton->setEnabled(false); - mButton->setCaption(_("Waiting for server")); - mState = NPC_TEXT_STATE_WAITING; -} - -void NpcTextDialog::nextDialog(int npcID) -{ - Net::getNpcHandler()->nextDialog(npcID); -} - -void NpcTextDialog::closeDialog(int npcID) -{ - Net::getNpcHandler()->closeDialog(npcID); -} - -void NpcTextDialog::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - setText(mText); -} diff --git a/src/gui/npctextdialog.h b/src/gui/npctextdialog.h deleted file mode 100644 index ad32fdf4..00000000 --- a/src/gui/npctextdialog.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef NPC_TEXT_H -#define NPC_TEXT_H - -#include "gui/widgets/window.h" - -#include "npc.h" - -#include <guichan/actionlistener.hpp> - -#include <string> - -class TextBox; - -/** - * The npc text dialog. - * - * \ingroup Interface - */ -class NpcTextDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - NpcTextDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Clears the text shown in the dialog. - */ - void clearText(); - - /** - * Sets the text shows in the dialog. - * - * @param string The new text. - */ - void setText(const std::string &string); - - /** - * Adds the text to the text shows in the dialog. Also adds a newline - * to the end. - * - * @param string The text to add. - */ - void addText(const std::string &string); - - void showNextButton(); - - void showCloseButton(); - - /** - * Notifies the server that the client has performed a next action. - */ - void nextDialog(int npcID = current_npc); - - /** - * Notifies the server that the client has performed a close action. - */ - void closeDialog(int npcID = current_npc); - - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - - private: - gcn::ScrollArea *mScrollArea; - TextBox *mTextBox; - gcn::Button *mButton; - - std::string mText; - - enum NPCTextState { - NPC_TEXT_STATE_WAITING, - NPC_TEXT_STATE_NEXT, - NPC_TEXT_STATE_CLOSE - }; - NPCTextState mState; -}; - -extern NpcTextDialog *npcTextDialog; - -#endif // NPC_TEXT_H diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6e5e7809..5dbce81b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -146,8 +146,6 @@ void Setup::action(const gcn::ActionEvent &event) #endif inventoryWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); - npcTextDialog->resetToDefaultSize(); - npcStringDialog->resetToDefaultSize(); skillDialog->resetToDefaultSize(); minimap->resetToDefaultSize(); equipmentWindow->resetToDefaultSize(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 7de09994..87051686 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -687,6 +687,19 @@ Layout &Window::getLayout() return *mLayout; } +void Window::clearLayout() +{ + clear(); // This removes widgets from the container + + while (!mWidgets.empty()) + delete mWidgets.front(); + + if (!mLayout) + delete mLayout; + mLayout = new Layout; + +} + LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) { add(wg); @@ -707,6 +720,17 @@ void Window::reflowLayout(int w, int h) setContentSize(w, h); } +void Window::redraw() +{ + if (mLayout) + { + const gcn::Rectangle area = getChildrenArea(); + int w = area.width; + int h = area.height; + mLayout->reflow(w, h); + } +} + void Window::center() { setLocationRelativeTo(getParent()); diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index aa9872d3..11193654 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -95,6 +95,8 @@ class Window : public gcn::Window, gcn::WidgetListener */ void setResizable(bool resize); + void redraw(); + /** * Called whenever the widget changes size. */ @@ -293,6 +295,11 @@ class Window : public gcn::Window, gcn::WidgetListener Layout &getLayout(); /** + * Clears the Window's layout (useful for redesigning the window) + */ + void clearLayout(); + + /** * Computes the position of the widgets according to the current * layout. Resizes the window so that the layout fits. Deletes the * layout. diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 65d19040..1f5f79c7 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -35,12 +35,8 @@ #include "npc.h" #include "playerrelations.h" -#include "gui/npctextdialog.h" - #include <iostream> -extern NpcTextDialog *npcTextDialog; - namespace EAthena { const int EMOTION_TIME = 150; /**< Duration of emotion icon */ @@ -246,9 +242,6 @@ void BeingHandler::handleMessage(MessageIn &msg) // A being should be removed or has died id = msg.readInt32(); - if (id == current_npc) - npcTextDialog->showCloseButton(); - dstBeing = beingManager->findBeing(id); if (!dstBeing) diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp index 5c41c380..16137476 100644 --- a/src/net/ea/npchandler.cpp +++ b/src/net/ea/npchandler.cpp @@ -32,10 +32,7 @@ #include "localplayer.h" #include "npc.h" -#include "gui/npctextdialog.h" -#include "gui/npcintegerdialog.h" -#include "gui/npclistdialog.h" -#include "gui/npcstringdialog.h" +#include "gui/npcdialog.h" #include <SDL_types.h> @@ -68,57 +65,58 @@ void NpcHandler::handleMessage(MessageIn &msg) msg.readInt16(); // length current_npc = msg.readInt32(); player_node->setAction(LocalPlayer::STAND); - npcListDialog->parseItems(msg.readString(msg.getLength() - 8)); - npcListDialog->setVisible(true); - npcListDialog->requestFocus(); + npcDialog->setNpc(current_npc); + npcDialog->choiceRequest(); + npcDialog->parseListItems(msg.readString(msg.getLength() - 8)); + npcDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: msg.readInt16(); // length current_npc = msg.readInt32(); player_node->setAction(LocalPlayer::STAND); - npcTextDialog->addText(msg.readString(msg.getLength() - 8)); - npcTextDialog->setVisible(true); - npcTextDialog->requestFocus(); + npcDialog->setNpc(current_npc); + npcDialog->addText(msg.readString(msg.getLength() - 8)); + npcDialog->setVisible(true); break; case SMSG_NPC_CLOSE: id = msg.readInt32(); // If we're talking to that NPC, show the close button if (id == current_npc) - npcTextDialog->showCloseButton(); + npcDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - npcTextDialog->closeDialog(id); + npcDialog->closeDialog(); break; + /* Note: with the new dialog, we automaticilly assume "Next" case SMSG_NPC_NEXT: id = msg.readInt32(); // If we're talking to that NPC, show the next button - if (id == current_npc) - npcTextDialog->showNextButton(); + if (id == current_npc && dialog) + dialog->showNextButton(); // Otherwise, move on as an empty dialog doesn't help - else - npcTextDialog->nextDialog(id); + else if (dialog) + nextDialog(id); break; - + */ case SMSG_NPC_INT_INPUT: // Request for an integer current_npc = msg.readInt32(); player_node->setAction(LocalPlayer::STAND); - npcIntegerDialog->setRange(0, 2147483647); - npcIntegerDialog->setDefaultValue(0); - npcIntegerDialog->setVisible(true); - npcIntegerDialog->requestFocus(); + npcDialog->setNpc(current_npc); + npcDialog->integerRequest(0); + npcDialog->setVisible(true); break; case SMSG_NPC_STR_INPUT: // Request for a string current_npc = msg.readInt32(); player_node->setAction(LocalPlayer::STAND); - npcStringDialog->setValue(""); - npcStringDialog->setVisible(true); - npcStringDialog->requestFocus(); + npcDialog->setNpc(current_npc); + npcDialog->textRequest(""); + npcDialog->setVisible(true); break; } } @@ -140,6 +138,8 @@ void NpcHandler::closeDialog(int npcId) { MessageOut outMsg(CMSG_NPC_CLOSE); outMsg.writeInt32(npcId); + npcDialog->setText(""); + npcDialog->setVisible(false); } void NpcHandler::listInput(int npcId, int value) @@ -158,6 +158,7 @@ void NpcHandler::integerInput(int npcId, int value) void NpcHandler::stringInput(int npcId, const std::string &value) { + printf("I got a %s", value.c_str()); MessageOut outMsg(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(value.length() + 9); outMsg.writeInt32(npcId); diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index ef6edc87..3f8fbc09 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -35,10 +35,6 @@ #include "gui/buy.h" #include "gui/buysell.h" #include "gui/gui.h" -#include "gui/npctextdialog.h" -#include "gui/npcintegerdialog.h" -#include "gui/npclistdialog.h" -#include "gui/npcstringdialog.h" #include "gui/okdialog.h" #include "gui/sell.h" #include "gui/skill.h" @@ -81,14 +77,6 @@ namespace { { player_node->revive(); deathNotice = NULL; - npcIntegerDialog->reset(); - npcIntegerDialog->setVisible(false); - npcListDialog->reset(); - npcListDialog->setVisible(false); - npcStringDialog->setValue(""); - npcStringDialog->setVisible(false); - npcTextDialog->clearText(); - npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); diff --git a/src/net/tmwserv/npchandler.cpp b/src/net/tmwserv/npchandler.cpp index 20a13ec2..9447e2f8 100644 --- a/src/net/tmwserv/npchandler.cpp +++ b/src/net/tmwserv/npchandler.cpp @@ -33,9 +33,8 @@ #include "beingmanager.h" #include "npc.h" -#include "gui/npclistdialog.h" #include "gui/npcpostdialog.h" -#include "gui/npctextdialog.h" +#include "gui/npcdialog.h" Net::NpcHandler *npcHandler; @@ -48,6 +47,7 @@ NpcHandler::NpcHandler() GPMSG_NPC_POST, GPMSG_NPC_MESSAGE, GPMSG_NPC_ERROR, + GPMSG_NPC_CLOSE, 0 }; handledMessages = _messages; @@ -63,31 +63,43 @@ void NpcHandler::handleMessage(MessageIn &msg) } current_npc = being->getId(); + npcDialog->setNpc(current_npc); switch (msg.getId()) { case GPMSG_NPC_CHOICE: - npcListDialog->reset(); + npcDialog->choiceRequest(); while (msg.getUnreadLength()) { - npcListDialog->addItem(msg.readString()); + npcDialog->addChoice(msg.readString()); } - npcListDialog->setVisible(true); break; + case GPMSG_NPC_NUMBER: + { + int min_num = msg.readInt32(); + int max_num = msg.readInt32(); + npcDialog->integerRequest(msg.readInt32(), min_num, max_num); + break; + } + case GPMSG_NPC_POST: - npcTextDialog->setVisible(false); + npcDialog->setVisible(false); npcPostDialog->clear(); npcPostDialog->setVisible(true); break; case GPMSG_NPC_ERROR: current_npc = NULL; + break; + case GPMSG_NPC_MESSAGE: - npcTextDialog->addText(msg.readString(msg.getUnreadLength())); - npcListDialog->setVisible(false); - npcTextDialog->setVisible(true); - npcPostDialog->setVisible(false); + npcDialog->addText(msg.readString(msg.getUnreadLength())); + npcDialog->setVisible(true); + break; + + case GPMSG_NPC_CLOSE: + npcDialog->showCloseButton(); break; } } @@ -108,7 +120,11 @@ void NpcHandler::nextDialog(int npcId) void NpcHandler::closeDialog(int npcId) { - // TODO + MessageOut msg(PGMSG_NPC_TALK_NEXT); + msg.writeInt16(npcId); + Net::GameServer::connection->send(msg); + npcDialog->setVisible(false); + npcDialog->setText(""); } void NpcHandler::listInput(int npcId, int value) @@ -121,12 +137,18 @@ void NpcHandler::listInput(int npcId, int value) void NpcHandler::integerInput(int npcId, int value) { - // TODO + MessageOut msg(PGMSG_NPC_NUMBER); + msg.writeInt16(npcId); + msg.writeInt32(value); + Net::GameServer::connection->send(msg); } void NpcHandler::stringInput(int npcId, const std::string &value) { - // TODO + MessageOut msg(PGMSG_NPC_STRING); + msg.writeInt16(npcId); + msg.writeString(value); + Net::GameServer::connection->send(msg); } void NpcHandler::sendLetter(int npcId, const std::string &recipient, diff --git a/src/net/tmwserv/npchandler.h b/src/net/tmwserv/npchandler.h index 2c405e16..2bf953c0 100644 --- a/src/net/tmwserv/npchandler.h +++ b/src/net/tmwserv/npchandler.h @@ -25,6 +25,8 @@ #include "net/messagehandler.h" #include "net/npchandler.h" +#include <list> + namespace TmwServ { class NpcHandler : public MessageHandler, public Net::NpcHandler diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index e2b5cec4..c7769ede 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -40,8 +40,6 @@ #include "gui/buy.h" #include "gui/chat.h" #include "gui/gui.h" -#include "gui/npclistdialog.h" -#include "gui/npctextdialog.h" #include "gui/okdialog.h" #include "gui/sell.h" #include "gui/skill.h" @@ -51,8 +49,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern NpcListDialog *npcListDialog; -extern NpcTextDialog *npcTextDialog; extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; @@ -87,8 +83,6 @@ namespace { { player_node->revive(); deathNotice = NULL; - npcListDialog->setVisible(false); - npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); current_npc = 0; diff --git a/src/net/tmwserv/protocol.h b/src/net/tmwserv/protocol.h index fc52bd57..7fa3b372 100644 --- a/src/net/tmwserv/protocol.h +++ b/src/net/tmwserv/protocol.h @@ -120,9 +120,14 @@ enum { GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }* PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount GPMSG_NPC_ERROR = 0x02B8, // B error + GPMSG_NPC_CLOSE = 0x02B9, // W being id GPMSG_NPC_POST = 0x02D0, // W being id PGMSG_NPC_POST_SEND = 0x02D1, // S name, S text, W item id GPMSG_NPC_POST_GET = 0x02D2, // W being id, { S name, S text, W item id } + PGMSG_NPC_NUMBER = 0x02D3, // W being id, L number + PGMSG_NPC_STRING = 0x02D4, // W being id, S string + GPMSG_NPC_NUMBER = 0x02D5, // W being id, L max, L min, L default + GPMSG_NPC_STRING = 0x02D6, // W being id PGMSG_TRADE_REQUEST = 0x02C0, // W being id GPMSG_TRADE_REQUEST = 0x02C1, // W being id GPMSG_TRADE_START = 0x02C2, // - diff --git a/src/npc.cpp b/src/npc.cpp index 40a98ca0..a49ef406 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -25,7 +25,6 @@ #include "particle.h" #include "text.h" -#include "gui/npctextdialog.h" #include "gui/palette.h" #include "net/net.h" |