mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-09 22:06:09 +08:00
feat: add UIManager interface for external modification
This commit is contained in:
@@ -20,9 +20,50 @@ public:
|
||||
virtual const UIRenderData& getUIRenderData() = 0;
|
||||
// 收集渲染数据
|
||||
virtual void CollectRenderData() = 0;
|
||||
|
||||
|
||||
|
||||
// 提供接口给外部设置ui的各种设置
|
||||
void setButton(const std::string& name, int x, int y) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_buttons.find(hash);
|
||||
if (it != m_buttons.end()) {
|
||||
it->second->setPosition(x, y);
|
||||
}
|
||||
}
|
||||
void setButton(const std::string&name, bool enabled) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_buttons.find(hash);
|
||||
if (it != m_buttons.end()) {
|
||||
it->second->setEnabled(enabled);
|
||||
it->second->setVisible(enabled);
|
||||
}
|
||||
}
|
||||
void setButton(const std::string& name, const std::string& text) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_buttons.find(hash);
|
||||
if (it != m_buttons.end()) {
|
||||
it->second->setText(text);
|
||||
}
|
||||
}
|
||||
void setLabel(const std::string& name, int x, int y) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_labels.find(hash);
|
||||
if (it != m_labels.end()) {
|
||||
it->second->setPosition(x, y);
|
||||
}
|
||||
}
|
||||
void setLabel(const std::string& name, bool visible) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_labels.find(hash);
|
||||
if (it != m_labels.end()) {
|
||||
it->second->setVisible(visible);
|
||||
}
|
||||
}
|
||||
void setLabel(const std::string& name, const std::string& text) {
|
||||
size_t hash = makeHash(name);
|
||||
auto it = m_labels.find(hash);
|
||||
if (it != m_labels.end()) {
|
||||
it->second->setText(text);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
std::unordered_map<int, std::unique_ptr<Button>> m_buttons;
|
||||
std::unordered_map<int, std::unique_ptr<Label>> m_labels;
|
||||
|
||||
@@ -44,7 +44,10 @@ public:
|
||||
m_rect.x = static_cast<float>(x);
|
||||
m_rect.y = static_cast<float>(y);
|
||||
}
|
||||
|
||||
void setPosition(int x, int y) {
|
||||
m_rect.x = static_cast<float>(x);
|
||||
m_rect.y = static_cast<float>(y);
|
||||
}
|
||||
/**
|
||||
* @brief 获取组件边界矩形
|
||||
* @return SDL_FRect 浮点矩形
|
||||
|
||||
Reference in New Issue
Block a user