--- a/src/player_gui.cpp Sat Oct 06 21:16:00 2007 +0000
+++ b/src/player_gui.cpp Mon Dec 03 23:39:38 2007 +0000
@@ -25,9 +25,11 @@
#include "newgrf.h"
#include "network/network_data.h"
#include "network/network_client.h"
+#include "network/network_gui.h"
#include "player_face.h"
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
+static void DoSelectPlayerFace(PlayerID player, bool show_big);
static void DrawPlayerEconomyStats(const Player *p, byte mode)
{
@@ -38,10 +40,10 @@
if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
/* draw categories */
- DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, 0);
+ DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
for (i = 0; i != 13; i++)
- DrawString(2, 27 + i * 10, STR_7011_CONSTRUCTION + i, 0);
- DrawStringRightAligned(111, 27 + 10 * 13 + 2, STR_7020_TOTAL, 0);
+ DrawString(2, 27 + i * 10, STR_7011_CONSTRUCTION + i, TC_FROMSTRING);
+ DrawStringRightAligned(111, 27 + 10 * 13 + 2, STR_7020_TOTAL, TC_FROMSTRING);
/* draw the price columns */
year = _cur_year - 2;
@@ -51,7 +53,7 @@
do {
if (year >= p->inaugurated_year) {
SetDParam(0, year);
- DrawStringRightAlignedUnderline(x, 15, STR_7010, 0);
+ DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING);
sum = 0;
for (i = 0; i != 13; i++) {
/* draw one row in the price column */
@@ -62,14 +64,14 @@
str = STR_701E;
if (cost < 0) { cost = -cost; str++; }
SetDParam(0, cost);
- DrawStringRightAligned(x, 27 + i * 10, str, 0);
+ DrawStringRightAligned(x, 27 + i * 10, str, TC_FROMSTRING);
}
}
str = STR_701E;
if (sum < 0) { sum = -sum; str++; }
SetDParam(0, sum);
- DrawStringRightAligned(x, 27 + 13 * 10 + 2, str, 0);
+ DrawStringRightAligned(x, 27 + 13 * 10 + 2, str, TC_FROMSTRING);
GfxFillRect(x - 75, 27 + 10 * 13, x, 27 + 10 * 13, 215);
x += 95;
@@ -82,27 +84,27 @@
/* draw max loan aligned to loan below (y += 10) */
SetDParam(0, _economy.max_loan);
- DrawString(202, y + 10, STR_MAX_LOAN, 0);
+ DrawString(202, y + 10, STR_MAX_LOAN, TC_FROMSTRING);
} else {
y = 15;
}
- DrawString(2, y, STR_7026_BANK_BALANCE, 0);
+ DrawString(2, y, STR_7026_BANK_BALANCE, TC_FROMSTRING);
SetDParam(0, p->player_money);
- DrawStringRightAligned(182, y, STR_7028, 0);
+ DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
y += 10;
- DrawString(2, y, STR_7027_LOAN, 0);
+ DrawString(2, y, STR_7027_LOAN, TC_FROMSTRING);
SetDParam(0, p->current_loan);
- DrawStringRightAligned(182, y, STR_7028, 0);
+ DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
y += 12;
GfxFillRect(182 - 75, y - 2, 182, y - 2, 215);
SetDParam(0, p->player_money - p->current_loan);
- DrawStringRightAligned(182, y, STR_7028, 0);
+ DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
}
static const Widget _player_finances_widgets[] = {
@@ -145,15 +147,15 @@
w->height = new_height;
SetWindowDirty(w);
- SetWindowWidgetHiddenState(w, 6, player != _local_player);
- SetWindowWidgetHiddenState(w, 7, player != _local_player);
+ w->SetWidgetHiddenState(6, player != _local_player);
+ w->SetWidgetHiddenState(7, player != _local_player);
}
/* Borrow button only shows when there is any more money to loan */
- SetWindowWidgetDisabledState(w, 6, p->current_loan == _economy.max_loan);
+ w->SetWidgetDisabledState(6, p->current_loan == _economy.max_loan);
/* Repay button only shows when there is any more money to repay */
- SetWindowWidgetDisabledState(w, 7, player != _local_player || p->current_loan == 0);
+ w->SetWidgetDisabledState(7, player != _local_player || p->current_loan == 0);
SetDParam(0, p->index);
SetDParam(1, p->index);
@@ -170,7 +172,7 @@
bool stickied = !!(w->flags4 & WF_STICKY);
PlayerID player = (PlayerID)w->window_number;
DeleteWindow(w);
- DoShowPlayerFinances(player, !HASBIT(mode, 0), stickied);
+ DoShowPlayerFinances(player, !HasBit(mode, 0), stickied);
} break;
case 6: /* increase loan */
@@ -271,16 +273,16 @@
LiveryScheme scheme;
/* Disallow other player colours for the primary colour */
- if (HASBIT(WP(w, livery_d).sel, LS_DEFAULT) && widget == 10) {
+ if (HasBit(WP(w, livery_d).sel, LS_DEFAULT) && widget == 10) {
const Player *p;
FOR_ALL_PLAYERS(p) {
- if (p->is_active && p->index != _local_player) SETBIT(used_colours, p->player_color);
+ if (p->is_active && p->index != _local_player) SetBit(used_colours, p->player_color);
}
}
/* Get the first selected livery to use as the default dropdown item */
for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
- if (HASBIT(WP(w, livery_d).sel, scheme)) break;
+ if (HasBit(WP(w, livery_d).sel, scheme)) break;
}
if (scheme == LS_END) scheme = LS_DEFAULT;
livery = &GetPlayer((PlayerID)w->window_number)->livery[scheme];
@@ -292,10 +294,10 @@
{
switch (e->event) {
case WE_CREATE:
- LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
+ w->LowerWidget(WP(w, livery_d).livery_class + 2);
if (!_loaded_newgrf_features.has_2CC) {
- HideWindowWidget(w, 11);
- HideWindowWidget(w, 12);
+ w->HideWidget(11);
+ w->HideWidget(12);
}
break;
@@ -305,14 +307,14 @@
int y = 51;
/* 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));
+ w->SetWidgetDisabledState( 9, (WP(w, livery_d).sel == 0));
+ w->SetWidgetDisabledState(10, (WP(w, livery_d).sel == 0));
+ w->SetWidgetDisabledState(11, (WP(w, livery_d).sel == 0));
+ w->SetWidgetDisabledState(12, (WP(w, livery_d).sel == 0));
if (!(WP(w, livery_d).sel == 0)) {
for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
- if (HASBIT(WP(w, livery_d).sel, scheme)) break;
+ if (HasBit(WP(w, livery_d).sel, scheme)) break;
}
if (scheme == LS_END) scheme = LS_DEFAULT;
}
@@ -324,20 +326,20 @@
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;
+ bool sel = HasBit(WP(w, livery_d).sel, scheme) != 0;
if (scheme != LS_DEFAULT) {
DrawSprite(p->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, 2, y);
}
- DrawString(15, y, STR_LIVERY_DEFAULT + scheme, sel ? 0xC : 0x10);
+ DrawString(15, y, STR_LIVERY_DEFAULT + scheme, sel ? TC_WHITE : TC_BLACK);
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour1), 152, y);
- DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? 0xC : 2);
+ DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? TC_WHITE : TC_GOLD);
if (_loaded_newgrf_features.has_2CC) {
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour2), 277, y);
- DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? 0xC : 2);
+ DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? TC_WHITE : TC_GOLD);
}
y += 14;
@@ -356,10 +358,10 @@
case 6: {
LiveryScheme scheme;
- RaiseWindowWidget(w, WP(w, livery_d).livery_class + 2);
+ w->RaiseWidget(WP(w, livery_d).livery_class + 2);
WP(w, livery_d).livery_class = (LiveryClass)(e->we.click.widget - 2);
WP(w, livery_d).sel = 0;
- LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
+ w->LowerWidget(WP(w, livery_d).livery_class + 2);
/* Select the first item in the list */
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
@@ -401,7 +403,7 @@
}
if (_ctrl_pressed) {
- TOGGLEBIT(WP(w, livery_d).sel, j);
+ ToggleBit(WP(w, livery_d).sel, j);
} else {
WP(w, livery_d).sel = 1 << j;
}
@@ -416,7 +418,7 @@
LiveryScheme scheme;
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
- if (HASBIT(WP(w, livery_d).sel, scheme)) {
+ if (HasBit(WP(w, livery_d).sel, scheme)) {
DoCommandP(0, scheme | (e->we.dropdown.button == 10 ? 0 : 256), e->we.dropdown.index, NULL, CMD_SET_PLAYER_COLOR);
}
}
@@ -489,15 +491,21 @@
{
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_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;
+
+ /* Modify eye colour palette only if 2 or more valid values exist */
+ if (_pf_info[PFV_EYE_COLOUR].valid_values[ge] < 2) {
+ pal = PAL_NONE;
+ } else {
+ 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) */
@@ -516,60 +524,426 @@
}
}
-static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- Player *p;
- LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
- DrawWindowWidgets(w);
- p = GetPlayer((PlayerID)w->window_number);
- DrawPlayerFace(WP(w, facesel_d).face, p->player_color, 2, 16);
- } break;
+/**
+ * Names of the widgets. Keep them in the same order as in the widget array.
+ * Do not change the order of the widgets from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R,
+ * this order is needed for the WE_CLICK event of DrawFaceStringLabel().
+ */
+enum PlayerFaceWindowWidgets {
+ PFW_WIDGET_CLOSEBOX = 0,
+ PFW_WIDGET_CAPTION,
+ PFW_WIDGET_TOGGLE_LARGE_SMALL,
+ PFW_WIDGET_SELECT_FACE,
+ PFW_WIDGET_CANCEL,
+ PFW_WIDGET_ACCEPT,
+ PFW_WIDGET_MALE,
+ PFW_WIDGET_FEMALE,
+ PFW_WIDGET_RANDOM_NEW_FACE,
+ PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON,
+ /* from here is the advanced player face selection window */
+ PFW_WIDGET_LOAD,
+ PFW_WIDGET_FACECODE,
+ PFW_WIDGET_SAVE,
+ PFW_WIDGET_ETHNICITY_EUR,
+ PFW_WIDGET_ETHNICITY_AFR,
+ PFW_WIDGET_HAS_MOUSTACHE_EARRING,
+ PFW_WIDGET_HAS_GLASSES,
+ PFW_WIDGET_EYECOLOUR_L,
+ PFW_WIDGET_EYECOLOUR,
+ PFW_WIDGET_EYECOLOUR_R,
+ PFW_WIDGET_CHIN_L,
+ PFW_WIDGET_CHIN,
+ PFW_WIDGET_CHIN_R,
+ PFW_WIDGET_EYEBROWS_L,
+ PFW_WIDGET_EYEBROWS,
+ PFW_WIDGET_EYEBROWS_R,
+ PFW_WIDGET_LIPS_MOUSTACHE_L,
+ PFW_WIDGET_LIPS_MOUSTACHE,
+ PFW_WIDGET_LIPS_MOUSTACHE_R,
+ PFW_WIDGET_NOSE_L,
+ PFW_WIDGET_NOSE,
+ PFW_WIDGET_NOSE_R,
+ PFW_WIDGET_HAIR_L,
+ PFW_WIDGET_HAIR,
+ PFW_WIDGET_HAIR_R,
+ PFW_WIDGET_JACKET_L,
+ PFW_WIDGET_JACKET,
+ PFW_WIDGET_JACKET_R,
+ PFW_WIDGET_COLLAR_L,
+ PFW_WIDGET_COLLAR,
+ PFW_WIDGET_COLLAR_R,
+ PFW_WIDGET_TIE_EARRING_L,
+ PFW_WIDGET_TIE_EARRING,
+ PFW_WIDGET_TIE_EARRING_R,
+ PFW_WIDGET_GLASSES_L,
+ PFW_WIDGET_GLASSES,
+ PFW_WIDGET_GLASSES_R,
+};
- case WE_CLICK:
- switch (e->we.click.widget) {
- case 3: DeleteWindow(w); break;
- case 4: /* ok click */
- DoCommandP(0, 0, WP(w, facesel_d).face, NULL, CMD_SET_PLAYER_FACE);
- DeleteWindow(w);
- break;
- case 5: /* male click */
- case 6: /* female click */
- 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);
- SetWindowDirty(w);
- break;
- case 7:
- WP(w, facesel_d).face = ConvertFromOldPlayerFace((WP(w, facesel_d).gender << 31) + GB(InteractiveRandom(), 0, 31));
- SetWindowDirty(w);
- break;
+/** Widget description for the normal/simple player face selection dialog */
+static const Widget _select_player_face_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // PFW_WIDGET_CLOSEBOX
+{ WWT_CAPTION, RESIZE_NONE, 14, 11, 174, 0, 13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // PFW_WIDGET_CAPTION
+{ WWT_IMGBTN, RESIZE_NONE, 14, 175, 189, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_FACE_ADVANCED_TIP}, // PFW_WIDGET_TOGGLE_LARGE_SMALL
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 189, 14, 150, 0x0, STR_NULL}, // PFW_WIDGET_SELECT_FACE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 94, 151, 162, STR_012E_CANCEL, STR_7047_CANCEL_NEW_FACE_SELECTION}, // PFW_WIDGET_CANCEL
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 189, 151, 162, STR_012F_OK, STR_7048_ACCEPT_NEW_FACE_SELECTION}, // PFW_WIDGET_ACCEPT
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 95, 187, 75, 86, STR_7044_MALE, STR_7049_SELECT_MALE_FACES}, // PFW_WIDGET_MALE
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 95, 187, 87, 98, STR_7045_FEMALE, STR_704A_SELECT_FEMALE_FACES}, // PFW_WIDGET_FEMALE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 2, 93, 137, 148, STR_7046_NEW_FACE, STR_704B_GENERATE_RANDOM_NEW_FACE}, // PFW_WIDGET_RANDOM_NEW_FACE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 187, 16, 27, STR_FACE_ADVANCED, STR_FACE_ADVANCED_TIP}, // PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
+{ WIDGETS_END},
+};
+
+/** Widget description for the advanced player face selection dialog */
+static const Widget _select_player_face_adv_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // PFW_WIDGET_CLOSEBOX
+{ WWT_CAPTION, RESIZE_NONE, 14, 11, 204, 0, 13, STR_7043_FACE_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // PFW_WIDGET_CAPTION
+{ WWT_IMGBTN, RESIZE_NONE, 14, 205, 219, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_FACE_SIMPLE_TIP}, // PFW_WIDGET_TOGGLE_LARGE_SMALL
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 219, 14, 207, 0x0, STR_NULL}, // PFW_WIDGET_SELECT_FACE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 94, 208, 219, STR_012E_CANCEL, STR_7047_CANCEL_NEW_FACE_SELECTION}, // PFW_WIDGET_CANCEL
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 219, 208, 219, STR_012F_OK, STR_7048_ACCEPT_NEW_FACE_SELECTION}, // PFW_WIDGET_ACCEPT
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 96, 156, 32, 43, STR_7044_MALE, STR_7049_SELECT_MALE_FACES}, // PFW_WIDGET_MALE
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 157, 217, 32, 43, STR_7045_FEMALE, STR_704A_SELECT_FEMALE_FACES}, // PFW_WIDGET_FEMALE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 2, 93, 137, 148, STR_RANDOM, STR_704B_GENERATE_RANDOM_NEW_FACE}, // PFW_WIDGET_RANDOM_NEW_FACE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 95, 217, 16, 27, STR_FACE_SIMPLE, STR_FACE_SIMPLE_TIP}, // PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 2, 93, 158, 169, STR_FACE_LOAD, STR_FACE_LOAD_TIP}, // PFW_WIDGET_LOAD
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 2, 93, 170, 181, STR_FACE_FACECODE, STR_FACE_FACECODE_TIP}, // PFW_WIDGET_FACECODE
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 2, 93, 182, 193, STR_FACE_SAVE, STR_FACE_SAVE_TIP}, // PFW_WIDGET_SAVE
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 96, 156, 46, 57, STR_FACE_EUROPEAN, STR_FACE_SELECT_EUROPEAN}, // PFW_WIDGET_ETHNICITY_EUR
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 157, 217, 46, 57, STR_FACE_AFRICAN, STR_FACE_SELECT_AFRICAN}, // PFW_WIDGET_ETHNICITY_AFR
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 175, 217, 60, 71, STR_EMPTY, STR_FACE_MOUSTACHE_EARRING_TIP}, // PFW_WIDGET_HAS_MOUSTACHE_EARRING
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 175, 217, 72, 83, STR_EMPTY, STR_FACE_GLASSES_TIP}, // PFW_WIDGET_HAS_GLASSES
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 110, 121, SPR_ARROW_LEFT, STR_FACE_EYECOLOUR_TIP}, // PFW_WIDGET_EYECOLOUR_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 110, 121, STR_EMPTY, STR_FACE_EYECOLOUR_TIP}, // PFW_WIDGET_EYECOLOUR
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 110, 121, SPR_ARROW_RIGHT, STR_FACE_EYECOLOUR_TIP}, // PFW_WIDGET_EYECOLOUR_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 158, 169, SPR_ARROW_LEFT, STR_FACE_CHIN_TIP}, // PFW_WIDGET_CHIN_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 158, 169, STR_EMPTY, STR_FACE_CHIN_TIP}, // PFW_WIDGET_CHIN
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 158, 169, SPR_ARROW_RIGHT, STR_FACE_CHIN_TIP}, // PFW_WIDGET_CHIN_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 98, 109, SPR_ARROW_LEFT, STR_FACE_EYEBROWS_TIP}, // PFW_WIDGET_EYEBROWS_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 98, 109, STR_EMPTY, STR_FACE_EYEBROWS_TIP}, // PFW_WIDGET_EYEBROWS
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 98, 109, SPR_ARROW_RIGHT, STR_FACE_EYEBROWS_TIP}, // PFW_WIDGET_EYEBROWS_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 146, 157, SPR_ARROW_LEFT, STR_FACE_LIPS_MOUSTACHE_TIP}, // PFW_WIDGET_LIPS_MOUSTACHE_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 146, 157, STR_EMPTY, STR_FACE_LIPS_MOUSTACHE_TIP}, // PFW_WIDGET_LIPS_MOUSTACHE
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 146, 157, SPR_ARROW_RIGHT, STR_FACE_LIPS_MOUSTACHE_TIP}, // PFW_WIDGET_LIPS_MOUSTACHE_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 134, 145, SPR_ARROW_LEFT, STR_FACE_NOSE_TIP}, // PFW_WIDGET_NOSE_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 134, 145, STR_EMPTY, STR_FACE_NOSE_TIP}, // PFW_WIDGET_NOSE
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 134, 145, SPR_ARROW_RIGHT, STR_FACE_NOSE_TIP}, // PFW_WIDGET_NOSE_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 86, 97, SPR_ARROW_LEFT, STR_FACE_HAIR_TIP}, // PFW_WIDGET_HAIR_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 86, 97, STR_EMPTY, STR_FACE_HAIR_TIP}, // PFW_WIDGET_HAIR
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 86, 97, SPR_ARROW_RIGHT, STR_FACE_HAIR_TIP}, // PFW_WIDGET_HAIR_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 170, 181, SPR_ARROW_LEFT, STR_FACE_JACKET_TIP}, // PFW_WIDGET_JACKET_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 170, 181, STR_EMPTY, STR_FACE_JACKET_TIP}, // PFW_WIDGET_JACKET
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 170, 181, SPR_ARROW_RIGHT, STR_FACE_JACKET_TIP}, // PFW_WIDGET_JACKET_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 182, 193, SPR_ARROW_LEFT, STR_FACE_COLLAR_TIP}, // PFW_WIDGET_COLLAR_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 182, 193, STR_EMPTY, STR_FACE_COLLAR_TIP}, // PFW_WIDGET_COLLAR
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 182, 193, SPR_ARROW_RIGHT, STR_FACE_COLLAR_TIP}, // PFW_WIDGET_COLLAR_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 194, 205, SPR_ARROW_LEFT, STR_FACE_TIE_EARRING_TIP}, // PFW_WIDGET_TIE_EARRING_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 194, 205, STR_EMPTY, STR_FACE_TIE_EARRING_TIP}, // PFW_WIDGET_TIE_EARRING
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 194, 205, SPR_ARROW_RIGHT, STR_FACE_TIE_EARRING_TIP}, // PFW_WIDGET_TIE_EARRING_R
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 175, 183, 122, 133, SPR_ARROW_LEFT, STR_FACE_GLASSES_TIP_2}, // PFW_WIDGET_GLASSES_L
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 184, 208, 122, 133, STR_EMPTY, STR_FACE_GLASSES_TIP_2}, // PFW_WIDGET_GLASSES
+{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 209, 217, 122, 133, SPR_ARROW_RIGHT, STR_FACE_GLASSES_TIP_2}, // PFW_WIDGET_GLASSES_R
+{ WIDGETS_END},
+};
+
+/**
+ * Draw dynamic a label to the left of the button and a value in the button
+ *
+ * @param w Window on which the widget is located
+ * @param widget_index index of this widget in the window
+ * @param str the label which will be draw
+ * @param val the value which will be draw
+ * @param is_bool_widget is it a bool button
+ */
+void DrawFaceStringLabel(const Window *w, byte widget_index, StringID str, uint8 val, bool is_bool_widget)
+{
+ /* Write the label in gold (0x2) to the left of the button. */
+ DrawStringRightAligned(w->widget[widget_index].left - (is_bool_widget ? 5 : 14), w->widget[widget_index].top + 1, str, TC_GOLD);
+
+ if (!w->IsWidgetDisabled(widget_index)) {
+ if (is_bool_widget) {
+ /* if it a bool button write yes or no */
+ str = (val != 0) ? STR_FACE_YES : STR_FACE_NO;
+ } else {
+ /* else write the value + 1 */
+ SetDParam(0, val + 1);
+ str = STR_JUST_INT;
}
- break;
+
+ /* Draw the value/bool in white (0xC). If the button clicked adds 1px to x and y text coordinates (IsWindowWidgetLowered()). */
+ DrawStringCentered(w->widget[widget_index].left + (w->widget[widget_index].right - w->widget[widget_index].left) / 2 +
+ w->IsWidgetLowered(widget_index), w->widget[widget_index].top + 1 + w->IsWidgetLowered(widget_index), str, TC_WHITE);
}
}
-static const Widget _select_player_face_widgets[] = {
-{ 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},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 189, 14, 136, 0x0, STR_NULL},
-{ 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},
-{ WIDGETS_END},
-};
+/**
+ * Player face selection window event definition
+ *
+ * @param w window pointer
+ * @param e event been triggered
+ */
+static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
+{
+ PlayerFace *pf = &WP(w, facesel_d).face; // pointer to the player face bits
+ GenderEthnicity ge = (GenderEthnicity)GB(*pf, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // get the gender and ethnicity
+ bool is_female = HasBit(ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female
+ bool is_moust_male = !is_female && GetPlayerFaceBits(*pf, PFV_HAS_MOUSTACHE, ge) != 0; // is a male face with moustache
+ switch (e->event) {
+ case WE_PAINT:
+ /* lower the non-selected gender button */
+ w->SetWidgetLoweredState(PFW_WIDGET_MALE, !is_female);
+ w->SetWidgetLoweredState(PFW_WIDGET_FEMALE, is_female);
+
+ /* advanced player face selection window */
+ if (WP(w, facesel_d).advanced) {
+ /* lower the non-selected ethnicity button */
+ w->SetWidgetLoweredState(PFW_WIDGET_ETHNICITY_EUR, !HasBit(ge, ETHNICITY_BLACK));
+ w->SetWidgetLoweredState(PFW_WIDGET_ETHNICITY_AFR, HasBit(ge, ETHNICITY_BLACK));
+
+
+ /* Disable dynamically the widgets which PlayerFaceVariable has less than 2 options
+ * (or in other words you haven't any choice).
+ * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
+
+ /* Eye colour buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_EYE_COLOUR].valid_values[ge] < 2,
+ PFW_WIDGET_EYECOLOUR, PFW_WIDGET_EYECOLOUR_L, PFW_WIDGET_EYECOLOUR_R, WIDGET_LIST_END);
+
+ /* Chin buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_CHIN].valid_values[ge] < 2,
+ PFW_WIDGET_CHIN, PFW_WIDGET_CHIN_L, PFW_WIDGET_CHIN_R, WIDGET_LIST_END);
+
+ /* Eyebrows buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_EYEBROWS].valid_values[ge] < 2,
+ PFW_WIDGET_EYEBROWS, PFW_WIDGET_EYEBROWS_L, PFW_WIDGET_EYEBROWS_R, WIDGET_LIST_END);
+
+ /* Lips or (if it a male face with a moustache) moustache buttons */
+ w->SetWidgetsDisabledState(_pf_info[is_moust_male ? PFV_MOUSTACHE : PFV_LIPS].valid_values[ge] < 2,
+ PFW_WIDGET_LIPS_MOUSTACHE, PFW_WIDGET_LIPS_MOUSTACHE_L, PFW_WIDGET_LIPS_MOUSTACHE_R, WIDGET_LIST_END);
+
+ /* Nose buttons | male faces with moustache haven't any nose options */
+ w->SetWidgetsDisabledState(_pf_info[PFV_NOSE].valid_values[ge] < 2 || is_moust_male,
+ PFW_WIDGET_NOSE, PFW_WIDGET_NOSE_L, PFW_WIDGET_NOSE_R, WIDGET_LIST_END);
+
+ /* Hair buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_HAIR].valid_values[ge] < 2,
+ PFW_WIDGET_HAIR, PFW_WIDGET_HAIR_L, PFW_WIDGET_HAIR_R, WIDGET_LIST_END);
+
+ /* Jacket buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_JACKET].valid_values[ge] < 2,
+ PFW_WIDGET_JACKET, PFW_WIDGET_JACKET_L, PFW_WIDGET_JACKET_R, WIDGET_LIST_END);
+
+ /* Collar buttons */
+ w->SetWidgetsDisabledState(_pf_info[PFV_COLLAR].valid_values[ge] < 2,
+ PFW_WIDGET_COLLAR, PFW_WIDGET_COLLAR_L, PFW_WIDGET_COLLAR_R, WIDGET_LIST_END);
+
+ /* Tie/earring buttons | female faces without earring haven't any earring options */
+ w->SetWidgetsDisabledState(_pf_info[PFV_TIE_EARRING].valid_values[ge] < 2 ||
+ (is_female && GetPlayerFaceBits(*pf, PFV_HAS_TIE_EARRING, ge) == 0),
+ PFW_WIDGET_TIE_EARRING, PFW_WIDGET_TIE_EARRING_L, PFW_WIDGET_TIE_EARRING_R, WIDGET_LIST_END);
+
+ /* Glasses buttons | faces without glasses haven't any glasses options */
+ w->SetWidgetsDisabledState(_pf_info[PFV_GLASSES].valid_values[ge] < 2 || GetPlayerFaceBits(*pf, PFV_HAS_GLASSES, ge) == 0,
+ PFW_WIDGET_GLASSES, PFW_WIDGET_GLASSES_L, PFW_WIDGET_GLASSES_R, WIDGET_LIST_END);
+ }
+
+ DrawWindowWidgets(w);
+
+ /* Draw dynamic button value and labels for the advanced player face selection window */
+ if (WP(w, facesel_d).advanced) {
+ if (is_female) {
+ /* Only for female faces */
+ DrawFaceStringLabel(w, PFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_EARRING, GetPlayerFaceBits(*pf, PFV_HAS_TIE_EARRING, ge), true );
+ DrawFaceStringLabel(w, PFW_WIDGET_TIE_EARRING, STR_FACE_EARRING, GetPlayerFaceBits(*pf, PFV_TIE_EARRING, ge), false);
+ } else {
+ /* Only for male faces */
+ DrawFaceStringLabel(w, PFW_WIDGET_HAS_MOUSTACHE_EARRING, STR_FACE_MOUSTACHE, GetPlayerFaceBits(*pf, PFV_HAS_MOUSTACHE, ge), true );
+ DrawFaceStringLabel(w, PFW_WIDGET_TIE_EARRING, STR_FACE_TIE, GetPlayerFaceBits(*pf, PFV_TIE_EARRING, ge), false);
+ }
+ if (is_moust_male) {
+ /* Only for male faces with moustache */
+ DrawFaceStringLabel(w, PFW_WIDGET_LIPS_MOUSTACHE, STR_FACE_MOUSTACHE, GetPlayerFaceBits(*pf, PFV_MOUSTACHE, ge), false);
+ } else {
+ /* Only for female faces or male faces without moustache */
+ DrawFaceStringLabel(w, PFW_WIDGET_LIPS_MOUSTACHE, STR_FACE_LIPS, GetPlayerFaceBits(*pf, PFV_LIPS, ge), false);
+ }
+ /* For all faces */
+ DrawFaceStringLabel(w, PFW_WIDGET_HAS_GLASSES, STR_FACE_GLASSES, GetPlayerFaceBits(*pf, PFV_HAS_GLASSES, ge), true );
+ DrawFaceStringLabel(w, PFW_WIDGET_HAIR, STR_FACE_HAIR, GetPlayerFaceBits(*pf, PFV_HAIR, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_EYEBROWS, STR_FACE_EYEBROWS, GetPlayerFaceBits(*pf, PFV_EYEBROWS, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_EYECOLOUR, STR_FACE_EYECOLOUR, GetPlayerFaceBits(*pf, PFV_EYE_COLOUR, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_GLASSES, STR_FACE_GLASSES, GetPlayerFaceBits(*pf, PFV_GLASSES, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_NOSE, STR_FACE_NOSE, GetPlayerFaceBits(*pf, PFV_NOSE, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_CHIN, STR_FACE_CHIN, GetPlayerFaceBits(*pf, PFV_CHIN, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_JACKET, STR_FACE_JACKET, GetPlayerFaceBits(*pf, PFV_JACKET, ge), false);
+ DrawFaceStringLabel(w, PFW_WIDGET_COLLAR, STR_FACE_COLLAR, GetPlayerFaceBits(*pf, PFV_COLLAR, ge), false);
+ }
+
+ /* Draw the player face picture */
+ DrawPlayerFace(*pf, GetPlayer((PlayerID)w->window_number)->player_color, 2, 16);
+ break;
+
+ case WE_CLICK:
+ switch (e->we.click.widget) {
+ /* Toggle size, advanced/simple face selection */
+ case PFW_WIDGET_TOGGLE_LARGE_SMALL:
+ case PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON:
+ DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE);
+ DeleteWindow(w);
+ DoSelectPlayerFace((PlayerID)w->window_number, !WP(w, facesel_d).advanced);
+ break;
+
+ /* Cancel button */
+ case PFW_WIDGET_CANCEL:
+ DeleteWindow(w);
+ break;
+
+ /* OK button */
+ case PFW_WIDGET_ACCEPT:
+ DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE);
+ DeleteWindow(w);
+ break;
+
+ /* Load button */
+ case PFW_WIDGET_LOAD:
+ *pf = _player_face;
+ ScaleAllPlayerFaceBits(*pf);
+ ShowErrorMessage(INVALID_STRING_ID, STR_FACE_LOAD_DONE, 0, 0);
+ SetWindowDirty(w);
+ break;
+
+ /* 'Player face number' button, view and/or set player face number */
+ case PFW_WIDGET_FACECODE:
+ SetDParam(0, *pf);
+ ShowQueryString(STR_JUST_INT, STR_FACE_FACECODE_CAPTION, 10 + 1, 0, w, CS_NUMERAL);
+ break;
+
+ /* Save button */
+ case PFW_WIDGET_SAVE:
+ _player_face = *pf;
+ ShowErrorMessage(INVALID_STRING_ID, STR_FACE_SAVE_DONE, 0, 0);
+ break;
+
+ /* Toggle gender (male/female) button */
+ case PFW_WIDGET_MALE:
+ case PFW_WIDGET_FEMALE:
+ SetPlayerFaceBits(*pf, PFV_GENDER, ge, e->we.click.widget - PFW_WIDGET_MALE);
+ ScaleAllPlayerFaceBits(*pf);
+ SetWindowDirty(w);
+ break;
+
+ /* Randomize face button */
+ case PFW_WIDGET_RANDOM_NEW_FACE:
+ RandomPlayerFaceBits(*pf, ge, WP(w, facesel_d).advanced);
+ SetWindowDirty(w);
+ break;
+
+ /* Toggle ethnicity (european/african) button */
+ case PFW_WIDGET_ETHNICITY_EUR:
+ case PFW_WIDGET_ETHNICITY_AFR:
+ SetPlayerFaceBits(*pf, PFV_ETHNICITY, ge, e->we.click.widget - PFW_WIDGET_ETHNICITY_EUR);
+ ScaleAllPlayerFaceBits(*pf);
+ SetWindowDirty(w);
+ break;
+
+ default:
+ /* For all buttons from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R is the same function.
+ * Therefor is this combined function.
+ * First it checks which PlayerFaceVariable will be change and then
+ * a: invert the value for boolean variables
+ * or b: it checks inside of IncreasePlayerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
+ if (WP(w, facesel_d).advanced && e->we.click.widget >= PFW_WIDGET_HAS_MOUSTACHE_EARRING && e->we.click.widget <= PFW_WIDGET_GLASSES_R) {
+ PlayerFaceVariable pfv; // which PlayerFaceVariable shall be edited
+
+ if (e->we.click.widget < PFW_WIDGET_EYECOLOUR_L) { // Bool buttons
+ switch (e->we.click.widget - PFW_WIDGET_HAS_MOUSTACHE_EARRING) {
+ default: NOT_REACHED();
+ case 0: pfv = is_female ? PFV_HAS_TIE_EARRING : PFV_HAS_MOUSTACHE; break; // Has earring/moustache button
+ case 1: pfv = PFV_HAS_GLASSES; break; // Has glasses button
+ }
+ SetPlayerFaceBits(*pf, pfv, ge, !GetPlayerFaceBits(*pf, pfv, ge));
+ ScaleAllPlayerFaceBits(*pf);
+
+ } else { // Value buttons
+ switch ((e->we.click.widget - PFW_WIDGET_EYECOLOUR_L) / 3) {
+ default: NOT_REACHED();
+ case 0: pfv = PFV_EYE_COLOUR; break; // Eye colour buttons
+ case 1: pfv = PFV_CHIN; break; // Chin buttons
+ case 2: pfv = PFV_EYEBROWS; break; // Eyebrows buttons
+ case 3: pfv = is_moust_male ? PFV_MOUSTACHE : PFV_LIPS; break; // Moustache or lips buttons
+ case 4: pfv = PFV_NOSE; break; // Nose buttons
+ case 5: pfv = PFV_HAIR; break; // Hair buttons
+ case 6: pfv = PFV_JACKET; break; // Jacket buttons
+ case 7: pfv = PFV_COLLAR; break; // Collar buttons
+ case 8: pfv = PFV_TIE_EARRING; break; // Tie/earring buttons
+ case 9: pfv = PFV_GLASSES; break; // Glasses buttons
+ }
+ /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
+ IncreasePlayerFaceBits(*pf, pfv, ge, (((e->we.click.widget - PFW_WIDGET_EYECOLOUR_L) % 3) != 0) ? 1 : -1);
+ }
+
+ SetWindowDirty(w);
+ }
+ break;
+ }
+ break;
+
+ case WE_ON_EDIT_TEXT:
+ /* Set a new player face number */
+ if (!StrEmpty(e->we.edittext.str)) {
+ *pf = strtoul(e->we.edittext.str, NULL, 10);
+ ScaleAllPlayerFaceBits(*pf);
+ ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0);
+ SetWindowDirty(w);
+ } else {
+ ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_ERR, 0, 0);
+ }
+ break;
+ }
+}
+
+/** normal/simple player face selection window description */
static const WindowDesc _select_player_face_desc = {
- WDP_AUTO, WDP_AUTO, 190, 149, 190, 149,
+ WDP_AUTO, WDP_AUTO, 190, 163, 190, 163,
WC_PLAYER_FACE, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_select_player_face_widgets,
SelectPlayerFaceWndProc
};
+/** advanced player face selection window description */
+static const WindowDesc _select_player_face_adv_desc = {
+ WDP_AUTO, WDP_AUTO, 220, 220, 220, 220,
+ WC_PLAYER_FACE, WC_NONE,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+ _select_player_face_adv_widgets,
+ SelectPlayerFaceWndProc
+};
+
+/**
+ * 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
+ *
+ * @pre is player a valid player
+ */
+static void DoSelectPlayerFace(PlayerID player, bool adv)
+{
+ if (!IsValidPlayer(player)) return;
+
+ Window *w = AllocateWindowDescFront(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, player); // simple or advanced window
+
+ if (w != NULL) {
+ w->caption_color = w->window_number;
+ WP(w, facesel_d).face = GetPlayer((PlayerID)w->window_number)->face;
+ WP(w, facesel_d).advanced = adv;
+ }
+}
+
+
/* Names of the widgets. Keep them in the same order as in the widget array */
enum PlayerCompanyWindowWidgets {
PCW_WIDGET_CLOSEBOX = 0,
@@ -602,17 +976,22 @@
{ WIDGETS_END},
};
+
+/**
+ * Draws text "Vehicles:" and number of all vehicle types, or "(none)"
+ * @param player ID of player to print statistics of
+ */
static void DrawPlayerVehiclesAmount(PlayerID player)
{
const int x = 110;
- int y = 72;
+ int y = 63;
const Vehicle *v;
uint train = 0;
uint road = 0;
uint air = 0;
uint ship = 0;
- DrawString(x, y, STR_7039_VEHICLES, 0);
+ DrawString(x, y, STR_7039_VEHICLES, TC_FROMSTRING);
FOR_ALL_VEHICLES(v) {
if (v->owner == player) {
@@ -627,29 +1006,29 @@
}
if (train + road + air + ship == 0) {
- DrawString(x + 70, y, STR_7042_NONE, 0);
+ DrawString(x + 70, y, STR_7042_NONE, TC_FROMSTRING);
} else {
if (train != 0) {
SetDParam(0, train);
- DrawString(x + 70, y, STR_TRAINS, 0);
+ DrawString(x + 70, y, STR_TRAINS, TC_FROMSTRING);
y += 10;
}
if (road != 0) {
SetDParam(0, road);
- DrawString(x + 70, y, STR_ROAD_VEHICLES, 0);
+ DrawString(x + 70, y, STR_ROAD_VEHICLES, TC_FROMSTRING);
y += 10;
}
if (air != 0) {
SetDParam(0, air);
- DrawString(x + 70, y, STR_AIRCRAFT, 0);
+ DrawString(x + 70, y, STR_AIRCRAFT, TC_FROMSTRING);
y += 10;
}
if (ship != 0) {
SetDParam(0, ship);
- DrawString(x + 70, y, STR_SHIPS, 0);
+ DrawString(x + 70, y, STR_SHIPS, TC_FROMSTRING);
}
}
}
@@ -662,26 +1041,33 @@
(p->share_owners[3] == owner);
}
+/**
+ * Draws list of all companies with shares
+ * @param p pointer to the Player structure
+ */
static void DrawCompanyOwnerText(const Player *p)
{
const Player *p2;
- int num = -1;
+ uint num = 0;
+ const byte height = GetCharacterHeight(FS_NORMAL);
FOR_ALL_PLAYERS(p2) {
uint amt = GetAmountOwnedBy(p, p2->index);
if (amt != 0) {
- num++;
+ SetDParam(0, amt * 25);
+ SetDParam(1, p2->index);
- SetDParam(num * 2 + 0, amt * 25);
- SetDParam(num * 2 + 1, p2->index);
-
- if (num != 0) break;
+ DrawString(120, (num++) * height + 116, STR_707D_OWNED_BY, TC_FROMSTRING);
}
}
-
- if (num >= 0) DrawString(120, 124, STR_707D_OWNED_BY + num, 0);
}
+/**
+ * Player company window event definition
+ *
+ * @param w window pointer
+ * @param e event been triggered
+ */
static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -689,34 +1075,34 @@
const Player *p = GetPlayer((PlayerID)w->window_number);
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->SetWidgetHiddenState(PCW_WIDGET_NEW_FACE, !local);
+ w->SetWidgetHiddenState(PCW_WIDGET_COLOR_SCHEME, !local);
+ w->SetWidgetHiddenState(PCW_WIDGET_PRESIDENT_NAME, !local);
+ w->SetWidgetHiddenState(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;
if (local && p->location_of_house != 0) w->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built.
- 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);
+ w->SetWidgetDisabledState(PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0);
+ w->SetWidgetHiddenState(PCW_WIDGET_RELOCATE_HQ, !local || p->location_of_house == 0);
+ w->SetWidgetHiddenState(PCW_WIDGET_BUY_SHARE, local);
+ w->SetWidgetHiddenState(PCW_WIDGET_SELL_SHARE, local);
+ w->SetWidgetHiddenState(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 */
- SetWindowWidgetDisabledState(w, PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 ||
+ w->SetWidgetDisabledState(PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 ||
/* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
(GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) ||
/* Spectators cannot do anything of course */
_local_player == PLAYER_SPECTATOR);
/* If the player doesn't own any shares, disable sell button */
- SetWindowWidgetDisabledState(w, PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) ||
+ w->SetWidgetDisabledState(PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) ||
/* Spectators cannot do anything of course */
_local_player == PLAYER_SPECTATOR);
} else { // Shares are not allowed, disable buy/sell buttons
- DisableWindowWidget(w, PCW_WIDGET_BUY_SHARE);
- DisableWindowWidget(w, PCW_WIDGET_SELL_SHARE);
+ w->DisableWidget(PCW_WIDGET_BUY_SHARE);
+ w->DisableWidget(PCW_WIDGET_SELL_SHARE);
}
}
@@ -725,23 +1111,30 @@
DrawWindowWidgets(w);
- SetDParam(0, p->inaugurated_year);
- DrawString(110, 25, STR_7038_INAUGURATED, 0);
-
- DrawPlayerVehiclesAmount((PlayerID)w->window_number);
-
- DrawString(110, 48, STR_7006_COLOR_SCHEME, 0);
- /* Draw company-colour bus */
- DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 49);
-
+ /* Player face */
DrawPlayerFace(p->face, p->player_color, 2, 16);
+ /* "xxx (Manager)" */
SetDParam(0, p->index);
DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
+ /* "Inaugurated:" */
+ SetDParam(0, p->inaugurated_year);
+ DrawString(110, 23, STR_7038_INAUGURATED, TC_FROMSTRING);
+
+ /* "Colour scheme:" */
+ DrawString(110, 43, STR_7006_COLOR_SCHEME, TC_FROMSTRING);
+ /* Draw company-colour bus */
+ DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 44);
+
+ /* "Vehicles:" */
+ DrawPlayerVehiclesAmount((PlayerID)w->window_number);
+
+ /* "Company value:" */
SetDParam(0, CalculateCompanyValue(p));
- DrawString(110, 114, STR_7076_COMPANY_VALUE, 0);
+ DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING);
+ /* Shares list */
DrawCompanyOwnerText(p);
break;
@@ -749,15 +1142,7 @@
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;
- WP(wf, facesel_d).face = GetPlayer((PlayerID)wf->window_number)->face;
- WP(wf, facesel_d).gender = 0;
- }
- break;
- }
+ case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)w->window_number, false); break;
case PCW_WIDGET_COLOR_SCHEME: {
Window *wf = AllocateWindowDescFront(_loaded_newgrf_features.has_2CC ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
@@ -765,7 +1150,7 @@
wf->caption_color = wf->window_number;
WP(wf, livery_d).livery_class = LC_OTHER;
WP(wf, livery_d).sel = 1;
- LowerWindowWidget(wf, 2);
+ wf->LowerWidget(2);
}
break;
}
@@ -791,9 +1176,9 @@
if (tile == 0) {
if ((byte)w->window_number != _local_player)
return;
- SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
+ SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w);
SetTileSelectSize(2, 2);
- LowerWindowWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
+ w->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ);
InvalidateWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
} else {
ScrollMainWindowToTile(tile);
@@ -802,9 +1187,9 @@
}
case PCW_WIDGET_RELOCATE_HQ:
- SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
+ SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w);
SetTileSelectSize(2, 2);
- LowerWindowWidget(w, PCW_WIDGET_RELOCATE_HQ);
+ w->LowerWidget(PCW_WIDGET_RELOCATE_HQ);
InvalidateWidget(w, PCW_WIDGET_RELOCATE_HQ);
break;
@@ -816,15 +1201,11 @@
DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
break;
- #ifdef ENABLE_NETWORK
+#ifdef ENABLE_NETWORK
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),
- STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w, CS_ALPHANUMERAL);
- }
+ if (w->window_number == _local_player) ShowNetworkCompanyPasswordWindow();
break;
- #endif /* ENABLE_NETWORK */
+#endif /* ENABLE_NETWORK */
}
break;
@@ -846,15 +1227,13 @@
case WE_DESTROY:
DeleteWindowById(WC_PLAYER_FACE, w->window_number);
+ if (w->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
break;
- case WE_ON_EDIT_TEXT: {
- char *b = e->we.edittext.str;
+ case WE_ON_EDIT_TEXT:
+ if (StrEmpty(e->we.edittext.str)) return;
- /* empty string is allowed for password */
- if (*b == '\0' && WP(w, def_d).byte_1 != 2) return;
-
- _cmd_text = b;
+ _cmd_text = e->we.edittext.str;
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));
@@ -862,15 +1241,8 @@
case 1: /* Change company name */
DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
break;
- #ifdef ENABLE_NETWORK
- case 2: /* Change company password */
- if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
- NetworkChangeCompanyPassword(1, &b);
- break;
- #endif /* ENABLE_NETWORK */
}
break;
- }
}
}
@@ -1025,10 +1397,10 @@
/* 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);
+ DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK);
if (hs[i].company[0] != '\0') {
- uint16 colour = (WP(w, highscore_d).rank == (int8)i) ? 0x3 : 0x10; // draw new highscore in red
+ TextColour colour = (WP(w, highscore_d).rank == (int8)i) ? TC_RED : TC_BLACK; // draw new highscore in red
DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour);
SetDParam(0, hs[i].title);