2020-12-12 15:41:56 +00:00
|
|
|
#include "dialogue_page.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-06-01 14:28:03 +01:00
|
|
|
#include <algorithm>
|
2021-09-11 14:48:13 +01:00
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
#include "fs.hpp"
|
|
|
|
#include "main_frame.hpp"
|
|
|
|
#include "utils.hpp"
|
2021-05-21 17:12:58 +01:00
|
|
|
|
2020-12-12 15:41:56 +00:00
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
|
|
|
|
2021-09-12 14:01:40 +01:00
|
|
|
void DialoguePage::CreateView()
|
2020-12-12 15:41:56 +00:00
|
|
|
{
|
2021-03-01 18:19:17 +00:00
|
|
|
this->button1 = (new brls::Button(brls::ButtonStyle::REGULAR))->setLabel("menus/common/yes"_i18n);
|
2020-12-12 15:41:56 +00:00
|
|
|
this->button1->setParent(this);
|
2021-03-01 18:19:17 +00:00
|
|
|
this->button2 = (new brls::Button(brls::ButtonStyle::REGULAR))->setLabel("menus/common/no"_i18n);
|
2020-12-12 15:41:56 +00:00
|
|
|
this->button2->setParent(this);
|
|
|
|
|
2021-09-12 14:01:40 +01:00
|
|
|
this->instantiateButtons();
|
2020-12-12 15:41:56 +00:00
|
|
|
|
|
|
|
this->label->setHorizontalAlign(NVG_ALIGN_CENTER);
|
|
|
|
this->label->setParent(this);
|
2021-02-06 21:38:16 +00:00
|
|
|
|
|
|
|
this->navigationMap.add(
|
|
|
|
this->button1,
|
|
|
|
brls::FocusDirection::RIGHT,
|
|
|
|
this->button2);
|
|
|
|
|
|
|
|
this->navigationMap.add(
|
|
|
|
this->button2,
|
|
|
|
brls::FocusDirection::LEFT,
|
|
|
|
this->button1);
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-02-15 18:31:06 +00:00
|
|
|
this->registerAction("", brls::Key::B, [this] { return true; });
|
2020-12-12 15:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialoguePage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
|
|
|
|
{
|
|
|
|
this->label->frame(ctx);
|
|
|
|
this->button1->frame(ctx);
|
2021-06-01 14:28:03 +01:00
|
|
|
|
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
|
|
auto missing = std::max(1l - std::chrono::duration_cast<std::chrono::seconds>(end - start).count(), 0l);
|
2021-09-11 14:48:13 +01:00
|
|
|
auto text = std::string("menus/common/no"_i18n);
|
2021-06-01 14:28:03 +01:00
|
|
|
if (missing > 0) {
|
|
|
|
this->button2->setLabel(text + " (" + std::to_string(missing) + ")");
|
|
|
|
this->button2->setState(brls::ButtonState::DISABLED);
|
2021-09-11 14:48:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-06-01 14:28:03 +01:00
|
|
|
this->button2->setLabel(text);
|
|
|
|
this->button2->setState(brls::ButtonState::ENABLED);
|
|
|
|
}
|
|
|
|
this->button2->invalidate();
|
2020-12-12 15:41:56 +00:00
|
|
|
this->button2->frame(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialoguePage::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash)
|
|
|
|
{
|
|
|
|
this->label->setWidth(this->width);
|
|
|
|
this->label->invalidate(true);
|
|
|
|
this->label->setBoundaries(
|
|
|
|
this->x + this->width / 2 - this->label->getWidth() / 2,
|
2021-09-11 14:48:13 +01:00
|
|
|
this->y + (this->height - this->label->getHeight() - this->y - style->CrashFrame.buttonHeight) / 2,
|
2020-12-12 15:41:56 +00:00
|
|
|
this->label->getWidth(),
|
|
|
|
this->label->getHeight());
|
|
|
|
this->button1->setBoundaries(
|
|
|
|
this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2 - 200,
|
2021-09-11 14:48:13 +01:00
|
|
|
this->y + (this->height - style->CrashFrame.buttonHeight * 3),
|
2020-12-12 15:41:56 +00:00
|
|
|
style->CrashFrame.buttonWidth,
|
|
|
|
style->CrashFrame.buttonHeight);
|
|
|
|
this->button1->invalidate();
|
|
|
|
|
|
|
|
this->button2->setBoundaries(
|
|
|
|
this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2 + 200,
|
2021-09-11 14:48:13 +01:00
|
|
|
this->y + (this->height - style->CrashFrame.buttonHeight * 3),
|
2020-12-12 15:41:56 +00:00
|
|
|
style->CrashFrame.buttonWidth,
|
|
|
|
style->CrashFrame.buttonHeight);
|
|
|
|
this->button2->invalidate();
|
2021-06-01 14:28:03 +01:00
|
|
|
|
|
|
|
start = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(150);
|
2020-12-12 15:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
brls::View* DialoguePage::getDefaultFocus()
|
|
|
|
{
|
|
|
|
return this->button1;
|
|
|
|
}
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
brls::View* DialoguePage::getNextFocus(brls::FocusDirection direction, brls::View* currentView)
|
|
|
|
{
|
2021-02-06 21:38:16 +00:00
|
|
|
return this->navigationMap.getNextFocus(direction, currentView);
|
2020-12-12 15:41:56 +00:00
|
|
|
}
|
2021-09-12 14:01:40 +01:00
|
|
|
|
|
|
|
void DialoguePage_ams::instantiateButtons()
|
|
|
|
{
|
|
|
|
this->button1->getClickEvent()->subscribe([this](View* view) {
|
|
|
|
if (!frame->isLastStage())
|
|
|
|
frame->nextStage();
|
|
|
|
else {
|
|
|
|
brls::Application::pushView(new MainFrame());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this->button2->getClickEvent()->subscribe([this](View* view) {
|
|
|
|
if (this->erista) {
|
|
|
|
util::rebootToPayload(RCM_PAYLOAD_PATH);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (std::filesystem::exists(UPDATE_BIN_PATH)) {
|
|
|
|
fs::copyFile(UPDATE_BIN_PATH, MARIKO_PAYLOAD_PATH_TEMP);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fs::copyFile(REBOOT_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH_TEMP);
|
|
|
|
}
|
|
|
|
fs::copyFile(RCM_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH);
|
|
|
|
util::shutDown(true);
|
|
|
|
}
|
|
|
|
brls::Application::popView();
|
|
|
|
});
|
|
|
|
|
|
|
|
this->label = new brls::Label(brls::LabelStyle::DIALOG, "menus/ams_update/install_hekate"_i18n + "\n\n" + this->text, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialoguePage_fw::instantiateButtons()
|
|
|
|
{
|
|
|
|
this->button2->getClickEvent()->subscribe([this](View* view) {
|
|
|
|
if (!frame->isLastStage())
|
|
|
|
frame->nextStage();
|
|
|
|
else {
|
|
|
|
brls::Application::pushView(new MainFrame());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this->button1->getClickEvent()->subscribe([this](View* view) {
|
|
|
|
envSetNextLoad(DAYBREAK_PATH, fmt::format("\"{}\" \"/firmware\"", DAYBREAK_PATH).c_str());
|
|
|
|
romfsExit();
|
|
|
|
brls::Application::quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
this->label = new brls::Label(brls::LabelStyle::DIALOG, fmt::format("{}\n\n{}", this->text, "menus/firmware/launch_daybreak"_i18n), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialoguePage_fw::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
|
|
|
|
{
|
|
|
|
this->label->frame(ctx);
|
|
|
|
this->button1->frame(ctx);
|
|
|
|
this->button2->frame(ctx);
|
|
|
|
}
|