mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
feat: add PieceInfo display
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui/managers/debug/DebugData.h"
|
||||
#include "input/InputState.h"
|
||||
|
||||
struct CoreData {
|
||||
DebugData debugData;
|
||||
InputState inputState;
|
||||
};
|
||||
@@ -31,7 +31,7 @@ bool GameApplication::initialize() {
|
||||
|
||||
|
||||
// 输入管理
|
||||
m_inputManager = std::make_unique<InputManager>();
|
||||
m_inputManager = std::make_unique<InputManager>(m_coreData.inputState);
|
||||
// 窗口管理
|
||||
m_windowManager = std::make_unique<WindowManager>();
|
||||
|
||||
@@ -79,6 +79,8 @@ SDL_AppResult GameApplication::handleInputEvent(SDL_Event* event) {
|
||||
}
|
||||
auto pos = Tools::physicalToLogical(input.mouseCurrentPosition.first, input.mouseCurrentPosition.second, m_windowManager->getViewport());
|
||||
|
||||
m_coreData.inputState.mouseCurrentLogicalPosition = pos;
|
||||
|
||||
m_debugManager->updateMousePos(pos.first, pos.second, input);
|
||||
|
||||
m_windowManager->setFullscreen(input.isFullscreen);
|
||||
|
||||
@@ -291,4 +291,21 @@ int GameSession::getOldComponentID(int row, int col) {
|
||||
|
||||
GameState GameSession::getGameState() const {
|
||||
return m_gameState;
|
||||
}
|
||||
|
||||
PieceInfo GameSession::getPieceInfo(int row, int col) const {
|
||||
PieceInfo pieceInfo;
|
||||
|
||||
auto piece = m_board->getPieceAt(row, col);
|
||||
|
||||
if (!piece) {
|
||||
pieceInfo.hasPiece = false;
|
||||
return pieceInfo;
|
||||
}
|
||||
pieceInfo.hasPiece = true;
|
||||
pieceInfo.HP = piece->getHP();
|
||||
pieceInfo.ATK = piece->getATK();
|
||||
|
||||
return pieceInfo;
|
||||
|
||||
}
|
||||
@@ -74,4 +74,6 @@ public:
|
||||
return m_gameRound;
|
||||
}
|
||||
|
||||
PieceInfo getPieceInfo(int row, int col) const;
|
||||
|
||||
};
|
||||
@@ -37,6 +37,12 @@ enum class GamePieceEvent {
|
||||
SPORE_PIECE
|
||||
};
|
||||
|
||||
struct PieceInfo {
|
||||
bool hasPiece = false;
|
||||
int HP = 0;
|
||||
int ATK = 0;
|
||||
};
|
||||
|
||||
|
||||
namespace Stat {
|
||||
constexpr int DefaultHP = 20;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
#include "InputManager.h"
|
||||
|
||||
InputManager::InputManager(InputState& inputState) :
|
||||
m_currentInputState(inputState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SDL_AppResult InputManager::handleInputEvent(const SDL_Event* event) {
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "InputState.h"
|
||||
class InputManager {
|
||||
public:
|
||||
|
||||
InputManager(InputState& inputState);
|
||||
SDL_AppResult handleInputEvent(const SDL_Event* event);
|
||||
|
||||
InputState GetInputState() const;
|
||||
private:
|
||||
InputState m_currentInputState;
|
||||
InputState& m_currentInputState;
|
||||
};
|
||||
@@ -5,5 +5,6 @@ struct InputState
|
||||
std::pair<float, float> mouseCilckOn;
|
||||
bool leftMouseDown = false;
|
||||
std::pair<float, float> mouseCurrentPosition;
|
||||
std::pair<int, int> mouseCurrentLogicalPosition;
|
||||
bool isFullscreen = false;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
label->setText(text, {"SourceHanSansSC-Regular.otf", UI::UI_NORMAL_FONT_SIZE, {0, 0, 0, 255}});
|
||||
label->setName(name);
|
||||
label->setVisible(true);
|
||||
label->setBackgroundColor({0, 0, 0, 0});
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,15 @@ void GameUIManager::setupUIComponents() {
|
||||
);
|
||||
m_labels.emplace(playerLabel->getNameHash(), std::move(playerLabel));
|
||||
|
||||
auto pieceInfoLabel = UIWidgetFactory::createStandardLabel(
|
||||
"PieceInfoLabel",
|
||||
"HP: 0\nATK: 0",
|
||||
120,
|
||||
0
|
||||
);
|
||||
pieceInfoLabel->setVisible(false);
|
||||
m_labels.emplace(pieceInfoLabel->getNameHash(), std::move(pieceInfoLabel));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user