src/misc_gui.c
branchcustombridgeheads
changeset 5648 1608018c5ff2
parent 5643 3778051e8095
equal deleted inserted replaced
5647:cbde85c8c878 5648:1608018c5ff2
    40 extern void SwitchMode(int new_mode);
    40 extern void SwitchMode(int new_mode);
    41 
    41 
    42 static bool _fios_path_changed;
    42 static bool _fios_path_changed;
    43 static bool _savegame_sort_dirty;
    43 static bool _savegame_sort_dirty;
    44 
    44 
    45 typedef struct LandInfoData {
    45 enum {
    46 	Town *town;
    46 	LAND_INFO_LINES          =   7,
    47 	int32 costclear;
    47 	LAND_INFO_LINE_BUFF_SIZE = 512,
    48 	AcceptedCargo ac;
    48 };
    49 	TileIndex tile;
    49 
    50 	TileDesc td;
    50 static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE];
    51 } LandInfoData;
       
    52 
    51 
    53 static void LandInfoWndProc(Window *w, WindowEvent *e)
    52 static void LandInfoWndProc(Window *w, WindowEvent *e)
    54 {
    53 {
    55 	if (e->event == WE_PAINT) {
    54 	if (e->event == WE_PAINT) {
    56 		const LandInfoData *lid;
       
    57 		StringID str;
       
    58 		int i;
       
    59 
       
    60 		DrawWindowWidgets(w);
    55 		DrawWindowWidgets(w);
    61 
    56 
    62 		lid = WP(w,void_d).data;
    57 		DoDrawStringCentered(140, 16, _landinfo_data[0], 13);
    63 
    58 		DoDrawStringCentered(140, 27, _landinfo_data[1], 0);
    64 		SetDParam(0, lid->td.dparam[0]);
    59 		DoDrawStringCentered(140, 38, _landinfo_data[2], 0);
    65 		DrawStringCentered(140, 16, lid->td.str, 13);
    60 		DoDrawStringCentered(140, 49, _landinfo_data[3], 0);
    66 
    61 		DoDrawStringCentered(140, 60, _landinfo_data[4], 0);
    67 		SetDParam(0, STR_01A6_N_A);
    62 		if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), 276);
    68 		if (lid->td.owner != OWNER_NONE && lid->td.owner != OWNER_WATER)
    63 		if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0);
    69 			GetNameOfOwner(lid->td.owner, lid->tile);
       
    70 		DrawStringCentered(140, 27, STR_01A7_OWNER, 0);
       
    71 
       
    72 		str = STR_01A4_COST_TO_CLEAR_N_A;
       
    73 		if (!CmdFailed(lid->costclear)) {
       
    74 			SetDParam(0, lid->costclear);
       
    75 			str = STR_01A5_COST_TO_CLEAR;
       
    76 		}
       
    77 		DrawStringCentered(140, 38, str, 0);
       
    78 
       
    79 		snprintf(_userstring, lengthof(_userstring), "0x%.4X", lid->tile);
       
    80 		SetDParam(0, TileX(lid->tile));
       
    81 		SetDParam(1, TileY(lid->tile));
       
    82 		SetDParam(2, STR_SPEC_USERSTRING);
       
    83 		DrawStringCentered(140, 49, STR_LANDINFO_COORDS, 0);
       
    84 
       
    85 		SetDParam(0, STR_01A9_NONE);
       
    86 		if (lid->town != NULL) {
       
    87 			SetDParam(0, STR_TOWN);
       
    88 			SetDParam(1, lid->town->index);
       
    89 		}
       
    90 		DrawStringCentered(140,60, STR_01A8_LOCAL_AUTHORITY, 0);
       
    91 
       
    92 		{
       
    93 			char buf[512];
       
    94 			char *p = GetString(buf, STR_01CE_CARGO_ACCEPTED, lastof(buf));
       
    95 			bool found = false;
       
    96 
       
    97 			for (i = 0; i < NUM_CARGO; ++i) {
       
    98 				if (lid->ac[i] > 0) {
       
    99 					// Add a comma between each item.
       
   100 					if (found) {
       
   101 						*p++ = ',';
       
   102 						*p++ = ' ';
       
   103 					}
       
   104 					found = true;
       
   105 
       
   106 					// If the accepted value is less than 8, show it in 1/8:ths
       
   107 					if (lid->ac[i] < 8) {
       
   108 						SetDParam(0, lid->ac[i]);
       
   109 						SetDParam(1, _cargoc.names_s[i]);
       
   110 						p = GetString(p, STR_01D1_8, lastof(buf));
       
   111 					} else {
       
   112 						p = GetString(p, _cargoc.names_s[i], lastof(buf));
       
   113 					}
       
   114 				}
       
   115 			}
       
   116 
       
   117 			if (found) DrawStringMultiCenter(140, 76, BindCString(buf), 276);
       
   118 		}
       
   119 
       
   120 		if (lid->td.build_date != 0) {
       
   121 			SetDParam(0,lid->td.build_date);
       
   122 			DrawStringCentered(140,71, STR_BUILD_DATE, 0);
       
   123 		}
       
   124 	}
    64 	}
   125 }
    65 }
   126 
    66 
   127 static const Widget _land_info_widgets[] = {
    67 static const Widget _land_info_widgets[] = {
   128 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
    68 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
   140 };
    80 };
   141 
    81 
   142 static void Place_LandInfo(TileIndex tile)
    82 static void Place_LandInfo(TileIndex tile)
   143 {
    83 {
   144 	Player *p;
    84 	Player *p;
   145 	static LandInfoData lid;
       
   146 	Window *w;
    85 	Window *w;
       
    86 	Town *t;
   147 	int64 old_money;
    87 	int64 old_money;
       
    88 	int64 costclear;
       
    89 	AcceptedCargo ac;
       
    90 	TileDesc td;
       
    91 	StringID str;
   148 
    92 
   149 	DeleteWindowById(WC_LAND_INFO, 0);
    93 	DeleteWindowById(WC_LAND_INFO, 0);
   150 
    94 
   151 	w = AllocateWindowDesc(&_land_info_desc);
    95 	w = AllocateWindowDesc(&_land_info_desc);
   152 	WP(w,void_d).data = &lid;
    96 	WP(w, void_d).data = &_landinfo_data;
   153 
       
   154 	lid.tile = tile;
       
   155 	lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
       
   156 
    97 
   157 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
    98 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
       
    99 	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   158 
   100 
   159 	old_money = p->money64;
   101 	old_money = p->money64;
   160 	p->money64 = p->player_money = 0x7fffffff;
   102 	p->money64 = p->player_money = 0x7fffffff;
   161 	lid.costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
   103 	costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
   162 	p->money64 = old_money;
   104 	p->money64 = old_money;
   163 	UpdatePlayerMoney32(p);
   105 	UpdatePlayerMoney32(p);
   164 
   106 
   165 	// Becuase build_date is not set yet in every TileDesc, we make sure it is empty
   107 	/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
   166 	lid.td.build_date = 0;
   108 	td.build_date = 0;
   167 
   109 	GetAcceptedCargo(tile, ac);
   168 	GetAcceptedCargo(tile, lid.ac);
   110 	GetTileDesc(tile, &td);
   169 	GetTileDesc(tile, &lid.td);
   111 
       
   112 	SetDParam(0, td.dparam[0]);
       
   113 	GetString(_landinfo_data[0], td.str, lastof(_landinfo_data[0]));
       
   114 
       
   115 	SetDParam(0, STR_01A6_N_A);
       
   116 	if (td.owner != OWNER_NONE && td.owner != OWNER_WATER) GetNameOfOwner(td.owner, tile);
       
   117 	GetString(_landinfo_data[1], STR_01A7_OWNER, lastof(_landinfo_data[1]));
       
   118 
       
   119 	str = STR_01A4_COST_TO_CLEAR_N_A;
       
   120 	if (!CmdFailed(costclear)) {
       
   121 		SetDParam(0, costclear);
       
   122 		str = STR_01A5_COST_TO_CLEAR;
       
   123 	}
       
   124 	GetString(_landinfo_data[2], str, lastof(_landinfo_data[2]));
       
   125 
       
   126 	snprintf(_userstring, lengthof(_userstring), "0x%.4X", tile);
       
   127 	SetDParam(0, TileX(tile));
       
   128 	SetDParam(1, TileY(tile));
       
   129 	SetDParam(2, STR_SPEC_USERSTRING);
       
   130 	GetString(_landinfo_data[3], STR_LANDINFO_COORDS, lastof(_landinfo_data[3]));
       
   131 
       
   132 	SetDParam(0, STR_01A9_NONE);
       
   133 	if (t != NULL && IsValidTown(t)) {
       
   134 		SetDParam(0, STR_TOWN);
       
   135 		SetDParam(1, t->index);
       
   136 	}
       
   137 	GetString(_landinfo_data[4], STR_01A8_LOCAL_AUTHORITY, lastof(_landinfo_data[4]));
       
   138 
       
   139 	{
       
   140 		int i;
       
   141 		char *p = GetString(_landinfo_data[5], STR_01CE_CARGO_ACCEPTED, lastof(_landinfo_data[5]));
       
   142 		bool found = false;
       
   143 
       
   144 		for (i = 0; i < NUM_CARGO; ++i) {
       
   145 			if (ac[i] > 0) {
       
   146 				/* Add a comma between each item. */
       
   147 				if (found) {
       
   148 					*p++ = ',';
       
   149 					*p++ = ' ';
       
   150 				}
       
   151 				found = true;
       
   152 
       
   153 				/* If the accepted value is less than 8, show it in 1/8:ths */
       
   154 				if (ac[i] < 8) {
       
   155 					SetDParam(0, ac[i]);
       
   156 					SetDParam(1, _cargoc.names_s[i]);
       
   157 					p = GetString(p, STR_01D1_8, lastof(_landinfo_data[5]));
       
   158 				} else {
       
   159 					p = GetString(p, _cargoc.names_s[i], lastof(_landinfo_data[5]));
       
   160 				}
       
   161 			}
       
   162 		}
       
   163 
       
   164 		if (!found) _landinfo_data[5][0] = '\0';
       
   165 	}
       
   166 
       
   167 	if (td.build_date != 0) {
       
   168 		SetDParam(0, td.build_date);
       
   169 		GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
       
   170 	} else {
       
   171 		_landinfo_data[6][0] = '\0';
       
   172 	}
   170 
   173 
   171 #if defined(_DEBUG)
   174 #if defined(_DEBUG)
   172 #	define LANDINFOD_LEVEL 0
   175 #	define LANDINFOD_LEVEL 0
   173 #else
   176 #else
   174 #	define LANDINFOD_LEVEL 1
   177 #	define LANDINFOD_LEVEL 1