backporting 2009-01-05T21:48:12Z!thomas.baumhauer@gmail.com per Soliton's request

This commit is contained in:
Thomas Baumhauer 2009-01-06 10:44:10 +00:00
parent beb357a62f
commit c0850701a3
4 changed files with 54 additions and 0 deletions

View file

@ -569,6 +569,19 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
set_dirty();
}
void gamebrowser::select_game(const std::string id) {
if (id.empty()) return;
for (unsigned int i=0; i < games_.size(); i++) {
if (games_[i].id == id) {
selected_ = i;
break;
}
}
adjust_position(selected_);
set_dirty();
}
lobby::lobby_sorter::lobby_sorter(const config& cfg) : cfg_(cfg)
{
set_alpha_sort(1);
@ -747,6 +760,11 @@ void lobby::process_event()
last_selected_game_ = selected_game;
}
if(selected_user_changed()) {
set_selected_user_changed(false);
games_menu_.select_game(get_selected_user_game());
}
if(join || observe) {
const int selected = games_menu_.selection();
if(!games_menu_.empty() && selected >= 0) {

View file

@ -73,6 +73,7 @@ public:
void reset_selection() { double_clicked_ = false; }
int selection() const { return selected_; }
game_item selected_game() { return games_[selected_]; }
void select_game(const std::string id);
protected:
unsigned int row_height() const { return item_height_ + (2 * style_->get_thickness()); }
private:

View file

@ -252,6 +252,8 @@ ui::ui(game_display& disp, const std::string& title, const config& cfg, chat& c,
users_menu_(disp.video(), std::vector<std::string>(), false, -1, -1, NULL, &umenu_style),
selected_game_(""),
selected_user_(""),
selected_user_changed_(false),
result_(CONTINUE),
gamelist_refresh_(false),
@ -393,6 +395,11 @@ void ui::handle_event(const SDL_Event& event)
network::send_data(request, 0, true);
}
}
if(users_menu_.selection() > 0 // -1 indicates an invalid selection
&& selected_user_ != user_list_[users_menu_.selection()]) {
selected_user_ = user_list_[users_menu_.selection()];
selected_user_changed_ = true;
}
}
void ui::add_chat_message(const time_t& time, const std::string& speaker, int /*side*/, const std::string& message, game_display::MESSAGE_TYPE /*type*/)
@ -674,6 +681,14 @@ void ui::set_selected_game(const std::string game_id)
void ui::set_user_menu_items(const std::vector<std::string>& list)
{
users_menu_.set_items(list,true,true);
// Try to keep selected player
std::vector<std::string>::const_iterator i =
std::find(user_list_.begin(), user_list_.end(), selected_user_);
if(i != user_list_.end()) {
users_menu_.reset_selection();
users_menu_.move_selection(i - user_list_.begin());
}
}
void ui::set_user_list(const std::vector<std::string>& list, bool silent)
@ -689,6 +704,19 @@ void ui::set_user_list(const std::vector<std::string>& list, bool silent)
user_list_ = list;
}
std::string ui::get_selected_user_game() {
config::child_list users = gamelist_.get_children("user");
config::child_iterator user;
for (user = users.begin(); user != users.end(); ++user) {
if((**user)["name"] == selected_user_) {
return (**user)["game_id"];
}
}
return "";
}
void ui::append_to_title(const std::string& text) {
title_.set_text(title_.get_text() + text);
}

View file

@ -169,6 +169,10 @@ protected:
void append_to_title(const std::string& name);
const gui::label& title() const;
std::string get_selected_user_game();
bool selected_user_changed() const { return selected_user_changed_; }
void set_selected_user_changed(const bool& changed) { selected_user_changed_ = changed; }
private:
/** Set to true when the widgets are intialized. Allows delayed
* initialization on first positioning. */
@ -200,6 +204,9 @@ private:
std::string selected_game_;
std::string selected_user_;
bool selected_user_changed_;
result result_;
bool gamelist_refresh_;