player_gui.c
changeset 4746 693a7e43596d
parent 4744 9906dae63088
child 4805 a03106c010b3
equal deleted inserted replaced
4745:21632cc267bb 4746:693a7e43596d
   557 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   557 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   558 	_select_player_face_widgets,
   558 	_select_player_face_widgets,
   559 	SelectPlayerFaceWndProc
   559 	SelectPlayerFaceWndProc
   560 };
   560 };
   561 
   561 
   562 static const Widget _my_player_company_widgets[] = {
   562 /* Names of the widgets. Keep them in the same order as in the widget array */
   563 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
   563 typedef enum PlayerCompanyWindowWidgets {
   564 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   359,     0,    13, STR_7001,                STR_018C_WINDOW_TITLE_DRAG_THIS},
   564 	PCW_WIDGET_CLOSEBOX = 0,
   565 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   359,    14,   157, 0x0,                     STR_NULL},
   565 	PCW_WIDGET_CAPTION,
   566 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    89,   158,   169, STR_7004_NEW_FACE,       STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
   566 	PCW_WIDGET_FACE,
   567 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    90,   179,   158,   169, STR_7005_COLOR_SCHEME,   STR_7031_CHANGE_THE_COMPANY_VEHICLE},
   567 	PCW_WIDGET_NEW_FACE,
   568 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   180,   269,   158,   169, STR_7009_PRESIDENT_NAME, STR_7032_CHANGE_THE_PRESIDENT_S},
   568 	PCW_WIDGET_COLOR_SCHEME,
   569 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   270,   359,   158,   169, STR_7008_COMPANY_NAME,   STR_7033_CHANGE_THE_COMPANY_NAME},
   569 	PCW_WIDGET_PRESIDENT_NAME,
   570 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    18,    29, STR_706F_BUILD_HQ,       STR_7070_BUILD_COMPANY_HEADQUARTERS},
   570 	PCW_WIDGET_COMPANY_NAME,
   571 {      WWT_EMPTY,   RESIZE_NONE,    14,     0,   355,    32,    43, 0x0,                     STR_NULL},
   571 	PCW_WIDGET_BUILD_VIEW_HQ,
   572 {      WWT_EMPTY,   RESIZE_NONE,    14,     0,   355,    32,    43, 0x0,                     STR_NULL},
   572 	PCW_WIDGET_RELOCATE_HQ,
   573 {      WWT_EMPTY,   RESIZE_NONE,    14,     0,   355,    32,    43, 0x0,                     STR_NULL},
   573 	PCW_WIDGET_BUY_SHARE,
   574 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,   138,   149, STR_COMPANY_PASSWORD,    STR_COMPANY_PASSWORD_TOOLTIP},
   574 	PCW_WIDGET_SELL_SHARE,
   575 {   WIDGETS_END},
   575 	PCW_WIDGET_COMPANY_PASSWORD,
   576 };
   576 } PlayerCompanyWindowWidget;
   577 
   577 
   578 static const Widget _other_player_company_widgets[] = {
   578 static const Widget _player_company_widgets[] = {
   579 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
   579 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
   580 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   359,     0,    13, STR_7001,                          STR_018C_WINDOW_TITLE_DRAG_THIS},
   580 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   359,     0,    13, STR_7001,                          STR_018C_WINDOW_TITLE_DRAG_THIS},
   581 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   359,    14,   157, 0x0,                               STR_NULL},
   581 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   359,    14,   157, 0x0,                               STR_NULL},
   582 {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,                               STR_NULL},
   582 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    89,   158,   169, STR_7004_NEW_FACE,                 STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
   583 {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,                               STR_NULL},
   583 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    90,   179,   158,   169, STR_7005_COLOR_SCHEME,             STR_7031_CHANGE_THE_COMPANY_VEHICLE},
   584 {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,                               STR_NULL},
   584 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   180,   269,   158,   169, STR_7009_PRESIDENT_NAME,           STR_7032_CHANGE_THE_PRESIDENT_S},
   585 {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,                               STR_NULL},
   585 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   270,   359,   158,   169, STR_7008_COMPANY_NAME,             STR_7033_CHANGE_THE_COMPANY_NAME},
   586 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    18,    29, STR_7072_VIEW_HQ,                  STR_7070_BUILD_COMPANY_HEADQUARTERS},
   586 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    18,    29, STR_7072_VIEW_HQ,                  STR_7070_BUILD_COMPANY_HEADQUARTERS},
   587 {      WWT_EMPTY,   RESIZE_NONE,     0,     0,     0,     0,     0, 0x0,                               STR_NULL},
   587 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    32,    43, STR_RELOCATE_HQ,                   STR_RELOCATE_COMPANY_HEADQUARTERS},
   588 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   179,   158,   169, STR_7077_BUY_25_SHARE_IN_COMPANY,  STR_7079_BUY_25_SHARE_IN_THIS_COMPANY},
   588 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   179,   158,   169, STR_7077_BUY_25_SHARE_IN_COMPANY,  STR_7079_BUY_25_SHARE_IN_THIS_COMPANY},
   589 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   180,   359,   158,   169, STR_7078_SELL_25_SHARE_IN_COMPANY, STR_707A_SELL_25_SHARE_IN_THIS_COMPANY},
   589 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   180,   359,   158,   169, STR_7078_SELL_25_SHARE_IN_COMPANY, STR_707A_SELL_25_SHARE_IN_THIS_COMPANY},
   590 {   WIDGETS_END},
   590 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,   138,   149, STR_COMPANY_PASSWORD,              STR_COMPANY_PASSWORD_TOOLTIP},
   591 };
       
   592 
       
   593 static const Widget _my_player_company_bh_widgets[] = {
       
   594 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
       
   595 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   359,     0,    13, STR_7001,                STR_018C_WINDOW_TITLE_DRAG_THIS},
       
   596 {     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   359,    14,   157, 0x0,                     STR_NULL},
       
   597 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    89,   158,   169, STR_7004_NEW_FACE,       STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
       
   598 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    90,   179,   158,   169, STR_7005_COLOR_SCHEME,   STR_7031_CHANGE_THE_COMPANY_VEHICLE},
       
   599 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   180,   269,   158,   169, STR_7009_PRESIDENT_NAME, STR_7032_CHANGE_THE_PRESIDENT_S},
       
   600 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   270,   359,   158,   169, STR_7008_COMPANY_NAME,   STR_7033_CHANGE_THE_COMPANY_NAME},
       
   601 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    18,    29, STR_7072_VIEW_HQ,        STR_7070_BUILD_COMPANY_HEADQUARTERS},
       
   602 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,    32,    43, STR_RELOCATE_HQ,         STR_RELOCATE_COMPANY_HEADQUARTERS},
       
   603 {      WWT_EMPTY,   RESIZE_NONE,    14,     0,   355,    32,    43, 0x0,                     STR_NULL},
       
   604 {      WWT_EMPTY,   RESIZE_NONE,    14,     0,   355,    32,    43, 0x0,                     STR_NULL},
       
   605 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   266,   355,   138,   149, STR_COMPANY_PASSWORD,    STR_COMPANY_PASSWORD_TOOLTIP},
       
   606 {   WIDGETS_END},
   591 {   WIDGETS_END},
   607 };
   592 };
   608 
   593 
   609 static void DrawPlayerVehiclesAmount(PlayerID player)
   594 static void DrawPlayerVehiclesAmount(PlayerID player)
   610 {
   595 {
   688 }
   673 }
   689 
   674 
   690 static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
   675 static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
   691 {
   676 {
   692 	switch (e->event) {
   677 	switch (e->event) {
   693 	case WE_PAINT: {
   678 		case WE_PAINT: {
   694 		const Player *p = GetPlayer(w->window_number);
   679 			const Player *p = GetPlayer(w->window_number);
   695 
   680 			bool local = w->window_number == _local_player;
   696 		if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
   681 
   697 			AssignWidgetToWindow(w, (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets);
   682 			SetWindowWidgetHiddenState(w, PCW_WIDGET_NEW_FACE,       !local);
   698 
   683 			SetWindowWidgetHiddenState(w, PCW_WIDGET_COLOR_SCHEME,   !local);
   699 			SetWindowWidgetHiddenState(w, 11, !_networking); // Hide company-password widget
   684 			SetWindowWidgetHiddenState(w, PCW_WIDGET_PRESIDENT_NAME, !local);
   700 		} else {
   685 			SetWindowWidgetHiddenState(w, PCW_WIDGET_COMPANY_NAME,   !local);
   701 			SetWindowWidgetDisabledState(w, 7, p->location_of_house == 0);
   686 			w->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_house == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ;
   702 
   687 			SetWindowWidgetDisabledState(w, PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0);
   703 			if (_patches.allow_shares) { // Shares are allowed
   688 			SetWindowWidgetHiddenState(w, PCW_WIDGET_RELOCATE_HQ,      !local || p->location_of_house == 0);
   704 				/* If all shares are owned by someone (none by nobody), disable buy button */
   689 			SetWindowWidgetHiddenState(w, PCW_WIDGET_BUY_SHARE,        local);
   705 				SetWindowWidgetDisabledState(w, 9, GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0 ||
   690 			SetWindowWidgetHiddenState(w, PCW_WIDGET_SELL_SHARE,       local);
   706 						/* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
   691 			SetWindowWidgetHiddenState(w, PCW_WIDGET_COMPANY_PASSWORD, !local || !_networking);
   707 						(GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) ||
   692 
   708 						/* Spectators cannot do anything of course */
   693 			if (!local) {
   709 						_local_player == OWNER_SPECTATOR);
   694 				if (_patches.allow_shares) { // Shares are allowed
   710 
   695 					/* If all shares are owned by someone (none by nobody), disable buy button */
   711 				/* If the player doesn't own any shares, disable sell button */
   696 					SetWindowWidgetDisabledState(w, PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0 ||
   712 				SetWindowWidgetDisabledState(w, 10, (GetAmountOwnedBy(p, _local_player) == 0) ||
   697 							/* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
   713 						/* Spectators cannot do anything of course */
   698 							(GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) ||
   714 						_local_player == OWNER_SPECTATOR);
   699 							/* Spectators cannot do anything of course */
   715 			} else { // Shares are not allowed, disable buy/sell buttons
   700 							_local_player == OWNER_SPECTATOR);
   716 				DisableWindowWidget(w,  9);
   701 
   717 				DisableWindowWidget(w, 10);
   702 					/* If the player doesn't own any shares, disable sell button */
       
   703 					SetWindowWidgetDisabledState(w, PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) ||
       
   704 							/* Spectators cannot do anything of course */
       
   705 							_local_player == OWNER_SPECTATOR);
       
   706 				} else { // Shares are not allowed, disable buy/sell buttons
       
   707 					DisableWindowWidget(w, PCW_WIDGET_BUY_SHARE);
       
   708 					DisableWindowWidget(w, PCW_WIDGET_SELL_SHARE);
       
   709 				}
   718 			}
   710 			}
   719 		}
   711 
   720 
   712 			SetDParam(0, p->name_1);
   721 		SetDParam(0, p->name_1);
   713 			SetDParam(1, p->name_2);
   722 		SetDParam(1, p->name_2);
   714 			SetDParam(2, GetPlayerNameString((byte)w->window_number, 3));
   723 		SetDParam(2, GetPlayerNameString((byte)w->window_number, 3));
   715 
   724 
   716 			DrawWindowWidgets(w);
   725 		DrawWindowWidgets(w);
   717 
   726 
   718 			SetDParam(0, p->inaugurated_year);
   727 		SetDParam(0, p->inaugurated_year);
   719 			DrawString(110, 25, STR_7038_INAUGURATED, 0);
   728 		DrawString(110, 25, STR_7038_INAUGURATED, 0);
   720 
   729 
   721 			DrawPlayerVehiclesAmount(w->window_number);
   730 		DrawPlayerVehiclesAmount(w->window_number);
   722 
   731 
   723 			DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
   732 		DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
   724 			// Draw company-colour bus
   733 		// Draw company-colour bus
   725 			DrawSprite(PLAYER_SPRITE_COLOR(p->index) + SPRITE_PALETTE(SPR_VEH_BUS_SW_VIEW), 215, 49);
   734 		DrawSprite(PLAYER_SPRITE_COLOR(p->index) + SPRITE_PALETTE(SPR_VEH_BUS_SW_VIEW), 215, 49);
   726 
   735 
   727 			DrawPlayerFace(p->face, p->player_color, 2, 16);
   736 		DrawPlayerFace(p->face, p->player_color, 2, 16);
   728 
   737 
   729 			SetDParam(0, p->president_name_1);
   738 		SetDParam(0, p->president_name_1);
   730 			SetDParam(1, p->president_name_2);
   739 		SetDParam(1, p->president_name_2);
   731 			DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
   740 		DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
   732 
   741 
   733 			SetDParam64(0, CalculateCompanyValue(p));
   742 		SetDParam64(0, CalculateCompanyValue(p));
   734 			DrawString(110, 114, STR_7076_COMPANY_VALUE, 0);
   743 		DrawString(110, 114, STR_7076_COMPANY_VALUE, 0);
   735 
   744 
   736 			DrawCompanyOwnerText(p);
   745 		DrawCompanyOwnerText(p);
   737 
   746 	} break;
   738 			break;
   747 
   739 		}
   748 	case WE_CLICK:
   740 
   749 		switch (e->we.click.widget) {
   741 		case WE_CLICK:
   750 		case 3: { /* select face */
   742 			switch (e->we.click.widget) {
   751 			Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
   743 				case PCW_WIDGET_NEW_FACE: {
   752 			if (wf != NULL) {
   744 					Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
   753 				wf->caption_color = w->window_number;
   745 					if (wf != NULL) {
   754 				WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
   746 						wf->caption_color = w->window_number;
   755 				WP(wf,facesel_d).gender = 0;
   747 						WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
       
   748 						WP(wf,facesel_d).gender = 0;
       
   749 					}
       
   750 					break;
       
   751 				}
       
   752 
       
   753 				case PCW_WIDGET_COLOR_SCHEME: {
       
   754 					Window *wf = AllocateWindowDescFront(_have_2cc ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
       
   755 					if (wf != NULL) {
       
   756 						wf->caption_color = wf->window_number;
       
   757 						WP(wf,livery_d).livery_class = LC_OTHER;
       
   758 						WP(wf,livery_d).sel = 1;
       
   759 						LowerWindowWidget(wf, 2);
       
   760 					}
       
   761 					break;
       
   762 				}
       
   763 
       
   764 				case PCW_WIDGET_PRESIDENT_NAME: {
       
   765 					const Player *p = GetPlayer(w->window_number);
       
   766 					WP(w, def_d).byte_1 = 0;
       
   767 					SetDParam(0, p->president_name_2);
       
   768 					ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number, CS_ALPHANUMERAL);
       
   769 					break;
       
   770 				}
       
   771 
       
   772 				case PCW_WIDGET_COMPANY_NAME: {
       
   773 					Player *p = GetPlayer(w->window_number);
       
   774 					WP(w,def_d).byte_1 = 1;
       
   775 					SetDParam(0, p->name_2);
       
   776 					ShowQueryString(p->name_1, STR_700A_COMPANY_NAME, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
       
   777 					break;
       
   778 				}
       
   779 
       
   780 				case PCW_WIDGET_BUILD_VIEW_HQ: {
       
   781 					TileIndex tile = GetPlayer(w->window_number)->location_of_house;
       
   782 					if (tile == 0) {
       
   783 						if ((byte)w->window_number != _local_player)
       
   784 							return;
       
   785 						SetObjectToPlaceWnd(SPR_CURSOR_HQ, 1, w);
       
   786 						SetTileSelectSize(2, 2);
       
   787 					} else {
       
   788 						ScrollMainWindowToTile(tile);
       
   789 					}
       
   790 					break;
       
   791 				}
       
   792 
       
   793 				case PCW_WIDGET_RELOCATE_HQ:
       
   794 					SetObjectToPlaceWnd(SPR_CURSOR_HQ, 1, w);
       
   795 					SetTileSelectSize(2, 2);
       
   796 					break;
       
   797 
       
   798 				case PCW_WIDGET_BUY_SHARE:
       
   799 					DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
       
   800 					break;
       
   801 
       
   802 				case PCW_WIDGET_SELL_SHARE:
       
   803 					DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
       
   804 					break;
       
   805 
       
   806 				case PCW_WIDGET_COMPANY_PASSWORD:
       
   807 					#ifdef ENABLE_NETWORK
       
   808 					if (w->window_number == _local_player) {
       
   809 						WP(w,def_d).byte_1 = 2;
       
   810 						ShowQueryString(BindCString(_network_player_info[_local_player].password),
       
   811 							STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w->window_class, w->window_number, CS_ALPHANUMERAL);
       
   812 					}
       
   813 					#endif
       
   814 					break;
   756 			}
   815 			}
   757 		} break;
   816 			break;
   758 
   817 
   759 		case 4: {/* change color */
   818 		case WE_MOUSELOOP:
   760 			Window *wf = AllocateWindowDescFront(_have_2cc ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
   819 			/* redraw the window every now and then */
   761 			if (wf != NULL) {
   820 			if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w);
   762 				wf->caption_color = wf->window_number;
   821 			break;
   763 				WP(wf,livery_d).livery_class = LC_OTHER;
   822 
   764 				WP(wf,livery_d).sel = 1;
   823 		case WE_PLACE_OBJ:
   765 				LowerWindowWidget(wf, 2);
   824 			if (DoCommandP(e->we.place.tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
       
   825 				ResetObjectToPlace();
       
   826 			break;
       
   827 
       
   828 		case WE_DESTROY:
       
   829 			DeleteWindowById(WC_PLAYER_FACE, w->window_number);
       
   830 			break;
       
   831 
       
   832 		case WE_ON_EDIT_TEXT: {
       
   833 			char *b = e->we.edittext.str;
       
   834 
       
   835 			// empty string is allowed for password
       
   836 			if (*b == '\0' && WP(w,def_d).byte_1 != 2) return;
       
   837 
       
   838 			_cmd_text = b;
       
   839 			switch (WP(w,def_d).byte_1) {
       
   840 				case 0: /* Change president name */
       
   841 					DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
       
   842 					break;
       
   843 				case 1: /* Change company name */
       
   844 					DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
       
   845 					break;
       
   846 				case 2: /* Change company password */
       
   847 					#ifdef ENABLE_NETWORK
       
   848 					if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
       
   849 					NetworkChangeCompanyPassword(1, &b);
       
   850 					#endif
       
   851 					break;
   766 			}
   852 			}
   767 		} break;
   853 			break;
   768 
   854 		}
   769 		case 5: {/* change president name */
   855 	}
   770 			const Player *p = GetPlayer(w->window_number);
   856 }
   771 			WP(w, def_d).byte_1 = 0;
   857 
   772 			SetDParam(0, p->president_name_2);
   858 
   773 			ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number, CS_ALPHANUMERAL);
   859 static const WindowDesc _player_company_desc = {
   774 		} break;
       
   775 
       
   776 		case 6: {/* change company name */
       
   777 			Player *p = GetPlayer(w->window_number);
       
   778 			WP(w,def_d).byte_1 = 1;
       
   779 			SetDParam(0, p->name_2);
       
   780 			ShowQueryString(p->name_1, STR_700A_COMPANY_NAME, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
       
   781 		} break;
       
   782 
       
   783 		case 7: {/* build hq */
       
   784 			TileIndex tile = GetPlayer(w->window_number)->location_of_house;
       
   785 			if (tile == 0) {
       
   786 				if ((byte)w->window_number != _local_player)
       
   787 					return;
       
   788 				SetObjectToPlaceWnd(SPR_CURSOR_HQ, 1, w);
       
   789 				SetTileSelectSize(2, 2);
       
   790 			} else {
       
   791 				ScrollMainWindowToTile(tile);
       
   792 			}
       
   793 		} break;
       
   794 
       
   795 		case 8: /* relocate HQ */
       
   796 			SetObjectToPlaceWnd(SPR_CURSOR_HQ, 1, w);
       
   797 			SetTileSelectSize(2, 2);
       
   798 			break;
       
   799 		case 9: /* buy 25% */
       
   800 			DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
       
   801 			break;
       
   802 
       
   803 		case 10: /* sell 25% */
       
   804 			DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
       
   805 			break;
       
   806 		case 11: { /* Password protect company */
       
   807 			#ifdef ENABLE_NETWORK
       
   808 			if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
       
   809 				WP(w,def_d).byte_1 = 2;
       
   810 				ShowQueryString(BindCString(_network_player_info[_local_player].password),
       
   811 					STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w->window_class, w->window_number, CS_ALPHANUMERAL);
       
   812 			}
       
   813 			#endif
       
   814 		}	break;
       
   815 		}
       
   816 
       
   817 	case WE_MOUSELOOP:
       
   818 		/* redraw the window every now and then */
       
   819 		if ((++w->vscroll.pos & 0x1F) == 0)
       
   820 			SetWindowDirty(w);
       
   821 		break;
       
   822 
       
   823 	case WE_PLACE_OBJ: {
       
   824 		if (DoCommandP(e->we.place.tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
       
   825 			ResetObjectToPlace();
       
   826 		break;
       
   827 	}
       
   828 
       
   829 
       
   830 	case WE_DESTROY:
       
   831 		DeleteWindowById(WC_PLAYER_FACE, w->window_number);
       
   832 		break;
       
   833 
       
   834 	case WE_ON_EDIT_TEXT: {
       
   835 		char *b = e->we.edittext.str;
       
   836 
       
   837 		// empty string is allowed for password
       
   838 		if (*b == '\0' && WP(w,def_d).byte_1 != 2) return;
       
   839 
       
   840 		_cmd_text = b;
       
   841 		switch (WP(w,def_d).byte_1) {
       
   842 		case 0: /* Change president name */
       
   843 			DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
       
   844 			break;
       
   845 		case 1: /* Change company name */
       
   846 			DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
       
   847 			break;
       
   848 		#ifdef ENABLE_NETWORK
       
   849 		case 2: /* Change company password */
       
   850 			if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
       
   851 			NetworkChangeCompanyPassword(1, &b);
       
   852 		#endif
       
   853 		}
       
   854 	} break;
       
   855 
       
   856 	}
       
   857 }
       
   858 
       
   859 
       
   860 static const WindowDesc _my_player_company_desc = {
       
   861 	-1, -1, 360, 170,
   860 	-1, -1, 360, 170,
   862 	WC_COMPANY, 0,
   861 	WC_COMPANY, 0,
   863 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   862 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   864 	_my_player_company_widgets,
   863 	_player_company_widgets,
   865 	PlayerCompanyWndProc
   864 	PlayerCompanyWndProc
   866 };
   865 };
   867 
   866 
   868 static const WindowDesc _other_player_company_desc = {
       
   869 	-1,-1, 360, 170,
       
   870 	WC_COMPANY,0,
       
   871 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
       
   872 	_other_player_company_widgets,
       
   873 	PlayerCompanyWndProc
       
   874 };
       
   875 
       
   876 void ShowPlayerCompany(PlayerID player)
   867 void ShowPlayerCompany(PlayerID player)
   877 {
   868 {
   878 	Window *w;
   869 	Window *w;
   879 
   870 
   880 	w = AllocateWindowDescFront(player == _local_player ? &_my_player_company_desc : &_other_player_company_desc, player);
   871 	w = AllocateWindowDescFront(&_player_company_desc, player);
   881 	if (w != NULL) w->caption_color = w->window_number;
   872 	if (w != NULL) w->caption_color = w->window_number;
   882 }
   873 }
   883 
   874 
   884 
   875 
   885 
   876