Render the Actiontype

This commit is contained in:
2025-12-13 18:35:49 +08:00
parent 4a71e4f742
commit 034c1a858e
5 changed files with 42 additions and 5 deletions

View File

@@ -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;
}
}
}