2020-09-20 01:21:28 +01:00
|
|
|
#include "confirm_page.hpp"
|
2020-10-05 23:53:12 +01:00
|
|
|
|
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2020-12-12 15:41:56 +00:00
|
|
|
ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, std::string text, bool done, bool reboot): done(done), reboot(reboot)
|
2020-09-20 01:21:28 +01:00
|
|
|
{
|
2020-10-05 23:53:12 +01:00
|
|
|
this->button = (new brls::Button(brls::ButtonStyle::BORDERLESS))->setLabel(done ? "menus/Back"_i18n : "menus/Continue"_i18n );
|
2020-09-20 01:21:28 +01:00
|
|
|
this->button->setParent(this);
|
|
|
|
this->button->getClickEvent()->subscribe([frame, this](View* view) {
|
2020-12-12 15:41:56 +00:00
|
|
|
if (!frame->isLastStage()) {
|
|
|
|
frame->nextStage();
|
|
|
|
}
|
2020-09-20 01:21:28 +01:00
|
|
|
else if (this->done) {
|
|
|
|
brls::Application::pushView(new MainFrame());
|
|
|
|
}
|
2020-12-12 15:41:56 +00:00
|
|
|
else if (this->reboot){
|
|
|
|
reboot_to_payload(RCM_PAYLOAD_PATH);
|
|
|
|
}
|
2020-09-20 01:21:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this->label = new brls::Label(brls::LabelStyle::DIALOG, text, true);
|
|
|
|
this->label->setHorizontalAlign(NVG_ALIGN_CENTER);
|
|
|
|
this->label->setParent(this);
|
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
this->registerAction("menus/Back"_i18n , brls::Key::B, [this] {
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
|
|
|
|
{
|
|
|
|
if(!this->done){
|
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
2020-09-20 21:58:40 +01:00
|
|
|
auto missing = std::max(1l - std::chrono::duration_cast<std::chrono::seconds>(end - start).count(), 0l);
|
2020-10-05 23:53:12 +01:00
|
|
|
auto text = std::string("menus/Continue"_i18n );
|
2020-09-20 01:21:28 +01:00
|
|
|
if (missing > 0) {
|
|
|
|
this->button->setLabel(text + " (" + std::to_string(missing) + ")");
|
|
|
|
this->button->setState(brls::ButtonState::DISABLED);
|
|
|
|
} else {
|
|
|
|
this->button->setLabel(text);
|
|
|
|
this->button->setState(brls::ButtonState::ENABLED);
|
|
|
|
}
|
|
|
|
this->button->invalidate();
|
|
|
|
}
|
2020-09-20 21:58:40 +01:00
|
|
|
else{
|
|
|
|
this->button->setState(brls::ButtonState::ENABLED);
|
|
|
|
}
|
2020-09-20 01:21:28 +01:00
|
|
|
this->label->frame(ctx);
|
|
|
|
this->button->frame(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
brls::View* ConfirmPage::getDefaultFocus()
|
|
|
|
{
|
|
|
|
return this->button;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPage::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash)
|
|
|
|
{
|
|
|
|
this->label->setWidth(this->width);
|
|
|
|
this->label->invalidate(true);
|
|
|
|
// this->label->setBackground(brls::ViewBackground::DEBUG);
|
|
|
|
this->label->setBoundaries(
|
|
|
|
this->x + this->width / 2 - this->label->getWidth() / 2,
|
|
|
|
this->y + (this->height - this->label->getHeight() - this->y - style->CrashFrame.buttonHeight)/2,
|
|
|
|
this->label->getWidth(),
|
|
|
|
this->label->getHeight());
|
|
|
|
|
|
|
|
this->button->setBoundaries(
|
|
|
|
this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2,
|
|
|
|
this->y + (this->height-style->CrashFrame.buttonHeight*3),
|
|
|
|
style->CrashFrame.buttonWidth,
|
|
|
|
style->CrashFrame.buttonHeight);
|
|
|
|
this->button->invalidate();
|
|
|
|
|
|
|
|
start = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(150);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmPage::~ConfirmPage()
|
|
|
|
{
|
|
|
|
delete this->label;
|
|
|
|
delete this->button;
|
|
|
|
}
|