Skip to content

Commit

Permalink
FullscreenUI: More animation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 26, 2024
1 parent 46a6681 commit 940200f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 67 deletions.
3 changes: 3 additions & 0 deletions dep/imgui/src/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12776,13 +12776,16 @@ static void ImGui::NavUpdateCancelRequest()
// Close open popup/menu
ClosePopupToLevel(g.OpenPopupStack.Size - 1, true);
}
#if 0
// DUCKSTATION-CHANGE: We want to keep nav active, since we handle menu exits ourselves.
else
{
// Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were
if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
g.NavWindow->NavLastIds[0] = 0;
g.NavId = 0;
}
#endif
}

// Handle PageUp/PageDown/Home/End keys
Expand Down
16 changes: 9 additions & 7 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2482,8 +2482,8 @@ void Achievements::DrawAchievementsWindow()
TRANSLATE_NOOP("Achievements", "Active Challenges"), TRANSLATE_NOOP("Achievements", "Almost There"),
};

ImGuiFullscreen::BeginMenuButtons();
ImGuiFullscreen::ResetFocusHere();
ImGuiFullscreen::BeginMenuButtons();

for (u32 bucket_type : {RC_CLIENT_ACHIEVEMENT_BUCKET_ACTIVE_CHALLENGE,
RC_CLIENT_ACHIEVEMENT_BUCKET_RECENTLY_UNLOCKED, RC_CLIENT_ACHIEVEMENT_BUCKET_UNLOCKED,
Expand Down Expand Up @@ -2948,8 +2948,8 @@ void Achievements::DrawLeaderboardsWindow()
ImVec2(display_size.x, display_size.y - heading_height - LayoutScale(ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT)),
"leaderboards", background, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f), 0))
{
ImGuiFullscreen::BeginMenuButtons();
ImGuiFullscreen::ResetFocusHere();
ImGuiFullscreen::BeginMenuButtons();

for (u32 bucket_index = 0; bucket_index < s_leaderboard_list->num_buckets; bucket_index++)
{
Expand All @@ -2969,14 +2969,19 @@ void Achievements::DrawLeaderboardsWindow()
ImVec2(display_size.x, display_size.y - heading_height - LayoutScale(ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT)),
"leaderboard", background, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f), 0))
{
// Defer focus reset until loading finishes.
if (!s_is_showing_all_leaderboard_entries ||
(ImGuiFullscreen::IsFocusResetFromWindowChange() && !s_leaderboard_entry_lists.empty()))
{
ImGuiFullscreen::ResetFocusHere();
}

ImGuiFullscreen::BeginMenuButtons();

if (!s_is_showing_all_leaderboard_entries)
{
if (s_leaderboard_nearby_entries)
{
ImGuiFullscreen::ResetFocusHere();

for (u32 i = 0; i < s_leaderboard_nearby_entries->num_entries; i++)
{
DrawLeaderboardEntry(s_leaderboard_nearby_entries->entries[i],
Expand All @@ -2999,9 +3004,6 @@ void Achievements::DrawLeaderboardsWindow()
}
else
{
if (ImGuiFullscreen::IsFocusResetFromWindowChange() && !s_leaderboard_entry_lists.empty())
ImGuiFullscreen::ResetFocusHere();

for (const rc_client_leaderboard_entry_list_t* list : s_leaderboard_entry_lists)
{
for (u32 i = 0; i < list->num_entries; i++)
Expand Down
93 changes: 47 additions & 46 deletions src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5345,10 +5345,10 @@ void FullscreenUI::DrawPauseMenu()
3, // Achievements
};

ResetFocusHere();
BeginMenuButtons(submenu_item_count[static_cast<u32>(s_current_pause_submenu)], 1.0f,
ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING,
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
ResetFocusHere();

switch (s_current_pause_submenu)
{
Expand Down Expand Up @@ -5617,6 +5617,7 @@ bool FullscreenUI::OpenSaveStateSelector(bool is_loading)
if (PopulateSaveStateListEntries(System::GetGameTitle(), System::GetGameSerial()) > 0)
{
s_save_state_selector_open = true;
QueueResetFocus(FocusResetType::PopupOpened);
return true;
}

Expand All @@ -5626,6 +5627,9 @@ bool FullscreenUI::OpenSaveStateSelector(bool is_loading)

void FullscreenUI::CloseSaveStateSelector()
{
if (s_save_state_selector_open)
QueueResetFocus(FocusResetType::PopupClosed);

ClearSaveStateEntryList();
s_save_state_selector_open = false;
s_save_state_selector_loading = false;
Expand Down Expand Up @@ -5674,14 +5678,13 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)

ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIPrimaryColor, 0.9f));

bool closed = false;
bool was_close_not_back = false;
if (ImGui::BeginChild("state_titlebar", heading_size, false, ImGuiWindowFlags_NavFlattened))
{
BeginNavBar();
if (NavButton(ICON_FA_BACKWARD, true, true))
{
CloseSaveStateSelector();
ReturnToPreviousWindow();
}
closed = true;

NavTitle(is_loading ? FSUI_CSTR("Load State") : FSUI_CSTR("Save State"));
EndNavBar();
Expand All @@ -5692,13 +5695,15 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIBackgroundColor, 0.9f));
ImGui::SetCursorPos(ImVec2(0.0f, heading_size.y));

bool closed = false;
bool close_handled = false;
if (s_save_state_selector_open &&
ImGui::BeginChild("state_list",
if (IsFocusResetFromWindowChange())
ImGui::SetNextWindowScroll(ImVec2(0.0f, 0.0f));


if (ImGui::BeginChild("state_list",
ImVec2(io.DisplaySize.x, io.DisplaySize.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - heading_size.y),
false, ImGuiWindowFlags_NavFlattened))
{
ResetFocusHere();
BeginMenuButtons();

const ImGuiStyle& style = ImGui::GetStyle();
Expand All @@ -5723,9 +5728,6 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
ImGui::SetCursorPos(ImVec2(start_x, 0.0f));
for (u32 i = 0; i < s_save_state_selector_slots.size();)
{
if (i == 0)
ResetFocusHere();

SaveStateListEntry& entry = s_save_state_selector_slots[i];
if (static_cast<s32>(i) == s_save_state_selector_submenu_index)
{
Expand Down Expand Up @@ -5768,6 +5770,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
DoSaveState(entry.slot, entry.global);

closed = true;
was_close_not_back = true;
}

if (!entry.path.empty() && ActiveButton(FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Delete Save"), false, true,
Expand All @@ -5785,9 +5788,14 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
removed = true;

if (s_save_state_selector_slots.empty())
{
closed = true;
was_close_not_back = true;
}
else
{
is_open = false;
}
}
else
{
Expand All @@ -5808,19 +5816,8 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
ImGui::EndPopup();
}

// don't let the back button flow through to the main window
if (WantsToCloseMenu())
{
close_handled = true;
is_open = false;
}

if (!is_open || closed)
{
if (!is_open)
s_save_state_selector_submenu_index = -1;
if (!closed)
QueueResetFocus(FocusResetType::ViewChanged);
}

ImGui::PopStyleColor(3);
ImGui::PopStyleVar(3);
Expand Down Expand Up @@ -5896,6 +5893,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
DoSaveState(entry.slot, entry.global);

closed = true;
was_close_not_back = true;
}
else if (hovered &&
(ImGui::IsItemClicked(ImGuiMouseButton_Right) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false) ||
Expand Down Expand Up @@ -5929,33 +5927,29 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
ImGui::EndPopup();
ImGui::PopStyleVar(5);

if (closed)
if (IsGamepadInputSource())
{
CloseSaveStateSelector();
ReturnToMainWindow();
SetFullscreenFooterText(std::array{std::make_pair(ICON_PF_XBOX_DPAD, FSUI_VSTR("Select State")),
std::make_pair(ICON_PF_BUTTON_Y, FSUI_VSTR("Delete State")),
std::make_pair(ICON_PF_BUTTON_A, FSUI_VSTR("Load State")),
std::make_pair(ICON_PF_BUTTON_B, FSUI_VSTR("Cancel"))});
}
else if (!close_handled && WantsToCloseMenu())
else
{
CloseSaveStateSelector();
ReturnToPreviousWindow();
SetFullscreenFooterText(std::array{
std::make_pair(ICON_PF_ARROW_UP ICON_PF_ARROW_DOWN ICON_PF_ARROW_LEFT ICON_PF_ARROW_RIGHT,
FSUI_VSTR("Select State")),
std::make_pair(ICON_PF_F1, FSUI_VSTR("Delete State")), std::make_pair(ICON_PF_ENTER, FSUI_VSTR("Load State")),
std::make_pair(ICON_PF_ESC, FSUI_VSTR("Cancel"))});
}
else

if (WantsToCloseMenu() || closed)
{
if (IsGamepadInputSource())
{
SetFullscreenFooterText(std::array{std::make_pair(ICON_PF_XBOX_DPAD, FSUI_VSTR("Select State")),
std::make_pair(ICON_PF_BUTTON_Y, FSUI_VSTR("Delete State")),
std::make_pair(ICON_PF_BUTTON_A, FSUI_VSTR("Load State")),
std::make_pair(ICON_PF_BUTTON_B, FSUI_VSTR("Cancel"))});
}
else
{
SetFullscreenFooterText(std::array{
std::make_pair(ICON_PF_ARROW_UP ICON_PF_ARROW_DOWN ICON_PF_ARROW_LEFT ICON_PF_ARROW_RIGHT,
FSUI_VSTR("Select State")),
std::make_pair(ICON_PF_F1, FSUI_VSTR("Delete State")), std::make_pair(ICON_PF_ENTER, FSUI_VSTR("Load State")),
std::make_pair(ICON_PF_ESC, FSUI_VSTR("Cancel"))});
}
CloseSaveStateSelector();
if (was_close_not_back)
ReturnToMainWindow();
else if (s_current_main_window != MainWindowType::GameList)
ReturnToPreviousWindow();
}
}

Expand All @@ -5971,6 +5965,7 @@ bool FullscreenUI::OpenLoadStateSelectorForGameResume(const GameList::Entry* ent
s_save_state_selector_loading = true;
s_save_state_selector_open = true;
s_save_state_selector_resuming = true;
QueueResetFocus(FocusResetType::PopupOpened);
return true;
}

Expand Down Expand Up @@ -6313,6 +6308,9 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
const GameList::Entry* selected_entry = nullptr;
PopulateGameListEntryList();

if (IsFocusResetFromWindowChange())
ImGui::SetNextWindowScroll(ImVec2(0.0f, 0.0f));

if (BeginFullscreenColumnWindow(0.0f, -530.0f, "game_list_entries"))
{
const ImVec2 image_size(LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT, LAYOUT_MENU_BUTTON_HEIGHT));
Expand Down Expand Up @@ -6509,6 +6507,9 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)

void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
{
if (IsFocusResetFromWindowChange())
ImGui::SetNextWindowScroll(ImVec2(0.0f, 0.0f));

ImGuiIO& io = ImGui::GetIO();
if (!BeginFullscreenWindow(
ImVec2(0.0f, heading_size.y),
Expand Down
Loading

0 comments on commit 940200f

Please sign in to comment.