Skip to content

Commit

Permalink
show current stage in loadingscren.
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Mar 30, 2016
1 parent e6c58dc commit 53e527a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
2 changes: 2 additions & 0 deletions data/gui/window/loadscreen.cfg
Expand Up @@ -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..."
Expand Down
32 changes: 28 additions & 4 deletions src/gui/dialogs/loadscreen.cpp
Expand Up @@ -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 <boost/bind.hpp>
Expand All @@ -34,8 +36,10 @@ tloadscreen::tloadscreen(boost::function<void()> f)
, work_(f)
, worker_()
, cursor_setter_()
, current_stage(NULL)
, current_stage_(NULL)
, current_visible_stage_(NULL)
{
current_load = this;
}
void tloadscreen::show(CVideo& video)
{
Expand Down Expand Up @@ -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<tlabel>(&window, "status", false);
}

void tloadscreen::post_show(twindow& /*window*/)
Expand All @@ -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;
Expand All @@ -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<void()> f)
{
if (current_load || video.faked()) {
f();
}
else {
tloadscreen(f).show(video);
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/gui/dialogs/loadscreen.hpp
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include "gui/dialogs/dialog.hpp"
#include "gui/widgets/label.hpp"

#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
Expand All @@ -38,22 +39,10 @@ class tloadscreen : public tdialog

tloadscreen(boost::function<void()> f);

~tloadscreen()
{
close();
}

static void display(CVideo& video, boost::function<void()> 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<void()> f);
static bool displaying() { return current_load != NULL; }

void show(CVideo& video);

Expand All @@ -66,7 +55,6 @@ class tloadscreen : public tdialog
* when the window is not shown.
*/
void close();

private:
twindow* window_;
size_t timer_id_;
Expand All @@ -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

0 comments on commit 53e527a

Please sign in to comment.