mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-09-12 12:35:26 -05:00
More refactoring. Add error::
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "appstates/SaveCreateState.hpp"
|
||||
|
||||
#include "StateManager.hpp"
|
||||
#include "appstates/TaskState.hpp"
|
||||
#include "data/data.hpp"
|
||||
@@ -8,6 +9,7 @@
|
||||
#include "strings.hpp"
|
||||
#include "system/Task.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <switch.h>
|
||||
@@ -23,7 +25,9 @@ static void create_save_data(sys::Task *task,
|
||||
static bool compare_info(data::TitleInfo *infoA, data::TitleInfo *infoB);
|
||||
|
||||
SaveCreateState::SaveCreateState(data::User *user, TitleSelectCommon *titleSelect)
|
||||
: m_user(user), m_titleSelect(titleSelect), m_saveMenu(8, 8, 624, 22, 720)
|
||||
: m_user(user)
|
||||
, m_titleSelect(titleSelect)
|
||||
, m_saveMenu(8, 8, 624, 22, 720)
|
||||
{
|
||||
// If the panel is null, create it.
|
||||
if (!sm_slidePanel)
|
||||
@@ -38,10 +42,7 @@ SaveCreateState::SaveCreateState(data::User *user, TitleSelectCommon *titleSelec
|
||||
// Sort it by alpha
|
||||
std::sort(m_titleInfoVector.begin(), m_titleInfoVector.end(), compare_info);
|
||||
|
||||
for (size_t i = 0; i < m_titleInfoVector.size(); i++)
|
||||
{
|
||||
m_saveMenu.add_option(m_titleInfoVector.at(i)->get_title());
|
||||
}
|
||||
for (size_t i = 0; i < m_titleInfoVector.size(); i++) { m_saveMenu.add_option(m_titleInfoVector.at(i)->get_title()); }
|
||||
}
|
||||
|
||||
void SaveCreateState::update()
|
||||
@@ -66,10 +67,7 @@ void SaveCreateState::update()
|
||||
data::TitleInfo *targetTitle = m_titleInfoVector.at(m_saveMenu.get_selected());
|
||||
StateManager::push_state(std::make_shared<TaskState>(create_save_data, m_user, targetTitle, this));
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_B))
|
||||
{
|
||||
sm_slidePanel->close();
|
||||
}
|
||||
else if (input::button_pressed(HidNpadButton_B)) { sm_slidePanel->close(); }
|
||||
else if (sm_slidePanel->is_closed())
|
||||
{
|
||||
sm_slidePanel->reset();
|
||||
@@ -87,10 +85,7 @@ void SaveCreateState::render()
|
||||
sm_slidePanel->render(NULL, hasFocus);
|
||||
}
|
||||
|
||||
void SaveCreateState::data_and_view_refresh_required()
|
||||
{
|
||||
m_refreshRequired = true;
|
||||
}
|
||||
void SaveCreateState::data_and_view_refresh_required() { m_refreshRequired = true; }
|
||||
|
||||
static void create_save_data(sys::Task *task,
|
||||
data::User *targetUser,
|
||||
@@ -98,18 +93,18 @@ static void create_save_data(sys::Task *task,
|
||||
SaveCreateState *spawningState)
|
||||
{
|
||||
// Set status. We'll just borrow the string from the other group.
|
||||
task->set_status(strings::get_by_name(strings::names::USER_OPTION_STATUS, 0), titleInfo->get_title());
|
||||
task->set_status(strings::get_by_name(strings::names::USEROPTION_STATUS, 0), titleInfo->get_title());
|
||||
|
||||
if (fs::create_save_data_for(targetUser, titleInfo))
|
||||
{
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::POP_MESSAGES_SAVE_CREATE, 0),
|
||||
strings::get_by_name(strings::names::SAVECREATE_POPS, 0),
|
||||
titleInfo->get_title());
|
||||
}
|
||||
else
|
||||
{
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_MESSAGE_TICKS,
|
||||
strings::get_by_name(strings::names::POP_MESSAGES_SAVE_CREATE, 1));
|
||||
strings::get_by_name(strings::names::SAVECREATE_POPS, 1));
|
||||
}
|
||||
|
||||
spawningState->data_and_view_refresh_required();
|
||||
@@ -123,8 +118,8 @@ static bool compare_info(data::TitleInfo *infoA, data::TitleInfo *infoB)
|
||||
const char *titleA = infoA->get_title();
|
||||
const char *titleB = infoB->get_title();
|
||||
|
||||
size_t titleALength = std::char_traits<char>::length(titleA);
|
||||
size_t titleBLength = std::char_traits<char>::length(titleB);
|
||||
size_t titleALength = std::char_traits<char>::length(titleA);
|
||||
size_t titleBLength = std::char_traits<char>::length(titleB);
|
||||
size_t shortestTitle = titleALength < titleBLength ? titleALength : titleBLength;
|
||||
// To do: This doesn't take into account which is the shortest title. This can still go out-of-bounds.
|
||||
for (size_t i = 0, j = 0; i < shortestTitle;)
|
||||
@@ -135,15 +130,9 @@ static bool compare_info(data::TitleInfo *infoA, data::TitleInfo *infoB)
|
||||
ssize_t unitCountA = decode_utf8(&codepointA, reinterpret_cast<const uint8_t *>(&titleA[i]));
|
||||
ssize_t unitCountB = decode_utf8(&codepointB, reinterpret_cast<const uint8_t *>(&titleB[j]));
|
||||
|
||||
if (unitCountA <= 0 || unitCountB <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (unitCountA <= 0 || unitCountB <= 0) { return false; }
|
||||
|
||||
if (codepointA != codepointB)
|
||||
{
|
||||
return codepointA < codepointB;
|
||||
}
|
||||
if (codepointA != codepointB) { return codepointA < codepointB; }
|
||||
|
||||
i += unitCountA;
|
||||
j += unitCountB;
|
||||
|
||||
Reference in New Issue
Block a user