The Battle for Wesnoth  1.17.10+dev
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
3  by David White <dave@whitevine.net>
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 
18 /**
19  * @file
20  * Manage display-related preferences, e.g. screen-size, etc.
21  */
22 
23 #include "preferences/display.hpp"
24 
25 #include "cursor.hpp"
26 #include "display.hpp"
27 #include "filesystem.hpp"
28 #include "formula/string_utils.hpp"
29 #include "preferences/game.hpp"
30 #include "gettext.hpp"
32 #include "gui/dialogs/message.hpp"
36 #include "gui/widgets/retval.hpp"
37 #include "log.hpp"
38 #include "play_controller.hpp"
39 #include "game_data.hpp"
40 #include "resources.hpp"
41 
42 namespace preferences {
43 
44 void set_color_cursors(bool value)
45 {
46  _set_color_cursors(value);
47 
48  cursor::set();
49 }
50 
52 {
53  return preferences::get("unit_standing_animations", true);
54 }
55 
57 {
58  set("unit_standing_animations", value);
59 
61  d->reset_standing_animations();
62  }
63 }
64 
66 {
67  std::vector<theme_info> themes = theme::get_basic_theme_info();
68 
69  if (themes.empty()) {
71  _("No known themes. Try changing from within an existing game."));
72 
73  return false;
74  }
75 
76  gui2::dialogs::theme_list dlg(themes);
77 
78  for (std::size_t k = 0; k < themes.size(); ++k) {
79  if(themes[k].id == preferences::theme()) {
80  dlg.set_selected_index(static_cast<int>(k));
81  }
82  }
83 
84  dlg.show();
85  const int action = dlg.selected_index();
86 
87  if (action >= 0) {
88  preferences::set_theme(themes[action].id);
89  if(display::get_singleton() && resources::gamedata && resources::gamedata->get_theme().empty()) {
90  display::get_singleton()->set_theme(themes[action].id);
91  }
92 
93  return true;
94  }
95 
96  return false;
97 }
98 
100 {
101 #ifndef _WIN32
102  const std::string filename = "wesnothd";
103 #else // _WIN32
104  const std::string filename = "wesnothd.exe";
105 #endif
106 
108  std::string path =
109  !old_path.empty() && filesystem::is_directory(old_path)
110  ? old_path : filesystem::get_exe_dir();
111 
112  const std::string msg = VGETTEXT(
113  "The <b>$filename</b> server application provides multiplayer server functionality and is required for hosting local network games. It will normally be found in the same folder as the game executable.", {{"filename", filename}});
114 
116 
117  dlg.set_title(_("Find Server Application"))
118  .set_message(msg)
119  .set_ok_label(_("Select"))
120  .set_read_only(true)
121  .set_filename(filename)
122  .set_path(path);
123 
124  if(dlg.show()) {
125  path = dlg.path();
127  }
128 }
129 
130 } // end namespace preferences
bool show_theme_dialog()
Definition: display.cpp:65
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:35
static std::vector< theme_info > get_basic_theme_info(bool include_hidden=false)
Returns minimal info about saved themes, optionally including hidden ones.
Definition: theme.cpp:988
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:98
void set_show_standing_animations(bool value)
Definition: display.cpp:56
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:176
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void _set_color_cursors(bool value)
Definition: general.cpp:923
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
void show_wesnothd_server_search()
Definition: display.cpp:99
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
#define d
static std::string _(const char *str)
Definition: gettext.hpp:93
bool show(const unsigned auto_close_time=0)
Shows the window.
game_data * gamedata
Definition: resources.cpp:23
std::string path() const
Gets the current file selection.
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:502
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:51
file_dialog & set_read_only(bool value)
Whether to provide user interface elements for manipulating existing objects.
std::string get(const std::string &key)
Definition: general.cpp:213
void set_theme(const std::string &theme)
Definition: game.cpp:817
std::string theme()
Definition: game.cpp:802
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:45
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
file_dialog & set_filename(const std::string &value)
Sets the initial file name input but not the path.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string path
Definition: game_config.cpp:39
Modify, read and display user preferences.
bool show_standing_animations()
Definition: display.cpp:51
void set_color_cursors(bool value)
Definition: display.cpp:44
void set_theme(const std::string &new_theme)
Definition: display.cpp:272
std::string get_exe_dir()
Definition: filesystem.cpp:927
std::string get_mp_server_program_name()
Definition: game.cpp:511
file_dialog & set_message(const std::string &value)
Sets the current dialog instructions/message text.
Definition: file_dialog.hpp:76
Declarations for File-IO.
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
Standard logging facilities (interface).
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
Definition: file_dialog.hpp:57