The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 /**
18  * @file
19  * Manage display-related preferences, e.g. screen-size, etc.
20  */
21 
22 #include "preferences/display.hpp"
23 
24 #include "display.hpp"
25 #include "filesystem.hpp"
26 #include "formatter.hpp"
27 #include "formula/string_utils.hpp"
28 #include "preferences/game.hpp"
29 #include "gettext.hpp"
31 #include "gui/dialogs/message.hpp"
35 #include "gui/widgets/window.hpp"
36 #include "log.hpp"
37 #include "play_controller.hpp"
38 #include "game_data.hpp"
39 #include "game_config_manager.hpp"
40 #include "resources.hpp"
41 
42 #include <boost/math/common_factor_rt.hpp>
43 
44 namespace preferences {
45 
47 {
48  set_grid(grid());
49  set_turbo(turbo());
51  set_color_cursors(preferences::get("color_cursors", true));
52 }
53 
54 void set_turbo(bool ison)
55 {
56  _set_turbo(ison);
57 
60  }
61 }
62 
63 void set_turbo_speed(double speed)
64 {
65  save_turbo_speed(speed);
66 
69  }
70 }
71 
72 void set_grid(bool ison)
73 {
74  _set_grid(ison);
75 
78  }
79 }
80 
81 void set_color_cursors(bool value)
82 {
83  _set_color_cursors(value);
84 
85  cursor::set();
86 }
87 
88 void set_idle_anim(bool ison) {
89  _set_idle_anim(ison);
90 
93  }
94 }
95 
96 void set_idle_anim_rate(int rate) {
97  _set_idle_anim_rate(rate);
98 
101  }
102 }
103 
105 {
106  return preferences::get("unit_standing_animations", true);
107 }
108 
110 {
111  set("unit_standing_animations", value);
112 
113  if(display* d = display::get_singleton()) {
114  d->reset_standing_animations();
115  }
116 }
117 
119 {
120  std::vector<theme_info> themes = theme::get_known_themes();
121 
122  if (themes.empty()) {
124  _("No known themes. Try changing from within an existing game."));
125 
126  return false;
127  }
128 
129  gui2::dialogs::theme_list dlg(themes);
130 
131  for (size_t k = 0; k < themes.size(); ++k) {
132  if(themes[k].id == preferences::theme()) {
133  dlg.set_selected_index(static_cast<int>(k));
134  }
135  }
136 
137  dlg.show();
138  const int action = dlg.selected_index();
139 
140  if (action >= 0) {
141  preferences::set_theme(themes[action].id);
144  }
145 
146  return true;
147  }
148 
149  return false;
150 }
151 
153 {
154 #ifndef _WIN32
155  const std::string filename = "wesnothd";
156 #else // _WIN32
157  const std::string filename = "wesnothd.exe";
158 #endif
159 
161  std::string path =
162  !old_path.empty() && filesystem::is_directory(old_path)
163  ? old_path : filesystem::get_exe_dir();
164 
165  const std::string msg = vgettext(
166  "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}});
167 
169 
170  dlg.set_title(_("Find Server Application"))
171  .set_message(msg)
172  .set_ok_label(_("Select"))
173  .set_read_only(true)
174  .set_filename(filename)
175  .set_path(path);
176 
177  if(dlg.show()) {
178  path = dlg.path();
180  }
181 }
182 
183 } // end namespace preferences
184 
bool show_theme_dialog()
Definition: display.cpp:118
play_controller * controller
Definition: resources.cpp:21
void set_turbo(bool ison)
Definition: display.cpp:54
void _set_turbo(bool ison)
Definition: general.cpp:426
void set_grid(bool ison)
Definition: display.cpp:72
void _set_grid(bool ison)
Definition: general.cpp:512
void set_preference_display_settings()
Definition: display.cpp:46
std::vector< char_t > string
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:87
void set_show_standing_animations(bool value)
Definition: display.cpp:109
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
void set_grid(const bool grid)
Determines whether a grid should be overlayed on the game board.
Definition: display.hpp:346
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void _set_color_cursors(bool value)
Definition: general.cpp:990
void set_turbo(const bool turbo)
Set/Get whether 'turbo' mode is on.
Definition: display.hpp:480
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
void set_idle_anim_rate(int rate)
Definition: display.cpp:2407
void show_wesnothd_server_search()
Definition: display.cpp:152
This file contains the window object, this object is a top level container which has the event manage...
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:436
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:36
void set(const std::string &key, bool value)
Definition: general.cpp:182
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
double turbo_speed()
Definition: general.cpp:431
std::string path() const
Gets the current file selection.
#define d
bool show(const unsigned auto_close_time=0)
Shows the window.
game_data * gamedata
Definition: resources.cpp:22
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:513
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:42
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
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:230
void set_idle_anim_rate(int rate)
Definition: display.cpp:96
void set_theme(const std::string &theme)
Definition: game.cpp:835
std::string theme()
Definition: game.cpp:820
void set_turbo_speed(double speed)
Definition: display.cpp:63
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:88
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string path
Definition: game_config.cpp:56
Modify, read and display user preferences.
bool show_standing_animations()
Definition: display.cpp:104
void set_color_cursors(bool value)
Definition: display.cpp:81
void _set_idle_anim(const bool ison)
Definition: general.cpp:462
std::string get_exe_dir()
std::string get_mp_server_program_name()
Definition: game.cpp:525
file_dialog & set_message(const std::string &value)
Sets the current dialog instructions/message text.
Definition: file_dialog.hpp:75
static std::vector< theme_info > get_known_themes()
Definition: theme.cpp:891
Game configuration data as global variables.
Definition: build_info.cpp:53
void set_turbo_speed(const double speed)
Definition: display.hpp:484
Declarations for File-IO.
void set_idle_anim(bool ison)
control unit idle animations and their frequency
Definition: display.hpp:487
std::string vgettext(const char *msgid, const utils::string_map &symbols)
bool grid()
Definition: general.cpp:507
Standard logging facilities (interface).
bool turbo()
Definition: general.cpp:417
void _set_idle_anim_rate(const int rate)
Definition: general.cpp:472
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:278
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
Definition: file_dialog.hpp:56