another bit of the new lobby.

Shows the minimap, more useful info in the gamelist and also fixed
preferences dialog display glitch
This commit is contained in:
Tomasz Śniatowski 2009-07-07 19:49:35 +01:00
parent cc1aa93ca3
commit 59a04d94a7
10 changed files with 179 additions and 68 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,003 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,023 B

View file

@ -61,6 +61,16 @@
[/column]
#enddef
#define GAMELISTBOX_BODY_IMAGE ID LABEL
[column]
[image]
id = {ID}
definition = "default"
label = {LABEL}
[/image]
[/column]
#enddef
#define GAMELISTBOX_EMPTY ID
[column]
[label]
@ -71,6 +81,15 @@
[/column]
#enddef
#define GAMELISTBOX_LABEL LABEL
[column]
[label]
definition = "default"
label = {LABEL}
[/label]
[/column]
#enddef
#define GAMELISTBOX
[listbox]
id = "game_list"
@ -80,15 +99,26 @@
[column]
[grid]
[row]
{GAMELISTBOX_HEADER_LABEL "map" "Map"}
{GAMELISTBOX_HEADER_LABEL "map" "Games"}
{GAMELISTBOX_EMPTY "minimap"}
{GAMELISTBOX_EMPTY "name"}
{GAMELISTBOX_EMPTY "era"}
{GAMELISTBOX_EMPTY "map_info"}
{GAMELISTBOX_EMPTY "slots"}
{GAMELISTBOX_EMPTY "status"}
{GAMELISTBOX_EMPTY "options"}
{GAMELISTBOX_EMPTY "observe"}
{GAMELISTBOX_HEADER_LABEL "join" "Join"}
{GAMELISTBOX_EMPTY "observer_icon"}
{GAMELISTBOX_EMPTY "gold_icon"}
{GAMELISTBOX_EMPTY "gold_text"}
{GAMELISTBOX_EMPTY "xp_icon"}
{GAMELISTBOX_EMPTY "xp_text"}
{GAMELISTBOX_EMPTY "time_limit_icon"}
{GAMELISTBOX_EMPTY "time_limit_text"}
{GAMELISTBOX_EMPTY "vision_text"}
{GAMELISTBOX_EMPTY "join"}
{GAMELISTBOX_EMPTY "map_size_text"}
{GAMELISTBOX_EMPTY "scenario"}
{GAMELISTBOX_EMPTY "vision_icon"}
[/row]
[/grid]
[/column]
@ -102,26 +132,41 @@
[toggle_panel]
definition = "default"
{HORIZONTAL_BEGIN}
[label]
[minimap]
id = "minimap"
definition = "default"
label = "Here be minimap"
[/label]
[/minimap]
{HORIZONTAL_SEP}
{VERTICAL_BEGIN}
[grid]
[row]
{GAMELISTBOX_BODY_LABEL "name" "Name"}
{GAMELISTBOX_BODY_LABEL "map" "Map"}
{GAMELISTBOX_BODY_LABEL "slots" "Slots"}
{GAMELISTBOX_BODY_LABEL "status" "Status"}
[/row]
[/grid]
{VERTICAL_SEP}
[grid]
[row]
{GAMELISTBOX_BODY_LABEL "map_info" "Map info"}
{GAMELISTBOX_BODY_LABEL "era" "Era"}
{GAMELISTBOX_BODY_LABEL "options" "Options"}
{GAMELISTBOX_BODY_LABEL "map_size_text" ""}
{GAMELISTBOX_BODY_LABEL "scenario" ""}
{GAMELISTBOX_BODY_IMAGE "observer_icon" "misc/eye.png"}
{GAMELISTBOX_BODY_IMAGE "gold_icon" "themes/gold.png"}
{GAMELISTBOX_BODY_LABEL "gold_text" "2"}
{GAMELISTBOX_BODY_IMAGE "xp_icon" "themes/units.png"}
{GAMELISTBOX_BODY_LABEL "xp_text" "70%"}
{GAMELISTBOX_BODY_IMAGE "time_limit_icon" "themes/sand-clock.png"}
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 1
[label]
id = "time_limit_text"
definition = "default_small"
[/label]
[/column]
{GAMELISTBOX_BODY_IMAGE "vision_icon" ""}
[/row]
[/grid]
{VERTICAL_END}
@ -255,9 +300,9 @@
[/button]
{VERTICAL_SEP}
[button]
id = "settings"
id = "show_preferences"
definition = "default"
label = _ "Settings"
label = _ "Preferences"
[/button]
{VERTICAL_SEP}
[button]

View file

@ -18,8 +18,10 @@
#include "gui/dialogs/helper.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/minimap.hpp"
#include "gui/widgets/text_box.hpp"
#include "foreach.hpp"
@ -74,10 +76,15 @@ tlobby_main::tlobby_main(const config& game_config, lobby_info& info)
, game_config_(game_config)
, gamelistbox_(NULL), chat_log_(NULL)
, chat_input_(NULL), window_(NULL)
, lobby_info_(info)
, lobby_info_(info), preferences_callback_(NULL)
{
}
void tlobby_main::set_preferences_callback(boost::function<void ()> cb)
{
preferences_callback_ = cb;
}
tlobby_main::~tlobby_main()
{
}
@ -97,6 +104,14 @@ void add_label_data(std::map<std::string, string_map>& map,
map.insert(std::make_pair(key, item));
}
void set_visible_if_exists(tgrid* grid, const char* id, bool visible)
{
twidget* w = grid->find_widget(id, false);
if (w) {
w->set_visible(visible ? twidget::VISIBLE : twidget::INVISIBLE);
}
}
} //end anonymous namespace
void tlobby_main::update_gamelist()
@ -110,29 +125,64 @@ void tlobby_main::update_gamelist()
add_label_data(data, "era", game.era);
add_label_data(data, "era_short", game.era_short);
add_label_data(data, "map_info", game.map_info);
add_label_data(data, "scenario", game.scenario);
add_label_data(data, "map_size_text", game.map_size_info);
add_label_data(data, "time_limit", game.time_limit);
add_label_data(data, "status", game.status);
add_label_data(data, "gold", game.gold);
add_label_data(data, "xp", game.xp);
add_label_data(data, "vision", game.vision);
add_label_data(data, "map_info", game.map_info);
add_label_data(data, "gold_text", game.gold);
add_label_data(data, "xp_text", game.xp);
add_label_data(data, "vision_text", game.vision);
add_label_data(data, "time_limit_icon", game.time_limit.empty() ? "" : "themes/sand-clock.png");
add_label_data(data, "time_limit_text", game.time_limit);
add_label_data(data, "status", game.status);
add_label_data(data, "observer_icon", game.observers ? "misc/eye.png" : "misc/no_observer.png");
const char* vision_icon;
if (game.fog) {
if (game.shroud) {
vision_icon = "misc/vision-fog-shroud.png";
} else {
vision_icon = "misc/vision-fog.png";
}
} else {
if (game.shroud) {
vision_icon = "misc/vision-shroud.png";
} else {
vision_icon = "misc/vision-none.png";
}
}
add_label_data(data, "vision_icon", vision_icon);
gamelistbox_->add_row(data);
tgrid* grid = gamelistbox_->get_row_grid(gamelistbox_->get_item_count() - 1);
tbutton* join_button = dynamic_cast<tbutton*>(
grid->find_widget("join", false));
join_button->set_callback_mouse_left_click(
dialog_callback<tlobby_main, &tlobby_main::join_button_callback>);
set_visible_if_exists(grid, "time_limit_icon", !game.time_limit.empty());
set_visible_if_exists(grid, "vision_fog", game.fog);
set_visible_if_exists(grid, "vision_shroud", game.shroud);
set_visible_if_exists(grid, "vision_none", !(game.fog || game.shroud));
set_visible_if_exists(grid, "observers_yes", game.observers);
set_visible_if_exists(grid, "observers_no", !game.observers);
set_visible_if_exists(grid, "needs_password", game.password_required);
set_visible_if_exists(grid, "reloaded", game.reloaded);
set_visible_if_exists(grid, "started", game.started);
set_visible_if_exists(grid, "use_map_settings", game.use_map_settings);
tbutton* observe_button = dynamic_cast<tbutton*>(
grid->find_widget("observe", false));
observe_button->set_callback_mouse_left_click(
dialog_callback<tlobby_main, &tlobby_main::observe_button_callback>);
}
for (size_t i = 0; i < userlistbox_->get_item_count(); ++i) {
userlistbox_->remove_row(0);
tbutton* join_button = dynamic_cast<tbutton*>(grid->find_widget("join", false));
if (join_button) {
join_button->set_callback_mouse_left_click(
dialog_callback<tlobby_main, &tlobby_main::join_button_callback>);
}
tbutton* observe_button = dynamic_cast<tbutton*>(grid->find_widget("observe", false));
if (observe_button) {
observe_button->set_callback_mouse_left_click(
dialog_callback<tlobby_main, &tlobby_main::observe_button_callback>);
}
tminimap* minimap = dynamic_cast<tminimap*>(grid->find_widget("minimap", false));
if (minimap) {
minimap->set_config(&game_config_);
minimap->set_map_data(game.map_data);
}
}
userlistbox_->clear();
foreach (const user_info& user, lobby_info_.users())
{
std::map<std::string, string_map> data;
@ -163,7 +213,7 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
GUI2_EASY_BUTTON_CALLBACK(create, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(show_help, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(refresh, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(settings, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(show_preferences, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(join_global, tlobby_main);
GUI2_EASY_BUTTON_CALLBACK(observe_global, tlobby_main);
}
@ -326,10 +376,12 @@ void tlobby_main::refresh_button_callback(gui2::twindow& /*window*/)
}
void tlobby_main::settings_button_callback(gui2::twindow& window)
void tlobby_main::show_preferences_button_callback(gui2::twindow& window)
{
legacy_result_ = PREFERENCES;
window.close();
if (preferences_callback_) {
preferences_callback_();
network::send_data(config("refresh_lobby"), 0, true);
}
}
void tlobby_main::show_help_button_callback(gui2::twindow& /*window*/)

View file

@ -20,7 +20,8 @@
#include "chat_events.hpp"
#include "lobby_data.hpp"
#include "boost/scoped_ptr.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/function.hpp>
namespace gui2 {
@ -37,6 +38,11 @@ public:
~tlobby_main();
/**
* Set the callback used to show the preferences.
*/
void set_preferences_callback(boost::function<void ()> f);
void update_gamelist();
enum legacy_result { QUIT, JOIN, OBSERVE, CREATE, PREFERENCES };
@ -89,7 +95,7 @@ private:
void create_button_callback(twindow& window);
void settings_button_callback(twindow& window);
void show_preferences_button_callback(twindow& window);
void show_help_button_callback(twindow& window);
@ -119,6 +125,8 @@ private:
twindow* window_;
lobby_info& lobby_info_;
boost::function<void ()> preferences_callback_;
};
} // namespace gui2

View file

@ -92,8 +92,10 @@ game_info::game_info() :
id(),
map_data(),
name(),
scenario(),
remote_scenario(false),
map_info(),
map_info_size(),
map_size_info(),
gold(),
xp(),
vision(),
@ -138,8 +140,10 @@ game_info::game_info(const config& game, const config& game_config)
, id(game["id"])
, map_data(game["map_data"])
, name(game["name"])
, scenario()
, remote_scenario(false)
, map_info()
, map_info_size()
, map_size_info()
, era()
, era_short()
, gold(game["mp_village_gold"])
@ -151,11 +155,11 @@ game_info::game_info(const config& game, const config& game_config)
, current_turn(0)
, reloaded(game["savegame"] == "yes")
, started(false)
, fog(false)
, shroud(false)
, fog(game["mp_fog"] == "yes")
, shroud(game["mp_shroud"] == "yes")
, observers(game["observer"] != "no")
, use_map_settings(game["mp_use_map_settings"] == "yes")
, verified(false)
, verified(true)
, password_required(game["password"] == "yes")
, have_era(true)
{
@ -186,7 +190,7 @@ game_info::game_info(const config& game, const config& game_config)
map_info = era;
if (map_data.empty()) {
map_data = read_map(game["map"]);
map_data = read_map(game["mp_scenario"]);
}
if (map_data.empty()) {
@ -195,9 +199,9 @@ game_info::game_info(const config& game, const config& game_config)
try {
gamemap map(game_config, map_data);
//mini_map = image::getMinimap(minimap_size_, minimap_size_, map, 0);
map_info_size = lexical_cast_default<std::string, int>(map.w(), "??")
map_size_info = lexical_cast_default<std::string, int>(map.w(), "??")
+ std::string("x") + lexical_cast_default<std::string, int>(map.h(), "??");
map_info += " - " + map_info_size;
map_info += " - " + map_size_info;
} catch (incorrect_map_format_exception &e) {
ERR_CF << "illegal map: " << e.msg_ << "\n";
verified = false;
@ -216,7 +220,8 @@ game_info::game_info(const config& game, const config& game_config)
level_cfg = &game_config.find_child("generic_multiplayer", "id", game["mp_scenario"]);
}
if (*level_cfg) {
map_info += level_cfg->get_attribute("name");
scenario = level_cfg->get_attribute("name");
map_info += scenario;
// reloaded games do not match the original scenario hash,
// so it makes no sense to test them, they always would appear
// as remote scenarios
@ -231,6 +236,7 @@ game_info::game_info(const config& game, const config& game_config)
}
}
if(!hash_found) {
remote_scenario = true;
map_info += " - ";
map_info += _("Remote scenario");
verified = false;
@ -240,11 +246,13 @@ game_info::game_info(const config& game, const config& game_config)
} else {
utils::string_map symbols;
symbols["scenario_id"] = game["mp_scenario"];
map_info += vgettext("Unknown scenario: $scenario_id", symbols);
scenario = vgettext("Unknown scenario: $scenario_id", symbols);
map_info += scenario;
verified = false;
}
} else {
map_info += _("Unknown scenario");
scenario = _("Unknown scenario");
map_info += scenario;
verified = false;
}
if (reloaded) {
@ -266,34 +274,23 @@ game_info::game_info(const config& game, const config& game_config)
if (vacant_slots > 0) {
status = std::string(_n("Vacant Slot:", "Vacant Slots:",
vacant_slots)) + " " + game["slots"];
if (password_required) {
status += std::string(" (") + std::string(_("Password Required")) + ")";
}
}
}
if (game["mp_fog"] == "yes") {
if (fog) {
vision = _("Fog");
fog = true;
if (game["mp_shroud"] == "yes") {
if (shroud) {
vision += "/";
vision += _("Shroud");
shroud = true;
} else {
shroud = false;
}
} else if (game["mp_shroud"] == "yes") {
} else if (shroud) {
vision = _("Shroud");
fog = false;
shroud = true;
} else {
vision = _("none");
fog = false;
shroud = false;
}
if (game["mp_countdown"] == "yes" ) {
time_limit = game["mp_countdown_init_time"] + " / +"
+ game["mp_countdown_turn_bonus"] + " "
time_limit = game["mp_countdown_init_time"] + "+"
+ game["mp_countdown_turn_bonus"] + "/"
+ game["mp_countdown_action_bonus"];
} else {
time_limit = "";

View file

@ -73,15 +73,17 @@ struct game_info
std::string id;
std::string map_data;
std::string name;
std::string scenario;
bool remote_scenario;
std::string map_info;
std::string map_info_size;
std::string map_size_info;
std::string era;
std::string era_short;
std::string gold;
std::string xp;
std::string vision;
std::string status;
std::string status; //vacant slots or turn info
std::string time_limit;
size_t vacant_slots;

View file

@ -33,6 +33,8 @@
#include "upload_log.hpp"
#include "formula_string_utils.hpp"
#include <boost/bind.hpp>
static lg::log_domain log_network("network");
#define LOG_NW LOG_STREAM(info, log_network)
@ -490,6 +492,12 @@ static void enter_create_mode(game_display& disp, const config& game_config, mp:
}
}
static void do_preferences_dialog(game_display& disp, const config& game_config)
{
const preferences::display_manager disp_manager(&disp);
preferences::show_preferences_dialog(disp,game_config);
}
static void enter_lobby_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist)
{
mp::ui::result res;
@ -498,15 +506,15 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, mp::
while (true) {
if(gui2::new_widgets) {
gui2::tlobby_main dlg(game_config, li);
dlg.set_preferences_callback(
boost::bind(do_preferences_dialog,
boost::ref(disp), boost::ref(game_config)));
dlg.show(disp.video());
//ugly kludge for launching other dialogs like the old lobby
switch (dlg.get_legacy_result()) {
case gui2::tlobby_main::CREATE:
res = mp::ui::CREATE;
break;
case gui2::tlobby_main::PREFERENCES:
res = mp::ui::PREFERENCES;
break;
case gui2::tlobby_main::JOIN:
res = mp::ui::JOIN;
break;
@ -560,8 +568,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config, mp::
return;
case mp::ui::PREFERENCES:
{
const preferences::display_manager disp_manager(&disp);
preferences::show_preferences_dialog(disp,game_config);
do_preferences_dialog(disp, game_config);
//update lobby content
network::send_data(config("refresh_lobby"), 0, true);
}