src/player_gui.cpp
branchnoai
changeset 10513 33cb70ff2f5d
parent 10455 22c441f5adf9
child 10645 8cbdb511a674
equal deleted inserted replaced
10455:22c441f5adf9 10513:33cb70ff2f5d
    40 	PlayerFace face; // player face bits
    40 	PlayerFace face; // player face bits
    41 	bool advanced;   // advance player face selection window
    41 	bool advanced;   // advance player face selection window
    42 };
    42 };
    43 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(facesel_d));
    43 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(facesel_d));
    44 
    44 
       
    45 struct highscore_d {
       
    46 	uint32 background_img;
       
    47 	int8 rank;
       
    48 };
       
    49 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d));
       
    50 
    45 enum {
    51 enum {
    46 	FIRST_GUI_CALL = INT_MAX,  ///< default value to specify thuis is the first call of the resizable gui
    52 	FIRST_GUI_CALL = INT_MAX,  ///< default value to specify thuis is the first call of the resizable gui
    47 };
    53 };
    48 
    54 
    49 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
    55 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
   245  */
   251  */
   246 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top, int left)
   252 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top, int left)
   247 {
   253 {
   248 	if (!IsValidPlayer(player)) return;
   254 	if (!IsValidPlayer(player)) return;
   249 
   255 
   250 	Window *w = AllocateWindowDescFront(show_small ? &_player_finances_small_desc : &_player_finances_desc, player);
   256 	Window *w = AllocateWindowDescFront<Window>(show_small ? &_player_finances_small_desc : &_player_finances_desc, player);
   251 	if (w != NULL) {
   257 	if (w != NULL) {
   252 		w->caption_color = w->window_number;
   258 		w->caption_color = w->window_number;
   253 		WP(w, def_d).data_1 = show_small;
   259 		WP(w, def_d).data_1 = show_small;
   254 
   260 
   255 		if (show_stickied) w->flags4 |= WF_STICKY;
   261 		if (show_stickied) w->flags4 |= WF_STICKY;
   971 					break;
   977 					break;
   972 			}
   978 			}
   973 			break;
   979 			break;
   974 
   980 
   975 		case WE_ON_EDIT_TEXT:
   981 		case WE_ON_EDIT_TEXT:
       
   982 			if (e->we.edittext.str == NULL) break;
   976 			/* Set a new player face number */
   983 			/* Set a new player face number */
   977 			if (!StrEmpty(e->we.edittext.str)) {
   984 			if (!StrEmpty(e->we.edittext.str)) {
   978 				*pf = strtoul(e->we.edittext.str, NULL, 10);
   985 				*pf = strtoul(e->we.edittext.str, NULL, 10);
   979 				ScaleAllPlayerFaceBits(*pf);
   986 				ScaleAllPlayerFaceBits(*pf);
   980 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0);
   987 				ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0);
  1016  */
  1023  */
  1017 static void DoSelectPlayerFace(PlayerID player, bool adv, int top, int left)
  1024 static void DoSelectPlayerFace(PlayerID player, bool adv, int top, int left)
  1018 {
  1025 {
  1019 	if (!IsValidPlayer(player)) return;
  1026 	if (!IsValidPlayer(player)) return;
  1020 
  1027 
  1021 	Window *w = AllocateWindowDescFront(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, player); // simple or advanced window
  1028 	Window *w = AllocateWindowDescFront<Window>(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, player); // simple or advanced window
  1022 
  1029 
  1023 	if (w != NULL) {
  1030 	if (w != NULL) {
  1024 		w->caption_color = w->window_number;
  1031 		w->caption_color = w->window_number;
  1025 		WP(w, facesel_d).face = GetPlayer((PlayerID)w->window_number)->face;
  1032 		WP(w, facesel_d).face = GetPlayer((PlayerID)w->window_number)->face;
  1026 		WP(w, facesel_d).advanced = adv;
  1033 		WP(w, facesel_d).advanced = adv;
  1233 		case WE_CLICK:
  1240 		case WE_CLICK:
  1234 			switch (e->we.click.widget) {
  1241 			switch (e->we.click.widget) {
  1235 				case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)w->window_number, false); break;
  1242 				case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)w->window_number, false); break;
  1236 
  1243 
  1237 				case PCW_WIDGET_COLOR_SCHEME: {
  1244 				case PCW_WIDGET_COLOR_SCHEME: {
  1238 					Window *wf = AllocateWindowDescFront(_loaded_newgrf_features.has_2CC ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
  1245 					Window *wf = AllocateWindowDescFront<Window>(_loaded_newgrf_features.has_2CC ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
  1239 					if (wf != NULL) {
  1246 					if (wf != NULL) {
  1240 						wf->caption_color = wf->window_number;
  1247 						wf->caption_color = wf->window_number;
  1241 						WP(wf, livery_d).livery_class = LC_OTHER;
  1248 						WP(wf, livery_d).livery_class = LC_OTHER;
  1242 						WP(wf, livery_d).sel = 1;
  1249 						WP(wf, livery_d).sel = 1;
  1243 						wf->LowerWidget(2);
  1250 						wf->LowerWidget(2);
  1301 					break;
  1308 					break;
  1302 #endif /* ENABLE_NETWORK */
  1309 #endif /* ENABLE_NETWORK */
  1303 			}
  1310 			}
  1304 			break;
  1311 			break;
  1305 
  1312 
  1306 		case WE_MOUSELOOP:
  1313 		case WE_TICK:
  1307 			/* redraw the window every now and then */
  1314 			/* redraw the window every now and then */
  1308 			if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty();
  1315 			if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty();
  1309 			break;
  1316 			break;
  1310 
  1317 
  1311 		case WE_PLACE_OBJ:
  1318 		case WE_PLACE_OBJ:
  1323 			DeleteWindowById(WC_PLAYER_FACE, w->window_number);
  1330 			DeleteWindowById(WC_PLAYER_FACE, w->window_number);
  1324 			if (w->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
  1331 			if (w->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
  1325 			break;
  1332 			break;
  1326 
  1333 
  1327 		case WE_ON_EDIT_TEXT:
  1334 		case WE_ON_EDIT_TEXT:
  1328 			if (StrEmpty(e->we.edittext.str)) return;
  1335 			if (StrEmpty(e->we.edittext.str)) break;
  1329 
  1336 
  1330 			_cmd_text = e->we.edittext.str;
  1337 			_cmd_text = e->we.edittext.str;
  1331 			switch (WP(w, def_d).byte_1) {
  1338 			switch (WP(w, def_d).byte_1) {
  1332 				case 0: /* Change president name */
  1339 				case 0: /* Change president name */
  1333 					DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
  1340 					DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
  1353 {
  1360 {
  1354 	Window *w;
  1361 	Window *w;
  1355 
  1362 
  1356 	if (!IsValidPlayer(player)) return;
  1363 	if (!IsValidPlayer(player)) return;
  1357 
  1364 
  1358 	w = AllocateWindowDescFront(&_player_company_desc, player);
  1365 	w = AllocateWindowDescFront<Window>(&_player_company_desc, player);
  1359 	if (w != NULL) w->caption_color = w->window_number;
  1366 	if (w != NULL) w->caption_color = w->window_number;
  1360 }
  1367 }
  1361 
  1368 
  1362 
  1369 
  1363 
  1370 
  1409 };
  1416 };
  1410 
  1417 
  1411 
  1418 
  1412 void ShowBuyCompanyDialog(uint player)
  1419 void ShowBuyCompanyDialog(uint player)
  1413 {
  1420 {
  1414 	AllocateWindowDescFront(&_buy_company_desc, player);
  1421 	AllocateWindowDescFront<Window>(&_buy_company_desc, player);
  1415 }
  1422 }
  1416 
  1423 
  1417 /********** HIGHSCORE and ENDGAME windows */
  1424 /********** HIGHSCORE and ENDGAME windows */
  1418 
  1425 
  1419 /* Always draw a maximized window and within there the centered background */
  1426 /* Always draw a maximized window and within there the centered background */
  1550 
  1557 
  1551 	/* Close all always on-top windows to get a clean screen */
  1558 	/* Close all always on-top windows to get a clean screen */
  1552 	if (_game_mode != GM_MENU) HideVitalWindows();
  1559 	if (_game_mode != GM_MENU) HideVitalWindows();
  1553 
  1560 
  1554 	DeleteWindowByClass(WC_HIGHSCORE);
  1561 	DeleteWindowByClass(WC_HIGHSCORE);
  1555 	w = AllocateWindowDesc(&_highscore_desc);
  1562 	w = new Window(&_highscore_desc);
  1556 
  1563 
  1557 	if (w != NULL) {
  1564 	if (w != NULL) {
  1558 		MarkWholeScreenDirty();
  1565 		MarkWholeScreenDirty();
  1559 		w->window_number = difficulty; // show highscore chart for difficulty...
  1566 		w->window_number = difficulty; // show highscore chart for difficulty...
  1560 		WP(w, highscore_d).background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
  1567 		WP(w, highscore_d).background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
  1573 	/* Pause in single-player to have a look at the highscore at your own leisure */
  1580 	/* Pause in single-player to have a look at the highscore at your own leisure */
  1574 	if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
  1581 	if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
  1575 
  1582 
  1576 	HideVitalWindows();
  1583 	HideVitalWindows();
  1577 	DeleteWindowByClass(WC_ENDSCREEN);
  1584 	DeleteWindowByClass(WC_ENDSCREEN);
  1578 	w = AllocateWindowDesc(&_endgame_desc);
  1585 	w = new Window(&_endgame_desc);
  1579 
  1586 
  1580 	if (w != NULL) {
  1587 	if (w != NULL) {
  1581 		MarkWholeScreenDirty();
  1588 		MarkWholeScreenDirty();
  1582 
  1589 
  1583 		WP(w, highscore_d).background_img = SPR_TYCOON_IMG1_BEGIN;
  1590 		WP(w, highscore_d).background_img = SPR_TYCOON_IMG1_BEGIN;