| 1216 | } |
| 1217 | |
| 1218 | void OptionsPanelClick(Point pt) |
| 1219 | { |
| 1220 | int32_t btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GO_OPTIONSPANEL, WidgetDimensions::scaled.framerect.top); |
| 1221 | if (btn == INT32_MAX || btn < this->warn_lines) return; |
| 1222 | btn -= this->warn_lines; |
| 1223 | |
| 1224 | uint cur_row = 0; |
| 1225 | BaseSettingEntry *clicked_entry = GetSettingsTree().FindEntry(btn, &cur_row); |
| 1226 | |
| 1227 | if (clicked_entry == nullptr) return; // Clicked below the last setting of the page |
| 1228 | |
| 1229 | const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GO_OPTIONSPANEL); |
| 1230 | int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - WidgetDimensions::scaled.frametext.left - (clicked_entry->level + 1) * WidgetDimensions::scaled.hsep_indent - wid->pos_x; // Shift x coordinate |
| 1231 | if (x < 0) return; // Clicked left of the entry |
| 1232 | |
| 1233 | SettingsPage *clicked_page = dynamic_cast<SettingsPage*>(clicked_entry); |
| 1234 | if (clicked_page != nullptr) { |
| 1235 | this->SetDisplayedHelpText(nullptr); |
| 1236 | clicked_page->folded = !clicked_page->folded; // Flip 'folded'-ness of the sub-page |
| 1237 | |
| 1238 | this->manually_changed_folding = true; |
| 1239 | |
| 1240 | this->InvalidateData(); |
| 1241 | return; |
| 1242 | } |
| 1243 | |
| 1244 | SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry); |
| 1245 | assert(pe != nullptr); |
| 1246 | const IntSettingDesc *sd = pe->setting; |
| 1247 | |
| 1248 | /* return if action is only active in network, or only settable by server */ |
| 1249 | if (!sd->IsEditable()) { |
| 1250 | this->SetDisplayedHelpText(pe); |
| 1251 | return; |
| 1252 | } |
| 1253 | |
| 1254 | auto [min_val, max_val] = sd->GetRange(); |
| 1255 | int32_t value = sd->Read(ResolveObject(settings_ptr, sd)); |
| 1256 | |
| 1257 | /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */ |
| 1258 | if (x < SETTING_BUTTON_WIDTH && sd->flags.Test(SettingFlag::GuiDropdown)) { |
| 1259 | this->SetDisplayedHelpText(pe); |
| 1260 | |
| 1261 | if (this->valuedropdown_entry == pe) { |
| 1262 | /* unclick the dropdown */ |
| 1263 | this->CloseChildWindows(WC_DROPDOWN_MENU); |
| 1264 | this->closing_dropdown = false; |
| 1265 | this->valuedropdown_entry->SetButtons({}); |
| 1266 | this->valuedropdown_entry = nullptr; |
| 1267 | } else { |
| 1268 | if (this->valuedropdown_entry != nullptr) this->valuedropdown_entry->SetButtons({}); |
| 1269 | this->closing_dropdown = false; |
| 1270 | |
| 1271 | int rel_y = (pt.y - wid->pos_y - WidgetDimensions::scaled.framerect.top) % wid->resize_y; |
| 1272 | |
| 1273 | Rect wi_rect; |
| 1274 | wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x); |
| 1275 | wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1; |
nothing calls this directly
no test coverage detected