2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/** @file player_gui.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "vehicle.h"
|
2004-09-08 19:26:10 +00:00
|
|
|
#include "economy.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2007-01-27 12:29:55 +00:00
|
|
|
#include "aircraft.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-10-05 15:07:34 +00:00
|
|
|
#include "newgrf.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network_data.h"
|
|
|
|
#include "network/network_client.h"
|
2007-03-02 01:17:11 +00:00
|
|
|
#include "player_face.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void DrawPlayerEconomyStats(const Player *p, byte mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int x,y,i,j,year;
|
2005-09-18 20:56:44 +00:00
|
|
|
const int64 (*tbl)[13];
|
|
|
|
int64 sum, cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
|
|
|
|
2004-09-08 19:26:10 +00:00
|
|
|
if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw categories */
|
|
|
|
DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, 0);
|
2006-02-01 07:36:15 +00:00
|
|
|
for (i = 0; i != 13; i++)
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(2, 27 + i*10, STR_7011_CONSTRUCTION + i, 0);
|
|
|
|
DrawStringRightAligned(111, 27 + 10*13 + 2, STR_7020_TOTAL, 0);
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw the price columns */
|
|
|
|
year = _cur_year - 2;
|
|
|
|
j = 3;
|
|
|
|
x = 215;
|
|
|
|
tbl = p->yearly_expenses + 2;
|
|
|
|
do {
|
2006-08-20 19:05:28 +00:00
|
|
|
if (year >= p->inaugurated_year) {
|
2006-08-16 11:39:55 +00:00
|
|
|
SetDParam(0, year);
|
2006-08-20 10:50:23 +00:00
|
|
|
DrawStringRightAlignedUnderline(x, 15, STR_7010, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
sum = 0;
|
2006-02-01 07:36:15 +00:00
|
|
|
for (i = 0; i != 13; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw one row in the price column */
|
|
|
|
cost = (*tbl)[i];
|
|
|
|
if (cost != 0) {
|
|
|
|
sum += cost;
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_701E;
|
|
|
|
if (cost < 0) { cost = -cost; str++; }
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, cost);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(x, 27+i*10, str, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str = STR_701E;
|
|
|
|
if (sum < 0) { sum = -sum; str++; }
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, sum);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(x, 27 + 13*10 + 2, str, 0);
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
GfxFillRect(x - 75, 27 + 10*13, x, 27 + 10*13, 215);
|
|
|
|
x += 95;
|
|
|
|
}
|
|
|
|
year++;
|
|
|
|
tbl--;
|
|
|
|
} while (--j != 0);
|
|
|
|
|
|
|
|
y = 171;
|
2004-09-08 19:26:10 +00:00
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/* draw max loan aligned to loan below (y += 10) */
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, (uint64)_economy.max_loan);
|
2004-09-08 19:26:10 +00:00
|
|
|
DrawString(202, y+10, STR_MAX_LOAN, 0);
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
y = 15;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawString(2, y, STR_7026_BANK_BALANCE, 0);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, p->money64);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(182, y, STR_7028, 0);
|
|
|
|
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
DrawString(2, y, STR_7027_LOAN, 0);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, p->current_loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(182, y, STR_7028, 0);
|
|
|
|
|
|
|
|
y += 12;
|
|
|
|
|
|
|
|
GfxFillRect(182 - 75, y-2, 182, y-2, 215);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam64(0, p->money64 - p->current_loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(182, y, STR_7028, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _player_finances_widgets[] = {
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 379, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 380, 394, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 395, 406, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 14, 169, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 170, 203, 0x0, STR_NULL},
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 202, 204, 215, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 203, 406, 204, 215, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _other_player_finances_widgets[] = {
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 379, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 380, 394, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 395, 406, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 14, 169, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 170, 203, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _other_player_finances_small_widgets[] = {
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 253, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 254, 267, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 268, 279, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 279, 14, 47, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _player_finances_small_widgets[] = {
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 253, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 254, 267, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 268, 279, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 279, 14, 47, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 139, 48, 59, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 140, 279, 48, 59, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2007-01-10 18:56:51 +00:00
|
|
|
PlayerID player = (PlayerID)w->window_number;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Player *p = GetPlayer(player);
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2006-10-10 17:19:21 +00:00
|
|
|
if (player == _local_player) {
|
|
|
|
/* borrow/repay buttons only exist for local player */
|
|
|
|
SetWindowWidgetDisabledState(w, 7, p->current_loan == 0);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
2005-09-30 20:37:25 +00:00
|
|
|
SetDParam(2, GetPlayerNameString(player, 3));
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(4, 10000);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
DrawPlayerEconomyStats(p, (byte)WP(w,def_d).data_1);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 2: {/* toggle size */
|
|
|
|
byte mode = (byte)WP(w,def_d).data_1;
|
2005-01-04 17:04:10 +00:00
|
|
|
bool stickied = !!(w->flags4 & WF_STICKY);
|
2007-01-10 18:56:51 +00:00
|
|
|
PlayerID player = (PlayerID)w->window_number;
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
2005-01-13 20:46:39 +00:00
|
|
|
DoShowPlayerFinances(player, !HASBIT(mode, 0), stickied);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
2005-01-04 17:04:10 +00:00
|
|
|
case 6: /* increase loan */
|
2005-05-06 06:56:30 +00:00
|
|
|
DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-04 17:04:10 +00:00
|
|
|
case 7: /* repay loan */
|
2005-05-06 06:56:30 +00:00
|
|
|
DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _player_finances_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 407, 216,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_FINANCES, WC_NONE,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_player_finances_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_finances_small_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 280, 60,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_FINANCES, WC_NONE,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_player_finances_small_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _other_player_finances_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 407, 204,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_FINANCES, WC_NONE,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_other_player_finances_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _other_player_finances_small_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 280, 48,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_FINANCES, WC_NONE,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_other_player_finances_small_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
};
|
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
int mode;
|
|
|
|
|
2006-10-31 21:15:56 +00:00
|
|
|
static const WindowDesc * const desc_table[2 * 2] = {
|
|
|
|
&_player_finances_desc, &_player_finances_small_desc,
|
|
|
|
&_other_player_finances_desc, &_other_player_finances_small_desc,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
mode = (player != _local_player) * 2 + show_small;
|
2005-10-23 13:04:44 +00:00
|
|
|
w = AllocateWindowDescFront(desc_table[mode], player);
|
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->caption_color = w->window_number;
|
|
|
|
WP(w,def_d).data_1 = mode;
|
2006-10-31 21:15:56 +00:00
|
|
|
if (show_stickied) w->flags4 |= WF_STICKY;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
void ShowPlayerFinances(PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-04 17:04:10 +00:00
|
|
|
DoShowPlayerFinances(player, false, false);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
/* List of colours for the livery window */
|
|
|
|
static const StringID _colour_dropdown[] = {
|
|
|
|
STR_00D1_DARK_BLUE,
|
|
|
|
STR_00D2_PALE_GREEN,
|
|
|
|
STR_00D3_PINK,
|
|
|
|
STR_00D4_YELLOW,
|
|
|
|
STR_00D5_RED,
|
|
|
|
STR_00D6_LIGHT_BLUE,
|
|
|
|
STR_00D7_GREEN,
|
|
|
|
STR_00D8_DARK_GREEN,
|
|
|
|
STR_00D9_BLUE,
|
|
|
|
STR_00DA_CREAM,
|
|
|
|
STR_00DB_MAUVE,
|
|
|
|
STR_00DC_PURPLE,
|
|
|
|
STR_00DD_ORANGE,
|
|
|
|
STR_00DE_BROWN,
|
|
|
|
STR_00DF_GREY,
|
|
|
|
STR_00E0_WHITE,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Association of liveries to livery classes */
|
|
|
|
static const LiveryClass livery_class[LS_END] = {
|
|
|
|
LC_OTHER,
|
2006-09-15 17:36:54 +00:00
|
|
|
LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL,
|
2006-09-15 12:27:00 +00:00
|
|
|
LC_ROAD, LC_ROAD,
|
|
|
|
LC_SHIP, LC_SHIP,
|
|
|
|
LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Number of liveries in each class, used to determine the height of the livery window */
|
|
|
|
static const byte livery_height[] = {
|
|
|
|
1,
|
2006-09-15 17:36:54 +00:00
|
|
|
11,
|
2006-09-15 12:27:00 +00:00
|
|
|
2,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct livery_d {
|
2006-09-15 12:27:00 +00:00
|
|
|
uint32 sel;
|
|
|
|
LiveryClass livery_class;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-09-15 12:27:00 +00:00
|
|
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(livery_d));
|
|
|
|
|
|
|
|
static void ShowColourDropDownMenu(Window *w, uint32 widget)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-09-15 12:27:00 +00:00
|
|
|
uint32 used_colours = 0;
|
|
|
|
const Livery *livery;
|
|
|
|
LiveryScheme scheme;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
/* Disallow other player colours for the primary colour */
|
|
|
|
if (HASBIT(WP(w, livery_d).sel, LS_DEFAULT) && widget == 10) {
|
|
|
|
const Player *p;
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_PLAYERS(p) {
|
2006-09-15 12:27:00 +00:00
|
|
|
if (p->is_active && p->index != _local_player) SETBIT(used_colours, p->player_color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the first selected livery to use as the default dropdown item */
|
2007-01-10 18:56:51 +00:00
|
|
|
for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
|
2006-09-15 12:27:00 +00:00
|
|
|
if (HASBIT(WP(w, livery_d).sel, scheme)) break;
|
|
|
|
}
|
|
|
|
if (scheme == LS_END) scheme = LS_DEFAULT;
|
2007-01-10 18:56:51 +00:00
|
|
|
livery = &GetPlayer((PlayerID)w->window_number)->livery[scheme];
|
2006-09-15 12:27:00 +00:00
|
|
|
|
|
|
|
ShowDropDownMenu(w, _colour_dropdown, widget == 10 ? livery->colour1 : livery->colour2, widget, used_colours, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
2006-10-05 15:07:34 +00:00
|
|
|
case WE_CREATE:
|
|
|
|
LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
|
|
|
|
if (!_have_2cc) {
|
|
|
|
HideWindowWidget(w, 11);
|
|
|
|
HideWindowWidget(w, 12);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
case WE_PAINT: {
|
2007-01-10 18:56:51 +00:00
|
|
|
const Player *p = GetPlayer((PlayerID)w->window_number);
|
2006-09-15 12:27:00 +00:00
|
|
|
LiveryScheme scheme = LS_DEFAULT;
|
|
|
|
int y = 51;
|
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
/* Disable dropdown controls if no scheme is selected */
|
|
|
|
SetWindowWidgetDisabledState(w, 9, (WP(w, livery_d).sel == 0));
|
|
|
|
SetWindowWidgetDisabledState(w, 10, (WP(w, livery_d).sel == 0));
|
|
|
|
SetWindowWidgetDisabledState(w, 11, (WP(w, livery_d).sel == 0));
|
|
|
|
SetWindowWidgetDisabledState(w, 12, (WP(w, livery_d).sel == 0));
|
|
|
|
|
|
|
|
if (!(WP(w, livery_d).sel == 0)) {
|
2007-01-10 18:56:51 +00:00
|
|
|
for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
|
2006-09-15 12:27:00 +00:00
|
|
|
if (HASBIT(WP(w, livery_d).sel, scheme)) break;
|
|
|
|
}
|
|
|
|
if (scheme == LS_END) scheme = LS_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDParam(0, STR_00D1_DARK_BLUE + p->livery[scheme].colour1);
|
|
|
|
SetDParam(1, STR_00D1_DARK_BLUE + p->livery[scheme].colour2);
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
|
|
|
if (livery_class[scheme] == WP(w, livery_d).livery_class) {
|
|
|
|
bool sel = HASBIT(WP(w, livery_d).sel, scheme) != 0;
|
|
|
|
|
|
|
|
if (scheme != LS_DEFAULT) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(p->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, 2, y);
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
DrawString(15, y, STR_LIVERY_DEFAULT + scheme, sel ? 0xC : 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour1), 152, y);
|
2006-09-15 12:27:00 +00:00
|
|
|
DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? 0xC : 2);
|
2006-10-05 15:07:34 +00:00
|
|
|
|
|
|
|
if (_have_2cc) {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour2), 277, y);
|
2006-10-05 15:07:34 +00:00
|
|
|
DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? 0xC : 2);
|
|
|
|
}
|
2006-09-15 12:27:00 +00:00
|
|
|
|
|
|
|
y += 14;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-09-15 12:27:00 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2006-09-15 12:27:00 +00:00
|
|
|
/* Livery Class buttons */
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6: {
|
|
|
|
LiveryScheme scheme;
|
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowWidget(w, WP(w, livery_d).livery_class + 2);
|
2007-01-10 18:56:51 +00:00
|
|
|
WP(w, livery_d).livery_class = (LiveryClass)(e->we.click.widget - 2);
|
2006-09-15 12:27:00 +00:00
|
|
|
WP(w, livery_d).sel = 0;
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
|
2006-09-15 12:27:00 +00:00
|
|
|
|
|
|
|
/* Select the first item in the list */
|
|
|
|
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
|
|
|
if (livery_class[scheme] == WP(w, livery_d).livery_class) {
|
|
|
|
WP(w, livery_d).sel = 1 << scheme;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w->height = 49 + livery_height[WP(w, livery_d).livery_class] * 14;
|
|
|
|
w->widget[13].bottom = w->height - 1;
|
|
|
|
w->widget[13].data = livery_height[WP(w, livery_d).livery_class] << 8 | 1;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 9:
|
2007-03-21 17:42:43 +00:00
|
|
|
case 10: /* First colour dropdown */
|
2006-09-15 12:27:00 +00:00
|
|
|
ShowColourDropDownMenu(w, 10);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
2007-03-21 17:42:43 +00:00
|
|
|
case 12: /* Second colour dropdown */
|
2006-09-15 12:27:00 +00:00
|
|
|
ShowColourDropDownMenu(w, 12);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13: {
|
|
|
|
LiveryScheme scheme;
|
2007-01-10 18:56:51 +00:00
|
|
|
LiveryScheme j = (LiveryScheme)((e->we.click.pt.y - 48) / 14);
|
2006-09-15 12:27:00 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
for (scheme = LS_BEGIN; scheme <= j; scheme++) {
|
2006-09-15 12:27:00 +00:00
|
|
|
if (livery_class[scheme] != WP(w, livery_d).livery_class) j++;
|
|
|
|
if (scheme >= LS_END) return;
|
|
|
|
}
|
|
|
|
if (j >= LS_END) return;
|
|
|
|
|
|
|
|
/* If clicking on the left edge, toggle using the livery */
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.click.pt.x < 10) {
|
2007-01-10 18:56:51 +00:00
|
|
|
DoCommandP(0, j | (2 << 8), !GetPlayer((PlayerID)w->window_number)->livery[j].in_use, NULL, CMD_SET_PLAYER_COLOR);
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
TOGGLEBIT(WP(w, livery_d).sel, j);
|
|
|
|
} else {
|
|
|
|
WP(w, livery_d).sel = 1 << j;
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-15 12:27:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_DROPDOWN_SELECT: {
|
|
|
|
LiveryScheme scheme;
|
|
|
|
|
|
|
|
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
|
|
|
if (HASBIT(WP(w, livery_d).sel, scheme)) {
|
2006-09-23 02:39:24 +00:00
|
|
|
DoCommandP(0, scheme | (e->we.dropdown.button == 10 ? 0 : 256), e->we.dropdown.index, NULL, CMD_SET_PLAYER_COLOR);
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-05 15:07:34 +00:00
|
|
|
static const Widget _select_player_livery_2cc_widgets[] = {
|
2006-09-15 12:27:00 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_7007_NEW_COLOR_SCHEME, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
2006-09-27 11:45:26 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 21, 14, 35, SPR_IMG_COMPANY_GENERAL, STR_LIVERY_GENERAL_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 22, 43, 14, 35, SPR_IMG_TRAINLIST, STR_LIVERY_TRAIN_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 44, 65, 14, 35, SPR_IMG_TRUCKLIST, STR_LIVERY_ROADVEH_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 66, 87, 14, 35, SPR_IMG_SHIPLIST, STR_LIVERY_SHIP_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 88, 109, 14, 35, SPR_IMG_AIRPLANESLIST, STR_LIVERY_AIRCRAFT_TIP },
|
2006-09-15 12:27:00 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 110, 399, 14, 35, 0x0, STR_NULL },
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 149, 36, 47, 0x0, STR_NULL },
|
2006-09-27 11:45:26 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 150, 262, 36, 47, STR_02BD, STR_LIVERY_PRIMARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 263, 274, 36, 47, STR_0225, STR_LIVERY_PRIMARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 275, 387, 36, 47, STR_02E1, STR_LIVERY_SECONDARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 388, 399, 36, 47, STR_0225, STR_LIVERY_SECONDARY_TIP },
|
|
|
|
{ WWT_MATRIX, RESIZE_NONE, 14, 0, 399, 48, 48 + 1 * 14, (1 << 8) | 1, STR_LIVERY_PANEL_TIP },
|
2006-09-15 12:27:00 +00:00
|
|
|
{ WIDGETS_END },
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-10-05 15:07:34 +00:00
|
|
|
static const WindowDesc _select_player_livery_2cc_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 400, 49 + 1 * 14,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_PLAYER_COLOR, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
2006-10-05 15:07:34 +00:00
|
|
|
_select_player_livery_2cc_widgets,
|
|
|
|
SelectPlayerLiveryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _select_player_livery_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 274, 0, 13, STR_7007_NEW_COLOR_SCHEME, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 21, 14, 35, SPR_IMG_COMPANY_GENERAL, STR_LIVERY_GENERAL_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 22, 43, 14, 35, SPR_IMG_TRAINLIST, STR_LIVERY_TRAIN_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 44, 65, 14, 35, SPR_IMG_TRUCKLIST, STR_LIVERY_ROADVEH_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 66, 87, 14, 35, SPR_IMG_SHIPLIST, STR_LIVERY_SHIP_TIP },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 88, 109, 14, 35, SPR_IMG_AIRPLANESLIST, STR_LIVERY_AIRCRAFT_TIP },
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 110, 274, 14, 35, 0x0, STR_NULL },
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 149, 36, 47, 0x0, STR_NULL },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 150, 262, 36, 47, STR_02BD, STR_LIVERY_PRIMARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 263, 274, 36, 47, STR_0225, STR_LIVERY_PRIMARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 275, 275, 36, 47, STR_02E1, STR_LIVERY_SECONDARY_TIP },
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 275, 275, 36, 47, STR_0225, STR_LIVERY_SECONDARY_TIP },
|
|
|
|
{ WWT_MATRIX, RESIZE_NONE, 14, 0, 274, 48, 48 + 1 * 14, (1 << 8) | 1, STR_LIVERY_PANEL_TIP },
|
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _select_player_livery_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 275, 49 + 1 * 14,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_PLAYER_COLOR, WC_NONE,
|
2006-10-05 15:07:34 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
2006-09-15 12:27:00 +00:00
|
|
|
_select_player_livery_widgets,
|
|
|
|
SelectPlayerLiveryWndProc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-02 01:17:11 +00:00
|
|
|
/**
|
|
|
|
* Draws the face of a player.
|
|
|
|
* @param pf the player's face
|
|
|
|
* @param color the (background) color of the gradient
|
|
|
|
* @param x x-position to draw the face
|
|
|
|
* @param y y-position to draw the face
|
|
|
|
*/
|
|
|
|
void DrawPlayerFace(PlayerFace pf, int color, int x, int y)
|
|
|
|
{
|
|
|
|
GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM);
|
|
|
|
|
|
|
|
bool has_moustache = !HASBIT(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0;
|
|
|
|
bool has_tie_earring = !HASBIT(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0;
|
|
|
|
bool has_glasses = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0;
|
|
|
|
SpriteID pal;
|
|
|
|
switch (GetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case 0: pal = PALETTE_TO_BROWN; break;
|
|
|
|
case 1: pal = PALETTE_TO_BLUE; break;
|
|
|
|
case 2: pal = PALETTE_TO_GREEN; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the gradient (background) */
|
|
|
|
DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOR(color), x, y);
|
|
|
|
|
|
|
|
for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) {
|
|
|
|
switch (pfv) {
|
|
|
|
case PFV_MOUSTACHE: if (!has_moustache) continue; break;
|
|
|
|
case PFV_LIPS: /* FALL THROUGH */
|
|
|
|
case PFV_NOSE: if (has_moustache) continue; break;
|
|
|
|
case PFV_TIE_EARRING: if (!has_tie_earring) continue; break;
|
|
|
|
case PFV_GLASSES: if (!has_glasses) continue; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
DrawSprite(GetPlayerFaceSprite(pf, pfv, ge), (pfv == PFV_EYEBROWS) ? pal : PAL_NONE, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
Player *p;
|
2006-10-05 19:00:24 +00:00
|
|
|
LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
2007-01-10 18:56:51 +00:00
|
|
|
p = GetPlayer((PlayerID)w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawPlayerFace(WP(w,facesel_d).face, p->player_color, 2, 16);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 3: DeleteWindow(w); break;
|
2004-09-11 09:40:19 +00:00
|
|
|
case 4: /* ok click */
|
2005-05-06 06:56:30 +00:00
|
|
|
DoCommandP(0, 0, WP(w,facesel_d).face, NULL, CMD_SET_PLAYER_FACE);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
case 5: /* male click */
|
|
|
|
case 6: /* female click */
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowWidget(w, WP(w, facesel_d).gender + 5);
|
|
|
|
WP(w, facesel_d).gender = e->we.click.widget - 5;
|
|
|
|
LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case 7:
|
2007-03-02 01:17:11 +00:00
|
|
|
WP(w,facesel_d).face = ConvertFromOldPlayerFace((WP(w, facesel_d).gender << 31) + GB(InteractiveRandom(), 0, 31));
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _select_player_face_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 189, 0, 13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 189, 14, 136, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 94, 137, 148, STR_012E_CANCEL, STR_7047_CANCEL_NEW_FACE_SELECTION},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 189, 137, 148, STR_012F_OK, STR_7048_ACCEPT_NEW_FACE_SELECTION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 95, 187, 25, 36, STR_7044_MALE, STR_7049_SELECT_MALE_FACES},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 95, 187, 37, 48, STR_7045_FEMALE, STR_704A_SELECT_FEMALE_FACES},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 187, 79, 90, STR_7046_NEW_FACE, STR_704B_GENERATE_RANDOM_NEW_FACE},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _select_player_face_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 190, 149,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_PLAYER_FACE, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_select_player_face_widgets,
|
|
|
|
SelectPlayerFaceWndProc
|
|
|
|
};
|
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
/* Names of the widgets. Keep them in the same order as in the widget array */
|
2006-12-07 13:00:41 +00:00
|
|
|
enum PlayerCompanyWindowWidgets {
|
2006-10-05 23:24:16 +00:00
|
|
|
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,
|
|
|
|
PCW_WIDGET_BUILD_VIEW_HQ,
|
|
|
|
PCW_WIDGET_RELOCATE_HQ,
|
|
|
|
PCW_WIDGET_BUY_SHARE,
|
|
|
|
PCW_WIDGET_SELL_SHARE,
|
|
|
|
PCW_WIDGET_COMPANY_PASSWORD,
|
2006-12-07 13:00:41 +00:00
|
|
|
};
|
2006-10-05 23:24:16 +00:00
|
|
|
|
|
|
|
static const Widget _player_company_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 359, 0, 13, STR_7001, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 359, 14, 157, 0x0, STR_NULL},
|
2006-10-05 23:24:16 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 89, 158, 169, STR_7004_NEW_FACE, STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 90, 179, 158, 169, STR_7005_COLOR_SCHEME, STR_7031_CHANGE_THE_COMPANY_VEHICLE},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 180, 269, 158, 169, STR_7009_PRESIDENT_NAME, STR_7032_CHANGE_THE_PRESIDENT_S},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 270, 359, 158, 169, STR_7008_COMPANY_NAME, STR_7033_CHANGE_THE_COMPANY_NAME},
|
2006-10-11 00:48:55 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 266, 355, 18, 29, STR_7072_VIEW_HQ, STR_7070_BUILD_COMPANY_HEADQUARTERS},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 266, 355, 32, 43, STR_RELOCATE_HQ, STR_RELOCATE_COMPANY_HEADQUARTERS},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 179, 158, 169, STR_7077_BUY_25_SHARE_IN_COMPANY, STR_7079_BUY_25_SHARE_IN_THIS_COMPANY},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 180, 359, 158, 169, STR_7078_SELL_25_SHARE_IN_COMPANY, STR_707A_SELL_25_SHARE_IN_THIS_COMPANY},
|
2006-10-05 23:24:16 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 266, 355, 138, 149, STR_COMPANY_PASSWORD, STR_COMPANY_PASSWORD_TOOLTIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void DrawPlayerVehiclesAmount(PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const int x = 110;
|
|
|
|
int y = 72;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v;
|
2005-11-13 14:54:09 +00:00
|
|
|
uint train = 0;
|
|
|
|
uint road = 0;
|
|
|
|
uint air = 0;
|
|
|
|
uint ship = 0;
|
2004-09-11 09:40:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_7039_VEHICLES, 0);
|
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->owner == player) {
|
2005-11-13 14:54:09 +00:00
|
|
|
switch (v->type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: if (IsFrontEngine(v)) train++; break;
|
|
|
|
case VEH_ROAD: road++; break;
|
|
|
|
case VEH_AIRCRAFT: if (IsNormalAircraft(v)) air++; break;
|
|
|
|
case VEH_SHIP: ship++; break;
|
2005-11-13 14:54:09 +00:00
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (train+road+air+ship == 0) {
|
|
|
|
DrawString(x+70, y, STR_7042_NONE, 0);
|
|
|
|
} else {
|
|
|
|
if (train != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, train);
|
2005-07-31 16:15:37 +00:00
|
|
|
DrawString(x + 70, y, STR_TRAINS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (road != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, road);
|
2005-07-31 16:15:37 +00:00
|
|
|
DrawString(x + 70, y, STR_ROAD_VEHICLES, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (air != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, air);
|
2005-07-31 16:15:37 +00:00
|
|
|
DrawString(x + 70, y, STR_AIRCRAFT, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ship != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, ship);
|
2005-07-31 16:15:37 +00:00
|
|
|
DrawString(x + 70, y, STR_SHIPS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
int GetAmountOwnedBy(const Player *p, PlayerID owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-11 09:40:19 +00:00
|
|
|
return (p->share_owners[0] == owner) +
|
|
|
|
(p->share_owners[1] == owner) +
|
|
|
|
(p->share_owners[2] == owner) +
|
2004-08-09 17:04:08 +00:00
|
|
|
(p->share_owners[3] == owner);
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void DrawCompanyOwnerText(const Player *p)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Player *p2;
|
2004-08-09 17:04:08 +00:00
|
|
|
int num = -1;
|
|
|
|
|
|
|
|
FOR_ALL_PLAYERS(p2) {
|
2005-10-23 13:04:44 +00:00
|
|
|
uint amt = GetAmountOwnedBy(p, p2->index);
|
|
|
|
if (amt != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
num++;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
SetDParam(num * 3 + 0, amt * 25);
|
|
|
|
SetDParam(num * 3 + 1, p2->name_1);
|
|
|
|
SetDParam(num * 3 + 2, p2->name_2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (num != 0) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (num >= 0) DrawString(120, 124, STR_707D_OWNED_BY + num, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
switch (e->event) {
|
2006-10-05 23:24:16 +00:00
|
|
|
case WE_PAINT: {
|
2007-01-10 18:56:51 +00:00
|
|
|
const Player *p = GetPlayer((PlayerID)w->window_number);
|
2006-10-05 23:24:16 +00:00
|
|
|
bool local = w->window_number == _local_player;
|
|
|
|
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_NEW_FACE, !local);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_COLOR_SCHEME, !local);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_PRESIDENT_NAME, !local);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_COMPANY_NAME, !local);
|
|
|
|
w->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_house == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ;
|
2006-10-11 00:48:55 +00:00
|
|
|
if (local && p->location_of_house != 0) w->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built.
|
2006-10-05 23:24:16 +00:00
|
|
|
SetWindowWidgetDisabledState(w, PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_RELOCATE_HQ, !local || p->location_of_house == 0);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_BUY_SHARE, local);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_SELL_SHARE, local);
|
|
|
|
SetWindowWidgetHiddenState(w, PCW_WIDGET_COMPANY_PASSWORD, !local || !_networking);
|
|
|
|
|
|
|
|
if (!local) {
|
|
|
|
if (_patches.allow_shares) { // Shares are allowed
|
|
|
|
/* If all shares are owned by someone (none by nobody), disable buy button */
|
2006-10-14 15:49:43 +00:00
|
|
|
SetWindowWidgetDisabledState(w, PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 ||
|
2006-10-05 23:24:16 +00:00
|
|
|
/* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
|
2006-10-14 15:49:43 +00:00
|
|
|
(GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) ||
|
2006-10-05 23:24:16 +00:00
|
|
|
/* Spectators cannot do anything of course */
|
2006-10-14 15:49:43 +00:00
|
|
|
_local_player == PLAYER_SPECTATOR);
|
2006-10-05 23:24:16 +00:00
|
|
|
|
|
|
|
/* If the player doesn't own any shares, disable sell button */
|
|
|
|
SetWindowWidgetDisabledState(w, PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) ||
|
|
|
|
/* Spectators cannot do anything of course */
|
2006-10-14 15:49:43 +00:00
|
|
|
_local_player == PLAYER_SPECTATOR);
|
2006-10-05 23:24:16 +00:00
|
|
|
} else { // Shares are not allowed, disable buy/sell buttons
|
|
|
|
DisableWindowWidget(w, PCW_WIDGET_BUY_SHARE);
|
|
|
|
DisableWindowWidget(w, PCW_WIDGET_SELL_SHARE);
|
|
|
|
}
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
2007-01-10 18:56:51 +00:00
|
|
|
SetDParam(2, GetPlayerNameString((PlayerID)w->window_number, 3));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
DrawWindowWidgets(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
SetDParam(0, p->inaugurated_year);
|
|
|
|
DrawString(110, 25, STR_7038_INAUGURATED, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
DrawPlayerVehiclesAmount((PlayerID)w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
|
2007-03-21 17:42:43 +00:00
|
|
|
/* Draw company-colour bus */
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 49);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
SetDParam(0, p->president_name_1);
|
|
|
|
SetDParam(1, p->president_name_2);
|
|
|
|
DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
SetDParam64(0, CalculateCompanyValue(p));
|
|
|
|
DrawString(110, 114, STR_7076_COMPANY_VALUE, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
DrawCompanyOwnerText(p);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case PCW_WIDGET_NEW_FACE: {
|
|
|
|
Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
|
|
|
|
if (wf != NULL) {
|
|
|
|
wf->caption_color = w->window_number;
|
2007-01-10 18:56:51 +00:00
|
|
|
WP(wf,facesel_d).face = GetPlayer((PlayerID)wf->window_number)->face;
|
2006-10-05 23:24:16 +00:00
|
|
|
WP(wf,facesel_d).gender = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_COLOR_SCHEME: {
|
|
|
|
Window *wf = AllocateWindowDescFront(_have_2cc ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
|
|
|
|
if (wf != NULL) {
|
|
|
|
wf->caption_color = wf->window_number;
|
|
|
|
WP(wf,livery_d).livery_class = LC_OTHER;
|
|
|
|
WP(wf,livery_d).sel = 1;
|
|
|
|
LowerWindowWidget(wf, 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_PRESIDENT_NAME: {
|
2007-01-10 18:56:51 +00:00
|
|
|
const Player *p = GetPlayer((PlayerID)w->window_number);
|
2006-10-05 23:24:16 +00:00
|
|
|
WP(w, def_d).byte_1 = 0;
|
|
|
|
SetDParam(0, p->president_name_2);
|
2006-12-30 01:17:53 +00:00
|
|
|
ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w, CS_ALPHANUMERAL);
|
2006-10-05 23:24:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_COMPANY_NAME: {
|
2007-01-10 18:56:51 +00:00
|
|
|
Player *p = GetPlayer((PlayerID)w->window_number);
|
2006-10-05 23:24:16 +00:00
|
|
|
WP(w,def_d).byte_1 = 1;
|
|
|
|
SetDParam(0, p->name_2);
|
2006-12-30 01:17:53 +00:00
|
|
|
ShowQueryString(p->name_1, STR_700A_COMPANY_NAME, 31, 150, w, CS_ALPHANUMERAL);
|
2006-10-05 23:24:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-06 18:54:13 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_BUILD_VIEW_HQ: {
|
2007-01-10 18:56:51 +00:00
|
|
|
TileIndex tile = GetPlayer((PlayerID)w->window_number)->location_of_house;
|
2006-10-05 23:24:16 +00:00
|
|
|
if (tile == 0) {
|
|
|
|
if ((byte)w->window_number != _local_player)
|
|
|
|
return;
|
2007-01-14 19:57:49 +00:00
|
|
|
SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
|
2006-10-05 23:24:16 +00:00
|
|
|
SetTileSelectSize(2, 2);
|
2006-10-11 00:48:55 +00:00
|
|
|
LowerWindowWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
|
|
|
|
InvalidateWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
|
2006-10-05 23:24:16 +00:00
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_RELOCATE_HQ:
|
2007-01-14 19:57:49 +00:00
|
|
|
SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
|
2006-10-05 23:24:16 +00:00
|
|
|
SetTileSelectSize(2, 2);
|
2006-10-11 00:48:55 +00:00
|
|
|
LowerWindowWidget(w, PCW_WIDGET_RELOCATE_HQ);
|
|
|
|
InvalidateWidget(w, PCW_WIDGET_RELOCATE_HQ);
|
2006-10-05 23:24:16 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_BUY_SHARE:
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
|
|
|
|
break;
|
2004-09-01 21:54:12 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_SELL_SHARE:
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-12 14:59:27 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2006-10-05 23:24:16 +00:00
|
|
|
case PCW_WIDGET_COMPANY_PASSWORD:
|
|
|
|
if (w->window_number == _local_player) {
|
|
|
|
WP(w,def_d).byte_1 = 2;
|
|
|
|
ShowQueryString(BindCString(_network_player_info[_local_player].password),
|
2006-12-30 01:17:53 +00:00
|
|
|
STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w, CS_ALPHANUMERAL);
|
2006-10-05 23:24:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-10-12 14:59:27 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2006-10-05 23:24:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case WE_MOUSELOOP:
|
|
|
|
/* redraw the window every now and then */
|
|
|
|
if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w);
|
|
|
|
break;
|
2004-12-22 23:24:53 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case WE_PLACE_OBJ:
|
|
|
|
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)))
|
|
|
|
ResetObjectToPlace();
|
2006-10-11 00:48:55 +00:00
|
|
|
w->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button
|
|
|
|
RaiseWindowButtons(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
|
|
|
RaiseWindowButtons(w);
|
2006-10-05 23:24:16 +00:00
|
|
|
break;
|
2004-12-22 23:24:53 +00:00
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
case WE_DESTROY:
|
|
|
|
DeleteWindowById(WC_PLAYER_FACE, w->window_number);
|
2004-12-22 23:24:53 +00:00
|
|
|
break;
|
2006-10-05 23:24:16 +00:00
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT: {
|
|
|
|
char *b = e->we.edittext.str;
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/* empty string is allowed for password */
|
2006-10-05 23:24:16 +00:00
|
|
|
if (*b == '\0' && WP(w,def_d).byte_1 != 2) return;
|
|
|
|
|
|
|
|
_cmd_text = b;
|
|
|
|
switch (WP(w,def_d).byte_1) {
|
|
|
|
case 0: /* Change president name */
|
|
|
|
DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
|
|
|
|
break;
|
|
|
|
case 1: /* Change company name */
|
|
|
|
DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
|
|
|
|
break;
|
2006-10-12 14:59:27 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2006-10-05 23:24:16 +00:00
|
|
|
case 2: /* Change company password */
|
|
|
|
if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
|
|
|
|
NetworkChangeCompanyPassword(1, &b);
|
|
|
|
break;
|
2006-10-12 14:59:27 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2006-10-05 23:24:16 +00:00
|
|
|
}
|
2004-12-22 23:24:53 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
static const WindowDesc _player_company_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 360, 170,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_COMPANY, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
2006-10-05 23:24:16 +00:00
|
|
|
_player_company_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
PlayerCompanyWndProc
|
|
|
|
};
|
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
void ShowPlayerCompany(PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2006-10-05 23:24:16 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_company_desc, player);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w != NULL) w->caption_color = w->window_number;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void BuyCompanyWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2007-01-10 18:56:51 +00:00
|
|
|
Player *p = GetPlayer((PlayerID)w->window_number);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, p->bankrupt_value);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(214, 65, STR_705B_WE_ARE_LOOKING_FOR_A_TRANSPORT, 238);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 3:
|
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
case 4: {
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_COMPANY | CMD_MSG(STR_7060_CAN_T_BUY_COMPANY));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _buy_company_widgets[] = {
|
2006-03-24 18:16:39 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 5, 0, 333, 14, 136, 0x0, STR_NULL},
|
2006-03-24 18:16:39 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 5, 148, 207, 117, 128, STR_00C9_NO, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 5, 218, 277, 117, 128, STR_00C8_YES, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _buy_company_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
153, 171, 334, 137,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_BUY_COMPANY, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_buy_company_widgets,
|
|
|
|
BuyCompanyWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowBuyCompanyDialog(uint player)
|
|
|
|
{
|
|
|
|
AllocateWindowDescFront(&_buy_company_desc, player);
|
|
|
|
}
|
2005-01-11 00:54:06 +00:00
|
|
|
|
|
|
|
/********** HIGHSCORE and ENDGAME windows */
|
|
|
|
|
|
|
|
/* Always draw a maximized window and within there the centered background */
|
|
|
|
static void SetupHighScoreEndWindow(Window *w, uint *x, uint *y)
|
|
|
|
{
|
|
|
|
uint i;
|
2007-03-21 17:42:43 +00:00
|
|
|
/* resize window to "full-screen" */
|
2005-01-11 00:54:06 +00:00
|
|
|
w->width = _screen.width;
|
|
|
|
w->height = _screen.height;
|
|
|
|
w->widget[0].right = w->width - 1;
|
|
|
|
w->widget[0].bottom = w->height - 1;
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
/* Center Highscore/Endscreen background */
|
|
|
|
*x = max(0, (_screen.width / 2) - (640 / 2));
|
|
|
|
*y = max(0, (_screen.height / 2) - (480 / 2));
|
|
|
|
for (i = 0; i < 10; i++) // the image is split into 10 50px high parts
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(WP(w, highscore_d).background_img + i, PAL_NONE, *x, *y + (i * 50));
|
2005-01-11 00:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern StringID EndGameGetPerformanceTitleFromValue(uint value);
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/** End game window shown at the end of the game */
|
2005-01-11 00:54:06 +00:00
|
|
|
static void EndGameWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
2006-10-31 01:45:41 +00:00
|
|
|
const Player *p;
|
2005-01-11 00:54:06 +00:00
|
|
|
uint x, y;
|
|
|
|
|
|
|
|
SetupHighScoreEndWindow(w, &x, &y);
|
|
|
|
|
2006-10-31 01:45:41 +00:00
|
|
|
if (!IsValidPlayer(_local_player)) break;
|
|
|
|
|
|
|
|
p = GetPlayer(_local_player);
|
2005-01-11 00:54:06 +00:00
|
|
|
/* We need to get performance from last year because the image is shown
|
|
|
|
* at the start of the new year when these things have already been copied */
|
2005-01-13 16:28:47 +00:00
|
|
|
if (WP(w, highscore_d).background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
|
2005-01-11 00:54:06 +00:00
|
|
|
SetDParam(0, p->president_name_1);
|
|
|
|
SetDParam(1, p->president_name_2);
|
|
|
|
SetDParam(2, p->name_1);
|
|
|
|
SetDParam(3, p->name_2);
|
|
|
|
SetDParam(4, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
|
|
|
|
DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
|
|
|
|
DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
|
|
|
|
}
|
2005-01-15 01:52:23 +00:00
|
|
|
} break;
|
2005-05-17 20:54:05 +00:00
|
|
|
case WE_CLICK: /* Close the window (and show the highscore window) */
|
2005-01-11 00:54:06 +00:00
|
|
|
DeleteWindow(w);
|
2005-05-30 13:06:15 +00:00
|
|
|
break;
|
2005-05-17 20:54:05 +00:00
|
|
|
case WE_DESTROY: /* Show the highscore window when this one is closed */
|
|
|
|
if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
|
|
|
|
ShowHighscoreTable(w->window_number, WP(w, highscore_d).rank);
|
|
|
|
break;
|
2005-01-11 00:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HighScoreWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
|
|
|
const HighScore *hs = _highscore_table[w->window_number];
|
2005-01-13 16:28:47 +00:00
|
|
|
uint x, y;
|
|
|
|
uint8 i;
|
2005-01-11 00:54:06 +00:00
|
|
|
|
|
|
|
SetupHighScoreEndWindow(w, &x, &y);
|
|
|
|
|
2006-08-15 14:52:17 +00:00
|
|
|
SetDParam(0, _patches.ending_year);
|
2005-01-13 16:28:47 +00:00
|
|
|
SetDParam(1, w->window_number + STR_6801_EASY);
|
|
|
|
DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500);
|
2005-01-11 00:54:06 +00:00
|
|
|
|
|
|
|
/* Draw Highscore peepz */
|
|
|
|
for (i = 0; i < lengthof(_highscore_table[0]); i++) {
|
|
|
|
SetDParam(0, i + 1);
|
|
|
|
DrawString(x + 40, y + 140 + (i * 55), STR_0212, 0x10);
|
|
|
|
|
|
|
|
if (hs[i].company[0] != '\0') {
|
2005-01-13 16:28:47 +00:00
|
|
|
uint16 colour = (WP(w, highscore_d).rank == (int8)i) ? 0x3 : 0x10; // draw new highscore in red
|
2005-01-11 00:54:06 +00:00
|
|
|
|
|
|
|
DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour);
|
|
|
|
SetDParam(0, hs[i].title);
|
|
|
|
SetDParam(1, hs[i].score);
|
|
|
|
DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
|
|
|
|
}
|
|
|
|
}
|
2005-01-15 08:58:31 +00:00
|
|
|
} break;
|
2005-01-11 00:54:06 +00:00
|
|
|
|
2005-05-17 20:54:05 +00:00
|
|
|
case WE_CLICK: /* Onclick to close window, and in destroy event handle the rest */
|
2005-01-11 00:54:06 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
2005-05-17 20:54:05 +00:00
|
|
|
|
|
|
|
case WE_DESTROY: /* Get back all the hidden windows */
|
|
|
|
if (_game_mode != GM_MENU) ShowVitalWindows();
|
|
|
|
|
|
|
|
if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
|
|
|
|
break;
|
|
|
|
}
|
2005-01-11 00:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _highscore_widgets[] = {
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 16, 0, 640, 0, 480, 0x0, STR_NULL},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _highscore_desc = {
|
|
|
|
0, 0, 641, 481,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_HIGHSCORE, WC_NONE,
|
2005-01-11 00:54:06 +00:00
|
|
|
0,
|
|
|
|
_highscore_widgets,
|
|
|
|
HighScoreWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _endgame_desc = {
|
|
|
|
0, 0, 641, 481,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_ENDSCREEN, WC_NONE,
|
2005-01-11 00:54:06 +00:00
|
|
|
0,
|
|
|
|
_highscore_widgets,
|
|
|
|
EndGameWndProc
|
|
|
|
};
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/** Show the highscore table for a given difficulty. When called from
|
2005-01-11 00:54:06 +00:00
|
|
|
* endgame ranking is set to the top5 element that was newly added
|
|
|
|
* and is thus highlighted */
|
2005-01-13 16:28:47 +00:00
|
|
|
void ShowHighscoreTable(int difficulty, int8 ranking)
|
2005-01-11 00:54:06 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/* pause game to show the chart */
|
2005-05-17 20:54:05 +00:00
|
|
|
if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
|
|
|
|
|
|
|
/* Close all always on-top windows to get a clean screen */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode != GM_MENU) HideVitalWindows();
|
2005-01-11 00:54:06 +00:00
|
|
|
|
2005-05-30 13:06:15 +00:00
|
|
|
DeleteWindowByClass(WC_HIGHSCORE);
|
2005-01-11 00:54:06 +00:00
|
|
|
w = AllocateWindowDesc(&_highscore_desc);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
w->window_number = difficulty; // show highscore chart for difficulty...
|
2005-01-13 16:28:47 +00:00
|
|
|
WP(w, highscore_d).background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
|
|
|
|
WP(w, highscore_d).rank = ranking;
|
2005-01-11 00:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 17:42:43 +00:00
|
|
|
/** Show the endgame victory screen in 2050. Update the new highscore
|
2005-01-11 00:54:06 +00:00
|
|
|
* if it was high enough */
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowEndGameChart()
|
2005-01-11 00:54:06 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2005-05-17 20:54:05 +00:00
|
|
|
/* Dedicated server doesn't need the highscore window */
|
|
|
|
if (_network_dedicated) return;
|
|
|
|
/* Pause in single-player to have a look at the highscore at your own leisure */
|
|
|
|
if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
2005-01-11 00:54:06 +00:00
|
|
|
|
2005-05-17 20:54:05 +00:00
|
|
|
HideVitalWindows();
|
2005-05-30 13:06:15 +00:00
|
|
|
DeleteWindowByClass(WC_ENDSCREEN);
|
2005-01-11 00:54:06 +00:00
|
|
|
w = AllocateWindowDesc(&_endgame_desc);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
MarkWholeScreenDirty();
|
2005-01-20 18:57:09 +00:00
|
|
|
|
|
|
|
WP(w, highscore_d).background_img = SPR_TYCOON_IMG1_BEGIN;
|
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (_local_player != PLAYER_SPECTATOR) {
|
2005-06-21 16:28:17 +00:00
|
|
|
const Player *p = GetPlayer(_local_player);
|
2005-01-20 18:57:09 +00:00
|
|
|
if (p->old_economy[0].performance_history == SCORE_MAX)
|
|
|
|
WP(w, highscore_d).background_img = SPR_TYCOON_IMG2_BEGIN;
|
|
|
|
}
|
|
|
|
|
2005-01-13 16:28:47 +00:00
|
|
|
/* In a network game show the endscores of the custom difficulty 'network' which is the last one
|
2005-01-20 18:57:09 +00:00
|
|
|
* as well as generate a TOP5 of that game, and not an all-time top5. */
|
|
|
|
if (_networking) {
|
|
|
|
w->window_number = lengthof(_highscore_table) - 1;
|
|
|
|
WP(w, highscore_d).rank = SaveHighScoreValueNetwork();
|
|
|
|
} else {
|
2007-03-21 17:42:43 +00:00
|
|
|
/* in single player _local player is always valid */
|
2005-06-21 16:28:17 +00:00
|
|
|
const Player *p = GetPlayer(_local_player);
|
2005-01-20 18:57:09 +00:00
|
|
|
w->window_number = _opt.diff_level;
|
|
|
|
WP(w, highscore_d).rank = SaveHighScoreValue(p);
|
|
|
|
}
|
2005-01-23 13:09:35 +00:00
|
|
|
}
|
2005-01-11 00:54:06 +00:00
|
|
|
}
|