From 08b04a3527933a8691f35bfd279c7ca9202e70bb Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Mon, 23 Jan 2023 15:43:55 +0300 Subject: [PATCH] handle double-click in Town Portal dialog --- client/gui/CGuiHandler.cpp | 7 ++++++- client/windows/GUIClasses.cpp | 7 ++++++- client/windows/GUIClasses.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index be4abb5b3..8d9d83ef9 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -284,6 +284,8 @@ void CGuiHandler::handleCurrentEvent() switch(current->button.button) { case SDL_BUTTON_LEFT: + { + auto doubleClicked = false; if(lastClick == current->motion && (SDL_GetTicks() - lastClickTime) < 300) { std::list hlp = doubleClickInterested; @@ -293,6 +295,7 @@ void CGuiHandler::handleCurrentEvent() if((*i)->pos.isInside(current->motion.x, current->motion.y)) { (*i)->onDoubleClick(); + doubleClicked = true; } } @@ -301,8 +304,10 @@ void CGuiHandler::handleCurrentEvent() lastClick = current->motion; lastClickTime = SDL_GetTicks(); - handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, true); + if(!doubleClicked) + handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, true); break; + } case SDL_BUTTON_RIGHT: handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true); break; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 72fed07f5..c8c29db8c 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -2039,7 +2039,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner): } CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::string _text) - : CIntObject(LCLICK), + : CIntObject(LCLICK | DOUBLECLICK), parent(_parent), index(_id) { @@ -2069,6 +2069,11 @@ void CObjectListWindow::CItem::clickLeft(tribool down, bool previousState) parent->changeSelection(index); } +void CObjectListWindow::CItem::onDoubleClick() +{ + parent->elementSelected(); +} + CObjectListWindow::CObjectListWindow(const std::vector & _items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection) : CWindowObject(PLAYER_COLORED, "TPGATE"), onSelect(Callback), diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index a9436a5ee..8e2efad6b 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -163,6 +163,7 @@ class CObjectListWindow : public CWindowObject void select(bool on); void clickLeft(tribool down, bool previousState) override; + void onDoubleClick() override; }; std::function onSelect;//called when OK button is pressed, returns id of selected item.