The Battle for Wesnoth  1.19.0-dev
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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"
34 #include "play_controller.hpp"
35 #include "game_data.hpp"
36 #include "resources.hpp"
37 
38 namespace preferences {
39 
40 void set_color_cursors(bool value)
41 {
42  _set_color_cursors(value);
43 
44  cursor::set();
45 }
46 
48 {
49  return preferences::get("unit_standing_animations", true);
50 }
51 
53 {
54  set("unit_standing_animations", value);
55 
57  d->reset_standing_animations();
58  }
59 }
60 
62 {
63  std::vector<theme_info> themes = theme::get_basic_theme_info();
64 
65  if (themes.empty()) {
67  _("No known themes. Try changing from within an existing game."));
68 
69  return false;
70  }
71 
72  gui2::dialogs::theme_list dlg(themes);
73 
74  for (std::size_t k = 0; k < themes.size(); ++k) {
75  if(themes[k].id == preferences::theme()) {
76  dlg.set_selected_index(static_cast<int>(k));
77  }
78  }
79 
80  dlg.show();
81  const int action = dlg.selected_index();
82 
83  if (action >= 0) {
84  preferences::set_theme(themes[action].id);
85  if(display::get_singleton() && resources::gamedata && resources::gamedata->get_theme().empty()) {
86  display::get_singleton()->set_theme(themes[action].id);
87  }
88 
89  return true;
90  }
91 
92  return false;
93 }
94 
96 {
97 #ifndef _WIN32
98  const std::string filename = "wesnothd";
99 #else // _WIN32
100  const std::string filename = "wesnothd.exe";
101 #endif
102 
104  std::string path =
105  !old_path.empty() && filesystem::is_directory(old_path)
106  ? old_path : filesystem::get_exe_dir();
107 
108  const std::string msg = VGETTEXT(
109  "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}});
110 
112 
113  dlg.set_title(_("Find Server Application"))
114  .set_message(msg)
115  .set_ok_label(_("Select"))
116  .set_read_only(true)
117  .set_filename(filename)
118  .set_path(path);
119 
120  if(dlg.show()) {
121  path = dlg.path();
123  }
124 }
125 
126 } // end namespace preferences
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:81
void set_theme(const std::string &new_theme)
Definition: display.cpp:248
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:95
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
Definition: file_dialog.hpp:59
file_dialog & set_read_only(bool value)
Whether to provide user interface elements for manipulating existing objects.
file_dialog & set_filename(const std::string &value)
Sets the initial file name input but not the path.
file_dialog & set_message(const std::string &value)
Sets the current dialog instructions/message text.
Definition: file_dialog.hpp:78
bool show(const unsigned auto_close_time=0)
Shows the window.
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:36
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:45
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:51
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:987
Declarations for File-IO.
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
static std::string _(const char *str)
Definition: gettext.hpp:93
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:176
std::string get_exe_dir()
Definition: filesystem.cpp:990
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
std::string path
Definition: filesystem.cpp:83
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.
Modify, read and display user preferences.
std::string get_mp_server_program_name()
Definition: game.cpp:507
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:498
bool show_theme_dialog()
Definition: display.cpp:61
void set(const std::string &key, bool value)
Definition: general.cpp:165
bool show_standing_animations()
Definition: display.cpp:47
std::string theme()
Definition: game.cpp:798
void set_theme(const std::string &theme)
Definition: game.cpp:813
void set_color_cursors(bool value)
Definition: display.cpp:40
void set_show_standing_animations(bool value)
Definition: display.cpp:52
std::string get(const std::string &key)
Definition: general.cpp:213
void _set_color_cursors(bool value)
Definition: general.cpp:912
void show_wesnothd_server_search()
Definition: display.cpp:95
game_data * gamedata
Definition: resources.cpp:22
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
#define d