The Battle for Wesnoth  1.15.0-dev
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 "cursor.hpp"
25 #include "display.hpp"
26 #include "filesystem.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/retval.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 namespace preferences {
43 
45 {
46  set_grid(grid());
47  set_turbo(turbo());
49  set_color_cursors(preferences::get("color_cursors", true));
50 }
51 
52 void set_turbo(bool ison)
53 {
54  _set_turbo(ison);
55 
58  }
59 }
60 
61 void set_turbo_speed(double speed)
62 {
63  save_turbo_speed(speed);
64 
67  }
68 }
69 
70 void set_grid(bool ison)
71 {
72  _set_grid(ison);
73 
76  }
77 }
78 
79 void set_color_cursors(bool value)
80 {
81  _set_color_cursors(value);
82 
83  cursor::set();
84 }
85 
86 void set_idle_anim(bool ison) {
87  _set_idle_anim(ison);
88 
91  }
92 }
93 
94 void set_idle_anim_rate(int rate) {
95  _set_idle_anim_rate(rate);
96 
99  }
100 }
101 
103 {
104  return preferences::get("unit_standing_animations", true);
105 }
106 
108 {
109  set("unit_standing_animations", value);
110 
111  if(display* d = display::get_singleton()) {
112  d->reset_standing_animations();
113  }
114 }
115 
117 {
118  std::vector<theme_info> themes = theme::get_known_themes();
119 
120  if (themes.empty()) {
122  _("No known themes. Try changing from within an existing game."));
123 
124  return false;
125  }
126 
127  gui2::dialogs::theme_list dlg(themes);
128 
129  for (std::size_t k = 0; k < themes.size(); ++k) {
130  if(themes[k].id == preferences::theme()) {
131  dlg.set_selected_index(static_cast<int>(k));
132  }
133  }
134 
135  dlg.show();
136  const int action = dlg.selected_index();
137 
138  if (action >= 0) {
139  preferences::set_theme(themes[action].id);
142  }
143 
144  return true;
145  }
146 
147  return false;
148 }
149 
151 {
152 #ifndef _WIN32
153  const std::string filename = "wesnothd";
154 #else // _WIN32
155  const std::string filename = "wesnothd.exe";
156 #endif
157 
159  std::string path =
160  !old_path.empty() && filesystem::is_directory(old_path)
161  ? old_path : filesystem::get_exe_dir();
162 
163  const std::string msg = VGETTEXT(
164  "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}});
165 
167 
168  dlg.set_title(_("Find Server Application"))
169  .set_message(msg)
170  .set_ok_label(_("Select"))
171  .set_read_only(true)
172  .set_filename(filename)
173  .set_path(path);
174 
175  if(dlg.show()) {
176  path = dlg.path();
178  }
179 }
180 
181 } // end namespace preferences
bool show_theme_dialog()
Definition: display.cpp:116
play_controller * controller
Definition: resources.cpp:21
void set_turbo(bool ison)
Definition: display.cpp:52
void _set_turbo(bool ison)
Definition: general.cpp:426
void set_grid(bool ison)
Definition: display.cpp:70
void _set_grid(bool ison)
Definition: general.cpp:512
void set_preference_display_settings()
Definition: display.cpp:44
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:99
void set_show_standing_animations(bool value)
Definition: display.cpp:107
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:173
void set_grid(const bool grid)
Determines whether a grid should be overlayed on the game board.
Definition: display.hpp:395
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
void _set_color_cursors(bool value)
Definition: general.cpp:852
void set_turbo(const bool turbo)
Set/Get whether &#39;turbo&#39; mode is on.
Definition: display.hpp:491
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
void set_idle_anim_rate(int rate)
Definition: display.cpp:1402
void show_wesnothd_server_search()
Definition: display.cpp:150
void save_turbo_speed(const double speed)
Definition: general.cpp:436
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
#define d
bool show(const unsigned auto_close_time=0)
Shows the window.
game_data * gamedata
Definition: resources.cpp:22
std::string path() const
Gets the current file selection.
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:512
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:94
void set_theme(const std::string &theme)
Definition: game.cpp:834
std::string theme()
Definition: game.cpp:819
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:36
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.
void set_turbo_speed(double speed)
Definition: display.cpp:61
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:86
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Definition: filesystem.cpp:984
Modify, read and display user preferences.
bool show_standing_animations()
Definition: display.cpp:102
void set_color_cursors(bool value)
Definition: display.cpp:79
void _set_idle_anim(const bool ison)
Definition: general.cpp:462
std::string get_exe_dir()
Definition: filesystem.cpp:795
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:75
static std::vector< theme_info > get_known_themes()
Definition: theme.cpp:890
Game configuration data as global variables.
Definition: build_info.cpp:46
void set_turbo_speed(const double speed)
Definition: display.hpp:498
Declarations for File-IO.
#define VGETTEXT(msgid,...)
void set_idle_anim(bool ison)
control unit idle animations and their frequency
Definition: display.hpp:504
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 path
File path.
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:173
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
Definition: file_dialog.hpp:56