mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-08 18:31:27 +00:00
WIP on the new lobby gui
This commit is contained in:
parent
2b6d65d733
commit
06ccc5262f
@ -156,11 +156,11 @@
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "center"
|
||||
horizontal_placement = "center"
|
||||
|
||||
automatic_placement = "false"
|
||||
x = 0
|
||||
y = 0
|
||||
width = "(screen_width)"
|
||||
height = "(screen_height)"
|
||||
[grid]
|
||||
[row]
|
||||
grow_factor = 0
|
||||
@ -190,6 +190,7 @@
|
||||
id = "chat_log"
|
||||
definition = "default"
|
||||
label = ""
|
||||
height = 200
|
||||
[/text_box]
|
||||
{VERTICAL_SEP}
|
||||
{HORIZONTAL_BEGIN}
|
||||
|
@ -15,7 +15,10 @@
|
||||
|
||||
#include "gui/dialogs/lobby_main.hpp"
|
||||
#include "gui/dialogs/field.hpp"
|
||||
#include "gui/dialogs/helper.hpp"
|
||||
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "foreach.hpp"
|
||||
@ -28,10 +31,19 @@ static lg::log_domain log_network("network");
|
||||
#define LOG_NW LOG_STREAM(info, log_network)
|
||||
#define ERR_NW LOG_STREAM(err, log_network)
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
tlobby_main::tlobby_main()
|
||||
: gamelist_(NULL), chat_log_(NULL)
|
||||
: games_(), games_initialized_(false)
|
||||
, gamelistbox_(NULL), chat_log_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -58,14 +70,25 @@ void tlobby_main::update_gamelist(const config& cfg)
|
||||
item["label"] = tmp;
|
||||
data.insert(std::make_pair("name", item));
|
||||
|
||||
gamelist_->add_row(data);
|
||||
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>);
|
||||
|
||||
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>);
|
||||
}
|
||||
}
|
||||
|
||||
void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
|
||||
{
|
||||
gamelist_ = dynamic_cast<tlistbox*>(window.find_widget("game_list", false));
|
||||
VALIDATE(gamelist_, missing_widget("game_list"));
|
||||
gamelistbox_ = dynamic_cast<tlistbox*>(window.find_widget("game_list", false));
|
||||
VALIDATE(gamelistbox_, missing_widget("game_list"));
|
||||
|
||||
chat_log_ = dynamic_cast<ttext_box*>(window.find_widget("chat_log", false));
|
||||
VALIDATE(chat_log_, missing_widget("chat_log"));
|
||||
@ -96,7 +119,7 @@ void tlobby_main::process_network_data(const config &data)
|
||||
} else if (const config &c = data.child("whisper")) {
|
||||
process_message(c, true);
|
||||
} else if(data.child("gamelist")) {
|
||||
process_gamelist(c);
|
||||
process_gamelist(data);
|
||||
} else if (const config &c = data.child("gamelist_diff")) {
|
||||
process_gamelist_diff(c);
|
||||
} else if (const config &c = data.child("room_join")) {
|
||||
@ -120,15 +143,29 @@ void tlobby_main::process_message(const config &data, bool /*whisper / *= false*
|
||||
}
|
||||
ss << sender << "> ";
|
||||
ss << message;
|
||||
chat_log_->set_value(chat_log_->text() + "\n" + ss.str());
|
||||
LOG_NW << "Message: " << ss.str() << std::endl;
|
||||
//chat_log_->set_value(chat_log_->text() + "\n" + ss.str());
|
||||
}
|
||||
|
||||
void tlobby_main::process_gamelist(const config &/*data*/)
|
||||
{
|
||||
games_ = data;
|
||||
games_initialized_ = true;
|
||||
update_gamelist(games_);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
update_gamelist(games_);
|
||||
}
|
||||
|
||||
void tlobby_main::process_room_join(const config &/*data*/)
|
||||
@ -143,4 +180,14 @@ void tlobby_main::process_room_query_response(const config &/*data*/)
|
||||
{
|
||||
}
|
||||
|
||||
void tlobby_main::join_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "join_button_callback\n";
|
||||
}
|
||||
|
||||
void tlobby_main::observe_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "observe_button_callback\n";
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
@ -16,11 +16,13 @@
|
||||
#define GUI_DIALOGS_LOBBY_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
class config;
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class tlabel;
|
||||
class tlistbox;
|
||||
class ttext_box;
|
||||
|
||||
@ -50,13 +52,22 @@ private:
|
||||
|
||||
void process_room_query_response(const config& data);
|
||||
|
||||
void join_button_callback(twindow& window);
|
||||
|
||||
void observe_button_callback(twindow& window);
|
||||
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow* build_window(CVideo& video);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
tlistbox* gamelist_;
|
||||
config games_;
|
||||
|
||||
bool games_initialized_;
|
||||
|
||||
tlistbox* gamelistbox_;
|
||||
|
||||
ttext_box* chat_log_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user