The Battle for Wesnoth  1.19.7+dev
player_list_helper.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
17 #include "gui/widgets/listbox.hpp"
18 #include "gui/widgets/window.hpp"
20 
21 namespace gui2
22 {
24  : list_(window->find_widget<listbox>("player_list"))
25 {
26  // add ourselves as the host
27  widget_data data = {
28  { "player_type_icon", {{ "label", "misc/leader-crown.png~CROP(12, 1, 15, 15)"}}},
29  { "player_name", {{ "label", prefs::get().login()}}}
30  };
32  list_.select_row(0);
33 }
34 
36 {
37  list_.clear();
38  unsigned i = 0;
39 
40  for(const config& user : users) {
42  widget_item item;
43 
44  const std::string name = user["name"];
45  const bool is_you = name == prefs::get().login();
46 
47  std::string icon;
48  if(user["host"].to_bool()) {
49  icon = "misc/leader-crown.png~CROP(12, 1, 15, 15)";
50  } else if(user["observer"].to_bool()) {
51  icon = "misc/eye.png";
52  } else if(is_you) {
53  icon = "lobby/status-lobby-s.png";
54  } else {
55  icon = "lobby/status-lobby-n.png";
56  }
57 
58  item["label"] = icon;
59  data.emplace("player_type_icon", item);
60 
61  item["label"] = name;
62  data.emplace("player_name", item);
63 
65 
66  if(is_you) {
68  }
69 
70  ++i;
71  }
72 }
73 
74 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:296
The listbox class.
Definition: listbox.hpp:41
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:92
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:280
void clear()
Removes all the rows in the listbox, clearing it.
Definition: listbox.cpp:153
void update_list(const config::const_child_itors &users)
player_list_helper(window *window)
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
static prefs & get()
std::string login()
std::size_t i
Definition: function.cpp:1029
This file contains the window object, this object is a top level container which has the event manage...
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
std::string_view data
Definition: picture.cpp:178