2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-08-05 00:59:45 +00:00
|
|
|
#include "hal.h"
|
(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
|
|
|
#include "heightmap.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-08-14 18:10:18 +00:00
|
|
|
#include "gfxinit.h"
|
2005-07-22 06:31:31 +00:00
|
|
|
#include "saveload.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-05-09 22:33:00 +00:00
|
|
|
#include "table/tree_land.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "town.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2004-12-04 17:54:56 +00:00
|
|
|
#include "network.h"
|
2005-02-21 18:59:54 +00:00
|
|
|
#include "string.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-05-22 14:41:20 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "train.h"
|
(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
|
|
|
#include "tgp.h"
|
|
|
|
#include "settings.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-09-28 23:05:03 +00:00
|
|
|
#include "resize_window_widgets.h"
|
2005-02-07 19:45:08 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
#include "fios.h"
|
|
|
|
/* Variables to display file lists */
|
|
|
|
FiosItem *_fios_list;
|
|
|
|
int _saveload_mode;
|
2004-08-09 17:04:08 +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
|
|
|
extern void GenerateLandscape(byte mode);
|
|
|
|
extern void SwitchMode(int new_mode);
|
|
|
|
|
2005-03-28 13:30:51 +00:00
|
|
|
static bool _fios_path_changed;
|
2005-03-28 08:48:41 +00:00
|
|
|
static bool _savegame_sort_dirty;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct LandInfoData {
|
|
|
|
Town *town;
|
|
|
|
int32 costclear;
|
|
|
|
AcceptedCargo ac;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
TileDesc td;
|
|
|
|
} LandInfoData;
|
|
|
|
|
|
|
|
static void LandInfoWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
if (e->event == WE_PAINT) {
|
2006-07-26 03:33:12 +00:00
|
|
|
const LandInfoData *lid;
|
2005-11-13 13:43:55 +00:00
|
|
|
StringID str;
|
2004-11-21 10:49:40 +00:00
|
|
|
int i;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
lid = WP(w,void_d).data;
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, lid->td.dparam[0]);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringCentered(140, 16, lid->td.str, 13);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_01A6_N_A);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (lid->td.owner != OWNER_NONE && lid->td.owner != OWNER_WATER)
|
|
|
|
GetNameOfOwner(lid->td.owner, lid->tile);
|
|
|
|
DrawStringCentered(140, 27, STR_01A7_OWNER, 0);
|
|
|
|
|
|
|
|
str = STR_01A4_COST_TO_CLEAR_N_A;
|
2005-12-10 12:05:39 +00:00
|
|
|
if (!CmdFailed(lid->costclear)) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, lid->costclear);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_01A5_COST_TO_CLEAR;
|
|
|
|
}
|
|
|
|
DrawStringCentered(140, 38, str, 0);
|
|
|
|
|
2005-09-14 19:22:06 +00:00
|
|
|
snprintf(_userstring, lengthof(_userstring), "0x%.4X", lid->tile);
|
2005-01-07 17:02:43 +00:00
|
|
|
SetDParam(0, TileX(lid->tile));
|
|
|
|
SetDParam(1, TileY(lid->tile));
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, STR_SPEC_USERSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringCentered(140, 49, STR_LANDINFO_COORDS, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_01A9_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (lid->town != NULL) {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, STR_TOWN);
|
|
|
|
SetDParam(1, lid->town->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
DrawStringCentered(140,60, STR_01A8_LOCAL_AUTHORITY, 0);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
{
|
|
|
|
char buf[512];
|
2006-10-21 23:31:34 +00:00
|
|
|
char *p = GetString(buf, STR_01CE_CARGO_ACCEPTED, lastof(buf));
|
2005-07-15 14:53:44 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CARGO; ++i) {
|
|
|
|
if (lid->ac[i] > 0) {
|
|
|
|
// Add a comma between each item.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (found) {
|
|
|
|
*p++ = ',';
|
|
|
|
*p++ = ' ';
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
found = true;
|
|
|
|
|
|
|
|
// If the accepted value is less than 8, show it in 1/8:ths
|
|
|
|
if (lid->ac[i] < 8) {
|
2006-08-27 10:04:33 +00:00
|
|
|
SetDParam(0, lid->ac[i]);
|
|
|
|
SetDParam(1, _cargoc.names_s[i]);
|
2006-10-21 23:31:34 +00:00
|
|
|
p = GetString(p, STR_01D1_8, lastof(buf));
|
2005-07-15 14:53:44 +00:00
|
|
|
} else {
|
2006-10-21 23:31:34 +00:00
|
|
|
p = GetString(p, _cargoc.names_s[i], lastof(buf));
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2004-11-21 10:49:40 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (found) DrawStringMultiCenter(140, 76, BindCString(buf), 276);
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-17 08:40:09 +00:00
|
|
|
if (lid->td.build_date != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0,lid->td.build_date);
|
2004-08-17 08:40:09 +00:00
|
|
|
DrawStringCentered(140,71, STR_BUILD_DATE, 0);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _land_info_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 279, 0, 13, STR_01A3_LAND_AREA_INFORMATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 279, 14, 92, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _land_info_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 280, 93,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_LAND_INFO,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_land_info_widgets,
|
|
|
|
LandInfoWndProc
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void Place_LandInfo(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Player *p;
|
|
|
|
static LandInfoData lid;
|
|
|
|
Window *w;
|
|
|
|
int64 old_money;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_LAND_INFO, 0);
|
|
|
|
|
|
|
|
w = AllocateWindowDesc(&_land_info_desc);
|
|
|
|
WP(w,void_d).data = &lid;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
lid.tile = tile;
|
|
|
|
lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
|
|
|
|
2006-10-14 22:31:18 +00:00
|
|
|
p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
|
2004-08-10 14:33:37 +00:00
|
|
|
|
|
|
|
old_money = p->money64;
|
|
|
|
p->money64 = p->player_money = 0x7fffffff;
|
2006-04-10 07:15:58 +00:00
|
|
|
lid.costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
|
2004-08-10 14:33:37 +00:00
|
|
|
p->money64 = old_money;
|
|
|
|
UpdatePlayerMoney32(p);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-17 08:40:09 +00:00
|
|
|
// Becuase build_date is not set yet in every TileDesc, we make sure it is empty
|
|
|
|
lid.td.build_date = 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-11-21 10:49:40 +00:00
|
|
|
GetAcceptedCargo(tile, lid.ac);
|
2004-08-09 17:04:08 +00:00
|
|
|
GetTileDesc(tile, &lid.td);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-06-10 08:37:41 +00:00
|
|
|
#if defined(_DEBUG)
|
|
|
|
# define LANDINFOD_LEVEL 0
|
|
|
|
#else
|
|
|
|
# define LANDINFOD_LEVEL 1
|
|
|
|
#endif
|
|
|
|
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) ("extra = %#x", _m[tile].extra);
|
|
|
|
#undef LANDINFOD_LEVEL
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void PlaceLandBlockInfo(void)
|
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;
|
2005-06-06 13:47:06 +00:00
|
|
|
SetObjectToPlace(SPR_CURSOR_QUERY, 1, 1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-03 16:45:42 +00:00
|
|
|
static const char *credits[] = {
|
|
|
|
/*************************************************************************
|
|
|
|
* maximum length of string which fits in window -^*/
|
|
|
|
"Original design by Chris Sawyer",
|
|
|
|
"Original graphics by Simon Foster",
|
|
|
|
"",
|
2005-01-23 20:41:20 +00:00
|
|
|
"The OpenTTD team (in alphabetical order):",
|
2005-04-14 20:42:30 +00:00
|
|
|
" Bjarni Corfitzen (Bjarni) - MacOSX port, coder",
|
2005-08-07 19:16:32 +00:00
|
|
|
" Matthijs Kooijman (blathijs) - Pathfinder-god",
|
2005-01-23 21:24:33 +00:00
|
|
|
" Victor Fischer (Celestar) - Programming everywhere you need him to",
|
2006-11-16 22:05:33 +00:00
|
|
|
" Tamás Faragó (Darkvater) - Lead coder",
|
|
|
|
" Attila Bán (MiHaMiX) - WebTranslator, Nightlies, Wiki and bugtracker host",
|
2005-01-23 20:41:20 +00:00
|
|
|
" Owen Rudge (orudge) - Forum- and masterserver host, OS/2 port",
|
2005-12-13 20:20:44 +00:00
|
|
|
" Peter Nelson (peter1138) - Spiritual descendant from newgrf gods",
|
2005-01-23 21:30:31 +00:00
|
|
|
" Christoph Mallon (Tron) - Programmer, code correctness police",
|
2005-01-23 20:41:20 +00:00
|
|
|
" Patric Stout (TrueLight) - Coder, network guru, SVN- and website host",
|
2005-01-23 21:24:33 +00:00
|
|
|
"",
|
|
|
|
"Retired Developers:",
|
|
|
|
" Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)",
|
2005-01-03 16:45:42 +00:00
|
|
|
" Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)",
|
2005-05-16 12:15:53 +00:00
|
|
|
" Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3.0 - 0.3.6)",
|
2005-01-03 16:45:42 +00:00
|
|
|
"",
|
|
|
|
"Special thanks go out to:",
|
|
|
|
" Josef Drexler - For his great work on TTDPatch",
|
|
|
|
" Marcin Grzegorczyk - For his documentation of TTD internals",
|
2005-03-27 00:42:57 +00:00
|
|
|
" Petr Baudis (pasky) - Many patches, newgrf support",
|
2006-11-16 22:05:33 +00:00
|
|
|
" Stefan Meißner (sign_de) - For his work on the console",
|
2005-05-16 12:15:53 +00:00
|
|
|
" Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with (and PBS)",
|
2005-01-23 20:41:20 +00:00
|
|
|
" Cian Duffy (MYOB) - BeOS port / manual writing",
|
2006-07-13 17:58:13 +00:00
|
|
|
" Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
|
2005-01-03 16:45:42 +00:00
|
|
|
"",
|
2006-11-16 22:05:33 +00:00
|
|
|
" Michael Blunck - Pre-Signals and Semaphores © 2003",
|
|
|
|
" George - Canal/Lock graphics © 2003-2004",
|
2005-01-03 16:45:42 +00:00
|
|
|
" 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!",
|
|
|
|
"",
|
|
|
|
"",
|
2005-01-23 20:41:20 +00:00
|
|
|
"And last but not least:",
|
2005-01-03 16:45:42 +00:00
|
|
|
" Chris Sawyer - For an amazing game!"
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void AboutWindowProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2005-01-03 16:45:42 +00:00
|
|
|
case WE_CREATE: /* Set up window counter and start position of scroller */
|
2005-01-13 16:28:47 +00:00
|
|
|
WP(w, scroller_d).counter = 0;
|
|
|
|
WP(w, scroller_d).height = w->height - 40;
|
2005-01-03 16:45:42 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2005-01-09 21:25:44 +00:00
|
|
|
uint i;
|
2005-01-13 16:28:47 +00:00
|
|
|
int y = WP(w, scroller_d).height;
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2005-01-03 16:45:42 +00:00
|
|
|
// Show original copyright and revision version
|
2005-01-23 21:24:33 +00:00
|
|
|
DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, 0);
|
|
|
|
DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, 0);
|
2005-01-03 16:45:42 +00:00
|
|
|
|
|
|
|
// Show all scrolling credits
|
|
|
|
for (i = 0; i < lengthof(credits); i++) {
|
|
|
|
if (y >= 50 && y < (w->height - 40)) {
|
2005-02-22 11:33:13 +00:00
|
|
|
DoDrawString(credits[i], 10, y, 0x10);
|
2005-01-03 16:45:42 +00:00
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the last text has scrolled start anew from the start
|
2005-01-13 16:28:47 +00:00
|
|
|
if (y < 50) WP(w, scroller_d).height = w->height - 40;
|
2005-01-03 16:45:42 +00:00
|
|
|
|
2005-07-19 22:12:04 +00:00
|
|
|
DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
|
|
|
|
DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
|
2005-01-03 16:45:42 +00:00
|
|
|
} break;
|
|
|
|
case WE_MOUSELOOP: /* Timer to scroll the text and adjust the new top */
|
2005-01-13 16:28:47 +00:00
|
|
|
if (WP(w, scroller_d).counter++ % 3 == 0) {
|
|
|
|
WP(w, scroller_d).height--;
|
2005-01-03 16:45:42 +00:00
|
|
|
SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-03 16:45:42 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _about_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_015B_OPENTTD, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL},
|
|
|
|
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _about_desc = {
|
2005-01-23 21:24:33 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 420, 272,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_GAME_OPTIONS,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_about_widgets,
|
|
|
|
AboutWindowProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowAboutWindow(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
|
|
AllocateWindowDesc(&_about_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _tree_to_plant;
|
|
|
|
|
|
|
|
static const uint32 _tree_sprites[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
0x655, 0x663, 0x678, 0x62B, 0x647, 0x639, 0x64E, 0x632, 0x67F, 0x68D, 0x69B, 0x6A9,
|
|
|
|
0x6AF, 0x6D2, 0x6D9, 0x6C4, 0x6CB, 0x6B6, 0x6BD, 0x6E0,
|
|
|
|
0x72E, 0x734, 0x74A, 0x74F, 0x76B, 0x78F, 0x788, 0x77B, 0x75F, 0x774, 0x720, 0x797,
|
|
|
|
0x79E, 0x7A5 | PALETTE_TO_GREEN, 0x7AC | PALETTE_TO_RED, 0x7B3, 0x7BA, 0x7C1 | PALETTE_TO_RED, 0x7C8 | PALETTE_TO_PALE_GREEN, 0x7CF | PALETTE_TO_YELLOW, 0x7D6 | PALETTE_TO_RED
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void BuildTreesWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int x,y;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
WP(w,tree_d).base = i = _tree_base_by_landscape[_opt.landscape];
|
|
|
|
WP(w,tree_d).count = count = _tree_count_by_landscape[_opt.landscape];
|
|
|
|
|
|
|
|
x = 18;
|
|
|
|
y = 54;
|
|
|
|
do {
|
|
|
|
DrawSprite(_tree_sprites[i], x, y);
|
|
|
|
x += 35;
|
|
|
|
if (!(++i & 3)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
x -= 35 * 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 47;
|
|
|
|
}
|
|
|
|
} while (--count);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
int wid = e->we.click.widget;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (wid) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0:
|
|
|
|
ResetObjectToPlace();
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case 3: case 4: case 5: case 6:
|
|
|
|
case 7: case 8: case 9: case 10:
|
|
|
|
case 11:case 12: case 13: case 14:
|
2005-11-14 19:48:04 +00:00
|
|
|
if (wid - 3 >= WP(w,tree_d).count) break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-06-06 13:47:06 +00:00
|
|
|
if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, 1, NULL))
|
2004-08-09 17:04:08 +00:00
|
|
|
_tree_to_plant = WP(w,tree_d).base + wid - 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15: // tree of random type.
|
2005-06-06 13:47:06 +00:00
|
|
|
if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, 1, NULL))
|
2004-08-09 17:04:08 +00:00
|
|
|
_tree_to_plant = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16: /* place trees randomly over the landscape*/
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayFx(SND_15_BEEP);
|
2004-08-09 17:04:08 +00:00
|
|
|
PlaceTreesRandomly();
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PLACE_OBJ:
|
2006-09-23 02:39:24 +00:00
|
|
|
VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED);
|
2004-08-09 17:04:08 +00:00
|
|
|
VpSetPlaceSizingLimit(20);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_DRAG:
|
2006-09-23 02:39:24 +00:00
|
|
|
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case WE_PLACE_MOUSEUP:
|
2006-10-28 23:47:00 +00:00
|
|
|
if (e->we.place.pt.x != -1) {
|
2006-09-23 02:39:24 +00:00
|
|
|
DoCommandP(e->we.place.tile, _tree_to_plant, e->we.place.starttile, NULL,
|
2004-08-09 17:04:08 +00:00
|
|
|
CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_TIMEOUT:
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowWidget(w, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowButtons(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _build_trees_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 170, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_trees_desc = {
|
|
|
|
497, 22, 143, 171,
|
2004-12-12 17:42:04 +00:00
|
|
|
WC_BUILD_TREES, WC_SCEN_LAND_GEN,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_trees_widgets,
|
|
|
|
BuildTreesWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_trees_scen_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_trees_scen_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 143, 184,
|
2004-12-12 17:42:04 +00:00
|
|
|
WC_BUILD_TREES,0,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_trees_scen_widgets,
|
|
|
|
BuildTreesWndProc
|
|
|
|
};
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowBuildTreesToolbar(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(_current_player)) return;
|
2005-05-19 17:40:26 +00:00
|
|
|
AllocateWindowDescFront(&_build_trees_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowBuildTreesScenToolbar(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
AllocateWindowDescFront(&_build_trees_scen_desc, 0);
|
|
|
|
}
|
|
|
|
|
2004-12-15 21:45:44 +00:00
|
|
|
static uint32 _errmsg_decode_params[20];
|
2004-08-09 17:04:08 +00:00
|
|
|
static StringID _errmsg_message_1, _errmsg_message_2;
|
|
|
|
static uint _errmsg_duration;
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _errmsg_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 239, 0, 13, STR_00B2_MESSAGE, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 4, 0, 239, 14, 45, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _errmsg_face_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 4, 0, 333, 14, 136, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ErrmsgWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
|
2005-01-03 19:45:18 +00:00
|
|
|
if (!IsWindowOfPrototype(w, _errmsg_face_widgets)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(
|
|
|
|
120,
|
2004-09-10 19:02:27 +00:00
|
|
|
(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15),
|
2004-08-09 17:04:08 +00:00
|
|
|
_errmsg_message_2,
|
|
|
|
238);
|
|
|
|
if (_errmsg_message_1 != INVALID_STRING_ID)
|
|
|
|
DrawStringMultiCenter(
|
|
|
|
120,
|
|
|
|
30,
|
|
|
|
_errmsg_message_1,
|
|
|
|
238);
|
|
|
|
} else {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Player *p = GetPlayer(GetDParamX(_errmsg_decode_params,2));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(
|
|
|
|
214,
|
2004-09-10 19:02:27 +00:00
|
|
|
(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
|
2004-08-09 17:04:08 +00:00
|
|
|
_errmsg_message_2,
|
|
|
|
238);
|
|
|
|
if (_errmsg_message_1 != INVALID_STRING_ID)
|
|
|
|
DrawStringMultiCenter(
|
|
|
|
214,
|
|
|
|
90,
|
|
|
|
_errmsg_message_1,
|
|
|
|
238);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP:
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_right_button_down) DeleteWindow(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_4:
|
2005-11-14 19:48:04 +00:00
|
|
|
if (--_errmsg_duration == 0) DeleteWindow(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
case WE_DESTROY:
|
2005-05-26 19:41:58 +00:00
|
|
|
SetRedErrorSquare(0);
|
2004-09-06 22:46:02 +00:00
|
|
|
_switch_mode_errorstr = INVALID_STRING_ID;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_KEYPRESS:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.keypress.keycode == WKC_SPACE) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// Don't continue.
|
2006-09-23 02:39:24 +00:00
|
|
|
e->we.keypress.cont = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
|
|
|
|
{
|
|
|
|
Window *w;
|
2006-11-18 00:14:43 +00:00
|
|
|
const ViewPort *vp;
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_ERRMSG, 0);
|
|
|
|
|
|
|
|
//assert(msg_2);
|
|
|
|
if (msg_2 == 0) msg_2 = STR_EMPTY;
|
|
|
|
|
|
|
|
_errmsg_message_1 = msg_1;
|
|
|
|
_errmsg_message_2 = msg_2;
|
|
|
|
COPY_OUT_DPARAM(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params));
|
|
|
|
_errmsg_duration = _patches.errmsg_duration;
|
2006-11-18 00:14:43 +00:00
|
|
|
if (!_errmsg_duration) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if ( (x|y) != 0) {
|
|
|
|
pt = RemapCoords2(x, y);
|
2006-11-18 00:14:43 +00:00
|
|
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// move x pos to opposite corner
|
|
|
|
pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
|
|
|
|
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// move y pos to opposite corner
|
|
|
|
pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top;
|
|
|
|
pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
pt.x = (_screen.width - 240) >> 1;
|
|
|
|
pt.y = (_screen.height - 46) >> 1;
|
|
|
|
}
|
|
|
|
w = AllocateWindow(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
|
|
|
|
} else {
|
|
|
|
if ( (x|y) != 0) {
|
|
|
|
pt = RemapCoords2(x, y);
|
2006-11-18 00:14:43 +00:00
|
|
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
2004-08-09 17:04:08 +00:00
|
|
|
pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
|
|
|
|
pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
|
|
|
|
} else {
|
|
|
|
pt.x = (_screen.width - 334) >> 1;
|
|
|
|
pt.y = (_screen.height - 137) >> 1;
|
|
|
|
}
|
|
|
|
w = AllocateWindow(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
|
|
|
|
}
|
|
|
|
|
|
|
|
w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowEstimatedCostOrIncome(int32 cost, int x, int y)
|
|
|
|
{
|
2005-10-07 07:35:15 +00:00
|
|
|
StringID msg = STR_0805_ESTIMATED_COST;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (cost < 0) {
|
|
|
|
cost = -cost;
|
|
|
|
msg = STR_0807_ESTIMATED_INCOME;
|
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, cost);
|
2005-10-07 07:35:15 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, msg, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost)
|
|
|
|
{
|
2005-10-07 07:35:15 +00:00
|
|
|
StringID msg;
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt = RemapCoords(x,y,z);
|
|
|
|
|
|
|
|
msg = STR_0801_COST;
|
|
|
|
if (cost < 0) {
|
|
|
|
cost = -cost;
|
|
|
|
msg = STR_0803_INCOME;
|
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, cost);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddTextEffect(msg, pt.x, pt.y, 0x250);
|
2005-06-15 16:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost)
|
|
|
|
{
|
|
|
|
Point pt = RemapCoords(x,y,z);
|
|
|
|
|
|
|
|
SetDParam(0, cost);
|
|
|
|
AddTextEffect(STR_FEEDER, pt.x, pt.y, 0x250);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-08-03 13:07:29 +00:00
|
|
|
static const Widget _tooltips_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 199, 0, 31, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void TooltipsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2006-10-12 15:13:40 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
uint arg;
|
2005-11-14 19:48:04 +00:00
|
|
|
GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);
|
|
|
|
GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44);
|
2006-10-12 15:13:40 +00:00
|
|
|
|
|
|
|
for (arg = 0; arg < WP(w, tooltips_d).paramcount; arg++) {
|
|
|
|
SetDParam(arg, WP(w, tooltips_d).params[arg]);
|
|
|
|
}
|
|
|
|
DrawStringMultiCenter((w->width >> 1), (w->height >> 1) - 5, WP(w, tooltips_d).string_id, 197);
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2006-10-12 15:13:40 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
case WE_MOUSELOOP:
|
2006-10-12 15:13:40 +00:00
|
|
|
/* We can show tooltips while dragging tools. These are shown as long as
|
|
|
|
* we are dragging the tool. Normal tooltips work with rmb */
|
|
|
|
if (WP(w, tooltips_d).paramcount == 0 ) {
|
|
|
|
if (!_right_button_down) DeleteWindow(w);
|
|
|
|
} else {
|
|
|
|
if (!_left_button_down) DeleteWindow(w);
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-12 15:13:40 +00:00
|
|
|
/** Shows a tooltip
|
|
|
|
* @param str String to be displayed
|
|
|
|
* @param params (optional) up to 5 pieces of additional information that may be
|
|
|
|
* added to a tooltip; currently only supports parameters of {NUM} (integer) */
|
2006-10-18 14:20:10 +00:00
|
|
|
void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
2006-10-12 15:13:40 +00:00
|
|
|
BoundingRect br;
|
2006-10-18 14:20:10 +00:00
|
|
|
Window *w;
|
2006-10-12 15:13:40 +00:00
|
|
|
uint i;
|
|
|
|
int x, y;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-10-18 14:20:10 +00:00
|
|
|
DeleteWindowById(WC_TOOLTIPS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-18 14:20:10 +00:00
|
|
|
/* We only show measurement tooltips with patch setting on */
|
|
|
|
if (str == STR_NULL || (paramcount != 0 && !_patches.measure_tooltip)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-12 15:13:40 +00:00
|
|
|
for (i = 0; i != paramcount; i++) SetDParam(i, params[i]);
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-12 15:13:40 +00:00
|
|
|
br = GetStringBoundingBox(buffer);
|
|
|
|
br.width += 6; br.height += 4; // increase slightly to have some space around the box
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-05 23:11:41 +00:00
|
|
|
/* Cut tooltip length to 200 pixels max, wrap to new line if longer */
|
2006-10-12 15:13:40 +00:00
|
|
|
if (br.width > 200) {
|
|
|
|
br.height += ((br.width - 4) / 176) * 10;
|
|
|
|
br.width = 200;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-09-05 23:11:41 +00:00
|
|
|
/* 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 */
|
|
|
|
y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
|
2006-10-12 15:13:40 +00:00
|
|
|
if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
|
|
|
|
x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
|
|
|
|
|
|
|
|
w = AllocateWindow(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
|
|
|
|
|
|
|
|
WP(w, tooltips_d).string_id = str;
|
|
|
|
assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0]));
|
|
|
|
memcpy(WP(w, tooltips_d).params, params, sizeof(WP(w, tooltips_d).params[0]) * paramcount);
|
|
|
|
WP(w, tooltips_d).paramcount = paramcount;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-05 23:11:41 +00:00
|
|
|
w->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
|
2006-10-12 15:13:40 +00:00
|
|
|
w->widget[0].right = br.width;
|
|
|
|
w->widget[0].bottom = br.height;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-25 14:19:33 +00:00
|
|
|
static void DrawStationCoverageText(const AcceptedCargo accepts,
|
|
|
|
int str_x, int str_y, uint mask)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-25 14:19:33 +00:00
|
|
|
char *b = _userstring;
|
2006-11-06 15:25:02 +00:00
|
|
|
bool first = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
int i;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-03-25 11:32:58 +00:00
|
|
|
b = InlineString(b, STR_000D_ACCEPTS);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-25 14:19:33 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++, mask >>= 1) {
|
2006-11-06 15:25:02 +00:00
|
|
|
if (b >= lastof(_userstring) - 5) break;
|
2005-03-25 14:19:33 +00:00
|
|
|
if (accepts[i] >= 8 && mask & 1) {
|
2006-11-06 15:25:02 +00:00
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
/* Add a comma if this is not the first item */
|
|
|
|
*b++ = ',';
|
|
|
|
*b++ = ' ';
|
|
|
|
}
|
2005-03-25 14:19:33 +00:00
|
|
|
b = InlineString(b, _cargoc.names_s[i]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-06 15:25:02 +00:00
|
|
|
/* If first is still true then no cargo is accepted */
|
|
|
|
if (first) b = InlineString(b, STR_00D0_NOTHING);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-06 15:25:02 +00:00
|
|
|
*b = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
|
|
|
|
}
|
|
|
|
|
2004-12-08 15:46:13 +00:00
|
|
|
void DrawStationCoverageAreaText(int sx, int sy, uint mask, int rad) {
|
2006-01-23 19:12:35 +00:00
|
|
|
TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
|
2005-10-07 07:35:15 +00:00
|
|
|
AcceptedCargo accepts;
|
2006-01-23 19:12:35 +00:00
|
|
|
if (tile < MapSize()) {
|
2006-04-03 05:32:11 +00:00
|
|
|
GetAcceptanceAroundTiles(accepts, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStationCoverageText(accepts, sx, sy, mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void CheckRedrawStationCoverage(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
if (_thd.dirty & 1) {
|
|
|
|
_thd.dirty &= ~1;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetVScrollCount(Window *w, int num)
|
|
|
|
{
|
|
|
|
w->vscroll.count = num;
|
|
|
|
num -= w->vscroll.cap;
|
|
|
|
if (num < 0) num = 0;
|
|
|
|
if (num < w->vscroll.pos) w->vscroll.pos = num;
|
|
|
|
}
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
void SetVScroll2Count(Window *w, int num)
|
2005-01-03 19:45:18 +00:00
|
|
|
{
|
2005-01-02 17:23:04 +00:00
|
|
|
w->vscroll2.count = num;
|
|
|
|
num -= w->vscroll2.cap;
|
|
|
|
if (num < 0) num = 0;
|
|
|
|
if (num < w->vscroll2.pos) w->vscroll2.pos = num;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void SetHScrollCount(Window *w, int num)
|
|
|
|
{
|
|
|
|
w->hscroll.count = num;
|
|
|
|
num -= w->hscroll.cap;
|
|
|
|
if (num < 0) num = 0;
|
|
|
|
if (num < w->hscroll.pos) w->hscroll.pos = num;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
uint width;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (backspace) {
|
|
|
|
do {
|
|
|
|
tb->caretpos--;
|
|
|
|
} while (IsUtf8Part(*(tb->buf + tb->caretpos)));
|
|
|
|
}
|
|
|
|
|
|
|
|
len = Utf8Decode(&c, tb->buf + tb->caretpos);
|
|
|
|
width = GetCharacterWidth(FS_NORMAL, c);
|
|
|
|
|
|
|
|
tb->width -= width;
|
|
|
|
if (backspace) tb->caretxoffs -= width;
|
|
|
|
|
|
|
|
/* Move the remaining characters over the marker */
|
|
|
|
memmove(tb->buf + tb->caretpos, tb->buf + tb->caretpos + len, tb->length - tb->caretpos - len + 1);
|
|
|
|
tb->length -= 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
|
|
|
|
* @param tb @Textbuf type to be changed
|
|
|
|
* @param delmode Type of deletion, either @WKC_BACKSPACE or @WKC_DELETE
|
|
|
|
* @return Return true on successfull change of Textbuf, or false otherwise
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
} else if (delmode == WKC_DELETE && tb->caretpos < tb->length) {
|
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
|
|
|
|
* @param tb @Textbuf buffer to be emptied
|
|
|
|
*/
|
|
|
|
void DeleteTextBufferAll(Textbuf *tb)
|
|
|
|
{
|
|
|
|
memset(tb->buf, 0, tb->maxlength);
|
|
|
|
tb->length = tb->width = 0;
|
|
|
|
tb->caretpos = tb->caretxoffs = 0;
|
|
|
|
}
|
|
|
|
|
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
|
2005-02-21 18:59:54 +00:00
|
|
|
* @param tb @Textbuf type to be changed
|
|
|
|
* @param key Character to be inserted
|
|
|
|
* @return Return true on successfull change of Textbuf, or false otherwise
|
|
|
|
*/
|
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);
|
2006-11-16 22:05:33 +00:00
|
|
|
size_t len = Utf8CharLen(key);
|
|
|
|
if (tb->length < (tb->maxlength - len) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
|
|
|
|
memmove(tb->buf + tb->caretpos + len, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
|
|
|
|
Utf8Encode(tb->buf + tb->caretpos, key);
|
|
|
|
tb->length += len;
|
|
|
|
tb->width += charwidth;
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
* @param tb @Textbuf type where navigation occurs
|
|
|
|
* @param navmode Direction in which navigation occurs @WKC_LEFT, @WKC_RIGHT, @WKC_END, @WKC_HOME
|
|
|
|
* @return Return true on successfull change of Textbuf, or false otherwise
|
|
|
|
*/
|
|
|
|
bool MoveTextBufferPos(Textbuf *tb, int navmode)
|
|
|
|
{
|
|
|
|
switch (navmode) {
|
|
|
|
case WKC_LEFT:
|
|
|
|
if (tb->caretpos != 0) {
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
|
|
|
|
|
|
|
do {
|
|
|
|
tb->caretpos--;
|
|
|
|
} while (IsUtf8Part(*(tb->buf + tb->caretpos)));
|
|
|
|
|
|
|
|
Utf8Decode(&c, tb->buf + tb->caretpos);
|
|
|
|
tb->caretxoffs -= GetCharacterWidth(FS_NORMAL, c);
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
return true;
|
2005-01-06 15:54:09 +00:00
|
|
|
}
|
2005-02-21 18:59:54 +00:00
|
|
|
break;
|
|
|
|
case WKC_RIGHT:
|
|
|
|
if (tb->caretpos < tb->length) {
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
|
|
|
|
|
|
|
tb->caretpos += Utf8Decode(&c, tb->buf + tb->caretpos);
|
|
|
|
tb->caretxoffs += GetCharacterWidth(FS_NORMAL, c);
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WKC_HOME:
|
|
|
|
tb->caretpos = 0;
|
|
|
|
tb->caretxoffs = 0;
|
|
|
|
return true;
|
|
|
|
case WKC_END:
|
|
|
|
tb->caretpos = tb->length;
|
|
|
|
tb->caretxoffs = tb->width;
|
|
|
|
return true;
|
|
|
|
}
|
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
|
|
|
|
* @param tb @Textbuf type which is getting initialized
|
|
|
|
* @param buf the buffer that will be holding the data for input
|
|
|
|
* @param maxlength maximum length in characters of this buffer
|
|
|
|
* @param maxwidth maximum length in pixels of this buffer. If reached, buffer
|
2006-10-27 11:09:24 +00:00
|
|
|
* cannot grow, even if maxlength would allow because there is space. A length
|
|
|
|
* of zero '0' means the buffer is only restricted by maxlength */
|
2006-10-24 22:57:44 +00:00
|
|
|
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth)
|
|
|
|
{
|
|
|
|
tb->buf = (char*)buf;
|
|
|
|
tb->maxlength = maxlength;
|
|
|
|
tb->maxwidth = maxwidth;
|
|
|
|
tb->caret = true;
|
|
|
|
UpdateTextBufferSize(tb);
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
/**
|
|
|
|
* Update @Textbuf type with its actual physical character and screenlength
|
|
|
|
* 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
|
|
|
|
* @param tb @Textbuf type which length is calculated
|
|
|
|
*/
|
|
|
|
void UpdateTextBufferSize(Textbuf *tb)
|
|
|
|
{
|
2006-11-16 22:05:33 +00:00
|
|
|
const char *buf = tb->buf;
|
|
|
|
WChar c = Utf8Consume(&buf);
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
tb->width = 0;
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
for (; c != '\0' && tb->length < (tb->maxlength - 1); c = Utf8Consume(&buf)) {
|
|
|
|
tb->width += GetCharacterWidth(FS_NORMAL, c);
|
2005-02-21 18:59:54 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
tb->length = buf - tb->buf - 1;
|
2005-02-21 18:59:54 +00:00
|
|
|
tb->caretpos = tb->length;
|
|
|
|
tb->caretxoffs = tb->width;
|
|
|
|
}
|
|
|
|
|
2006-10-21 22:50:57 +00:00
|
|
|
int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *e)
|
2005-02-21 18:59:54 +00:00
|
|
|
{
|
2006-09-23 02:39:24 +00:00
|
|
|
e->we.keypress.cont = false;
|
2005-02-21 18:59:54 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.keypress.keycode) {
|
2005-02-21 18:59:54 +00:00
|
|
|
case WKC_ESC: return 2;
|
|
|
|
case WKC_RETURN: case WKC_NUM_ENTER: return 1;
|
|
|
|
case (WKC_CTRL | 'V'):
|
2006-01-26 16:19:24 +00:00
|
|
|
if (InsertTextBufferClipboard(&string->text))
|
2005-02-21 18:59:54 +00:00
|
|
|
InvalidateWidget(w, wid);
|
|
|
|
break;
|
2005-05-30 16:03:21 +00:00
|
|
|
case (WKC_CTRL | 'U'):
|
2006-01-26 16:19:24 +00:00
|
|
|
DeleteTextBufferAll(&string->text);
|
2005-05-30 16:03:21 +00:00
|
|
|
InvalidateWidget(w, wid);
|
|
|
|
break;
|
2005-02-21 18:59:54 +00:00
|
|
|
case WKC_BACKSPACE: case WKC_DELETE:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode))
|
2005-02-21 18:59:54 +00:00
|
|
|
InvalidateWidget(w, wid);
|
|
|
|
break;
|
|
|
|
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (MoveTextBufferPos(&string->text, e->we.keypress.keycode))
|
2005-02-21 18:59:54 +00:00
|
|
|
InvalidateWidget(w, wid);
|
2006-06-27 21:25:53 +00:00
|
|
|
break;
|
2005-02-21 18:59:54 +00:00
|
|
|
default:
|
2006-11-16 22:05:33 +00:00
|
|
|
if (IsValidChar(e->we.keypress.key, string->afilter)) {
|
|
|
|
if (InsertTextBufferChar(&string->text, e->we.keypress.key)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidateWidget(w, wid);
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
2006-08-19 09:31:22 +00:00
|
|
|
} else { // key wasn't caught. Continue only if standard entry specified
|
2006-10-21 22:50:57 +00:00
|
|
|
e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
bool HandleCaret(Textbuf *tb)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* caret changed? */
|
2005-02-21 18:59:54 +00:00
|
|
|
bool b = !!(_caret_timer & 0x20);
|
|
|
|
|
|
|
|
if (b != tb->caret) {
|
|
|
|
tb->caret = b;
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-02-21 18:59:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-01-26 16:19:24 +00:00
|
|
|
void HandleEditBox(Window *w, querystr_d *string, int wid)
|
2005-02-21 18:59:54 +00:00
|
|
|
{
|
2006-01-26 16:19:24 +00:00
|
|
|
if (HandleCaret(&string->text)) InvalidateWidget(w, wid);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-01-26 16:19:24 +00:00
|
|
|
void DrawEditBox(Window *w, querystr_d *string, int wid)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-27 10:12:57 +00:00
|
|
|
DrawPixelInfo dpi, *old_dpi;
|
|
|
|
int delta;
|
|
|
|
const Widget *wi = &w->widget[wid];
|
2006-01-26 16:19:24 +00:00
|
|
|
const Textbuf *tb = &string->text;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-27 10:12:57 +00:00
|
|
|
/* Limit the drawing of the string inside the widget boundaries */
|
|
|
|
if (!FillDrawPixelInfo(&dpi,
|
2006-11-18 00:14:43 +00:00
|
|
|
wi->left + 4,
|
|
|
|
wi->top + 1,
|
|
|
|
wi->right - wi->left - 4,
|
|
|
|
wi->bottom - wi->top - 1)
|
2006-10-27 10:12:57 +00:00
|
|
|
) return;
|
|
|
|
|
|
|
|
GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
|
|
|
|
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
|
_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 */
|
|
|
|
delta = (wi->right - wi->left) - tb->width - 10;
|
|
|
|
if (delta > 0) delta = 0;
|
|
|
|
|
|
|
|
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
|
|
|
|
|
|
|
|
DoDrawString(tb->buf, delta, 0, 8);
|
|
|
|
if (tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, 12);
|
|
|
|
|
|
|
|
_cur_dpi = old_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void QueryStringWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2004-12-04 17:54:56 +00:00
|
|
|
static bool closed = false;
|
2005-05-17 23:25:18 +00:00
|
|
|
switch (e->event) {
|
|
|
|
case WE_CREATE:
|
|
|
|
SETBIT(_no_scroll, SCROLL_EDIT);
|
|
|
|
closed = false;
|
|
|
|
break;
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
case WE_PAINT:
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, WP(w,querystr_d).caption);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2006-01-26 16:19:24 +00:00
|
|
|
DrawEditBox(w, &WP(w,querystr_d), 5);
|
2005-02-21 18:59:54 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 3: DeleteWindow(w); break;
|
|
|
|
case 4:
|
|
|
|
press_ok:;
|
2005-02-19 14:40:32 +00:00
|
|
|
if (WP(w, querystr_d).orig != NULL &&
|
2005-02-21 18:59:54 +00:00
|
|
|
strcmp(WP(w, querystr_d).text.buf, WP(w, querystr_d).orig) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
} else {
|
2005-02-21 18:59:54 +00:00
|
|
|
char *buf = WP(w,querystr_d).text.buf;
|
2004-11-14 09:31:39 +00:00
|
|
|
WindowClass wnd_class = WP(w,querystr_d).wnd_class;
|
|
|
|
WindowNumber wnd_num = WP(w,querystr_d).wnd_num;
|
|
|
|
Window *parent;
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
// Mask the edit-box as closed, so we don't send out a CANCEL
|
|
|
|
closed = true;
|
|
|
|
|
2004-12-12 13:46:10 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
|
2004-11-14 09:31:39 +00:00
|
|
|
parent = FindWindowById(wnd_class, wnd_num);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (parent != NULL) {
|
|
|
|
WindowEvent e;
|
|
|
|
e.event = WE_ON_EDIT_TEXT;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.edittext.str = buf;
|
2004-08-09 17:04:08 +00:00
|
|
|
parent->wndproc(parent, &e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP: {
|
|
|
|
if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
2006-01-26 16:19:24 +00:00
|
|
|
HandleEditBox(w, &WP(w, querystr_d), 5);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_KEYPRESS: {
|
2006-10-21 22:50:57 +00:00
|
|
|
switch (HandleEditBoxKey(w, &WP(w, querystr_d), 5, e)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 1: // Return
|
|
|
|
goto press_ok;
|
|
|
|
case 2: // Escape
|
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
2004-12-04 17:54:56 +00:00
|
|
|
// If the window is not closed yet, it means it still needs to send a CANCEL
|
|
|
|
if (!closed) {
|
|
|
|
Window *parent = FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num);
|
|
|
|
if (parent != NULL) {
|
|
|
|
WindowEvent e;
|
|
|
|
e.event = WE_ON_EDIT_TEXT_CANCEL;
|
|
|
|
parent->wndproc(parent, &e);
|
|
|
|
}
|
|
|
|
}
|
2005-02-22 14:52:20 +00:00
|
|
|
CLRBIT(_no_scroll, SCROLL_EDIT);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _query_string_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 259, 0, 13, STR_012D, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 259, 14, 29, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 129, 30, 41, STR_012E_CANCEL, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 130, 259, 30, 41, STR_012F_OK, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 2, 257, 16, 27, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _query_string_desc = {
|
|
|
|
190, 219, 260, 42,
|
|
|
|
WC_QUERY_STRING,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_query_string_widgets,
|
|
|
|
QueryStringWndProc
|
|
|
|
};
|
|
|
|
|
2005-02-19 14:40:32 +00:00
|
|
|
static char _edit_str_buf[64];
|
|
|
|
static char _orig_str_buf[lengthof(_edit_str_buf)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-19 09:31:22 +00:00
|
|
|
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, WindowClass window_class, WindowNumber window_number, CharSetFilter afilter)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
2005-02-21 18:59:54 +00:00
|
|
|
uint realmaxlen = maxlen & ~0x1000;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
assert(realmaxlen < lengthof(_edit_str_buf));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DeleteWindowById(WC_QUERY_STRING, 0);
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
|
2005-02-19 14:40:32 +00:00
|
|
|
w = AllocateWindowDesc(&_query_string_desc);
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(_edit_str_buf, str, lastof(_edit_str_buf));
|
2006-10-24 23:11:40 +00:00
|
|
|
_edit_str_buf[realmaxlen - 1] = '\0';
|
2004-12-11 12:30:12 +00:00
|
|
|
|
|
|
|
if (maxlen & 0x1000) {
|
2005-02-19 14:40:32 +00:00
|
|
|
WP(w, querystr_d).orig = NULL;
|
|
|
|
} else {
|
2006-10-24 23:11:40 +00:00
|
|
|
strecpy(_orig_str_buf, _edit_str_buf, lastof(_orig_str_buf));
|
2005-02-19 14:40:32 +00:00
|
|
|
WP(w, querystr_d).orig = _orig_str_buf;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, 5);
|
2005-02-21 18:59:54 +00:00
|
|
|
WP(w, querystr_d).caption = caption;
|
|
|
|
WP(w, querystr_d).wnd_class = window_class;
|
|
|
|
WP(w, querystr_d).wnd_num = window_number;
|
2006-08-19 09:31:22 +00:00
|
|
|
WP(w, querystr_d).afilter = afilter;
|
2006-10-24 22:57:44 +00:00
|
|
|
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth);
|
2004-08-09 17:04:08 +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
|
|
|
static void QueryWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT:
|
|
|
|
SetDParam(0, WP(w, query_d).caption);
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(90, 38, WP(w, query_d).message, 178);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
(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
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
WP(w, query_d).calledback = true;
|
2006-09-23 02:39:24 +00:00
|
|
|
if (WP(w, query_d).ok_cancel_callback != NULL) WP(w, query_d).ok_cancel_callback(e->we.click.widget == 4);
|
(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
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP:
|
|
|
|
if (!FindWindowById(WP(w, query_d).wnd_class, WP(w, query_d).wnd_num)) DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
if (!WP(w, query_d).calledback && WP(w, query_d).ok_cancel_callback != NULL) WP(w, query_d).ok_cancel_callback(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _query_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 179, 0, 13, STR_012D, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 4, 0, 179, 14, 91, 0x0, STR_NULL},
|
(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
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 12, 25, 84, 72, 83, STR_012E_CANCEL, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 12, 95, 154, 72, 83, STR_012F_OK, STR_NULL},
|
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _query_desc = {
|
|
|
|
WDP_CENTER, WDP_CENTER, 180, 92,
|
|
|
|
WC_OK_CANCEL_QUERY, 0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_query_widgets,
|
|
|
|
QueryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowQuery(StringID caption, StringID message, void (*ok_cancel_callback)(bool ok_clicked), WindowClass window_class, WindowNumber window_number)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_OK_CANCEL_QUERY, 0);
|
|
|
|
|
|
|
|
w = AllocateWindowDesc(&_query_desc);
|
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, 5);
|
(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
|
|
|
WP(w, query_d).caption = caption;
|
|
|
|
WP(w, query_d).message = message;
|
|
|
|
WP(w, query_d).wnd_class = window_class;
|
|
|
|
WP(w, query_d).wnd_num = window_number;
|
|
|
|
WP(w, query_d).ok_cancel_callback = ok_cancel_callback;
|
|
|
|
WP(w, query_d).calledback = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-14 00:27:28 +00:00
|
|
|
static const Widget _load_dialog_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 256, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 128, 256, 14, 25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 0, 256, 26, 47, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 256, 48, 293, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 245, 256, 48, 59, SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON},
|
|
|
|
{ WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 291, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 281, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 282, 293, 0x0, STR_RESIZE_BUTTON},
|
(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
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const Widget _save_dialog_widgets[] = {
|
2006-11-14 00:27:28 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 256, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 128, 256, 14, 25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 0, 256, 26, 47, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 256, 48, 291, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 245, 256, 48, 59, SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON},
|
|
|
|
{ WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 290, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 291, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 256, 292, 307, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 2, 254, 294, 305, 0x0, STR_400B_CURRENTLY_SELECTED_NAME},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 127, 308, 319, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 128, 244, 308, 319, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 308, 319, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-08-01 16:31:19 +00:00
|
|
|
// Colors for fios types
|
(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
|
|
|
const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5, 6, 6, 8};
|
2005-08-01 16:31:19 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void BuildFileList(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-28 13:30:51 +00:00
|
|
|
_fios_path_changed = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
FiosFreeSavegameList();
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
switch (_saveload_mode) {
|
|
|
|
case SLD_NEW_GAME:
|
|
|
|
case SLD_LOAD_SCENARIO:
|
|
|
|
case SLD_SAVE_SCENARIO:
|
2006-08-05 00:59:45 +00:00
|
|
|
_fios_list = FiosGetScenarioList(_saveload_mode); 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
|
|
|
case SLD_LOAD_HEIGHTMAP:
|
|
|
|
_fios_list = FiosGetHeightmapList(_saveload_mode); break;
|
2005-10-23 13:04:44 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
default: _fios_list = FiosGetSavegameList(_saveload_mode); break;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 16:01:26 +00:00
|
|
|
static void DrawFiosTexts(uint maxw)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-28 13:30:51 +00:00
|
|
|
static const char *path = NULL;
|
|
|
|
static StringID str = STR_4006_UNABLE_TO_READ_DRIVE;
|
|
|
|
static uint32 tot = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-28 13:30:51 +00:00
|
|
|
if (_fios_path_changed) {
|
|
|
|
str = FiosGetDescText(&path, &tot);
|
|
|
|
_fios_path_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str != STR_4006_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
|
|
|
|
DrawString(2, 37, str, 0);
|
2005-07-17 17:15:33 +00:00
|
|
|
DoDrawStringTruncated(path, 2, 27, 16, maxw);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void MakeSortedSaveGameList(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-13 14:54:09 +00:00
|
|
|
uint sort_start = 0;
|
|
|
|
uint sort_end = 0;
|
|
|
|
uint s_amount;
|
|
|
|
int i;
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
/* Directories are always above the files (FIOS_TYPE_DIR)
|
|
|
|
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
|
|
|
|
* Only sort savegames/scenarios, not directories
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-11-13 14:54:09 +00:00
|
|
|
for (i = 0; i < _fios_num; i++) {
|
|
|
|
switch (_fios_list[i].type) {
|
|
|
|
case FIOS_TYPE_DIR: sort_start++; break;
|
|
|
|
case FIOS_TYPE_PARENT: sort_start++; break;
|
|
|
|
case FIOS_TYPE_DRIVE: sort_end++; break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s_amount = _fios_num - sort_start - sort_end;
|
2005-01-23 10:54:32 +00:00
|
|
|
if (s_amount > 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
qsort(_fios_list + sort_start, s_amount, sizeof(FiosItem), compare_FiosItems);
|
|
|
|
}
|
|
|
|
|
2004-11-14 15:11:25 +00:00
|
|
|
static void GenerateFileName(void)
|
|
|
|
{
|
2004-12-13 18:53:59 +00:00
|
|
|
/* Check if we are not a specatator who wants to generate a name..
|
|
|
|
Let's use the name of player #0 for now. */
|
2006-10-14 22:31:18 +00:00
|
|
|
const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
|
2004-12-13 18:53:59 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, _date);
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
|
2004-11-14 15:11:25 +00:00
|
|
|
}
|
|
|
|
|
2005-01-23 23:59:49 +00:00
|
|
|
extern void StartupEngines(void);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-10-28 00:09:59 +00:00
|
|
|
static FiosItem o_dir;
|
|
|
|
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_CREATE: { /* Set up OPENTTD button */
|
|
|
|
o_dir.type = FIOS_TYPE_DIRECT;
|
|
|
|
switch (_saveload_mode) {
|
2005-11-14 19:48:04 +00:00
|
|
|
case SLD_SAVE_GAME:
|
|
|
|
case SLD_LOAD_GAME:
|
2005-10-28 00:09:59 +00:00
|
|
|
ttd_strlcpy(&o_dir.name[0], _path.save_dir, sizeof(o_dir.name));
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
case SLD_SAVE_SCENARIO:
|
|
|
|
case SLD_LOAD_SCENARIO:
|
2005-10-28 00:09:59 +00:00
|
|
|
ttd_strlcpy(&o_dir.name[0], _path.scenario_dir, sizeof(o_dir.name));
|
|
|
|
break;
|
2005-11-14 19:48:04 +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
|
|
|
case SLD_LOAD_HEIGHTMAP:
|
|
|
|
ttd_strlcpy(&o_dir.name[0], _path.heightmap_dir, sizeof(o_dir.name));
|
|
|
|
break;
|
|
|
|
|
2005-10-28 00:09:59 +00:00
|
|
|
default:
|
|
|
|
ttd_strlcpy(&o_dir.name[0], _path.personal_dir, sizeof(o_dir.name));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2006-06-10 08:37:41 +00:00
|
|
|
int pos;
|
|
|
|
int y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SetVScrollCount(w, _fios_num);
|
|
|
|
DrawWindowWidgets(w);
|
2005-07-17 16:01:26 +00:00
|
|
|
DrawFiosTexts(w->width);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (_savegame_sort_dirty) {
|
|
|
|
_savegame_sort_dirty = false;
|
|
|
|
MakeSortedSaveGameList();
|
|
|
|
}
|
|
|
|
|
2005-12-13 22:28:44 +00:00
|
|
|
GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7);
|
2005-10-17 19:57:00 +00:00
|
|
|
DoDrawString(
|
|
|
|
_savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
|
|
|
|
_savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9,
|
|
|
|
15, 16
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-12-13 22:28:44 +00:00
|
|
|
y = w->widget[7].top + 1;
|
2006-06-10 08:37:41 +00:00
|
|
|
for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
|
2006-07-26 03:33:12 +00:00
|
|
|
const FiosItem *item = _fios_list + pos;
|
2006-06-10 08:37:41 +00:00
|
|
|
|
2005-07-17 17:15:33 +00:00
|
|
|
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18);
|
2005-10-23 13:04:44 +00:00
|
|
|
y += 10;
|
2005-12-13 22:28:44 +00:00
|
|
|
if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
2006-01-26 16:19:24 +00:00
|
|
|
DrawEditBox(w, &WP(w,querystr_d), 10);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-06-10 08:37:41 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 2: /* Sort save names by name */
|
2005-10-17 19:57:00 +00:00
|
|
|
_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
|
|
|
|
SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
|
2004-08-09 17:04:08 +00:00
|
|
|
_savegame_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Sort save names by date */
|
2005-10-17 19:57:00 +00:00
|
|
|
_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
|
|
|
|
SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
|
2004-08-09 17:04:08 +00:00
|
|
|
_savegame_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2005-12-13 22:28:44 +00:00
|
|
|
case 6: /* OpenTTD 'button', jumps to OpenTTD directory */
|
|
|
|
FiosBrowseTo(&o_dir);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
BuildFileList();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7: { /* Click the listbox */
|
2006-09-23 02:39:24 +00:00
|
|
|
int y = (e->we.click.pt.y - w->widget[e->we.click.widget].top - 1) / 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
char *name;
|
|
|
|
const FiosItem *file;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
file = _fios_list + y;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
name = FiosBrowseTo(file);
|
|
|
|
if (name != NULL) {
|
2005-07-17 16:01:26 +00:00
|
|
|
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
|
|
|
|
_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetFiosType(file->type);
|
2005-07-17 16:01:26 +00:00
|
|
|
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
|
|
|
|
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
(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
|
|
|
} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
|
|
|
|
SetFiosType(file->type);
|
|
|
|
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
|
|
|
|
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
|
|
|
|
|
|
|
|
DeleteWindow(w);
|
|
|
|
ShowHeightmapLoad();
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox
|
2006-03-21 22:08:15 +00:00
|
|
|
ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
|
2005-02-21 18:59:54 +00:00
|
|
|
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
2005-10-28 00:09:59 +00:00
|
|
|
InvalidateWidget(w, 10);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Changed directory, need repaint.
|
|
|
|
SetWindowDirty(w);
|
|
|
|
BuildFileList();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-10-28 00:09:59 +00:00
|
|
|
|
|
|
|
case 11: case 12: /* Delete, Save game */
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_MOUSELOOP:
|
2006-01-26 16:19:24 +00:00
|
|
|
HandleEditBox(w, &WP(w, querystr_d), 10);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
case WE_KEYPRESS:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.keypress.keycode == WKC_ESC) {
|
2005-07-22 09:16:34 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
2006-10-21 22:50:57 +00:00
|
|
|
if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) /* Press Enter */
|
2005-10-28 00:09:59 +00:00
|
|
|
HandleButtonClick(w, 12);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_TIMEOUT:
|
2006-11-06 19:59:19 +00:00
|
|
|
/* This test protects against using widgets 11 and 12 which are only available
|
|
|
|
* in those two saveload mode */
|
|
|
|
if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
|
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
if (IsWindowWidgetLowered(w, 11)) { /* Delete button clicked */
|
2006-11-28 14:42:31 +00:00
|
|
|
if (!FiosDelete(WP(w,querystr_d).text.buf)) {
|
2005-08-01 00:14:22 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
|
2006-03-21 22:09:19 +00:00
|
|
|
} else {
|
|
|
|
BuildFileList();
|
|
|
|
/* Reset file name to current date on successfull delete */
|
|
|
|
if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
|
2005-08-01 00:14:22 +00:00
|
|
|
}
|
2006-03-21 22:09:19 +00:00
|
|
|
|
|
|
|
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
2006-10-03 20:16:20 +00:00
|
|
|
} else if (IsWindowWidgetLowered(w, 12)) { /* Save button clicked */
|
2004-08-09 17:04:08 +00:00
|
|
|
_switch_mode = SM_SAVE;
|
2006-03-21 22:08:15 +00:00
|
|
|
FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf, sizeof(_file_to_saveload.name));
|
2005-01-23 23:59:49 +00:00
|
|
|
|
|
|
|
/* In the editor set up the vehicle engines correctly (date might have changed) */
|
|
|
|
if (_game_mode == GM_EDITOR) StartupEngines();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_DESTROY:
|
2005-02-03 19:23:06 +00:00
|
|
|
// pause is only used in single-player, non-editor mode, non menu mode
|
2006-02-01 07:36:15 +00:00
|
|
|
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
2004-09-17 17:53:34 +00:00
|
|
|
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
2006-02-01 07:36:15 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
FiosFreeSavegameList();
|
2005-02-22 14:52:20 +00:00
|
|
|
CLRBIT(_no_scroll, SCROLL_SAVE);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
case WE_RESIZE: {
|
|
|
|
/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
|
2006-09-23 02:39:24 +00:00
|
|
|
uint diff = e->we.sizing.diff.x / 2;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget[2].right += diff;
|
|
|
|
w->widget[3].left += diff;
|
2006-09-23 02:39:24 +00:00
|
|
|
w->widget[3].right += e->we.sizing.diff.x;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-10-28 00:09:59 +00:00
|
|
|
/* Same for widget 11 and 12 in save-dialog */
|
2005-01-03 19:45:18 +00:00
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
2005-10-28 00:09:59 +00:00
|
|
|
w->widget[11].right += diff;
|
|
|
|
w->widget[12].left += diff;
|
2006-09-23 02:39:24 +00:00
|
|
|
w->widget[12].right += e->we.sizing.diff.x;
|
2005-01-03 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 10;
|
2005-01-03 19:45:18 +00:00
|
|
|
} break;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _load_dialog_desc = {
|
|
|
|
WDP_CENTER, WDP_CENTER, 257, 294,
|
|
|
|
WC_SAVELOAD,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2006-11-14 00:27:28 +00:00
|
|
|
_load_dialog_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
SaveLoadDlgWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _save_dialog_desc = {
|
|
|
|
WDP_CENTER, WDP_CENTER, 257, 320,
|
|
|
|
WC_SAVELOAD,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_save_dialog_widgets,
|
|
|
|
SaveLoadDlgWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowSaveLoadDialog(int mode)
|
|
|
|
{
|
2006-11-14 00:27:28 +00:00
|
|
|
static const StringID saveload_captions[] = {
|
|
|
|
STR_4001_LOAD_GAME,
|
|
|
|
STR_0298_LOAD_SCENARIO,
|
|
|
|
STR_4000_SAVE_GAME,
|
|
|
|
STR_0299_SAVE_SCENARIO,
|
|
|
|
STR_4011_LOAD_HEIGHTMAP,
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *w;
|
2006-11-14 00:27:28 +00:00
|
|
|
const WindowDesc *sld = &_save_dialog_desc;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-06 13:47:06 +00:00
|
|
|
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_QUERY_STRING, 0);
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
|
|
|
|
_saveload_mode = mode;
|
2005-02-22 14:52:20 +00:00
|
|
|
SETBIT(_no_scroll, SCROLL_SAVE);
|
|
|
|
|
|
|
|
switch (mode) {
|
2005-11-13 14:54:09 +00:00
|
|
|
case SLD_SAVE_GAME: GenerateFileName(); break;
|
|
|
|
case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
|
2006-11-14 00:27:28 +00:00
|
|
|
default: sld = &_load_dialog_desc; break;
|
2005-02-22 14:52:20 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-14 00:27:28 +00:00
|
|
|
assert((uint)mode < lengthof(saveload_captions));
|
|
|
|
w = AllocateWindowDesc(sld);
|
|
|
|
w->widget[1].data = saveload_captions[mode];
|
2004-08-09 17:04:08 +00:00
|
|
|
w->vscroll.cap = 24;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.step_width = 2;
|
|
|
|
w->resize.step_height = 10;
|
|
|
|
w->resize.height = w->height - 14 * 10; // Minimum of 10 items
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, 7);
|
2006-10-24 22:57:44 +00:00
|
|
|
|
|
|
|
WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
|
|
|
|
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-03 19:23:06 +00:00
|
|
|
// pause is only used in single-player, non-editor mode, non-menu mode. It
|
|
|
|
// will be unpaused in the WE_DESTROY event handler.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
|
2004-09-17 17:53:34 +00:00
|
|
|
DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-09-17 17:53:34 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
BuildFileList();
|
|
|
|
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void RedrawAutosave(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0));
|
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void SetFiosType(const byte fiostype)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
switch (fiostype) {
|
2005-10-23 13:04:44 +00:00
|
|
|
case FIOS_TYPE_FILE:
|
|
|
|
case FIOS_TYPE_SCENARIO:
|
|
|
|
_file_to_saveload.mode = SL_LOAD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOS_TYPE_OLDFILE:
|
|
|
|
case FIOS_TYPE_OLD_SCENARIO:
|
|
|
|
_file_to_saveload.mode = SL_OLD_LOAD;
|
|
|
|
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
|
|
|
#ifdef WITH_PNG
|
|
|
|
case FIOS_TYPE_PNG:
|
|
|
|
_file_to_saveload.mode = SL_PNG;
|
|
|
|
break;
|
|
|
|
#endif /* WITH_PNG */
|
|
|
|
|
|
|
|
case FIOS_TYPE_BMP:
|
|
|
|
_file_to_saveload.mode = SL_BMP;
|
|
|
|
break;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
default:
|
|
|
|
_file_to_saveload.mode = SL_INVALID;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-14 19:44:06 +00:00
|
|
|
static int32 ClickMoneyCheat(int32 p1, int32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// p1 player to set to, p2 is -1 or +1 (down/up)
|
2004-11-14 19:44:06 +00:00
|
|
|
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-14 22:31:18 +00:00
|
|
|
while (IsValidPlayer((PlayerID)p1)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_players[p1].is_active) {
|
2006-10-14 22:31:18 +00:00
|
|
|
_local_player = (PlayerID)p1;
|
2004-08-25 09:23:55 +00:00
|
|
|
MarkWholeScreenDirty();
|
2004-08-09 17:04:08 +00:00
|
|
|
return _local_player;
|
|
|
|
}
|
|
|
|
p1 += p2;
|
|
|
|
}
|
2004-09-03 21:48:21 +00:00
|
|
|
|
|
|
|
return _local_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-21 13:21:09 +00:00
|
|
|
// p1 -1 or +1 (down/up)
|
2005-01-22 22:47:58 +00:00
|
|
|
static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
|
2004-08-21 13:21:09 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (p1 == -1) p1 = 3;
|
|
|
|
if (p1 == 4) p1 = 0;
|
2004-08-21 13:21:09 +00:00
|
|
|
_opt.landscape = p1;
|
|
|
|
GfxLoadSprites();
|
2006-11-24 18:39:22 +00:00
|
|
|
LoadStringWidthTable();
|
2004-08-21 13:21:09 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
return _opt.landscape;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
extern void EnginesMonthlyLoop(void);
|
2004-08-22 15:25:36 +00:00
|
|
|
|
|
|
|
// p2 1 (increase) or -1 (decrease)
|
2005-01-22 22:47:58 +00:00
|
|
|
static int32 ClickChangeDateCheat(int32 p1, int32 p2)
|
2004-08-22 15:25:36 +00:00
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
2006-08-15 16:49:48 +00:00
|
|
|
ConvertDateToYMD(_date, &ymd);
|
2004-08-22 15:25:36 +00:00
|
|
|
|
2006-08-16 11:39:55 +00:00
|
|
|
if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
|
2004-08-22 15:25:36 +00:00
|
|
|
|
2006-08-15 16:49:48 +00:00
|
|
|
SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
|
2004-08-22 15:25:36 +00:00
|
|
|
EnginesMonthlyLoop();
|
|
|
|
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0));
|
|
|
|
return _cur_year;
|
|
|
|
}
|
2004-08-21 13:21:09 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef int32 CheckButtonClick(int32, int32);
|
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
enum ce_flags {CE_CLICK = 1 << 0};
|
|
|
|
|
|
|
|
typedef byte ce_flags;
|
2005-02-08 16:53:28 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct CheatEntry {
|
2006-03-01 20:49:47 +00:00
|
|
|
VarType type; // type of selector
|
|
|
|
ce_flags flags; // selector flags
|
|
|
|
StringID str; // string with descriptive text
|
|
|
|
void *variable; // pointer to the variable
|
|
|
|
bool *been_used; // has this cheat been used before?
|
|
|
|
CheckButtonClick *proc;// procedure
|
|
|
|
int16 min, max; // range for spinbox setting
|
2004-08-09 17:04:08 +00:00
|
|
|
} CheatEntry;
|
|
|
|
|
|
|
|
static const CheatEntry _cheats_ui[] = {
|
2006-03-01 20:49:47 +00:00
|
|
|
{SLE_BOOL,CE_CLICK, STR_CHEAT_MONEY, &_cheats.money.value, &_cheats.money.been_used, &ClickMoneyCheat, 0, 0},
|
|
|
|
{SLE_UINT8, 0, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat, 0, 11},
|
|
|
|
{SLE_BOOL, 0, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL, 0, 0},
|
|
|
|
{SLE_BOOL, 0, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL, 0, 0},
|
|
|
|
{SLE_BOOL, 0, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL, 0, 0},
|
|
|
|
{SLE_BOOL, 0, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL, 0, 0},
|
|
|
|
{SLE_BOOL, 0, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL, 0, 0},
|
|
|
|
{SLE_UINT8, 0, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat,-1, 4},
|
2006-08-20 18:40:57 +00:00
|
|
|
{SLE_INT32, 0, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat, -1, 1},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _cheat_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_CHEATS_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-04-29 14:31:16 +00:00
|
|
|
extern void DrawPlayerIcon(PlayerID pid, int x, int y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void CheatsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int clk = WP(w,def_d).data_1;
|
|
|
|
int x, y;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, 350);
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
x = 0;
|
|
|
|
y = 45;
|
|
|
|
|
|
|
|
for (i = 0; i != lengthof(_cheats_ui); i++) {
|
2006-03-01 20:49:47 +00:00
|
|
|
const CheatEntry *ce = &_cheats_ui[i];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-19 06:46:41 +00:00
|
|
|
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, x + 5, y + 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
switch (ce->type) {
|
|
|
|
case SLE_BOOL: {
|
|
|
|
bool on = (*(bool*)ce->variable);
|
|
|
|
|
|
|
|
if (ce->flags & CE_CLICK) {
|
|
|
|
DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : 0);
|
2006-03-13 23:13:21 +00:00
|
|
|
if (i == 0) { // XXX - hack/hack for first element which is increase money. Told ya it's a mess
|
|
|
|
SetDParam64(0, 10000000);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, false);
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2006-03-01 20:49:47 +00:00
|
|
|
DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : 0);
|
|
|
|
SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2006-03-01 20:49:47 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
int32 val = (int32)ReadValue(ce->variable, ce->type);
|
2006-04-19 16:02:07 +00:00
|
|
|
char buf[512];
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-03-01 20:24:22 +00:00
|
|
|
/* Draw [<][>] boxes for settings of an integer-type */
|
2006-08-02 18:36:53 +00:00
|
|
|
DrawArrowButtons(x + 20, y, 3, clk - (i * 2), true, true);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
switch (ce->str) {
|
|
|
|
/* Display date for change date cheat */
|
|
|
|
case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
|
|
|
|
/* Draw colored flag for change player cheat */
|
|
|
|
case STR_CHEAT_CHANGE_PLAYER:
|
|
|
|
SetDParam(0, val);
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf));
|
2006-09-16 13:20:14 +00:00
|
|
|
DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2);
|
2006-03-01 20:49:47 +00:00
|
|
|
break;
|
|
|
|
/* Set correct string for switch climate cheat */
|
|
|
|
case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE;
|
|
|
|
/* Fallthrough */
|
|
|
|
default: SetDParam(0, val);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2006-03-01 20:49:47 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
DrawString(50, y + 1, ce->str, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
y += 12;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_CLICK: {
|
|
|
|
const CheatEntry *ce;
|
2006-09-23 02:39:24 +00:00
|
|
|
uint btn = (e->we.click.pt.y - 46) / 12;
|
2006-03-01 20:49:47 +00:00
|
|
|
int32 value, oldvalue;
|
2006-09-23 02:39:24 +00:00
|
|
|
uint x = e->we.click.pt.x;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// not clicking a button?
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!IS_INT_INSIDE(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
ce = &_cheats_ui[btn];
|
2006-03-01 20:49:47 +00:00
|
|
|
oldvalue = value = (int32)ReadValue(ce->variable, ce->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
*ce->been_used = true;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (ce->type) {
|
2006-03-01 20:49:47 +00:00
|
|
|
case SLE_BOOL:
|
|
|
|
if (ce->flags & CE_CLICK) WP(w,def_d).data_1 = btn * 2 + 1;
|
|
|
|
value ^= 1;
|
|
|
|
if (ce->proc != NULL) ce->proc(value, 0);
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
/* Add a dynamic step-size to the scroller. In a maximum of
|
|
|
|
* 50-steps you should be able to get from min to max */
|
|
|
|
uint16 step = ((ce->max - ce->min) / 20);
|
|
|
|
if (step == 0) step = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
/* Increase or decrease the value and clamp it to extremes */
|
|
|
|
value += (x >= 30) ? step : -step;
|
|
|
|
clamp(value, ce->min, ce->max);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
// take whatever the function returns
|
|
|
|
value = ce->proc(value, (x >= 30) ? 1 : -1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
if (value != oldvalue) {
|
|
|
|
WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-03-01 20:49:47 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-01 20:49:47 +00:00
|
|
|
if (value != oldvalue) {
|
|
|
|
WriteValue(ce->variable, ce->type, (int64)value);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_TIMEOUT:
|
|
|
|
WP(w,def_d).data_1 = 0;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const WindowDesc _cheats_desc = {
|
2006-05-22 14:41:20 +00:00
|
|
|
240, 22, 400, 170,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_CHEATS,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_cheat_widgets,
|
|
|
|
CheatsWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowCheatWindow(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_CHEATS, 0);
|
2006-11-19 22:24:18 +00:00
|
|
|
AllocateWindowDesc(&_cheats_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-09-28 23:05:03 +00:00
|
|
|
|
|
|
|
/** Resize the widgets in a window
|
|
|
|
* @param *w Window to resize in
|
|
|
|
* @param *resizearray Bytearray of the same length as the window contains widgets. Each byte tells how to move the widget of the same index using the flags in resize_window_widgets.h
|
|
|
|
* @param length Length of the bytearray
|
|
|
|
* @param horizontal Tells how far to the right the widgets should be moved (note: negative moves left)
|
|
|
|
* @param vertical Tells how far down the widgets should be moved (note: negative moves up)
|
|
|
|
*/
|
2006-09-29 10:54:59 +00:00
|
|
|
void ResizeWindowWidgets(Window *w, const byte *resizearray, int16 length, byte horizontal, int16 vertical)
|
2006-09-28 23:05:03 +00:00
|
|
|
{
|
|
|
|
byte i;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
if (resizearray[i] & WIDGET_DEFINE_MOVE_LEFT) w->widget[i].left += horizontal;
|
|
|
|
if (resizearray[i] & WIDGET_DEFINE_MOVE_RIGHT) w->widget[i].right += horizontal;
|
|
|
|
if (resizearray[i] & WIDGET_DEFINE_MOVE_TOP) w->widget[i].top += vertical;
|
|
|
|
if (resizearray[i] & WIDGET_DEFINE_MOVE_BOTTOM) w->widget[i].bottom += vertical;
|
|
|
|
}
|
|
|
|
}
|