| 394 | } |
| 395 | |
| 396 | void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override |
| 397 | { |
| 398 | switch (widget) { |
| 399 | case WID_SCRS_BACKGROUND: { |
| 400 | auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget); |
| 401 | if (it == this->visible_settings.end()) break; |
| 402 | |
| 403 | const ScriptConfigItem &config_item = **it; |
| 404 | if (!this->IsEditableItem(config_item)) return; |
| 405 | |
| 406 | int num = it - this->visible_settings.begin(); |
| 407 | if (this->clicked_row != num) { |
| 408 | this->CloseChildWindows(WC_QUERY_STRING); |
| 409 | this->CloseChildWindows(WC_DROPDOWN_MENU); |
| 410 | this->clicked_row = num; |
| 411 | this->clicked_dropdown = false; |
| 412 | } |
| 413 | |
| 414 | bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean); |
| 415 | |
| 416 | Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero); |
| 417 | int x = pt.x - r.left; |
| 418 | if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x; |
| 419 | |
| 420 | /* One of the arrows is clicked (or green/red rect in case of bool value) */ |
| 421 | int old_val = this->script_config->GetSetting(config_item.name); |
| 422 | if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) { |
| 423 | if (this->clicked_dropdown) { |
| 424 | /* unclick the dropdown */ |
| 425 | this->CloseChildWindows(WC_DROPDOWN_MENU); |
| 426 | this->clicked_dropdown = false; |
| 427 | this->closing_dropdown = false; |
| 428 | } else { |
| 429 | int rel_y = (pt.y - r.top) % this->line_height; |
| 430 | |
| 431 | Rect wi_rect; |
| 432 | wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x); |
| 433 | wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1; |
| 434 | wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2; |
| 435 | wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1; |
| 436 | |
| 437 | /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */ |
| 438 | if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) { |
| 439 | this->clicked_dropdown = true; |
| 440 | this->closing_dropdown = false; |
| 441 | |
| 442 | DropDownList list; |
| 443 | for (int i = config_item.min_value; i <= config_item.max_value; i++) { |
| 444 | list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i)); |
| 445 | } |
| 446 | |
| 447 | ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE); |
| 448 | } |
| 449 | } |
| 450 | } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) { |
| 451 | int new_val = old_val; |
| 452 | if (bool_item) { |
| 453 | new_val = !new_val; |
nothing calls this directly
no test coverage detected