OpenTTD Source: src/cheat_gui.cpp Source File

OpenTTD Source 13.2.1

cheat_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "command_func.h"
12 #include "cheat_type.h"
13 #include "company_base.h"
14 #include "company_func.h"
15 #include "date_func.h"
16 #include "saveload/saveload.h"
17 #include "vehicle_base.h"
18 #include "textbuf_gui.h"
19 #include "window_gui.h"
20 #include "string_func.h"
21 #include "strings_func.h"
22 #include "window_func.h"
23 #include "rail_gui.h"
24 #include "settings_gui.h"
25 #include "company_gui.h"
26 #include "linkgraph/linkgraphschedule.h"
27 #include "map_func.h"
28 #include "tile_map.h"
29 #include "newgrf.h"
30 #include "error.h"
31 #include "misc_cmd.h"
32 #include "core/geometry_func.hpp"
33
34 #include "widgets/cheat_widget.h"
35
36 #include "table/sprites.h"
37
38 #include "safeguards.h"
39
40
46 static int32 _money_cheat_amount = 10000000;
47
57 static int32 ClickMoneyCheat(int32 p1, int32 p2)
58 {
59 Command<CMD_MONEY_CHEAT>::Post(p2 * _money_cheat_amount);
60 return _money_cheat_amount;
61 }
62
69 static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
70 {
71 while ((uint)p1 < Company::GetPoolSize()) {
72 if (Company::IsValidID((CompanyID)p1)) {
73 SetLocalCompany((CompanyID)p1);
74 return _local_company;
75 }
76 p1 += p2;
77 }
78
79 return _local_company;
80 }
81
88 static int32 ClickSetProdCheat(int32 p1, int32 p2)
89 {
90 _cheats.setup_prod.value = (p1 != 0);
91 InvalidateWindowClassesData(WC_INDUSTRY_VIEW);
92 return _cheats.setup_prod.value;
93 }
94
95 extern void EnginesMonthlyLoop();
96
103 static int32 ClickChangeDateCheat(int32 p1, int32 p2)
104 {
105 YearMonthDay ymd;
106 ConvertDateToYMD(_date, &ymd);
107
108 p1 = Clamp(p1, MIN_YEAR, MAX_YEAR);
109 if (p1 == _cur_year) return _cur_year;
110
111 Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day);
112 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - _date);
113 LinkGraphSchedule::instance.ShiftDates(new_date - _date);
114 SetDate(new_date, _date_fract);
115 EnginesMonthlyLoop();
116 SetWindowDirty(WC_STATUS_BAR, 0);
117 InvalidateWindowClassesData(WC_BUILD_STATION, 0);
118 InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
119 ResetSignalVariant();
120 return _cur_year;
121 }
122
130 static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
131 {
132 p1 = Clamp(p1, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);
133
134 /* Check if at least one mountain on the map is higher than the new value.
135 * If yes, disallow the change. */
136 for (TileIndex t = 0; t < MapSize(); t++) {
137 if ((int32)TileHeight(t) > p1) {
138 ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
139 /* Return old, unchanged value */
140 return _settings_game.construction.map_height_limit;
141 }
142 }
143
144 /* Execute the change and reload GRF Data */
145 _settings_game.construction.map_height_limit = p1;
146 ReloadNewGRFData();
147
148 /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
149 InvalidateWindowClassesData(WC_SMALLMAP, 2);
150
151 return _settings_game.construction.map_height_limit;
152 }
153
155 enum CheatNumbers {
156 CHT_MONEY,
157 CHT_CHANGE_COMPANY,
158 CHT_EXTRA_DYNAMITE,
159 CHT_CROSSINGTUNNELS,
160 CHT_NO_JETCRASH,
161 CHT_SETUP_PROD,
162 CHT_EDIT_MAX_HL,
163 CHT_CHANGE_DATE,
164
165 CHT_NUM_CHEATS,
166 };
167
173 typedef int32 CheckButtonClick(int32 p1, int32 p2);
174
176 struct CheatEntry {
177 VarType type;
178 StringID str;
179 void *variable;
180 bool *been_used;
181 CheckButtonClick *proc;
182 };
183
188 static const CheatEntry _cheats_ui[] = {
189 {SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
190 {SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
191 {SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
192 {SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
193 {SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
194 {SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
195 {SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.map_height_limit, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
196 {SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
197 };
198
199 static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
200
202 static const NWidgetPart _nested_cheat_widgets[] = {
203 NWidget(NWID_HORIZONTAL),
204 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
205 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CHEATS, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
206 NWidget(WWT_SHADEBOX, COLOUR_GREY),
207 NWidget(WWT_STICKYBOX, COLOUR_GREY),
208 EndContainer(),
209 NWidget(WWT_PANEL, COLOUR_GREY, WID_C_PANEL), SetDataTip(0x0, STR_CHEATS_TOOLTIP), EndContainer(),
210 NWidget(WWT_PANEL, COLOUR_GREY),
211 NWidget(WWT_LABEL, COLOUR_GREY, WID_C_NOTE), SetFill(1, 1), SetDataTip(STR_CHEATS_NOTE, STR_NULL), SetPadding(WidgetDimensions::unscaled.frametext),
212 EndContainer(),
213 };
214
216 struct CheatWindow : Window {
217 int clicked;
218 int clicked_widget;
219 uint line_height;
220 Dimension box;
221 Dimension icon;
222
223 CheatWindow(WindowDesc *desc) : Window(desc)
224 {
225 this->InitNested();
226 }
227
228 void OnInit() override
229 {
230 this->box = maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED));
231 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
232 }
233
234 void DrawWidget(const Rect &r, int widget) const override
235 {
236 if (widget != WID_C_PANEL) return;
237
238 const Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
239 int y = ir.top;
240
241 bool rtl = _current_text_dir == TD_RTL;
242 uint box_left = rtl ? ir.right - this->box.width - WidgetDimensions::scaled.hsep_wide : ir.left + WidgetDimensions::scaled.hsep_wide;
243 uint button_left = rtl ? ir.right - this->box.width - WidgetDimensions::scaled.hsep_wide * 2 - SETTING_BUTTON_WIDTH : ir.left + this->box.width + WidgetDimensions::scaled.hsep_wide * 2;
244 uint text_left = ir.left + (rtl ? 0 : WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH);
245 uint text_right = ir.right - (rtl ? WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH : 0);
246
247 int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
248 int box_y_offset = (this->line_height - this->box.height) / 2;
249 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
250 int icon_y_offset = (this->line_height - this->icon.height) / 2;
251
252 for (int i = 0; i != lengthof(_cheats_ui); i++) {
253 const CheatEntry *ce = &_cheats_ui[i];
254
255 DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + box_y_offset);
256
257 switch (ce->type) {
258 case SLE_BOOL: {
259 bool on = (*(bool*)ce->variable);
260
261 DrawBoolButton(button_left, y + button_y_offset, on, true);
262 SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
263 break;
264 }
265
266 default: {
267 int32 val = (int32)ReadValue(ce->variable, ce->type);
268 char buf[512];
269
270 /* Draw [<][>] boxes for settings of an integer-type */
271 DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
272
273 switch (ce->str) {
274 /* Display date for change date cheat */
275 case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
276
277 /* Draw coloured flag for change company cheat */
278 case STR_CHEAT_CHANGE_COMPANY: {
279 SetDParam(0, val + 1);
280 GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf));
281 uint offset = WidgetDimensions::scaled.hsep_indent + GetStringBoundingBox(buf).width;
282 DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset);
283 break;
284 }
285
286 default: SetDParam(0, val);
287 }
288 break;
289 }
290 }
291
292 DrawString(text_left, text_right, y + text_y_offset, ce->str);
293
294 y += this->line_height;
295 }
296 }
297
298 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
299 {
300 if (widget != WID_C_PANEL) return;
301
302 uint width = 0;
303 for (int i = 0; i != lengthof(_cheats_ui); i++) {
304 const CheatEntry *ce = &_cheats_ui[i];
305 switch (ce->type) {
306 case SLE_BOOL:
307 SetDParam(0, STR_CONFIG_SETTING_ON);
308 width = std::max(width, GetStringBoundingBox(ce->str).width);
309 SetDParam(0, STR_CONFIG_SETTING_OFF);
310 width = std::max(width, GetStringBoundingBox(ce->str).width);
311 break;
312
313 default:
314 switch (ce->str) {
315 /* Display date for change date cheat */
316 case STR_CHEAT_CHANGE_DATE:
317 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 11, 31));
318 width = std::max(width, GetStringBoundingBox(ce->str).width);
319 break;
320
321 /* Draw coloured flag for change company cheat */
322 case STR_CHEAT_CHANGE_COMPANY:
323 SetDParamMaxValue(0, MAX_COMPANIES);
324 width = std::max(width, GetStringBoundingBox(ce->str).width + WidgetDimensions::scaled.hsep_wide * 4);
325 break;
326
327 default:
328 SetDParam(0, INT64_MAX);
329 width = std::max(width, GetStringBoundingBox(ce->str).width);
330 break;
331 }
332 break;
333 }
334 }
335
336 this->line_height = std::max(this->box.height, this->icon.height);
337 this->line_height = std::max<uint>(this->line_height, SETTING_BUTTON_HEIGHT);
338 this->line_height = std::max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WidgetDimensions::scaled.framerect.Vertical();
339
340 size->width = width + WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH /* stuff on the left */ + WidgetDimensions::scaled.hsep_wide * 2 /* extra spacing on right */;
341 size->height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lengthof(_cheats_ui);
342 }
343
344 void OnClick(Point pt, int widget, int click_count) override
345 {
346 Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
347 uint btn = (pt.y - r.top) / this->line_height;
348 uint x = pt.x - r.left;
349 bool rtl = _current_text_dir == TD_RTL;
350 if (rtl) x = r.Width() - 1 - x;
351
352 if (btn >= lengthof(_cheats_ui)) return;
353
354 const CheatEntry *ce = &_cheats_ui[btn];
355 int value = (int32)ReadValue(ce->variable, ce->type);
356 int oldvalue = value;
357
358 if (btn == CHT_CHANGE_DATE && x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH) {
359 /* Click at the date text directly. */
360 clicked_widget = CHT_CHANGE_DATE;
361 SetDParam(0, value);
362 ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
363 return;
364 } else if (btn == CHT_EDIT_MAX_HL && x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH) {
365 clicked_widget = CHT_EDIT_MAX_HL;
366 SetDParam(0, value);
367 ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
368 return;
369 }
370
371 /* Not clicking a button? */
372 if (!IsInsideMM(x, WidgetDimensions::scaled.hsep_wide * 2 + this->box.width, WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH)) return;
373
374 *ce->been_used = true;
375
376 switch (ce->type) {
377 case SLE_BOOL:
378 value ^= 1;
379 if (ce->proc != nullptr) ce->proc(value, 0);
380 break;
381
382 default:
383 /* Take whatever the function returns */
384 value = ce->proc(value + ((x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
385
386 /* The first cheat (money), doesn't return a different value. */
387 if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
388 break;
389 }
390
391 if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
392
393 this->SetTimeout();
394
395 this->SetDirty();
396 }
397
398 void OnTimeout() override
399 {
400 this->clicked = 0;
401 this->SetDirty();
402 }
403
404 void OnQueryTextFinished(char *str) override
405 {
406 /* Was 'cancel' pressed or nothing entered? */
407 if (str == nullptr || StrEmpty(str)) return;
408
409 const CheatEntry *ce = &_cheats_ui[clicked_widget];
410 int oldvalue = (int32)ReadValue(ce->variable, ce->type);
411 int value = atoi(str);
412 *ce->been_used = true;
413 value = ce->proc(value, value - oldvalue);
414
415 if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
416 this->SetDirty();
417 }
418 };
419
421 static WindowDesc _cheats_desc(
422 WDP_AUTO, "cheats", 0, 0,
423 WC_CHEATS, WC_NONE,
424 0,
425 _nested_cheat_widgets, lengthof(_nested_cheat_widgets)
426 );
427
429 void ShowCheatWindow()
430 {
431 CloseWindowById(WC_CHEATS, 0);
432 new CheatWindow(&_cheats_desc);
433 }
CheatEntry::type
VarType type
type of selector
Definition: cheat_gui.cpp:177
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:295
YearMonthDay::day
Day day
Day (1..31)
Definition: date_type.h:107
Cheats::no_jetcrash
Cheat no_jetcrash
no jet will crash on small airports anymore
Definition: cheat_type.h:31
IsInsideMM
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:230
Cheats::crossing_tunnels
Cheat crossing_tunnels
allow tunnels that cross each other
Definition: cheat_type.h:30
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3156
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3247
WID_C_NOTE
@ WID_C_NOTE
Note on top of panel for use of cheat.
Definition: cheat_widget.h:15
LinkGraphSchedule::ShiftDates
void ShiftDates(int interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
Definition: linkgraphschedule.cpp:135
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
_money_cheat_amount
static int32 _money_cheat_amount
The 'amount' to cheat with.
Definition: cheat_gui.cpp:46
Cheats::edit_max_hl
Cheat edit_max_hl
edit the maximum heightlevel; this is a cheat because of the fact that it needs to reset NewGRF game ...
Definition: cheat_type.h:34
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
company_base.h
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
CheatWindow
GUI for the cheats.
Definition: cheat_gui.cpp:216
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
company_gui.h
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
_cheats_desc
static WindowDesc _cheats_desc(WDP_AUTO, "cheats", 0, 0, WC_CHEATS, WC_NONE, 0, _nested_cheat_widgets, lengthof(_nested_cheat_widgets))
Window description of the cheats GUI.
CheatEntry
Information of a cheat.
Definition: cheat_gui.cpp:176
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
ConstructionSettings::map_height_limit
uint8 map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:342
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:356
CheatWindow::icon
Dimension icon
Dimension of company icon sprite.
Definition: cheat_gui.cpp:221
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition: linkgraphschedule.h:52
map_func.h
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
SetDate
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:37
misc_cmd.h
CheatWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: cheat_gui.cpp:298
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition: cheat_type.h:33
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
SetLocalCompany
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
Definition: company_cmd.cpp:103
vehicle_base.h
CHT_CHANGE_COMPANY
@ CHT_CHANGE_COMPANY
Switch company.
Definition: cheat_gui.cpp:157
saveload.h
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
WC_BUILD_STATION
@ WC_BUILD_STATION
Build station; Window numbers:
Definition: window_type.h:390
ClickChangeMaxHlCheat
static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
Allow (or disallow) a change of the maximum allowed heightlevel.
Definition: cheat_gui.cpp:130
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
WC_CHEATS
@ WC_CHEATS
Cheat window; Window numbers:
Definition: window_type.h:618
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
CheatEntry::been_used
bool * been_used
has this cheat been used before?
Definition: cheat_gui.cpp:180
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
textbuf_gui.h
CHT_MONEY
@ CHT_MONEY
Change amount of money.
Definition: cheat_gui.cpp:156
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
CheatNumbers
CheatNumbers
Available cheats.
Definition: cheat_gui.cpp:155
WindowDesc
High level window description.
Definition: window_gui.h:102
ClickChangeDateCheat
static int32 ClickChangeDateCheat(int32 p1, int32 p2)
Handle changing of the current year.
Definition: cheat_gui.cpp:103
window_gui.h
Pool::PoolItem<&_company_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:358
CHT_EDIT_MAX_HL
@ CHT_EDIT_MAX_HL
Edit maximum allowed heightlevel.
Definition: cheat_gui.cpp:162
tile_map.h
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
CheatWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: cheat_gui.cpp:398
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
Cheats::money
Cheat money
get rich or poor
Definition: cheat_type.h:29
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
CheatEntry::proc
CheckButtonClick * proc
procedure
Definition: cheat_gui.cpp:181
MIN_YEAR
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:84
MAX_MAP_HEIGHT_LIMIT
static const uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:30
YearMonthDay::month
Month month
Month (0..11)
Definition: date_type.h:106
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
CHT_NUM_CHEATS
@ CHT_NUM_CHEATS
Number of cheats.
Definition: cheat_gui.cpp:165
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
CheatWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: cheat_gui.cpp:344
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1115
CheatEntry::variable
void * variable
pointer to the variable
Definition: cheat_gui.cpp:179
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
ClickMoneyCheat
static int32 ClickMoneyCheat(int32 p1, int32 p2)
Handle cheating of money.
Definition: cheat_gui.cpp:57
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1058
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
date_func.h
linkgraphschedule.h
stdafx.h
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2539
CheatWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: cheat_gui.cpp:228
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
_cheats_ui
static const CheatEntry _cheats_ui[]
The available cheats.
Definition: cheat_gui.cpp:188
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:147
WriteValue
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:829
CheatWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: cheat_gui.cpp:234
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
string_func.h
rail_gui.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
strings_func.h
ClickSetProdCheat
static int32 ClickSetProdCheat(int32 p1, int32 p2)
Allow (or disallow) changing production of all industries.
Definition: cheat_gui.cpp:88
MIN_MAP_HEIGHT_LIMIT
static const uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:29
CheatEntry::str
StringID str
string with descriptive text
Definition: cheat_gui.cpp:178
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
_nested_cheat_widgets
static const NWidgetPart _nested_cheat_widgets[]
Widget definitions of the cheat GUI.
Definition: cheat_gui.cpp:202
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
geometry_func.hpp
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:95
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3271
cheat_type.h
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
CHT_SETUP_PROD
@ CHT_SETUP_PROD
Allow manually editing of industry production.
Definition: cheat_gui.cpp:161
newgrf.h
Cheats::change_date
Cheat change_date
changes date ingame
Definition: cheat_type.h:32
CHT_NO_JETCRASH
@ CHT_NO_JETCRASH
Disable jet-airplane crashes.
Definition: cheat_gui.cpp:160
company_func.h
CheckButtonClick
int32 CheckButtonClick(int32 p1, int32 p2)
Signature of handler function when user clicks at a cheat.
Definition: cheat_gui.cpp:173
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
ClickChangeCompanyCheat
static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
Handle changing of company.
Definition: cheat_gui.cpp:69
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
CommandHelper
Definition: command_func.h:94
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
WC_BUILD_OBJECT
@ WC_BUILD_OBJECT
Build object; Window numbers:
Definition: window_type.h:369
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
CHT_CROSSINGTUNNELS
@ CHT_CROSSINGTUNNELS
Allow tunnels to cross each other.
Definition: cheat_gui.cpp:159
CheatWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: cheat_gui.cpp:404
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
ResetSignalVariant
void ResetSignalVariant(int32 new_value)
Updates the current signal variant used in the signal GUI to the one adequate to current year.
Definition: rail_gui.cpp:2207
ReadValue
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:805
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
Window
Data structure for an opened window.
Definition: window_gui.h:213
cheat_widget.h
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:57
Cheat::been_used
bool been_used
has this cheat been used before?
Definition: cheat_type.h:17
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2591
settings_gui.h
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
WID_C_PANEL
@ WID_C_PANEL
Panel where all cheats are shown in.
Definition: cheat_widget.h:16
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
Cheats::switch_company
Cheat switch_company
change to another company
Definition: cheat_type.h:28
CheatWindow::box
Dimension box
Dimension of box sprite.
Definition: cheat_gui.cpp:220
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:97
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
CHT_CHANGE_DATE
@ CHT_CHANGE_DATE
Do time traveling.
Definition: cheat_gui.cpp:163
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
EnginesMonthlyLoop
void EnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition: engine.cpp:1066
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
CHT_EXTRA_DYNAMITE
@ CHT_EXTRA_DYNAMITE
Dynamite anything.
Definition: cheat_gui.cpp:158
ShowCheatWindow
void ShowCheatWindow()
Open cheat window.
Definition: cheat_gui.cpp:429
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:95
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62