diff -r 934fde7398f9 src/settings_gui.cpp --- a/src/settings_gui.cpp Sun Nov 16 11:14:33 2008 +0100 +++ b/src/settings_gui.cpp Sun Nov 16 12:00:23 2008 +0100 @@ -615,6 +615,7 @@ byte num; ///< Number of entries on the page (statically filled). void Init(); + PatchEntry *FindEntry(uint row) const; void Draw(GameSettings *patches_ptr, int base_x, int base_y, uint first_row, uint max_row) const; }; @@ -716,6 +717,19 @@ { for (uint fld = 0; fld < num; fld++) entries[fld].Init(); +} + +/** + * Find the patch entry at row-number \a row + * @param row Index of setting to return + * @return The requested patch entry or \c NULL if it does not exist + */ +PatchEntry *PatchPage::FindEntry(uint row) const +{ + if (row >= num) + return NULL; + + return &entries[row]; } /** @@ -953,10 +967,11 @@ if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting const PatchPage *page = &_patches_page[this->page]; + PatchEntry *pe = page->FindEntry(btn); - if (btn >= page->num) return; // Clicked below the last setting of the page + if (pe == NULL) return; // Clicked below the last setting of the page - const SettingDesc *sd = page->entries[btn].setting; + const SettingDesc *sd = pe->setting; /* return if action is only active in network, or only settable by server */ if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return; @@ -1001,7 +1016,7 @@ if (depressed_entry != NULL) // If another entry has depressed buttons, release them depressed_entry->SetButtons(0); - depressed_entry = &page->entries[btn]; + depressed_entry = pe; depressed_entry->SetButtons((x >= 10) ? PEF_RIGHT_DEPRESSED : PEF_LEFT_DEPRESSED); this->flags4 |= WF_TIMEOUT_BEGIN; _left_button_clicked = false; @@ -1011,7 +1026,7 @@ } if (value != oldvalue) { - SetPatchValue(page->entries[btn].index, value); + SetPatchValue(pe->index, value); this->SetDirty(); } } else { @@ -1020,7 +1035,7 @@ /* Show the correct currency-translated value */ if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate; - valuewindow_entry = &page->entries[btn]; + valuewindow_entry = pe; SetDParam(0, value); ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, this, CS_NUMERAL, QSF_NONE); }