src/misc_gui.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
equal deleted inserted replaced
5649:55c8267c933f 5650:aefc131bf5ce
    93 	DeleteWindowById(WC_LAND_INFO, 0);
    93 	DeleteWindowById(WC_LAND_INFO, 0);
    94 
    94 
    95 	w = AllocateWindowDesc(&_land_info_desc);
    95 	w = AllocateWindowDesc(&_land_info_desc);
    96 	WP(w, void_d).data = &_landinfo_data;
    96 	WP(w, void_d).data = &_landinfo_data;
    97 
    97 
    98 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
    98 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
    99 	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
    99 	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   100 
   100 
   101 	old_money = p->money64;
   101 	old_money = p->money64;
   102 	p->money64 = p->player_money = 0x7fffffff;
   102 	p->money64 = p->player_money = 0x7fffffff;
   103 	costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
   103 	costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
   164 		if (!found) _landinfo_data[5][0] = '\0';
   164 		if (!found) _landinfo_data[5][0] = '\0';
   165 	}
   165 	}
   166 
   166 
   167 	if (td.build_date != 0) {
   167 	if (td.build_date != 0) {
   168 		SetDParam(0, td.build_date);
   168 		SetDParam(0, td.build_date);
   169 		GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
   169 	GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
   170 	} else {
   170 	} else {
   171 		_landinfo_data[6][0] = '\0';
   171 		_landinfo_data[6][0] = '\0';
   172 	}
   172 	}
   173 
   173 
   174 #if defined(_DEBUG)
   174 #if defined(_DEBUG)
   503 					120,
   503 					120,
   504 					30,
   504 					30,
   505 					_errmsg_message_1,
   505 					_errmsg_message_1,
   506 					238);
   506 					238);
   507 		} else {
   507 		} else {
   508 			const Player *p = GetPlayer(GetDParamX(_errmsg_decode_params,2));
   508 			const Player *p = GetPlayer((PlayerID)GetDParamX(_errmsg_decode_params,2));
   509 			DrawPlayerFace(p->face, p->player_color, 2, 16);
   509 			DrawPlayerFace(p->face, p->player_color, 2, 16);
   510 
   510 
   511 			DrawStringMultiCenter(
   511 			DrawStringMultiCenter(
   512 				214,
   512 				214,
   513 				(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
   513 				(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
  1381 
  1381 
  1382 static void GenerateFileName(void)
  1382 static void GenerateFileName(void)
  1383 {
  1383 {
  1384 	/* Check if we are not a specatator who wants to generate a name..
  1384 	/* Check if we are not a specatator who wants to generate a name..
  1385 	    Let's use the name of player #0 for now. */
  1385 	    Let's use the name of player #0 for now. */
  1386 	const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
  1386 	const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
  1387 
  1387 
  1388 	SetDParam(0, p->name_1);
  1388 	SetDParam(0, p->name_1);
  1389 	SetDParam(1, p->name_2);
  1389 	SetDParam(1, p->name_2);
  1390 	SetDParam(2, _date);
  1390 	SetDParam(2, _date);
  1391 	GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
  1391 	GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
  1689 	}
  1689 	}
  1690 }
  1690 }
  1691 
  1691 
  1692 static int32 ClickMoneyCheat(int32 p1, int32 p2)
  1692 static int32 ClickMoneyCheat(int32 p1, int32 p2)
  1693 {
  1693 {
  1694 		DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
  1694 		DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
  1695 		return true;
  1695 		return true;
  1696 }
  1696 }
  1697 
  1697 
  1698 // p1 player to set to, p2 is -1 or +1 (down/up)
  1698 // p1 player to set to, p2 is -1 or +1 (down/up)
  1699 static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
  1699 static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
  1737 	return _cur_year;
  1737 	return _cur_year;
  1738 }
  1738 }
  1739 
  1739 
  1740 typedef int32 CheckButtonClick(int32, int32);
  1740 typedef int32 CheckButtonClick(int32, int32);
  1741 
  1741 
  1742 enum ce_flags {CE_CLICK = 1 << 0};
  1742 enum ce_flags_long
  1743 
  1743 {
  1744 typedef byte ce_flags;
  1744 	CE_NONE = 0,
       
  1745 	CE_CLICK = 1 << 0,
       
  1746 	CE_END = 1 << 1,
       
  1747 };
       
  1748 
       
  1749 /** Define basic enum properties */
       
  1750 template <> struct EnumPropsT<ce_flags_long> : MakeEnumPropsT<ce_flags_long, byte, CE_NONE, CE_END, CE_END> {};
       
  1751 typedef TinyEnumT<ce_flags_long> ce_flags;
       
  1752 
  1745 
  1753 
  1746 typedef struct CheatEntry {
  1754 typedef struct CheatEntry {
  1747 	VarType type;          // type of selector
  1755 	VarType type;          // type of selector
  1748 	ce_flags flags;        // selector flags
  1756 	ce_flags flags;        // selector flags
  1749 	StringID str;          // string with descriptive text
  1757 	StringID str;          // string with descriptive text
  1752 	CheckButtonClick *proc;// procedure
  1760 	CheckButtonClick *proc;// procedure
  1753 	int16 min, max;        // range for spinbox setting
  1761 	int16 min, max;        // range for spinbox setting
  1754 } CheatEntry;
  1762 } CheatEntry;
  1755 
  1763 
  1756 static const CheatEntry _cheats_ui[] = {
  1764 static const CheatEntry _cheats_ui[] = {
  1757 	{SLE_BOOL,CE_CLICK, STR_CHEAT_MONEY,          &_cheats.money.value,           &_cheats.money.been_used,           &ClickMoneyCheat,         0,  0},
  1765 	{SLE_BOOL, {CE_CLICK}, STR_CHEAT_MONEY,          &_cheats.money.value,           &_cheats.money.been_used,           &ClickMoneyCheat,         0,  0},
  1758 	{SLE_UINT8,      0, STR_CHEAT_CHANGE_PLAYER,  &_local_player,                 &_cheats.switch_player.been_used,   &ClickChangePlayerCheat,  0, 11},
  1766 	{SLE_UINT8, {CE_NONE}, STR_CHEAT_CHANGE_PLAYER,  &_local_player,                 &_cheats.switch_player.been_used,   &ClickChangePlayerCheat,  0, 11},
  1759 	{SLE_BOOL,       0, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL,                     0,  0},
  1767 	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL,                     0,  0},
  1760 	{SLE_BOOL,       0, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL,                     0,  0},
  1768 	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL,                     0,  0},
  1761 	{SLE_BOOL,       0, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value,  &_cheats.build_in_pause.been_used,  NULL,                     0,  0},
  1769 	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value,  &_cheats.build_in_pause.been_used,  NULL,                     0,  0},
  1762 	{SLE_BOOL,       0, STR_CHEAT_NO_JETCRASH,    &_cheats.no_jetcrash.value,     &_cheats.no_jetcrash.been_used,     NULL,                     0,  0},
  1770 	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_NO_JETCRASH,    &_cheats.no_jetcrash.value,     &_cheats.no_jetcrash.been_used,     NULL,                     0,  0},
  1763 	{SLE_BOOL,       0, STR_CHEAT_SETUP_PROD,     &_cheats.setup_prod.value,      &_cheats.setup_prod.been_used,      NULL,                     0,  0},
  1771 	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_SETUP_PROD,     &_cheats.setup_prod.value,      &_cheats.setup_prod.been_used,      NULL,                     0,  0},
  1764 	{SLE_UINT8,      0, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape,                &_cheats.switch_climate.been_used,  &ClickChangeClimateCheat,-1,  4},
  1772 	{SLE_UINT8, {CE_NONE}, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape,                &_cheats.switch_climate.been_used,  &ClickChangeClimateCheat,-1,  4},
  1765 	{SLE_INT32,      0, STR_CHEAT_CHANGE_DATE,    &_cur_year,                     &_cheats.change_date.been_used,     &ClickChangeDateCheat,   -1,  1},
  1773 	{SLE_INT32, {CE_NONE}, STR_CHEAT_CHANGE_DATE,    &_cur_year,                     &_cheats.change_date.been_used,     &ClickChangeDateCheat,   -1,  1},
  1766 };
  1774 };
  1767 
  1775 
  1768 
  1776 
  1769 static const Widget _cheat_widgets[] = {
  1777 static const Widget _cheat_widgets[] = {
  1770 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,   STR_018B_CLOSE_WINDOW},
  1778 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,   STR_018B_CLOSE_WINDOW},
  1799 			switch (ce->type) {
  1807 			switch (ce->type) {
  1800 			case SLE_BOOL: {
  1808 			case SLE_BOOL: {
  1801 				bool on = (*(bool*)ce->variable);
  1809 				bool on = (*(bool*)ce->variable);
  1802 
  1810 
  1803 				if (ce->flags & CE_CLICK) {
  1811 				if (ce->flags & CE_CLICK) {
  1804 					DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : 0);
  1812 					DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : FR_NONE);
  1805 					if (i == 0) { // XXX - hack/hack for first element which is increase money. Told ya it's a mess
  1813 					if (i == 0) { // XXX - hack/hack for first element which is increase money. Told ya it's a mess
  1806 						SetDParam64(0, 10000000);
  1814 						SetDParam64(0, 10000000);
  1807 					} else {
  1815 					} else {
  1808 						SetDParam(0, false);
  1816 						SetDParam(0, false);
  1809 					}
  1817 					}
  1810 				} else {
  1818 				} else {
  1811 					DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : 0);
  1819 					DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE);
  1812 					SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
  1820 					SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
  1813 				}
  1821 				}
  1814 			} break;
  1822 			} break;
  1815 			default: {
  1823 			default: {
  1816 				int32 val = (int32)ReadValue(ce->variable, ce->type);
  1824 				int32 val = (int32)ReadValue(ce->variable, ce->type);