Refactor certain pref flags out of the display class
This replaces them with direct queries to saved preferences. This also removes the need for set_preference_display_settings,
(introduced in 0cd14d875d
) since its only purpose was to ensure the display flags were set
correctly.
Relevant intermediate setters were merged into the main setters (`_set_*` -> `set_*`).
Idle anim rates are now saved in preferences the same way they were in the display class. Additionally, its query func now
returns double instead of int.
set_color_cursors is currently not called, and therefore removing set_preference_display_settings had no effect. Curors are
still correctly changed when changing the preference.
display::turbo_speed remains, since it does additional work with the saved pref value that depends on the display class.
This commit is contained in:
parent
97b22161d4
commit
098c3342d5
9 changed files with 29 additions and 128 deletions
|
@ -192,11 +192,8 @@ display::display(const display_context* dc,
|
|||
, redrawMinimap_(false)
|
||||
, redraw_background_(true)
|
||||
, invalidateAll_(true)
|
||||
, grid_(false)
|
||||
, diagnostic_label_(0)
|
||||
, panelsDrawn_(false)
|
||||
, turbo_speed_(2)
|
||||
, turbo_(false)
|
||||
, invalidateGameStatus_(true)
|
||||
, map_labels_(new map_labels(nullptr))
|
||||
, reports_object_(&reports_object)
|
||||
|
@ -231,8 +228,6 @@ display::display(const display_context* dc,
|
|||
, fps_handle_(0)
|
||||
, invalidated_hexes_(0)
|
||||
, drawn_hexes_(0)
|
||||
, idle_anim_(preferences::idle_anim())
|
||||
, idle_anim_rate_(1.0)
|
||||
, map_screenshot_surf_(nullptr)
|
||||
, redraw_observers_()
|
||||
, draw_coordinates_(false)
|
||||
|
@ -261,8 +256,6 @@ display::display(const display_context* dc,
|
|||
fill_images_list(game_config::fog_prefix, fog_images_);
|
||||
fill_images_list(game_config::shroud_prefix, shroud_images_);
|
||||
|
||||
set_idle_anim_rate(preferences::idle_anim_rate());
|
||||
|
||||
unsigned int tile_size = preferences::tile_size();
|
||||
if(tile_size < MinZoom || tile_size > MaxZoom)
|
||||
tile_size = DefaultZoom;
|
||||
|
@ -2377,23 +2370,18 @@ void display::bounds_check_position(int& xpos, int& ypos) const
|
|||
|
||||
double display::turbo_speed() const
|
||||
{
|
||||
bool res = turbo_;
|
||||
bool res = preferences::turbo();
|
||||
if(keys_[SDLK_LSHIFT] || keys_[SDLK_RSHIFT]) {
|
||||
res = !res;
|
||||
}
|
||||
|
||||
res |= screen_.faked();
|
||||
if (res)
|
||||
return turbo_speed_;
|
||||
return preferences::turbo_speed();
|
||||
else
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void display::set_idle_anim_rate(int rate)
|
||||
{
|
||||
idle_anim_rate_ = std::pow(2.0, -rate/10.0);
|
||||
}
|
||||
|
||||
void display::redraw_everything()
|
||||
{
|
||||
if(screen_.update_locked())
|
||||
|
@ -2584,7 +2572,7 @@ void display::draw_hex(const map_location& loc) {
|
|||
num_images_fg = terrain_image_vector_.size();
|
||||
|
||||
// Draw the grid, if that's been enabled
|
||||
if(grid_) {
|
||||
if(preferences::grid()) {
|
||||
static const image::locator grid_top(game_config::images::grid_top);
|
||||
drawing_buffer_add(LAYER_GRID_TOP, loc, xpos, ypos,
|
||||
image::get_image(grid_top, image::TOD_COLORED));
|
||||
|
|
|
@ -348,12 +348,6 @@ public:
|
|||
/** Returns true if location (x,y) is covered in fog. */
|
||||
bool fogged(const map_location& loc) const;
|
||||
|
||||
/**
|
||||
* Determines whether a grid should be overlayed on the game board.
|
||||
* (to more clearly show where hexes are)
|
||||
*/
|
||||
void set_grid(const bool grid) { grid_ = grid; }
|
||||
|
||||
/** Getter for the x,y debug overlay on tiles */
|
||||
bool get_draw_coordinates() const { return draw_coordinates_; }
|
||||
/** Setter for the x,y debug overlay on tiles */
|
||||
|
@ -475,22 +469,8 @@ public:
|
|||
|
||||
void set_diagnostic(const std::string& msg);
|
||||
|
||||
/**
|
||||
* Set/Get whether 'turbo' mode is on.
|
||||
* When turbo mode is on, everything moves much faster.
|
||||
*/
|
||||
void set_turbo(const bool turbo) { turbo_ = turbo; }
|
||||
|
||||
double turbo_speed() const;
|
||||
|
||||
void set_turbo_speed(const double speed) { turbo_speed_ = speed; }
|
||||
|
||||
/** control unit idle animations and their frequency */
|
||||
void set_idle_anim(bool ison) { idle_anim_ = ison; }
|
||||
bool idle_anim() const { return idle_anim_; }
|
||||
void set_idle_anim_rate(int rate);
|
||||
double idle_anim_rate() const { return idle_anim_rate_; }
|
||||
|
||||
void bounds_check_position();
|
||||
void bounds_check_position(int& xpos, int& ypos) const;
|
||||
|
||||
|
@ -754,11 +734,8 @@ protected:
|
|||
bool redrawMinimap_;
|
||||
bool redraw_background_;
|
||||
bool invalidateAll_;
|
||||
bool grid_;
|
||||
int diagnostic_label_;
|
||||
bool panelsDrawn_;
|
||||
double turbo_speed_;
|
||||
bool turbo_;
|
||||
bool invalidateGameStatus_;
|
||||
const std::unique_ptr<map_labels> map_labels_;
|
||||
reports * reports_object_;
|
||||
|
@ -1054,9 +1031,6 @@ private:
|
|||
int invalidated_hexes_;
|
||||
int drawn_hexes_;
|
||||
|
||||
bool idle_anim_;
|
||||
double idle_anim_rate_;
|
||||
|
||||
surface map_screenshot_surf_;
|
||||
|
||||
std::vector<std::function<void(display&)>> redraw_observers_;
|
||||
|
|
|
@ -97,7 +97,6 @@ editor_controller::editor_controller()
|
|||
void editor_controller::init_gui()
|
||||
{
|
||||
gui_->change_display_context(&get_current_map_context());
|
||||
preferences::set_preference_display_settings();
|
||||
gui_->add_redraw_observer(std::bind(&editor_controller::display_redraw_callback, this, std::placeholders::_1));
|
||||
floating_label_manager_.reset(new font::floating_label_context());
|
||||
gui().set_draw_coordinates(preferences::editor::draw_hex_coordinates());
|
||||
|
|
|
@ -336,7 +336,6 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
|
|||
void play_controller::init_managers()
|
||||
{
|
||||
LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
preferences::set_preference_display_settings();
|
||||
tooltips_manager_.reset(new tooltips::manager());
|
||||
soundsources_manager_.reset(new soundsource::manager(*gui_));
|
||||
|
||||
|
|
|
@ -42,41 +42,6 @@
|
|||
|
||||
namespace preferences {
|
||||
|
||||
void set_preference_display_settings()
|
||||
{
|
||||
set_grid(grid());
|
||||
set_turbo(turbo());
|
||||
set_turbo_speed(turbo_speed());
|
||||
set_color_cursors(preferences::get("color_cursors", true));
|
||||
}
|
||||
|
||||
void set_turbo(bool ison)
|
||||
{
|
||||
_set_turbo(ison);
|
||||
|
||||
if(display::get_singleton()) {
|
||||
display::get_singleton()->set_turbo(ison);
|
||||
}
|
||||
}
|
||||
|
||||
void set_turbo_speed(double speed)
|
||||
{
|
||||
save_turbo_speed(speed);
|
||||
|
||||
if(display::get_singleton()) {
|
||||
display::get_singleton()->set_turbo_speed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
void set_grid(bool ison)
|
||||
{
|
||||
_set_grid(ison);
|
||||
|
||||
if(display::get_singleton()) {
|
||||
display::get_singleton()->set_grid(ison);
|
||||
}
|
||||
}
|
||||
|
||||
void set_color_cursors(bool value)
|
||||
{
|
||||
_set_color_cursors(value);
|
||||
|
@ -84,22 +49,6 @@ void set_color_cursors(bool value)
|
|||
cursor::set();
|
||||
}
|
||||
|
||||
void set_idle_anim(bool ison) {
|
||||
_set_idle_anim(ison);
|
||||
|
||||
if(display::get_singleton()) {
|
||||
display::get_singleton()->set_idle_anim(ison);
|
||||
}
|
||||
}
|
||||
|
||||
void set_idle_anim_rate(int rate) {
|
||||
_set_idle_anim_rate(rate);
|
||||
|
||||
if(display::get_singleton()) {
|
||||
display::get_singleton()->set_idle_anim_rate(rate);
|
||||
}
|
||||
}
|
||||
|
||||
bool show_standing_animations()
|
||||
{
|
||||
return preferences::get("unit_standing_animations", true);
|
||||
|
|
|
@ -17,21 +17,13 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace preferences {
|
||||
void set_preference_display_settings();
|
||||
namespace preferences
|
||||
{
|
||||
void set_color_cursors(bool value);
|
||||
|
||||
void set_turbo(bool ison);
|
||||
void set_grid(bool ison);
|
||||
void set_turbo_speed(double speed);
|
||||
void set_color_cursors(bool value);
|
||||
bool show_standing_animations();
|
||||
void set_show_standing_animations(bool value);
|
||||
|
||||
// Control unit idle animations
|
||||
void set_idle_anim(bool ison);
|
||||
void set_idle_anim_rate(int rate);
|
||||
|
||||
bool show_standing_animations();
|
||||
void set_show_standing_animations(bool value);
|
||||
|
||||
void show_wesnothd_server_search();
|
||||
bool show_theme_dialog();
|
||||
void show_wesnothd_server_search();
|
||||
bool show_theme_dialog();
|
||||
} // end namespace preferences
|
||||
|
|
|
@ -451,7 +451,7 @@ bool turbo()
|
|||
return get("turbo", false);
|
||||
}
|
||||
|
||||
void _set_turbo(bool ison)
|
||||
void set_turbo(bool ison)
|
||||
{
|
||||
prefs["turbo"] = ison;
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ double turbo_speed()
|
|||
return prefs["turbo_speed"].to_double(2.0);
|
||||
}
|
||||
|
||||
void save_turbo_speed(const double speed)
|
||||
void set_turbo_speed(const double speed)
|
||||
{
|
||||
prefs["turbo_speed"] = speed;
|
||||
}
|
||||
|
@ -487,19 +487,19 @@ bool idle_anim()
|
|||
return get("idle_anim", true);
|
||||
}
|
||||
|
||||
void _set_idle_anim(const bool ison)
|
||||
void set_idle_anim(const bool ison)
|
||||
{
|
||||
prefs["idle_anim"] = ison;
|
||||
}
|
||||
|
||||
int idle_anim_rate()
|
||||
double idle_anim_rate()
|
||||
{
|
||||
return prefs["idle_anim_rate"];
|
||||
return prefs["idle_anim_rate"].to_double(1.0);
|
||||
}
|
||||
|
||||
void _set_idle_anim_rate(const int rate)
|
||||
void set_idle_anim_rate(const int rate)
|
||||
{
|
||||
prefs["idle_anim_rate"] = rate;
|
||||
prefs["idle_anim_rate"] = std::pow(2.0, -rate / 10.0);
|
||||
}
|
||||
|
||||
std::string language()
|
||||
|
@ -537,7 +537,7 @@ bool grid()
|
|||
return get("grid", false);
|
||||
}
|
||||
|
||||
void _set_grid(bool ison)
|
||||
void set_grid(bool ison)
|
||||
{
|
||||
preferences::set("grid", ison);
|
||||
}
|
||||
|
|
|
@ -85,20 +85,20 @@ namespace preferences {
|
|||
void set_vsync(bool ison);
|
||||
|
||||
bool turbo();
|
||||
void _set_turbo(bool ison);
|
||||
void set_turbo(bool ison);
|
||||
|
||||
double turbo_speed();
|
||||
void save_turbo_speed(const double speed);
|
||||
void set_turbo_speed(const double speed);
|
||||
|
||||
int font_scaling();
|
||||
void set_font_scaling(int scale);
|
||||
int font_scaled(int size);
|
||||
|
||||
bool idle_anim();
|
||||
void _set_idle_anim(const bool ison);
|
||||
void set_idle_anim(const bool ison);
|
||||
|
||||
int idle_anim_rate();
|
||||
void _set_idle_anim_rate(const int rate);
|
||||
double idle_anim_rate();
|
||||
void set_idle_anim_rate(const int rate);
|
||||
|
||||
std::string language();
|
||||
void set_language(const std::string& s);
|
||||
|
@ -240,7 +240,7 @@ namespace preferences {
|
|||
void set_ellipses(bool ison);
|
||||
|
||||
bool grid();
|
||||
void _set_grid(bool ison);
|
||||
void set_grid(bool ison);
|
||||
|
||||
bool confirm_load_save_from_different_version();
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "display.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "preferences/display.hpp"
|
||||
#include "preferences/general.hpp"
|
||||
#include "random.hpp"
|
||||
#include "units/unit.hpp"
|
||||
#include "units/types.hpp"
|
||||
|
@ -99,7 +100,6 @@ void unit_animation_component::set_selecting()
|
|||
void unit_animation_component::start_animation (int start_time, const unit_animation *animation,
|
||||
bool with_bars, const std::string &text, color_t text_color, STATE state)
|
||||
{
|
||||
const display * disp = display::get_singleton();
|
||||
if (!animation) {
|
||||
if (state == STATE_STANDING)
|
||||
state_ = state;
|
||||
|
@ -116,9 +116,9 @@ void unit_animation_component::start_animation (int start_time, const unit_anima
|
|||
anim_->start_animation(real_start_time, u_.loc_, u_.loc_.get_direction(u_.facing_),
|
||||
text, text_color, accelerate);
|
||||
frame_begin_time_ = anim_->get_begin_time() -1;
|
||||
if (disp->idle_anim()) {
|
||||
if (preferences::idle_anim()) {
|
||||
next_idling_ = get_current_animation_tick()
|
||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * disp->idle_anim_rate());
|
||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * preferences::idle_anim_rate());
|
||||
} else {
|
||||
next_idling_ = INT_MAX;
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ void unit_animation_component::refresh()
|
|||
if (get_current_animation_tick() > next_idling_ + 1000)
|
||||
{
|
||||
// prevent all units animating at the same time
|
||||
if (disp.idle_anim()) {
|
||||
if (preferences::idle_anim()) {
|
||||
next_idling_ = get_current_animation_tick()
|
||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * disp.idle_anim_rate());
|
||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * preferences::idle_anim_rate());
|
||||
} else {
|
||||
next_idling_ = INT_MAX;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue