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

Method OnClick

src/town_gui.cpp:281–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279 }
280
281 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
282 {
283 switch (widget) {
284 case WID_TA_ZONE_BUTTON: {
285 bool new_show_state = !this->town->show_zone;
286 TownID index = this->town->index;
287
288 new_show_state ? _town_local_authority_kdtree.Insert(index) : _town_local_authority_kdtree.Remove(index);
289
290 this->town->show_zone = new_show_state;
291 this->SetWidgetLoweredState(widget, new_show_state);
292 SndClickBeep();
293 MarkWholeScreenDirty();
294 break;
295 }
296
297 case WID_TA_COMMAND_LIST: {
298 int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, GetCharacterHeight(FS_NORMAL)) - 1;
299
300 auto action = this->enabled_actions.GetNthSetBit(y);
301 if (!action.has_value()) break;
302
303 this->sel_action = *action;
304 this->SetDirty();
305
306 /* When double-clicking, continue */
307 if (click_count == 1 || !this->available_actions.Test(this->sel_action)) break;
308 [[fallthrough]];
309 }
310
311 case WID_TA_EXECUTE:
312 Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, static_cast<TownID>(this->window_number), this->sel_action);
313 break;
314 }
315 }
316
317 /** Redraw the whole window on a regular interval. */
318 const IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {

Callers

nothing calls this directly

Calls 10

SndClickBeepFunction · 0.85
MarkWholeScreenDirtyFunction · 0.85
GetCharacterHeightFunction · 0.85
SetWidgetLoweredStateMethod · 0.80
GetRowFromWidgetMethod · 0.80
GetNthSetBitMethod · 0.80
TestMethod · 0.80
InsertMethod · 0.45
RemoveMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected