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

Method CheatPanelClick

src/cheat_gui.cpp:437–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435 }
436
437 void CheatPanelClick(Point pt)
438 {
439 Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
440 uint btn = (pt.y - r.top) / this->line_height;
441 int x = pt.x - r.left;
442 bool rtl = _current_text_dir == TD_RTL;
443 if (rtl) x = r.Width() - 1 - x;
444
445 if (btn >= lengthof(_cheats_ui)) return;
446
447 const CheatEntry *ce = &_cheats_ui[btn];
448 int value = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
449 int oldvalue = value;
450
451 if (btn == CHT_CHANGE_DATE && x >= SETTING_BUTTON_WIDTH) {
452 /* Click at the date text directly. */
453 clicked_cheat = CHT_CHANGE_DATE;
454 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
455 return;
456 } else if (btn == CHT_EDIT_MAX_HL && x >= SETTING_BUTTON_WIDTH) {
457 clicked_cheat = CHT_EDIT_MAX_HL;
458 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
459 return;
460 }
461
462 /* Not clicking a button? */
463 if (!IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) return;
464
465 this->clicked_setting = nullptr;
466 *ce->been_used = true;
467
468 switch (ce->type) {
469 case SLE_BOOL:
470 value ^= 1;
471 if (ce->proc != nullptr) ce->proc(value, 0);
472 break;
473
474 default:
475 /* Take whatever the function returns */
476 value = ce->proc(value + ((x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
477
478 /* The first cheat (money), doesn't return a different value. */
479 if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
480 break;
481 }
482
483 if (value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(value));
484
485 this->SetTimeout();
486
487 this->SetDirty();
488 }
489
490 void SettingsPanelClick(Point pt)
491 {

Callers

nothing calls this directly

Calls 11

ReadValueFunction · 0.85
ShowQueryStringFunction · 0.85
IsInsideMMFunction · 0.85
WriteValueFunction · 0.85
ShrinkMethod · 0.80
GetCurrentRectMethod · 0.80
SetTimeoutMethod · 0.80
GetStringFunction · 0.70
WidthMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected