The Battle for Wesnoth  1.17.0-dev
depcheck_select_new.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2018 by Boldizs√°r Lipka <lipkab@zoho.com>
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 
15 #pragma once
16 
19 #include <vector>
20 
21 
22 namespace gui2::dialogs
23 {
24 
25 /**
26  * @ingroup GUIWindowDefinitionWML
27  *
28  * Offers a list of compatible items if a currently selected one is incompatible. Currently used for switching era or map.
29  * Key |Type |Mandatory|Description
30  * ------------------|--------------|---------|-----------
31  * message | @ref label |yes |displays the details of the required changes
32  * itemlist | @ref listbox |yes |displays the available items to choose from
33  * cancel | @ref button |yes |refuse to apply any changes
34  * ok | @ref button |yes |select the chosen item
35  */
37 {
38 public:
39  /**
40  * Constructor.
41  *
42  * @param name the type of which we want to select a new item
43  * @param options the names of the components which can be chosen
44  */
46  const std::vector<std::string>& options);
47 
48  /**
49  * Returns the selected item.
50  *
51  * @return the index of the selected item, or -1 if none was selected
52  * (the dialog was closed with the cancel button)
53  */
54  int result() const
55  {
56  return result_;
57  }
58 
59 protected:
60  virtual const std::string& window_id() const override;
61 
62  virtual void pre_show(window& window) override;
63 
64  virtual void post_show(window& window) override;
65 
66 private:
67  /** the options available */
68  std::vector<std::string> items_;
69 
70  /** the index of the selected item */
71  int result_;
72 };
73 } // namespace dialogs
int result_
the index of the selected item
depcheck_select_new(ng::depcheck::component_type name, const std::vector< std::string > &options)
Constructor.
const config & options()
Definition: game.cpp:568
std::vector< std::string > items_
the options available
int result() const
Returns the selected item.
Offers a list of compatible items if a currently selected one is incompatible.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Abstract base class for all modal dialogs.
virtual const std::string & window_id() const override
The id of the window to build.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64