mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 23:53:54 -07:00
Implements a start to the keyboard navigation with the direction arrows and the space key for card selection. Some binds are still needed, but navigating the board is now possible. The feature includes tests for the implemented feature. Closes #5043 Co-authored-by: Manuel Ramos Monge <manuel.monge@tecnico.ulisboa.pt>
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
/**
|
|
* @file keyboard_card_navigator.h
|
|
* @ingroup GameInput
|
|
* @brief Handles keyboard navigation for selecting cards using arrow keys.
|
|
*
|
|
* Allows players to navigate through hand cards using directional arrow keys.
|
|
* Spatially-aware: finds adjacent cards based on screen position.
|
|
*/
|
|
|
|
#ifndef KEYBOARD_CARD_NAVIGATOR_H
|
|
#define KEYBOARD_CARD_NAVIGATOR_H
|
|
|
|
#include "zones/card_zone_logic.h"
|
|
|
|
class PlayerLogic;
|
|
class CardItem;
|
|
class QKeyEvent;
|
|
class ArrowItem;
|
|
|
|
class KeyboardCardNavigator
|
|
{
|
|
private:
|
|
CardZoneLogic *currentZone;
|
|
int hoveredCardIndex = -1;
|
|
bool isArrowModeActive;
|
|
CardItem *arrowOriginCard;
|
|
ArrowItem *previewArrow;
|
|
PlayerLogic *playerLogic;
|
|
/**
|
|
* @brief Gets hand cards sorted by visual position.
|
|
* @return List of cards sorted by visual order (left-to-right for horizontal, top-to-bottom for vertical).
|
|
*/
|
|
CardList getVisuallyOrderedHandCards() const;
|
|
|
|
public:
|
|
KeyboardCardNavigator(PlayerLogic *player = nullptr);
|
|
int getHoveredIndex();
|
|
CardZoneLogic *getCurrentZone();
|
|
void setCurrentZone(CardZoneLogic *zone);
|
|
void switchCardInZone(QKeyEvent *event);
|
|
void switchZone(QKeyEvent *event);
|
|
void setPlayer(PlayerLogic *player);
|
|
/**
|
|
* @brief Validates and resets the hovered card if needed.
|
|
* Call this when hand composition changes.
|
|
*/
|
|
void setHoveredCardIndex(int index);
|
|
void unhoverCard();
|
|
void changeHoverCard(int cardIndex, bool hover);
|
|
void createArrow(CardItem *targetCard);
|
|
void createTempArrow(CardItem *targetCard);
|
|
void startArrowMode(CardItem *originCard);
|
|
void cancelArrowMode();
|
|
CardZoneLogic *findZoneWithCards(QList<CardZoneLogic *> &zonesList, int currentZoneIndex, bool upperZone);
|
|
bool isArrowModeActiveVar() const
|
|
{
|
|
return isArrowModeActive;
|
|
}
|
|
};
|
|
|
|
#endif
|