From 53e527acc7fbd547a3d3b95e73922e4cd560db59 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Wed, 30 Mar 2016 15:26:48 +0200 Subject: [PATCH] show current stage in loadingscren. --- data/gui/window/loadscreen.cfg | 2 ++ src/gui/dialogs/loadscreen.cpp | 32 ++++++++++++++++++++++++++++---- src/gui/dialogs/loadscreen.hpp | 28 ++++++++++------------------ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/data/gui/window/loadscreen.cfg b/data/gui/window/loadscreen.cfg index a57c8bc700f0..8cb03f332f14 100644 --- a/data/gui/window/loadscreen.cfg +++ b/data/gui/window/loadscreen.cfg @@ -102,8 +102,10 @@ border_size = 5 horizontal_alignment = "center" vertical_alignment = "center" + horizontal_grow = "true" [label] + text_alignment = "center" definition = "default_large" id = "status" label = _ "Loading..." diff --git a/src/gui/dialogs/loadscreen.cpp b/src/gui/dialogs/loadscreen.cpp index 0db775a3eaef..1f80ed5286dc 100644 --- a/src/gui/dialogs/loadscreen.cpp +++ b/src/gui/dialogs/loadscreen.cpp @@ -18,6 +18,8 @@ #include "gui/widgets/window.hpp" #include "gui/widgets/settings.hpp" #include "gui/core/timer.hpp" +#include "gui/auxiliary/find_widget.hpp" + #include "video.hpp" #include "cursor.hpp" #include @@ -34,8 +36,10 @@ tloadscreen::tloadscreen(boost::function f) , work_(f) , worker_() , cursor_setter_() - , current_stage(NULL) + , current_stage_(NULL) + , current_visible_stage_(NULL) { + current_load = this; } void tloadscreen::show(CVideo& video) { @@ -73,6 +77,7 @@ void tloadscreen::pre_show(twindow& window) worker_.reset(new boost::thread(work_)); timer_id_ = add_timer(100, boost::bind(&tloadscreen::timer_callback, this, boost::ref(window)), true); cursor_setter_.reset(new cursor::setter(cursor::WAIT)); + progress_stage_label_ = &find_widget(&window, "status", false); } void tloadscreen::post_show(twindow& /*window*/) @@ -89,10 +94,8 @@ void tloadscreen::progress(const char* stage) } // Currently this is a no-op stub if(stage) { - // TODO: Update displayed stage - current_load->current_stage = stage; + current_load->current_stage_ = stage; } - // TODO: Indicate progress somehow } tloadscreen* tloadscreen::current_load = NULL; @@ -101,7 +104,28 @@ void tloadscreen::timer_callback(twindow& window) { if (!worker_ || worker_->timed_join(boost::posix_time::milliseconds(0))) { window.close(); + } + if (current_stage_ != current_visible_stage_) + { + current_visible_stage_ = current_stage_; + progress_stage_label_->set_label(current_visible_stage_); + + } +} +tloadscreen::~tloadscreen() +{ + close(); + current_load = NULL; +} + +void tloadscreen::display(CVideo& video, boost::function f) +{ + if (current_load || video.faked()) { + f(); + } + else { + tloadscreen(f).show(video); } } diff --git a/src/gui/dialogs/loadscreen.hpp b/src/gui/dialogs/loadscreen.hpp index 02f62f2aadf9..d344eaaa9203 100644 --- a/src/gui/dialogs/loadscreen.hpp +++ b/src/gui/dialogs/loadscreen.hpp @@ -14,6 +14,7 @@ #pragma once #include "gui/dialogs/dialog.hpp" +#include "gui/widgets/label.hpp" #include #include @@ -38,22 +39,10 @@ class tloadscreen : public tdialog tloadscreen(boost::function f); - ~tloadscreen() - { - close(); - } - - static void display(CVideo& video, boost::function f) { - static bool already_shown = false; - if (already_shown) { - f(); - } - else { - already_shown = true; - tloadscreen(f).show(video); - already_shown = false; - } - } + ~tloadscreen(); + + static void display(CVideo& video, boost::function f); + static bool displaying() { return current_load != NULL; } void show(CVideo& video); @@ -66,7 +55,6 @@ class tloadscreen : public tdialog * when the window is not shown. */ void close(); - private: twindow* window_; size_t timer_id_; @@ -86,8 +74,12 @@ class tloadscreen : public tdialog /** Inherited from tdialog. */ void post_show(twindow& window); + tlabel* progress_stage_label_; static tloadscreen* current_load; - const char* current_stage; + + //Note we cannot use std::strings here unless we we explicitly use mutexes. + const char* current_stage_; + const char* current_visible_stage_; }; } // namespace gui2