MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SettingsPanelClick

Method SettingsPanelClick

src/cheat_gui.cpp:490–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488 }
489
490 void SettingsPanelClick(Point pt)
491 {
492 int row = this->GetRowFromWidget(pt.y, WID_C_SETTINGS, WidgetDimensions::scaled.framerect.top, this->line_height);
493 if (row == INT_MAX) return;
494
495 const SettingDesc *desc = this->sandbox_settings[row];
496 const IntSettingDesc *sd = desc->AsIntSetting();
497
498 if (!sd->IsEditable()) return;
499
500 Rect r = this->GetWidget<NWidgetBase>(WID_C_SETTINGS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
501 int x = pt.x - r.left;
502 bool rtl = _current_text_dir == TD_RTL;
503 if (rtl) x = r.Width() - 1 - x;
504
505 if (x < SETTING_BUTTON_WIDTH) {
506 ChangeSettingValue(sd, x);
507 } else {
508 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
509 if (this->last_clicked_setting == sd && !sd->IsBoolSetting() && !sd->flags.Test(SettingFlag::GuiDropdown)) {
510 int64_t value64 = sd->Read(&GetGameSettings());
511
512 /* Show the correct currency-translated value */
513 if (sd->flags.Test(SettingFlag::GuiCurrency)) value64 *= GetCurrency().rate;
514
515 CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed
516 if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input
517
518 this->valuewindow_entry = sd;
519
520 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
521 ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QueryStringFlag::EnableDefault);
522 }
523
524 this->clicked_setting = sd;
525 }
526 }
527
528 void ChangeSettingValue(const IntSettingDesc *sd, int x)
529 {

Callers

nothing calls this directly

Calls 12

ShowQueryStringFunction · 0.85
GetRowFromWidgetMethod · 0.80
AsIntSettingMethod · 0.80
ShrinkMethod · 0.80
GetCurrentRectMethod · 0.80
TestMethod · 0.80
GetStringFunction · 0.70
IsEditableMethod · 0.45
WidthMethod · 0.45
IsBoolSettingMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected