2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file misc_gui.cpp GUIs for a number of misc windows. */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2010-06-03 11:05:20 +00:00
|
|
|
#include "debug.h"
|
2007-04-12 13:07:15 +00:00
|
|
|
#include "landscape.h"
|
2007-10-17 20:09:16 +00:00
|
|
|
#include "newgrf_text.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
2010-06-03 11:05:20 +00:00
|
|
|
#include "string_func.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "company_base.h"
|
|
|
|
#include "texteff.hpp"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_manager_face.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "zoom_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-05-11 12:26:20 +00:00
|
|
|
#include "querystring_gui.h"
|
2010-02-24 14:46:15 +00:00
|
|
|
#include "console_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2010-04-24 13:39:11 +00:00
|
|
|
#include "newgrf_debug.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-10-04 21:08:38 +00:00
|
|
|
/**
|
|
|
|
* Try to retrive the current clipboard contents.
|
|
|
|
*
|
|
|
|
* @note OS-specific funtion.
|
|
|
|
* @return True if some text could be retrived.
|
|
|
|
*/
|
|
|
|
bool GetClipboardContents(char *buffer, size_t buff_len);
|
|
|
|
|
2009-02-25 21:45:14 +00:00
|
|
|
int _caret_timer;
|
2005-03-28 08:48:41 +00:00
|
|
|
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2009-03-21 20:40:02 +00:00
|
|
|
/** Widgets for the land info window. */
|
|
|
|
enum LandInfoWidgets {
|
|
|
|
LIW_BACKGROUND, ///< Background to draw on
|
|
|
|
};
|
|
|
|
|
2009-04-11 19:14:34 +00:00
|
|
|
static const NWidgetPart _nested_land_info_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2010-04-24 13:39:11 +00:00
|
|
|
NWidget(WWT_DEBUGBOX, COLOUR_GREY),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
2009-08-30 17:07:53 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, LIW_BACKGROUND), EndContainer(),
|
2009-04-11 19:14:34 +00:00
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _land_info_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_LAND_INFO, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_land_info_widgets, lengthof(_nested_land_info_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-08 19:26:55 +00:00
|
|
|
class LandInfoWindow : public Window {
|
2010-05-13 10:14:29 +00:00
|
|
|
enum LandInfoLines {
|
2008-07-25 22:37:34 +00:00
|
|
|
LAND_INFO_CENTERED_LINES = 12, ///< Up to 12 centered lines
|
2008-05-21 22:15:39 +00:00
|
|
|
LAND_INFO_MULTICENTER_LINE = LAND_INFO_CENTERED_LINES, ///< One multicenter line
|
|
|
|
LAND_INFO_LINE_END,
|
2008-05-08 19:26:55 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-05-13 10:14:29 +00:00
|
|
|
static const uint LAND_INFO_LINE_BUFF_SIZE = 512;
|
|
|
|
|
2008-05-08 19:26:55 +00:00
|
|
|
public:
|
2008-05-21 22:15:39 +00:00
|
|
|
char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE];
|
2010-04-24 13:39:11 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-10 19:59:41 +00:00
|
|
|
virtual void OnPaint()
|
2008-05-08 19:26:55 +00:00
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-08-30 17:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != LIW_BACKGROUND) return;
|
|
|
|
|
|
|
|
uint y = r.top + WD_TEXTPANEL_TOP;
|
|
|
|
for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
|
|
|
|
if (StrEmpty(this->landinfo_data[i])) break;
|
|
|
|
|
2010-07-02 13:53:05 +00:00
|
|
|
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
|
2009-08-30 17:07:53 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
|
|
|
if (i == 0) y += 4;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-08-30 17:07:53 +00:00
|
|
|
if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
|
|
|
|
SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
|
|
|
|
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_TEXTPANEL_BOTTOM, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-30 17:07:53 +00:00
|
|
|
{
|
|
|
|
if (widget != LIW_BACKGROUND) return;
|
|
|
|
|
|
|
|
size->height = WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
|
2008-05-21 22:15:39 +00:00
|
|
|
for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
|
2008-06-21 18:59:15 +00:00
|
|
|
if (StrEmpty(this->landinfo_data[i])) break;
|
2008-05-21 22:15:39 +00:00
|
|
|
|
2009-08-30 17:07:53 +00:00
|
|
|
uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
|
|
|
|
size->width = max(size->width, width);
|
|
|
|
|
|
|
|
size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
|
|
|
if (i == 0) size->height += 4;
|
2008-05-21 22:15:39 +00:00
|
|
|
}
|
|
|
|
|
2008-07-17 13:47:04 +00:00
|
|
|
if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
|
2009-08-30 17:07:53 +00:00
|
|
|
uint width = GetStringBoundingBox(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
|
|
|
|
size->width = max(size->width, min(300u, width));
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
|
2009-11-21 17:22:37 +00:00
|
|
|
size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
|
2008-07-17 13:47:04 +00:00
|
|
|
}
|
2008-05-08 19:26:55 +00:00
|
|
|
}
|
2008-04-04 17:27:38 +00:00
|
|
|
|
2010-04-24 13:39:11 +00:00
|
|
|
LandInfoWindow(TileIndex tile) : Window(), tile(tile) {
|
2008-05-29 15:13:28 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
|
2007-01-10 16:31:40 +00:00
|
|
|
|
2008-05-08 19:26:55 +00:00
|
|
|
/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
|
|
|
|
TileDesc td;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-07-25 19:50:40 +00:00
|
|
|
td.build_date = INVALID_DATE;
|
2008-05-21 22:15:39 +00:00
|
|
|
|
|
|
|
/* Most tiles have only one owner, but
|
|
|
|
* - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
|
|
|
|
* - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
|
|
|
|
*/
|
2009-04-21 23:40:56 +00:00
|
|
|
td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
|
2008-05-21 22:15:39 +00:00
|
|
|
td.owner_type[1] = STR_NULL; // STR_NULL results in skipping the owner
|
|
|
|
td.owner_type[2] = STR_NULL;
|
|
|
|
td.owner_type[3] = STR_NULL;
|
|
|
|
td.owner[0] = OWNER_NONE;
|
|
|
|
td.owner[1] = OWNER_NONE;
|
|
|
|
td.owner[2] = OWNER_NONE;
|
|
|
|
td.owner[3] = OWNER_NONE;
|
|
|
|
|
2008-07-25 22:37:34 +00:00
|
|
|
td.station_class = STR_NULL;
|
|
|
|
td.station_name = STR_NULL;
|
2010-09-01 23:14:15 +00:00
|
|
|
td.airport_class = STR_NULL;
|
|
|
|
td.airport_name = STR_NULL;
|
2010-02-22 14:17:17 +00:00
|
|
|
td.airport_tile_name = STR_NULL;
|
2010-03-16 06:43:41 +00:00
|
|
|
td.rail_speed = 0;
|
2008-07-25 22:37:34 +00:00
|
|
|
|
|
|
|
td.grf = NULL;
|
|
|
|
|
2009-06-27 18:26:50 +00:00
|
|
|
CargoArray acceptance;
|
2009-09-07 07:39:08 +00:00
|
|
|
AddAcceptedCargo(tile, acceptance, NULL);
|
2008-05-08 19:26:55 +00:00
|
|
|
GetTileDesc(tile, &td);
|
2007-01-10 16:31:40 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
uint line_nr = 0;
|
|
|
|
|
|
|
|
/* Tiletype */
|
2008-05-08 19:26:55 +00:00
|
|
|
SetDParam(0, td.dparam[0]);
|
2008-05-21 22:15:39 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
2007-01-10 16:31:40 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
/* Up to four owners */
|
|
|
|
for (uint i = 0; i < 4; i++) {
|
|
|
|
if (td.owner_type[i] == STR_NULL) continue;
|
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A);
|
2008-05-21 22:15:39 +00:00
|
|
|
if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile);
|
|
|
|
GetString(this->landinfo_data[line_nr], td.owner_type[i], lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
|
|
|
}
|
2008-05-08 19:26:55 +00:00
|
|
|
|
2008-12-26 23:37:53 +00:00
|
|
|
/* Cost to clear/revenue when cleared */
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
|
2009-05-19 19:26:03 +00:00
|
|
|
Company *c = Company::GetIfValid(_local_company);
|
|
|
|
if (c != NULL) {
|
|
|
|
Money old_money = c->money;
|
|
|
|
c->money = INT64_MAX;
|
|
|
|
CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
|
|
|
c->money = old_money;
|
2010-01-18 22:57:21 +00:00
|
|
|
if (costclear.Succeeded()) {
|
2009-05-19 19:26:03 +00:00
|
|
|
Money cost = costclear.GetCost();
|
|
|
|
if (cost < 0) {
|
|
|
|
cost = -cost; // Negate negative cost to a positive revenue
|
2009-08-05 17:59:21 +00:00
|
|
|
str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
|
2009-05-19 19:26:03 +00:00
|
|
|
} else {
|
|
|
|
str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
|
|
|
|
}
|
|
|
|
SetDParam(0, cost);
|
2008-12-26 23:37:53 +00:00
|
|
|
}
|
2008-05-08 19:26:55 +00:00
|
|
|
}
|
2008-05-21 22:15:39 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], str, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
2008-05-08 19:26:55 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
/* Location */
|
2008-07-17 13:47:04 +00:00
|
|
|
char tmp[16];
|
|
|
|
snprintf(tmp, lengthof(tmp), "0x%.4X", tile);
|
2008-05-08 19:26:55 +00:00
|
|
|
SetDParam(0, TileX(tile));
|
|
|
|
SetDParam(1, TileY(tile));
|
|
|
|
SetDParam(2, TileHeight(tile));
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(3, tmp);
|
2009-08-05 17:59:21 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, lastof(this->landinfo_data[line_nr]));
|
2008-05-21 22:15:39 +00:00
|
|
|
line_nr++;
|
2008-05-08 19:26:55 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
/* Local authority */
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
|
2009-05-22 15:13:50 +00:00
|
|
|
if (t != NULL) {
|
2009-07-20 11:21:57 +00:00
|
|
|
SetDParam(0, STR_TOWN_NAME);
|
2008-05-08 19:26:55 +00:00
|
|
|
SetDParam(1, t->index);
|
|
|
|
}
|
2009-04-21 23:40:56 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));
|
2008-05-21 22:15:39 +00:00
|
|
|
line_nr++;
|
2008-05-08 19:26:55 +00:00
|
|
|
|
2008-05-21 22:15:39 +00:00
|
|
|
/* Build date */
|
2008-07-25 19:50:40 +00:00
|
|
|
if (td.build_date != INVALID_DATE) {
|
2008-05-21 22:15:39 +00:00
|
|
|
SetDParam(0, td.build_date);
|
2009-08-05 17:59:21 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_BUILD_DATE, lastof(this->landinfo_data[line_nr]));
|
2008-05-21 22:15:39 +00:00
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
2008-07-25 22:37:34 +00:00
|
|
|
/* Station class */
|
|
|
|
if (td.station_class != STR_NULL) {
|
|
|
|
SetDParam(0, td.station_class);
|
2009-08-05 17:59:21 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_CLASS, lastof(this->landinfo_data[line_nr]));
|
2008-07-25 22:37:34 +00:00
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Station type name */
|
|
|
|
if (td.station_name != STR_NULL) {
|
|
|
|
SetDParam(0, td.station_name);
|
2009-08-05 17:59:21 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_TYPE, lastof(this->landinfo_data[line_nr]));
|
2008-07-25 22:37:34 +00:00
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
2010-09-01 23:14:15 +00:00
|
|
|
/* Airport class */
|
|
|
|
if (td.airport_class != STR_NULL) {
|
|
|
|
SetDParam(0, td.airport_class);
|
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Airport name */
|
|
|
|
if (td.airport_name != STR_NULL) {
|
|
|
|
SetDParam(0, td.airport_name);
|
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_NAME, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Airport tile name */
|
2010-02-22 14:17:17 +00:00
|
|
|
if (td.airport_tile_name != STR_NULL) {
|
|
|
|
SetDParam(0, td.airport_tile_name);
|
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
2010-03-16 06:43:41 +00:00
|
|
|
/* Rail speed limit */
|
|
|
|
if (td.rail_speed != 0) {
|
|
|
|
SetDParam(0, td.rail_speed);
|
|
|
|
GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
|
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
2008-07-25 22:37:34 +00:00
|
|
|
/* NewGRF name */
|
|
|
|
if (td.grf != NULL) {
|
|
|
|
SetDParamStr(0, td.grf);
|
2009-08-05 17:59:21 +00:00
|
|
|
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_NEWGRF_NAME, lastof(this->landinfo_data[line_nr]));
|
2008-07-25 22:37:34 +00:00
|
|
|
line_nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(line_nr < LAND_INFO_CENTERED_LINES);
|
|
|
|
|
2008-06-21 18:59:15 +00:00
|
|
|
/* Mark last line empty */
|
|
|
|
this->landinfo_data[line_nr][0] = '\0';
|
2008-05-21 22:15:39 +00:00
|
|
|
|
|
|
|
/* Cargo acceptance is displayed in a extra multiline */
|
2009-04-21 23:40:56 +00:00
|
|
|
char *strp = GetString(this->landinfo_data[LAND_INFO_MULTICENTER_LINE], STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
|
2008-05-08 19:26:55 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
2009-06-27 18:26:50 +00:00
|
|
|
if (acceptance[i] > 0) {
|
2008-05-08 19:26:55 +00:00
|
|
|
/* Add a comma between each item. */
|
|
|
|
if (found) {
|
|
|
|
*strp++ = ',';
|
|
|
|
*strp++ = ' ';
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
/* If the accepted value is less than 8, show it in 1/8:ths */
|
2009-06-27 18:26:50 +00:00
|
|
|
if (acceptance[i] < 8) {
|
|
|
|
SetDParam(0, acceptance[i]);
|
2009-07-16 19:00:13 +00:00
|
|
|
SetDParam(1, CargoSpec::Get(i)->name);
|
2009-04-21 23:40:56 +00:00
|
|
|
strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
|
2008-05-08 19:26:55 +00:00
|
|
|
} else {
|
2009-07-16 19:00:13 +00:00
|
|
|
strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
|
2008-05-08 19:26:55 +00:00
|
|
|
}
|
2007-01-10 16:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-21 22:15:39 +00:00
|
|
|
if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0';
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-08-30 17:07:53 +00:00
|
|
|
this->InitNested(&_land_info_desc);
|
2008-06-21 18:59:15 +00:00
|
|
|
|
2006-06-10 08:37:41 +00:00
|
|
|
#if defined(_DEBUG)
|
|
|
|
# define LANDINFOD_LEVEL 0
|
|
|
|
#else
|
|
|
|
# define LANDINFOD_LEVEL 1
|
|
|
|
#endif
|
2008-05-08 19:26:55 +00:00
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "type_height = %#x", _m[tile].type_height);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6);
|
|
|
|
DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7);
|
2006-06-10 08:37:41 +00:00
|
|
|
#undef LANDINFOD_LEVEL
|
2008-05-08 19:26:55 +00:00
|
|
|
}
|
2010-04-24 13:39:11 +00:00
|
|
|
|
|
|
|
virtual bool IsNewGRFInspectable() const
|
|
|
|
{
|
|
|
|
return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ShowNewGRFInspectWindow() const
|
|
|
|
{
|
|
|
|
::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile);
|
|
|
|
}
|
2008-05-08 19:26:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void Place_LandInfo(TileIndex tile)
|
|
|
|
{
|
|
|
|
DeleteWindowById(WC_LAND_INFO, 0);
|
|
|
|
new LandInfoWindow(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void PlaceLandBlockInfo()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-06 13:47:06 +00:00
|
|
|
if (_cursor.sprite == SPR_CURSOR_QUERY) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
} else {
|
|
|
|
_place_proc = Place_LandInfo;
|
2009-04-19 10:31:30 +00:00
|
|
|
SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-21 20:40:02 +00:00
|
|
|
/** Widgets for the land info window. */
|
|
|
|
enum AboutWidgets {
|
2009-11-19 22:49:04 +00:00
|
|
|
AW_SCROLLING_TEXT, ///< The actually scrolling text
|
2009-08-29 20:54:32 +00:00
|
|
|
AW_WEBSITE, ///< URL of OpenTTD website
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-04-11 19:14:34 +00:00
|
|
|
static const NWidgetPart _nested_about_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
|
2009-11-28 15:00:45 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_ORIGINAL_COPYRIGHT, STR_NULL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_VERSION, STR_NULL),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
|
2009-11-19 22:49:04 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, AW_SCROLLING_TEXT),
|
|
|
|
EndContainer(),
|
2009-11-28 15:00:45 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY, AW_WEBSITE), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_COPYRIGHT_OPENTTD, STR_NULL),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _about_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_CENTER, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_about_widgets, lengthof(_nested_about_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-20 23:11:01 +00:00
|
|
|
static const char * const _credits[] = {
|
2009-08-29 20:54:32 +00:00
|
|
|
"Original design by Chris Sawyer",
|
|
|
|
"Original graphics by Simon Foster",
|
|
|
|
"",
|
|
|
|
"The OpenTTD team (in alphabetical order):",
|
2009-11-15 21:07:39 +00:00
|
|
|
" Albert Hofkamp (Alberth) - GUI expert",
|
2010-02-04 17:11:46 +00:00
|
|
|
" Jean-Fran\xC3\xA7ois Claeys (Belugas) - GUI, newindustries and more",
|
2009-08-29 20:54:32 +00:00
|
|
|
" Matthijs Kooijman (blathijs) - Pathfinder-guru, pool rework",
|
|
|
|
" Christoph Elsenhans (frosch) - General coding",
|
|
|
|
" Lo\xC3\xAF""c Guilloux (glx) - Windows Expert",
|
|
|
|
" Michael Lutz (michi_cc) - Path based signals",
|
|
|
|
" Owen Rudge (orudge) - Forum host, OS/2 port",
|
2010-02-03 23:08:46 +00:00
|
|
|
" Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods",
|
2010-10-16 06:14:24 +00:00
|
|
|
" Ingo von Borstel (planetmaker) - Support",
|
2009-08-29 20:54:32 +00:00
|
|
|
" Remko Bijker (Rubidium) - Lead coder and way more",
|
|
|
|
" Zden\xC4\x9Bk Sojka (SmatZ) - Bug finder and fixer",
|
2010-02-03 23:08:46 +00:00
|
|
|
" Jos\xC3\xA9 Soler (Terkhen) - General coding",
|
2009-08-29 20:54:32 +00:00
|
|
|
" Thijs Marinussen (Yexo) - AI Framework",
|
|
|
|
"",
|
|
|
|
"Inactive Developers:",
|
2010-02-03 23:08:46 +00:00
|
|
|
" Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles",
|
|
|
|
" Victor Fischer (Celestar) - Programming everywhere you need him to",
|
2009-08-29 20:54:32 +00:00
|
|
|
" Tam\xC3\xA1s Farag\xC3\xB3 (Darkvater) - Ex-Lead coder",
|
|
|
|
" Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;)",
|
|
|
|
" Jonathan Coome (Maedhros) - High priest of the NewGRF Temple",
|
|
|
|
" Attila B\xC3\xA1n (MiHaMiX) - Developer WebTranslator 1 and 2",
|
|
|
|
" Christoph Mallon (Tron) - Programmer, code correctness police",
|
|
|
|
"",
|
|
|
|
"Retired Developers:",
|
|
|
|
" Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)",
|
|
|
|
" Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)",
|
|
|
|
" Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3.0 - 0.3.6)",
|
|
|
|
" Benedikt Br\xC3\xBCggemeier (skidd13) - Bug fixer and code reworker",
|
|
|
|
" Patric Stout (TrueLight) - Programmer (0.3 - pre0.7), sys op (active)",
|
|
|
|
"",
|
|
|
|
"Special thanks go out to:",
|
|
|
|
" Josef Drexler - For his great work on TTDPatch",
|
2010-07-15 22:30:38 +00:00
|
|
|
" Marcin Grzegorczyk - For describing Transport Tycoon Deluxe internals",
|
2009-09-17 18:56:31 +00:00
|
|
|
" Petr Baudi\xC5\xA1 (pasky) - Many patches, newGRF support",
|
2009-08-29 20:54:32 +00:00
|
|
|
" Stefan Mei\xC3\x9Fner (sign_de) - For his work on the console",
|
|
|
|
" Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with",
|
|
|
|
" Cian Duffy (MYOB) - BeOS port / manual writing",
|
|
|
|
" Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
|
|
|
|
" Richard Kempton (richK) - additional airports, initial TGP implementation",
|
|
|
|
"",
|
|
|
|
" Alberto Demichelis - Squirrel scripting language \xC2\xA9 2003-2008",
|
|
|
|
" L. Peter Deutsch - MD5 implementation \xC2\xA9 1999, 2000, 2002",
|
|
|
|
" Michael Blunck - Pre-Signals and Semaphores \xC2\xA9 2003",
|
|
|
|
" George - Canal/Lock graphics \xC2\xA9 2003-2004",
|
|
|
|
" David Dallaston - Tram tracks",
|
|
|
|
" Marcin Grzegorczyk - Foundations for Tracks on Slopes",
|
|
|
|
" All Translators - Who made OpenTTD a truly international game",
|
|
|
|
" Bug Reporters - Without whom OpenTTD would still be full of bugs!",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"And last but not least:",
|
|
|
|
" Chris Sawyer - For an amazing game!"
|
|
|
|
};
|
|
|
|
|
2008-05-14 20:01:06 +00:00
|
|
|
struct AboutWindow : public Window {
|
2009-08-29 20:54:32 +00:00
|
|
|
int text_position; ///< The top of the scrolling text
|
|
|
|
byte counter; ///< Used to scroll the text every 5 ticks
|
|
|
|
int line_height; ///< The height of a single line
|
2009-09-01 21:27:33 +00:00
|
|
|
static const int num_visible_lines = 19; ///< The number of lines visible simultaneously
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
AboutWindow() : Window()
|
2008-05-14 20:01:06 +00:00
|
|
|
{
|
2009-08-29 20:54:32 +00:00
|
|
|
this->InitNested(&_about_desc);
|
|
|
|
|
2008-05-14 20:01:06 +00:00
|
|
|
this->counter = 5;
|
2009-11-19 22:49:04 +00:00
|
|
|
this->text_position = this->GetWidget<NWidgetBase>(AW_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(AW_SCROLLING_TEXT)->current_y;
|
2008-05-14 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
2008-05-14 20:01:06 +00:00
|
|
|
{
|
2009-08-29 20:54:32 +00:00
|
|
|
if (widget == AW_WEBSITE) SetDParamStr(0, "Website: http://www.openttd.org");
|
|
|
|
}
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-29 20:54:32 +00:00
|
|
|
{
|
2009-11-19 22:49:04 +00:00
|
|
|
if (widget != AW_SCROLLING_TEXT) return;
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
this->line_height = FONT_HEIGHT_NORMAL;
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
Dimension d;
|
|
|
|
d.height = this->line_height * num_visible_lines;
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
d.width = 0;
|
|
|
|
for (uint i = 0; i < lengthof(_credits); i++) {
|
|
|
|
d.width = max(d.width, GetStringBoundingBox(_credits[i]).width);
|
2008-05-14 20:01:06 +00:00
|
|
|
}
|
2009-08-29 20:54:32 +00:00
|
|
|
*size = maxdim(*size, d);
|
|
|
|
}
|
2008-05-14 20:01:06 +00:00
|
|
|
|
2009-08-29 20:54:32 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
2009-11-19 22:49:04 +00:00
|
|
|
if (widget != AW_SCROLLING_TEXT) return;
|
2009-08-29 20:54:32 +00:00
|
|
|
|
|
|
|
int y = this->text_position;
|
|
|
|
|
|
|
|
/* Show all scrolling _credits */
|
|
|
|
for (uint i = 0; i < lengthof(_credits); i++) {
|
|
|
|
if (y >= r.top + 7 && y < r.bottom - this->line_height) {
|
2009-11-19 22:49:04 +00:00
|
|
|
DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
|
2009-08-29 20:54:32 +00:00
|
|
|
}
|
|
|
|
y += this->line_height;
|
|
|
|
}
|
2008-05-14 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnTick()
|
|
|
|
{
|
|
|
|
if (--this->counter == 0) {
|
|
|
|
this->counter = 5;
|
2009-08-29 20:54:32 +00:00
|
|
|
this->text_position--;
|
|
|
|
/* If the last text has scrolled start a new from the start */
|
2009-11-19 22:49:04 +00:00
|
|
|
if (this->text_position < (int)(this->GetWidget<NWidgetBase>(AW_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
|
|
|
|
this->text_position = this->GetWidget<NWidgetBase>(AW_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(AW_SCROLLING_TEXT)->current_y;
|
2009-08-29 20:54:32 +00:00
|
|
|
}
|
2008-05-14 20:01:06 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowAboutWindow()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
2008-05-14 20:01:06 +00:00
|
|
|
new AboutWindow();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 10:11:46 +00:00
|
|
|
/** Widgets of the error message windows */
|
|
|
|
enum ErrorMessageWidgets {
|
|
|
|
EMW_CAPTION,
|
|
|
|
EMW_FACE,
|
|
|
|
EMW_MESSAGE,
|
|
|
|
};
|
|
|
|
|
2009-05-04 18:42:49 +00:00
|
|
|
static const NWidgetPart _nested_errmsg_widgets[] = {
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_RED),
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_RED, EMW_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION, STR_NULL),
|
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_RED),
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_RED, EMW_MESSAGE), SetPadding(0, 2, 0, 2), SetMinimalSize(236, 32),
|
2009-05-04 18:42:49 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
static const WindowDesc _errmsg_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-11-01 14:28:53 +00:00
|
|
|
WC_ERRMSG, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_errmsg_widgets, lengthof(_nested_errmsg_widgets)
|
2009-11-01 14:28:53 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-04 18:42:49 +00:00
|
|
|
static const NWidgetPart _nested_errmsg_face_widgets[] = {
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_RED),
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_RED, EMW_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL),
|
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_RED),
|
2009-11-01 14:28:53 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(2, 1, 2),
|
2009-12-28 13:04:18 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_RED, EMW_FACE), SetMinimalSize(92, 119), SetFill(0, 1), SetPadding(2, 0, 1, 0),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_RED, EMW_MESSAGE), SetFill(0, 1), SetMinimalSize(238, 123),
|
2009-05-04 18:42:49 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
static const WindowDesc _errmsg_face_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-11-01 14:28:53 +00:00
|
|
|
WC_ERRMSG, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets)
|
2009-11-01 14:28:53 +00:00
|
|
|
);
|
|
|
|
|
2009-10-31 14:33:07 +00:00
|
|
|
/** Window class for displaying an error message window. */
|
2008-05-17 02:54:04 +00:00
|
|
|
struct ErrmsgWindow : public Window {
|
|
|
|
private:
|
2009-10-31 14:33:07 +00:00
|
|
|
uint duration; ///< Length of display of the message. 0 means forever,
|
|
|
|
uint64 decode_params[20]; ///< Parameters of the message strings.
|
2009-10-31 18:22:39 +00:00
|
|
|
StringID summary_msg; ///< General error message showed in first line. Must be valid.
|
2009-10-31 19:46:51 +00:00
|
|
|
StringID detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
|
2009-11-01 14:28:53 +00:00
|
|
|
uint height_summary; ///< Height of the #summary_msg string in pixels in the #EMW_MESSAGE widget.
|
|
|
|
uint height_detailed; ///< Height of the #detailed_msg string in pixels in the #EMW_MESSAGE widget.
|
|
|
|
Point position; ///< Position of the error message window.
|
2010-03-06 16:23:32 +00:00
|
|
|
CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2008-05-17 02:54:04 +00:00
|
|
|
public:
|
2010-03-06 16:23:32 +00:00
|
|
|
ErrmsgWindow(Point pt, StringID summary_msg, StringID detailed_msg, bool no_timeout) : Window()
|
2008-05-17 02:54:04 +00:00
|
|
|
{
|
2009-11-01 14:28:53 +00:00
|
|
|
this->position = pt;
|
2009-05-24 12:50:58 +00:00
|
|
|
this->duration = no_timeout ? 0 : _settings_client.gui.errmsg_duration;
|
2008-05-17 02:54:04 +00:00
|
|
|
CopyOutDParam(this->decode_params, 0, lengthof(this->decode_params));
|
2009-10-31 18:22:39 +00:00
|
|
|
this->summary_msg = summary_msg;
|
2009-10-31 19:46:51 +00:00
|
|
|
this->detailed_msg = detailed_msg;
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2010-03-06 16:23:32 +00:00
|
|
|
CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
|
2010-03-16 06:25:35 +00:00
|
|
|
this->face = (this->detailed_msg == STR_ERROR_OWNED_BY && company < MAX_COMPANIES) ? company : INVALID_COMPANY;
|
2010-03-06 16:23:32 +00:00
|
|
|
const WindowDesc *desc = (face == INVALID_COMPANY) ? &_errmsg_desc : &_errmsg_face_desc;
|
|
|
|
|
2009-10-31 18:22:39 +00:00
|
|
|
assert(summary_msg != INVALID_STRING_ID);
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
this->InitNested(desc);
|
|
|
|
}
|
2009-10-31 15:47:22 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-11-01 14:28:53 +00:00
|
|
|
{
|
|
|
|
if (widget != EMW_MESSAGE) return;
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
|
|
|
|
/* If the error message comes from a NewGRF, we must use the text ref. stack reserved for error messages.
|
|
|
|
* If the message doesn't come from a NewGRF, it won't use the TTDP-style text ref. stack, so we won't hurt anything
|
|
|
|
*/
|
|
|
|
SwitchToErrorRefStack();
|
|
|
|
RewindTextRefStack();
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
int text_width = max(0, (int)size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
|
2009-11-01 17:45:24 +00:00
|
|
|
this->height_summary = GetStringHeight(this->summary_msg, text_width);
|
|
|
|
this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, text_width);
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
SwitchToNormalRefStack(); // Switch back to the normal text ref. stack for NewGRF texts.
|
2008-07-22 19:25:47 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
uint panel_height = WD_FRAMERECT_TOP + this->height_summary + WD_FRAMERECT_BOTTOM;
|
2009-11-01 17:45:24 +00:00
|
|
|
if (this->detailed_msg != INVALID_STRING_ID) panel_height += this->height_detailed + WD_PAR_VSEP_WIDE;
|
2009-11-01 14:28:53 +00:00
|
|
|
|
|
|
|
size->height = max(size->height, panel_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
|
|
|
|
{
|
2009-11-01 17:38:14 +00:00
|
|
|
/* Position (0, 0) given, center the window. */
|
|
|
|
if (this->position.x == 0 && this->position.y == 0) {
|
|
|
|
Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2009-11-07 17:24:04 +00:00
|
|
|
/* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
|
2009-11-01 19:19:14 +00:00
|
|
|
* Add a fixed distance 20 to make it less cluttered.
|
|
|
|
*/
|
2009-11-07 17:24:04 +00:00
|
|
|
int scr_top = GetMainViewTop() + 20;
|
|
|
|
int scr_bot = GetMainViewBottom() - 20;
|
2009-11-01 19:19:14 +00:00
|
|
|
|
2009-11-01 17:38:14 +00:00
|
|
|
Point pt = RemapCoords2(this->position.x, this->position.y);
|
|
|
|
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
2010-03-06 16:23:32 +00:00
|
|
|
if (this->face == INVALID_COMPANY) {
|
2009-11-01 17:38:14 +00:00
|
|
|
/* move x pos to opposite corner */
|
|
|
|
pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
|
2009-11-01 19:19:14 +00:00
|
|
|
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; // Stay 20 pixels away from the edge of the screen.
|
2009-11-01 17:38:14 +00:00
|
|
|
|
|
|
|
/* move y pos to opposite corner */
|
|
|
|
pt.y = UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top;
|
2009-11-01 19:19:14 +00:00
|
|
|
pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
|
2009-11-01 17:38:14 +00:00
|
|
|
} else {
|
2009-11-01 17:45:24 +00:00
|
|
|
pt.x = Clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (sm_width / 2), 0, _screen.width - sm_width);
|
2009-11-01 19:19:14 +00:00
|
|
|
pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (sm_height / 2), scr_top, scr_bot - sm_height);
|
2009-11-01 17:38:14 +00:00
|
|
|
}
|
|
|
|
return pt;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-11-01 14:28:53 +00:00
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
|
2010-03-06 16:26:09 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
|
|
|
/* If company gets shut down, while displaying an error about it, remove the error message. */
|
|
|
|
if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this;
|
|
|
|
}
|
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == EMW_CAPTION) CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
|
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case EMW_FACE: {
|
2010-03-06 16:23:32 +00:00
|
|
|
const Company *c = Company::Get(this->face);
|
2009-11-01 14:28:53 +00:00
|
|
|
DrawCompanyManagerFace(c->face, c->colour, r.left, r.top);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
case EMW_MESSAGE:
|
|
|
|
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
|
|
|
|
SwitchToErrorRefStack();
|
|
|
|
RewindTextRefStack();
|
|
|
|
|
|
|
|
if (this->detailed_msg == INVALID_STRING_ID) {
|
|
|
|
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
|
|
|
|
this->summary_msg, TC_FROMSTRING, SA_CENTER);
|
|
|
|
} else {
|
|
|
|
int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
|
|
|
|
|
2010-08-16 12:32:49 +00:00
|
|
|
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
|
2009-11-01 14:28:53 +00:00
|
|
|
int top = r.top + WD_FRAMERECT_TOP;
|
|
|
|
int bottom = top + this->height_summary + extra;
|
2010-08-16 12:32:49 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_WHITE, SA_CENTER);
|
2009-11-01 14:28:53 +00:00
|
|
|
|
|
|
|
bottom = r.bottom - WD_FRAMERECT_BOTTOM;
|
|
|
|
top = bottom - this->height_detailed - extra;
|
2010-08-16 12:32:49 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_WHITE, SA_CENTER);
|
2009-11-01 14:28:53 +00:00
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
|
2009-11-01 14:28:53 +00:00
|
|
|
SwitchToNormalRefStack(); // Switch back to the normal text ref. stack for NewGRF texts.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnMouseLoop()
|
|
|
|
{
|
2009-05-24 12:50:58 +00:00
|
|
|
/* Disallow closing the window too easily, if timeout is disabled */
|
|
|
|
if (_right_button_down && this->duration != 0) delete this;
|
2008-05-17 02:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnHundredthTick()
|
|
|
|
{
|
2009-05-24 12:50:58 +00:00
|
|
|
/* Timeout enabled? */
|
|
|
|
if (this->duration != 0) {
|
|
|
|
this->duration--;
|
|
|
|
if (this->duration == 0) delete this;
|
|
|
|
}
|
2008-05-17 02:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~ErrmsgWindow()
|
|
|
|
{
|
2009-01-19 15:06:11 +00:00
|
|
|
SetRedErrorSquare(INVALID_TILE);
|
2008-05-17 02:54:04 +00:00
|
|
|
extern StringID _switch_mode_errorstr;
|
|
|
|
_switch_mode_errorstr = INVALID_STRING_ID;
|
|
|
|
}
|
|
|
|
|
2008-05-17 23:11:06 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
2008-05-17 02:54:04 +00:00
|
|
|
{
|
2008-05-17 23:11:06 +00:00
|
|
|
if (keycode != WKC_SPACE) return ES_NOT_HANDLED;
|
2008-05-17 02:54:04 +00:00
|
|
|
delete this;
|
2008-05-17 23:11:06 +00:00
|
|
|
return ES_HANDLED;
|
2008-05-17 02:54:04 +00:00
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-24 12:50:58 +00:00
|
|
|
/**
|
|
|
|
* Display an error message in a window.
|
2009-10-31 18:22:39 +00:00
|
|
|
* @param summary_msg General error message showed in first line. Must be valid.
|
2009-10-31 19:46:51 +00:00
|
|
|
* @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID.
|
2010-02-24 14:46:15 +00:00
|
|
|
* @param wl Message severity
|
2009-10-31 18:22:39 +00:00
|
|
|
* @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
|
|
|
|
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
|
2009-05-24 12:50:58 +00:00
|
|
|
*/
|
2010-02-24 14:46:15 +00:00
|
|
|
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-02-24 14:50:04 +00:00
|
|
|
if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
|
|
|
|
|
|
|
|
if (wl != WL_INFO) {
|
|
|
|
/* Print message to console */
|
|
|
|
char buf[DRAW_STRING_BUFFER];
|
|
|
|
char *b = GetString(buf, summary_msg, lastof(buf));
|
|
|
|
if (detailed_msg != INVALID_STRING_ID) {
|
|
|
|
b += seprintf(b, lastof(buf), " ");
|
|
|
|
GetString(b, detailed_msg, lastof(buf));
|
|
|
|
}
|
|
|
|
switch (wl) {
|
|
|
|
case WL_WARNING: IConsolePrint(CC_WARNING, buf); break;
|
|
|
|
default: IConsoleError(buf); break;
|
|
|
|
};
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-02-24 14:46:15 +00:00
|
|
|
bool no_timeout = wl == WL_CRITICAL;
|
|
|
|
|
2009-05-24 12:50:58 +00:00
|
|
|
if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-02-24 14:50:04 +00:00
|
|
|
DeleteWindowById(WC_ERRMSG, 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-11-01 17:38:14 +00:00
|
|
|
Point pt = {x, y};
|
2010-03-06 16:23:32 +00:00
|
|
|
new ErrmsgWindow(pt, summary_msg, detailed_msg, no_timeout);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID msg = STR_MESSAGE_ESTIMATED_COST;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (cost < 0) {
|
|
|
|
cost = -cost;
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_MESSAGE_ESTIMATED_INCOME;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, cost);
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(msg, INVALID_STRING_ID, WL_INFO, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-01-09 22:56:28 +00:00
|
|
|
Point pt = RemapCoords(x, y, z);
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID msg = STR_INCOME_FLOAT_COST;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (cost < 0) {
|
|
|
|
cost = -cost;
|
2009-04-21 23:40:56 +00:00
|
|
|
msg = STR_INCOME_FLOAT_INCOME;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, cost);
|
2009-12-25 23:22:41 +00:00
|
|
|
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
2005-06-15 16:58:15 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
void ShowFeederIncomeAnimation(int x, int y, int z, Money cost)
|
2005-06-15 16:58:15 +00:00
|
|
|
{
|
2009-01-09 22:56:28 +00:00
|
|
|
Point pt = RemapCoords(x, y, z);
|
2005-06-15 16:58:15 +00:00
|
|
|
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, cost);
|
2009-12-25 23:22:41 +00:00
|
|
|
AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
2007-06-21 16:17:47 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 18:28:44 +00:00
|
|
|
TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string)
|
2007-06-21 16:17:47 +00:00
|
|
|
{
|
|
|
|
Point pt = RemapCoords(x, y, z);
|
|
|
|
|
2007-06-22 18:28:44 +00:00
|
|
|
assert(string != STR_NULL);
|
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
SetDParam(0, percent);
|
2009-12-25 23:22:41 +00:00
|
|
|
return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
|
2007-06-21 16:17:47 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 18:28:44 +00:00
|
|
|
void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
|
2007-06-21 16:17:47 +00:00
|
|
|
{
|
2007-06-22 18:28:44 +00:00
|
|
|
assert(string != STR_NULL);
|
|
|
|
|
2007-06-21 16:17:47 +00:00
|
|
|
SetDParam(0, percent);
|
2007-06-22 18:28:44 +00:00
|
|
|
UpdateTextEffect(te_id, string);
|
2007-06-21 16:17:47 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 18:28:35 +00:00
|
|
|
void HideFillingPercent(TextEffectID *te_id)
|
2007-06-21 16:17:47 +00:00
|
|
|
{
|
2008-09-21 18:28:35 +00:00
|
|
|
if (*te_id == INVALID_TE_ID) return;
|
|
|
|
|
|
|
|
RemoveTextEffect(*te_id);
|
|
|
|
*te_id = INVALID_TE_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 18:42:49 +00:00
|
|
|
static const NWidgetPart _nested_tooltips_widgets[] = {
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, 0), SetMinimalSize(200, 32), EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-10-31 13:01:52 +00:00
|
|
|
static const WindowDesc _tool_tips_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_MANUAL, 0, 0, // Coordinates and sizes are not used,
|
2009-10-31 13:01:52 +00:00
|
|
|
WC_TOOLTIPS, WC_NONE,
|
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_tooltips_widgets, lengthof(_nested_tooltips_widgets)
|
2009-10-31 13:01:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/** Window for displaying a tooltip. */
|
2008-05-11 17:44:38 +00:00
|
|
|
struct TooltipsWindow : public Window
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-07-11 10:55:57 +00:00
|
|
|
StringID string_id; ///< String to display as tooltip.
|
|
|
|
byte paramcount; ///< Number of string parameters in #string_id.
|
|
|
|
uint64 params[5]; ///< The string parameters.
|
|
|
|
TooltipCloseCondition close_cond; ///< Condition for closing the window.
|
2006-10-12 15:13:40 +00:00
|
|
|
|
2010-07-11 10:55:57 +00:00
|
|
|
TooltipsWindow(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) : Window()
|
2008-05-11 17:44:38 +00:00
|
|
|
{
|
|
|
|
this->string_id = str;
|
2009-09-04 23:02:52 +00:00
|
|
|
assert_compile(sizeof(this->params[0]) == sizeof(params[0]));
|
2008-09-29 16:27:02 +00:00
|
|
|
assert(paramcount <= lengthof(this->params));
|
2008-05-11 17:44:38 +00:00
|
|
|
memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
|
|
|
|
this->paramcount = paramcount;
|
2010-07-11 10:55:57 +00:00
|
|
|
this->close_cond = close_tooltip;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-10-31 13:01:52 +00:00
|
|
|
this->InitNested(&_tool_tips_desc);
|
|
|
|
|
2008-05-11 17:44:38 +00:00
|
|
|
this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
|
2009-10-31 13:01:52 +00:00
|
|
|
}
|
2006-10-12 15:13:40 +00:00
|
|
|
|
2009-10-31 13:01:52 +00:00
|
|
|
virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
|
|
|
|
{
|
2009-11-07 17:24:04 +00:00
|
|
|
/* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
|
2009-11-01 19:19:14 +00:00
|
|
|
* Add a fixed distance 2 so the tooltip floats free from both bars.
|
|
|
|
*/
|
2009-11-07 17:24:04 +00:00
|
|
|
int scr_top = GetMainViewTop() + 2;
|
|
|
|
int scr_bot = GetMainViewBottom() - 2;
|
2009-11-01 19:19:14 +00:00
|
|
|
|
2009-10-31 13:14:51 +00:00
|
|
|
Point pt;
|
|
|
|
|
|
|
|
/* Correctly position the tooltip position, watch out for window and cursor size
|
|
|
|
* Clamp value to below main toolbar and above statusbar. If tooltip would
|
|
|
|
* go below window, flip it so it is shown above the cursor */
|
2009-11-01 19:19:14 +00:00
|
|
|
pt.y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, scr_top, scr_bot);
|
|
|
|
if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.offs.y - 5, scr_bot) - sm_height;
|
2010-08-22 20:25:45 +00:00
|
|
|
pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
|
2009-10-31 13:14:51 +00:00
|
|
|
|
|
|
|
return pt;
|
2008-05-11 17:44:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2008-05-11 17:44:38 +00:00
|
|
|
{
|
2009-10-31 13:01:52 +00:00
|
|
|
/* There is only one widget. */
|
2009-10-31 13:29:53 +00:00
|
|
|
for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]);
|
|
|
|
|
|
|
|
size->width = min(GetStringBoundingBox(this->string_id).width, 194);
|
|
|
|
size->height = GetStringHeight(this->string_id, size->width);
|
|
|
|
|
|
|
|
/* Increase slightly to have some space around the box. */
|
|
|
|
size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
|
size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
2009-10-31 13:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
/* There is only one widget. */
|
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, 0);
|
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0x44);
|
2008-05-11 17:44:38 +00:00
|
|
|
|
|
|
|
for (uint arg = 0; arg < this->paramcount; arg++) {
|
|
|
|
SetDParam(arg, this->params[arg]);
|
|
|
|
}
|
2009-10-31 13:01:52 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, this->string_id, TC_FROMSTRING, SA_CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-11 17:44:38 +00:00
|
|
|
|
|
|
|
virtual void OnMouseLoop()
|
|
|
|
{
|
2010-08-19 08:22:08 +00:00
|
|
|
/* Always close tooltips when the cursor is not in our window. */
|
|
|
|
if (!_cursor.in_window) {
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-11 17:44:38 +00:00
|
|
|
/* We can show tooltips while dragging tools. These are shown as long as
|
2010-08-19 08:22:08 +00:00
|
|
|
* we are dragging the tool. Normal tooltips work with hover or rmb. */
|
2010-07-11 10:55:57 +00:00
|
|
|
switch (this->close_cond) {
|
|
|
|
case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
|
|
|
|
case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break;
|
|
|
|
case TCC_HOVER: if (!_mouse_hovering) delete this; break;
|
|
|
|
}
|
2008-05-11 17:44:38 +00:00
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Shows a tooltip
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param str String to be displayed
|
|
|
|
* @param paramcount number of params to deal with
|
2008-08-02 11:26:25 +00:00
|
|
|
* @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
|
|
|
|
* @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released
|
|
|
|
*/
|
2010-07-11 10:55:57 +00:00
|
|
|
void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-18 14:20:10 +00:00
|
|
|
DeleteWindowById(WC_TOOLTIPS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-08-02 11:26:25 +00:00
|
|
|
if (str == STR_NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-07-11 10:55:57 +00:00
|
|
|
new TooltipsWindow(str, paramcount, params, close_tooltip);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
/* Delete a character at the caret position in a text buf.
|
|
|
|
* If backspace is set, delete the character before the caret,
|
|
|
|
* else delete the character after it. */
|
|
|
|
static void DelChar(Textbuf *tb, bool backspace)
|
2005-01-06 15:54:09 +00:00
|
|
|
{
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2007-03-05 00:34:48 +00:00
|
|
|
char *s = tb->buf + tb->caretpos;
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2007-03-05 00:34:48 +00:00
|
|
|
if (backspace) s = Utf8PrevChar(s);
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-05-27 21:41:00 +00:00
|
|
|
uint16 len = (uint16)Utf8Decode(&c, s);
|
2008-03-26 10:38:31 +00:00
|
|
|
uint width = GetCharacterWidth(FS_NORMAL, c);
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
tb->width -= width;
|
2007-03-05 00:34:48 +00:00
|
|
|
if (backspace) {
|
|
|
|
tb->caretpos -= len;
|
|
|
|
tb->caretxoffs -= width;
|
|
|
|
}
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
/* Move the remaining characters over the marker */
|
2008-10-22 19:12:10 +00:00
|
|
|
memmove(s, s + len, tb->size - (s - tb->buf) - len);
|
|
|
|
tb->size -= len;
|
2005-01-06 15:54:09 +00:00
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
/**
|
|
|
|
* Delete a character from a textbuffer, either with 'Delete' or 'Backspace'
|
|
|
|
* The character is delete from the position the caret is at
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf type to be changed
|
|
|
|
* @param delmode Type of deletion, either WKC_BACKSPACE or WKC_DELETE
|
2007-07-30 13:36:09 +00:00
|
|
|
* @return Return true on successful change of Textbuf, or false otherwise
|
2005-02-21 18:59:54 +00:00
|
|
|
*/
|
|
|
|
bool DeleteTextBufferChar(Textbuf *tb, int delmode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-21 18:59:54 +00:00
|
|
|
if (delmode == WKC_BACKSPACE && tb->caretpos != 0) {
|
2006-11-16 22:05:33 +00:00
|
|
|
DelChar(tb, true);
|
2005-02-21 18:59:54 +00:00
|
|
|
return true;
|
2008-10-22 19:12:10 +00:00
|
|
|
} else if (delmode == WKC_DELETE && tb->caretpos < tb->size - 1) {
|
2006-11-16 22:05:33 +00:00
|
|
|
DelChar(tb, false);
|
2005-02-21 18:59:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-30 16:03:21 +00:00
|
|
|
/**
|
|
|
|
* Delete every character in the textbuffer
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf buffer to be emptied
|
2005-05-30 16:03:21 +00:00
|
|
|
*/
|
|
|
|
void DeleteTextBufferAll(Textbuf *tb)
|
|
|
|
{
|
2008-10-22 19:12:10 +00:00
|
|
|
memset(tb->buf, 0, tb->maxsize);
|
|
|
|
tb->size = 1;
|
|
|
|
tb->width = tb->caretpos = tb->caretxoffs = 0;
|
2005-05-30 16:03:21 +00:00
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
/**
|
2006-04-06 19:16:39 +00:00
|
|
|
* Insert a character to a textbuffer. If maxwidth of the Textbuf is zero,
|
|
|
|
* we don't care about the visual-length but only about the physical
|
2006-04-06 19:11:41 +00:00
|
|
|
* length of the string
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf type to be changed
|
2005-02-21 18:59:54 +00:00
|
|
|
* @param key Character to be inserted
|
2007-07-30 13:36:09 +00:00
|
|
|
* @return Return true on successful change of Textbuf, or false otherwise
|
2005-02-21 18:59:54 +00:00
|
|
|
*/
|
2006-11-16 22:05:33 +00:00
|
|
|
bool InsertTextBufferChar(Textbuf *tb, WChar key)
|
2005-02-21 18:59:54 +00:00
|
|
|
{
|
2006-05-09 13:23:04 +00:00
|
|
|
const byte charwidth = GetCharacterWidth(FS_NORMAL, key);
|
2008-05-27 21:41:00 +00:00
|
|
|
uint16 len = (uint16)Utf8CharLen(key);
|
2008-10-22 19:12:10 +00:00
|
|
|
if (tb->size + len <= tb->maxsize && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
|
|
|
|
memmove(tb->buf + tb->caretpos + len, tb->buf + tb->caretpos, tb->size - tb->caretpos);
|
2006-11-16 22:05:33 +00:00
|
|
|
Utf8Encode(tb->buf + tb->caretpos, key);
|
2008-10-22 19:12:10 +00:00
|
|
|
tb->size += len;
|
|
|
|
tb->width += charwidth;
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
tb->caretpos += len;
|
2005-02-21 18:59:54 +00:00
|
|
|
tb->caretxoffs += charwidth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-06 15:54:09 +00:00
|
|
|
|
2009-10-04 21:08:38 +00:00
|
|
|
/**
|
|
|
|
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
|
|
|
|
* and append this up to the maximum length (either absolute or screenlength). If maxlength
|
|
|
|
* is zero, we don't care about the screenlength but only about the physical length of the string
|
|
|
|
* @param tb Textbuf type to be changed
|
|
|
|
* @return true on successful change of Textbuf, or false otherwise
|
|
|
|
*/
|
|
|
|
bool InsertTextBufferClipboard(Textbuf *tb)
|
|
|
|
{
|
|
|
|
char utf8_buf[512];
|
|
|
|
|
|
|
|
if (!GetClipboardContents(utf8_buf, lengthof(utf8_buf))) return false;
|
|
|
|
|
|
|
|
uint16 width = 0, length = 0;
|
|
|
|
WChar c;
|
|
|
|
for (const char *ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) {
|
|
|
|
if (!IsPrintable(c)) break;
|
|
|
|
|
|
|
|
byte len = Utf8CharLen(c);
|
|
|
|
if (tb->size + length + len > tb->maxsize) break;
|
|
|
|
|
|
|
|
byte charwidth = GetCharacterWidth(FS_NORMAL, c);
|
|
|
|
if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break;
|
|
|
|
|
|
|
|
width += charwidth;
|
|
|
|
length += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length == 0) return false;
|
|
|
|
|
|
|
|
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->size - tb->caretpos);
|
|
|
|
memcpy(tb->buf + tb->caretpos, utf8_buf, length);
|
|
|
|
tb->width += width;
|
|
|
|
tb->caretxoffs += width;
|
|
|
|
|
|
|
|
tb->size += length;
|
|
|
|
tb->caretpos += length;
|
|
|
|
assert(tb->size <= tb->maxsize);
|
|
|
|
tb->buf[tb->size - 1] = '\0'; // terminating zero
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
/**
|
|
|
|
* Handle text navigation with arrow keys left/right.
|
|
|
|
* This defines where the caret will blink and the next characer interaction will occur
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf type where navigation occurs
|
|
|
|
* @param navmode Direction in which navigation occurs WKC_LEFT, WKC_RIGHT, WKC_END, WKC_HOME
|
2007-07-30 13:36:09 +00:00
|
|
|
* @return Return true on successful change of Textbuf, or false otherwise
|
2005-02-21 18:59:54 +00:00
|
|
|
*/
|
|
|
|
bool MoveTextBufferPos(Textbuf *tb, int navmode)
|
|
|
|
{
|
|
|
|
switch (navmode) {
|
2008-03-26 10:38:31 +00:00
|
|
|
case WKC_LEFT:
|
|
|
|
if (tb->caretpos != 0) {
|
|
|
|
WChar c;
|
|
|
|
const char *s = Utf8PrevChar(tb->buf + tb->caretpos);
|
|
|
|
Utf8Decode(&c, s);
|
|
|
|
tb->caretpos = s - tb->buf; // -= (tb->buf + tb->caretpos - s)
|
|
|
|
tb->caretxoffs -= GetCharacterWidth(FS_NORMAL, c);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-03-26 10:38:31 +00:00
|
|
|
case WKC_RIGHT:
|
2008-10-22 19:12:10 +00:00
|
|
|
if (tb->caretpos < tb->size - 1) {
|
2008-03-26 10:38:31 +00:00
|
|
|
WChar c;
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-05-27 21:41:00 +00:00
|
|
|
tb->caretpos += (uint16)Utf8Decode(&c, tb->buf + tb->caretpos);
|
2008-03-26 10:38:31 +00:00
|
|
|
tb->caretxoffs += GetCharacterWidth(FS_NORMAL, c);
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-03-26 10:38:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_HOME:
|
|
|
|
tb->caretpos = 0;
|
|
|
|
tb->caretxoffs = 0;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case WKC_END:
|
2008-10-22 19:12:10 +00:00
|
|
|
tb->caretpos = tb->size - 1;
|
2008-03-26 10:38:31 +00:00
|
|
|
tb->caretxoffs = tb->width;
|
2005-02-21 18:59:54 +00:00
|
|
|
return true;
|
2008-04-04 17:27:38 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2005-02-21 18:59:54 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-10-24 22:57:44 +00:00
|
|
|
/**
|
|
|
|
* Initialize the textbuffer by supplying it the buffer to write into
|
|
|
|
* and the maximum length of this buffer
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf type which is getting initialized
|
2006-10-24 22:57:44 +00:00
|
|
|
* @param buf the buffer that will be holding the data for input
|
2008-10-22 19:12:10 +00:00
|
|
|
* @param maxsize maximum size in bytes, including terminating '\0'
|
2006-10-24 22:57:44 +00:00
|
|
|
* @param maxwidth maximum length in pixels of this buffer. If reached, buffer
|
2008-10-22 19:12:10 +00:00
|
|
|
* cannot grow, even if maxsize would allow because there is space. Width
|
2010-08-01 19:44:49 +00:00
|
|
|
* of zero '0' means the buffer is only restricted by maxsize
|
|
|
|
*/
|
2008-10-22 19:12:10 +00:00
|
|
|
void InitializeTextBuffer(Textbuf *tb, char *buf, uint16 maxsize, uint16 maxwidth)
|
2006-10-24 22:57:44 +00:00
|
|
|
{
|
2008-10-22 19:12:10 +00:00
|
|
|
assert(maxsize != 0);
|
|
|
|
|
|
|
|
tb->buf = buf;
|
|
|
|
tb->maxsize = maxsize;
|
|
|
|
tb->maxwidth = maxwidth;
|
|
|
|
tb->caret = true;
|
2006-10-24 22:57:44 +00:00
|
|
|
UpdateTextBufferSize(tb);
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
/**
|
2007-04-17 20:23:13 +00:00
|
|
|
* Update Textbuf type with its actual physical character and screenlength
|
2005-02-21 18:59:54 +00:00
|
|
|
* Get the count of characters in the string as well as the width in pixels.
|
|
|
|
* Useful when copying in a larger amount of text at once
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param tb Textbuf type which length is calculated
|
2005-02-21 18:59:54 +00:00
|
|
|
*/
|
|
|
|
void UpdateTextBufferSize(Textbuf *tb)
|
|
|
|
{
|
2006-11-16 22:05:33 +00:00
|
|
|
const char *buf = tb->buf;
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
tb->width = 0;
|
2008-10-22 19:12:10 +00:00
|
|
|
tb->size = 1; // terminating zero
|
2005-02-21 18:59:54 +00:00
|
|
|
|
2008-10-22 19:12:10 +00:00
|
|
|
WChar c;
|
|
|
|
while ((c = Utf8Consume(&buf)) != '\0') {
|
2006-11-16 22:05:33 +00:00
|
|
|
tb->width += GetCharacterWidth(FS_NORMAL, c);
|
2008-10-22 19:12:10 +00:00
|
|
|
tb->size += Utf8CharLen(c);
|
2005-02-21 18:59:54 +00:00
|
|
|
}
|
|
|
|
|
2008-10-22 19:12:10 +00:00
|
|
|
assert(tb->size <= tb->maxsize);
|
|
|
|
|
|
|
|
tb->caretpos = tb->size - 1;
|
2005-02-21 18:59:54 +00:00
|
|
|
tb->caretxoffs = tb->width;
|
|
|
|
}
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
bool HandleCaret(Textbuf *tb)
|
2005-02-21 18:59:54 +00:00
|
|
|
{
|
2008-05-11 12:26:20 +00:00
|
|
|
/* caret changed? */
|
|
|
|
bool b = !!(_caret_timer & 0x20);
|
2005-02-21 18:59:54 +00:00
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
if (b != tb->caret) {
|
|
|
|
tb->caret = b;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-09 01:22:29 +00:00
|
|
|
bool QueryString::HasEditBoxFocus(const Window *w, int wid) const
|
|
|
|
{
|
2009-06-04 14:07:05 +00:00
|
|
|
if (w->IsWidgetGloballyFocused(wid)) return true;
|
|
|
|
if (w->window_class != WC_OSK || _focused_window != w->parent) return false;
|
2009-11-15 13:36:30 +00:00
|
|
|
return w->parent->nested_focus != NULL && w->parent->nested_focus->type == WWT_EDITBOX;
|
2009-02-09 01:22:29 +00:00
|
|
|
}
|
|
|
|
|
2010-05-30 12:06:18 +00:00
|
|
|
HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state)
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
2009-02-09 01:22:29 +00:00
|
|
|
if (!QueryString::HasEditBoxFocus(w, wid)) return HEBR_NOT_FOCUSED;
|
|
|
|
|
2010-05-30 12:06:18 +00:00
|
|
|
state = ES_HANDLED;
|
2008-05-11 12:26:20 +00:00
|
|
|
|
|
|
|
switch (keycode) {
|
2008-10-25 19:59:11 +00:00
|
|
|
case WKC_ESC: return HEBR_CANCEL;
|
2008-03-26 10:38:31 +00:00
|
|
|
|
2008-10-25 19:59:11 +00:00
|
|
|
case WKC_RETURN: case WKC_NUM_ENTER: return HEBR_CONFIRM;
|
2008-03-26 10:38:31 +00:00
|
|
|
|
2009-10-04 21:08:38 +00:00
|
|
|
#ifdef WITH_COCOA
|
|
|
|
case (WKC_META | 'V'):
|
|
|
|
#endif
|
2008-03-26 10:38:31 +00:00
|
|
|
case (WKC_CTRL | 'V'):
|
2009-09-13 19:15:59 +00:00
|
|
|
if (InsertTextBufferClipboard(&this->text)) w->SetWidgetDirty(wid);
|
2008-03-26 10:38:31 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-04 21:08:38 +00:00
|
|
|
#ifdef WITH_COCOA
|
|
|
|
case (WKC_META | 'U'):
|
|
|
|
#endif
|
2008-03-26 10:38:31 +00:00
|
|
|
case (WKC_CTRL | 'U'):
|
2008-05-11 12:26:20 +00:00
|
|
|
DeleteTextBufferAll(&this->text);
|
2009-09-13 19:15:59 +00:00
|
|
|
w->SetWidgetDirty(wid);
|
2008-03-26 10:38:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_BACKSPACE: case WKC_DELETE:
|
2009-09-13 19:15:59 +00:00
|
|
|
if (DeleteTextBufferChar(&this->text, keycode)) w->SetWidgetDirty(wid);
|
2008-03-26 10:38:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
2009-09-13 19:15:59 +00:00
|
|
|
if (MoveTextBufferPos(&this->text, keycode)) w->SetWidgetDirty(wid);
|
2008-03-26 10:38:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-05-11 12:26:20 +00:00
|
|
|
if (IsValidChar(key, this->afilter)) {
|
2009-09-13 19:15:59 +00:00
|
|
|
if (InsertTextBufferChar(&this->text, key)) w->SetWidgetDirty(wid);
|
2009-03-11 09:21:11 +00:00
|
|
|
} else {
|
2010-05-30 12:06:18 +00:00
|
|
|
state = ES_NOT_HANDLED;
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 19:59:11 +00:00
|
|
|
return HEBR_EDITING;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
void QueryString::HandleEditBox(Window *w, int wid)
|
2005-02-21 18:59:54 +00:00
|
|
|
{
|
2009-02-09 01:22:29 +00:00
|
|
|
if (HasEditBoxFocus(w, wid) && HandleCaret(&this->text)) {
|
2009-09-13 19:15:59 +00:00
|
|
|
w->SetWidgetDirty(wid);
|
2009-01-25 22:16:08 +00:00
|
|
|
/* When we're not the OSK, notify 'our' OSK to redraw the widget,
|
|
|
|
* so the caret changes appropriately. */
|
|
|
|
if (w->window_class != WC_OSK) {
|
|
|
|
Window *w_osk = FindWindowById(WC_OSK, 0);
|
2009-09-30 21:07:54 +00:00
|
|
|
if (w_osk != NULL && w_osk->parent == w) w_osk->InvalidateData();
|
2009-01-25 22:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
void QueryString::DrawEditBox(Window *w, int wid)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-11-15 13:36:30 +00:00
|
|
|
const NWidgetBase *wi = w->GetWidget<NWidgetBase>(wid);
|
2008-03-26 10:08:17 +00:00
|
|
|
|
2009-11-15 13:36:30 +00:00
|
|
|
assert((wi->type & WWT_MASK) == WWT_EDITBOX);
|
|
|
|
int left = wi->pos_x;
|
|
|
|
int right = wi->pos_x + wi->current_x - 1;
|
|
|
|
int top = wi->pos_y;
|
|
|
|
int bottom = wi->pos_y + wi->current_y - 1;
|
2007-01-13 15:00:40 +00:00
|
|
|
|
2009-09-11 18:52:56 +00:00
|
|
|
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, 215);
|
2008-04-04 17:27:38 +00:00
|
|
|
|
2006-10-27 10:12:57 +00:00
|
|
|
/* Limit the drawing of the string inside the widget boundaries */
|
2009-09-11 18:52:56 +00:00
|
|
|
DrawPixelInfo dpi;
|
2009-09-23 15:42:29 +00:00
|
|
|
if (!FillDrawPixelInfo(&dpi, left + WD_FRAMERECT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMERECT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
|
2006-10-27 10:12:57 +00:00
|
|
|
|
2008-04-04 17:27:38 +00:00
|
|
|
DrawPixelInfo *old_dpi = _cur_dpi;
|
2006-10-27 10:12:57 +00:00
|
|
|
_cur_dpi = &dpi;
|
|
|
|
|
|
|
|
/* We will take the current widget length as maximum width, with a small
|
|
|
|
* space reserved at the end for the caret to show */
|
2008-05-11 12:26:20 +00:00
|
|
|
const Textbuf *tb = &this->text;
|
2009-09-11 18:52:56 +00:00
|
|
|
int delta = min(0, (right - left) - tb->width - 10);
|
2006-10-27 10:12:57 +00:00
|
|
|
|
|
|
|
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
|
|
|
|
|
2009-03-21 22:46:17 +00:00
|
|
|
DrawString(delta, tb->width, 0, tb->buf, TC_YELLOW);
|
2009-03-25 00:28:57 +00:00
|
|
|
if (HasEditBoxFocus(w, wid) && tb->caret) {
|
|
|
|
int caret_width = GetStringBoundingBox("_").width;
|
|
|
|
DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
|
|
|
|
}
|
2006-10-27 10:12:57 +00:00
|
|
|
|
|
|
|
_cur_dpi = old_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-03 23:40:29 +00:00
|
|
|
HandleEditBoxResult QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state)
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
2008-05-17 23:11:06 +00:00
|
|
|
return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state);
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QueryStringBaseWindow::HandleEditBox(int wid)
|
|
|
|
{
|
|
|
|
this->QueryString::HandleEditBox(this, wid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueryStringBaseWindow::DrawEditBox(int wid)
|
|
|
|
{
|
|
|
|
this->QueryString::DrawEditBox(this, wid);
|
|
|
|
}
|
|
|
|
|
2009-01-03 13:59:05 +00:00
|
|
|
void QueryStringBaseWindow::OnOpenOSKWindow(int wid)
|
|
|
|
{
|
|
|
|
ShowOnScreenKeyboard(this, wid, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-11-03 20:04:05 +00:00
|
|
|
/** Widget of the string query window. */
|
2006-12-30 01:17:53 +00:00
|
|
|
enum QueryStringWidgets {
|
2009-04-11 18:38:10 +00:00
|
|
|
QUERY_STR_WIDGET_CAPTION,
|
|
|
|
QUERY_STR_WIDGET_TEXT,
|
2008-09-15 19:02:50 +00:00
|
|
|
QUERY_STR_WIDGET_DEFAULT,
|
2006-12-30 01:17:53 +00:00
|
|
|
QUERY_STR_WIDGET_CANCEL,
|
|
|
|
QUERY_STR_WIDGET_OK
|
|
|
|
};
|
|
|
|
|
2009-11-03 20:04:05 +00:00
|
|
|
/** Class for the string query window. */
|
2008-05-11 12:26:20 +00:00
|
|
|
struct QueryStringWindow : public QueryStringBaseWindow
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-11-03 20:04:05 +00:00
|
|
|
QueryStringFlags flags; ///< Flags controlling behaviour of the window.
|
|
|
|
|
|
|
|
QueryStringWindow(StringID str, StringID caption, uint maxsize, uint maxwidth, const WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
|
|
|
|
QueryStringBaseWindow(maxsize)
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
2009-11-03 20:04:05 +00:00
|
|
|
GetString(this->edit_str_buf, str, &this->edit_str_buf[maxsize - 1]);
|
2010-07-25 23:14:59 +00:00
|
|
|
str_validate(this->edit_str_buf, &this->edit_str_buf[maxsize - 1], false, true);
|
2009-11-03 20:04:05 +00:00
|
|
|
|
|
|
|
if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
|
|
|
|
|
|
|
|
this->caption = caption;
|
|
|
|
this->afilter = afilter;
|
|
|
|
this->flags = flags;
|
|
|
|
InitializeTextBuffer(&this->text, this->edit_str_buf, maxsize, maxwidth);
|
|
|
|
|
|
|
|
this->InitNested(desc);
|
|
|
|
|
2008-05-14 19:08:09 +00:00
|
|
|
this->parent = parent;
|
2009-11-03 20:04:05 +00:00
|
|
|
|
2009-02-09 01:22:29 +00:00
|
|
|
this->SetFocusedWidget(QUERY_STR_WIDGET_TEXT);
|
2009-11-03 20:04:05 +00:00
|
|
|
this->LowerWidget(QUERY_STR_WIDGET_TEXT);
|
|
|
|
}
|
2005-05-17 23:25:18 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-11-03 20:04:05 +00:00
|
|
|
{
|
2009-11-03 20:21:49 +00:00
|
|
|
if (widget == QUERY_STR_WIDGET_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) {
|
2010-01-23 19:30:03 +00:00
|
|
|
/* We don't want this widget to show! */
|
|
|
|
fill->width = 0;
|
|
|
|
resize->width = 0;
|
2009-11-03 20:04:05 +00:00
|
|
|
size->width = 0;
|
|
|
|
}
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
this->DrawEditBox(QUERY_STR_WIDGET_TEXT);
|
|
|
|
}
|
|
|
|
|
2009-11-03 20:04:05 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == QUERY_STR_WIDGET_CAPTION) SetDParam(0, this->caption);
|
|
|
|
}
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
void OnOk()
|
|
|
|
{
|
|
|
|
if (this->orig == NULL || strcmp(this->text.buf, this->orig) != 0) {
|
|
|
|
/* If the parent is NULL, the editbox is handled by general function
|
2008-07-23 15:01:50 +00:00
|
|
|
* HandleOnEditText */
|
2008-05-11 12:26:20 +00:00
|
|
|
if (this->parent != NULL) {
|
|
|
|
this->parent->OnQueryTextFinished(this->text.buf);
|
|
|
|
} else {
|
|
|
|
HandleOnEditText(this->text.buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-14 20:28:11 +00:00
|
|
|
this->handled = true;
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2008-09-15 19:02:50 +00:00
|
|
|
case QUERY_STR_WIDGET_DEFAULT:
|
|
|
|
this->text.buf[0] = '\0';
|
2010-07-29 14:26:28 +00:00
|
|
|
/* FALL THROUGH */
|
2008-05-11 12:26:20 +00:00
|
|
|
case QUERY_STR_WIDGET_OK:
|
|
|
|
this->OnOk();
|
2010-07-29 14:26:28 +00:00
|
|
|
/* FALL THROUGH */
|
2008-05-11 12:26:20 +00:00
|
|
|
case QUERY_STR_WIDGET_CANCEL:
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
virtual void OnMouseLoop()
|
|
|
|
{
|
|
|
|
this->HandleEditBox(QUERY_STR_WIDGET_TEXT);
|
2008-05-10 13:46:36 +00:00
|
|
|
}
|
2008-05-11 12:26:20 +00:00
|
|
|
|
2008-05-17 23:11:06 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
2009-03-11 09:21:11 +00:00
|
|
|
EventState state = ES_NOT_HANDLED;
|
2008-05-17 23:11:06 +00:00
|
|
|
switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, state)) {
|
2008-05-28 15:28:27 +00:00
|
|
|
default: NOT_REACHED();
|
2008-10-25 19:59:11 +00:00
|
|
|
case HEBR_EDITING: {
|
2008-05-28 15:28:27 +00:00
|
|
|
Window *osk = FindWindowById(WC_OSK, 0);
|
2009-09-30 21:07:54 +00:00
|
|
|
if (osk != NULL && osk->parent == this) osk->InvalidateData();
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-25 19:59:11 +00:00
|
|
|
case HEBR_CONFIRM: this->OnOk();
|
2010-08-01 20:52:11 +00:00
|
|
|
/* FALL THROUGH */
|
2008-10-25 19:59:11 +00:00
|
|
|
case HEBR_CANCEL: delete this; break; // close window, abandon changes
|
2009-02-09 01:22:29 +00:00
|
|
|
case HEBR_NOT_FOCUSED: break;
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
2008-05-17 23:11:06 +00:00
|
|
|
return state;
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
|
|
|
|
2009-01-03 13:59:05 +00:00
|
|
|
virtual void OnOpenOSKWindow(int wid)
|
|
|
|
{
|
|
|
|
ShowOnScreenKeyboard(this, wid, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK);
|
|
|
|
}
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
~QueryStringWindow()
|
|
|
|
{
|
|
|
|
if (!this->handled && this->parent != NULL) {
|
2008-05-27 23:40:36 +00:00
|
|
|
Window *parent = this->parent;
|
|
|
|
this->parent = NULL; // so parent doesn't try to delete us again
|
|
|
|
parent->OnQueryTextFinished(NULL);
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-11 19:14:34 +00:00
|
|
|
static const NWidgetPart _nested_query_string_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2009-08-29 21:28:36 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, QUERY_STR_WIDGET_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EDITBOX, COLOUR_GREY, QUERY_STR_WIDGET_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
2009-11-03 20:25:19 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, QUERY_STR_WIDGET_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, QUERY_STR_WIDGET_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, QUERY_STR_WIDGET_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_OK, STR_NULL),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _query_string_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_AUTO, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_QUERY_STRING, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_query_string_widgets, lengthof(_nested_query_string_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Show a query popup window with a textbox in it.
|
2006-12-30 01:17:53 +00:00
|
|
|
* @param str StringID for the text shown in the textbox
|
|
|
|
* @param caption StringID of text shown in caption of querywindow
|
2008-10-22 19:12:10 +00:00
|
|
|
* @param maxsize maximum size in bytes (including terminating '\0')
|
2006-12-30 01:17:53 +00:00
|
|
|
* @param maxwidth maximum width in pixels allowed
|
|
|
|
* @param parent pointer to a Window that will handle the events (ok/cancel) of this
|
2008-05-19 09:24:03 +00:00
|
|
|
* window. If NULL, results are handled by global function HandleOnEditText
|
2008-09-15 16:29:40 +00:00
|
|
|
* @param afilter filters out unwanted character input
|
|
|
|
* @param flags various flags, @see QueryStringFlags
|
|
|
|
*/
|
2008-10-22 19:12:10 +00:00
|
|
|
void ShowQueryString(StringID str, StringID caption, uint maxsize, uint maxwidth, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_QUERY_STRING, 0);
|
2009-11-03 20:04:05 +00:00
|
|
|
new QueryStringWindow(str, caption, maxsize, maxwidth, &_query_string_desc, parent, afilter, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-29 17:54:47 +00:00
|
|
|
|
|
|
|
enum QueryWidgets {
|
2009-04-11 18:38:10 +00:00
|
|
|
QUERY_WIDGET_CAPTION,
|
2009-09-30 15:14:34 +00:00
|
|
|
QUERY_WIDGET_TEXT,
|
2009-04-11 18:38:10 +00:00
|
|
|
QUERY_WIDGET_NO,
|
2006-12-29 17:54:47 +00:00
|
|
|
QUERY_WIDGET_YES
|
|
|
|
};
|
|
|
|
|
2008-05-11 06:59:51 +00:00
|
|
|
/**
|
|
|
|
* Window used for asking the user a YES/NO question.
|
|
|
|
*/
|
|
|
|
struct QueryWindow : public Window {
|
2008-05-19 19:17:56 +00:00
|
|
|
QueryCallbackProc *proc; ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
|
|
|
|
uint64 params[10]; ///< local copy of _decode_parameters
|
|
|
|
StringID message; ///< message shown for query window
|
2009-09-30 15:14:34 +00:00
|
|
|
StringID caption; ///< title of window
|
2006-12-29 17:54:47 +00:00
|
|
|
|
2009-09-30 15:14:34 +00:00
|
|
|
QueryWindow(const WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window()
|
2008-05-11 06:59:51 +00:00
|
|
|
{
|
|
|
|
/* Create a backup of the variadic arguments to strings because it will be
|
2008-07-23 15:01:50 +00:00
|
|
|
* overridden pretty often. We will copy these back for drawing */
|
2008-05-11 06:59:51 +00:00
|
|
|
CopyOutDParam(this->params, 0, lengthof(this->params));
|
2009-09-30 15:14:34 +00:00
|
|
|
this->caption = caption;
|
|
|
|
this->message = message;
|
|
|
|
this->proc = callback;
|
2008-05-11 11:41:18 +00:00
|
|
|
|
2009-09-30 15:14:34 +00:00
|
|
|
this->InitNested(desc);
|
|
|
|
|
|
|
|
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
this->parent = parent;
|
|
|
|
this->left = parent->left + (parent->width / 2) - (this->width / 2);
|
|
|
|
this->top = parent->top + (parent->height / 2) - (this->height / 2);
|
2008-05-11 06:59:51 +00:00
|
|
|
}
|
2006-12-29 17:54:47 +00:00
|
|
|
|
2008-05-11 06:59:51 +00:00
|
|
|
~QueryWindow()
|
|
|
|
{
|
|
|
|
if (this->proc != NULL) this->proc(this->parent, false);
|
|
|
|
}
|
2006-12-29 17:54:47 +00:00
|
|
|
|
2009-09-30 15:14:34 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case QUERY_WIDGET_CAPTION:
|
2009-10-02 15:06:14 +00:00
|
|
|
CopyInDParam(1, this->params, lengthof(this->params));
|
2009-09-30 15:14:34 +00:00
|
|
|
SetDParam(0, this->caption);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QUERY_WIDGET_TEXT:
|
|
|
|
CopyInDParam(0, this->params, lengthof(this->params));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-09-30 15:14:34 +00:00
|
|
|
{
|
|
|
|
if (widget != QUERY_WIDGET_TEXT) return;
|
|
|
|
|
|
|
|
Dimension d = GetStringMultiLineBoundingBox(this->message, *size);
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != QUERY_WIDGET_TEXT) return;
|
|
|
|
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->message, TC_FROMSTRING, SA_CENTER);
|
|
|
|
}
|
|
|
|
|
2008-05-11 06:59:51 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-05-11 06:59:51 +00:00
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-11 06:59:51 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2008-05-19 19:17:56 +00:00
|
|
|
case QUERY_WIDGET_YES: {
|
|
|
|
/* in the Generate New World window, clicking 'Yes' causes
|
|
|
|
* DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
|
|
|
|
QueryCallbackProc *proc = this->proc;
|
|
|
|
Window *parent = this->parent;
|
2008-05-28 06:30:55 +00:00
|
|
|
/* Prevent the destructor calling the callback function */
|
|
|
|
this->proc = NULL;
|
2008-05-19 19:17:56 +00:00
|
|
|
delete this;
|
|
|
|
if (proc != NULL) {
|
|
|
|
proc(parent, true);
|
|
|
|
proc = NULL;
|
2006-12-29 17:54:47 +00:00
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-11 06:59:51 +00:00
|
|
|
case QUERY_WIDGET_NO:
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-05-17 23:11:06 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
2008-05-11 06:59:51 +00:00
|
|
|
{
|
|
|
|
/* ESC closes the window, Enter confirms the action */
|
|
|
|
switch (keycode) {
|
|
|
|
case WKC_RETURN:
|
|
|
|
case WKC_NUM_ENTER:
|
|
|
|
if (this->proc != NULL) {
|
|
|
|
this->proc(this->parent, true);
|
|
|
|
this->proc = NULL;
|
|
|
|
}
|
2010-07-29 14:26:28 +00:00
|
|
|
/* FALL THROUGH */
|
2008-05-11 06:59:51 +00:00
|
|
|
case WKC_ESC:
|
|
|
|
delete this;
|
2008-05-17 23:11:06 +00:00
|
|
|
return ES_HANDLED;
|
2008-05-11 06:59:51 +00:00
|
|
|
}
|
2008-05-17 23:11:06 +00:00
|
|
|
return ES_NOT_HANDLED;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
}
|
2008-05-11 06:59:51 +00:00
|
|
|
};
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2009-04-11 19:14:34 +00:00
|
|
|
static const NWidgetPart _nested_query_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_RED),
|
2009-09-30 15:14:34 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_RED, QUERY_WIDGET_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_RED), SetPIP(8, 15, 8),
|
2009-09-30 15:14:34 +00:00
|
|
|
NWidget(WWT_TEXT, COLOUR_RED, QUERY_WIDGET_TEXT), SetMinimalSize(200, 12),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(20, 29, 20),
|
2009-08-05 17:59:21 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, QUERY_WIDGET_NO), SetMinimalSize(71, 12), SetDataTip(STR_QUIT_NO, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, QUERY_WIDGET_YES), SetMinimalSize(71, 12), SetDataTip(STR_QUIT_YES, STR_NULL),
|
2009-04-11 19:14:34 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _query_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_CENTER, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_CONFIRM_POPUP_QUERY, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS | WDF_MODAL,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_query_widgets, lengthof(_nested_query_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Show a modal confirmation window with standard 'yes' and 'no' buttons
|
2006-12-29 17:54:47 +00:00
|
|
|
* The window is aligned to the centre of its parent.
|
|
|
|
* @param caption string shown as window caption
|
|
|
|
* @param message string that will be shown for the window
|
|
|
|
* @param parent pointer to parent window, if this pointer is NULL the parent becomes
|
|
|
|
* the main window WC_MAIN_WINDOW
|
2008-07-23 15:01:50 +00:00
|
|
|
* @param callback callback function pointer to set in the window descriptor
|
|
|
|
*/
|
2008-05-19 19:17:56 +00:00
|
|
|
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
{
|
2008-05-11 06:59:51 +00:00
|
|
|
new QueryWindow(&_query_desc, caption, message, parent, callback);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
}
|