feat: add PieceInfo display

This commit is contained in:
2026-02-05 11:08:07 +08:00
parent 38c6c7474d
commit dd8b57c306
12 changed files with 78 additions and 4 deletions

View File

@@ -82,7 +82,7 @@ void GameScene::onEnter(SDL_Renderer* renderer, int WIDTH, int HEIGHT, UIRendere
}
void GameScene::update() {
updatePieceInfo();
}
void GameScene::renderWorld() {
@@ -149,4 +149,30 @@ void GameScene::restartGame() {
}
);
}
void GameScene::updatePieceInfo() {
auto [mouseX, mouseY] = m_coreData->inputState.mouseCurrentLogicalPosition;
auto click = m_CoordinateConverter->ScreenToBoard(mouseX, mouseY, m_boardRenderer->getBoardArea());
if (click == std::nullopt) {
m_gameUIManager->setLabel("PieceInfoLabel", false);
return;
}
auto [row, col] = click.value();
PieceInfo pieceInfo = m_gameSession->getPieceInfo(row, col);
if (!pieceInfo.hasPiece) {
m_gameUIManager->setLabel("PieceInfoLabel", false);
return;
}
std::string text = "HP: " + std::to_string(pieceInfo.HP) + "\n" + "ATK: " + std::to_string(pieceInfo.ATK);
m_gameUIManager->setLabel("PieceInfoLabel", true);
m_gameUIManager->setLabel("PieceInfoLabel", text);
m_gameUIManager->setLabel("PieceInfoLabel", mouseX, mouseY);
}

View File

@@ -31,6 +31,8 @@ protected:
virtual void handleBoardClick(int row, int col);
void updatePieceInfo();
// 公共成员,子类可以直接访问
std::unique_ptr<BoardRenderer> m_boardRenderer;
std::unique_ptr<CoordinateConverter> m_CoordinateConverter;