summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aethyra.cbp2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/chat.cpp22
-rw-r--r--src/gui/chat.h7
-rw-r--r--src/gui/inventorywindow.cpp6
-rw-r--r--src/gui/inventorywindow.h2
-rw-r--r--src/gui/itemcontainer.cpp10
-rw-r--r--src/gui/itemcontainer.h2
-rw-r--r--src/gui/itemlinkhandler.cpp60
-rw-r--r--src/gui/itemlinkhandler.h40
-rw-r--r--src/gui/itempopup.cpp6
-rw-r--r--src/gui/popupmenu.cpp7
13 files changed, 150 insertions, 18 deletions
diff --git a/aethyra.cbp b/aethyra.cbp
index 633cea8d..ebda9029 100644
--- a/aethyra.cbp
+++ b/aethyra.cbp
@@ -167,6 +167,8 @@
<Unit filename="src\gui\item_amount.h" />
<Unit filename="src\gui\itemcontainer.cpp" />
<Unit filename="src\gui\itemcontainer.h" />
+ <Unit filename="src\gui\itemlinkhandler.cpp" />
+ <Unit filename="src\gui\itemlinkhandler.h" />
<Unit filename="src\gui\itempopup.cpp" />
<Unit filename="src\gui\itempopup.h" />
<Unit filename="src\gui\itemshortcutcontainer.cpp" />
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1aa38230..94cf0174 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -103,6 +103,8 @@ SET(SRCS
gui/inventorywindow.h
gui/itemcontainer.cpp
gui/itemcontainer.h
+ gui/itemlinkhandler.cpp
+ gui/itemlinkhandler.h
gui/itempopup.cpp
gui/itempopup.h
gui/itemshortcutcontainer.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 37b40936..8f76b06a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,6 +61,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
gui/inventorywindow.h \
gui/itemcontainer.cpp \
gui/itemcontainer.h \
+ gui/itemlinkhandler.cpp \
+ gui/itemlinkhandler.h \
gui/itempopup.cpp \
gui/itempopup.h \
gui/itemshortcutcontainer.cpp \
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index fa969d17..3e9b292e 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -27,6 +27,7 @@
#include "browserbox.h"
#include "chat.h"
#include "chatinput.h"
+#include "itemlinkhandler.h"
#include "scrollarea.h"
#include "sdlinput.h"
#include "windowcontainer.h"
@@ -54,19 +55,23 @@ Window(""), mNetwork(network), mTmpVisible(false)
setResizable(true);
setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123);
+ mItemLinkHandler = new ItemLinkHandler();
+
mChatInput = new ChatInput;
mChatInput->setActionEventId("chatinput");
mChatInput->addActionListener(this);
mTextOutput = new BrowserBox(BrowserBox::AUTO_WRAP);
mTextOutput->setOpaque(false);
- mTextOutput->disableLinksAndUserColors();
mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0));
+ mTextOutput->setLinkHandler(mItemLinkHandler);
+
mScrollArea = new ScrollArea(mTextOutput);
- mScrollArea->setPosition(mScrollArea->getFrameSize(),
+ mScrollArea->setPosition(mScrollArea->getFrameSize(),
mScrollArea->getFrameSize());
mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER,
gcn::ScrollArea::SHOW_ALWAYS);
+ mScrollArea->setScrollAmount(0, 1);
mScrollArea->setOpaque(false);
add(mScrollArea);
@@ -257,9 +262,8 @@ void ChatWindow::action(const gcn::ActionEvent & event)
// If the chatWindow is shown up because you want to send a message
// It should hide now
- if (mTmpVisible) {
+ if (mTmpVisible)
setVisible(false);
- }
}
}
}
@@ -697,7 +701,15 @@ 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();
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index f7d05df1..03b2062a 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -38,6 +38,7 @@ class Network;
class Recorder;
class Party;
class ScrollArea;
+class ItemLinkHandler;
#define BY_GM 0 // those should be self-explanatory =)
#define BY_PLAYER 1
@@ -185,6 +186,9 @@ class ChatWindow : public Window, public gcn::ActionListener,
/** 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);
@@ -234,7 +238,8 @@ class ChatWindow : public Window, public gcn::ActionListener,
gcn::TextField *mChatInput; /**< Input box for typing chat messages */
BrowserBox *mTextOutput; /**< Text box for displaying chat history */
ScrollArea *mScrollArea; /**< Scroll area around text output */
-
+ ItemLinkHandler *mItemLinkHandler; /** Used for showing item popup on
+ clicking links **/
typedef std::list<std::string> History;
typedef History::iterator HistoryIterator;
History mHistory; /**< Command history */
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 5ac966e3..efe1cd51 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -42,7 +42,8 @@
#include "../utils/tostring.h"
InventoryWindow::InventoryWindow():
- Window(_("Inventory"))
+ Window(_("Inventory")),
+ mItemDesc(false)
{
setWindowName(_("Inventory"));
setResizable(true);
@@ -201,8 +202,7 @@ void InventoryWindow::updateButtons()
}
else {
mUseButton->setCaption(_("Equip"));
- }
- }
+ } }
else {
mUseButton->setCaption(_("Use"));
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 989a5c1d..922dd28f 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -90,6 +90,8 @@ class InventoryWindow : public Window, gcn::ActionListener,
gcn::Button *mUseButton, *mDropButton;
gcn::ScrollArea *mInvenScroll;
TextBox *mWeightLabel;
+
+ bool mItemDesc;
};
extern InventoryWindow *inventoryWindow;
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 7d9b3f70..78745158 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -164,7 +164,8 @@ void ItemContainer::selectNone()
void ItemContainer::refindSelectedItem()
{
- if (mSelectedItemIndex != NO_ITEM) {
+ if (mSelectedItemIndex != NO_ITEM)
+ {
if (mInventory->getItem(mSelectedItemIndex) &&
mInventory->getItem(mSelectedItemIndex)->getId() == mLastSelectedItemId)
@@ -175,7 +176,8 @@ void ItemContainer::refindSelectedItem()
for (int i = 0; i <= mMaxItems + 1; i++)
if (mInventory->getItem(i) &&
- mInventory->getItem(i)->getId() == mLastSelectedItemId) {
+ mInventory->getItem(i)->getId() == mLastSelectedItemId)
+ {
mSelectedItemIndex = i;
return;
}
@@ -248,12 +250,11 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
{
Item *item = mInventory->getItem( getSlotIndex(event.getX(), event.getY() ) );
- if( item )
+ if (item)
{
mItemPopup->setPosition(getParent()->getParent()->getX() +
getParent()->getParent()->getWidth(),
getParent()->getParent()->getY());
-
mItemPopup->setItem(item->getInfo());
mItemPopup->setOpaque(false);
mItemPopup->setVisible(true);
@@ -278,4 +279,3 @@ int ItemContainer::getSlotIndex(const int posX, const int posY) const
return (index);
}
-
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 223a3677..558470bd 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -144,9 +144,9 @@ class ItemContainer : public gcn::Widget,
Inventory *mInventory;
Image *mSelImg;
+
int mSelectedItemIndex;
int mLastSelectedItemId; // last selected item ID. If we lose the item, find again by ID.
-
int mMaxItems;
int mOffset;
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 5f7dc736..c0a75193 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -50,6 +50,7 @@ ItemPopup::ItemPopup():
// Item Description
mItemDesc = new TextBox();
mItemDesc->setEditable(false);
+ mItemDesc->setMinWidth(186);
mItemDescScroll = new ScrollArea(mItemDesc);
mItemDescScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -61,6 +62,7 @@ ItemPopup::ItemPopup():
// Item Effect
mItemEffect = new TextBox();
mItemEffect->setEditable(false);
+ mItemEffect->setMinWidth(186);
mItemEffectScroll = new ScrollArea(mItemEffect);
mItemEffectScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -98,11 +100,9 @@ void ItemPopup::setItem(const ItemInfo &item)
int numRowsEffect = mItemEffect->getNumberOfRows();
if(item.getEffect() == "")
- {
setContentSize(200, (numRowsDesc * 14) + 30);
- } else {
+ else
setContentSize(200, (numRowsDesc * 14) + (numRowsEffect * 14) + 30);
- }
mItemDescScroll->setDimension(gcn::Rectangle(2, 0, 196, numRowsDesc * 14));
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index a02a9eae..fde81cd8 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -25,6 +25,7 @@
#include <guichan/focushandler.hpp>
#include "browserbox.h"
+#include "chat.h"
#include "inventorywindow.h"
#include "item_amount.h"
#include "popupmenu.h"
@@ -248,6 +249,11 @@ void PopupMenu::handleLink(const std::string& link)
}
}
+ else if (link == "chat")
+ {
+ chatWindow->addItemText(mItem->getId(), mItem->getInfo().getName());
+ }
+
else if (link == "drop")
{
new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem);
@@ -297,6 +303,7 @@ void PopupMenu::showPopup(int x, int y, Item *item)
mBrowserBox->addRow(_("@@use|Use@@"));
mBrowserBox->addRow(_("@@drop|Drop@@"));
+ mBrowserBox->addRow(_("@@chat|Add to Chat@@"));
mBrowserBox->addRow(_("@@description|Description@@"));
mBrowserBox->addRow("##3---");
mBrowserBox->addRow(_("@@cancel|Cancel@@"));