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

Method ChangeSettingValue

src/cheat_gui.cpp:528–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526 }
527
528 void ChangeSettingValue(const IntSettingDesc *sd, int x)
529 {
530 int32_t value = sd->Read(&GetGameSettings());
531 int32_t oldvalue = value;
532 if (sd->IsBoolSetting()) {
533 value ^= 1;
534 } else {
535 /* don't allow too fast scrolling */
536 if (this->flags.Test(WindowFlag::Timeout) && this->timeout_timer > 1) {
537 _left_button_clicked = false;
538 return;
539 }
540
541 /* Add a dynamic step-size to the scroller. In a maximum of
542 * 50-steps you should be able to get from min to max,
543 * unless specified otherwise in the 'interval' variable
544 * of the current setting. */
545 uint32_t step = (sd->interval == 0) ? ((sd->max - sd->min) / 50) : sd->interval;
546 if (step == 0) step = 1;
547
548 /* Increase or decrease the value and clamp it to extremes */
549 if (x >= SETTING_BUTTON_WIDTH / 2) {
550 value += step;
551 if (sd->min < 0) {
552 assert(static_cast<int32_t>(sd->max) >= 0);
553 if (value > static_cast<int32_t>(sd->max)) value = static_cast<int32_t>(sd->max);
554 } else {
555 if (static_cast<uint32_t>(value) > sd->max) value = static_cast<int32_t>(sd->max);
556 }
557 if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
558 } else {
559 value -= step;
560 if (value < sd->min) value = sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : sd->min;
561 }
562
563 /* Set up scroller timeout for numeric values */
564 if (value != oldvalue) {
565 this->last_clicked_setting = nullptr;
566 this->clicked_setting = sd;
567 this->clicked = (x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? 2 : 1;
568 this->SetTimeout();
569 _left_button_clicked = false;
570 }
571 }
572
573 if (value != oldvalue) {
574 SetSettingValue(sd, value);
575 this->SetDirty();
576 }
577 }
578
579 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
580 {

Callers

nothing calls this directly

Calls 6

SetSettingValueFunction · 0.85
TestMethod · 0.80
SetTimeoutMethod · 0.80
ReadMethod · 0.45
IsBoolSettingMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected