mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-25 07:57:04 -05:00
Use ui::Transition for FileOptionState.
This commit is contained in:
parent
16e9c88227
commit
046d5581ee
|
|
@ -57,14 +57,11 @@ class FileOptionState final : public BaseState
|
|||
/// @brief Pointer to spawning FileMode state.
|
||||
FileModeState *m_spawningState{};
|
||||
|
||||
/// @brief X coordinate. This is set at construction according to the target from the spawning state.
|
||||
int m_x{};
|
||||
/// @brief Stores the target for easier access.
|
||||
bool m_target{};
|
||||
|
||||
/// @brief X coordinate for the target to reach.
|
||||
int m_targetX{};
|
||||
|
||||
/// @brief Whether or not the dialog/menu is in place.
|
||||
bool m_inPlace{};
|
||||
/// @brief Transition.
|
||||
ui::Transition m_transition{};
|
||||
|
||||
/// @brief Whether or not the state should be closed.
|
||||
bool m_close{};
|
||||
|
|
@ -85,9 +82,6 @@ class FileOptionState final : public BaseState
|
|||
/// @brief Ensures static members of all instances are allocated.
|
||||
void initialize_static_members();
|
||||
|
||||
/// @brief Sets whether the dialog/menu are positioned left or right depending on the menu active in the spawning state.
|
||||
void set_menu_side();
|
||||
|
||||
/// @brief Assigns the pointer to this.
|
||||
void initialize_data_struct();
|
||||
|
||||
|
|
@ -97,9 +91,6 @@ class FileOptionState final : public BaseState
|
|||
/// @brief Updates the FileModeState's destination data.
|
||||
void update_filemode_dest();
|
||||
|
||||
/// @brief Updates the Y coordinate
|
||||
void update_x_coord();
|
||||
|
||||
/// @brief Sets up and begins the copy task.
|
||||
void copy_target();
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ FileModeState::FileModeState(std::string_view mountA, std::string_view mountB, i
|
|||
: m_mountA(mountA)
|
||||
, m_mountB(mountB)
|
||||
, m_journalSize(journalSize)
|
||||
, m_transition(23, 720, 23, 91, 4)
|
||||
, m_transition(15, 720, 15, 87, 4)
|
||||
, m_isSystem(isSystem)
|
||||
, m_allowSystem(config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM))
|
||||
{
|
||||
|
|
@ -76,10 +76,8 @@ void FileModeState::render()
|
|||
|
||||
sm_frame->render(sdl::Texture::Null, true);
|
||||
|
||||
const int x = m_transition.get_x();
|
||||
const int y = m_transition.get_y();
|
||||
|
||||
sm_renderTarget->render(sdl::Texture::Null, x, y + 12);
|
||||
sm_renderTarget->render(sdl::Texture::Null, 23, y + 12);
|
||||
}
|
||||
|
||||
void FileModeState::initialize_static_members()
|
||||
|
|
|
|||
|
|
@ -41,20 +41,26 @@ static std::string get_size_string(int64_t totalSize);
|
|||
|
||||
FileOptionState::FileOptionState(FileModeState *spawningState)
|
||||
: m_spawningState(spawningState)
|
||||
, m_target(spawningState->m_target)
|
||||
, m_transition(m_target ? 1280 : -240, 218, m_target ? 840 : 200, 218, 4)
|
||||
, m_dataStruct(std::make_shared<FileOptionState::DataStruct>())
|
||||
{
|
||||
FileOptionState::initialize_static_members();
|
||||
FileOptionState::set_menu_side();
|
||||
FileOptionState::initialize_data_struct();
|
||||
}
|
||||
|
||||
void FileOptionState::update()
|
||||
{
|
||||
m_transition.update();
|
||||
if (!m_transition.in_place())
|
||||
{
|
||||
const int x = m_transition.get_x();
|
||||
sm_dialog->set_x(x);
|
||||
sm_copyMenu->set_x(x + 9);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
FileOptionState::update_x_coord();
|
||||
if (!m_inPlace) { return; }
|
||||
|
||||
if (m_updateSource)
|
||||
{
|
||||
FileOptionState::update_filemode_source();
|
||||
|
|
@ -101,10 +107,17 @@ void FileOptionState::update_destination() { m_updateDest = true; }
|
|||
|
||||
void FileOptionState::initialize_static_members()
|
||||
{
|
||||
if (sm_copyMenu && sm_dialog) { return; }
|
||||
if (sm_copyMenu && sm_dialog)
|
||||
{
|
||||
const int x = m_transition.get_x();
|
||||
|
||||
sm_copyMenu = ui::Menu::create(0, 236, 234, 20, 720); // High target height is a workaround.
|
||||
sm_dialog = ui::DialogBox::create(520, 218, 256, 256);
|
||||
sm_dialog->set_x(x);
|
||||
sm_copyMenu->set_x(x + 9);
|
||||
return;
|
||||
}
|
||||
|
||||
sm_copyMenu = ui::Menu::create(1280, 236, 234, 20, 720); // High target height is a workaround.
|
||||
sm_dialog = ui::DialogBox::create(1280, 218, 256, 256);
|
||||
|
||||
// This never changes, so...
|
||||
for (int i = 0; const char *menuOption = strings::get_by_name(strings::names::FILEOPTION_MENU, i); i++)
|
||||
|
|
@ -113,16 +126,6 @@ void FileOptionState::initialize_static_members()
|
|||
}
|
||||
}
|
||||
|
||||
void FileOptionState::set_menu_side()
|
||||
{
|
||||
const bool target = m_spawningState->m_target;
|
||||
m_x = target ? 1280 : -240;
|
||||
|
||||
m_targetX = target ? 840 : 200;
|
||||
sm_dialog->set_x(m_x);
|
||||
sm_copyMenu->set_x(m_x + 9);
|
||||
}
|
||||
|
||||
void FileOptionState::initialize_data_struct() { m_dataStruct->spawningState = this; }
|
||||
|
||||
void FileOptionState::update_filemode_source()
|
||||
|
|
@ -143,24 +146,6 @@ void FileOptionState::update_filemode_dest()
|
|||
m_spawningState->initialize_directory_menu(destPath, destDir, destMenu);
|
||||
}
|
||||
|
||||
void FileOptionState::update_x_coord()
|
||||
{
|
||||
if (m_x == m_targetX) { return; }
|
||||
|
||||
// We're going to borrow the scaling from the FileMode
|
||||
const int add = (m_targetX - m_x) / config::get_animation_scaling();
|
||||
m_x += add;
|
||||
|
||||
const int distance = math::Util<int>::absolute_distance(m_x, m_targetX);
|
||||
if (distance <= 4)
|
||||
{
|
||||
m_x = m_targetX;
|
||||
m_inPlace = true;
|
||||
}
|
||||
sm_dialog->set_x(m_x);
|
||||
sm_copyMenu->set_x(m_x + 9);
|
||||
}
|
||||
|
||||
void FileOptionState::copy_target()
|
||||
{
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
|
|
@ -282,7 +267,7 @@ void FileOptionState::rename_target()
|
|||
const std::string newString = newPath.string();
|
||||
|
||||
// If this is false and there's a journaling size set, we need to commit on renaming for it to stick.
|
||||
const bool isSource = !m_spawningState->m_target;
|
||||
const bool isSource = !m_target;
|
||||
const int64_t journalSize = m_spawningState->m_journalSize;
|
||||
const bool commitNeeded = isSource && journalSize > 0;
|
||||
|
||||
|
|
@ -420,13 +405,12 @@ void FileOptionState::pop_system_error()
|
|||
|
||||
void FileOptionState::close()
|
||||
{
|
||||
const bool target = m_spawningState->m_target;
|
||||
|
||||
m_close = true;
|
||||
m_targetX = target ? 1280 : -240;
|
||||
m_close = true;
|
||||
const int targetX = m_target ? 1280 : -240;
|
||||
m_transition.set_target_x(targetX);
|
||||
}
|
||||
|
||||
bool FileOptionState::is_closed() { return m_close && m_x == m_targetX; }
|
||||
bool FileOptionState::is_closed() { return m_close && m_transition.in_place(); }
|
||||
|
||||
void FileOptionState::deactivate_state()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user