more new lobby WIP

This commit is contained in:
Tomasz Śniatowski 2009-07-04 17:24:35 +01:00
parent 889c53d0a5
commit 5c380490ef
4 changed files with 22 additions and 33 deletions

View file

@ -83,7 +83,6 @@
horizontal_grow = "true"
[toggle_panel]
definition = "default"
return_value_id = "ok"
[grid]
[row]
{GAMELISTBOX_BODY_LABEL "name" "Name"}
@ -128,7 +127,6 @@
horizontal_grow = "true"
[toggle_panel]
definition = "default"
return_value_id = "ok"
[grid]
[row]
[column]
@ -153,7 +151,6 @@
[window]
id = "lobby_main"
description = "Lobby screen."
[resolution]
definition = "default"
automatic_placement = "false"
@ -235,7 +232,7 @@
[/button]
{VERTICAL_SEP}
[button]
id = "help"
id = "show_help"
definition = "default"
label = _ "Help"
[/button]

View file

@ -23,6 +23,7 @@
#include "gui/widgets/text_box.hpp"
#include "foreach.hpp"
#include "lobby_data.hpp"
#include "log.hpp"
#include "network.hpp"
#include "game_preferences.hpp"
@ -68,10 +69,11 @@ void tlobby_main::add_chat_message(const time_t& /*time*/, const std::string& sp
window_->invalidate_layout();
}
tlobby_main::tlobby_main()
: games_(), games_initialized_(false)
tlobby_main::tlobby_main(const config& game_config)
: game_config_(game_config)
, gamelistbox_(NULL), chat_log_(NULL)
, chat_input_(NULL), window_(NULL)
, lobby_info_(new lobby_info(game_config))
{
}
@ -84,22 +86,18 @@ twindow* tlobby_main::build_window(CVideo& video)
return build(video, get_id(LOBBY_MAIN));
}
void tlobby_main::update_gamelist(const config& cfg)
void tlobby_main::update_gamelist()
{
foreach (const config &game, cfg.child("gamelist").child_range("game"))
foreach (const game_info &game, lobby_info_->games())
{
std::map<std::string, string_map> data;
string_map item;
std::string tmp;
tmp = game["name"];
utils::truncate_as_wstring(tmp, 20);
item["label"] = tmp;
item["label"] = game.name;
data.insert(std::make_pair("name", item));
tmp = game["mp_era"];
utils::truncate_as_wstring(tmp, 20);
item["label"] = tmp;
item["label"] = game.map_info;
data.insert(std::make_pair("name", item));
gamelistbox_->add_row(data);
@ -191,23 +189,15 @@ void tlobby_main::process_message(const config &data, bool /*whisper / *= false*
void tlobby_main::process_gamelist(const config &data)
{
games_ = data;
games_initialized_ = true;
update_gamelist(games_);
lobby_info_->process_gamelist(data);
update_gamelist();
}
void tlobby_main::process_gamelist_diff(const config &data)
{
if (!games_initialized_) return;
try {
games_.apply_diff(data);
} catch(config::error& e) {
ERR_CF << "Error while applying the gamelist diff: '"
<< e.message << "' Getting a new gamelist.\n";
network::send_data(config("refresh_lobby"), 0, true);
return;
if (lobby_info_->process_gamelist_diff(data)) {
update_gamelist();
}
update_gamelist(games_);
}
void tlobby_main::process_room_join(const config &/*data*/)

View file

@ -19,7 +19,9 @@
#include "config.hpp"
#include "chat_events.hpp"
class config;
#include "boost/scoped_ptr.hpp"
class lobby_info;
namespace gui2 {
@ -31,11 +33,11 @@ class twindow;
class tlobby_main : public tdialog, private events::chat_handler
{
public:
tlobby_main();
tlobby_main(const config& game_config);
~tlobby_main();
void update_gamelist(const config& cfg);
void update_gamelist();
protected:
void send_chat_message(const std::string& message, bool /*allies_only*/);
void add_chat_message(const time_t& time, const std::string& speaker,
@ -77,9 +79,7 @@ private:
/** Inherited from tdialog. */
void post_show(twindow& window);
config games_;
bool games_initialized_;
const config& game_config_;
tlistbox* gamelistbox_;
@ -88,6 +88,8 @@ private:
ttext_box* chat_input_;
twindow* window_;
boost::scoped_ptr<lobby_info> lobby_info_;
};
} // namespace gui2

View file

@ -577,7 +577,7 @@ void start_client(game_display& disp, const config& game_config,
switch(type) {
case WESNOTHD_SERVER:
if(gui2::new_widgets) {
gui2::tlobby_main dlg;
gui2::tlobby_main dlg(game_config);
dlg.show(disp.video());
} else {
enter_lobby_mode(disp, game_config, chat, gamelist);