mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Render the Actiontype
This commit is contained in:
@@ -198,4 +198,8 @@ int GameSession::getOldComponentID(int row, int col) {
|
||||
|
||||
const Board* GameSession::getBoard() const {
|
||||
return m_board.get();
|
||||
}
|
||||
|
||||
ActionType GameSession::getCurrentActionType() const {
|
||||
return m_currentActionType;
|
||||
}
|
||||
@@ -52,4 +52,7 @@ public:
|
||||
std::optional<std::pair<int, int>> getSelectedPiece() const;
|
||||
|
||||
const Board* getBoard() const;
|
||||
|
||||
ActionType getCurrentActionType() const;
|
||||
|
||||
};
|
||||
@@ -45,6 +45,7 @@ void GameScene::handleClick(float screenX, float screenY) {
|
||||
auto [row, col] = click.value();
|
||||
m_gameSession->handleCoordinateInput(row, col);
|
||||
m_gameSession->printBoard();
|
||||
m_gameUIManager->updateActionType( m_gameSession->getCurrentActionType());
|
||||
} else {
|
||||
SDL_Log("invail cilck aera!");
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ void GameUIManager::init() {
|
||||
button->setPosition(20, 20);
|
||||
button->setEnabled(true);
|
||||
button->setVisible(true);
|
||||
button->setText("hello,world!!", {"SourceHanSansSC-Regular.otf", 48, {0, 0, 0, 255}});
|
||||
button->setName("TestButton");
|
||||
button->setText("Please Choose", {"SourceHanSansSC-Regular.otf", 48, {0, 0, 0, 255}});
|
||||
button->setName("ActionButton");
|
||||
m_buttons.emplace(button->getNameHash(), std::move(button));
|
||||
|
||||
auto label = std::make_unique<Label>();
|
||||
label->setPosition(1200, 20);
|
||||
label->setText("0 0", {"SourceHanSansSC-Regular.otf", 48, {0, 0, 0, 255}});
|
||||
@@ -67,3 +68,28 @@ void GameUIManager::UpdateMousePositon(float x, float y) {
|
||||
|
||||
m_labels[makeHash("MousePositionLabel")]->setText(pos);
|
||||
}
|
||||
|
||||
void GameUIManager::updateActionType(ActionType type) {
|
||||
// 根据传入的 ActionType 更新 UI 组件状态
|
||||
auto buttonIt = m_buttons.find(makeHash("ActionButton"));
|
||||
if (buttonIt != m_buttons.end()) {
|
||||
auto& button = buttonIt->second;
|
||||
switch (type) {
|
||||
case ActionType::GROW:
|
||||
button->setBackgroundColor({255, 100, 0, 255}); // 橙色
|
||||
button->setText("GROW");
|
||||
break;
|
||||
case ActionType::MOVE:
|
||||
button->setBackgroundColor({0, 255, 0, 255}); // 绿色
|
||||
button->setText("MOVE");
|
||||
break;
|
||||
case ActionType::SPORE:
|
||||
button->setBackgroundColor({0, 0, 255, 255}); // 蓝色
|
||||
button->setText("SPORE");
|
||||
break;
|
||||
default:
|
||||
button->setBackgroundColor({255, 100, 0, 255}); // 默认橙色
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
#include "ui/base/IUIManager.h"
|
||||
|
||||
#include "game/GameTypes.h"
|
||||
class GameUIManager : public IUIManager {
|
||||
private:
|
||||
|
||||
public:
|
||||
GameUIManager(SDL_Renderer* renderer, TextRenderer* textRenderer);
|
||||
|
||||
@@ -16,4 +14,9 @@ public:
|
||||
void CollectRenderData();
|
||||
|
||||
void UpdateMousePositon(float x, float y);
|
||||
|
||||
void updateActionType(ActionType type);
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user