The Battle for Wesnoth  1.19.0-dev
depcheck_select_new.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2024
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 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
21 #include "gui/widgets/window.hpp"
22 #include "gui/widgets/listbox.hpp"
23 #include "gettext.hpp"
24 
25 namespace gui2::dialogs
26 {
27 
28 REGISTER_DIALOG(depcheck_select_new)
29 
31  ng::depcheck::component_type name,
32  const std::vector<std::string>& items)
33  : modal_dialog(window_id())
34  , items_(items)
35  , result_(-1)
36 {
37  std::string message;
38 
39  switch(name) {
41  message = _("The currently chosen scenario "
42  "is not compatible with your setup."
43  "\nPlease select a compatible one.");
44  break;
45  case ng::depcheck::ERA:
46  message = _("The currently chosen era "
47  "is not compatible with your setup."
48  "\nPlease select a compatible one.");
49  break;
51  // currently this can't happen, but be prepared for anything...
52  message = _("The currently chosen modification "
53  "is not compatible with your setup."
54  "\nPlease select a compatible one.");
55  }
56 
57  register_label("message", false, message);
58 }
59 
61 {
62  listbox& items = find_widget<listbox>(&window, "itemlist", false);
63 
64  for(const auto & item : items_)
65  {
67  data["option"]["label"] = item;
68 
69  items.add_row(data);
70  }
71 
72  items.select_row(0);
73 }
74 
76 {
77  if(get_retval() == retval::OK) {
78  listbox& items = find_widget<listbox>(&window, "itemlist", false);
79  result_ = items.get_selected_row();
80  }
81 }
82 } // namespace dialogs
Offers a list of compatible items if a currently selected one is incompatible.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
int result_
the index of the selected item
std::vector< std::string > items_
the options available
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Main class to show messages to the user.
Definition: message.hpp:36
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
The listbox class.
Definition: listbox.hpp:43
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(tod_new_schedule)
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:34
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:412
const std::vector< std::string > items
std::string_view data
Definition: picture.cpp:194