summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-07 20:02:02 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-07 20:02:02 +0300
commit4fc40c384a3423e43f2e589809c9bc9aa8bda495 (patch)
treebe68429d688d6ef7bcba72c865ebcd080db871c6
parent249d59d10905f46ee91683d08386c7bc9936bc4b (diff)
downloadmv-4fc40c384a3423e43f2e589809c9bc9aa8bda495.tar.gz
mv-4fc40c384a3423e43f2e589809c9bc9aa8bda495.tar.bz2
mv-4fc40c384a3423e43f2e589809c9bc9aa8bda495.tar.xz
mv-4fc40c384a3423e43f2e589809c9bc9aa8bda495.zip
For some popup menus use current mouse position.
-rw-r--r--src/actions/actions.cpp3
-rw-r--r--src/gui/popups/popupmenu.cpp55
-rw-r--r--src/gui/popups/popupmenu.h13
-rw-r--r--src/gui/widgets/avatarlistbox.cpp4
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp6
-rw-r--r--src/gui/widgets/textfield.cpp16
-rw-r--r--src/gui/widgets/window.cpp17
-rw-r--r--src/gui/windows/whoisonline.cpp4
8 files changed, 44 insertions, 74 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 572068a63..825e5756a 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -572,8 +572,7 @@ impHandler0(showWindows)
{
if (popupMenu)
{
- popupMenu->showWindowsPopup(viewport->mMouseX,
- viewport->mMouseY);
+ popupMenu->showWindowsPopup();
return true;
}
return false;
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index b3569488e..14f3cf495 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -40,6 +40,7 @@
#include "input/inputmanager.h"
#include "gui/buttontext.h"
+#include "gui/gui.h"
#include "gui/viewport.h"
#include "gui/windows/chatwindow.h"
@@ -317,6 +318,19 @@ void PopupMenu::showPopup(const int x, const int y, const Being *const being)
showPopup(x, y);
}
+void PopupMenu::setMousePos()
+{
+ if (viewport)
+ {
+ mX = viewport->mMouseX;
+ mY = viewport->mMouseY;
+ }
+ else
+ {
+ Gui::getMouseState(&mX, &mY);
+ }
+}
+
void PopupMenu::showPopup(const int x, const int y,
const std::vector<ActorSprite*> &beings)
{
@@ -351,17 +365,15 @@ void PopupMenu::showPopup(const int x, const int y,
showPopup(x, y);
}
-void PopupMenu::showPlayerPopup(const int x, const int y,
- const std::string &nick)
+void PopupMenu::showPlayerPopup(const std::string &nick)
{
if (nick.empty() || !localPlayer)
return;
+ setMousePos();
mNick = nick;
mBeingId = 0;
mType = static_cast<int>(ActorType::PLAYER);
- mX = x;
- mY = y;
mBrowserBox->clearRows();
const std::string &name = mNick;
@@ -447,7 +459,7 @@ void PopupMenu::showPlayerPopup(const int x, const int y,
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
void PopupMenu::showPopup(const int x, const int y,
@@ -456,9 +468,9 @@ void PopupMenu::showPopup(const int x, const int y,
if (!floorItem)
return;
- mFloorItemId = floorItem->getId();
mX = x;
mY = y;
+ mFloorItemId = floorItem->getId();
mType = static_cast<int>(ActorType::FLOOR_ITEM);
mBrowserBox->clearRows();
const std::string name = floorItem->getName();
@@ -494,7 +506,7 @@ void PopupMenu::showPopup(const int x, const int y,
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
void PopupMenu::showPopup(const int x, const int y, MapItem *const mapItem)
@@ -854,12 +866,12 @@ void PopupMenu::showChangePos(const int x, const int y)
}
}
-void PopupMenu::showWindowPopup(Window *const window,
- const int x, const int y)
+void PopupMenu::showWindowPopup(Window *const window)
{
if (!window)
return;
+ setMousePos();
mWindow = window;
mBrowserBox->clearRows();
// TRANSLATORS: popup menu header
@@ -871,7 +883,7 @@ void PopupMenu::showWindowPopup(Window *const window,
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
void PopupMenu::addWindowMenu(Window *const window)
@@ -2412,10 +2424,9 @@ void PopupMenu::showUndressPopup(const int x, const int y,
showPopup(x, y);
}
-void PopupMenu::showTextFieldPopup(int x, int y, TextField *const input)
+void PopupMenu::showTextFieldPopup(TextField *const input)
{
- mX = x;
- mY = y;
+ setMousePos();
mTextField = input;
mBrowserBox->clearRows();
@@ -2431,14 +2442,12 @@ void PopupMenu::showTextFieldPopup(int x, int y, TextField *const input)
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
-void PopupMenu::showLinkPopup(const int x, const int y,
- const std::string &link)
+void PopupMenu::showLinkPopup(const std::string &link)
{
- mX = x;
- mY = y;
+ setMousePos();
mNick = link;
mBrowserBox->clearRows();
@@ -2454,14 +2463,12 @@ void PopupMenu::showLinkPopup(const int x, const int y,
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
-void PopupMenu::showWindowsPopup(const int x, const int y)
+void PopupMenu::showWindowsPopup()
{
- mX = x;
- mY = y;
-
+ setMousePos();
mBrowserBox->clearRows();
const std::vector<ButtonText*> &names = windowMenu->getButtonTexts();
// TRANSLATORS: popup menu header
@@ -2481,7 +2488,7 @@ void PopupMenu::showWindowsPopup(const int x, const int y)
// TRANSLATORS: close menu
mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
+ showPopup(mX, mY);
}
void PopupMenu::showNpcDialogPopup(const int npcId, const int x, const int y)
diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h
index fe9d0855e..2e15652e6 100644
--- a/src/gui/popups/popupmenu.h
+++ b/src/gui/popups/popupmenu.h
@@ -73,8 +73,7 @@ class PopupMenu final : public Popup, public LinkHandler
void showPopup(const int x, const int y,
const std::vector<ActorSprite*> &beings);
- void showPlayerPopup(const int x, const int y,
- const std::string &nick);
+ void showPlayerPopup(const std::string &nick);
/**
* Shows the floor item related popup menu at the specified
@@ -131,15 +130,15 @@ class PopupMenu final : public Popup, public LinkHandler
void showPopup(const int x, const int y, ListModel *const model);
- void showTextFieldPopup(int x, int y, TextField *const input);
+ void showTextFieldPopup(TextField *const input);
- void showLinkPopup(const int x, const int y, const std::string &link);
+ void showLinkPopup(const std::string &link);
- void showWindowsPopup(const int x, const int y);
+ void showWindowsPopup();
void showNpcDialogPopup(const int npcId, const int x, const int y);
- void showWindowPopup(Window *const window, const int x, const int y);
+ void showWindowPopup(Window *const window);
/**
* Handles link action.
@@ -150,6 +149,8 @@ class PopupMenu final : public Popup, public LinkHandler
void clear();
private:
+ void setMousePos();
+
void addPlayerRelation(const std::string &name);
void addFollow();
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 909f01618..e0fbc4d4b 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -401,9 +401,7 @@ void AvatarListBox::mousePressed(MouseEvent &event)
}
else
{
- popupMenu->showPlayerPopup(viewport->mMouseX,
- viewport->mMouseY,
- avatar->getName());
+ popupMenu->showPlayerPopup(avatar->getName());
}
}
break;
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 6c04ca41f..eef888169 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -76,11 +76,7 @@ void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
else if (button == MouseButton::RIGHT)
{
if (popupMenu)
- {
- popupMenu->showLinkPopup(viewport->mMouseX,
- viewport->mMouseY,
- url);
- }
+ popupMenu->showLinkPopup(url);
}
}
else if (!link.empty() && link[0] == '?')
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index a20b05e1e..48d3a86fc 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -706,21 +706,7 @@ void TextField::mousePressed(MouseEvent &event)
if (event.getButton() == MouseButton::RIGHT)
{
if (popupMenu)
- {
- if (viewport)
- {
- popupMenu->showTextFieldPopup(viewport->mMouseX,
- viewport->mMouseY,
- this);
- }
- else
- {
- int mouseX = 0;
- int mouseY = 0;
- Gui::getMouseState(&mouseX, &mouseY);
- popupMenu->showTextFieldPopup(mouseX, mouseY, this);
- }
- }
+ popupMenu->showTextFieldPopup(this);
}
else if (event.getButton() == MouseButton::LEFT)
{
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index dd7627b23..5cf430821 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -769,22 +769,7 @@ void Window::mousePressed(MouseEvent &event)
if (popupMenu)
{
event.consume();
-
- if (viewport)
- {
- popupMenu->showWindowPopup(this,
- viewport->mMouseX,
- viewport->mMouseY);
- }
- else
- {
- int mouseX = 0;
- int mouseY = 0;
- Gui::getMouseState(&mouseX, &mouseY);
- popupMenu->showWindowPopup(this,
- mouseX,
- mouseY);
- }
+ popupMenu->showWindowPopup(this);
}
}
}
diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp
index 57d36e57c..c71eb4055 100644
--- a/src/gui/windows/whoisonline.cpp
+++ b/src/gui/windows/whoisonline.cpp
@@ -217,9 +217,7 @@ void WhoIsOnline::handleLink(const std::string& link, MouseEvent *event)
return;
}
}
- popupMenu->showPlayerPopup(viewport->mMouseX,
- viewport->mMouseY,
- link);
+ popupMenu->showPlayerPopup(link);
}
}
}