added 'Advanced' preferences section
This commit is contained in:
parent
c9fd93b08e
commit
b07008c34d
9 changed files with 147 additions and 39 deletions
|
@ -1,5 +1,6 @@
|
|||
CVS HEAD:
|
||||
* user interface improvements:
|
||||
* added 'Advanced' preferences section with 'binary save files' and 'show combat' as initial options
|
||||
* fix editor file chooser when starting directory has many files (#11698)
|
||||
* made it so network dialogs show progress of data transfers again
|
||||
* starting position in editor now starts at player 1 (#10625)
|
||||
|
|
BIN
images/icons/icon-advanced.png
Normal file
BIN
images/icons/icon-advanced.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
15
src/game.cpp
15
src/game.cpp
|
@ -102,6 +102,8 @@ public:
|
|||
bool play_multiplayer();
|
||||
bool change_language();
|
||||
|
||||
void show_preferences();
|
||||
|
||||
enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
|
||||
void play_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
|
||||
|
||||
|
@ -1173,6 +1175,14 @@ bool game_controller::change_language()
|
|||
return false;
|
||||
}
|
||||
|
||||
void game_controller::show_preferences()
|
||||
{
|
||||
const preferences::display_manager disp_manager(&disp());
|
||||
preferences::show_preferences_dialog(disp(),game_config_);
|
||||
|
||||
disp().redraw_everything();
|
||||
}
|
||||
|
||||
//this function reads the game configuration, searching for valid cached copies first
|
||||
void game_controller::read_game_cfg(preproc_map& defines, config& cfg, bool use_cache)
|
||||
{
|
||||
|
@ -1564,10 +1574,7 @@ int play_game(int argc, char** argv)
|
|||
continue;
|
||||
}
|
||||
} else if(res == gui::EDIT_PREFERENCES) {
|
||||
const preferences::display_manager disp_manager(&game.disp());
|
||||
preferences::show_preferences_dialog(game.disp());
|
||||
|
||||
game.disp().redraw_everything();
|
||||
game.show_preferences();
|
||||
continue;
|
||||
} else if(res == gui::SHOW_ABOUT) {
|
||||
about::show_about(game.disp());
|
||||
|
|
|
@ -2123,7 +2123,7 @@ void turn_info::change_unit_side()
|
|||
|
||||
void turn_info::preferences()
|
||||
{
|
||||
preferences::show_preferences_dialog(gui_);
|
||||
preferences::show_preferences_dialog(gui_,terrain_config_);
|
||||
gui_.redraw_everything();
|
||||
}
|
||||
|
||||
|
|
|
@ -791,7 +791,7 @@ namespace {
|
|||
class preferences_dialog : public gui::preview_pane
|
||||
{
|
||||
public:
|
||||
preferences_dialog(display& disp);
|
||||
preferences_dialog(display& disp, const config& game_cfg);
|
||||
|
||||
struct video_mode_change_exception
|
||||
{
|
||||
|
@ -809,22 +809,28 @@ private:
|
|||
bool left_side() const { return false; }
|
||||
void set_selection(int index);
|
||||
void update_location(SDL_Rect const &rect);
|
||||
const config* get_advanced_pref() const;
|
||||
void set_advanced_menu();
|
||||
|
||||
gui::slider music_slider_, sound_slider_, scroll_slider_, gamma_slider_;
|
||||
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
|
||||
show_grid_button_, show_floating_labels_button_, turn_dialog_button_,
|
||||
turn_bell_button_, show_team_colours_button_, show_colour_cursors_button_,
|
||||
show_haloing_button_, video_mode_button_, hotkeys_button_, gamma_button_,
|
||||
flip_time_button_;
|
||||
flip_time_button_, advanced_button_;
|
||||
gui::label music_label_, sound_label_, scroll_label_, gamma_label_;
|
||||
unsigned slider_label_width_;
|
||||
|
||||
enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB };
|
||||
gui::menu advanced_;
|
||||
int advanced_selection_;
|
||||
|
||||
enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, ADVANCED_TAB };
|
||||
TAB tab_;
|
||||
display &disp_;
|
||||
const config& game_cfg_;
|
||||
};
|
||||
|
||||
preferences_dialog::preferences_dialog(display& disp)
|
||||
preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
|
||||
: gui::preview_pane(disp.video()),
|
||||
music_slider_(disp.video()), sound_slider_(disp.video()),
|
||||
scroll_slider_(disp.video()), gamma_slider_(disp.video()),
|
||||
|
@ -842,9 +848,11 @@ preferences_dialog::preferences_dialog(display& disp)
|
|||
hotkeys_button_(disp.video(), _("Hotkeys")),
|
||||
gamma_button_(disp.video(), _("Adjust Gamma"), gui::button::TYPE_CHECK),
|
||||
flip_time_button_(disp.video(), _("Reverse Time Graphics"), gui::button::TYPE_CHECK),
|
||||
advanced_button_(disp.video(), "", gui::button::TYPE_CHECK),
|
||||
music_label_(disp.video(), _("Music Volume:")), sound_label_(disp.video(), _("SFX Volume:")),
|
||||
scroll_label_(disp.video(), _("Scroll Speed:")), gamma_label_(disp.video(), _("Gamma:")),
|
||||
slider_label_width_(0), tab_(GENERAL_TAB), disp_(disp)
|
||||
slider_label_width_(0), advanced_(disp.video(),std::vector<std::string>()), advanced_selection_(-1),
|
||||
tab_(GENERAL_TAB), disp_(disp), game_cfg_(game_cfg)
|
||||
{
|
||||
// FIXME: this box should be vertically centered on the screen, but is not
|
||||
#if USE_TINY_GUI
|
||||
|
@ -917,6 +925,8 @@ preferences_dialog::preferences_dialog(display& disp)
|
|||
show_haloing_button_.set_help_string(_("Use graphical special effects (may be slower)"));
|
||||
|
||||
hotkeys_button_.set_help_string(_("View and configure keyboard shortcuts"));
|
||||
|
||||
set_advanced_menu();
|
||||
}
|
||||
|
||||
void preferences_dialog::update_location(SDL_Rect const &rect)
|
||||
|
@ -971,6 +981,15 @@ void preferences_dialog::update_location(SDL_Rect const &rect)
|
|||
rect.w - slider_label_width_ - border, 0 };
|
||||
sound_slider_.set_location(sound_rect);
|
||||
|
||||
//Advanced tab
|
||||
ypos = rect.y;
|
||||
advanced_.set_location(rect.x,ypos);
|
||||
advanced_.set_max_height(height()-100);
|
||||
|
||||
ypos += advanced_.height() + border;
|
||||
|
||||
advanced_button_.set_location(rect.x,ypos);
|
||||
|
||||
set_selection(tab_);
|
||||
}
|
||||
|
||||
|
@ -1014,6 +1033,64 @@ void preferences_dialog::process_event()
|
|||
set_music_volume(music_slider_.value());
|
||||
set_scroll_speed(scroll_slider_.value());
|
||||
set_gamma(gamma_slider_.value());
|
||||
|
||||
if(advanced_.selection() != advanced_selection_) {
|
||||
advanced_selection_ = advanced_.selection();
|
||||
const config* const adv = get_advanced_pref();
|
||||
if(adv != NULL) {
|
||||
const config& pref = *adv;
|
||||
advanced_button_.set_label(pref["name"]);
|
||||
std::string value = prefs[pref["field"]];
|
||||
if(value.empty()) {
|
||||
value = pref["default"];
|
||||
}
|
||||
|
||||
advanced_button_.set_check(value == "yes");
|
||||
}
|
||||
}
|
||||
|
||||
if(advanced_button_.pressed()) {
|
||||
const config* const adv = get_advanced_pref();
|
||||
if(adv != NULL) {
|
||||
const config& pref = *adv;
|
||||
prefs[pref["field"]] = advanced_button_.checked() ? "yes" : "no";
|
||||
set_advanced_menu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const config* preferences_dialog::get_advanced_pref() const
|
||||
{
|
||||
const config::child_list& adv = game_cfg_.get_children("advanced_preference");
|
||||
if(advanced_selection_ >= 0 && advanced_selection_ < int(adv.size())) {
|
||||
return adv[advanced_selection_];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void preferences_dialog::set_advanced_menu()
|
||||
{
|
||||
std::vector<std::string> advanced_items;
|
||||
const config::child_list& adv = game_cfg_.get_children("advanced_preference");
|
||||
for(config::child_list::const_iterator i = adv.begin(); i != adv.end(); ++i) {
|
||||
std::ostringstream str;
|
||||
std::string field = prefs[(**i)["field"]];
|
||||
if(field.empty()) {
|
||||
field = (**i)["default"];
|
||||
}
|
||||
|
||||
if(field == "yes") {
|
||||
field = _("yes");
|
||||
} else if(field == "no") {
|
||||
field = _("no");
|
||||
}
|
||||
|
||||
str << (**i)["name"] << COLUMN_SEPARATOR << field;
|
||||
advanced_items.push_back(str.str());
|
||||
}
|
||||
|
||||
advanced_.set_items(advanced_items,true,true);
|
||||
}
|
||||
|
||||
void preferences_dialog::set_selection(int index)
|
||||
|
@ -1022,7 +1099,7 @@ void preferences_dialog::set_selection(int index)
|
|||
set_dirty();
|
||||
bg_restore();
|
||||
|
||||
bool hide_general = tab_ != GENERAL_TAB;
|
||||
const bool hide_general = tab_ != GENERAL_TAB;
|
||||
scroll_label_.hide(hide_general);
|
||||
scroll_slider_.hide(hide_general);
|
||||
turbo_button_.hide(hide_general);
|
||||
|
@ -1033,7 +1110,7 @@ void preferences_dialog::set_selection(int index)
|
|||
show_team_colours_button_.hide(hide_general);
|
||||
show_grid_button_.hide(hide_general);
|
||||
|
||||
bool hide_display = tab_ != DISPLAY_TAB, hide_gamma = hide_display || !adjust_gamma();
|
||||
const bool hide_display = tab_ != DISPLAY_TAB, hide_gamma = hide_display || !adjust_gamma();
|
||||
gamma_label_.hide(hide_gamma);
|
||||
gamma_slider_.hide(hide_gamma);
|
||||
gamma_button_.hide(hide_display);
|
||||
|
@ -1044,16 +1121,20 @@ void preferences_dialog::set_selection(int index)
|
|||
video_mode_button_.hide(hide_display);
|
||||
flip_time_button_.hide(hide_display);
|
||||
|
||||
bool hide_sound = tab_ != SOUND_TAB;
|
||||
const bool hide_sound = tab_ != SOUND_TAB;
|
||||
music_label_.hide(hide_sound);
|
||||
music_slider_.hide(hide_sound);
|
||||
sound_label_.hide(hide_sound);
|
||||
sound_slider_.hide(hide_sound);
|
||||
|
||||
const bool hide_advanced = tab_ != ADVANCED_TAB;
|
||||
advanced_.hide(hide_advanced);
|
||||
advanced_button_.hide(hide_advanced);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void show_preferences_dialog(display& disp)
|
||||
void show_preferences_dialog(display& disp, const config& game_cfg)
|
||||
{
|
||||
std::vector<std::string> items;
|
||||
|
||||
|
@ -1062,12 +1143,13 @@ void show_preferences_dialog(display& disp)
|
|||
items.push_back(pre + "general.png" + sep + dsgettext(GETTEXT_DOMAIN,"Prefs section^General"));
|
||||
items.push_back(pre + "display.png" + sep + dsgettext(GETTEXT_DOMAIN,"Prefs section^Display"));
|
||||
items.push_back(pre + "music.png" + sep + dsgettext(GETTEXT_DOMAIN,"Prefs section^Sound"));
|
||||
items.push_back(pre + "advanced.png" + sep + dsgettext(GETTEXT_DOMAIN,"Advanced section^Advanced"));
|
||||
|
||||
for(;;) {
|
||||
try {
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
preferences_dialog dialog(disp);
|
||||
preferences_dialog dialog(disp,game_cfg);
|
||||
std::vector<gui::preview_pane*> panes;
|
||||
panes.push_back(&dialog);
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace preferences {
|
|||
void set_theme(const std::string& theme);
|
||||
const std::string& theme();
|
||||
|
||||
void show_preferences_dialog(display& disp);
|
||||
void show_preferences_dialog(display& disp, const config& game_cfg);
|
||||
bool show_video_mode_dialog(display& disp);
|
||||
// If prefs is non-null, save the hotkeys in that config instead of
|
||||
// the default.
|
||||
|
|
|
@ -33,7 +33,8 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
|
|||
std::string button_image_name, SPACE_CONSUMPTION spacing)
|
||||
: widget(video), label_(label),
|
||||
image_(NULL), pressedImage_(NULL), activeImage_(NULL), pressedActiveImage_(NULL),
|
||||
button_(true), state_(NORMAL), type_(type), enabled_(true), pressed_(false)
|
||||
button_(true), state_(NORMAL), type_(type), enabled_(true), pressed_(false),
|
||||
spacing_(spacing), base_height_(0), base_width_(0)
|
||||
{
|
||||
set_label(label);
|
||||
|
||||
|
@ -65,10 +66,27 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
|
|||
if (button_image.null())
|
||||
throw error();
|
||||
|
||||
textRect_.x = 0;
|
||||
textRect_.y = 0;
|
||||
textRect_.w = video.getx();
|
||||
textRect_.h = video.gety();
|
||||
base_height_ = button_image->h;
|
||||
base_width_ = button_image->w;
|
||||
|
||||
calculate_size();
|
||||
|
||||
if(type == TYPE_PRESS) {
|
||||
image_.assign(scale_surface(button_image,location().w,location().h));
|
||||
pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
|
||||
activeImage_.assign(scale_surface(active_image,location().w,location().h));
|
||||
} else {
|
||||
image_.assign(scale_surface(button_image,button_image->w,button_image->h));
|
||||
pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
|
||||
activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
|
||||
if (type == TYPE_CHECK)
|
||||
pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
|
||||
}
|
||||
}
|
||||
|
||||
void button::calculate_size()
|
||||
{
|
||||
textRect_ = screen_area();
|
||||
|
||||
textRect_ = font::draw_text(NULL,textRect_,font_size,
|
||||
font::BUTTON_COLOUR,label_,0,0);
|
||||
|
@ -76,28 +94,20 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
|
|||
#ifdef USE_TINY_GUI
|
||||
set_height(textRect_.h+vertical_padding);
|
||||
#else
|
||||
set_height(maximum(textRect_.h+vertical_padding,button_image->h));
|
||||
set_height(maximum(textRect_.h+vertical_padding,base_height_));
|
||||
#endif
|
||||
if(type == TYPE_PRESS) {
|
||||
if(type_ == TYPE_PRESS) {
|
||||
#ifdef USE_TINY_GUI
|
||||
set_width(textRect_.w + horizontal_padding);
|
||||
#else
|
||||
if(spacing == MINIMUM_SPACE) {
|
||||
if(spacing_ == MINIMUM_SPACE) {
|
||||
set_width(textRect_.w + horizontal_padding);
|
||||
} else {
|
||||
set_width(maximum(textRect_.w+horizontal_padding,button_image->w));
|
||||
set_width(maximum(textRect_.w+horizontal_padding,base_width_));
|
||||
}
|
||||
#endif
|
||||
image_.assign(scale_surface(button_image,location().w,location().h));
|
||||
pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
|
||||
activeImage_.assign(scale_surface(active_image,location().w,location().h));
|
||||
} else {
|
||||
set_width(checkbox_horizontal_padding + textRect_.w + button_image->w);
|
||||
image_.assign(scale_surface(button_image,button_image->w,button_image->h));
|
||||
pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
|
||||
activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
|
||||
if (type == TYPE_CHECK)
|
||||
pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
|
||||
set_width(checkbox_horizontal_padding + textRect_.w + base_width_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +195,7 @@ namespace {
|
|||
|
||||
void button::set_label(const std::string& val)
|
||||
{
|
||||
bg_restore();
|
||||
label_ = val;
|
||||
|
||||
//if we have a list of items, use the first one that isn't an image
|
||||
|
@ -196,10 +207,7 @@ void button::set_label(const std::string& val)
|
|||
}
|
||||
}
|
||||
|
||||
textRect_ = screen_area();
|
||||
const std::string etext = font::make_text_ellipsis(label_, font_size, width());
|
||||
textRect_ = font::draw_text(NULL,textRect_,font_size,
|
||||
font::BUTTON_COLOUR,etext,0,0);
|
||||
calculate_size();
|
||||
|
||||
set_dirty(true);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
void calculate_size();
|
||||
|
||||
std::string label_;
|
||||
surface image_, pressedImage_, activeImage_, pressedActiveImage_;
|
||||
SDL_Rect textRect_;
|
||||
|
@ -72,6 +74,10 @@ private:
|
|||
|
||||
bool pressed_;
|
||||
|
||||
SPACE_CONSUMPTION spacing_;
|
||||
|
||||
int base_height_, base_width_;
|
||||
|
||||
bool hit(int x, int y) const;
|
||||
}; //end class button
|
||||
|
||||
|
|
|
@ -147,7 +147,11 @@ void menu::set_items(const std::vector<std::string>& items, bool strip_spaces, b
|
|||
//undrawn_items_.clear();
|
||||
max_items_ = -1; // Force recalculation of the max items.
|
||||
item_height_ = -1; // Force recalculation of the item height.
|
||||
selected_ = 0;
|
||||
|
||||
if(keep_viewport == false || selected_ >= int(items.size())) {
|
||||
selected_ = 0;
|
||||
}
|
||||
|
||||
fill_items(items, strip_spaces);
|
||||
if (!keep_viewport)
|
||||
set_position(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue