From 24f4c6de03a3a65df1ad9100e912e968fe9b8b18 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 12 Jun 2013 23:45:14 +0300 Subject: add copy to clipboard in npc dialog. --- src/gui/npcdialog.cpp | 26 ++++++++++++++++++++++++++ src/gui/npcdialog.h | 4 ++++ src/gui/popupmenu.cpp | 20 ++++++++++++++++++++ src/gui/popupmenu.h | 2 ++ src/gui/viewport.cpp | 5 +++++ src/gui/viewport.h | 3 +++ 6 files changed, 60 insertions(+) (limited to 'src') diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 2271a0bc7..0d9a27bcc 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -50,6 +50,7 @@ #include "net/net.h" #include "net/npchandler.h" +#include "utils/copynpaste.h" #include "utils/gettext.h" #include @@ -787,3 +788,28 @@ void NpcDialog::clearDialogs() } mNpcDialogs.clear(); } + +void NpcDialog::mousePressed(gcn::MouseEvent &event) +{ + Window::mousePressed(event); + if (event.getButton() == gcn::MouseEvent::RIGHT + && event.getSource() == mTextBox) + { + if (viewport) + viewport->showNpcDialogPopup(mNpcId); + } +} + +void NpcDialog::copyToClipboard(const int npcId, const int x, const int y) +{ + NpcDialogs::iterator it = mNpcDialogs.find(npcId); + if (it != mNpcDialogs.end()) + { + const BrowserBox *const text = (*it).second->mTextBox; + if (!text) + return; + + std::string str = text->getTextAtPos(x, y); + sendBuffer(str); + } +} diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index 8a4e5b614..815bc7564 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -205,6 +205,10 @@ class NpcDialog final : public Window, void clearRows(); + void mousePressed(gcn::MouseEvent &event); + + static void copyToClipboard(const int npcId, const int x, const int y); + static NpcDialogs mNpcDialogs; static void clearDialogs(); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 91bf514a3..b6272a4e4 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -44,6 +44,7 @@ #include "gui/inventorywindow.h" #include "gui/itemamountwindow.h" #include "gui/ministatuswindow.h" +#include "gui/npcdialog.h" #include "gui/outfitwindow.h" #include "gui/selldialog.h" #include "gui/skilldialog.h" @@ -1352,6 +1353,10 @@ void PopupMenu::handleLink(const std::string &link, if (chatWindow) chatWindow->copyToClipboard(mX, mY); } + else if (link == "npc clipboard" && mBeingId) + { + NpcDialog::copyToClipboard(mBeingId, mX, mY); + } else if (link == "remove attack" && being) { if (actorSpriteManager && being->getType() == Being::MONSTER) @@ -2366,6 +2371,21 @@ void PopupMenu::showWindowsPopup(const int x, const int y) showPopup(x, y); } +void PopupMenu::showNpcDialogPopup(const int npcId, const int x, const int y) +{ + mBeingId = npcId; + mX = x; + mY = y; + mBrowserBox->clearRows(); + // TRANSLATORS: popup menu item + mBrowserBox->addRow("npc clipboard", _("Copy to clipboard")); + mBrowserBox->addRow("##3---"); + // TRANSLATORS: popup menu item + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); +} + void PopupMenu::showPopup(int x, int y) { const int pad2 = 2 * mPadding; diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index ef2c10ff0..3eac9355a 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -178,6 +178,8 @@ class PopupMenu final : public Popup, public LinkHandler void showWindowsPopup(const int x, const int y); + void showNpcDialogPopup(const int npcId, const int x, const int y); + /** * Handles link action. */ diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 7ca330f95..867142c52 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -813,6 +813,11 @@ void Viewport::showWindowsPopup() mPopupMenu->showWindowsPopup(mMouseX, mMouseY); } +void Viewport::showNpcDialogPopup(const int npcId) +{ + mPopupMenu->showNpcDialogPopup(npcId, mMouseX, mMouseY); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index cde09b7fd..128689186 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -35,6 +35,7 @@ class ActorSprite; class Button; class Being; class BeingPopup; +class BrowserBox; class ChatTab; class FloorItem; class Graphics; @@ -189,6 +190,8 @@ class Viewport final : public WindowContainer, void showWindowsPopup(); + void showNpcDialogPopup(const int npcId); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. -- cgit v1.2.3-70-g09d2