From 25de0fac3fac02fbd843e33e1494c697dd35638a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 20 Mar 2014 17:52:17 +0300 Subject: Improve viewport. --- src/gui/viewport.h | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src/gui/viewport.h') diff --git a/src/gui/viewport.h b/src/gui/viewport.h index c98350744..a627702d8 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -124,32 +124,39 @@ class Viewport final : public WindowContainer, * Shows a popup for an item. * TODO Find some way to get rid of Item here */ - void showPopup(Window *const parent, const int x, const int y, - Item *const item, const bool isInventory = true); + void showPopup(Window *const parent, + const int x, const int y, + Item *const item, + const bool isInventory = true); /** * Shows a popup for an item. * TODO Find some way to get rid of Item here */ - void showPopup(Window *const parent, Item *const item, + void showPopup(Window *const parent, + Item *const item, const bool isInventory = true); - void showPopup(const int x, const int y, Button *const button); + void showPopup(const int x, const int y, + Button *const button); - void showPopup(const int x, const int y, const ProgressBar *const bar); + void showPopup(const int x, const int y, + const ProgressBar *const bar); void showPopup(MapItem *const item); void showItemPopup(Item *const item); - void showItemPopup(const int itemId, const unsigned char color = 1); + void showItemPopup(const int itemId, + const unsigned char color = 1); void showDropPopup(Item *const item); /** * Shows a popup for being. */ - void showPopup(const int x, const int y, const Being *const being); + void showPopup(const int x, const int y, + const Being *const being); void showPopup(const Being *const being); @@ -161,7 +168,8 @@ class Viewport final : public WindowContainer, void showSpellPopup(TextCommand *const cmd); - void showAttackMonsterPopup(const std::string &name, const int type); + void showAttackMonsterPopup(const std::string &name, + const int type); void showPickupItemPopup(const std::string &name); @@ -169,7 +177,8 @@ class Viewport final : public WindowContainer, * Shows the related popup menu when right click on the chat * at the specified mouse coordinates. */ - void showChatPopup(const int x, const int y, ChatTab *const tab); + void showChatPopup(const int x, const int y, + ChatTab *const tab); /** * Shows the related popup menu when right click on the chat @@ -177,7 +186,8 @@ class Viewport final : public WindowContainer, void showChatPopup(ChatTab *const tab); void showUndressPopup(const int x, const int y, - const Being *const being, Item *const item); + const Being *const being, + Item *const item); void showMapPopup(const int x, const int y); @@ -268,7 +278,8 @@ class Viewport final : public WindowContainer, bool isPopupMenuVisible() const A_WARN_UNUSED; - void moveCameraToActor(const int actorId, const int x = 0, + void moveCameraToActor(const int actorId, + const int x = 0, const int y = 0); void moveCameraToPosition(const int x, const int y); @@ -292,13 +303,14 @@ class Viewport final : public WindowContainer, * Finds a path from the player to the mouse, and draws it. This is for * debug purposes. */ - void _drawDebugPath(Graphics *const graphics); + void drawDebugPath(Graphics *const graphics); /** * Draws the given path. */ - void _drawPath(Graphics *const graphics, const Path &path, - const Color &color = Color(255, 0, 0)) const; + void drawPath(Graphics *const graphics, + const Path &path, + const Color &color = Color(255, 0, 0)) const; bool leftMouseAction(); @@ -309,7 +321,7 @@ class Viewport final : public WindowContainer, /** * Make the player go to the mouse position. */ - void _followMouse(); + void followMouse(); Map *mMap; /**< The current map. */ -- cgit v1.2.3-70-g09d2 From 7b07b0a09fd9799a7aca09c0dcd97a53547b0fa1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 22 Mar 2014 15:38:51 +0300 Subject: Add context menu into windows. --- src/gui/popups/popupmenu.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++-- src/gui/popups/popupmenu.h | 2 ++ src/gui/viewport.cpp | 5 ++++ src/gui/viewport.h | 2 ++ src/gui/widgets/window.cpp | 16 +++++++++-- src/gui/widgets/window.h | 3 +++ 6 files changed, 87 insertions(+), 4 deletions(-) (limited to 'src/gui/viewport.h') diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 3905d91e6..330df1a6c 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -840,6 +840,47 @@ void PopupMenu::showChangePos(const int x, const int y) } } +void PopupMenu::showWindowPopup(Window *const window, + const int x, const int y) +{ + if (!window) + return; + + mWindow = window; + mBrowserBox->clearRows(); + // TRANSLATORS: popup menu header + mBrowserBox->addRow(_("window")); + + if (window->getCloseButton()) + { + // TRANSLATORS: popup menu item + // TRANSLATORS: close window + mBrowserBox->addRow("window close", _("Close")); + } + + if (window->isStickyButtonLock()) + { + if (window->isSticky()) + { + // TRANSLATORS: popup menu item + // TRANSLATORS: unlock window + mBrowserBox->addRow("window unlock", _("Unlock")); + } + else + { + // TRANSLATORS: popup menu item + // TRANSLATORS: lock window + mBrowserBox->addRow("window lock", _("Lock")); + } + } + + // TRANSLATORS: popup menu item + // TRANSLATORS: close menu + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); +} + void PopupMenu::handleLink(const std::string &link, MouseEvent *event A_UNUSED) { @@ -1196,8 +1237,11 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "retrieve" && mItem) { - ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, - mWindow, mItem); + if (Widget::widgetExists(mWindow)) + { + ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, + mWindow, mItem); + } } else if (link == "retrieve 10" && mItem) { @@ -1748,6 +1792,21 @@ void PopupMenu::handleLink(const std::string &link, showGMPopup(); return; } + else if (link == "window close" && mWindow) + { + if (Widget::widgetExists(mWindow)) + mWindow->close(); + } + else if (link == "window unlock" && mWindow) + { + if (Widget::widgetExists(mWindow)) + mWindow->setSticky(false); + } + else if (link == "window lock" && mWindow) + { + if (Widget::widgetExists(mWindow)) + mWindow->setSticky(true); + } else if (!link.compare(0, 10, "guild-pos-")) { if (player_node) diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h index 7eb38dc15..8bdbd3b1b 100644 --- a/src/gui/popups/popupmenu.h +++ b/src/gui/popups/popupmenu.h @@ -182,6 +182,8 @@ class PopupMenu final : public Popup, public LinkHandler void showNpcDialogPopup(const int npcId, const int x, const int y); + void showWindowPopup(Window *const window, const int x, const int y); + /** * Handles link action. */ diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 16112fef6..ba11bdf95 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -846,6 +846,11 @@ void Viewport::showNpcDialogPopup(const int npcId) mPopupMenu->showNpcDialogPopup(npcId, mMouseX, mMouseY); } +void Viewport::showWindowPopup(Window *const window) +{ + mPopupMenu->showWindowPopup(window, mMouseX, mMouseY); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index a627702d8..d401a3af4 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -199,6 +199,8 @@ class Viewport final : public WindowContainer, void showNpcDialogPopup(const int npcId); + void showWindowPopup(Window *const window); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 8d457e599..4f8bc88b3 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -641,6 +641,7 @@ void Window::setStickyButton(const bool flag) void Window::setSticky(const bool sticky) { mSticky = sticky; + mRedraw = true; } void Window::setStickyButtonLock(const bool lock) @@ -704,6 +705,9 @@ void Window::scheduleDelete() void Window::mousePressed(MouseEvent &event) { + if (event.isConsumed()) + return; + if (event.getSource() == this) { if (getParent()) @@ -714,7 +718,8 @@ void Window::mousePressed(MouseEvent &event) mMoved = event.getY() <= static_cast(mTitleBarHeight); } - if (event.getButton() == MouseEvent::LEFT) + const unsigned int button = event.getButton(); + if (button == MouseEvent::LEFT) { const int x = event.getX(); const int y = event.getY(); @@ -735,7 +740,6 @@ void Window::mousePressed(MouseEvent &event) setSticky(!isSticky()); mouseResize = 0; mMoved = 0; - mRedraw = true; event.consume(); return; } @@ -749,6 +753,14 @@ void Window::mousePressed(MouseEvent &event) else mMoved = false; } + else if (button == MouseEvent::RIGHT) + { + if (viewport) + { + event.consume(); + viewport->showWindowPopup(this); + } + } } void Window::close() diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 2c4ee5e5f..dfd1f63b7 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -170,6 +170,9 @@ class Window : public BasicContainer2, */ void setCloseButton(const bool flag); + bool getCloseButton() const A_WARN_UNUSED + { return mCloseWindowButton; } + /** * Returns whether the window can be resized. */ -- cgit v1.2.3-70-g09d2