The Battle for Wesnoth  1.17.0-dev
depcheck_select_new.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2021
3  by Boldizs√°r Lipka <lipkab@zoho.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 
20 #include <vector>
21 
22 
23 namespace gui2::dialogs
24 {
25 
26 /**
27  * @ingroup GUIWindowDefinitionWML
28  *
29  * Offers a list of compatible items if a currently selected one is incompatible. Currently used for switching era or map.
30  * Key |Type |Mandatory|Description
31  * ------------------|--------------|---------|-----------
32  * message | @ref label |yes |displays the details of the required changes
33  * itemlist | @ref listbox |yes |displays the available items to choose from
34  * cancel | @ref button |yes |refuse to apply any changes
35  * ok | @ref button |yes |select the chosen item
36  */
38 {
39 public:
40  /**
41  * Constructor.
42  *
43  * @param name the type of which we want to select a new item
44  * @param options the names of the components which can be chosen
45  */
47  const std::vector<std::string>& options);
48 
49  /**
50  * Returns the selected item.
51  *
52  * @return the index of the selected item, or -1 if none was selected
53  * (the dialog was closed with the cancel button)
54  */
55  int result() const
56  {
57  return result_;
58  }
59 
60 protected:
61  virtual const std::string& window_id() const override;
62 
63  virtual void pre_show(window& window) override;
64 
65  virtual void post_show(window& window) override;
66 
67 private:
68  /** the options available */
69  std::vector<std::string> items_;
70 
71  /** the index of the selected item */
72  int result_;
73 };
74 } // 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:569
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:65