mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-24 23:37:24 -05:00
Refactor TextTitleSelect
This commit is contained in:
parent
58e6217e73
commit
040329b256
|
|
@ -33,4 +33,13 @@ class TextTitleSelectState final : public TitleSelectCommon
|
|||
|
||||
/// @brief Target to render to.
|
||||
sdl::SharedTexture m_renderTarget{};
|
||||
|
||||
/// @brief Creates a new backup menu instance.
|
||||
void create_backup_menu();
|
||||
|
||||
/// @brief Creates a new instance of the title options menu.
|
||||
void create_title_option_menu();
|
||||
|
||||
/// @brief Adds or removes the current highlighted title to favorites.
|
||||
void add_remove_favorite();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,6 +51,14 @@ void SaveCreateState::update()
|
|||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
m_saveMenu.update(hasFocus);
|
||||
sm_slidePanel->update(hasFocus);
|
||||
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool panelClosed = sm_slidePanel->is_closed();
|
||||
const int selected = m_saveMenu.get_selected();
|
||||
|
||||
if (m_refreshRequired.load())
|
||||
{
|
||||
m_user->load_user_data();
|
||||
|
|
@ -58,16 +66,15 @@ void SaveCreateState::update()
|
|||
m_refreshRequired.store(false);
|
||||
}
|
||||
|
||||
m_saveMenu.update(hasFocus);
|
||||
sm_slidePanel->update(hasFocus);
|
||||
|
||||
if (input::button_pressed(HidNpadButton_A))
|
||||
if (aPressed)
|
||||
{
|
||||
data::TitleInfo *targetTitle = m_titleInfoVector.at(m_saveMenu.get_selected());
|
||||
StateManager::push_state(std::make_shared<TaskState>(create_save_data, m_user, targetTitle, this));
|
||||
data::TitleInfo *titleInfo = m_titleInfoVector[selected];
|
||||
auto createTask = std::make_shared<TaskState>(create_save_data, m_user, titleInfo, this);
|
||||
|
||||
StateManager::push_state(createTask);
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_B)) { sm_slidePanel->close(); }
|
||||
else if (sm_slidePanel->is_closed())
|
||||
else if (bPressed) { sm_slidePanel->close(); }
|
||||
else if (panelClosed)
|
||||
{
|
||||
sm_slidePanel->reset();
|
||||
BaseState::deactivate();
|
||||
|
|
@ -135,7 +142,6 @@ static bool compare_info(data::TitleInfo *infoA, data::TitleInfo *infoB)
|
|||
const uint8_t *pointB = reinterpret_cast<const uint8_t *>(&titleB[j]);
|
||||
const ssize_t unitCountA = decode_utf8(&codepointA, pointA);
|
||||
const ssize_t unitCountB = decode_utf8(&codepointB, pointB);
|
||||
|
||||
if (unitCountA <= 0 || unitCountB <= 0) { return false; }
|
||||
|
||||
if (codepointA != codepointB) { return codepointA < codepointB; }
|
||||
|
|
|
|||
|
|
@ -34,58 +34,18 @@ TextTitleSelectState::TextTitleSelectState(data::User *user)
|
|||
|
||||
void TextTitleSelectState::update()
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input::button_pressed(HidNpadButton_Y);
|
||||
|
||||
m_titleSelectMenu.update(BaseState::has_focus());
|
||||
|
||||
// Both title selection states work too differently for this stuff to be shared IMO.
|
||||
if (input::button_pressed(HidNpadButton_A))
|
||||
{
|
||||
// Grab selected.
|
||||
int selected = m_titleSelectMenu.get_selected();
|
||||
|
||||
// Grab what we need to continue.
|
||||
uint64_t applicationID = m_user->get_application_id_at(selected);
|
||||
FsSaveDataInfo *saveInfo = m_user->get_save_info_by_id(applicationID);
|
||||
data::TitleInfo *titleInfo = data::get_title_info_by_id(m_user->get_application_id_at(selected));
|
||||
|
||||
// Output path.
|
||||
fslib::Path targetPath = config::get_working_directory() / titleInfo->get_path_safe_title();
|
||||
|
||||
if ((fslib::directory_exists(targetPath) || fslib::create_directory(targetPath)) &&
|
||||
fslib::open_save_data_with_save_info(fs::DEFAULT_SAVE_MOUNT, *saveInfo))
|
||||
{
|
||||
// State
|
||||
auto backupMenuState = std::make_shared<BackupMenuState>(m_user, titleInfo);
|
||||
|
||||
StateManager::push_state(backupMenuState);
|
||||
}
|
||||
else { logger::log(fslib::error::get_string()); }
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_X))
|
||||
{
|
||||
int selected = m_titleSelectMenu.get_selected();
|
||||
|
||||
uint64_t applicationID = m_user->get_application_id_at(selected);
|
||||
data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID);
|
||||
|
||||
auto titleOptionState = std::make_shared<TitleOptionState>(m_user, titleInfo, this);
|
||||
|
||||
StateManager::push_state(titleOptionState);
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_Y))
|
||||
{
|
||||
uint64_t applicationID = m_user->get_application_id_at(m_titleSelectMenu.get_selected());
|
||||
|
||||
config::add_remove_favorite(applicationID);
|
||||
|
||||
// We need to resort all users, not just this one.
|
||||
data::UserList list;
|
||||
data::get_users(list);
|
||||
for (data::User *user : list) { user->sort_data(); }
|
||||
|
||||
// Let the main menu state take care of this.
|
||||
MainMenuState::refresh_view_states();
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_B)) { BaseState::deactivate(); }
|
||||
if (aPressed) { TextTitleSelectState::create_backup_menu(); }
|
||||
else if (xPressed) { TextTitleSelectState::create_title_option_menu(); }
|
||||
else if (yPressed) { TextTitleSelectState::add_remove_favorite(); }
|
||||
else if (bPressed) { BaseState::deactivate(); }
|
||||
}
|
||||
|
||||
void TextTitleSelectState::render()
|
||||
|
|
@ -109,3 +69,39 @@ void TextTitleSelectState::refresh()
|
|||
m_titleSelectMenu.add_option(option.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void TextTitleSelectState::create_backup_menu()
|
||||
{
|
||||
const int selected = m_titleSelectMenu.get_selected();
|
||||
const uint64_t applicationID = m_user->get_application_id_at(selected);
|
||||
const FsSaveDataInfo *saveInfo = m_user->get_save_info_by_id(applicationID);
|
||||
data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID);
|
||||
|
||||
auto backupMenuState = std::make_shared<BackupMenuState>(m_user, titleInfo);
|
||||
StateManager::push_state(backupMenuState);
|
||||
}
|
||||
|
||||
void TextTitleSelectState::create_title_option_menu()
|
||||
{
|
||||
const int selected = m_titleSelectMenu.get_selected();
|
||||
const uint64_t applicationID = m_user->get_application_id_at(selected);
|
||||
data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID);
|
||||
|
||||
auto titleOptionState = std::make_shared<TitleOptionState>(m_user, titleInfo, this);
|
||||
StateManager::push_state(titleOptionState);
|
||||
}
|
||||
|
||||
void TextTitleSelectState::add_remove_favorite()
|
||||
{
|
||||
const int selected = m_titleSelectMenu.get_selected();
|
||||
const uint64_t applicationID = m_user->get_application_id_at(selected);
|
||||
|
||||
config::add_remove_favorite(applicationID);
|
||||
|
||||
// This applies to all users.
|
||||
data::UserList list{};
|
||||
data::get_users(list);
|
||||
for (data::User *user : list) { user->sort_data(); }
|
||||
|
||||
MainMenuState::refresh_view_states();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ void TitleInfoState::initialize_static_members()
|
|||
{
|
||||
if (!sm_slidePanel)
|
||||
{
|
||||
sm_slidePanel = std::make_unique<ui::SlideOutPanel>(SIZE_PANEL_WIDTH, ui::SlideOutPanel::Side::Left);
|
||||
sm_slidePanel = std::make_unique<ui::SlideOutPanel>(SIZE_PANEL_WIDTH, ui::SlideOutPanel::Side::Right);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user