From 221794bbd6787e0094b774df319a5d72a57d642d Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Sun, 24 Dec 2023 07:14:34 +1100 Subject: [PATCH] feat(ui): Shop keyboard navigation remembers selected column when moving between differently sized rows (#9617) --- source/ShopPanel.cpp | 11 +++++++++-- source/ShopPanel.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/ShopPanel.cpp b/source/ShopPanel.cpp index 2ef16a91012e..3f185f573b0e 100644 --- a/source/ShopPanel.cpp +++ b/source/ShopPanel.cpp @@ -518,6 +518,8 @@ bool ShopPanel::Click(int x, int y, int /* clicks */) else selectedOutfit = zone.GetOutfit(); + previousX = zone.Center().X(); + return true; } @@ -628,6 +630,9 @@ void ShopPanel::DoFind(const string &text) selectedShip = best->GetShip(); else selectedOutfit = best->GetOutfit(); + + previousX = best->Center().X(); + MainAutoScroll(best); } } @@ -1212,6 +1217,8 @@ void ShopPanel::MainLeft() MainAutoScroll(it); } + previousX = it->Center().X(); + selectedShip = it->GetShip(); selectedOutfit = it->GetOutfit(); } @@ -1234,6 +1241,8 @@ void ShopPanel::MainRight() else MainAutoScroll(it); + previousX = it->Center().X(); + selectedShip = it->GetShip(); selectedOutfit = it->GetOutfit(); } @@ -1250,7 +1259,6 @@ void ShopPanel::MainUp() if(it == zones.end()) it = zones.begin(); - const double previousX = it->Center().X(); const double previousY = it->Center().Y(); while(it != zones.begin() && it->Center().Y() == previousY) --it; @@ -1289,7 +1297,6 @@ void ShopPanel::MainDown() return; } - const double previousX = it->Center().X(); const double previousY = it->Center().Y(); ++it; while(it != zones.end() && it->Center().Y() == previousY) diff --git a/source/ShopPanel.h b/source/ShopPanel.h index 6c89ef022a21..95ae30e87ac1 100644 --- a/source/ShopPanel.h +++ b/source/ShopPanel.h @@ -176,6 +176,8 @@ class ShopPanel : public Panel { ShopPane activePane = ShopPane::Main; char hoverButton = '\0'; + double previousX = 0.; + std::vector zones; std::vector> shipZones; std::vector> categoryZones;