86 lines
1.5 KiB
C++
86 lines
1.5 KiB
C++
#include "dl_ui_msg_box.h"
|
|
|
|
#include "ui/dl_ui_manager.h"
|
|
|
|
namespace dl::UI
|
|
{
|
|
|
|
dl::UI::MsgBox* MsgBox::Create(UI::Text* title, UI::Text* content, UI::Button* btn)
|
|
{
|
|
MsgBox* ret = new MsgBox;
|
|
ret->_txtTitle = title;
|
|
ret->_txtContent = content;
|
|
ret->_btn = btn;
|
|
ret->_init();
|
|
return ret;
|
|
}
|
|
|
|
void MsgBox::Set(std::string_view title, std::string_view info, std::vector<std::string_view> all_btn)
|
|
{
|
|
_txtTitle->SetString(title);
|
|
if (_bAddTab)
|
|
_txtContent->SetString(std::string{ "\t" } + std::string{ info });
|
|
else
|
|
_txtContent->SetString(info);
|
|
|
|
// 不够按钮就增加
|
|
while (all_btn.size() > _allBtn.size())
|
|
{
|
|
UI::Button* btn = _btn->Clone();
|
|
_panelBtn->Add(btn);
|
|
_allBtn.push_back(btn);
|
|
}
|
|
|
|
for (std::size_t i = 0; i < _allBtn.size(); ++i)
|
|
{
|
|
_allBtn[i]->SetString(all_btn[i]);
|
|
}
|
|
}
|
|
|
|
void MsgBox::_init()
|
|
{
|
|
_txtTitle->GetText()->SetUI(false);
|
|
_txtContent->GetText()->SetUI(false);
|
|
|
|
_panelBtn = g_ui->CreatePanel(_panel);
|
|
_panel->Add(_txtTitle);
|
|
_panel->Add(_txtContent);
|
|
}
|
|
|
|
MsgBox::~MsgBox()
|
|
{
|
|
delete _btn;
|
|
}
|
|
|
|
void MsgBox::Update()
|
|
{
|
|
Window::Update();
|
|
if (IsClickClose())
|
|
SetVisible(false);
|
|
if (_bClickClose && _panelBtn->GetClickIndex() != -1)
|
|
SetVisible(false);
|
|
}
|
|
|
|
size_t MsgBox::GetClickIndex()
|
|
{
|
|
for (size_t i = 0; i < _allBtn.size(); ++i)
|
|
{
|
|
if (_allBtn[i]->IsClick())
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
size_t MsgBox::GetOverOnceIndex()
|
|
{
|
|
for (size_t i = 0; i < _allBtn.size(); ++i)
|
|
{
|
|
if (_allBtn[i]->IsOverOnce())
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
|