The Battle for Wesnoth  1.19.7+dev
lobby_player_list_helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <array>
19 #include <functional>
20 #include <map>
21 #include <string>
22 
23 namespace mp
24 {
25 struct user_info;
26 }
27 
28 namespace gui2
29 {
30 class label;
31 class tree_view;
32 class tree_view_node;
33 class window;
34 
36 {
37 public:
38  void init(window& w);
39 
40  /** Updates the tree contents based on the given user data. */
41  void update(const std::vector<mp::user_info>& user_info, int focused_game);
42 
43 private:
44  struct sub_list
45  {
46  sub_list() = default;
47  sub_list(tree_view* parent_tree, const std::string& label, const bool unfolded);
48 
50 
52 
54  };
55 
56  /** Main subsections of the player tree. This should never change at runtime so the number is hardcoded. */
57  std::array<sub_list, 3> player_lists;
58 
59  /** The parent tree. */
61 
62  /** The double click callback bound to each player's tree node. */
63  std::function<void(const mp::user_info*)> user_callback;
64 
65  /** Node-to-info mappings for easy access. */
66  std::map<const tree_view_node*, const mp::user_info*> info_map;
67 
68 public:
70  : player_lists()
71  , tree(nullptr)
72  , user_callback(ucb)
73  , info_map()
74  {
75  }
76 
77  const mp::user_info* get_selected_info() const;
78 };
79 } // namespace gui2
std::map< const tree_view_node *, const mp::user_info * > info_map
Node-to-info mappings for easy access.
lobby_player_list_helper(decltype(user_callback) ucb)
const mp::user_info * get_selected_info() const
std::array< sub_list, 3 > player_lists
Main subsections of the player tree.
void update(const std::vector< mp::user_info > &user_info, int focused_game)
Updates the tree contents based on the given user data.
std::function< void(const mp::user_info *)> user_callback
The double click callback bound to each player's tree node.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
int w
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:200
Generic file dialog.
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:50
This class represents the information a client has about another player.
Definition: lobby_data.hpp:30