After discussing with ilor the overloaded get_value() in field.hpp was unclear.
Renamed both versions and fixed the callers. Also added more comment to the functions.
This commit is contained in:
parent
d0813a499e
commit
0804846d7d
5 changed files with 52 additions and 35 deletions
|
@ -44,22 +44,22 @@ teditor_new_map::teditor_new_map() :
|
|||
|
||||
void teditor_new_map::set_map_width(int value)
|
||||
{
|
||||
map_width_->set_value(value);
|
||||
map_width_->set_cache_value(value);
|
||||
}
|
||||
|
||||
int teditor_new_map::map_width() const
|
||||
{
|
||||
return map_width_->get_value();
|
||||
return map_width_->get_cache_value();
|
||||
}
|
||||
|
||||
void teditor_new_map::set_map_height(int value)
|
||||
{
|
||||
map_height_->set_value(value);
|
||||
map_height_->set_cache_value(value);
|
||||
}
|
||||
|
||||
int teditor_new_map::map_height() const
|
||||
{
|
||||
return map_height_->get_value();
|
||||
return map_height_->get_cache_value();
|
||||
}
|
||||
|
||||
twindow teditor_new_map::build_window(CVideo& video)
|
||||
|
|
|
@ -60,22 +60,22 @@ teditor_resize_map::teditor_resize_map() :
|
|||
|
||||
void teditor_resize_map::set_map_width(int value)
|
||||
{
|
||||
map_width_->set_value(value);
|
||||
map_width_->set_cache_value(value);
|
||||
}
|
||||
|
||||
int teditor_resize_map::map_width() const
|
||||
{
|
||||
return map_width_->get_value();
|
||||
return map_width_->get_cache_value();
|
||||
}
|
||||
|
||||
void teditor_resize_map::set_map_height(int value)
|
||||
{
|
||||
map_height_->set_value(value);
|
||||
map_height_->set_cache_value(value);
|
||||
}
|
||||
|
||||
int teditor_resize_map::map_height() const
|
||||
{
|
||||
return map_height_->get_value();
|
||||
return map_height_->get_cache_value();
|
||||
}
|
||||
|
||||
void teditor_resize_map::set_old_map_width(int value)
|
||||
|
@ -90,7 +90,7 @@ void teditor_resize_map::set_old_map_height(int value)
|
|||
|
||||
bool teditor_resize_map::copy_edge_terrain() const
|
||||
{
|
||||
return copy_edge_terrain_->get_value();
|
||||
return copy_edge_terrain_->get_cache_value();
|
||||
}
|
||||
|
||||
twindow teditor_resize_map::build_window(CVideo& video)
|
||||
|
@ -159,8 +159,8 @@ void teditor_resize_map::update_expand_direction(twindow& window)
|
|||
set_direction_icon(i, "none");
|
||||
}
|
||||
|
||||
int xdiff = map_width_->get_value(window) - old_width_ ;
|
||||
int ydiff = map_height_->get_value(window) - old_height_ ;
|
||||
int xdiff = map_width_->get_widget_value(window) - old_width_ ;
|
||||
int ydiff = map_height_->get_widget_value(window) - old_height_ ;
|
||||
int x = static_cast<int>(expand_direction_) % 3;
|
||||
int y = static_cast<int>(expand_direction_) / 3;
|
||||
set_direction_icon(expand_direction_, "center");
|
||||
|
|
|
@ -225,23 +225,29 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the widget.
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* This sets the value in both the internal cache value and in the widget
|
||||
* itself.
|
||||
*
|
||||
* @param window The window containing the widget.
|
||||
* @param value The new value.
|
||||
*/
|
||||
void set_value(twindow& window, CT value)
|
||||
void set_widget_value(twindow& window, CT value)
|
||||
{
|
||||
value_ = value;
|
||||
restore(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the widget.
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* This sets the internal cache value but not the widget value, this can
|
||||
* be used to initialize the field.
|
||||
*
|
||||
* @param value The new value.
|
||||
*/
|
||||
void set_value(CT value)
|
||||
void set_cache_value(CT value)
|
||||
{
|
||||
value_ = value;
|
||||
}
|
||||
|
@ -253,20 +259,31 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the widget.
|
||||
* Gets the value of the field.
|
||||
*
|
||||
* This function gets the value of the widget and stores that in the
|
||||
* internal cache, then that value is returned.
|
||||
*
|
||||
* @param window The window containing the widget.
|
||||
*/
|
||||
T get_value(twindow& window)
|
||||
*
|
||||
* @returns The current value of the widget.
|
||||
*/
|
||||
T get_widget_value(twindow& window)
|
||||
{
|
||||
save(window, false);
|
||||
return value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the widget.
|
||||
*/
|
||||
T get_value()
|
||||
* Gets the value of the field.
|
||||
*
|
||||
* This function returns the value internal cache, this function can be
|
||||
* used after the widget no longer exists. The cache is normally updated
|
||||
* when the window is closed with succes.
|
||||
*
|
||||
* @returns The currently value of the internal cache.
|
||||
*/
|
||||
T get_cache_value()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ void tmp_connect::show_server_list(twindow& window)
|
|||
dlg.show(*video_);
|
||||
|
||||
if(dlg.get_retval() == twindow::OK) {
|
||||
host_name_->set_value(window, dlg.host_name());
|
||||
host_name_->set_widget_value(window, dlg.host_name());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ void tmp_create_game::update_map(twindow& window)
|
|||
|
||||
void tmp_create_game::update_map_settings(twindow& window)
|
||||
{
|
||||
const bool use_map_settings = use_map_settings_->get_value(window);
|
||||
const bool use_map_settings = use_map_settings_->get_widget_value(window);
|
||||
|
||||
fog_->widget_set_enabled(window, !use_map_settings, false);
|
||||
shroud_->widget_set_enabled(window, !use_map_settings, false);
|
||||
|
@ -171,26 +171,26 @@ void tmp_create_game::update_map_settings(twindow& window)
|
|||
if(use_map_settings) {
|
||||
if(scenario_) {
|
||||
|
||||
fog_->set_value(window, ::settings::use_fog((*(*scenario_).get_children("side").front())["fog"]));
|
||||
shroud_->set_value(window, ::settings::use_shroud((*(*scenario_).get_children("side").front())["shroud"]));
|
||||
start_time_->set_value(window, ::settings::use_random_start_time((*scenario_)["random_start_time"]));
|
||||
fog_->set_widget_value(window, ::settings::use_fog((*(*scenario_).get_children("side").front())["fog"]));
|
||||
shroud_->set_widget_value(window, ::settings::use_shroud((*(*scenario_).get_children("side").front())["shroud"]));
|
||||
start_time_->set_widget_value(window, ::settings::use_random_start_time((*scenario_)["random_start_time"]));
|
||||
|
||||
turns_->set_value(window, ::settings::get_turns((*scenario_)["turns"]));
|
||||
gold_->set_value(window, ::settings::get_village_gold((*(*scenario_).get_children("side").front())["village_gold"]));
|
||||
experience_->set_value(window, ::settings::get_xp_modifier((*scenario_)["experience_modifier"]));
|
||||
turns_->set_widget_value(window, ::settings::get_turns((*scenario_)["turns"]));
|
||||
gold_->set_widget_value(window, ::settings::get_village_gold((*(*scenario_).get_children("side").front())["village_gold"]));
|
||||
experience_->set_widget_value(window, ::settings::get_xp_modifier((*scenario_)["experience_modifier"]));
|
||||
}
|
||||
// No scenario selected just leave the state unchanged for now.
|
||||
|
||||
} else {
|
||||
|
||||
// Fixme we should store the value and reuse it later...
|
||||
fog_->set_value(window, preferences::fog());
|
||||
shroud_->set_value(window, preferences::shroud());
|
||||
start_time_->set_value(window, preferences::random_start_time());
|
||||
fog_->set_widget_value(window, preferences::fog());
|
||||
shroud_->set_widget_value(window, preferences::shroud());
|
||||
start_time_->set_widget_value(window, preferences::random_start_time());
|
||||
|
||||
turns_->set_value(window, preferences::turns());
|
||||
gold_->set_value(window, preferences::village_gold());
|
||||
experience_->set_value(window, preferences::xp_modifier());
|
||||
turns_->set_widget_value(window, preferences::turns());
|
||||
gold_->set_widget_value(window, preferences::village_gold());
|
||||
experience_->set_widget_value(window, preferences::xp_modifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue