The Battle for Wesnoth  1.17.0-dev
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 "game_config_manager.hpp"
41 #include "resources.hpp"
42 
43 namespace preferences {
44 
46 {
47  set_grid(grid());
48  set_turbo(turbo());
50  set_color_cursors(preferences::get("color_cursors", true));
51 }
52 
53 void set_turbo(bool ison)
54 {
55  _set_turbo(ison);
56 
59  }
60 }
61 
62 void set_turbo_speed(double speed)
63 {
64  save_turbo_speed(speed);
65 
68  }
69 }
70 
71 void set_grid(bool ison)
72 {
73  _set_grid(ison);
74 
77  }
78 }
79 
80 void set_color_cursors(bool value)
81 {
82  _set_color_cursors(value);
83 
84  cursor::set();
85 }
86 
87 void set_idle_anim(bool ison) {
88  _set_idle_anim(ison);
89 
92  }
93 }
94 
95 void set_idle_anim_rate(int rate) {
96  _set_idle_anim_rate(rate);
97 
100  }
101 }
102 
104 {
105  return preferences::get("unit_standing_animations", true);
106 }
107 
109 {
110  set("unit_standing_animations", value);
111 
112  if(display* d = display::get_singleton()) {
113  d->reset_standing_animations();
114  }
115 }
116 
118 {
119  std::vector<theme_info> themes = theme::get_known_themes();
120 
121  if (themes.empty()) {
123  _("No known themes. Try changing from within an existing game."));
124 
125  return false;
126  }
127 
128  gui2::dialogs::theme_list dlg(themes);
129 
130  for (std::size_t k = 0; k < themes.size(); ++k) {
131  if(themes[k].id == preferences::theme()) {
132  dlg.set_selected_index(static_cast<int>(k));
133  }
134  }
135 
136  dlg.show();
137  const int action = dlg.selected_index();
138 
139  if (action >= 0) {
140  preferences::set_theme(themes[action].id);
143  }
144 
145  return true;
146  }
147 
148  return false;
149 }
150 
152 {
153 #ifndef _WIN32
154  const std::string filename = "wesnothd";
155 #else // _WIN32
156  const std::string filename = "wesnothd.exe";
157 #endif
158 
160  std::string path =
161  !old_path.empty() && filesystem::is_directory(old_path)
162  ? old_path : filesystem::get_exe_dir();
163 
164  const std::string msg = VGETTEXT(
165  "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}});
166 
168 
169  dlg.set_title(_("Find Server Application"))
170  .set_message(msg)
171  .set_ok_label(_("Select"))
172  .set_read_only(true)
173  .set_filename(filename)
174  .set_path(path);
175 
176  if(dlg.show()) {
177  path = dlg.path();
179  }
180 }
181 
182 } // end namespace preferences
bool show_theme_dialog()
Definition: display.cpp:117
play_controller * controller
Definition: resources.cpp:22
void set_turbo(bool ison)
Definition: display.cpp:53
void _set_turbo(bool ison)
Definition: general.cpp:454
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:35
void set_grid(bool ison)
Definition: display.cpp:71
void _set_grid(bool ison)
Definition: general.cpp:540
void set_preference_display_settings()
Definition: display.cpp:45
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:92
void set_show_standing_animations(bool value)
Definition: display.cpp:108
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:176
void set_grid(const bool grid)
Determines whether a grid should be overlayed on the game board.
Definition: display.hpp:355
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void _set_color_cursors(bool value)
Definition: general.cpp:890
void set_turbo(const bool turbo)
Set/Get whether &#39;turbo&#39; mode is on.
Definition: display.hpp:489
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
void set_idle_anim_rate(int rate)
Definition: display.cpp:2414
void show_wesnothd_server_search()
Definition: display.cpp:151
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, const bool restore_background)
Shows a transient message to the user.
void save_turbo_speed(const double speed)
Definition: general.cpp:464
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
double turbo_speed()
Definition: general.cpp:459
#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:515
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:51
static game_config_manager * get()
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:209
void set_idle_anim_rate(int rate)
Definition: display.cpp:95
void set_theme(const std::string &theme)
Definition: game.cpp:830
std::string theme()
Definition: game.cpp:815
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:45
void set_turbo_speed(double speed)
Definition: display.cpp:62
file_dialog & set_filename(const std::string &value)
Sets the initial file name input but not the path.
void set_idle_anim(bool ison)
Definition: display.cpp:87
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:103
void set_color_cursors(bool value)
Definition: display.cpp:80
void _set_idle_anim(const bool ison)
Definition: general.cpp:490
std::string get_exe_dir()
Definition: filesystem.cpp:907
std::string get_mp_server_program_name()
Definition: game.cpp:524
file_dialog & set_message(const std::string &value)
Sets the current dialog instructions/message text.
Definition: file_dialog.hpp:76
static std::vector< theme_info > get_known_themes()
Definition: theme.cpp:935
Game configuration data as global variables.
Definition: build_info.cpp:59
void set_turbo_speed(const double speed)
Definition: display.hpp:493
Declarations for File-IO.
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
void set_idle_anim(bool ison)
control unit idle animations and their frequency
Definition: display.hpp:496
bool grid()
Definition: general.cpp:535
Standard logging facilities (interface).
bool turbo()
Definition: general.cpp:445
void _set_idle_anim_rate(const int rate)
Definition: general.cpp:500
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
void set_theme(config theme_cfg)
Definition: display.cpp:297
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
Definition: file_dialog.hpp:57