Changeset - r9241:4fad6d9f7a34
[Not reviewed]
master
0 3 0
glx - 17 years ago 2008-05-15 19:24:15
glx@openttd.org
(svn r13107) -Codechange: make NetworkCompanyPasswordWindow and SelectPlayerFaceWindow children of PlayerCompanyWindow.
3 files changed with 23 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -1923,26 +1923,27 @@ void ShowNetworkChatQueryWindow(DestType
 
enum NetworkCompanyPasswordWindowWidgets {
 
	NCPWW_CLOSE,                    ///< Close 'X' button
 
	NCPWW_CAPTION,                  ///< Caption of the whole window
 
	NCPWW_BACKGROUND,               ///< The background of the interface
 
	NCPWW_LABEL,                    ///< Label in front of the password field
 
	NCPWW_PASSWORD,                 ///< Input field for the password
 
	NCPWW_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password
 
	NCPWW_CANCEL,                   ///< Close the window without changing anything
 
	NCPWW_OK,                       ///< Safe the password etc.
 
};
 

	
 
struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
 
	NetworkCompanyPasswordWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
 
	NetworkCompanyPasswordWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(desc)
 
	{
 
		this->parent = parent;
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, min(lengthof(_network_default_company_pass), lengthof(this->edit_str_buf)), 0);
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	void OnOk()
 
	{
 
		if (this->IsWidgetLowered(NCPWW_SAVE_AS_DEFAULT_PASSWORD)) {
 
			snprintf(_network_default_company_pass, lengthof(_network_default_company_pass), "%s", this->edit_str_buf);
 
		}
 

	
 
@@ -2012,20 +2013,20 @@ static const Widget _ncp_window_widgets[
 
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 299, 51, 62, STR_012F_OK,                       STR_COMPANY_PASSWORD_OK},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _ncp_window_desc = {
 
	WDP_AUTO, WDP_AUTO, 300, 63, 300, 63,
 
	WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
 
	_ncp_window_widgets,
 
	NULL
 
};
 

	
 
void ShowNetworkCompanyPasswordWindow()
 
void ShowNetworkCompanyPasswordWindow(Window *parent)
 
{
 
	DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
 

	
 
	new NetworkCompanyPasswordWindow(&_ncp_window_desc);
 
	new NetworkCompanyPasswordWindow(&_ncp_window_desc, parent);
 
}
 

	
 
#endif /* ENABLE_NETWORK */
src/network/network_gui.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file network_gui.h GUIs related to networking. */
 

	
 
#ifndef NETWORK_GUI_H
 
#define NETWORK_GUI_H
 

	
 
#include "../window_type.h"
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "network_data.h"
 

	
 
void ShowNetworkNeedPassword(NetworkPasswordType npt);
 
void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
 
void ShowNetworkChatQueryWindow(DestType type, int dest);
 
void ShowJoinStatusWindow();
 
void ShowNetworkGameWindow();
 
void ShowClientList();
 
void ShowNetworkCompanyPasswordWindow();
 
void ShowNetworkCompanyPasswordWindow(Window *parent);
 

	
 
#else /* ENABLE_NETWORK */
 
/* Network function stubs when networking is disabled */
 

	
 
static inline void ShowNetworkChatQueryWindow(byte desttype, int dest) {}
 
static inline void ShowClientList() {}
 
static inline void ShowNetworkGameWindow() {}
 
static inline void ShowNetworkCompanyPasswordWindow() {}
 
static inline void ShowNetworkCompanyPasswordWindow(Window *parent) {}
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NETWORK_GUI_H */
src/player_gui.cpp
Show inline comments
 
@@ -37,25 +37,25 @@
 

	
 
struct highscore_d {
 
	uint32 background_img;
 
	int8 rank;
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d));
 

	
 
enum {
 
	FIRST_GUI_CALL = INT_MAX,  ///< default value to specify thuis is the first call of the resizable gui
 
};
 

	
 
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
 
static void DoSelectPlayerFace(PlayerID player, bool show_big, int top =  FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
 
static void DoSelectPlayerFace(Window *parent, bool show_big, int top =  FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
 

	
 
static void DrawPlayerEconomyStats(const Player *p, byte mode)
 
{
 
	int x, y, i, j, year;
 
	const Money (*tbl)[EXPENSES_END];
 
	Money sum, cost;
 
	StringID str;
 

	
 
	if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
 
		/* draw categories */
 
		DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
 
		for (i = 0; i != EXPENSES_END; i++)
 
@@ -750,29 +750,30 @@ class SelectPlayerFaceWindow : public Wi
 
				this->IsWidgetLowered(widget_index), this->widget[widget_index].top + 1 + this->IsWidgetLowered(widget_index), str, TC_WHITE);
 
		}
 
	}
 

	
 
	void UpdateData()
 
	{
 
		this->ge = (GenderEthnicity)GB(this->face, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // get the gender and ethnicity
 
		this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
 
		this->is_moust_male = !is_female && GetPlayerFaceBits(this->face, PFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache
 
	}
 

	
 
public:
 
	SelectPlayerFaceWindow(const WindowDesc *desc, PlayerID player, bool advanced) : Window(desc, player)
 
	SelectPlayerFaceWindow(const WindowDesc *desc, Window *parent, bool advanced) : Window(desc, parent->window_number)
 
	{
 
		this->parent = parent;
 
		this->FindWindowPlacementAndResize(desc);
 
		this->caption_color = this->window_number;
 
		this->face = GetPlayer(player)->face;
 
		this->face = GetPlayer((PlayerID)this->window_number)->face;
 
		this->advanced = advanced;
 

	
 
		this->UpdateData();
 

	
 
		/* Check if repositioning from default is required */
 
		if (top != FIRST_GUI_CALL && left != FIRST_GUI_CALL) {
 
			this->top = top;
 
			this->left = left;
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
@@ -867,35 +868,36 @@ public:
 
		}
 

	
 
		/* Draw the player face picture */
 
		DrawPlayerFace(this->face, GetPlayer((PlayerID)this->window_number)->player_color, 2, 16);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			/* Toggle size, advanced/simple face selection */
 
			case PFW_WIDGET_TOGGLE_LARGE_SMALL:
 
			case PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: {
 
				DoCommandP(0, 0, this->face, NULL, CMD_SET_PLAYER_FACE);
 

	
 
				/* Backup some data before deletion */
 
				int oldtop = this->top;     ///< current top position of the window before closing it
 
				int oldleft = this->left;   ///< current top position of the window before closing it
 
				PlayerID player = (PlayerID)this->window_number;
 
				bool adv = !this->advanced;
 

	
 
				DoCommandP(0, 0, this->face, NULL, CMD_SET_PLAYER_FACE);
 
				Window *parent = this->parent;
 

	
 
				delete this;
 

	
 
				/* Open up the (toggled size) Face selection window at the same position as the previous */
 
				DoSelectPlayerFace(player, adv, oldtop, oldleft);
 
				DoSelectPlayerFace(parent, adv, oldtop, oldleft);
 
			} break;
 

	
 

	
 
			/* OK button */
 
			case PFW_WIDGET_ACCEPT:
 
				DoCommandP(0, 0, this->face, NULL, CMD_SET_PLAYER_FACE);
 
				/* Fall-Through */
 

	
 
			/* Cancel button */
 
			case PFW_WIDGET_CANCEL:
 
				delete this;
 
				break;
 
@@ -1022,30 +1024,30 @@ static const WindowDesc _select_player_f
 
};
 

	
 
/**
 
 * Open the simple/advanced player face selection window
 
 *
 
 * @param player the player which face shall be edited
 
 * @param adv    simple or advanced player face selection window
 
 * @param top    previous top position of the window
 
 * @param left   previous left position of the window
 
 *
 
 * @pre is player a valid player
 
 */
 
static void DoSelectPlayerFace(PlayerID player, bool adv, int top, int left)
 
static void DoSelectPlayerFace(Window *parent, bool adv, int top, int left)
 
{
 
	if (!IsValidPlayer(player)) return;
 
	if (!IsValidPlayer((PlayerID)parent->window_number)) return;
 

	
 
	if (BringWindowToFrontById(WC_PLAYER_FACE, player)) return;
 
	new SelectPlayerFaceWindow(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, player, adv); // simple or advanced window
 
	if (BringWindowToFrontById(WC_PLAYER_FACE, parent->window_number)) return;
 
	new SelectPlayerFaceWindow(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, parent, adv); // simple or advanced window
 
}
 

	
 

	
 
/* Names of the widgets. Keep them in the same order as in the widget array */
 
enum PlayerCompanyWindowWidgets {
 
	PCW_WIDGET_CLOSEBOX = 0,
 
	PCW_WIDGET_CAPTION,
 
	PCW_WIDGET_FACE,
 
	PCW_WIDGET_NEW_FACE,
 
	PCW_WIDGET_COLOR_SCHEME,
 
	PCW_WIDGET_PRESIDENT_NAME,
 
	PCW_WIDGET_COMPANY_NAME,
 
@@ -1164,30 +1166,24 @@ static void DrawCompanyOwnerText(const P
 
 * @param w window pointer
 
 * @param e event been triggered
 
 */
 
struct PlayerCompanyWindow : Window
 
{
 
	PlayerCompanyWindowWidgets query_widget;
 

	
 
	PlayerCompanyWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->caption_color = this->window_number;
 
	}
 

	
 
	~PlayerCompanyWindow()
 
	{
 
		DeleteWindowById(WC_PLAYER_FACE, this->window_number);
 
		if (this->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		const Player *p = GetPlayer((PlayerID)this->window_number);
 
		bool local = this->window_number == _local_player;
 

	
 
		this->SetWidgetHiddenState(PCW_WIDGET_NEW_FACE,       !local);
 
		this->SetWidgetHiddenState(PCW_WIDGET_COLOR_SCHEME,   !local);
 
		this->SetWidgetHiddenState(PCW_WIDGET_PRESIDENT_NAME, !local);
 
		this->SetWidgetHiddenState(PCW_WIDGET_COMPANY_NAME,   !local);
 
		this->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_house == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ;
 
		if (local && p->location_of_house != 0) this->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built.
 
		this->SetWidgetDisabledState(PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0);
 
@@ -1241,25 +1237,25 @@ struct PlayerCompanyWindow : Window
 

	
 
		/* "Company value:" */
 
		SetDParam(0, CalculateCompanyValue(p));
 
		DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING);
 

	
 
		/* Shares list */
 
		DrawCompanyOwnerText(p);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)this->window_number, false); break;
 
			case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace(this, false); break;
 

	
 
			case PCW_WIDGET_COLOR_SCHEME:
 
				if (BringWindowToFrontById(WC_PLAYER_COLOR, this->window_number)) break;
 
				new SelectPlayerLiveryWindow(&_select_player_livery_desc, (PlayerID)this->window_number);
 
				break;
 

	
 
			case PCW_WIDGET_PRESIDENT_NAME:
 
				this->query_widget = PCW_WIDGET_PRESIDENT_NAME;
 
				SetDParam(0, this->window_number);
 
				ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, 31, 94, this, CS_ALPHANUMERAL);
 
				break;
 

	
 
@@ -1295,25 +1291,25 @@ struct PlayerCompanyWindow : Window
 
				break;
 

	
 
			case PCW_WIDGET_BUY_SHARE:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
 
				break;
 

	
 
			case PCW_WIDGET_SELL_SHARE:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
 
				break;
 

	
 
#ifdef ENABLE_NETWORK
 
			case PCW_WIDGET_COMPANY_PASSWORD:
 
				if (this->window_number == _local_player) ShowNetworkCompanyPasswordWindow();
 
				if (this->window_number == _local_player) ShowNetworkCompanyPasswordWindow(this);
 
				break;
 
#endif /* ENABLE_NETWORK */
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		/* redraw the window every now and then */
 
		if ((++this->vscroll.pos & 0x1F) == 0) this->SetDirty();
 
	}
 

	
 
	virtual void OnPlaceObject(Point pt, TileIndex tile)
0 comments (0 inline, 0 general)