Skip to content

Commit

Permalink
Better menu handling. Not much better
Browse files Browse the repository at this point in the history
  • Loading branch information
aerisarn committed Mar 29, 2024
1 parent 9f2af9f commit 109e8e1
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions source/common/platform/uwp/system_uwp.cpp
Expand Up @@ -66,6 +66,10 @@ FString uwp_GetAppDataPath()
std::ofstream redirect_file_stream(app_data_redirect_file.string(), std::ios::trunc);
redirect_file_stream << new_path.string() << std::endl;
}
else {
std::ofstream redirect_file_stream(app_data_redirect_file.string(), std::ios::trunc);
redirect_file_stream << local_state << std::endl;
}
}
std::ifstream redirect_file_stream(app_data_redirect_file.string());
std::string appdata;
Expand Down Expand Up @@ -130,57 +134,39 @@ std::string PickAFolder()
return out;
}

#define MAX_MENU_ENTRIES 6

int uwp_ChooseWad(WadStuff* wads, int numwads, int defaultiwad, int& autoloadflags)
{
int selected = -1;
int selected = defaultiwad;
Windows::UI::Popups::PopupMenu^ popupmenu = ref new Windows::UI::Popups::PopupMenu();

int current_base = 0;
Windows::UI::Popups::IUICommand^ result = nullptr;


if (numwads <= 6)
int displacement = min(numwads, MAX_MENU_ENTRIES);
while (result == nullptr)
{
selected = defaultiwad;
for (int i = 0; i < numwads; ++i)
popupmenu->Commands->Clear();
for (int i = 0; i < displacement; ++i)
{
popupmenu->Commands->Append(
ref new Windows::UI::Popups::UICommand(
StdToPlatform(wads[i].Name.GetChars()),
ref new Windows::UI::Popups::UICommandInvokedHandler([&selected, i](Windows::UI::Popups::IUICommand^ command)
StdToPlatform(wads[(current_base + i) % numwads].Name.GetChars()),
ref new Windows::UI::Popups::UICommandInvokedHandler([&selected, i, current_base, numwads](Windows::UI::Popups::IUICommand^ command)
{
selected = i;
selected = (current_base + i) % numwads;
}
)
)
);
}
auto asyncop = popupmenu->ShowForSelectionAsync(CoreWindow::GetForCurrentThread()->Bounds);
WaitForAsync(asyncop);
}
else
{
while (result == nullptr)
{
popupmenu->Commands->Clear();
for (int i = 0; i < 6; ++i)
{
popupmenu->Commands->Append(
ref new Windows::UI::Popups::UICommand(
StdToPlatform(wads[(current_base + i) % numwads].Name.GetChars()),
ref new Windows::UI::Popups::UICommandInvokedHandler([&selected, i, current_base, numwads](Windows::UI::Popups::IUICommand^ command)
{
selected = (current_base + i) % numwads;
}
)
)
);
}
auto asyncop = popupmenu->ShowForSelectionAsync(CoreWindow::GetForCurrentThread()->Bounds);
WaitForAsync(asyncop);
current_base = (current_base + 6) % numwads;
result = asyncop->GetResults();
}

if (numwads > MAX_MENU_ENTRIES)
current_base = (current_base + MAX_MENU_ENTRIES) % numwads;
result = asyncop->GetResults();
}

return selected;
Expand Down

0 comments on commit 109e8e1

Please sign in to comment.