1 #ifndef _GalaxySetupWnd_h_ 2 #define _GalaxySetupWnd_h_ 3 4 #include <GG/GGFwd.h> 5 #include <GG/ListBox.h> 6 7 #include "../universe/Universe.h" 8 #include "ClientUI.h" 9 #include "CUIWnd.h" 10 11 class EmpireColorSelector; 12 class SpeciesSelector; 13 struct GalaxySetupData; 14 class CUIEdit; 15 16 /** Displays game rules options */ 17 class GameRulesPanel : public GG::Control { 18 public: 19 /** \name Structors*/ //!@{ 20 GameRulesPanel(GG::X w = GG::X1, GG::Y h = GG::Y1); 21 //!@} 22 void CompleteConstruction() override; 23 24 /** \name Accessors*/ //!@{ 25 std::map<std::string, std::string> GetRulesAsStrings() const; 26 //!@} 27 28 mutable boost::signals2::signal<void ()> SettingsChangedSignal; 29 30 /** \name Mutators*/ //!@{ 31 void SizeMove(const GG::Pt& ul, const GG::Pt& lr) override; 32 void Render() override; 33 void Disable(bool b = true) override; 34 //!@} 35 36 private: 37 void DoLayout(); 38 void SettingChanged(); 39 40 GG::ListBox* CreatePage(const std::string& name); 41 void CreateSectionHeader(GG::ListBox* page, int indentation_level, 42 const std::string& name, const std::string& tooltip = ""); 43 GG::StateButton* BoolRuleWidget(GG::ListBox* page, int indentation_level, 44 const std::string& rule_name); 45 GG::Spin<int>* IntRuleWidget(GG::ListBox* page, int indentation_level, 46 const std::string& rule_name); 47 GG::Spin<double>* DoubleRuleWidget(GG::ListBox* page, int indentation_level, 48 const std::string& rule_name); 49 GG::DropDownList* StringRuleWidget(GG::ListBox* page, int indentation_level, 50 const std::string& rule_name); 51 52 void BoolRuleChanged(const GG::StateButton* button, const std::string& rule_name); 53 void IntRuleChanged(const GG::Spin<int>* spin, const std::string& rule_name); 54 void DoubleRuleChanged(const GG::Spin<double>* spin, const std::string& rule_name); 55 void StringRuleChanged(const GG::DropDownList* drop, const std::string& rule_name); 56 57 std::map<std::string, std::string> m_rules; 58 std::shared_ptr<GG::TabWnd> m_tabs; 59 }; 60 61 /** Encapsulates the galaxy setup options so that they may be reused in the 62 * GalaxySetupWnd and the MultiPlayerLobbyWnd. */ 63 class GalaxySetupPanel : public GG::Control { 64 public: 65 static const GG::X DefaultWidth(); 66 67 /** \name Structors*/ //!@{ 68 GalaxySetupPanel(GG::X w = GG::X(FontBasedUpscale(305)), GG::Y h = GG::Y(330)); 69 //!@} 70 71 void CompleteConstruction() override; 72 73 /** \name Accessors*/ //!@{ 74 const std::string& GetSeed() const; //!< Returns string version of seed. This value is converted to a number or (if that fails) hashed to get the actual seed value. 75 int Systems() const; //!< Returns the number of star systems to use in generating the galaxy 76 Shape GetShape() const; //!< Returns the shape of the galaxy 77 GalaxySetupOption GetAge() const; //!< Returns the age of the galaxy 78 GalaxySetupOption GetStarlaneFrequency() const; //!< Returns the frequency of starlanes in the galaxy 79 GalaxySetupOption GetPlanetDensity() const; //!< Returns the density of planets within systems 80 GalaxySetupOption GetSpecialsFrequency() const; //!< Returns the rarity of planetary and system specials 81 GalaxySetupOption GetMonsterFrequency() const; //!< Returns the frequency of space monsters 82 GalaxySetupOption GetNativeFrequency() const; //!< Returns the frequency of natives 83 Aggression GetAIAggression() const; //!< Returns the maximum AI aggression level 84 85 /** Returns the current preview image texture. */ 86 std::shared_ptr<GG::Texture> PreviewImage() const; 87 88 /** the settings changed signal object for this GalaxySetupPanel */ 89 mutable boost::signals2::signal<void ()> SettingsChangedSignal; 90 91 /** the image changed signal object for this GalaxySetupPanel */ 92 mutable boost::signals2::signal<void (std::shared_ptr<GG::Texture>)> ImageChangedSignal; 93 //!@} 94 95 /** \name Mutators*/ //!@{ 96 void SizeMove(const GG::Pt& ul, const GG::Pt& lr) override; Render()97 void Render() override {} 98 void Disable(bool b = true) override; 99 void SetFromSetupData(const GalaxySetupData& setup_data); ///< sets the controls from a GalaxySetupData 100 void GetSetupData(GalaxySetupData& setup_data) const; ///< fills values in \a setup_data from the panel's current state 101 void SetSeed(const std::string& seed, bool inhibit_single = false); 102 //!@} 103 104 private: 105 void DoLayout(); 106 void RandomClicked(); 107 void SettingChanged(); 108 void ShapeChanged(GG::ListBox::iterator it); 109 110 std::shared_ptr<GG::Label> m_seed_label; 111 std::shared_ptr<CUIEdit> m_seed_edit; //!< The seed used in the generation of the galaxy; 112 std::string m_seed; 113 std::shared_ptr<GG::Button> m_random; //!< Random seed button; 114 std::shared_ptr<GG::Label> m_stars_label; 115 std::shared_ptr<GG::Spin<int>> m_stars_spin; //!< The number of stars to include in the galaxy; 116 std::shared_ptr<GG::Label> m_galaxy_shapes_label; 117 std::shared_ptr<GG::DropDownList> m_galaxy_shapes_list; //!< The possible shapes for the galaxy; 118 std::shared_ptr<GG::Label> m_galaxy_ages_label; 119 std::shared_ptr<GG::DropDownList> m_galaxy_ages_list; //!< The possible ages for the galaxy; 120 std::shared_ptr<GG::Label> m_starlane_freq_label; 121 std::shared_ptr<GG::DropDownList> m_starlane_freq_list; //!< The frequency of starlanes in the galaxy; 122 std::shared_ptr<GG::Label> m_planet_density_label; 123 std::shared_ptr<GG::DropDownList> m_planet_density_list; //!< The density of planets in each system; 124 std::shared_ptr<GG::Label> m_specials_freq_label; 125 std::shared_ptr<GG::DropDownList> m_specials_freq_list; //!< The frequency of specials in systems and on planets; 126 std::shared_ptr<GG::Label> m_monster_freq_label; 127 std::shared_ptr<GG::DropDownList> m_monster_freq_list; //!< The frequency of monsters; 128 std::shared_ptr<GG::Label> m_native_freq_label; 129 std::shared_ptr<GG::DropDownList> m_native_freq_list; //!< The frequency of natives; 130 std::shared_ptr<GG::Label> m_ai_aggression_label; 131 std::shared_ptr<GG::DropDownList> m_ai_aggression_list; //!< The max aggression choices for AI opponents; 132 133 /** Textures for galaxy previews. */ 134 std::vector<std::shared_ptr<GG::Texture>> m_textures; 135 }; 136 137 //! This class is the Galaxy Setup window. It is a modal window 138 //! that allows the user to choose a galaxy style, size, etc. 139 class GalaxySetupWnd : public CUIWnd { 140 public: 141 /** \name Structors*/ //!@{ 142 GalaxySetupWnd(); 143 void CompleteConstruction() override; 144 //!@} 145 146 /** \name Accessors*/ //!@{ 147 /** returns true iff the dialog is finished running and it was closed with the "OK" button */ EndedWithOk()148 bool EndedWithOk() const {return m_done && m_ended_with_ok;} 149 150 /** returns the panel containing all the user-chosen options. */ 151 const std::string& EmpireName() const; 152 GG::Clr EmpireColor() const; 153 const std::string& StartingSpeciesName() const; 154 int NumberAIs() const; 155 std::map<std::string, std::string> 156 GetRulesAsStrings() const; 157 //!@} 158 159 /** \name Mutators*/ //!@{ 160 void Render() override; 161 void KeyPress(GG::Key key, std::uint32_t key_code_point, GG::Flags<GG::ModKey> mod_keys) override; 162 void SizeMove(const GG::Pt& ul, const GG::Pt& lr) override; 163 //!@} 164 165 protected: 166 GG::Rect CalculatePosition() const override; 167 168 private: 169 void DoLayout(); 170 void PreviewImageChanged(std::shared_ptr<GG::Texture> new_image); 171 void EmpireNameChanged(const std::string& name); 172 void PlayerNameChanged(const std::string& name); 173 void OkClicked(); 174 void CancelClicked(); 175 176 bool m_ended_with_ok = false; //!< indicates whether or not we ended the dialog with OK or not 177 178 std::shared_ptr<GalaxySetupPanel> m_galaxy_setup_panel; //!< The GalaxySetupPanel that does most of the work of the dialog 179 std::shared_ptr<GameRulesPanel> m_game_rules_panel; 180 std::shared_ptr<GG::Label> m_player_name_label; 181 std::shared_ptr<GG::Edit> m_player_name_edit; 182 std::shared_ptr<GG::Label> m_empire_name_label; 183 std::shared_ptr<GG::Edit> m_empire_name_edit; 184 std::shared_ptr<GG::Label> m_empire_color_label; 185 std::shared_ptr<EmpireColorSelector> m_empire_color_selector; 186 std::shared_ptr<SpeciesSelector> m_starting_secies_selector; 187 std::shared_ptr<GG::Label> m_starting_species_label; 188 std::shared_ptr<GG::Label> m_number_ais_label; 189 std::shared_ptr<GG::Spin<int>> m_number_ais_spin; 190 std::shared_ptr<GG::StaticGraphic> m_preview_image; //!< The galaxy shape preview image; 191 std::shared_ptr<GG::Button> m_ok; //!< OK button; 192 std::shared_ptr<GG::Button> m_cancel; //!< Cancel button; 193 194 GG::Pt m_preview_ul; 195 }; 196 197 #endif // _GalaxySetupWnd_h_ 198