src/player_gui.cpp
changeset 6190 01a2b579b668
parent 5893 7e431a4abebb
child 6247 7d81e3a5d803
equal deleted inserted replaced
6189:7418216ee28a 6190:01a2b579b668
    19 #include "aircraft.h"
    19 #include "aircraft.h"
    20 #include "date.h"
    20 #include "date.h"
    21 #include "newgrf.h"
    21 #include "newgrf.h"
    22 #include "network/network_data.h"
    22 #include "network/network_data.h"
    23 #include "network/network_client.h"
    23 #include "network/network_client.h"
       
    24 #include "player_face.h"
    24 
    25 
    25 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
    26 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
    26 
    27 
    27 static void DrawPlayerEconomyStats(const Player *p, byte mode)
    28 static void DrawPlayerEconomyStats(const Player *p, byte mode)
    28 {
    29 {
   503 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   504 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   504 	_select_player_livery_widgets,
   505 	_select_player_livery_widgets,
   505 	SelectPlayerLiveryWndProc
   506 	SelectPlayerLiveryWndProc
   506 };
   507 };
   507 
   508 
       
   509 /**
       
   510  * Draws the face of a player.
       
   511  * @param pf    the player's face
       
   512  * @param color the (background) color of the gradient
       
   513  * @param x     x-position to draw the face
       
   514  * @param y     y-position to draw the face
       
   515  */
       
   516 void DrawPlayerFace(PlayerFace pf, int color, int x, int y)
       
   517 {
       
   518 	GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM);
       
   519 
       
   520 	bool has_moustache   = !HASBIT(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE,   ge) != 0;
       
   521 	bool has_tie_earring = !HASBIT(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0;
       
   522 	bool has_glasses     = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0;
       
   523 	SpriteID pal;
       
   524 	switch (GetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge)) {
       
   525 		default: NOT_REACHED();
       
   526 		case 0: pal = PALETTE_TO_BROWN; break;
       
   527 		case 1: pal = PALETTE_TO_BLUE;  break;
       
   528 		case 2: pal = PALETTE_TO_GREEN; break;
       
   529 	}
       
   530 
       
   531 	/* Draw the gradient (background) */
       
   532 	DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOR(color), x, y);
       
   533 
       
   534 	for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) {
       
   535 		switch (pfv) {
       
   536 			case PFV_MOUSTACHE:   if (!has_moustache)   continue; break;
       
   537 			case PFV_LIPS:        /* FALL THROUGH */
       
   538 			case PFV_NOSE:        if (has_moustache)    continue; break;
       
   539 			case PFV_TIE_EARRING: if (!has_tie_earring) continue; break;
       
   540 			case PFV_GLASSES:     if (!has_glasses)     continue; break;
       
   541 			default: break;
       
   542 		}
       
   543 		DrawSprite(GetPlayerFaceSprite(pf, pfv, ge), (pfv == PFV_EYEBROWS) ? pal : PAL_NONE, x, y);
       
   544 	}
       
   545 }
       
   546 
   508 static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
   547 static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
   509 {
   548 {
   510 	switch (e->event) {
   549 	switch (e->event) {
   511 	case WE_PAINT: {
   550 	case WE_PAINT: {
   512 		Player *p;
   551 		Player *p;
   529 			WP(w, facesel_d).gender = e->we.click.widget - 5;
   568 			WP(w, facesel_d).gender = e->we.click.widget - 5;
   530 			LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
   569 			LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
   531 			SetWindowDirty(w);
   570 			SetWindowDirty(w);
   532 			break;
   571 			break;
   533 		case 7:
   572 		case 7:
   534 			WP(w,facesel_d).face = (WP(w,facesel_d).gender << 31) + GB(InteractiveRandom(), 0, 31);
   573 			WP(w,facesel_d).face = ConvertFromOldPlayerFace((WP(w, facesel_d).gender << 31) + GB(InteractiveRandom(), 0, 31));
   535 			SetWindowDirty(w);
   574 			SetWindowDirty(w);
   536 			break;
   575 			break;
   537 		}
   576 		}
   538 		break;
   577 		break;
   539 	}
   578 	}