1 #ifndef _OptionsWnd_h_
2 #define _OptionsWnd_h_
3 
4 #include <boost/filesystem/path.hpp>
5 #include <GG/GGFwd.h>
6 
7 #include "CUIWnd.h"
8 #include "Sound.h"
9 
10 #include <functional>
11 #include <utility>
12 #include <vector>
13 
14 
15 //! This is a dialog box that allows the user to control certain basic game parameters, such as sound and music
16 class OptionsWnd : public CUIWnd {
17 public:
18     //! \name Structors
19     //!@{
20     OptionsWnd(bool is_game_running_);
21     ~OptionsWnd();
22     void CompleteConstruction() override;
23     //!@}
24 
25     //! \name Mutators
26     //!@{
27     void KeyPress(GG::Key key, std::uint32_t key_code_point, GG::Flags<GG::ModKey> mod_keys) override;
28     void SizeMove(const GG::Pt& ul, const GG::Pt& lr) override;
29     //!@}
30 
31 protected:
32     GG::Rect CalculatePosition() const override;
33 
34 private:
35     /**SoundOptionsFeedback enables immediate player feedback when
36        sound options are changed.*/
37     class SoundOptionsFeedback {
38     public:
SoundOptionsFeedback()39         SoundOptionsFeedback() {}
40 
41         /** Stores a pointer to the sound effects check box.*/
42         void SetEffectsButton(std::shared_ptr<GG::StateButton> button);
43         /** Stores pointer to music enable check box.*/
44         void SetMusicButton(std::shared_ptr<GG::StateButton> button);
45 
46         /**Enables/disables sound effects when the sound effects check
47            box is clicked.*/
48         void SoundEffectsEnableClicked(bool checked);
49         /**Enables/disables background music when the music check
50            box is clicked.*/
51         void MusicClicked(bool checked);
52         /** Adjusts the music volume.*/
53         void MusicVolumeSlid(int pos, int low, int high) const;
54         /** Adjusts the effects volume.*/
55         void UISoundsVolumeSlid(int pos, int low, int high) const;
56         /** Handles a sound initialization failure by setting sound
57             effects and music enable check boxes to disabled and
58             informing the player with a popup message box.*/
59         void SoundInitializationFailure(Sound::InitializationFailureException const &e);
60 
61     private:
62         std::shared_ptr<GG::StateButton> m_effects_button;
63         std::shared_ptr<GG::StateButton> m_music_button;
64     };
65 
66     void                DoLayout();
67 
68     GG::ListBox*        CreatePage(const std::string& name);
69     void                CreateSectionHeader(GG::ListBox* page, int indentation_level,
70                                             const std::string& name, const std::string& tooltip = "");
71     void                HotkeysPage();
72     GG::StateButton*    BoolOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
73     GG::Spin<int>*      IntOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
74     GG::Spin<double>*   DoubleOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
75     void                HotkeyOption(GG::ListBox* page, int indentation_level, const std::string& hotkey_name);
76     void                MusicVolumeOption(GG::ListBox* page, int indentation_level, SoundOptionsFeedback &fb);
77     void                VolumeOption(GG::ListBox* page, int indentation_level, const std::string& toggle_option_name,
78                                      const std::string& volume_option_name, const std::string& text, bool toggle_value,
79                                      SoundOptionsFeedback &fb);
80     void                FileOptionImpl(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text, const boost::filesystem::path& path, const std::vector<std::pair<std::string, std::string>>& filters, std::function<bool (const std::string&)> string_validator, bool directory, bool relative_path, bool disabled);
81     void                FileOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text, const boost::filesystem::path& path, std::function<bool (const std::string&)> string_validator = nullptr);
82     void                FileOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text, const boost::filesystem::path& path, const std::pair<std::string, std::string>& filter, std::function<bool (const std::string&)> string_validator = nullptr);
83     void                FileOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text, const boost::filesystem::path& path, const std::vector<std::pair<std::string, std::string>>& filters, std::function<bool (const std::string&)> string_validator = nullptr);
84     void                DirectoryOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text, const boost::filesystem::path& path, bool disabled = false);
85     void                SoundFileOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
86     void                ColorOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
87     void                FontOption(GG::ListBox* page, int indentation_level, const std::string& option_name, const std::string& text);
88     void                ResolutionOption(GG::ListBox* page, int indentation_level);
89 
90     void                DoneClicked();
91 
92     bool                        is_game_running;
93     std::shared_ptr<GG::TabWnd> m_tabs;
94     std::shared_ptr<GG::Button> m_done_button;
95     SoundOptionsFeedback        m_sound_feedback;   // Enable and disable the sound when audio options are changed.
96 };
97 
98 #endif // _OptionsWnd_h_
99