diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/chat.cpp | 15 | ||||
-rw-r--r-- | src/gui/chat.h | 7 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 5 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 2 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 21 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 1 | ||||
-rw-r--r-- | src/gui/itemlinkhandler.cpp | 60 | ||||
-rw-r--r-- | src/gui/itemlinkhandler.h | 40 | ||||
-rw-r--r-- | src/gui/itempopup.cpp | 13 | ||||
-rw-r--r-- | src/gui/itempopup.h | 2 |
10 files changed, 151 insertions, 15 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 888dd27d..34daab38 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -28,6 +28,7 @@ #include "browserbox.h" #include "chatinput.h" +#include "itemlinkhandler.h" #include "scrollarea.h" #include "sdlinput.h" #include "windowcontainer.h" @@ -57,14 +58,16 @@ ChatWindow::ChatWindow(): setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); setOpaque(false); + mItemLinkHandler = new ItemLinkHandler(); + mChatInput = new ChatInput; mChatInput->setActionEventId("chatinput"); mChatInput->addActionListener(this); BrowserBox *textOutput = new BrowserBox(BrowserBox::AUTO_WRAP); textOutput->setOpaque(false); - textOutput->disableLinksAndUserColors(); textOutput->setMaxRow((int) config.getValue("ChatLogLength", 0)); + textOutput->setLinkHandler(mItemLinkHandler); ScrollArea *scrollArea = new ScrollArea(textOutput); scrollArea->setPosition( @@ -416,10 +419,18 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) void ChatWindow::setInputText(std::string input_str) { - mChatInput->setText(input_str + " "); + mChatInput->setText(mChatInput->getText() + input_str + " "); requestChatFocus(); } +void ChatWindow::addItemText(int itemId, const std::string &item) +{ + std::ostringstream text; + text << "[@@" << itemId << "|" << item << "@@] "; + mChatInput->setText(mChatInput->getText() + text.str()); + requestChatFocus(); +} + void ChatWindow::setVisible(bool isVisible) { Window::setVisible(isVisible); diff --git a/src/gui/chat.h b/src/gui/chat.h index 8ca0e4c9..bb742a77 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -37,6 +37,7 @@ class BrowserBox; class ScrollArea; class TabbedArea; class Channel; +class ItemLinkHandler; enum { @@ -141,6 +142,9 @@ class ChatWindow : public Window, /** Called to set current text */ void setInputText(std::string input_str); + /** Called to add item to chat */ + void addItemText(int itemid, const std::string &item); + /** Override to reset mTmpVisible */ void setVisible(bool visible); @@ -175,6 +179,9 @@ class ChatWindow : public Window, ScrollArea *scroll; }; + /** Used for showing item popup on clicking links **/ + ItemLinkHandler *mItemLinkHandler; + /** Tabbed area for holding each channel. */ TabbedArea *mChatTabs; diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 1e3c4084..1765eeea 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -51,7 +51,8 @@ InventoryWindow::InventoryWindow(): Window(_("Inventory")), - mSplit(false) + mSplit(false), + mItemDesc(false) { setWindowName("Inventory"); setResizable(false); @@ -200,6 +201,7 @@ void InventoryWindow::keyPressed(gcn::KeyEvent &event) case Key::LEFT_SHIFT: case Key::RIGHT_SHIFT: mSplit = true; + break; } } @@ -210,5 +212,6 @@ void InventoryWindow::keyReleased(gcn::KeyEvent &event) case Key::LEFT_SHIFT: case Key::RIGHT_SHIFT: mSplit = false; + break; } } diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index ad1c8f38..9d342c83 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -93,6 +93,8 @@ class InventoryWindow : public Window, gcn::ScrollArea *mInvenScroll; /**< Inventory Scroll Area. */ bool mSplit; + + bool mItemDesc; }; extern InventoryWindow *inventoryWindow; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 141b4360..4a90510c 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -20,6 +20,7 @@ */ #include "itemcontainer.h" +#include "chat.h" #include <guichan/mouseinput.hpp> #include <guichan/selectionlistener.hpp> @@ -61,7 +62,8 @@ ItemContainer::ItemContainer(Inventory *inventory, mSelectedItem(NULL), mHighlightedItem(NULL), mSelectionStatus(SEL_NONE), - mSwapItems(false) + mSwapItems(false), + mDescItems(false) { mItemPopup = new ItemPopup(); setFocusable(true); @@ -195,6 +197,10 @@ ItemContainer::keyPressed(gcn::KeyEvent &event) case Key::LEFT_ALT: case Key::RIGHT_ALT: mSwapItems = true; + break; + case Key::RIGHT_CONTROL: + mDescItems = true; + break; } } @@ -206,13 +212,16 @@ ItemContainer::keyReleased(gcn::KeyEvent &event) case Key::LEFT_ALT: case Key::RIGHT_ALT: mSwapItems = false; + break; + case Key::RIGHT_CONTROL: + mDescItems = false; + break; } } void ItemContainer::mousePressed(gcn::MouseEvent &event) { - const int button = event.getButton(); if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) { @@ -223,6 +232,12 @@ ItemContainer::mousePressed(gcn::MouseEvent &event) Item *item = mInventory->getItem(index); + // put item name into chat window + if (mDescItems) + { + chatWindow->addItemText(item->getId(), item->getInfo().getName()); + } + if (mSelectedItem && mSelectedItem == item) { mSelectionStatus = SEL_DESELECTING; @@ -288,7 +303,7 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) { mItemPopup->setPosition(getParent()->getParent()->getX() + getParent()->getParent()->getWidth(), getParent()->getParent()->getY()); - mItemPopup->setItem(item); + mItemPopup->setItem(item->getInfo()); mItemPopup->setVisible(true); } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 8d93671c..7636ef0c 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -169,6 +169,7 @@ class ItemContainer : public gcn::Widget, Item *mSelectedItem, *mHighlightedItem; int mSelectionStatus; bool mSwapItems; + bool mDescItems; int mDragPosX, mDragPosY; ItemPopup *mItemPopup; diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp new file mode 100644 index 00000000..bdfa2ca6 --- /dev/null +++ b/src/gui/itemlinkhandler.cpp @@ -0,0 +1,60 @@ +/* + * The Mana World + * Copyright 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "itemlinkhandler.h" +#include "itempopup.h" + +#include "../resources/iteminfo.h" +#include "../resources/itemdb.h" + +#include <sstream> +#include <string> + +ItemLinkHandler::ItemLinkHandler() +{ + mItemPopup = new ItemPopup; +} + +ItemLinkHandler::~ItemLinkHandler() +{ + delete mItemPopup; +} + +void ItemLinkHandler::handleLink(const std::string &link) +{ + int id = 0; + std::stringstream stream; + stream << link; + stream >> id; + if (id > 0) + { + const ItemInfo &iteminfo = ItemDB::get(id); + mItemPopup->setItem(iteminfo); + if (mItemPopup->isVisible()) + { + mItemPopup->setVisible(false); + } + else + { + mItemPopup->setVisible(true); + } + } +} diff --git a/src/gui/itemlinkhandler.h b/src/gui/itemlinkhandler.h new file mode 100644 index 00000000..973aab75 --- /dev/null +++ b/src/gui/itemlinkhandler.h @@ -0,0 +1,40 @@ +/* + * The Mana World + * Copyright 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _TMW_ITEM_LINK_HANDLER_H_ +#define _TMW_ITEM_LINK_HANDLER_H_ + +#include "linkhandler.h" + +class ItemPopup; + +class ItemLinkHandler : public LinkHandler +{ + public: + ItemLinkHandler(); + ~ItemLinkHandler(); + void handleLink(const std::string &link); + + private: + ItemPopup *mItemPopup; +}; + +#endif diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index ee58c5cd..7a662151 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -81,19 +81,16 @@ ItemPopup::ItemPopup() mItemEffect->setTextWrapped( "" ); } -void ItemPopup::setItem(Item *item) +void ItemPopup::setItem(const ItemInfo &item) { - - ItemInfo const *info = item ? &item->getInfo() : NULL; - - mItemName->setCaption(info->getName()); - mItemDesc->setTextWrapped( info->getDescription() ); - mItemEffect->setTextWrapped( info->getEffect() ); + mItemName->setCaption(item.getName()); + mItemDesc->setTextWrapped(item.getDescription()); + mItemEffect->setTextWrapped(item.getEffect()); int numRowsDesc = mItemDesc->getNumberOfRows(); int numRowsEffect = mItemEffect->getNumberOfRows(); - if(info->getEffect() == "") + if(item.getEffect() == "") { setContentSize(200, (numRowsDesc * 14) + 30); } else { diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index 0179bf78..8da0b32a 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -34,7 +34,7 @@ class ItemPopup : public Window public: ItemPopup(); - void setItem(Item *item); + void setItem(const ItemInfo &item); unsigned int getNumRows(); private: |