Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (38 sloc) 1.215 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#ifndef NO_EDITOR
#include <boost/bind.hpp>

#include "dialog.hpp"
#include "editor_dialogs.hpp"
#include "foreach.hpp"
#include "grid_widget.hpp"
#include "label.hpp"
#include "load_level.hpp"
#include "raster.hpp"
#include "widget.hpp"

namespace {
void do_select_level(gui::dialog* d, const std::vector<std::string>& levels, int index, std::string* result) {
if(index >= 0 && index < levels.size()) {
d->close();
*result = levels[index];
}
}
}

std::string show_choose_level_dialog(const std::string& prompt)
{
using namespace gui;
dialog d(0, 0, graphics::screen_width(), graphics::screen_height());
d.add_widget(widget_ptr(new label(prompt, graphics::color_white(), 48)));

std::string result;
std::vector<std::string> levels = get_known_levels();
gui::grid* grid = new gui::grid(1);
grid->set_max_height(graphics::screen_height() - 80);
grid->set_show_background(true);
grid->allow_selection();

grid->register_selection_callback(boost::bind(&do_select_level, &d, levels, _1, &result));
foreach(const std::string& lvl, levels) {
grid->add_col(widget_ptr(new label(lvl, graphics::color_white())));
}

d.add_widget(widget_ptr(grid));
d.show_modal();
return result;
}
#endif // NO_EDITOR

Something went wrong with that request. Please try again.