diff options
Diffstat (limited to 'src/gui/npclistdialog.cpp')
-rw-r--r-- | src/gui/npclistdialog.cpp | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 505912ac..968e2514 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -1,9 +1,8 @@ /* - * Aethyra + * The Mana World * Copyright (C) 2004 The Mana World Development Team * - * This file is part of Aethyra based on original code - * from The Mana World. + * 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 @@ -24,6 +23,7 @@ #include "button.h" #include "listbox.h" +#include "npc_text.h" #include "npclistdialog.h" #include "scrollarea.h" @@ -32,14 +32,26 @@ #include "../npc.h" #include "../net/messageout.h" -#include "../net/protocol.h" +#ifdef TMWSERV_SUPPORT +#include "../net/tmwserv/gameserver/player.h" +#else +#include "../net/ea/protocol.h" +#endif #include "../utils/gettext.h" - -NpcListDialog::NpcListDialog(Network *network): - Window("NPC"), mNetwork(network) +#include "../utils/strprintf.h" + +#ifdef TMWSERV_SUPPORT +NpcListDialog::NpcListDialog() +#else +NpcListDialog::NpcListDialog(Network *network) +#endif + : Window("NPC") +#ifdef EATHENA_SUPPORT + , mNetwork(network) +#endif { - setWindowName(_("NPC")); + setWindowName("NPCList"); setResizable(true); setMinWidth(200); @@ -50,10 +62,10 @@ NpcListDialog::NpcListDialog(Network *network): mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); - scrollArea = new ScrollArea(mItemList); + gcn::ScrollArea *scrollArea = new ScrollArea(mItemList); - okButton = new Button(_("OK"), "ok", this); - cancelButton = new Button(_("Cancel"), "cancel", this); + 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); @@ -65,6 +77,7 @@ NpcListDialog::NpcListDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } @@ -78,6 +91,11 @@ 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); @@ -89,7 +107,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { - NPC::mTalking = false; + NPC::isTalking = false; mItemList->setSelected(-1); mItems.clear(); } @@ -97,18 +115,23 @@ void NpcListDialog::reset() 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) @@ -117,13 +140,25 @@ void NpcListDialog::action(const gcn::ActionEvent &event) saveWindowState(); reset(); +#ifdef TMWSERV_SUPPORT + Net::GameServer::Player::selectFromNPC(current_npc, choice); +#else MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(current_npc); outMsg.writeInt8(choice); +#endif + } +} - current_npc = 0; +void NpcListDialog::setVisible(bool visible) +{ + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); } + + Window::setVisible(visible); } void NpcListDialog::requestFocus() |