(svn r22428) -Codechange: Reduce code duplication in the smallmap legend.

pull/155/head
michi_cc 13 years ago
parent d4c6960654
commit b339fdae41

@ -1312,9 +1312,7 @@ public:
break; break;
case SM_WIDGET_LEGEND: // Legend case SM_WIDGET_LEGEND: // Legend
/* If industry type small map*/ if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER) {
if (this->map_type == SMT_INDUSTRY) {
/* If click on industries label, find right industry type and enable/disable it */
const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_LEGEND); // Label panel const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_LEGEND); // Label panel
uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL; uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
uint columns = this->GetNumberColumnsLegend(wi->current_x); uint columns = this->GetNumberColumnsLegend(wi->current_x);
@ -1326,11 +1324,13 @@ public:
if (rtl) x = wi->current_x - x; if (rtl) x = wi->current_x - x;
uint column = (x - WD_FRAMERECT_LEFT) / this->column_width; uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
/* Check if click is on industry label*/ /* If industry type small map*/
if (this->map_type == SMT_INDUSTRY) {
/* If click on industries label, find right industry type and enable/disable it. */
int industry_pos = (column * number_of_rows) + line; int industry_pos = (column * number_of_rows) + line;
if (industry_pos < _smallmap_industry_count) { if (industry_pos < _smallmap_industry_count) {
if (_ctrl_pressed) { if (_ctrl_pressed) {
/* Disable all, except the clicked one */ /* Disable all, except the clicked one. */
bool changes = false; bool changes = false;
for (int i = 0; i != _smallmap_industry_count; i++) { for (int i = 0; i != _smallmap_industry_count; i++) {
bool new_state = i == industry_pos; bool new_state = i == industry_pos;
@ -1349,21 +1349,8 @@ public:
_legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map; _legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map;
} }
} }
this->SetDirty();
} else if (this->map_type == SMT_OWNER) { } else if (this->map_type == SMT_OWNER) {
/* If click on companies label, find right company and enable/disable it. */ /* If click on companies label, find right company and enable/disable it. */
const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_LEGEND);
uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
uint columns = this->GetNumberColumnsLegend(wi->current_x);
uint number_of_rows = max(CeilDiv(max(_smallmap_company_count, _smallmap_industry_count), columns), this->min_number_of_fixed_rows);
if (line >= number_of_rows) break;
bool rtl = _current_text_dir == TD_RTL;
int x = pt.x - wi->pos_x;
if (rtl) x = wi->current_x - x;
uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
/* Check if click is on company label. */
int company_pos = (column * number_of_rows) + line; int company_pos = (column * number_of_rows) + line;
if (company_pos < NUM_NO_COMPANY_ENTRIES) break; if (company_pos < NUM_NO_COMPANY_ENTRIES) break;
if (company_pos < _smallmap_company_count) { if (company_pos < _smallmap_company_count) {
@ -1387,6 +1374,7 @@ public:
_legend_land_owners[company_pos].show_on_map = !_legend_land_owners[company_pos].show_on_map; _legend_land_owners[company_pos].show_on_map = !_legend_land_owners[company_pos].show_on_map;
} }
} }
}
this->SetDirty(); this->SetDirty();
} }
break; break;

Loading…
Cancel
Save