openttd updated to 1.5.0-beta2

--HG--
branch : openttd
This commit is contained in:
Pavel Stupnikov
2015-03-01 00:30:53 +03:00
parent 0abb47ce90
commit d201932121
682 changed files with 26103 additions and 16553 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: cheat_gui.cpp 25867 2013-10-15 17:32:31Z fonsinchen $ */
/* $Id: cheat_gui.cpp 27151 2015-02-14 21:55:30Z frosch $ */
/*
* This file is part of OpenTTD.
@@ -25,11 +25,17 @@
#include "settings_gui.h"
#include "company_gui.h"
#include "linkgraph/linkgraphschedule.h"
#include "map_func.h"
#include "tile_map.h"
#include "newgrf.h"
#include "error.h"
#include "widgets/cheat_widget.h"
#include "table/sprites.h"
#include "safeguards.h"
/**
* The 'amount' to cheat with.
@@ -112,6 +118,37 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
return _cur_year;
}
/**
* Allow (or disallow) a change of the maximum allowed heightlevel.
* @param p1 new value
* @param p2 unused
* @return New value (or unchanged old value) of the maximum
* allowed heightlevel value.
*/
static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
{
p1 = Clamp(p1, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (TileIndex t = 0; t < MapSize(); t++) {
if ((int32)TileHeight(t) > p1) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */
return _settings_game.construction.max_heightlevel;
}
}
/* Execute the change and reload GRF Data */
_settings_game.construction.max_heightlevel = p1;
ReloadNewGRFData();
/* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
InvalidateWindowClassesData(WC_SMALLMAP, 2);
return _settings_game.construction.max_heightlevel;
}
/** Available cheats. */
enum CheatNumbers {
CHT_MONEY, ///< Change amount of money.
@@ -120,6 +157,7 @@ enum CheatNumbers {
CHT_CROSSINGTUNNELS, ///< Allow tunnels to cross each other.
CHT_NO_JETCRASH, ///< Disable jet-airplane crashes.
CHT_SETUP_PROD, ///< Allow manually editing of industry production.
CHT_EDIT_MAX_HL, ///< Edit maximum allowed heightlevel
CHT_CHANGE_DATE, ///< Do time traveling.
CHT_NUM_CHEATS, ///< Number of cheats.
@@ -152,6 +190,7 @@ static const CheatEntry _cheats_ui[] = {
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL },
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL },
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
{SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.max_heightlevel, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
};
@@ -172,9 +211,13 @@ static const NWidgetPart _nested_cheat_widgets[] = {
struct CheatWindow : Window {
int clicked;
int header_height;
int clicked_widget;
uint line_height;
int box_width;
CheatWindow(WindowDesc *desc) : Window(desc)
{
this->box_width = GetSpriteSize(SPR_BOX_EMPTY).width;
this->InitNested();
}
@@ -186,21 +229,24 @@ struct CheatWindow : Window {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, y, STR_CHEATS_WARNING, TC_FROMSTRING, SA_CENTER);
bool rtl = _current_text_dir == TD_RTL;
uint box_left = rtl ? r.right - 12 : r.left + 5;
uint button_left = rtl ? r.right - 20 - SETTING_BUTTON_WIDTH : r.left + 20;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 30 + SETTING_BUTTON_WIDTH);
uint text_right = r.right - (rtl ? 30 + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT);
uint box_left = rtl ? r.right - this->box_width - 5 : r.left + 5;
uint button_left = rtl ? r.right - this->box_width - 10 - SETTING_BUTTON_WIDTH : r.left + this->box_width + 10;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 20 + this->box_width + SETTING_BUTTON_WIDTH);
uint text_right = r.right - (rtl ? 20 + this->box_width + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT);
int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
int icon_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
for (int i = 0; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i];
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + 2);
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + icon_y_offset + 2);
switch (ce->type) {
case SLE_BOOL: {
bool on = (*(bool*)ce->variable);
DrawBoolButton(button_left, y, on, true);
DrawBoolButton(button_left, y + icon_y_offset, on, true);
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
break;
}
@@ -210,7 +256,7 @@ struct CheatWindow : Window {
char buf[512];
/* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(button_left, y, COLOUR_YELLOW, clicked - (i * 2), true, true);
DrawArrowButtons(button_left, y + icon_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
switch (ce->str) {
/* Display date for change date cheat */
@@ -221,7 +267,7 @@ struct CheatWindow : Window {
SetDParam(0, val + 1);
GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf));
uint offset = 10 + GetStringBoundingBox(buf).width;
DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + 2);
DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + icon_y_offset + 2);
break;
}
@@ -231,9 +277,9 @@ struct CheatWindow : Window {
}
}
DrawString(text_left, text_right, y + 1, ce->str);
DrawString(text_left, text_right, y + text_y_offset, ce->str);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
y += this->line_height;
}
}
@@ -275,16 +321,20 @@ struct CheatWindow : Window {
}
}
size->width = width + 50 /* stuff on the left */ + 10 /* extra spacing on right */;
this->line_height = max(GetSpriteSize(SPR_BOX_CHECKED).height, GetSpriteSize(SPR_BOX_EMPTY).height);
this->line_height = max<uint>(this->line_height, SETTING_BUTTON_HEIGHT);
this->line_height = max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WD_PAR_VSEP_NORMAL;
size->width = width + 20 + this->box_width + SETTING_BUTTON_WIDTH /* stuff on the left */ + 10 /* extra spacing on right */;
this->header_height = GetStringHeight(STR_CHEATS_WARNING, size->width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT) + WD_PAR_VSEP_WIDE;
size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL) * lengthof(_cheats_ui);
size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui);
}
virtual void OnClick(Point pt, int widget, int click_count)
{
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_C_PANEL);
uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL);
uint x = pt.x - wid->pos_x;
uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / this->line_height;
int x = pt.x - wid->pos_x;
bool rtl = _current_text_dir == TD_RTL;
if (rtl) x = wid->current_x - x;
@@ -294,15 +344,21 @@ struct CheatWindow : Window {
int value = (int32)ReadValue(ce->variable, ce->type);
int oldvalue = value;
if (btn == CHT_CHANGE_DATE && x >= 20 + SETTING_BUTTON_WIDTH) {
if (btn == CHT_CHANGE_DATE && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) {
/* Click at the date text directly. */
clicked_widget = CHT_CHANGE_DATE;
SetDParam(0, value);
ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
return;
} else if (btn == CHT_EDIT_MAX_HL && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) {
clicked_widget = CHT_EDIT_MAX_HL;
SetDParam(0, value);
ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
return;
}
/* Not clicking a button? */
if (!IsInsideMM(x, 20, 20 + SETTING_BUTTON_WIDTH)) return;
if (!IsInsideMM(x, 10 + this->box_width, 10 + this->box_width + SETTING_BUTTON_WIDTH)) return;
*ce->been_used = true;
@@ -314,10 +370,10 @@ struct CheatWindow : Window {
default:
/* Take whatever the function returns */
value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
/* The first cheat (money), doesn't return a different value. */
if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
break;
}
@@ -339,7 +395,7 @@ struct CheatWindow : Window {
/* Was 'cancel' pressed or nothing entered? */
if (str == NULL || StrEmpty(str)) return;
const CheatEntry *ce = &_cheats_ui[CHT_CHANGE_DATE];
const CheatEntry *ce = &_cheats_ui[clicked_widget];
int oldvalue = (int32)ReadValue(ce->variable, ce->type);
int value = atoi(str);
*ce->been_used = true;