-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
addon_list.hpp
205 lines (159 loc) · 5.41 KB
/
addon_list.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
Copyright (C) 2016 - 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "addon/info.hpp"
#include "addon/manager.hpp"
#include "addon/state.hpp"
#include "gui/widgets/container_base.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/widget.hpp"
#include <boost/dynamic_bitset.hpp>
#include <functional>
#include <string>
#include <vector>
namespace gui2
{
namespace implementation
{
struct builder_addon_list;
}
class addon_list : public container_base
{
friend struct implementation::builder_addon_list;
public:
explicit addon_list(const implementation::builder_addon_list& builder);
/** Special retval for the toggle panels in the addons list */
static const int DEFAULT_ACTION_RETVAL = 200;
/** Sets the add-ons to show. */
void set_addons(const addons_list& addons);
/** Sets up a callback that will be called when the player selects an add-on. */
void set_callback_value_change(const std::function<void(widget&)>& callback)
{
get_listbox().set_callback_value_change(callback);
}
/** Returns the selected add-on. */
const addon_info* get_selected_addon() const;
/** Returns the selected add-on id, for use with remote publish/delete ops. */
std::string get_remote_addon_id();
/** Selects the add-on with the given ID. */
void select_addon(const std::string& id);
/** Sets the function to call when the player clicks the install button. */
void set_install_function(std::function<void(const addon_info&)> function)
{
install_function_ = function;
}
/** Sets the function to call when the player clicks the uninstall button. */
void set_uninstall_function(std::function<void(const addon_info&)> function)
{
uninstall_function_ = function;
}
/** Sets the function to call when the player clicks the update button. */
void set_update_function(std::function<void(const addon_info&)> function)
{
update_function_ = function;
}
/** Sets the function to upload an addon to the addons server. */
void set_publish_function(std::function<void(const addon_info&)> function)
{
publish_function_ = function;
}
/** Sets the function to install an addon from the addons server. */
void set_delete_function(std::function<void(const addon_info&)> function)
{
delete_function_ = function;
}
/** Filters which add-ons are visible. 1 = visible, 0 = hidden. */
void set_addon_shown(boost::dynamic_bitset<>& shown)
{
get_listbox().set_row_shown(shown);
}
/**
* Changes the color of an add-on state string (installed, outdated, etc.) according to the state itself.
* This function is here because the add-on list widget itself needs it.
*/
static std::string colorify_addon_state_string(const std::string& str, ADDON_STATUS state, bool verbose = false);
/** Determines if install status of each widget is shown. */
void set_install_status_visibility(visibility visibility)
{
install_status_visibility_ = visibility;
}
/** Determines if install/uninstall buttons are shown for each widget. */
void set_install_buttons_visibility(visibility visibility)
{
install_buttons_visibility_ = visibility;
}
/** Adds the internal listbox to the keyboard event chain. */
void add_list_to_keyboard_chain();
/** See @ref styled_widget::set_active. */
virtual void set_active(const bool) override
{
// DO NOTHING
}
/** See @ref styled_widget::get_active. */
virtual bool get_active() const override
{
return true;
}
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override
{
return 0;
}
private:
std::vector<const addon_info*> addon_vector_;
visibility install_status_visibility_;
visibility install_buttons_visibility_;
std::function<void(const addon_info&)> install_function_;
std::function<void(const addon_info&)> uninstall_function_;
std::function<void(const addon_info&)> update_function_;
std::function<void(const addon_info&)> publish_function_;
std::function<void(const addon_info&)> delete_function_;
static std::string describe_status(const addon_tracking_info& info);
/** Returns the underlying list box. */
listbox& get_listbox();
void finalize_setup();
/** Needed because otherwise the add-on with the first ID would be initially selected. */
void select_first_addon();
/** See @ref control::get_control_type. */
const std::string& get_control_type() const override
{
static const std::string control_type = "addon_list";
return control_type;
}
/** See @ref container_::set_self_active. */
void set_self_active(const bool) override
{
// DO NOTHING
}
};
struct addon_list_definition : public styled_widget_definition
{
explicit addon_list_definition(const config& cfg);
struct resolution : public resolution_definition
{
explicit resolution(const config& cfg);
builder_grid_ptr grid;
};
};
namespace implementation
{
struct builder_addon_list : public builder_styled_widget
{
public:
explicit builder_addon_list(const config& cfg);
using builder_styled_widget::build;
widget* build() const;
private:
widget::visibility install_status_visibility_;
widget::visibility install_buttons_visibility_;
};
}
}