From fc1de272d5e3d9f5666ecd792d770b63dce7d8e4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 4 Apr 2011 04:03:47 +0300 Subject: Rename some gui class files to real class names. --- manaplus.cbp | 24 +- src/CMakeLists.txt | 20 +- src/Makefile.am | 20 +- src/actorspritemanager.cpp | 2 +- src/being.cpp | 4 +- src/client.cpp | 4 +- src/commandhandler.cpp | 4 +- src/dropshortcut.cpp | 2 +- src/game.cpp | 6 +- src/gui/botcheckerwindow.cpp | 2 +- src/gui/buy.cpp | 325 -------- src/gui/buy.h | 152 ---- src/gui/buydialog.cpp | 325 ++++++++ src/gui/buydialog.h | 152 ++++ src/gui/buysell.cpp | 138 ---- src/gui/buysell.h | 79 -- src/gui/buyselldialog.cpp | 138 ++++ src/gui/buyselldialog.h | 79 ++ src/gui/chat.cpp | 1416 --------------------------------- src/gui/chat.h | 319 -------- src/gui/chatwindow.cpp | 1416 +++++++++++++++++++++++++++++++++ src/gui/chatwindow.h | 319 ++++++++ src/gui/help.cpp | 107 --- src/gui/help.h | 77 -- src/gui/helpwindow.cpp | 107 +++ src/gui/helpwindow.h | 77 ++ src/gui/inventorywindow.cpp | 2 +- src/gui/itemamount.cpp | 433 ---------- src/gui/itemamount.h | 125 --- src/gui/itemamountwindow.cpp | 433 ++++++++++ src/gui/itemamountwindow.h | 125 +++ src/gui/killstats.cpp | 2 +- src/gui/ministatus.cpp | 2 +- src/gui/outfitwindow.cpp | 2 +- src/gui/popupmenu.cpp | 6 +- src/gui/quitdialog.cpp | 2 +- src/gui/setup_chat.cpp | 2 +- src/gui/shopwindow.cpp | 4 +- src/gui/textcommandeditor.cpp | 2 +- src/gui/trade.cpp | 2 +- src/gui/viewport.cpp | 2 +- src/gui/whoisonline.cpp | 2 +- src/gui/widgets/avatarlistbox.cpp | 2 +- src/gui/widgets/chattab.h | 2 +- src/gui/widgets/itemcontainer.cpp | 2 +- src/localplayer.cpp | 2 +- src/net/manaserv/buysellhandler.cpp | 4 +- src/net/manaserv/chathandler.cpp | 2 +- src/net/manaserv/guildhandler.cpp | 2 +- src/net/manaserv/inventoryhandler.cpp | 2 +- src/net/manaserv/playerhandler.cpp | 2 +- src/net/tmwa/buysellhandler.cpp | 4 +- src/net/tmwa/chathandler.cpp | 2 +- src/spellmanager.cpp | 2 +- src/spellshortcut.cpp | 2 +- 55 files changed, 3245 insertions(+), 3245 deletions(-) delete mode 100644 src/gui/buy.cpp delete mode 100644 src/gui/buy.h create mode 100644 src/gui/buydialog.cpp create mode 100644 src/gui/buydialog.h delete mode 100644 src/gui/buysell.cpp delete mode 100644 src/gui/buysell.h create mode 100644 src/gui/buyselldialog.cpp create mode 100644 src/gui/buyselldialog.h delete mode 100644 src/gui/chat.cpp delete mode 100644 src/gui/chat.h create mode 100644 src/gui/chatwindow.cpp create mode 100644 src/gui/chatwindow.h delete mode 100644 src/gui/help.cpp delete mode 100644 src/gui/help.h create mode 100644 src/gui/helpwindow.cpp create mode 100644 src/gui/helpwindow.h delete mode 100644 src/gui/itemamount.cpp delete mode 100644 src/gui/itemamount.h create mode 100644 src/gui/itemamountwindow.cpp create mode 100644 src/gui/itemamountwindow.h diff --git a/manaplus.cbp b/manaplus.cbp index a1558d70d..352aa6f6f 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -151,10 +151,10 @@ - - - - + + + + @@ -163,8 +163,8 @@ - - + + @@ -181,12 +181,12 @@ - - + + - - + + @@ -267,8 +267,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b2dc20bf..9a466a57d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -219,10 +219,10 @@ SET(SRCS gui/widgets/windowcontainer.h gui/beingpopup.cpp gui/beingpopup.h - gui/buy.cpp - gui/buy.h - gui/buysell.cpp - gui/buysell.h + gui/buydialog.cpp + gui/buydialog.h + gui/buyselldialog.cpp + gui/buyselldialog.h gui/changeemaildialog.cpp gui/changeemaildialog.h gui/changepassworddialog.cpp @@ -231,8 +231,8 @@ SET(SRCS gui/charselectdialog.h gui/charcreatedialog.cpp gui/charcreatedialog.h - gui/chat.cpp - gui/chat.h + gui/chatwindow.cpp + gui/chatwindow.h gui/confirmdialog.cpp gui/confirmdialog.h gui/connectiondialog.cpp @@ -247,8 +247,8 @@ SET(SRCS gui/focushandler.h gui/gui.cpp gui/gui.h - gui/help.cpp - gui/help.h + gui/helpwindow.cpp + gui/helpwindow.h gui/inventorywindow.cpp gui/inventorywindow.h gui/itempopup.cpp @@ -259,8 +259,8 @@ SET(SRCS gui/statuspopup.h gui/killstats.cpp gui/killstats.h - gui/itemamount.cpp - gui/itemamount.h + gui/itemamountwindow.cpp + gui/itemamountwindow.h gui/login.cpp gui/login.h gui/minimap.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c07f5b1ea..68393ab44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,10 +114,10 @@ manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/widgets/windowcontainer.h \ gui/beingpopup.cpp \ gui/beingpopup.h \ - gui/buy.cpp \ - gui/buy.h \ - gui/buysell.cpp \ - gui/buysell.h \ + gui/buydialog.cpp \ + gui/buydialog.h \ + gui/buyselldialog.cpp \ + gui/buyselldialog.h \ gui/changeemaildialog.cpp \ gui/changeemaildialog.h \ gui/changepassworddialog.cpp \ @@ -126,8 +126,8 @@ manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/charselectdialog.h \ gui/charcreatedialog.cpp \ gui/charcreatedialog.h \ - gui/chat.cpp \ - gui/chat.h \ + gui/chatwindow.cpp \ + gui/chatwindow.h \ gui/confirmdialog.cpp \ gui/confirmdialog.h \ gui/connectiondialog.cpp \ @@ -142,12 +142,12 @@ manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/focushandler.h \ gui/gui.cpp \ gui/gui.h \ - gui/help.cpp \ - gui/help.h \ + gui/helpwindow.cpp \ + gui/helpwindow.h \ gui/inventorywindow.cpp \ gui/inventorywindow.h \ - gui/itemamount.cpp \ - gui/itemamount.h \ + gui/itemamountwindow.cpp \ + gui/itemamountwindow.h \ gui/itempopup.cpp \ gui/itempopup.h \ gui/spellpopup.cpp \ diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 302b656d7..2dfe08ef3 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -30,7 +30,7 @@ #include "gui/widgets/chattab.h" #include "gui/killstats.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/skilldialog.h" #include "gui/viewport.h" diff --git a/src/being.cpp b/src/being.cpp index be446e0fa..659b883bc 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -41,8 +41,8 @@ #include "text.h" #include "statuseffect.h" -#include "gui/buy.h" -#include "gui/buysell.h" +#include "gui/buydialog.h" +#include "gui/buyselldialog.h" #include "gui/gui.h" #include "gui/npcdialog.h" #include "gui/npcpostdialog.h" diff --git a/src/client.cpp b/src/client.cpp index 2d5680d18..03c2fc648 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -41,8 +41,8 @@ #include "statuseffect.h" #include "units.h" -#include "gui/buy.h" -#include "gui/buysell.h" +#include "gui/buydialog.h" +#include "gui/buyselldialog.h" #include "gui/changeemaildialog.h" #include "gui/changepassworddialog.h" #include "gui/charselectdialog.h" diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 3b2f38f72..df45a4f66 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -30,8 +30,8 @@ #include "log.h" #include "main.h" -#include "gui/chat.h" -#include "gui/help.h" +#include "gui/chatwindow.h" +#include "gui/helpwindow.h" #include "gui/gui.h" #include "gui/outfitwindow.h" #include "gui/shopwindow.h" diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp index 6976f3f1f..ca68ffbc9 100644 --- a/src/dropshortcut.cpp +++ b/src/dropshortcut.cpp @@ -28,7 +28,7 @@ #include "localplayer.h" #include "playerinfo.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/widgets/chattab.h" #include "net/inventoryhandler.h" diff --git a/src/game.cpp b/src/game.cpp index bcbbefc4a..9c1e4ca0d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -48,13 +48,13 @@ #include "sound.h" #include "gui/botcheckerwindow.h" -#include "gui/buysell.h" -#include "gui/chat.h" +#include "gui/buyselldialog.h" +#include "gui/chatwindow.h" #include "gui/confirmdialog.h" #include "gui/debugwindow.h" #include "gui/equipmentwindow.h" #include "gui/gui.h" -#include "gui/help.h" +#include "gui/helpwindow.h" #include "gui/inventorywindow.h" #include "gui/killstats.h" #include "gui/minimap.h" diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index c2cfab2f6..c110e880e 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -36,7 +36,7 @@ #include "gui/widgets/table.h" #include "actorspritemanager.h" -#include "chat.h" +#include "chatwindow.h" #include "configuration.h" #include "localplayer.h" #include "main.h" diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp deleted file mode 100644 index c413fdffc..000000000 --- a/src/gui/buy.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "gui/buy.h" - -#include "shopitem.h" -#include "units.h" - -#include "gui/setup.h" -#include "gui/trade.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/shopitems.h" -#include "gui/widgets/shoplistbox.h" -#include "gui/widgets/slider.h" - -#include "shopitem.h" -#include "units.h" - -#include "net/buysellhandler.h" -#include "net/net.h" -#include "net/npchandler.h" - -#include "resources/iteminfo.h" - -#include "utils/gettext.h" -#include "utils/stringutils.h" - -BuyDialog::DialogList BuyDialog::instances; - -BuyDialog::BuyDialog(int npcId): - Window(_("Buy")), - mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), mNick("") -{ - init(); -} - -BuyDialog::BuyDialog(std::string nick): - Window(_("Buy")), - mNpcId(-1), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(nick) -{ - init(); - logger->log("BuyDialog::BuyDialog nick:" + mNick); -} - -void BuyDialog::init() -{ - setWindowName("Buy"); - setResizable(true); - setCloseButton(true); - setMinWidth(260); - setMinHeight(230); - setDefaultSize(260, 230, ImageRect::CENTER); - - mShopItems = new ShopItems; - - mShopItemList = new ShopListBox(mShopItems, mShopItems); - mScrollArea = new ScrollArea(mShopItemList); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - - mSlider = new Slider(1.0); - mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); - mQuantityLabel->setAlignment(gcn::Graphics::CENTER); - mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"), - "", "")); - - // TRANSLATORS: This is a narrow symbol used to denote 'increasing'. - // You may change this symbol if your language uses another. - mIncreaseButton = new Button(_("+"), "inc", this); - // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'. - // You may change this symbol if your language uses another. - mDecreaseButton = new Button(_("-"), "dec", this); - mBuyButton = new Button(_("Buy"), "buy", this); - mQuitButton = new Button(_("Quit"), "quit", this); - mAddMaxButton = new Button(_("Max"), "max", this); - - mDecreaseButton->adjustSize(); - mDecreaseButton->setWidth(mIncreaseButton->getWidth()); - - mIncreaseButton->setEnabled(false); - mDecreaseButton->setEnabled(false); - mBuyButton->setEnabled(false); - mSlider->setEnabled(false); - - mSlider->setActionEventId("slider"); - mSlider->addActionListener(this); - mShopItemList->addSelectionListener(this); - - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, mScrollArea, 8, 5).setPadding(3); - place(0, 5, mDecreaseButton); - place(1, 5, mSlider, 3); - place(4, 5, mIncreaseButton); - place(5, 5, mQuantityLabel, 2); - place(7, 5, mAddMaxButton); - place(0, 6, mMoneyLabel, 8); - place(6, 7, mBuyButton); - place(7, 7, mQuitButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - center(); - loadWindowState(); - - instances.push_back(this); - setVisible(true); -} - -BuyDialog::~BuyDialog() -{ - delete mShopItems; - mShopItems = 0; - - instances.remove(this); -} - -void BuyDialog::setMoney(int amount) -{ - mMoney = amount; - mShopItemList->setPlayersMoney(amount); - - updateButtonsAndLabels(); -} - -void BuyDialog::reset() -{ - mShopItems->clear(); - mShopItemList->adjustSize(); - - // Reset previous selected items to prevent failing asserts - mShopItemList->setSelected(-1); - mSlider->setValue(0); - - setMoney(0); -} - -void BuyDialog::addItem(int id, unsigned char color, int amount, int price) -{ - mShopItems->addItem(id, color, amount, price); - mShopItemList->adjustSize(); -} - -void BuyDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "quit") - { - close(); - return; - } - - int selectedItem = mShopItemList->getSelected(); - - // The following actions require a valid selection - if (selectedItem < 0 || - selectedItem >= static_cast(mShopItems->getNumberOfElements())) - { - return; - } - - if (event.getId() == "slider") - { - mAmountItems = static_cast(mSlider->getValue()); - updateButtonsAndLabels(); - } - else if (event.getId() == "inc" && mAmountItems < mMaxItems) - { - mAmountItems++; - mSlider->setValue(mAmountItems); - updateButtonsAndLabels(); - } - else if (event.getId() == "dec" && mAmountItems > 1) - { - mAmountItems--; - mSlider->setValue(mAmountItems); - updateButtonsAndLabels(); - } - else if (event.getId() == "max") - { - mAmountItems = mMaxItems; - mSlider->setValue(mAmountItems); - updateButtonsAndLabels(); - } - // TODO: Actually we'd have a bug elsewhere if this check for the number - // of items to be bought ever fails, Bertram removed the assertions, is - // there a better way to ensure this fails in an _obvious_ way in C++? - else if (event.getId() == "buy" && mAmountItems > 0 && - mAmountItems <= mMaxItems) - { - if (mNpcId != -1) - { - ShopItem *item = mShopItems->at(selectedItem); - Net::getNpcHandler()->buyItem(mNpcId, item->getId(), - item->getColor(), mAmountItems); - - // Update money and adjust the max number of items that can be bought - mMaxItems -= mAmountItems; - setMoney(mMoney - - mAmountItems * mShopItems->at(selectedItem)->getPrice()); - - // Reset selection - mAmountItems = 1; - mSlider->setValue(1); - mSlider->gcn::Slider::setScale(1, mMaxItems); - } - else if (tradeWindow) - { - ShopItem *item = mShopItems->at(selectedItem); - if (item) - { - Net::getBuySellHandler()->sendBuyRequest(mNick, - item, mAmountItems); -// logger->log("buy button mNick:" + mNick); - if (tradeWindow) - { - tradeWindow->addAutoMoney(mNick, - item->getPrice() * mAmountItems); - } - } - } - } -} - -void BuyDialog::valueChanged(const gcn::SelectionEvent &event _UNUSED_) -{ - // Reset amount of items and update labels - mAmountItems = 1; - mSlider->setValue(1); - - updateButtonsAndLabels(); - mSlider->gcn::Slider::setScale(1, mMaxItems); -} - -void BuyDialog::updateButtonsAndLabels() -{ - const int selectedItem = mShopItemList->getSelected(); - int price = 0; - - if (selectedItem > -1) - { - ShopItem * item = mShopItems->at(selectedItem); - if (item) - { - int itemPrice = item->getPrice(); - - // Calculate how many the player can afford - if (itemPrice) - mMaxItems = mMoney / itemPrice; - else - mMaxItems = 1; - - if (item->getQuantity() > 0 && mMaxItems > item->getQuantity()) - mMaxItems = item->getQuantity(); - - if (mAmountItems > mMaxItems) - mAmountItems = mMaxItems; - - // Calculate price of pending purchase - price = mAmountItems * itemPrice; - } - } - else - { - mMaxItems = 0; - mAmountItems = 0; - } - - // Enable or disable buttons and slider - mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mDecreaseButton->setEnabled(mAmountItems > 1); - mBuyButton->setEnabled(mAmountItems > 0); - mSlider->setEnabled(mMaxItems > 1); - - // Update quantity and money labels - mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); - mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), - Units::formatCurrency(price).c_str(), - Units::formatCurrency(mMoney - price).c_str())); -} - -void BuyDialog::setVisible(bool visible) -{ - Window::setVisible(visible); - - if (visible && mShopItemList) - mShopItemList->requestFocus(); - else - scheduleDelete(); -} - -void BuyDialog::closeAll() -{ - DialogList::iterator it = instances.begin(); - DialogList::iterator it_end = instances.end(); - - for (; it != it_end; ++it) - { - if (*it) - (*it)->close(); - } -} diff --git a/src/gui/buy.h b/src/gui/buy.h deleted file mode 100644 index c9d412645..000000000 --- a/src/gui/buy.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#ifndef BUY_H -#define BUY_H - -#include "guichanfwd.h" - -#include "gui/widgets/window.h" - -#include -#include - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -class ShopItems; -class ShopListBox; -class ListBox; - -/** - * The buy dialog. - * - * \ingroup Interface - */ -class BuyDialog : public Window, public gcn::ActionListener, - public gcn::SelectionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - BuyDialog(int npcId); - - /** - * Constructor. - */ - BuyDialog(std::string nick); - - /** - * Destructor - */ - ~BuyDialog(); - - void init(); - - /** - * Resets the dialog, clearing shop inventory. - */ - void reset(); - - /** - * Sets the amount of available money. - */ - void setMoney(int amount); - - /** - * Adds an item to the shop inventory. - */ - void addItem(int id, unsigned char color, int amount, int price); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Returns the number of items in the shop inventory. - */ - int getNumberOfElements(); - - /** - * Updates the labels according to the selected item. - */ - void valueChanged(const gcn::SelectionEvent &event); - - /** - * Returns the name of item number i in the shop inventory. - */ - std::string getElementAt(int i); - - /** - * Updates the state of buttons and labels. - */ - void updateButtonsAndLabels(); - - /** - * Sets the visibility of this window. - */ - void setVisible(bool visible); - - /** - * Returns true if any instances exist. - */ - static bool isActive() - { return !instances.empty(); } - - /** - * Closes all instances. - */ - static void closeAll(); - - private: - typedef std::list DialogList; - static DialogList instances; - - int mNpcId; - - gcn::Button *mBuyButton; - gcn::Button *mQuitButton; - gcn::Button *mAddMaxButton; - gcn::Button *mIncreaseButton; - gcn::Button *mDecreaseButton; - ShopListBox *mShopItemList; - gcn::ScrollArea *mScrollArea; - gcn::Label *mMoneyLabel; - gcn::Label *mQuantityLabel; - gcn::Slider *mSlider; - - ShopItems *mShopItems; - - int mMoney; - int mAmountItems; - int mMaxItems; - std::string mNick; -}; - -#endif diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp new file mode 100644 index 000000000..fe504413c --- /dev/null +++ b/src/gui/buydialog.cpp @@ -0,0 +1,325 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#include "gui/buydialog.h" + +#include "shopitem.h" +#include "units.h" + +#include "gui/setup.h" +#include "gui/trade.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/shopitems.h" +#include "gui/widgets/shoplistbox.h" +#include "gui/widgets/slider.h" + +#include "shopitem.h" +#include "units.h" + +#include "net/buysellhandler.h" +#include "net/net.h" +#include "net/npchandler.h" + +#include "resources/iteminfo.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" + +BuyDialog::DialogList BuyDialog::instances; + +BuyDialog::BuyDialog(int npcId): + Window(_("Buy")), + mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), mNick("") +{ + init(); +} + +BuyDialog::BuyDialog(std::string nick): + Window(_("Buy")), + mNpcId(-1), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(nick) +{ + init(); + logger->log("BuyDialog::BuyDialog nick:" + mNick); +} + +void BuyDialog::init() +{ + setWindowName("Buy"); + setResizable(true); + setCloseButton(true); + setMinWidth(260); + setMinHeight(230); + setDefaultSize(260, 230, ImageRect::CENTER); + + mShopItems = new ShopItems; + + mShopItemList = new ShopListBox(mShopItems, mShopItems); + mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + mSlider = new Slider(1.0); + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); + mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"), + "", "")); + + // TRANSLATORS: This is a narrow symbol used to denote 'increasing'. + // You may change this symbol if your language uses another. + mIncreaseButton = new Button(_("+"), "inc", this); + // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'. + // You may change this symbol if your language uses another. + mDecreaseButton = new Button(_("-"), "dec", this); + mBuyButton = new Button(_("Buy"), "buy", this); + mQuitButton = new Button(_("Quit"), "quit", this); + mAddMaxButton = new Button(_("Max"), "max", this); + + mDecreaseButton->adjustSize(); + mDecreaseButton->setWidth(mIncreaseButton->getWidth()); + + mIncreaseButton->setEnabled(false); + mDecreaseButton->setEnabled(false); + mBuyButton->setEnabled(false); + mSlider->setEnabled(false); + + mSlider->setActionEventId("slider"); + mSlider->addActionListener(this); + mShopItemList->addSelectionListener(this); + + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 8, 5).setPadding(3); + place(0, 5, mDecreaseButton); + place(1, 5, mSlider, 3); + place(4, 5, mIncreaseButton); + place(5, 5, mQuantityLabel, 2); + place(7, 5, mAddMaxButton); + place(0, 6, mMoneyLabel, 8); + place(6, 7, mBuyButton); + place(7, 7, mQuitButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + + center(); + loadWindowState(); + + instances.push_back(this); + setVisible(true); +} + +BuyDialog::~BuyDialog() +{ + delete mShopItems; + mShopItems = 0; + + instances.remove(this); +} + +void BuyDialog::setMoney(int amount) +{ + mMoney = amount; + mShopItemList->setPlayersMoney(amount); + + updateButtonsAndLabels(); +} + +void BuyDialog::reset() +{ + mShopItems->clear(); + mShopItemList->adjustSize(); + + // Reset previous selected items to prevent failing asserts + mShopItemList->setSelected(-1); + mSlider->setValue(0); + + setMoney(0); +} + +void BuyDialog::addItem(int id, unsigned char color, int amount, int price) +{ + mShopItems->addItem(id, color, amount, price); + mShopItemList->adjustSize(); +} + +void BuyDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "quit") + { + close(); + return; + } + + int selectedItem = mShopItemList->getSelected(); + + // The following actions require a valid selection + if (selectedItem < 0 || + selectedItem >= static_cast(mShopItems->getNumberOfElements())) + { + return; + } + + if (event.getId() == "slider") + { + mAmountItems = static_cast(mSlider->getValue()); + updateButtonsAndLabels(); + } + else if (event.getId() == "inc" && mAmountItems < mMaxItems) + { + mAmountItems++; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } + else if (event.getId() == "dec" && mAmountItems > 1) + { + mAmountItems--; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } + else if (event.getId() == "max") + { + mAmountItems = mMaxItems; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } + // TODO: Actually we'd have a bug elsewhere if this check for the number + // of items to be bought ever fails, Bertram removed the assertions, is + // there a better way to ensure this fails in an _obvious_ way in C++? + else if (event.getId() == "buy" && mAmountItems > 0 && + mAmountItems <= mMaxItems) + { + if (mNpcId != -1) + { + ShopItem *item = mShopItems->at(selectedItem); + Net::getNpcHandler()->buyItem(mNpcId, item->getId(), + item->getColor(), mAmountItems); + + // Update money and adjust the max number of items that can be bought + mMaxItems -= mAmountItems; + setMoney(mMoney - + mAmountItems * mShopItems->at(selectedItem)->getPrice()); + + // Reset selection + mAmountItems = 1; + mSlider->setValue(1); + mSlider->gcn::Slider::setScale(1, mMaxItems); + } + else if (tradeWindow) + { + ShopItem *item = mShopItems->at(selectedItem); + if (item) + { + Net::getBuySellHandler()->sendBuyRequest(mNick, + item, mAmountItems); +// logger->log("buy button mNick:" + mNick); + if (tradeWindow) + { + tradeWindow->addAutoMoney(mNick, + item->getPrice() * mAmountItems); + } + } + } + } +} + +void BuyDialog::valueChanged(const gcn::SelectionEvent &event _UNUSED_) +{ + // Reset amount of items and update labels + mAmountItems = 1; + mSlider->setValue(1); + + updateButtonsAndLabels(); + mSlider->gcn::Slider::setScale(1, mMaxItems); +} + +void BuyDialog::updateButtonsAndLabels() +{ + const int selectedItem = mShopItemList->getSelected(); + int price = 0; + + if (selectedItem > -1) + { + ShopItem * item = mShopItems->at(selectedItem); + if (item) + { + int itemPrice = item->getPrice(); + + // Calculate how many the player can afford + if (itemPrice) + mMaxItems = mMoney / itemPrice; + else + mMaxItems = 1; + + if (item->getQuantity() > 0 && mMaxItems > item->getQuantity()) + mMaxItems = item->getQuantity(); + + if (mAmountItems > mMaxItems) + mAmountItems = mMaxItems; + + // Calculate price of pending purchase + price = mAmountItems * itemPrice; + } + } + else + { + mMaxItems = 0; + mAmountItems = 0; + } + + // Enable or disable buttons and slider + mIncreaseButton->setEnabled(mAmountItems < mMaxItems); + mDecreaseButton->setEnabled(mAmountItems > 1); + mBuyButton->setEnabled(mAmountItems > 0); + mSlider->setEnabled(mMaxItems > 1); + + // Update quantity and money labels + mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); + mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), + Units::formatCurrency(price).c_str(), + Units::formatCurrency(mMoney - price).c_str())); +} + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible && mShopItemList) + mShopItemList->requestFocus(); + else + scheduleDelete(); +} + +void BuyDialog::closeAll() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; ++it) + { + if (*it) + (*it)->close(); + } +} diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h new file mode 100644 index 000000000..eabf26ef8 --- /dev/null +++ b/src/gui/buydialog.h @@ -0,0 +1,152 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#ifndef BUYDIALOG_H +#define BUYDIALOG_H + +#include "guichanfwd.h" + +#include "gui/widgets/window.h" + +#include +#include + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +class ShopItems; +class ShopListBox; +class ListBox; + +/** + * The buy dialog. + * + * \ingroup Interface + */ +class BuyDialog : public Window, public gcn::ActionListener, + public gcn::SelectionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + BuyDialog(int npcId); + + /** + * Constructor. + */ + BuyDialog(std::string nick); + + /** + * Destructor + */ + ~BuyDialog(); + + void init(); + + /** + * Resets the dialog, clearing shop inventory. + */ + void reset(); + + /** + * Sets the amount of available money. + */ + void setMoney(int amount); + + /** + * Adds an item to the shop inventory. + */ + void addItem(int id, unsigned char color, int amount, int price); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Returns the number of items in the shop inventory. + */ + int getNumberOfElements(); + + /** + * Updates the labels according to the selected item. + */ + void valueChanged(const gcn::SelectionEvent &event); + + /** + * Returns the name of item number i in the shop inventory. + */ + std::string getElementAt(int i); + + /** + * Updates the state of buttons and labels. + */ + void updateButtonsAndLabels(); + + /** + * Sets the visibility of this window. + */ + void setVisible(bool visible); + + /** + * Returns true if any instances exist. + */ + static bool isActive() + { return !instances.empty(); } + + /** + * Closes all instances. + */ + static void closeAll(); + + private: + typedef std::list DialogList; + static DialogList instances; + + int mNpcId; + + gcn::Button *mBuyButton; + gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; + gcn::Button *mIncreaseButton; + gcn::Button *mDecreaseButton; + ShopListBox *mShopItemList; + gcn::ScrollArea *mScrollArea; + gcn::Label *mMoneyLabel; + gcn::Label *mQuantityLabel; + gcn::Slider *mSlider; + + ShopItems *mShopItems; + + int mMoney; + int mAmountItems; + int mMaxItems; + std::string mNick; +}; + +#endif diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp deleted file mode 100644 index 30f8478ba..000000000 --- a/src/gui/buysell.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "gui/buysell.h" - -#include "gui/setup.h" - -#include "gui/widgets/button.h" - -#include "net/buysellhandler.h" -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" - -BuySellDialog::DialogList BuySellDialog::instances; - -BuySellDialog::BuySellDialog(int npcId): - Window(_("Shop")), - mNpcId(npcId), - mNick(""), - mBuyButton(0) -{ - init(); -} - -BuySellDialog::BuySellDialog(std::string nick): - Window(_("Shop")), - mNpcId(-1), - mNick(nick), - mBuyButton(0) -{ - init(); -} - -void BuySellDialog::init() -{ - setWindowName("BuySell"); - //setupWindow->registerWindowForReset(this); - setCloseButton(true); - - static const char *buttonNames[] = - { - N_("Buy"), N_("Sell"), N_("Cancel"), 0 - }; - int x = 10, y = 10; - - for (const char **curBtn = buttonNames; *curBtn; curBtn++) - { - Button *btn = new Button(gettext(*curBtn), *curBtn, this); - if (!mBuyButton) - mBuyButton = btn; // For focus request - btn->setPosition(x, y); - add(btn); - x += btn->getWidth() + 10; - } - mBuyButton->requestFocus(); - - setContentSize(x, 2 * y + mBuyButton->getHeight()); - - center(); - setDefaultSize(); - loadWindowState(); - - instances.push_back(this); - setVisible(true); -} - -BuySellDialog::~BuySellDialog() -{ - instances.remove(this); -} - -void BuySellDialog::setVisible(bool visible) -{ - Window::setVisible(visible); - - if (visible) - { - if (mBuyButton) - mBuyButton->requestFocus(); - } - else - { - scheduleDelete(); - } -} - -void BuySellDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "Buy") - { - if (mNpcId != -1) - Net::getNpcHandler()->buy(mNpcId); - else - Net::getBuySellHandler()->requestSellList(mNick); - } - else if (event.getId() == "Sell") - { - if (mNpcId != -1) - Net::getNpcHandler()->sell(mNpcId); - else - Net::getBuySellHandler()->requestBuyList(mNick); - } - - close(); -} - -void BuySellDialog::closeAll() -{ - DialogList::iterator it = instances.begin(); - DialogList::iterator it_end = instances.end(); - - for (; it != it_end; ++it) - { - if (*it) - (*it)->close(); - } -} diff --git a/src/gui/buysell.h b/src/gui/buysell.h deleted file mode 100644 index f05c5d083..000000000 --- a/src/gui/buysell.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#ifndef BUYSELL_H -#define BUYSELL_H - -#include "gui/widgets/window.h" - -#include - -/** - * A dialog to choose between buying or selling at a shop. - * - * \ingroup Interface - */ -class BuySellDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. The action listener passed will receive "sell", "buy" - * or "cancel" events when the respective buttons are pressed. - * - * @see Window::Window - */ - BuySellDialog(int npcId); - - BuySellDialog(std::string nick); - - virtual ~BuySellDialog(); - - void init(); - - void setVisible(bool visible); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Returns true if any instances exist. - */ - static bool isActive() - { return !instances.empty(); } - - /** - * Closes all instances. - */ - static void closeAll(); - - private: - typedef std::list DialogList; - static DialogList instances; - - int mNpcId; - std::string mNick; - gcn::Button *mBuyButton; -}; - -#endif diff --git a/src/gui/buyselldialog.cpp b/src/gui/buyselldialog.cpp new file mode 100644 index 000000000..961e744c0 --- /dev/null +++ b/src/gui/buyselldialog.cpp @@ -0,0 +1,138 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#include "gui/buyselldialog.h" + +#include "gui/setup.h" + +#include "gui/widgets/button.h" + +#include "net/buysellhandler.h" +#include "net/net.h" +#include "net/npchandler.h" + +#include "utils/gettext.h" + +BuySellDialog::DialogList BuySellDialog::instances; + +BuySellDialog::BuySellDialog(int npcId): + Window(_("Shop")), + mNpcId(npcId), + mNick(""), + mBuyButton(0) +{ + init(); +} + +BuySellDialog::BuySellDialog(std::string nick): + Window(_("Shop")), + mNpcId(-1), + mNick(nick), + mBuyButton(0) +{ + init(); +} + +void BuySellDialog::init() +{ + setWindowName("BuySell"); + //setupWindow->registerWindowForReset(this); + setCloseButton(true); + + static const char *buttonNames[] = + { + N_("Buy"), N_("Sell"), N_("Cancel"), 0 + }; + int x = 10, y = 10; + + for (const char **curBtn = buttonNames; *curBtn; curBtn++) + { + Button *btn = new Button(gettext(*curBtn), *curBtn, this); + if (!mBuyButton) + mBuyButton = btn; // For focus request + btn->setPosition(x, y); + add(btn); + x += btn->getWidth() + 10; + } + mBuyButton->requestFocus(); + + setContentSize(x, 2 * y + mBuyButton->getHeight()); + + center(); + setDefaultSize(); + loadWindowState(); + + instances.push_back(this); + setVisible(true); +} + +BuySellDialog::~BuySellDialog() +{ + instances.remove(this); +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) + { + if (mBuyButton) + mBuyButton->requestFocus(); + } + else + { + scheduleDelete(); + } +} + +void BuySellDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "Buy") + { + if (mNpcId != -1) + Net::getNpcHandler()->buy(mNpcId); + else + Net::getBuySellHandler()->requestSellList(mNick); + } + else if (event.getId() == "Sell") + { + if (mNpcId != -1) + Net::getNpcHandler()->sell(mNpcId); + else + Net::getBuySellHandler()->requestBuyList(mNick); + } + + close(); +} + +void BuySellDialog::closeAll() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; ++it) + { + if (*it) + (*it)->close(); + } +} diff --git a/src/gui/buyselldialog.h b/src/gui/buyselldialog.h new file mode 100644 index 000000000..2c7e5c101 --- /dev/null +++ b/src/gui/buyselldialog.h @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#ifndef BUYSELLDIALOG_H +#define BUYSELLDIALOG_H + +#include "gui/widgets/window.h" + +#include + +/** + * A dialog to choose between buying or selling at a shop. + * + * \ingroup Interface + */ +class BuySellDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. The action listener passed will receive "sell", "buy" + * or "cancel" events when the respective buttons are pressed. + * + * @see Window::Window + */ + BuySellDialog(int npcId); + + BuySellDialog(std::string nick); + + virtual ~BuySellDialog(); + + void init(); + + void setVisible(bool visible); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Returns true if any instances exist. + */ + static bool isActive() + { return !instances.empty(); } + + /** + * Closes all instances. + */ + static void closeAll(); + + private: + typedef std::list DialogList; + static DialogList instances; + + int mNpcId; + std::string mNick; + gcn::Button *mBuyButton; +}; + +#endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp deleted file mode 100644 index e50310409..000000000 --- a/src/gui/chat.cpp +++ /dev/null @@ -1,1416 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "chat.h" - -#include "actorspritemanager.h" -#include "client.h" -#include "configuration.h" -#include "guild.h" -#include "keyboardconfig.h" -#include "localplayer.h" -#include "party.h" -#include "playerinfo.h" -#include "playerrelations.h" -#include "spellshortcut.h" -#include "sound.h" - -#include "gui/setup.h" -#include "gui/sdlinput.h" -#include "gui/theme.h" -#include "gui/viewport.h" - -#include "gui/widgets/battletab.h" -#include "gui/widgets/chattab.h" -#include "gui/widgets/dropdown.h" -#include "gui/widgets/itemlinkhandler.h" -#include "gui/widgets/layouthelper.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/tabbedarea.h" -#include "gui/widgets/textfield.h" -#include "gui/widgets/tradetab.h" -#include "gui/widgets/whispertab.h" - -#include "net/chathandler.h" -#include "net/playerhandler.h" -#include "net/net.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" - -#include -#include - -#include - -#include - -/** - * The chat input hides when it loses focus. It is also invisible by default. - */ -class ChatInput : public TextField, public gcn::FocusListener -{ - public: - ChatInput(): - TextField("", false) - { - setVisible(false); - addFocusListener(this); - } - - /** - * Called if the chat input loses focus. It will set itself to - * invisible as result. - */ - void focusLost(const gcn::Event &event _UNUSED_) - { - setVisible(false); - } -}; - -const char *COLOR_NAME[14] = -{ - N_("default"), - N_("black"), - N_("red"), - N_("green"), - N_("blue"), - N_("gold"), - N_("yellow"), - N_("pink"), - N_("purple"), - N_("grey"), - N_("brown"), - N_("rainbow 1"), - N_("rainbow 2"), - N_("rainbow 3"), -}; - - -class ColorListModel : public gcn::ListModel -{ -public: - virtual ~ColorListModel() { } - - virtual int getNumberOfElements() - { - return 14; - } - - virtual std::string getElementAt(int i) - { - if (i >= getNumberOfElements() || i < 0) - return _("???"); - - return gettext(COLOR_NAME[i]); - } -}; - -#define ACTION_COLOR_PICKER "color picker" - - -ChatWindow::ChatWindow(): - Window(_("Chat")), - mTmpVisible(false), - mChatHistoryIndex(0) -{ - listen(CHANNEL_NOTICES); - listen(CHANNEL_ATTRIBUTES); - - setWindowName("Chat"); - - if (setupWindow) - setupWindow->registerWindowForReset(this); - - // no title presented, title bar is padding so window can be moved. - gcn::Window::setTitleBarHeight(gcn::Window::getPadding() + 4); - setShowTitle(false); - setResizable(true); - setDefaultVisible(true); - setSaveVisible(true); - setDefaultSize(600, 123, ImageRect::LOWER_LEFT); - setMinWidth(150); - setMinHeight(90); - - mItemLinkHandler = new ItemLinkHandler; - - mChatInput = new ChatInput; - mChatInput->setActionEventId("chatinput"); - mChatInput->addActionListener(this); - - mChatTabs = new TabbedArea; - mChatTabs->enableScrollButtons(true); - - mChatColor = config.getIntValue("chatColor"); - mColorListModel = new ColorListModel; - mColorPicker = new DropDown(mColorListModel); - - mColorPicker->setActionEventId(ACTION_COLOR_PICKER); - mColorPicker->addActionListener(this); - mColorPicker->setSelected(mChatColor); - - add(mChatTabs); - add(mChatInput); - add(mColorPicker); - - loadWindowState(); - - mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth() - - 2*getPadding() - 8 - 16, getPadding()); - - // Add key listener to chat input to be able to respond to up/down - mChatInput->addKeyListener(this); - mCurHist = mHistory.end(); - - mReturnToggles = config.getBoolValue("ReturnToggles"); - - mRainbowColor = 0; - - mColorPicker->setVisible(config.getBoolValue("showChatColorsList")); - - fillCommands(); - initTradeFilter(); -} - -ChatWindow::~ChatWindow() -{ - config.setValue("ReturnToggles", mReturnToggles); - removeAllWhispers(); - delete mItemLinkHandler; - mItemLinkHandler = 0; - delete mColorPicker; - mColorPicker = 0; - delete mColorListModel; - mColorListModel = 0; -} - -void ChatWindow::fillCommands() -{ - mCommands.push_back("/all"); - mCommands.push_back("/away "); - mCommands.push_back("/closeall"); - mCommands.push_back("/clear"); - mCommands.push_back("/create "); - mCommands.push_back("/close"); - mCommands.push_back("/cacheinfo"); - mCommands.push_back("/erase "); - mCommands.push_back("/follow "); - mCommands.push_back("/heal "); - mCommands.push_back("/ignoreall"); - mCommands.push_back("/help"); - mCommands.push_back("/announce "); - mCommands.push_back("/where"); - mCommands.push_back("/who"); - mCommands.push_back("/msg "); - mCommands.push_back("/mail "); - mCommands.push_back("/whisper "); - mCommands.push_back("/w "); - mCommands.push_back("/query "); - mCommands.push_back("/ignore "); - mCommands.push_back("/unignore "); - mCommands.push_back("/join "); - mCommands.push_back("/list"); - mCommands.push_back("/party"); - mCommands.push_back("/createparty "); - mCommands.push_back("/createguild "); - mCommands.push_back("/me "); - mCommands.push_back("/toggle"); - mCommands.push_back("/present"); - mCommands.push_back("/quit"); - mCommands.push_back("/move "); - mCommands.push_back("/target "); - mCommands.push_back("/invite "); - mCommands.push_back("/leave"); - mCommands.push_back("/kick "); - mCommands.push_back("/item"); - mCommands.push_back("/imitation"); - mCommands.push_back("/exp"); - mCommands.push_back("/ping"); - mCommands.push_back("/outfit "); - mCommands.push_back("/emote "); - mCommands.push_back("/navigate "); - mCommands.push_back("/priceload"); - mCommands.push_back("/pricesave"); - mCommands.push_back("/trade "); - mCommands.push_back("/friend "); - mCommands.push_back("/befriend "); - mCommands.push_back("/disregard "); - mCommands.push_back("/neutral "); - mCommands.push_back("/raw "); - mCommands.push_back("/disconnect"); - mCommands.push_back("/undress "); - mCommands.push_back("/attack"); - mCommands.push_back("/dirs"); - mCommands.push_back("/info"); - mCommands.push_back("/wait"); - mCommands.push_back("/uptime"); -} - -void ChatWindow::resetToDefaultSize() -{ - Window::resetToDefaultSize(); -} - -void ChatWindow::adjustTabSize() -{ - const gcn::Rectangle area = getChildrenArea(); - - mChatInput->setPosition(mChatInput->getFrameSize(), - area.height - mChatInput->getHeight() - - mChatInput->getFrameSize()); - mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize()); - - mChatTabs->setWidth(area.width - 2 * mChatTabs->getFrameSize()); - mChatTabs->setHeight(area.height - 2 * mChatTabs->getFrameSize() - - (mChatInput->getHeight() + mChatInput->getFrameSize() * 2)); - - ChatTab *tab = getFocused(); - if (tab) - { - gcn::Widget *content = tab->mScrollArea; - if (content) - { - content->setSize(mChatTabs->getWidth() - - 2 * content->getFrameSize(), - mChatTabs->getContainerHeight() - - 2 * content->getFrameSize()); - content->logic(); - } - } - - mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth() - - 2*getPadding() - 8 - 16, getPadding()); - -// if (mColorPicker->isVisible()) -// mChatTabs->setRightMargin(mColorPicker->getWidth() - 8); -} - -void ChatWindow::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - adjustTabSize(); -} - -/* -void ChatWindow::logic() -{ - Window::logic(); - - Tab *tab = getFocused(); - if (tab != mCurrentTab) - mCurrentTab = tab; -} -*/ - -ChatTab *ChatWindow::getFocused() const -{ - return static_cast(mChatTabs->getSelectedTab()); -} - -void ChatWindow::clearTab(ChatTab *tab) -{ - if (tab) - tab->clearText(); -} - -void ChatWindow::clearTab() -{ - clearTab(getFocused()); -} - -void ChatWindow::prevTab() -{ - if (!mChatTabs) - return; - - int tab = mChatTabs->getSelectedTabIndex(); - - if (tab == 0) - tab = mChatTabs->getNumberOfTabs(); - tab--; - - mChatTabs->setSelectedTab(tab); -} - -void ChatWindow::nextTab() -{ - if (!mChatTabs) - return; - - int tab = mChatTabs->getSelectedTabIndex(); - - tab++; - if (tab == mChatTabs->getNumberOfTabs()) - tab = 0; - - mChatTabs->setSelectedTab(tab); -} - -void ChatWindow::defaultTab() -{ - if (mChatTabs) - mChatTabs->setSelectedTab(static_cast(0)); -} - -void 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 - chatInput(addColors(message)); - - // Clear the text from the chat input - mChatInput->setText(""); - } - - if (message.empty() || !mReturnToggles) - { - // Remove focus and hide input - if (mFocusHandler) - mFocusHandler->focusNone(); - - // If the chatWindow is shown up because you want to send a message - // It should hide now - if (mTmpVisible) - setVisible(false); - } - } - else if (event.getId() == ACTION_COLOR_PICKER) - { - mChatColor = mColorPicker->getSelected(); - config.setValue("chatColor", mChatColor); - } - - if (mColorPicker && mColorPicker->isVisible() - != config.getBoolValue("showChatColorsList")) - { - mColorPicker->setVisible(config.getBoolValue( - "showChatColorsList")); - } -} - -bool 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; - } - - // Don't do anything else if the input is already visible and has focus - if (mChatInput->isVisible() && mChatInput->isFocused()) - return false; - - // Give focus to the chat input - mChatInput->setVisible(true); - mChatInput->requestFocus(); - return true; -} - -bool ChatWindow::isInputFocused() const -{ - return mChatInput->isFocused(); -} - -void ChatWindow::removeTab(ChatTab *tab) -{ - mChatTabs->removeTab(tab); -} - -void ChatWindow::addTab(ChatTab *tab) -{ - mChatTabs->addTab(tab, tab->mScrollArea); - - // Update UI - logic(); -} - -void ChatWindow::removeWhisper(const std::string &nick) -{ - std::string tempNick = nick; - toLower(tempNick); - mWhispers.erase(tempNick); -} - -void ChatWindow::removeAllWhispers() -{ - TabMap::iterator iter; - std::list tabs; - - for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) - tabs.push_back(iter->second); - - for (std::list::iterator it = tabs.begin(); - it != tabs.end(); ++it) - { - delete *it; - } - - mWhispers.clear(); -} - -void ChatWindow::ignoreAllWhispers() -{ - TabMap::iterator iter; - for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) - { - WhisperTab *tab = dynamic_cast(iter->second); - if (tab && player_relations.getRelation(tab->getNick()) - != PlayerRelation::IGNORED) - { - player_relations.setRelation(tab->getNick(), - PlayerRelation::IGNORED); - } - - delete(iter->second); - iter->second = 0; - } -} - -void ChatWindow::chatInput(const std::string &message) -{ - ChatTab *tab = NULL; - std::string msg = message; - trim(msg); - - if (config.getBoolValue("allowCommandsInChatTabs") - && msg.length() > 1 - && ((msg.at(0) == '#' && msg.at(1) != '#') || msg.at(0) == '@') - && localChatTab) - { - tab = localChatTab; - } - else - { - tab = getFocused(); - } - if (tab) - tab->chatInput(msg); - Game::instance()->setValidSpeed(); -} - -void ChatWindow::localChatInput(const std::string &msg) -{ - if (localChatTab) - localChatTab->chatInput(msg); - else - chatInput(msg); -} - -void ChatWindow::doPresent() -{ - if (!actorSpriteManager) - return; - - const ActorSprites &actors = actorSpriteManager->getAll(); - std::string response = ""; - int playercount = 0; - - for (ActorSpritesConstIterator it = actors.begin(), it_end = actors.end(); - it != it_end; ++it) - { - if ((*it)->getType() == ActorSprite::PLAYER) - { - if (!response.empty()) - response += ", "; - response += static_cast(*it)->getName(); - ++playercount; - } - } - - std::string log = strprintf(_("Present: %s; %d players are present."), - response.c_str(), playercount); - - if (getFocused()) - getFocused()->chatLog(log, BY_SERVER); -} - -void ChatWindow::scroll(int amount) -{ - if (!isVisible()) - return; - - ChatTab *tab = getFocused(); - if (tab) - tab->scroll(amount); -} - -void ChatWindow::mousePressed(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::RIGHT) - { - if (viewport) - { - gcn::Tab *tab = mChatTabs->getSelectedTab(); - if (tab) - { - ChatTab *cTab = dynamic_cast(tab); - if (cTab) - viewport->showChatPopup(cTab); - } - } - } - - Window::mousePressed(event); - - if (event.isConsumed()) - return; - - if (event.getButton() == gcn::MouseEvent::LEFT) - { - ChatTab *tab = getFocused(); - if (tab) - mMoved = !isResizeAllowed(event); - } - - mDragOffsetX = event.getX(); - mDragOffsetY = event.getY(); -} - -void ChatWindow::mouseDragged(gcn::MouseEvent &event) -{ - Window::mouseDragged(event); - - if (event.isConsumed()) - return; - - if (isMovable() && mMoved) - { - int newX = std::max(0, getX() + event.getX() - mDragOffsetX); - int newY = std::max(0, getY() + event.getY() - mDragOffsetY); - newX = std::min(graphics->getWidth() - getWidth(), newX); - newY = std::min(graphics->getHeight() - getHeight(), newY); - setPosition(newX, newY); - } -} - -/* -void ChatWindow::mouseReleased(gcn::MouseEvent &event _UNUSED_) -{ - -} -*/ - -void ChatWindow::keyPressed(gcn::KeyEvent &event) -{ - if (event.getKey().getValue() == Key::DOWN) - { - if (mCurHist != mHistory.end()) - { - // Move forward through the history - HistoryIterator prevHist = mCurHist++; - - if (mCurHist != mHistory.end()) - { - mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(static_cast( - mChatInput->getText().length())); - } - else - { - mChatInput->setText(""); - mCurHist = prevHist; - } - } - else if (mChatInput->getText() != "") - { - mChatInput->setText(""); - } - } - else if (event.getKey().getValue() == Key::UP && - mCurHist != mHistory.begin() && !mHistory.empty()) - { - // Move backward through the history - --mCurHist; - mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(static_cast( - mChatInput->getText().length())); - } - else if (event.getKey().getValue() == Key::INSERT && - mChatInput->getText() != "") - { - // Add the current message to the history and clear the text - if (mHistory.empty() || mChatInput->getText() != mHistory.back()) - mHistory.push_back(mChatInput->getText()); - mCurHist = mHistory.end(); - mChatInput->setText(""); - } - else if (keyboard.isKeyActive(keyboard.KEY_AUTOCOMPLETE_CHAT) && - mChatInput->getText() != "") - { - autoComplete(); - return; - } - else if (keyboard.isKeyActive(keyboard.KEY_DEACTIVATE_CHAT) && - mChatInput->isVisible()) - { - mChatInput->setVisible(false); - } - else if (keyboard.isKeyActive(keyboard.KEY_CHAT_PREV_HISTORY) && - mChatInput->isVisible()) - { - ChatTab *tab = getFocused(); - if (tab && (unsigned)tab->getRows().size() > 0) - { - if (!mChatHistoryIndex) - { - mChatHistoryIndex = static_cast( - tab->getRows().size()); - - mChatInput->setText(""); - mChatInput->setCaretPosition(0); - return; - } - else - { - mChatHistoryIndex --; - } - - std::list::iterator it; - unsigned int f = 0; - for (it = tab->getRows().begin(); - it != tab->getRows().end(); ++it, f++) - { - if (f == mChatHistoryIndex) - mChatInput->setText(*it); - } - mChatInput->setCaretPosition(static_cast( - mChatInput->getText().length())); - } - } - else if (keyboard.isKeyActive(keyboard.KEY_CHAT_NEXT_HISTORY) && - mChatInput->isVisible()) - { - ChatTab *tab = getFocused(); - if (tab && !tab->getRows().empty()) - { - if (mChatHistoryIndex + 1 < tab->getRows().size()) - { - mChatHistoryIndex ++; - } - else if (mChatHistoryIndex < tab->getRows().size()) - { - mChatHistoryIndex ++; - mChatInput->setText(""); - mChatInput->setCaretPosition(0); - return; - } - else - { - mChatHistoryIndex = 0; - } - - std::list::iterator it; - unsigned int f = 0; - for (it = tab->getRows().begin(); - it != tab->getRows().end(); ++it, f++) - { - if (f == mChatHistoryIndex) - mChatInput->setText(*it); - } - mChatInput->setCaretPosition(static_cast( - mChatInput->getText().length())); - } - } - - std::string Temp; - switch (event.getKey().getValue()) - { - case Key::F2: Temp = "\u2318"; break; - case Key::F3: Temp = "\u263A"; break; - case Key::F4: Temp = "\u2665"; break; - case Key::F5: Temp = "\u266A"; break; - case Key::F6: Temp = "\u266B"; break; - case Key::F7: Temp = "\u26A0"; break; - case Key::F8: Temp = "\u2622"; break; - case Key::F9: Temp = "\u262E"; break; - case Key::F10: Temp = "\u2605"; break; - case Key::F11: Temp = "\u2618"; break; - case Key::F12: Temp = "\u2592"; break; - default: break; - } - - if (Temp != "") - addInputText(Temp, false); -} - -void ChatWindow::event(Channels channel, const Mana::Event &event) -{ - if (channel == CHANNEL_NOTICES) - { - if (event.getName() == EVENT_SERVERNOTICE && localChatTab) - localChatTab->chatLog(event.getString("message"), BY_SERVER); - } - else if (channel == CHANNEL_ATTRIBUTES) - { - if (!config.getBoolValue("showBattleEvents")) - return; - - if (event.getName() == EVENT_UPDATEATTRIBUTE) - { - switch (event.getInt("id")) - { - case EXP: - { - if (event.getInt("oldValue") > event.getInt("newValue")) - break; - - int change = event.getInt("newValue") - - event.getInt("oldValue"); - - if (change != 0) - battleChatLog("+" + toString(change) + " xp"); - break; - } - case LEVEL: - battleChatLog("Level: " + toString( - event.getInt("newValue"))); - break; - default: - break; - }; - } - else if (event.getName() == EVENT_UPDATESTAT) - { - if (!config.getBoolValue("showJobExp")) - return; - - int id = event.getInt("id"); - if (id == Net::getPlayerHandler()->getJobLocation()) - { - std::pair exp - = PlayerInfo::getStatExperience(id); - if (event.getInt("oldValue1") > exp.first - || !event.getInt("oldValue2")) - { - return; - } - - int change = exp.first - event.getInt("oldValue1"); - if (change != 0) - battleChatLog("+" + toString(change) + " job"); - } - } - } -} - -void ChatWindow::addInputText(const std::string &text, bool space) -{ - int caretPos = mChatInput->getCaretPosition(); - const std::string inputText = mChatInput->getText(); - - std::ostringstream ss; - ss << inputText.substr(0, caretPos) << text; - if (space) - ss << " "; - - ss << inputText.substr(caretPos); - - mChatInput->setText(ss.str()); - mChatInput->setCaretPosition(caretPos + static_cast( - text.length()) + static_cast(space)); - requestChatFocus(); -} - -void ChatWindow::addItemText(const std::string &item) -{ - std::ostringstream text; - text << "[" << item << "]"; - addInputText(text.str()); -} - -void ChatWindow::setVisible(bool isVisible) -{ - Window::setVisible(isVisible); - - /* - * For whatever reason, if setVisible is called, the mTmpVisible effect - * should be disabled. - */ - mTmpVisible = false; -} - -void ChatWindow::whisper(const std::string &nick, - const std::string &mes, Own own) -{ - if (mes.empty() || !player_node) - return; - - std::string playerName = player_node->getName(); - std::string tempNick = nick; - - toLower(playerName); - toLower(tempNick); - - if (tempNick.compare(playerName) == 0) - return; - - ChatTab *tab = 0; - TabMap::const_iterator i = mWhispers.find(tempNick); - - if (i != mWhispers.end()) - tab = i->second; - else if (config.getBoolValue("whispertab")) - tab = addWhisperTab(nick); - - if (tab) - { - if (own == BY_PLAYER) - { - tab->chatInput(mes); - } - else if (own == BY_SERVER) - { - tab->chatLog(mes); - } - else - { - if (tab->getRemoveNames()) - { - std::string msg = mes; - std::string nick2; - int idx = mes.find(":"); - if (idx > 0) - { - nick2 = msg.substr(0, idx); - msg = msg.substr(idx + 1); - nick2 = removeColors(nick2); - nick2 = trim(nick2); - msg = trim(msg); - tab->chatLog(nick2, msg); - } - else - { - tab->chatLog(nick, mes); - } - } - else - { - tab->chatLog(nick, mes); - } - player_node->afkRespond(tab, nick); - } - } - else if (localChatTab) - { - if (own == BY_PLAYER) - { - Net::getChatHandler()->privateMessage(nick, mes); - - localChatTab->chatLog(strprintf(_("Whispering to %s: %s"), - nick.c_str(), mes.c_str()), BY_PLAYER); - } - else - { - localChatTab->chatLog(nick + " : " + mes, ACT_WHISPER, false); - if (player_node) - player_node->afkRespond(0, nick); - } - } -} - -ChatTab *ChatWindow::addWhisperTab(const std::string &nick, bool switchTo) -{ - if (!player_node) - return NULL; - - std::string playerName = player_node->getName(); - std::string tempNick = nick; - - toLower(playerName); - toLower(tempNick); - - TabMap::const_iterator i = mWhispers.find(tempNick); - ChatTab *ret; - - if (tempNick.compare(playerName) == 0) - return NULL; - - if (i != mWhispers.end()) - { - ret = i->second; - } - else - { - ret = new WhisperTab(nick); - mWhispers[tempNick] = ret; - if (config.getBoolValue("showChatHistory")) - ret->loadFromLogFile(nick); - } - - if (switchTo) - mChatTabs->setSelectedTab(ret); - - return ret; -} - -ChatTab *ChatWindow::getWhisperTab(const std::string &nick) const -{ - if (!player_node) - return NULL; - - std::string playerName = player_node->getName(); - std::string tempNick = nick; - - toLower(playerName); - toLower(tempNick); - - TabMap::const_iterator i = mWhispers.find(tempNick); - ChatTab *ret = 0; - - if (tempNick.compare(playerName) == 0) - return NULL; - - if (i != mWhispers.end()) - ret = i->second; - - return ret; -} - -std::string ChatWindow::addColors(std::string &msg) -{ - // default color or chat command - if (mChatColor == 0 || msg.length() == 0 || msg.at(0) == '#' - || msg.at(0) == '/' || msg.at(0) == '@' || msg.at(0) == '!') - { - return msg; - } - - std::string newMsg = ""; - int cMap[] = {1, 4, 5, 2, 3, 6, 7, 9, 0, 8}; - - // rainbow - switch(mChatColor) - { - case 11: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(mRainbowColor++) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } - return newMsg; - case 12: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } - return newMsg; - case 13: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } - return newMsg; - default: - break; - } - - // simple colors - return "##" + toString(mChatColor - 1) + msg; -} - -void ChatWindow::autoComplete() -{ - int caretPos = mChatInput->getCaretPosition(); - int startName = 0; - const std::string inputText = mChatInput->getText(); - std::string name = inputText.substr(0, caretPos); - std::string newName(""); - - for (int f = caretPos - 1; f > -1; f --) - { - if (isWordSeparator(inputText[f])) - { - startName = f + 1; - name = inputText.substr(f + 1, caretPos - f); - break; - } - } - - if (caretPos - 1 + 1 == startName) - return; - - ChatTab *cTab = static_cast(mChatTabs->getSelectedTab()); - std::vector nameList; - - cTab->getAutoCompleteList(nameList); - newName = autoComplete(nameList, name); - - if (newName == "" && actorSpriteManager) - { - actorSpriteManager->getPlayerNames(nameList, true); - newName = autoComplete(nameList, name); - } - if (newName == "") - newName = autoCompleteHistory(name); - if (newName == "" && spellManager) - newName = spellManager->autoComplete(name); - if (newName == "") - newName = autoCompleteCommands(name); - if (newName == "" && actorSpriteManager) - { - actorSpriteManager->getMobNames(nameList); - newName = autoComplete(nameList, name); - } - - if (newName != "") - { - mChatInput->setText(inputText.substr(0, startName) + newName - + inputText.substr(caretPos, inputText.length() - caretPos)); - - int len = caretPos - static_cast(name.length()) - + static_cast(newName.length()); - - if (startName > 0) - mChatInput->setCaretPosition(len + 1); - else - mChatInput->setCaretPosition(len); - } -} - -std::string ChatWindow::autoComplete(std::vector &names, - std::string partName) const -{ - std::vector::iterator i = names.begin(); - toLower(partName); - std::string newName(""); - - while (i != names.end()) - { - if (!i->empty()) - { - std::string name = *i; - toLower(name); - - std::string::size_type pos = name.find(partName, 0); - if (pos == 0) - { - if (newName != "") - { - toLower(newName); - newName = findSameSubstring(name, newName); - } - else - { - newName = *i; - } - } - } - ++i; - } - - return newName; -} - -std::string ChatWindow::autoCompleteCommands(std::string partName) -{ - Commands::iterator i = mCommands.begin(); - std::vector nameList; - - while (i != mCommands.end()) - { - std::string line = *i; - std::string::size_type pos = line.find(partName, 0); - if (pos == 0) - nameList.push_back(line); - ++i; - } - return autoComplete(nameList, partName); -} - -/* -void ChatWindow::moveTabLeft(ChatTab *tab) -{ - mChatTabs->moveLeft(tab); -} - -void ChatWindow::moveTabRight(ChatTab *tab) -{ - mChatTabs->moveRight(tab); -} -*/ - -std::string ChatWindow::autoCompleteHistory(std::string partName) -{ - History::iterator i = mHistory.begin(); - std::vector nameList; - - while (i != mHistory.end()) - { - std::string line = *i; - unsigned int f = 0; - while (f < line.length() && !isWordSeparator(line.at(f))) - f++; - - line = line.substr(0, f); - if (line != "") - nameList.push_back(line); - - ++i; - } - return autoComplete(nameList, partName); -} - -void ChatWindow::resortChatLog(std::string line, Own own, - bool ignoreRecord, bool tryRemoveColors) -{ - if (own == -1) - own = BY_SERVER; - - if (tradeChatTab) - { - if (findI(line, mTradeFilter) != std::string::npos) - { -// logger->log("trade: " + line); - tradeChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); - return; - } - - unsigned long idx = line.find(": \302\202"); - if (idx != std::string::npos) - { - line = line.erase(idx + 2, 2); - tradeChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); - return; - } - - unsigned long idx1 = line.find("@@"); - if (idx1 != std::string::npos) - { - unsigned long idx2 = line.find("|", idx1); - if (idx2 != std::string::npos) - { - unsigned long idx3 = line.find("@@", idx2); - if (idx3 != std::string::npos) - { - tradeChatTab->chatLog(line, own, ignoreRecord, - tryRemoveColors); - return; - } - } - } - } - - if (localChatTab) - localChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); -} - -void ChatWindow::battleChatLog(std::string line, Own own, - bool ignoreRecord, bool tryRemoveColors) -{ - if (own == -1) - own = BY_SERVER; - if (battleChatTab) - battleChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); - else if (debugChatTab) - debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); -} - -void ChatWindow::initTradeFilter() -{ - std::string tradeListName = Client::getServerConfigDirectory() - + "/tradefilter.txt"; - - std::ifstream tradeFile; - struct stat statbuf; - - if (!stat(tradeListName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) - { - tradeFile.open(tradeListName.c_str(), std::ios::in); - char line[100]; - while (tradeFile.getline(line, 100)) - { - std::string str = line; - if (!str.empty()) - mTradeFilter.push_back(str); - } - tradeFile.close(); - } -} - -void ChatWindow::updateOnline(std::set &onlinePlayers) -{ - TabMap::iterator iter; - const Party *party = 0; - const Guild *guild = 0; - if (player_node) - { - party = player_node->getParty(); - guild = player_node->getGuild(); - } - for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) - { - if (!iter->second) - return; - - WhisperTab *tab = static_cast(iter->second); - - if (!tab) - continue; - - if (onlinePlayers.find(tab->getNick()) != onlinePlayers.end()) - { - tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); - } - else - { - const std::string nick = tab->getNick(); - if (actorSpriteManager) - { - const Being *being = actorSpriteManager->findBeingByName( - nick, ActorSprite::PLAYER); - if (being) - { - tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); - continue; - } - } - if (party) - { - const PartyMember *pm = party->getMember(nick); - if (pm && pm->getOnline()) - { - tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); - continue; - } - } - if (guild) - { - const GuildMember *gm = guild->getMember(nick); - if (gm && gm->getOnline()) - { - tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); - continue; - } - } - tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER_OFFLINE)); - } - } -} - -void ChatWindow::loadState() -{ - int num = 0; - while (num < 50) - { - std::string nick = serverConfig.getValue( - "chatWhisper" + toString(num), ""); - - if (nick.empty()) - break; - int flags = serverConfig.getValue( - "chatWhisperFlags" + toString(num), 1); - - ChatTab *tab = addWhisperTab(nick); - if (tab) - { - tab->setAllowHighlight(flags & 1); - tab->setRemoveNames((flags & 2) / 2); - tab->setNoAway((flags & 4) / 4); - } - serverConfig.deleteKey("chatWhisper" + toString(num)); - serverConfig.deleteKey("chatWhisperFlags" + toString(num)); - num ++; - } - - while (num < 50) - { - serverConfig.deleteKey("chatWhisper" + toString(num)); - serverConfig.deleteKey("chatWhisperFlags" + toString(num)); - num ++; - } -} - -void ChatWindow::saveState() -{ - int num = 0; - TabMap::iterator iter; - for (iter = mWhispers.begin(); iter != mWhispers.end() && num < 50; ++iter) - { - if (!iter->second) - return; - - WhisperTab *tab = static_cast(iter->second); - - if (!tab) - continue; - - serverConfig.setValue("chatWhisper" + toString(num), - tab->getNick()); - - serverConfig.setValue("chatWhisperFlags" + toString(num), - static_cast(tab->getAllowHighlight()) - + (2 * static_cast(tab->getRemoveNames())) - + (4 * static_cast(tab->getNoAway()))); - - num ++; - } - - while (num < 50) - { - serverConfig.deleteKey("chatWhisper" + toString(num)); - serverConfig.deleteKey("chatWhisperFlags" + toString(num)); - num ++; - } -} - -std::string ChatWindow::doReplace(const std::string &msg) -{ - if (Client::getServerName() == "server.themanaworld.org" - || Client::getServerName() == "themanaworld.org" - || Client::getServerName() == "81.161.192.4") - { - return msg; - } - - std::string str = msg; - replaceSpecialChars(str); - return str; -} diff --git a/src/gui/chat.h b/src/gui/chat.h deleted file mode 100644 index 58405405d..000000000 --- a/src/gui/chat.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#ifndef CHAT_H -#define CHAT_H - -#include "listener.h" - -#include "gui/widgets/window.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -class BrowserBox; -class ChatTab; -class Channel; -class ChatInput; -class ColorListModel; -class ScrollArea; -class TabbedArea; -class ItemLinkHandler; -class Tab; -class WhisperTab; - -#define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'. - -enum Own -{ - BY_GM = 0, - BY_PLAYER, - BY_OTHER, - BY_SERVER, - BY_CHANNEL, - ACT_WHISPER, // getting whispered at - ACT_IS, // equivalent to "/me" on IRC - BY_LOGGER, - BY_UNKNOWN = -1 -}; - -/** One item in the chat log */ -struct CHATLOG -{ - std::string nick; - std::string text; - Own own; -}; - -/** - * The chat window. - * - * \ingroup Interface - */ -class ChatWindow : public Window, - public gcn::ActionListener, - public gcn::KeyListener, - public Mana::Listener -{ - public: - /** - * Constructor. - */ - ChatWindow(); - - /** - * Destructor: used to write back values to the config file - */ - ~ChatWindow(); - - /** - * Reset the chat window to default positions. - */ - void resetToDefaultSize(); - - /** - * Gets the focused tab. - */ - ChatTab *getFocused() const; - - /** - * Clear the given tab. - */ - void clearTab(ChatTab *tab); - - /** - * Clear the current tab. - */ - void clearTab(); - - /** - * Switch to the previous tab in order - */ - void prevTab(); - - /** - * Switch to the next tab in order - */ - void nextTab(); - - /** - * Switch to the default tab - */ - void defaultTab(); - - /** - * Performs action. - */ - void action(const gcn::ActionEvent &event); - - /** - * Request focus for typing chat message. - * - * \returns true if the input was shown - * false otherwise - */ - bool requestChatFocus(); - - /** - * Checks whether ChatWindow is Focused or not. - */ - bool isInputFocused() const; - - /** - * Passes the text to the current tab as input - * - * @param msg The message text which is to be sent. - */ - void chatInput(const std::string &msg); - - /** - * Passes the text to the local chat tab as input - * - * @param msg The message text which is to be sent. - */ - void localChatInput(const std::string &msg); - - /** Called when key is pressed */ - void keyPressed(gcn::KeyEvent &event); - - /** Set the chat input as the given text. */ - void setInputText(const std::string &text); - - /** Add the given text to the chat input. */ - void addInputText(const std::string &text, bool space = true); - - /** Called to add item to chat */ - void addItemText(const std::string &item); - - /** Override to reset mTmpVisible */ - void setVisible(bool visible); - - /** - * Handles mouse when dragged. - */ - void mouseDragged(gcn::MouseEvent &event); - - /** - * Handles mouse when pressed. - */ - void mousePressed(gcn::MouseEvent &event); - - void event(Channels channel, const Mana::Event &event); - - /** - * 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); - - /** - * Sets the file being recorded to - * - * @param msg The file to write out to. If null, then stop recording. - */ - void setRecordingFile(const std::string &msg); - - bool getReturnTogglesChat() const - { return mReturnToggles; } - - void setReturnTogglesChat(bool toggles) - { mReturnToggles = toggles; } - - void doPresent(); - - void whisper(const std::string &nick, const std::string &mes, - Own own = BY_OTHER); - - ChatTab *addWhisperTab(const std::string &nick, bool switchTo = false); - - ChatTab *getWhisperTab(const std::string &nick) const; - - void removeAllWhispers(); - - void ignoreAllWhispers(); - - void resortChatLog(std::string line, Own own = BY_UNKNOWN, - bool ignoreRecord = false, - bool tryRemoveColors = true); - - void battleChatLog(std::string line, Own own = BY_UNKNOWN, - bool ignoreRecord = false, - bool tryRemoveColors = true); - - void updateOnline(std::set &onlinePlayers); - - void loadState(); - - void saveState(); - - std::string doReplace(const std::string &msg); - - protected: - friend class ChatTab; - friend class WhisperTab; - friend class PopupMenu; - - /** Remove the given tab from the window */ - void removeTab(ChatTab *tab); - - /** Add the tab to the window */ - void addTab(ChatTab *tab); - - void removeWhisper(const std::string &nick); - - void adjustTabSize(); - - void autoComplete(); - - std::string addColors(std::string &msg); - - std::string autoCompleteHistory(std::string partName); - - std::string autoCompleteCommands(std::string partName); - - std::string autoComplete(std::vector &names, - std::string partName) const; - - /** Used for showing item popup on clicking links **/ - ItemLinkHandler *mItemLinkHandler; - - /** Input box for typing chat messages. */ - ChatInput *mChatInput; - - void widgetResized(const gcn::Event &event); - - void initTradeFilter(); - - int mRainbowColor; - - private: - void fillCommands(); - - bool mTmpVisible; - - /** Tabbed area for holding each channel. */ - TabbedArea *mChatTabs; - - typedef std::map TabMap; - /** Manage whisper tabs */ - TabMap mWhispers; - - typedef std::list History; - typedef History::iterator HistoryIterator; - History mHistory; /**< Command history. */ - HistoryIterator mCurHist; /**< History iterator. */ - - typedef std::list Commands; - typedef Commands::iterator CommandsIterator; - History mCommands; /**< Command list. */ - - bool mReturnToggles; /**< Marks whether toggles the chat log - or not */ - - std::list mTradeFilter; - - gcn::DropDown *mColorPicker; - ColorListModel *mColorListModel; - int mChatColor; - unsigned int mChatHistoryIndex; -}; - -extern ChatWindow *chatWindow; - -#endif diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp new file mode 100644 index 000000000..1e530ecba --- /dev/null +++ b/src/gui/chatwindow.cpp @@ -0,0 +1,1416 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#include "chatwindow.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "guild.h" +#include "keyboardconfig.h" +#include "localplayer.h" +#include "party.h" +#include "playerinfo.h" +#include "playerrelations.h" +#include "spellshortcut.h" +#include "sound.h" + +#include "gui/setup.h" +#include "gui/sdlinput.h" +#include "gui/theme.h" +#include "gui/viewport.h" + +#include "gui/widgets/battletab.h" +#include "gui/widgets/chattab.h" +#include "gui/widgets/dropdown.h" +#include "gui/widgets/itemlinkhandler.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/tabbedarea.h" +#include "gui/widgets/textfield.h" +#include "gui/widgets/tradetab.h" +#include "gui/widgets/whispertab.h" + +#include "net/chathandler.h" +#include "net/playerhandler.h" +#include "net/net.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include +#include + +#include + +#include + +/** + * The chat input hides when it loses focus. It is also invisible by default. + */ +class ChatInput : public TextField, public gcn::FocusListener +{ + public: + ChatInput(): + TextField("", false) + { + setVisible(false); + addFocusListener(this); + } + + /** + * Called if the chat input loses focus. It will set itself to + * invisible as result. + */ + void focusLost(const gcn::Event &event _UNUSED_) + { + setVisible(false); + } +}; + +const char *COLOR_NAME[14] = +{ + N_("default"), + N_("black"), + N_("red"), + N_("green"), + N_("blue"), + N_("gold"), + N_("yellow"), + N_("pink"), + N_("purple"), + N_("grey"), + N_("brown"), + N_("rainbow 1"), + N_("rainbow 2"), + N_("rainbow 3"), +}; + + +class ColorListModel : public gcn::ListModel +{ +public: + virtual ~ColorListModel() { } + + virtual int getNumberOfElements() + { + return 14; + } + + virtual std::string getElementAt(int i) + { + if (i >= getNumberOfElements() || i < 0) + return _("???"); + + return gettext(COLOR_NAME[i]); + } +}; + +#define ACTION_COLOR_PICKER "color picker" + + +ChatWindow::ChatWindow(): + Window(_("Chat")), + mTmpVisible(false), + mChatHistoryIndex(0) +{ + listen(CHANNEL_NOTICES); + listen(CHANNEL_ATTRIBUTES); + + setWindowName("Chat"); + + if (setupWindow) + setupWindow->registerWindowForReset(this); + + // no title presented, title bar is padding so window can be moved. + gcn::Window::setTitleBarHeight(gcn::Window::getPadding() + 4); + setShowTitle(false); + setResizable(true); + setDefaultVisible(true); + setSaveVisible(true); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); + setMinWidth(150); + setMinHeight(90); + + mItemLinkHandler = new ItemLinkHandler; + + mChatInput = new ChatInput; + mChatInput->setActionEventId("chatinput"); + mChatInput->addActionListener(this); + + mChatTabs = new TabbedArea; + mChatTabs->enableScrollButtons(true); + + mChatColor = config.getIntValue("chatColor"); + mColorListModel = new ColorListModel; + mColorPicker = new DropDown(mColorListModel); + + mColorPicker->setActionEventId(ACTION_COLOR_PICKER); + mColorPicker->addActionListener(this); + mColorPicker->setSelected(mChatColor); + + add(mChatTabs); + add(mChatInput); + add(mColorPicker); + + loadWindowState(); + + mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth() + - 2*getPadding() - 8 - 16, getPadding()); + + // Add key listener to chat input to be able to respond to up/down + mChatInput->addKeyListener(this); + mCurHist = mHistory.end(); + + mReturnToggles = config.getBoolValue("ReturnToggles"); + + mRainbowColor = 0; + + mColorPicker->setVisible(config.getBoolValue("showChatColorsList")); + + fillCommands(); + initTradeFilter(); +} + +ChatWindow::~ChatWindow() +{ + config.setValue("ReturnToggles", mReturnToggles); + removeAllWhispers(); + delete mItemLinkHandler; + mItemLinkHandler = 0; + delete mColorPicker; + mColorPicker = 0; + delete mColorListModel; + mColorListModel = 0; +} + +void ChatWindow::fillCommands() +{ + mCommands.push_back("/all"); + mCommands.push_back("/away "); + mCommands.push_back("/closeall"); + mCommands.push_back("/clear"); + mCommands.push_back("/create "); + mCommands.push_back("/close"); + mCommands.push_back("/cacheinfo"); + mCommands.push_back("/erase "); + mCommands.push_back("/follow "); + mCommands.push_back("/heal "); + mCommands.push_back("/ignoreall"); + mCommands.push_back("/help"); + mCommands.push_back("/announce "); + mCommands.push_back("/where"); + mCommands.push_back("/who"); + mCommands.push_back("/msg "); + mCommands.push_back("/mail "); + mCommands.push_back("/whisper "); + mCommands.push_back("/w "); + mCommands.push_back("/query "); + mCommands.push_back("/ignore "); + mCommands.push_back("/unignore "); + mCommands.push_back("/join "); + mCommands.push_back("/list"); + mCommands.push_back("/party"); + mCommands.push_back("/createparty "); + mCommands.push_back("/createguild "); + mCommands.push_back("/me "); + mCommands.push_back("/toggle"); + mCommands.push_back("/present"); + mCommands.push_back("/quit"); + mCommands.push_back("/move "); + mCommands.push_back("/target "); + mCommands.push_back("/invite "); + mCommands.push_back("/leave"); + mCommands.push_back("/kick "); + mCommands.push_back("/item"); + mCommands.push_back("/imitation"); + mCommands.push_back("/exp"); + mCommands.push_back("/ping"); + mCommands.push_back("/outfit "); + mCommands.push_back("/emote "); + mCommands.push_back("/navigate "); + mCommands.push_back("/priceload"); + mCommands.push_back("/pricesave"); + mCommands.push_back("/trade "); + mCommands.push_back("/friend "); + mCommands.push_back("/befriend "); + mCommands.push_back("/disregard "); + mCommands.push_back("/neutral "); + mCommands.push_back("/raw "); + mCommands.push_back("/disconnect"); + mCommands.push_back("/undress "); + mCommands.push_back("/attack"); + mCommands.push_back("/dirs"); + mCommands.push_back("/info"); + mCommands.push_back("/wait"); + mCommands.push_back("/uptime"); +} + +void ChatWindow::resetToDefaultSize() +{ + Window::resetToDefaultSize(); +} + +void ChatWindow::adjustTabSize() +{ + const gcn::Rectangle area = getChildrenArea(); + + mChatInput->setPosition(mChatInput->getFrameSize(), + area.height - mChatInput->getHeight() - + mChatInput->getFrameSize()); + mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize()); + + mChatTabs->setWidth(area.width - 2 * mChatTabs->getFrameSize()); + mChatTabs->setHeight(area.height - 2 * mChatTabs->getFrameSize() - + (mChatInput->getHeight() + mChatInput->getFrameSize() * 2)); + + ChatTab *tab = getFocused(); + if (tab) + { + gcn::Widget *content = tab->mScrollArea; + if (content) + { + content->setSize(mChatTabs->getWidth() + - 2 * content->getFrameSize(), + mChatTabs->getContainerHeight() + - 2 * content->getFrameSize()); + content->logic(); + } + } + + mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth() + - 2*getPadding() - 8 - 16, getPadding()); + +// if (mColorPicker->isVisible()) +// mChatTabs->setRightMargin(mColorPicker->getWidth() - 8); +} + +void ChatWindow::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + + adjustTabSize(); +} + +/* +void ChatWindow::logic() +{ + Window::logic(); + + Tab *tab = getFocused(); + if (tab != mCurrentTab) + mCurrentTab = tab; +} +*/ + +ChatTab *ChatWindow::getFocused() const +{ + return static_cast(mChatTabs->getSelectedTab()); +} + +void ChatWindow::clearTab(ChatTab *tab) +{ + if (tab) + tab->clearText(); +} + +void ChatWindow::clearTab() +{ + clearTab(getFocused()); +} + +void ChatWindow::prevTab() +{ + if (!mChatTabs) + return; + + int tab = mChatTabs->getSelectedTabIndex(); + + if (tab == 0) + tab = mChatTabs->getNumberOfTabs(); + tab--; + + mChatTabs->setSelectedTab(tab); +} + +void ChatWindow::nextTab() +{ + if (!mChatTabs) + return; + + int tab = mChatTabs->getSelectedTabIndex(); + + tab++; + if (tab == mChatTabs->getNumberOfTabs()) + tab = 0; + + mChatTabs->setSelectedTab(tab); +} + +void ChatWindow::defaultTab() +{ + if (mChatTabs) + mChatTabs->setSelectedTab(static_cast(0)); +} + +void 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 + chatInput(addColors(message)); + + // Clear the text from the chat input + mChatInput->setText(""); + } + + if (message.empty() || !mReturnToggles) + { + // Remove focus and hide input + if (mFocusHandler) + mFocusHandler->focusNone(); + + // If the chatWindow is shown up because you want to send a message + // It should hide now + if (mTmpVisible) + setVisible(false); + } + } + else if (event.getId() == ACTION_COLOR_PICKER) + { + mChatColor = mColorPicker->getSelected(); + config.setValue("chatColor", mChatColor); + } + + if (mColorPicker && mColorPicker->isVisible() + != config.getBoolValue("showChatColorsList")) + { + mColorPicker->setVisible(config.getBoolValue( + "showChatColorsList")); + } +} + +bool 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; + } + + // Don't do anything else if the input is already visible and has focus + if (mChatInput->isVisible() && mChatInput->isFocused()) + return false; + + // Give focus to the chat input + mChatInput->setVisible(true); + mChatInput->requestFocus(); + return true; +} + +bool ChatWindow::isInputFocused() const +{ + return mChatInput->isFocused(); +} + +void ChatWindow::removeTab(ChatTab *tab) +{ + mChatTabs->removeTab(tab); +} + +void ChatWindow::addTab(ChatTab *tab) +{ + mChatTabs->addTab(tab, tab->mScrollArea); + + // Update UI + logic(); +} + +void ChatWindow::removeWhisper(const std::string &nick) +{ + std::string tempNick = nick; + toLower(tempNick); + mWhispers.erase(tempNick); +} + +void ChatWindow::removeAllWhispers() +{ + TabMap::iterator iter; + std::list tabs; + + for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) + tabs.push_back(iter->second); + + for (std::list::iterator it = tabs.begin(); + it != tabs.end(); ++it) + { + delete *it; + } + + mWhispers.clear(); +} + +void ChatWindow::ignoreAllWhispers() +{ + TabMap::iterator iter; + for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) + { + WhisperTab *tab = dynamic_cast(iter->second); + if (tab && player_relations.getRelation(tab->getNick()) + != PlayerRelation::IGNORED) + { + player_relations.setRelation(tab->getNick(), + PlayerRelation::IGNORED); + } + + delete(iter->second); + iter->second = 0; + } +} + +void ChatWindow::chatInput(const std::string &message) +{ + ChatTab *tab = NULL; + std::string msg = message; + trim(msg); + + if (config.getBoolValue("allowCommandsInChatTabs") + && msg.length() > 1 + && ((msg.at(0) == '#' && msg.at(1) != '#') || msg.at(0) == '@') + && localChatTab) + { + tab = localChatTab; + } + else + { + tab = getFocused(); + } + if (tab) + tab->chatInput(msg); + Game::instance()->setValidSpeed(); +} + +void ChatWindow::localChatInput(const std::string &msg) +{ + if (localChatTab) + localChatTab->chatInput(msg); + else + chatInput(msg); +} + +void ChatWindow::doPresent() +{ + if (!actorSpriteManager) + return; + + const ActorSprites &actors = actorSpriteManager->getAll(); + std::string response = ""; + int playercount = 0; + + for (ActorSpritesConstIterator it = actors.begin(), it_end = actors.end(); + it != it_end; ++it) + { + if ((*it)->getType() == ActorSprite::PLAYER) + { + if (!response.empty()) + response += ", "; + response += static_cast(*it)->getName(); + ++playercount; + } + } + + std::string log = strprintf(_("Present: %s; %d players are present."), + response.c_str(), playercount); + + if (getFocused()) + getFocused()->chatLog(log, BY_SERVER); +} + +void ChatWindow::scroll(int amount) +{ + if (!isVisible()) + return; + + ChatTab *tab = getFocused(); + if (tab) + tab->scroll(amount); +} + +void ChatWindow::mousePressed(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + if (viewport) + { + gcn::Tab *tab = mChatTabs->getSelectedTab(); + if (tab) + { + ChatTab *cTab = dynamic_cast(tab); + if (cTab) + viewport->showChatPopup(cTab); + } + } + } + + Window::mousePressed(event); + + if (event.isConsumed()) + return; + + if (event.getButton() == gcn::MouseEvent::LEFT) + { + ChatTab *tab = getFocused(); + if (tab) + mMoved = !isResizeAllowed(event); + } + + mDragOffsetX = event.getX(); + mDragOffsetY = event.getY(); +} + +void ChatWindow::mouseDragged(gcn::MouseEvent &event) +{ + Window::mouseDragged(event); + + if (event.isConsumed()) + return; + + if (isMovable() && mMoved) + { + int newX = std::max(0, getX() + event.getX() - mDragOffsetX); + int newY = std::max(0, getY() + event.getY() - mDragOffsetY); + newX = std::min(graphics->getWidth() - getWidth(), newX); + newY = std::min(graphics->getHeight() - getHeight(), newY); + setPosition(newX, newY); + } +} + +/* +void ChatWindow::mouseReleased(gcn::MouseEvent &event _UNUSED_) +{ + +} +*/ + +void ChatWindow::keyPressed(gcn::KeyEvent &event) +{ + if (event.getKey().getValue() == Key::DOWN) + { + if (mCurHist != mHistory.end()) + { + // Move forward through the history + HistoryIterator prevHist = mCurHist++; + + if (mCurHist != mHistory.end()) + { + mChatInput->setText(*mCurHist); + mChatInput->setCaretPosition(static_cast( + mChatInput->getText().length())); + } + else + { + mChatInput->setText(""); + mCurHist = prevHist; + } + } + else if (mChatInput->getText() != "") + { + mChatInput->setText(""); + } + } + else if (event.getKey().getValue() == Key::UP && + mCurHist != mHistory.begin() && !mHistory.empty()) + { + // Move backward through the history + --mCurHist; + mChatInput->setText(*mCurHist); + mChatInput->setCaretPosition(static_cast( + mChatInput->getText().length())); + } + else if (event.getKey().getValue() == Key::INSERT && + mChatInput->getText() != "") + { + // Add the current message to the history and clear the text + if (mHistory.empty() || mChatInput->getText() != mHistory.back()) + mHistory.push_back(mChatInput->getText()); + mCurHist = mHistory.end(); + mChatInput->setText(""); + } + else if (keyboard.isKeyActive(keyboard.KEY_AUTOCOMPLETE_CHAT) && + mChatInput->getText() != "") + { + autoComplete(); + return; + } + else if (keyboard.isKeyActive(keyboard.KEY_DEACTIVATE_CHAT) && + mChatInput->isVisible()) + { + mChatInput->setVisible(false); + } + else if (keyboard.isKeyActive(keyboard.KEY_CHAT_PREV_HISTORY) && + mChatInput->isVisible()) + { + ChatTab *tab = getFocused(); + if (tab && (unsigned)tab->getRows().size() > 0) + { + if (!mChatHistoryIndex) + { + mChatHistoryIndex = static_cast( + tab->getRows().size()); + + mChatInput->setText(""); + mChatInput->setCaretPosition(0); + return; + } + else + { + mChatHistoryIndex --; + } + + std::list::iterator it; + unsigned int f = 0; + for (it = tab->getRows().begin(); + it != tab->getRows().end(); ++it, f++) + { + if (f == mChatHistoryIndex) + mChatInput->setText(*it); + } + mChatInput->setCaretPosition(static_cast( + mChatInput->getText().length())); + } + } + else if (keyboard.isKeyActive(keyboard.KEY_CHAT_NEXT_HISTORY) && + mChatInput->isVisible()) + { + ChatTab *tab = getFocused(); + if (tab && !tab->getRows().empty()) + { + if (mChatHistoryIndex + 1 < tab->getRows().size()) + { + mChatHistoryIndex ++; + } + else if (mChatHistoryIndex < tab->getRows().size()) + { + mChatHistoryIndex ++; + mChatInput->setText(""); + mChatInput->setCaretPosition(0); + return; + } + else + { + mChatHistoryIndex = 0; + } + + std::list::iterator it; + unsigned int f = 0; + for (it = tab->getRows().begin(); + it != tab->getRows().end(); ++it, f++) + { + if (f == mChatHistoryIndex) + mChatInput->setText(*it); + } + mChatInput->setCaretPosition(static_cast( + mChatInput->getText().length())); + } + } + + std::string Temp; + switch (event.getKey().getValue()) + { + case Key::F2: Temp = "\u2318"; break; + case Key::F3: Temp = "\u263A"; break; + case Key::F4: Temp = "\u2665"; break; + case Key::F5: Temp = "\u266A"; break; + case Key::F6: Temp = "\u266B"; break; + case Key::F7: Temp = "\u26A0"; break; + case Key::F8: Temp = "\u2622"; break; + case Key::F9: Temp = "\u262E"; break; + case Key::F10: Temp = "\u2605"; break; + case Key::F11: Temp = "\u2618"; break; + case Key::F12: Temp = "\u2592"; break; + default: break; + } + + if (Temp != "") + addInputText(Temp, false); +} + +void ChatWindow::event(Channels channel, const Mana::Event &event) +{ + if (channel == CHANNEL_NOTICES) + { + if (event.getName() == EVENT_SERVERNOTICE && localChatTab) + localChatTab->chatLog(event.getString("message"), BY_SERVER); + } + else if (channel == CHANNEL_ATTRIBUTES) + { + if (!config.getBoolValue("showBattleEvents")) + return; + + if (event.getName() == EVENT_UPDATEATTRIBUTE) + { + switch (event.getInt("id")) + { + case EXP: + { + if (event.getInt("oldValue") > event.getInt("newValue")) + break; + + int change = event.getInt("newValue") + - event.getInt("oldValue"); + + if (change != 0) + battleChatLog("+" + toString(change) + " xp"); + break; + } + case LEVEL: + battleChatLog("Level: " + toString( + event.getInt("newValue"))); + break; + default: + break; + }; + } + else if (event.getName() == EVENT_UPDATESTAT) + { + if (!config.getBoolValue("showJobExp")) + return; + + int id = event.getInt("id"); + if (id == Net::getPlayerHandler()->getJobLocation()) + { + std::pair exp + = PlayerInfo::getStatExperience(id); + if (event.getInt("oldValue1") > exp.first + || !event.getInt("oldValue2")) + { + return; + } + + int change = exp.first - event.getInt("oldValue1"); + if (change != 0) + battleChatLog("+" + toString(change) + " job"); + } + } + } +} + +void ChatWindow::addInputText(const std::string &text, bool space) +{ + int caretPos = mChatInput->getCaretPosition(); + const std::string inputText = mChatInput->getText(); + + std::ostringstream ss; + ss << inputText.substr(0, caretPos) << text; + if (space) + ss << " "; + + ss << inputText.substr(caretPos); + + mChatInput->setText(ss.str()); + mChatInput->setCaretPosition(caretPos + static_cast( + text.length()) + static_cast(space)); + requestChatFocus(); +} + +void ChatWindow::addItemText(const std::string &item) +{ + std::ostringstream text; + text << "[" << item << "]"; + addInputText(text.str()); +} + +void ChatWindow::setVisible(bool isVisible) +{ + Window::setVisible(isVisible); + + /* + * For whatever reason, if setVisible is called, the mTmpVisible effect + * should be disabled. + */ + mTmpVisible = false; +} + +void ChatWindow::whisper(const std::string &nick, + const std::string &mes, Own own) +{ + if (mes.empty() || !player_node) + return; + + std::string playerName = player_node->getName(); + std::string tempNick = nick; + + toLower(playerName); + toLower(tempNick); + + if (tempNick.compare(playerName) == 0) + return; + + ChatTab *tab = 0; + TabMap::const_iterator i = mWhispers.find(tempNick); + + if (i != mWhispers.end()) + tab = i->second; + else if (config.getBoolValue("whispertab")) + tab = addWhisperTab(nick); + + if (tab) + { + if (own == BY_PLAYER) + { + tab->chatInput(mes); + } + else if (own == BY_SERVER) + { + tab->chatLog(mes); + } + else + { + if (tab->getRemoveNames()) + { + std::string msg = mes; + std::string nick2; + int idx = mes.find(":"); + if (idx > 0) + { + nick2 = msg.substr(0, idx); + msg = msg.substr(idx + 1); + nick2 = removeColors(nick2); + nick2 = trim(nick2); + msg = trim(msg); + tab->chatLog(nick2, msg); + } + else + { + tab->chatLog(nick, mes); + } + } + else + { + tab->chatLog(nick, mes); + } + player_node->afkRespond(tab, nick); + } + } + else if (localChatTab) + { + if (own == BY_PLAYER) + { + Net::getChatHandler()->privateMessage(nick, mes); + + localChatTab->chatLog(strprintf(_("Whispering to %s: %s"), + nick.c_str(), mes.c_str()), BY_PLAYER); + } + else + { + localChatTab->chatLog(nick + " : " + mes, ACT_WHISPER, false); + if (player_node) + player_node->afkRespond(0, nick); + } + } +} + +ChatTab *ChatWindow::addWhisperTab(const std::string &nick, bool switchTo) +{ + if (!player_node) + return NULL; + + std::string playerName = player_node->getName(); + std::string tempNick = nick; + + toLower(playerName); + toLower(tempNick); + + TabMap::const_iterator i = mWhispers.find(tempNick); + ChatTab *ret; + + if (tempNick.compare(playerName) == 0) + return NULL; + + if (i != mWhispers.end()) + { + ret = i->second; + } + else + { + ret = new WhisperTab(nick); + mWhispers[tempNick] = ret; + if (config.getBoolValue("showChatHistory")) + ret->loadFromLogFile(nick); + } + + if (switchTo) + mChatTabs->setSelectedTab(ret); + + return ret; +} + +ChatTab *ChatWindow::getWhisperTab(const std::string &nick) const +{ + if (!player_node) + return NULL; + + std::string playerName = player_node->getName(); + std::string tempNick = nick; + + toLower(playerName); + toLower(tempNick); + + TabMap::const_iterator i = mWhispers.find(tempNick); + ChatTab *ret = 0; + + if (tempNick.compare(playerName) == 0) + return NULL; + + if (i != mWhispers.end()) + ret = i->second; + + return ret; +} + +std::string ChatWindow::addColors(std::string &msg) +{ + // default color or chat command + if (mChatColor == 0 || msg.length() == 0 || msg.at(0) == '#' + || msg.at(0) == '/' || msg.at(0) == '@' || msg.at(0) == '!') + { + return msg; + } + + std::string newMsg = ""; + int cMap[] = {1, 4, 5, 2, 3, 6, 7, 9, 0, 8}; + + // rainbow + switch(mChatColor) + { + case 11: + msg = removeColors(msg); + for (unsigned int f = 0; f < msg.length(); f ++) + { + newMsg += "##" + toString(mRainbowColor++) + msg.at(f); + if (mRainbowColor > 9) + mRainbowColor = 0; + } + return newMsg; + case 12: + msg = removeColors(msg); + for (unsigned int f = 0; f < msg.length(); f ++) + { + newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f); + if (mRainbowColor > 9) + mRainbowColor = 0; + } + return newMsg; + case 13: + msg = removeColors(msg); + for (unsigned int f = 0; f < msg.length(); f ++) + { + newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f); + if (mRainbowColor > 9) + mRainbowColor = 0; + } + return newMsg; + default: + break; + } + + // simple colors + return "##" + toString(mChatColor - 1) + msg; +} + +void ChatWindow::autoComplete() +{ + int caretPos = mChatInput->getCaretPosition(); + int startName = 0; + const std::string inputText = mChatInput->getText(); + std::string name = inputText.substr(0, caretPos); + std::string newName(""); + + for (int f = caretPos - 1; f > -1; f --) + { + if (isWordSeparator(inputText[f])) + { + startName = f + 1; + name = inputText.substr(f + 1, caretPos - f); + break; + } + } + + if (caretPos - 1 + 1 == startName) + return; + + ChatTab *cTab = static_cast(mChatTabs->getSelectedTab()); + std::vector nameList; + + cTab->getAutoCompleteList(nameList); + newName = autoComplete(nameList, name); + + if (newName == "" && actorSpriteManager) + { + actorSpriteManager->getPlayerNames(nameList, true); + newName = autoComplete(nameList, name); + } + if (newName == "") + newName = autoCompleteHistory(name); + if (newName == "" && spellManager) + newName = spellManager->autoComplete(name); + if (newName == "") + newName = autoCompleteCommands(name); + if (newName == "" && actorSpriteManager) + { + actorSpriteManager->getMobNames(nameList); + newName = autoComplete(nameList, name); + } + + if (newName != "") + { + mChatInput->setText(inputText.substr(0, startName) + newName + + inputText.substr(caretPos, inputText.length() - caretPos)); + + int len = caretPos - static_cast(name.length()) + + static_cast(newName.length()); + + if (startName > 0) + mChatInput->setCaretPosition(len + 1); + else + mChatInput->setCaretPosition(len); + } +} + +std::string ChatWindow::autoComplete(std::vector &names, + std::string partName) const +{ + std::vector::iterator i = names.begin(); + toLower(partName); + std::string newName(""); + + while (i != names.end()) + { + if (!i->empty()) + { + std::string name = *i; + toLower(name); + + std::string::size_type pos = name.find(partName, 0); + if (pos == 0) + { + if (newName != "") + { + toLower(newName); + newName = findSameSubstring(name, newName); + } + else + { + newName = *i; + } + } + } + ++i; + } + + return newName; +} + +std::string ChatWindow::autoCompleteCommands(std::string partName) +{ + Commands::iterator i = mCommands.begin(); + std::vector nameList; + + while (i != mCommands.end()) + { + std::string line = *i; + std::string::size_type pos = line.find(partName, 0); + if (pos == 0) + nameList.push_back(line); + ++i; + } + return autoComplete(nameList, partName); +} + +/* +void ChatWindow::moveTabLeft(ChatTab *tab) +{ + mChatTabs->moveLeft(tab); +} + +void ChatWindow::moveTabRight(ChatTab *tab) +{ + mChatTabs->moveRight(tab); +} +*/ + +std::string ChatWindow::autoCompleteHistory(std::string partName) +{ + History::iterator i = mHistory.begin(); + std::vector nameList; + + while (i != mHistory.end()) + { + std::string line = *i; + unsigned int f = 0; + while (f < line.length() && !isWordSeparator(line.at(f))) + f++; + + line = line.substr(0, f); + if (line != "") + nameList.push_back(line); + + ++i; + } + return autoComplete(nameList, partName); +} + +void ChatWindow::resortChatLog(std::string line, Own own, + bool ignoreRecord, bool tryRemoveColors) +{ + if (own == -1) + own = BY_SERVER; + + if (tradeChatTab) + { + if (findI(line, mTradeFilter) != std::string::npos) + { +// logger->log("trade: " + line); + tradeChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); + return; + } + + unsigned long idx = line.find(": \302\202"); + if (idx != std::string::npos) + { + line = line.erase(idx + 2, 2); + tradeChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); + return; + } + + unsigned long idx1 = line.find("@@"); + if (idx1 != std::string::npos) + { + unsigned long idx2 = line.find("|", idx1); + if (idx2 != std::string::npos) + { + unsigned long idx3 = line.find("@@", idx2); + if (idx3 != std::string::npos) + { + tradeChatTab->chatLog(line, own, ignoreRecord, + tryRemoveColors); + return; + } + } + } + } + + if (localChatTab) + localChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); +} + +void ChatWindow::battleChatLog(std::string line, Own own, + bool ignoreRecord, bool tryRemoveColors) +{ + if (own == -1) + own = BY_SERVER; + if (battleChatTab) + battleChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); + else if (debugChatTab) + debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); +} + +void ChatWindow::initTradeFilter() +{ + std::string tradeListName = Client::getServerConfigDirectory() + + "/tradefilter.txt"; + + std::ifstream tradeFile; + struct stat statbuf; + + if (!stat(tradeListName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + { + tradeFile.open(tradeListName.c_str(), std::ios::in); + char line[100]; + while (tradeFile.getline(line, 100)) + { + std::string str = line; + if (!str.empty()) + mTradeFilter.push_back(str); + } + tradeFile.close(); + } +} + +void ChatWindow::updateOnline(std::set &onlinePlayers) +{ + TabMap::iterator iter; + const Party *party = 0; + const Guild *guild = 0; + if (player_node) + { + party = player_node->getParty(); + guild = player_node->getGuild(); + } + for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) + { + if (!iter->second) + return; + + WhisperTab *tab = static_cast(iter->second); + + if (!tab) + continue; + + if (onlinePlayers.find(tab->getNick()) != onlinePlayers.end()) + { + tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); + } + else + { + const std::string nick = tab->getNick(); + if (actorSpriteManager) + { + const Being *being = actorSpriteManager->findBeingByName( + nick, ActorSprite::PLAYER); + if (being) + { + tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); + continue; + } + } + if (party) + { + const PartyMember *pm = party->getMember(nick); + if (pm && pm->getOnline()) + { + tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); + continue; + } + } + if (guild) + { + const GuildMember *gm = guild->getMember(nick); + if (gm && gm->getOnline()) + { + tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER)); + continue; + } + } + tab->setTabColor(&Theme::getThemeColor(Theme::WHISPER_OFFLINE)); + } + } +} + +void ChatWindow::loadState() +{ + int num = 0; + while (num < 50) + { + std::string nick = serverConfig.getValue( + "chatWhisper" + toString(num), ""); + + if (nick.empty()) + break; + int flags = serverConfig.getValue( + "chatWhisperFlags" + toString(num), 1); + + ChatTab *tab = addWhisperTab(nick); + if (tab) + { + tab->setAllowHighlight(flags & 1); + tab->setRemoveNames((flags & 2) / 2); + tab->setNoAway((flags & 4) / 4); + } + serverConfig.deleteKey("chatWhisper" + toString(num)); + serverConfig.deleteKey("chatWhisperFlags" + toString(num)); + num ++; + } + + while (num < 50) + { + serverConfig.deleteKey("chatWhisper" + toString(num)); + serverConfig.deleteKey("chatWhisperFlags" + toString(num)); + num ++; + } +} + +void ChatWindow::saveState() +{ + int num = 0; + TabMap::iterator iter; + for (iter = mWhispers.begin(); iter != mWhispers.end() && num < 50; ++iter) + { + if (!iter->second) + return; + + WhisperTab *tab = static_cast(iter->second); + + if (!tab) + continue; + + serverConfig.setValue("chatWhisper" + toString(num), + tab->getNick()); + + serverConfig.setValue("chatWhisperFlags" + toString(num), + static_cast(tab->getAllowHighlight()) + + (2 * static_cast(tab->getRemoveNames())) + + (4 * static_cast(tab->getNoAway()))); + + num ++; + } + + while (num < 50) + { + serverConfig.deleteKey("chatWhisper" + toString(num)); + serverConfig.deleteKey("chatWhisperFlags" + toString(num)); + num ++; + } +} + +std::string ChatWindow::doReplace(const std::string &msg) +{ + if (Client::getServerName() == "server.themanaworld.org" + || Client::getServerName() == "themanaworld.org" + || Client::getServerName() == "81.161.192.4") + { + return msg; + } + + std::string str = msg; + replaceSpecialChars(str); + return str; +} diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h new file mode 100644 index 000000000..97f586442 --- /dev/null +++ b/src/gui/chatwindow.h @@ -0,0 +1,319 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#ifndef CHATWINDOW_H +#define CHATWINDOW_H + +#include "listener.h" + +#include "gui/widgets/window.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +class BrowserBox; +class ChatTab; +class Channel; +class ChatInput; +class ColorListModel; +class ScrollArea; +class TabbedArea; +class ItemLinkHandler; +class Tab; +class WhisperTab; + +#define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'. + +enum Own +{ + BY_GM = 0, + BY_PLAYER, + BY_OTHER, + BY_SERVER, + BY_CHANNEL, + ACT_WHISPER, // getting whispered at + ACT_IS, // equivalent to "/me" on IRC + BY_LOGGER, + BY_UNKNOWN = -1 +}; + +/** One item in the chat log */ +struct CHATLOG +{ + std::string nick; + std::string text; + Own own; +}; + +/** + * The chat window. + * + * \ingroup Interface + */ +class ChatWindow : public Window, + public gcn::ActionListener, + public gcn::KeyListener, + public Mana::Listener +{ + public: + /** + * Constructor. + */ + ChatWindow(); + + /** + * Destructor: used to write back values to the config file + */ + ~ChatWindow(); + + /** + * Reset the chat window to default positions. + */ + void resetToDefaultSize(); + + /** + * Gets the focused tab. + */ + ChatTab *getFocused() const; + + /** + * Clear the given tab. + */ + void clearTab(ChatTab *tab); + + /** + * Clear the current tab. + */ + void clearTab(); + + /** + * Switch to the previous tab in order + */ + void prevTab(); + + /** + * Switch to the next tab in order + */ + void nextTab(); + + /** + * Switch to the default tab + */ + void defaultTab(); + + /** + * Performs action. + */ + void action(const gcn::ActionEvent &event); + + /** + * Request focus for typing chat message. + * + * \returns true if the input was shown + * false otherwise + */ + bool requestChatFocus(); + + /** + * Checks whether ChatWindow is Focused or not. + */ + bool isInputFocused() const; + + /** + * Passes the text to the current tab as input + * + * @param msg The message text which is to be sent. + */ + void chatInput(const std::string &msg); + + /** + * Passes the text to the local chat tab as input + * + * @param msg The message text which is to be sent. + */ + void localChatInput(const std::string &msg); + + /** Called when key is pressed */ + void keyPressed(gcn::KeyEvent &event); + + /** Set the chat input as the given text. */ + void setInputText(const std::string &text); + + /** Add the given text to the chat input. */ + void addInputText(const std::string &text, bool space = true); + + /** Called to add item to chat */ + void addItemText(const std::string &item); + + /** Override to reset mTmpVisible */ + void setVisible(bool visible); + + /** + * Handles mouse when dragged. + */ + void mouseDragged(gcn::MouseEvent &event); + + /** + * Handles mouse when pressed. + */ + void mousePressed(gcn::MouseEvent &event); + + void event(Channels channel, const Mana::Event &event); + + /** + * 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); + + /** + * Sets the file being recorded to + * + * @param msg The file to write out to. If null, then stop recording. + */ + void setRecordingFile(const std::string &msg); + + bool getReturnTogglesChat() const + { return mReturnToggles; } + + void setReturnTogglesChat(bool toggles) + { mReturnToggles = toggles; } + + void doPresent(); + + void whisper(const std::string &nick, const std::string &mes, + Own own = BY_OTHER); + + ChatTab *addWhisperTab(const std::string &nick, bool switchTo = false); + + ChatTab *getWhisperTab(const std::string &nick) const; + + void removeAllWhispers(); + + void ignoreAllWhispers(); + + void resortChatLog(std::string line, Own own = BY_UNKNOWN, + bool ignoreRecord = false, + bool tryRemoveColors = true); + + void battleChatLog(std::string line, Own own = BY_UNKNOWN, + bool ignoreRecord = false, + bool tryRemoveColors = true); + + void updateOnline(std::set &onlinePlayers); + + void loadState(); + + void saveState(); + + std::string doReplace(const std::string &msg); + + protected: + friend class ChatTab; + friend class WhisperTab; + friend class PopupMenu; + + /** Remove the given tab from the window */ + void removeTab(ChatTab *tab); + + /** Add the tab to the window */ + void addTab(ChatTab *tab); + + void removeWhisper(const std::string &nick); + + void adjustTabSize(); + + void autoComplete(); + + std::string addColors(std::string &msg); + + std::string autoCompleteHistory(std::string partName); + + std::string autoCompleteCommands(std::string partName); + + std::string autoComplete(std::vector &names, + std::string partName) const; + + /** Used for showing item popup on clicking links **/ + ItemLinkHandler *mItemLinkHandler; + + /** Input box for typing chat messages. */ + ChatInput *mChatInput; + + void widgetResized(const gcn::Event &event); + + void initTradeFilter(); + + int mRainbowColor; + + private: + void fillCommands(); + + bool mTmpVisible; + + /** Tabbed area for holding each channel. */ + TabbedArea *mChatTabs; + + typedef std::map TabMap; + /** Manage whisper tabs */ + TabMap mWhispers; + + typedef std::list History; + typedef History::iterator HistoryIterator; + History mHistory; /**< Command history. */ + HistoryIterator mCurHist; /**< History iterator. */ + + typedef std::list Commands; + typedef Commands::iterator CommandsIterator; + History mCommands; /**< Command list. */ + + bool mReturnToggles; /**< Marks whether toggles the chat log + or not */ + + std::list mTradeFilter; + + gcn::DropDown *mColorPicker; + ColorListModel *mColorListModel; + int mChatColor; + unsigned int mChatHistoryIndex; +}; + +extern ChatWindow *chatWindow; + +#endif diff --git a/src/gui/help.cpp b/src/gui/help.cpp deleted file mode 100644 index 40996d2b0..000000000 --- a/src/gui/help.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "gui/help.h" - -#include "gui/gui.h" -#include "gui/setup.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/browserbox.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/scrollarea.h" - -#include "resources/resourcemanager.h" -#include "configuration.h" - -#include "utils/gettext.h" - -HelpWindow::HelpWindow(): - Window(_("Help")) -{ - setMinWidth(300); - setMinHeight(250); - setContentSize(455, 350); - setWindowName("Help"); - setResizable(true); - setupWindow->registerWindowForReset(this); - - setDefaultSize(500, 400, ImageRect::CENTER); - - mBrowserBox = new BrowserBox; - mBrowserBox->setOpaque(false); - mScrollArea = new ScrollArea(mBrowserBox); - Button *okButton = new Button(_("Close"), "close", this); - - mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, - 335 - okButton->getHeight())); - okButton->setPosition(450 - okButton->getWidth(), - 345 - okButton->getHeight()); - - mBrowserBox->setLinkHandler(this); - mBrowserBox->setFont(gui->getHelpFont()); - - place(0, 0, mScrollArea, 5, 3).setPadding(3); - place(4, 3, okButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - loadWindowState(); -} - -void HelpWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "close") - setVisible(false); -} - -void HelpWindow::handleLink(const std::string &link, - gcn::MouseEvent *event _UNUSED_) -{ - std::string helpFile = link; - loadHelp(helpFile); -} - -void HelpWindow::loadHelp(const std::string &helpFile) -{ - mBrowserBox->clearRows(); - - loadFile("header"); - loadFile(helpFile); - - mScrollArea->setVerticalScrollAmount(0); - setVisible(true); -} - -void HelpWindow::loadFile(const std::string &file) -{ - ResourceManager *resman = ResourceManager::getInstance(); - std::string helpPath = branding.getStringValue("helpPath"); - if (helpPath.empty()) - helpPath = paths.getStringValue("help"); - std::vector lines = - resman->loadTextFile(helpPath + file + ".txt"); - - for (unsigned int i = 0; i < lines.size(); ++i) - mBrowserBox->addRow(lines[i]); -} diff --git a/src/gui/help.h b/src/gui/help.h deleted file mode 100644 index 7b74edab4..000000000 --- a/src/gui/help.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#ifndef HELP_H -#define HELP_H - -#include "gui/widgets/linkhandler.h" -#include "gui/widgets/window.h" - -#include - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -class BrowserBox; -class LinkHandler; - -/** - * The help dialog. - */ -class HelpWindow : public Window, public LinkHandler, - public gcn::ActionListener -{ - public: - /** - * Constructor. - */ - HelpWindow(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Handles link action. - */ - void handleLink(const std::string &link, - gcn::MouseEvent *event _UNUSED_); - - /** - * Loads help in the dialog. - */ - void loadHelp(const std::string &helpFile); - - private: - void loadFile(const std::string &file); - - BrowserBox *mBrowserBox; - gcn::ScrollArea *mScrollArea; -}; - -extern HelpWindow *helpWindow; - -#endif diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp new file mode 100644 index 000000000..c67fa8424 --- /dev/null +++ b/src/gui/helpwindow.cpp @@ -0,0 +1,107 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#include "gui/helpwindow.h" + +#include "gui/gui.h" +#include "gui/setup.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/browserbox.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/scrollarea.h" + +#include "resources/resourcemanager.h" +#include "configuration.h" + +#include "utils/gettext.h" + +HelpWindow::HelpWindow(): + Window(_("Help")) +{ + setMinWidth(300); + setMinHeight(250); + setContentSize(455, 350); + setWindowName("Help"); + setResizable(true); + setupWindow->registerWindowForReset(this); + + setDefaultSize(500, 400, ImageRect::CENTER); + + mBrowserBox = new BrowserBox; + mBrowserBox->setOpaque(false); + mScrollArea = new ScrollArea(mBrowserBox); + Button *okButton = new Button(_("Close"), "close", this); + + mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, + 335 - okButton->getHeight())); + okButton->setPosition(450 - okButton->getWidth(), + 345 - okButton->getHeight()); + + mBrowserBox->setLinkHandler(this); + mBrowserBox->setFont(gui->getHelpFont()); + + place(0, 0, mScrollArea, 5, 3).setPadding(3); + place(4, 3, okButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + + loadWindowState(); +} + +void HelpWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "close") + setVisible(false); +} + +void HelpWindow::handleLink(const std::string &link, + gcn::MouseEvent *event _UNUSED_) +{ + std::string helpFile = link; + loadHelp(helpFile); +} + +void HelpWindow::loadHelp(const std::string &helpFile) +{ + mBrowserBox->clearRows(); + + loadFile("header"); + loadFile(helpFile); + + mScrollArea->setVerticalScrollAmount(0); + setVisible(true); +} + +void HelpWindow::loadFile(const std::string &file) +{ + ResourceManager *resman = ResourceManager::getInstance(); + std::string helpPath = branding.getStringValue("helpPath"); + if (helpPath.empty()) + helpPath = paths.getStringValue("help"); + std::vector lines = + resman->loadTextFile(helpPath + file + ".txt"); + + for (unsigned int i = 0; i < lines.size(); ++i) + mBrowserBox->addRow(lines[i]); +} diff --git a/src/gui/helpwindow.h b/src/gui/helpwindow.h new file mode 100644 index 000000000..df7a867d2 --- /dev/null +++ b/src/gui/helpwindow.h @@ -0,0 +1,77 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#ifndef HELPWINDOW_H +#define HELPWINDOW_H + +#include "gui/widgets/linkhandler.h" +#include "gui/widgets/window.h" + +#include + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +class BrowserBox; +class LinkHandler; + +/** + * The help dialog. + */ +class HelpWindow : public Window, public LinkHandler, + public gcn::ActionListener +{ + public: + /** + * Constructor. + */ + HelpWindow(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Handles link action. + */ + void handleLink(const std::string &link, + gcn::MouseEvent *event _UNUSED_); + + /** + * Loads help in the dialog. + */ + void loadHelp(const std::string &helpFile); + + private: + void loadFile(const std::string &file); + + BrowserBox *mBrowserBox; + gcn::ScrollArea *mScrollArea; +}; + +extern HelpWindow *helpWindow; + +#endif diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index bdef93f73..b897ad4b8 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -28,7 +28,7 @@ #include "keyboardconfig.h" #include "playerinfo.h" -#include "gui/itemamount.h" +#include "gui/itemamountwindow.h" #include "gui/setup.h" #include "gui/sdlinput.h" #include "gui/shopwindow.h" diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp deleted file mode 100644 index b538d1d16..000000000 --- a/src/gui/itemamount.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "gui/itemamount.h" - -#include "item.h" -#include "keyboardconfig.h" - -#include "gui/trade.h" -#include "net/inventoryhandler.h" -#include "gui/itempopup.h" -#include "net/net.h" -#include "gui/shopwindow.h" -#include "gui/viewport.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/dropdown.h" -#include "gui/widgets/icon.h" -#include "gui/widgets/inttextfield.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/label.h" -#include "gui/widgets/slider.h" - -#include "resources/itemdb.h" - -#include "utils/gettext.h" - -#include - -class ItemsModal : public gcn::ListModel -{ -public: - ItemsModal() - { - std::map info = ItemDB::getItemInfos(); - std::list tempStrings; - - for (std::map::const_iterator - i = info.begin(), i_end = info.end(); - i != i_end; ++i) - { - if (i->first < 0) - continue; - - ItemInfo info = (*i->second); - std::string name = info.getName(); - if (name != "unnamed" && !info.getName().empty() - && info.getName() != "unnamed") - { - tempStrings.push_back(name); - } - } - tempStrings.sort(); - for (std::list::const_iterator i = tempStrings.begin(), - i_end = tempStrings.end(); i != i_end; ++i) - { - mStrings.push_back(*i); - } - } - - virtual ~ItemsModal() - { } - - virtual int getNumberOfElements() - { - return static_cast(mStrings.size()); - } - - virtual std::string getElementAt(int i) - { - if (i < 0 || i >= getNumberOfElements()) - return _("???"); - - return mStrings.at(i); - } -private: - std::vector mStrings; -}; - -void ItemAmountWindow::finish(Item *item, int amount, int price, Usage usage) -{ - switch (usage) - { - case TradeAdd: - if (tradeWindow) - tradeWindow->tradeItem(item, amount); - break; - case ItemDrop: - Net::getInventoryHandler()->dropItem(item, amount); - break; - case ItemSplit: - Net::getInventoryHandler()->splitItem(item, amount); - break; - case StoreAdd: - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, - item->getInvIndex(), amount, - Inventory::STORAGE); - break; - case StoreRemove: - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, - item->getInvIndex(), amount, - Inventory::INVENTORY); - break; - case ShopBuyAdd: - if (shopWindow) - shopWindow->addBuyItem(item, amount, price); - break; - case ShopSellAdd: - if (shopWindow) - shopWindow->addSellItem(item, amount, price); - break; - default: - break; - } -} - -ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, - int maxRange): - Window("", true, parent), - mItemPriceTextField(0), - mGPLabel(0), - mItem(item), - mMax(maxRange), - mUsage(usage), - mItemPriceSlide(0), - mItemsModal(0), - mPrice(0) -{ - if (!mItem) - { - setVisible(false); - return; - } - if (usage == ShopBuyAdd) - mMax = 10000; - else if (!mMax) - mMax = mItem->getQuantity(); - - // Save keyboard state - mEnabledKeyboard = keyboard.isEnabled(); - keyboard.setEnabled(false); - - // Integer field - mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, mMax); - mItemAmountTextField->setWidth(35); - mItemAmountTextField->addKeyListener(this); - - // Slider - mItemAmountSlide = new Slider(1.0, mMax); - mItemAmountSlide->setHeight(10); - mItemAmountSlide->setActionEventId("slide"); - mItemAmountSlide->addActionListener(this); - - if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) - { - // Integer field - mItemPriceTextField = new IntTextField(1); - mItemPriceTextField->setRange(1, 10000000); - mItemPriceTextField->setWidth(35); - mItemPriceTextField->addKeyListener(this); - - // Slider - mItemPriceSlide = new Slider(1.0, 10000000); - mItemPriceSlide->setHeight(10); - mItemPriceSlide->setActionEventId("slidePrice"); - mItemPriceSlide->addActionListener(this); - - mGPLabel = new Label(" GP"); - } - - if (mUsage == ShopBuyAdd) - { - mItemsModal = new ItemsModal; - mItemDropDown = new DropDown(mItemsModal); - mItemDropDown->setActionEventId("itemType"); - mItemDropDown->addActionListener(this); - } - - //Item icon - Image *image = item->getImage(); - mItemIcon = new Icon(image); - - // Buttons - Button *minusAmountButton = new Button(_("-"), "dec", this); - Button *plusAmountButton = new Button(_("+"), "inc", this); - Button *okButton = new Button(_("OK"), "ok", this); - Button *cancelButton = new Button(_("Cancel"), "cancel", this); - Button *addAllButton = new Button(_("All"), "all", this); - - minusAmountButton->adjustSize(); - minusAmountButton->setWidth(plusAmountButton->getWidth()); - - // Set positions - ContainerPlacer place; - place = getPlacer(0, 0); - int n = 0; - if (mUsage == ShopBuyAdd) - { - place(0, n, mItemDropDown, 8); - n++; - } - place(1, n, minusAmountButton); - place(2, n, mItemAmountTextField, 3); - place(5, n, plusAmountButton); - place(6, n, addAllButton); - - place(0, n, mItemIcon, 1, 3); - place(1, n + 1, mItemAmountSlide, 7); - - if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) - { - Button *minusPriceButton = new Button(_("-"), "decPrice", this); - Button *plusPriceButton = new Button(_("+"), "incPrice", this); - minusPriceButton->adjustSize(); - minusPriceButton->setWidth(plusPriceButton->getWidth()); - - place(1, n + 2, minusPriceButton); - place(2, n + 2, mItemPriceTextField, 3); - place(5, n + 2, plusPriceButton); - place(6, n + 2, mGPLabel); - - place(1, n + 3, mItemPriceSlide, 7); - place(4, n + 5, cancelButton); - place(5, n + 5, okButton); - } - else - { - place(4, n + 2, cancelButton); - place(5, n + 2, okButton); - } - - reflowLayout(225, 0); - - resetAmount(); - - switch (usage) - { - case TradeAdd: - setCaption(_("Select amount of items to trade.")); - break; - case ItemDrop: - setCaption(_("Select amount of items to drop.")); - break; - case StoreAdd: - setCaption(_("Select amount of items to store.")); - break; - case StoreRemove: - setCaption(_("Select amount of items to retrieve.")); - break; - case ItemSplit: - setCaption(_("Select amount of items to split.")); - break; - case ShopBuyAdd: - setCaption(_("Add to buy shop.")); - break; - case ShopSellAdd: - setCaption(_("Add to sell shop.")); - break; - default: - setCaption(_("Unknown.")); - break; - } - - setLocationRelativeTo(getParentWindow()); - setVisible(true); - - mItemPopup = new ItemPopup; - mItemIcon->addMouseListener(this); -} - -ItemAmountWindow::~ItemAmountWindow() -{ - delete mItemPopup; - mItemPopup = 0; -} - -// Show ItemTooltip -void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event) -{ - if (!viewport || !mItemPopup) - return; - - if (event.getSource() == mItemIcon) - { - mItemPopup->setItem(mItem); - mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); - } -} - -// Hide ItemTooltip -void ItemAmountWindow::mouseExited(gcn::MouseEvent &event _UNUSED_) -{ - if (mItemPopup) - mItemPopup->setVisible(false); -} - -void ItemAmountWindow::resetAmount() -{ - mItemAmountTextField->setValue(1); -} - -void ItemAmountWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "cancel") - { - close(); - return; - } - else if (event.getId() == "ok") - { - if (mItemPriceTextField) - { - finish(mItem, mItemAmountTextField->getValue(), - mItemPriceTextField->getValue(), mUsage); - } - else - { - finish(mItem, mItemAmountTextField->getValue(), - 0, mUsage); - } - close(); - return; - } - else if (event.getId() == "itemType") - { - if (!mItemDropDown || !mItemsModal) - return; - - std::string str = mItemsModal->getElementAt( - mItemDropDown->getSelected()); - int id = ItemDB::get(str).getId(); - - mItem = new Item(id, 10000); - - if (mUsage == ShopBuyAdd) - mMax = 10000; - else if (!mMax) - mMax = mItem->getQuantity(); - - Image *image = mItem->getImage(); - mItemIcon->setImage(image); - } - - int amount = mItemAmountTextField->getValue(); - - if (event.getId() == "inc" && amount < mMax) - amount++; - else if (event.getId() == "dec" && amount > 1) - amount--; - else if (event.getId() == "all") - amount = mMax; - else if (event.getId() == "slide") - amount = static_cast(mItemAmountSlide->getValue()); - mItemAmountTextField->setValue(amount); - mItemAmountSlide->setValue(amount); - - if (mItemPriceTextField && mItemPriceSlide) - { - int price = 0; - - if (mPrice > 7) - mPrice = 7; - else if (mPrice < 0) - mPrice = 0; - - if (event.getId() == "incPrice") - { - mPrice++; - price = static_cast(pow(10, mPrice)); - } - else if (event.getId() == "decPrice") - { - mPrice--; - price = static_cast(pow(10, mPrice)); - } - else if (event.getId() == "slidePrice") - { - price = static_cast(mItemPriceSlide->getValue()); - if (price) - mPrice = static_cast(log(price)); - else - mPrice = 0; - } - mItemPriceTextField->setValue(price); - mItemPriceSlide->setValue(price); - } -} - -void ItemAmountWindow::close() -{ - keyboard.setEnabled(mEnabledKeyboard); - scheduleDelete(); -} - -void ItemAmountWindow::keyReleased(gcn::KeyEvent &keyEvent _UNUSED_) -{ - mItemAmountSlide->setValue(mItemAmountTextField->getValue()); -} - -void ItemAmountWindow::showWindow(Usage usage, Window *parent, Item *item, - int maxRange) -{ - if (!item) - return; - - if (!maxRange) - maxRange = item->getQuantity(); - - if (usage != ShopBuyAdd && usage != ShopSellAdd && maxRange <= 1) - finish(item, maxRange, 0, usage); - else - new ItemAmountWindow(usage, parent, item, maxRange); -} diff --git a/src/gui/itemamount.h b/src/gui/itemamount.h deleted file mode 100644 index f51c074f7..000000000 --- a/src/gui/itemamount.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#ifndef ITEM_AMOUNT_WINDOW_H -#define ITEM_AMOUNT_WINDOW_H - -#include "gui/widgets/window.h" - -#include -#include - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -class Icon; -class IntTextField; -class Item; -class ItemsModal; -class ItemPopup; -class Label; - -/** - * Window used for selecting the amount of items to drop, trade or split. - * - * \ingroup Interface - */ -class ItemAmountWindow : public Window, - public gcn::ActionListener, - public gcn::KeyListener -{ - public: - enum Usage - { - TradeAdd = 0, - ItemDrop, - StoreAdd, - StoreRemove, - ItemSplit, - ShopBuyAdd, - ShopSellAdd - }; - - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &event); - - /** - * Sets default amount value. - */ - void resetAmount(); - - // MouseListener - void mouseMoved(gcn::MouseEvent &event); - void mouseExited(gcn::MouseEvent &event); - - /** - * Schedules the Item Amount window for deletion. - */ - void close(); - - void keyReleased(gcn::KeyEvent &keyEvent); - - /** - * Creates the dialog, or bypass it if there aren't enough items. - */ - static void showWindow(Usage usage, Window *parent, Item *item, - int maxRange = 0); - - ~ItemAmountWindow(); - - private: - static void finish(Item *item, int amount, int price, Usage usage); - - ItemAmountWindow(Usage usage, Window *parent, Item *item, - int maxRange = 0); - - IntTextField *mItemAmountTextField; /**< Item amount caption. */ - IntTextField *mItemPriceTextField; /**< Item price caption. */ - Label *mGPLabel; - Item *mItem; - Icon *mItemIcon; - - int mMax; - Usage mUsage; - ItemPopup *mItemPopup; - - /** - * Item Amount buttons. - */ - gcn::Slider *mItemAmountSlide; - - gcn::Slider *mItemPriceSlide; - - gcn::DropDown *mItemDropDown; - - ItemsModal *mItemsModal; - - bool mEnabledKeyboard; - int mPrice; -}; - -#endif // ITEM_AMOUNT_WINDOW_H diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp new file mode 100644 index 000000000..751578d9b --- /dev/null +++ b/src/gui/itemamountwindow.cpp @@ -0,0 +1,433 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#include "gui/itemamountwindow.h" + +#include "item.h" +#include "keyboardconfig.h" + +#include "gui/trade.h" +#include "net/inventoryhandler.h" +#include "gui/itempopup.h" +#include "net/net.h" +#include "gui/shopwindow.h" +#include "gui/viewport.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/dropdown.h" +#include "gui/widgets/icon.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/label.h" +#include "gui/widgets/slider.h" + +#include "resources/itemdb.h" + +#include "utils/gettext.h" + +#include + +class ItemsModal : public gcn::ListModel +{ +public: + ItemsModal() + { + std::map info = ItemDB::getItemInfos(); + std::list tempStrings; + + for (std::map::const_iterator + i = info.begin(), i_end = info.end(); + i != i_end; ++i) + { + if (i->first < 0) + continue; + + ItemInfo info = (*i->second); + std::string name = info.getName(); + if (name != "unnamed" && !info.getName().empty() + && info.getName() != "unnamed") + { + tempStrings.push_back(name); + } + } + tempStrings.sort(); + for (std::list::const_iterator i = tempStrings.begin(), + i_end = tempStrings.end(); i != i_end; ++i) + { + mStrings.push_back(*i); + } + } + + virtual ~ItemsModal() + { } + + virtual int getNumberOfElements() + { + return static_cast(mStrings.size()); + } + + virtual std::string getElementAt(int i) + { + if (i < 0 || i >= getNumberOfElements()) + return _("???"); + + return mStrings.at(i); + } +private: + std::vector mStrings; +}; + +void ItemAmountWindow::finish(Item *item, int amount, int price, Usage usage) +{ + switch (usage) + { + case TradeAdd: + if (tradeWindow) + tradeWindow->tradeItem(item, amount); + break; + case ItemDrop: + Net::getInventoryHandler()->dropItem(item, amount); + break; + case ItemSplit: + Net::getInventoryHandler()->splitItem(item, amount); + break; + case StoreAdd: + Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + item->getInvIndex(), amount, + Inventory::STORAGE); + break; + case StoreRemove: + Net::getInventoryHandler()->moveItem(Inventory::STORAGE, + item->getInvIndex(), amount, + Inventory::INVENTORY); + break; + case ShopBuyAdd: + if (shopWindow) + shopWindow->addBuyItem(item, amount, price); + break; + case ShopSellAdd: + if (shopWindow) + shopWindow->addSellItem(item, amount, price); + break; + default: + break; + } +} + +ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange): + Window("", true, parent), + mItemPriceTextField(0), + mGPLabel(0), + mItem(item), + mMax(maxRange), + mUsage(usage), + mItemPriceSlide(0), + mItemsModal(0), + mPrice(0) +{ + if (!mItem) + { + setVisible(false); + return; + } + if (usage == ShopBuyAdd) + mMax = 10000; + else if (!mMax) + mMax = mItem->getQuantity(); + + // Save keyboard state + mEnabledKeyboard = keyboard.isEnabled(); + keyboard.setEnabled(false); + + // Integer field + mItemAmountTextField = new IntTextField(1); + mItemAmountTextField->setRange(1, mMax); + mItemAmountTextField->setWidth(35); + mItemAmountTextField->addKeyListener(this); + + // Slider + mItemAmountSlide = new Slider(1.0, mMax); + mItemAmountSlide->setHeight(10); + mItemAmountSlide->setActionEventId("slide"); + mItemAmountSlide->addActionListener(this); + + if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) + { + // Integer field + mItemPriceTextField = new IntTextField(1); + mItemPriceTextField->setRange(1, 10000000); + mItemPriceTextField->setWidth(35); + mItemPriceTextField->addKeyListener(this); + + // Slider + mItemPriceSlide = new Slider(1.0, 10000000); + mItemPriceSlide->setHeight(10); + mItemPriceSlide->setActionEventId("slidePrice"); + mItemPriceSlide->addActionListener(this); + + mGPLabel = new Label(" GP"); + } + + if (mUsage == ShopBuyAdd) + { + mItemsModal = new ItemsModal; + mItemDropDown = new DropDown(mItemsModal); + mItemDropDown->setActionEventId("itemType"); + mItemDropDown->addActionListener(this); + } + + //Item icon + Image *image = item->getImage(); + mItemIcon = new Icon(image); + + // Buttons + Button *minusAmountButton = new Button(_("-"), "dec", this); + Button *plusAmountButton = new Button(_("+"), "inc", this); + Button *okButton = new Button(_("OK"), "ok", this); + Button *cancelButton = new Button(_("Cancel"), "cancel", this); + Button *addAllButton = new Button(_("All"), "all", this); + + minusAmountButton->adjustSize(); + minusAmountButton->setWidth(plusAmountButton->getWidth()); + + // Set positions + ContainerPlacer place; + place = getPlacer(0, 0); + int n = 0; + if (mUsage == ShopBuyAdd) + { + place(0, n, mItemDropDown, 8); + n++; + } + place(1, n, minusAmountButton); + place(2, n, mItemAmountTextField, 3); + place(5, n, plusAmountButton); + place(6, n, addAllButton); + + place(0, n, mItemIcon, 1, 3); + place(1, n + 1, mItemAmountSlide, 7); + + if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) + { + Button *minusPriceButton = new Button(_("-"), "decPrice", this); + Button *plusPriceButton = new Button(_("+"), "incPrice", this); + minusPriceButton->adjustSize(); + minusPriceButton->setWidth(plusPriceButton->getWidth()); + + place(1, n + 2, minusPriceButton); + place(2, n + 2, mItemPriceTextField, 3); + place(5, n + 2, plusPriceButton); + place(6, n + 2, mGPLabel); + + place(1, n + 3, mItemPriceSlide, 7); + place(4, n + 5, cancelButton); + place(5, n + 5, okButton); + } + else + { + place(4, n + 2, cancelButton); + place(5, n + 2, okButton); + } + + reflowLayout(225, 0); + + resetAmount(); + + switch (usage) + { + case TradeAdd: + setCaption(_("Select amount of items to trade.")); + break; + case ItemDrop: + setCaption(_("Select amount of items to drop.")); + break; + case StoreAdd: + setCaption(_("Select amount of items to store.")); + break; + case StoreRemove: + setCaption(_("Select amount of items to retrieve.")); + break; + case ItemSplit: + setCaption(_("Select amount of items to split.")); + break; + case ShopBuyAdd: + setCaption(_("Add to buy shop.")); + break; + case ShopSellAdd: + setCaption(_("Add to sell shop.")); + break; + default: + setCaption(_("Unknown.")); + break; + } + + setLocationRelativeTo(getParentWindow()); + setVisible(true); + + mItemPopup = new ItemPopup; + mItemIcon->addMouseListener(this); +} + +ItemAmountWindow::~ItemAmountWindow() +{ + delete mItemPopup; + mItemPopup = 0; +} + +// Show ItemTooltip +void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event) +{ + if (!viewport || !mItemPopup) + return; + + if (event.getSource() == mItemIcon) + { + mItemPopup->setItem(mItem); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); + } +} + +// Hide ItemTooltip +void ItemAmountWindow::mouseExited(gcn::MouseEvent &event _UNUSED_) +{ + if (mItemPopup) + mItemPopup->setVisible(false); +} + +void ItemAmountWindow::resetAmount() +{ + mItemAmountTextField->setValue(1); +} + +void ItemAmountWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "cancel") + { + close(); + return; + } + else if (event.getId() == "ok") + { + if (mItemPriceTextField) + { + finish(mItem, mItemAmountTextField->getValue(), + mItemPriceTextField->getValue(), mUsage); + } + else + { + finish(mItem, mItemAmountTextField->getValue(), + 0, mUsage); + } + close(); + return; + } + else if (event.getId() == "itemType") + { + if (!mItemDropDown || !mItemsModal) + return; + + std::string str = mItemsModal->getElementAt( + mItemDropDown->getSelected()); + int id = ItemDB::get(str).getId(); + + mItem = new Item(id, 10000); + + if (mUsage == ShopBuyAdd) + mMax = 10000; + else if (!mMax) + mMax = mItem->getQuantity(); + + Image *image = mItem->getImage(); + mItemIcon->setImage(image); + } + + int amount = mItemAmountTextField->getValue(); + + if (event.getId() == "inc" && amount < mMax) + amount++; + else if (event.getId() == "dec" && amount > 1) + amount--; + else if (event.getId() == "all") + amount = mMax; + else if (event.getId() == "slide") + amount = static_cast(mItemAmountSlide->getValue()); + mItemAmountTextField->setValue(amount); + mItemAmountSlide->setValue(amount); + + if (mItemPriceTextField && mItemPriceSlide) + { + int price = 0; + + if (mPrice > 7) + mPrice = 7; + else if (mPrice < 0) + mPrice = 0; + + if (event.getId() == "incPrice") + { + mPrice++; + price = static_cast(pow(10, mPrice)); + } + else if (event.getId() == "decPrice") + { + mPrice--; + price = static_cast(pow(10, mPrice)); + } + else if (event.getId() == "slidePrice") + { + price = static_cast(mItemPriceSlide->getValue()); + if (price) + mPrice = static_cast(log(price)); + else + mPrice = 0; + } + mItemPriceTextField->setValue(price); + mItemPriceSlide->setValue(price); + } +} + +void ItemAmountWindow::close() +{ + keyboard.setEnabled(mEnabledKeyboard); + scheduleDelete(); +} + +void ItemAmountWindow::keyReleased(gcn::KeyEvent &keyEvent _UNUSED_) +{ + mItemAmountSlide->setValue(mItemAmountTextField->getValue()); +} + +void ItemAmountWindow::showWindow(Usage usage, Window *parent, Item *item, + int maxRange) +{ + if (!item) + return; + + if (!maxRange) + maxRange = item->getQuantity(); + + if (usage != ShopBuyAdd && usage != ShopSellAdd && maxRange <= 1) + finish(item, maxRange, 0, usage); + else + new ItemAmountWindow(usage, parent, item, maxRange); +} diff --git a/src/gui/itemamountwindow.h b/src/gui/itemamountwindow.h new file mode 100644 index 000000000..f51c074f7 --- /dev/null +++ b/src/gui/itemamountwindow.h @@ -0,0 +1,125 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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, see . + */ + +#ifndef ITEM_AMOUNT_WINDOW_H +#define ITEM_AMOUNT_WINDOW_H + +#include "gui/widgets/window.h" + +#include +#include + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +class Icon; +class IntTextField; +class Item; +class ItemsModal; +class ItemPopup; +class Label; + +/** + * Window used for selecting the amount of items to drop, trade or split. + * + * \ingroup Interface + */ +class ItemAmountWindow : public Window, + public gcn::ActionListener, + public gcn::KeyListener +{ + public: + enum Usage + { + TradeAdd = 0, + ItemDrop, + StoreAdd, + StoreRemove, + ItemSplit, + ShopBuyAdd, + ShopSellAdd + }; + + /** + * Called when receiving actions from widget. + */ + void action(const gcn::ActionEvent &event); + + /** + * Sets default amount value. + */ + void resetAmount(); + + // MouseListener + void mouseMoved(gcn::MouseEvent &event); + void mouseExited(gcn::MouseEvent &event); + + /** + * Schedules the Item Amount window for deletion. + */ + void close(); + + void keyReleased(gcn::KeyEvent &keyEvent); + + /** + * Creates the dialog, or bypass it if there aren't enough items. + */ + static void showWindow(Usage usage, Window *parent, Item *item, + int maxRange = 0); + + ~ItemAmountWindow(); + + private: + static void finish(Item *item, int amount, int price, Usage usage); + + ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange = 0); + + IntTextField *mItemAmountTextField; /**< Item amount caption. */ + IntTextField *mItemPriceTextField; /**< Item price caption. */ + Label *mGPLabel; + Item *mItem; + Icon *mItemIcon; + + int mMax; + Usage mUsage; + ItemPopup *mItemPopup; + + /** + * Item Amount buttons. + */ + gcn::Slider *mItemAmountSlide; + + gcn::Slider *mItemPriceSlide; + + gcn::DropDown *mItemDropDown; + + ItemsModal *mItemsModal; + + bool mEnabledKeyboard; + int mPrice; +}; + +#endif // ITEM_AMOUNT_WINDOW_H diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index f01dd01c7..e373153e6 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -29,7 +29,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "gui/widgets/chattab.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "actorspritemanager.h" #include "event.h" diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 303b36ae3..e0103f080 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -27,7 +27,7 @@ #include "graphics.h" #include "playerinfo.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/gui.h" #include "gui/statuswindow.h" #include "gui/statuspopup.h" diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 3550883ba..57ad6ab21 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -31,7 +31,7 @@ #include "log.h" #include "playerinfo.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/viewport.h" #include "gui/widgets/button.h" diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 0ab0ac4a3..8e668c1ed 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -38,10 +38,10 @@ #include "playerrelations.h" #include "spellmanager.h" -#include "gui/buy.h" -#include "gui/chat.h" +#include "gui/buydialog.h" +#include "gui/chatwindow.h" #include "gui/inventorywindow.h" -#include "gui/itemamount.h" +#include "gui/itemamountwindow.h" #include "gui/ministatus.h" #include "gui/outfitwindow.h" #include "gui/sell.h" diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index f7ac5bff2..423e2404d 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -24,7 +24,7 @@ #include "client.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/npcdialog.h" #include "gui/sdlinput.h" #include "gui/viewport.h" diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 08c76685a..f666284d6 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -22,7 +22,7 @@ #include "gui/setup_chat.h" #include "gui/editdialog.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index d458a5156..60d48a4c7 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -22,8 +22,8 @@ #include "gui/shopwindow.h" -#include "gui/buy.h" -#include "gui/itemamount.h" +#include "gui/buydialog.h" +#include "gui/itemamountwindow.h" #include "gui/sell.h" #include "gui/setup.h" #include "gui/trade.h" diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index 2300033a5..019827048 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -38,7 +38,7 @@ #include "gui/widgets/table.h" #include "gui/widgets/textfield.h" -#include "chat.h" +#include "chatwindow.h" #include "configuration.h" #include "item.h" #include "localplayer.h" diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index ab53c38e6..38aaecb83 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -29,7 +29,7 @@ #include "units.h" #include "gui/inventorywindow.h" -#include "gui/itemamount.h" +#include "gui/itemamountwindow.h" #include "gui/setup.h" #include "gui/theme.h" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 4dd5431ee..ef33aa75b 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -34,7 +34,7 @@ #include "textmanager.h" #include "gui/beingpopup.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/gui.h" #include "gui/ministatus.h" #include "gui/popupmenu.h" diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 9a72bb7fd..c1b7f03d1 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -40,7 +40,7 @@ #include "playerrelations.h" #include "main.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index fe8032063..c1458d3fd 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -27,7 +27,7 @@ #include "guild.h" #include "localplayer.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/gui.h" #include "gui/palette.h" #include "gui/viewport.h" diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index 611ca8ef3..66e9f637d 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -23,7 +23,7 @@ #ifndef CHATTAB_H #define CHATTAB_H -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/widgets/browserbox.h" #include "gui/widgets/tab.h" diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index b76385f03..509c7b218 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -29,7 +29,7 @@ #include "dropshortcut.h" #include "log.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/itempopup.h" #include "gui/outfitwindow.h" #include "gui/palette.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index a6ed4c00a..7cf26cd44 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -42,7 +42,7 @@ #include "text.h" #include "dropshortcut.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/gui.h" #include "gui/inventorywindow.h" #include "gui/killstats.h" diff --git a/src/net/manaserv/buysellhandler.cpp b/src/net/manaserv/buysellhandler.cpp index a519125de..cd73f03f5 100644 --- a/src/net/manaserv/buysellhandler.cpp +++ b/src/net/manaserv/buysellhandler.cpp @@ -28,8 +28,8 @@ #include "playerinfo.h" #include "shopitem.h" -#include "gui/buy.h" -#include "gui/chat.h" +#include "gui/buydialog.h" +#include "gui/chatwindow.h" #include "gui/sell.h" #include "net/messagein.h" diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 5536413ab..bdb903fe1 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -28,7 +28,7 @@ #include "channel.h" #include "channelmanager.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/widgets/channeltab.h" diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index dd57a5584..f074152d6 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -30,7 +30,7 @@ #include "channelmanager.h" #include "gui/widgets/channeltab.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/socialwindow.h" #include "net/messagein.h" diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 741eee9df..111eee944 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -29,7 +29,7 @@ #include "localplayer.h" #include "playerinfo.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "net/manaserv/connection.h" #include "net/manaserv/messagein.h" diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 292915581..54d6dc7de 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -32,7 +32,7 @@ #include "playerinfo.h" #include "configuration.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/gui.h" #include "gui/okdialog.h" #include "gui/viewport.h" diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index 07d5bcc96..e1f6cfd22 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -31,8 +31,8 @@ #include "playerinfo.h" #include "shopitem.h" -#include "gui/buy.h" -#include "gui/buysell.h" +#include "gui/buydialog.h" +#include "gui/buyselldialog.h" #include "gui/sell.h" #include "gui/shopwindow.h" diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 5bd3df339..d8a842003 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -31,7 +31,7 @@ #include "playerrelations.h" #include "log.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/shopwindow.h" #include "gui/widgets/chattab.h" diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 31451c09a..f4462c732 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -28,7 +28,7 @@ #include "localplayer.h" #include "playerinfo.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "net/net.h" #include "net/playerhandler.h" diff --git a/src/spellshortcut.cpp b/src/spellshortcut.cpp index 89a82401e..1559cfa47 100644 --- a/src/spellshortcut.cpp +++ b/src/spellshortcut.cpp @@ -26,7 +26,7 @@ #include "spellshortcut.h" #include "localplayer.h" -#include "gui/chat.h" +#include "gui/chatwindow.h" #include "gui/widgets/chattab.h" #include "net/inventoryhandler.h" -- cgit v1.2.3-70-g09d2