The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
player_list_helper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
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
20
21namespace gui2
22{
24 : list_(window->find_widget<listbox>("player_list"))
25{
26 // add ourselves as the host
28 { "player_type_icon", {
29 { "label", "misc/leader-crown.png~CROP(12, 1, 15, 15)" }
30 }},
31 { "player_name", {
32 { "label", prefs::get().login() }
33 }}
34 });
36}
37
39{
40 list_.clear();
41 unsigned i = 0;
42
43 for(const config& user : users) {
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
59 { "player_type_icon", {
60 { "label", icon }
61 }},
62 { "player_name", {
63 { "label", name }
64 }}
65 });
66
67 if(is_you) {
69 }
70
71 ++i;
72 }
73}
74
75} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
boost::iterator_range< const_child_iterator > const_child_itors
Definition config.hpp:281
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:267
void clear()
Removes all the rows in the listbox, clearing it.
Definition listbox.cpp:147
void update_list(const config::const_child_itors &users)
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition window.hpp:59
static prefs & get()
std::string login()
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
#define i