Skip to content

Commit

Permalink
mp selector: replaced refreshing message with spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
tritonas00 committed Apr 8, 2022
1 parent b503880 commit 185d106
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions source/main/gui/panels/GUI_MultiplayerSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ void MultiplayerSelector::DrawDirectTab()

void MultiplayerSelector::DrawServerlistTab()
{
GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();

const char* draw_label_text = nullptr;
ImVec4 draw_label_color;

Expand All @@ -252,6 +254,14 @@ void MultiplayerSelector::DrawServerlistTab()
draw_label_color = m_serverlist_msg_color;
}

if (m_show_spinner)
{
float spinner_size = 25.f;
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.f) - spinner_size);
ImGui::SetCursorPosY((ImGui::GetWindowSize().y / 2.f) - spinner_size);
LoadingIndicatorCircle("spinner", spinner_size, theme.value_blue_text_color, theme.value_blue_text_color, 10, 10);
}

// DRAW SERVERLIST TABLE
if (m_draw_table)
{
Expand Down Expand Up @@ -355,11 +365,11 @@ void MultiplayerSelector::DrawServerlistTab()
void MultiplayerSelector::StartAsyncRefresh()
{
#if defined(USE_CURL)
m_show_spinner = true;
m_draw_table = false;
m_serverlist_data.clear();
m_selected_item = -1;
m_serverlist_msg = _LC("MultiplayerSelector", "... refreshing ...");
m_serverlist_msg_color = App::GetGuiManager()->GetTheme().in_progress_text_color;
m_serverlist_msg = "";
std::packaged_task<void(std::string)> task(FetchServerlist);
std::thread(std::move(task), App::mp_api_url->getStr()).detach(); // launch on a thread
#endif // defined(USE_CURL)
Expand All @@ -381,13 +391,15 @@ void MultiplayerSelector::SetVisible(bool visible)

void MultiplayerSelector::DisplayRefreshFailed(std::string const& msg)
{
m_show_spinner = false;
m_serverlist_msg = msg;
m_serverlist_msg_color = App::GetGuiManager()->GetTheme().error_text_color;
m_draw_table = false;
}

void MultiplayerSelector::UpdateServerlist(MpServerInfoVec* data)
{
m_show_spinner = false;
m_serverlist_data = *data;
m_draw_table = true;
if (m_serverlist_data.empty())
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_MultiplayerSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class MultiplayerSelector
Str<1000> m_password_buf;
Str<1000> m_server_host_buf;
Ogre::TexturePtr m_lock_icon;
bool m_show_spinner = false;
};

} // namespace GUI
Expand Down

0 comments on commit 185d106

Please # to comment.