diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index c090c2d27..ad49ad486 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -912,10 +912,21 @@ Uint32 dbClickTimer; bool HandleMouseEventList(const SDL_Event &event, UiList *uiList) { - if (event.type != SDL_MOUSEBUTTONUP || event.button.button != SDL_BUTTON_LEFT) + if (event.button.button != SDL_BUTTON_LEFT) + return false; + + if (event.type != SDL_MOUSEBUTTONUP && event.type != SDL_MOUSEBUTTONDOWN) return false; std::size_t index = uiList->indexAt(event.button.y); + if (event.type == SDL_MOUSEBUTTONDOWN) { + uiList->Press(index); + return true; + } + + if (event.type == SDL_MOUSEBUTTONUP && !uiList->IsPressed(index)) + return false; + index += listOffset; if (gfnListFocus != nullptr && SelectedItem != index) { @@ -1038,6 +1049,8 @@ bool UiItemMouseEvents(SDL_Event *event, const std::vector &items) for (const auto &item : items) { if (item->IsType(UiType::Button)) { HandleGlobalMouseUpButton(static_cast(item)); + } else if (item->IsType(UiType::List)) { + static_cast(item)->Release(); } } } @@ -1069,6 +1082,8 @@ bool UiItemMouseEvents(SDL_Event *event, const std::vectorIsType(UiType::Button)) { HandleGlobalMouseUpButton(static_cast(item.get())); + } else if (item->IsType(UiType::List)) { + static_cast(item.get())->Release(); } } } diff --git a/Source/DiabloUI/ui_item.h b/Source/DiabloUI/ui_item.h index ad51143bf..b04c79776 100644 --- a/Source/DiabloUI/ui_item.h +++ b/Source/DiabloUI/ui_item.h @@ -381,6 +381,8 @@ public: { for (const auto &item : vItems) m_vecItems.push_back(item.get()); + + pressed_item_index_ = -1; } [[nodiscard]] SDL_Rect itemRect(int i) const @@ -412,6 +414,21 @@ public: return spacing_; } + [[nodiscard]] bool IsPressed(size_t index) const + { + return pressed_item_index_ == index; + } + + void Press(size_t index) + { + pressed_item_index_ = index; + } + + void Release() + { + pressed_item_index_ = -1; + } + // private: size_t viewportSize; Sint16 m_x, m_y; @@ -420,5 +437,8 @@ public: private: int spacing_; + + // State + size_t pressed_item_index_; }; } // namespace devilution