From: Ingo Ruhnke Date: Tue, 26 Aug 2014 20:00:33 +0000 (+0200) Subject: Wait for an explicit "Close" by the user instead of closing the DownloadDialog automa... X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=c9ac532882ccae6870377e801154a04c5fe181e8;hp=e9df7ac74e53d818c21b4a67e9ef0e83d9c89dd4;p=supertux.git Wait for an explicit "Close" by the user instead of closing the DownloadDialog automatically Downloads are most of the time rather fast, having the window just pop up and go away feels a bit irritating. --- diff --git a/src/gui/dialog.cpp b/src/gui/dialog.cpp index 260c7bf0b..b10f29918 100644 --- a/src/gui/dialog.cpp +++ b/src/gui/dialog.cpp @@ -49,6 +49,13 @@ Dialog::set_text(const std::string& text) } void +Dialog::clear_buttons() +{ + m_buttons.clear(); + m_selected_button = 0; +} + +void Dialog::add_button(const std::string& text, const std::function& callback, bool focus) { m_buttons.push_back({text, callback}); diff --git a/src/gui/dialog.hpp b/src/gui/dialog.hpp index bb379c137..86c499a2f 100644 --- a/src/gui/dialog.hpp +++ b/src/gui/dialog.hpp @@ -47,6 +47,7 @@ public: virtual ~Dialog(); void set_text(const std::string& text); + void clear_buttons(); void add_button(const std::string& text, const std::function& callback = {}, bool focus = false); diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index 76f64f886..b9ee6c380 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -186,7 +186,6 @@ AddonMenu::menu_action(MenuItem* item) { TransferStatusPtr status = m_addon_manager.request_check_online(); status->then([this]{ - MenuManager::instance().set_dialog({}); refresh(); }); std::unique_ptr dialog(new DownloadDialog(status)); @@ -236,7 +235,6 @@ AddonMenu::menu_action(MenuItem* item) { log_warning << "Enabling addon failed: " << err.what() << std::endl; } - MenuManager::instance().set_dialog({}); refresh(); }); diff --git a/src/supertux/menu/download_dialog.cpp b/src/supertux/menu/download_dialog.cpp index 8ba7fc288..c8d1cfdf5 100644 --- a/src/supertux/menu/download_dialog.cpp +++ b/src/supertux/menu/download_dialog.cpp @@ -30,6 +30,10 @@ DownloadDialog::DownloadDialog(TransferStatusPtr status) : }); update_text(); + + status->then([this]{ + on_download_complete(); + }); } void @@ -70,4 +74,13 @@ DownloadDialog::on_abort() AddonManager::current()->abort_install(); } +void +DownloadDialog::on_download_complete() +{ + clear_buttons(); + add_button(_("Close"), [this]{ + MenuManager::instance().set_dialog({}); + }); +} + /* EOF */ diff --git a/src/supertux/menu/download_dialog.hpp b/src/supertux/menu/download_dialog.hpp index 1853ae930..45b5b5fb5 100644 --- a/src/supertux/menu/download_dialog.hpp +++ b/src/supertux/menu/download_dialog.hpp @@ -38,6 +38,7 @@ public: private: void on_abort(); + void on_download_complete(); void update_text();