(svn r18317) -Codechange: Merge both face windows into a single window description and widget parts array.

pull/155/head
alberth 15 years ago
parent 87b9be8ef4
commit ea6e621024

@ -40,7 +40,7 @@ enum {
EXP_BLOCKSPACE = 10, ///< Amount of vertical space between two blocks of numbers.
};
static void DoSelectCompanyManagerFace(Window *parent, bool show_big, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
static void DoSelectCompanyManagerFace(Window *parent);
/** Standard unsorted list of expenses. */
static ExpensesType _expenses_list_1[] = {
@ -877,8 +877,10 @@ enum SelectCompanyManagerFaceWidgets {
SCMFW_WIDGET_SELECT_FACE,
SCMFW_WIDGET_CANCEL,
SCMFW_WIDGET_ACCEPT,
SCMFW_WIDGET_MALE,
SCMFW_WIDGET_FEMALE,
SCMFW_WIDGET_MALE, ///< Male button in the simple view.
SCMFW_WIDGET_FEMALE, ///< Female button in the simple view.
SCMFW_WIDGET_MALE2, ///< Male button in the advanced view.
SCMFW_WIDGET_FEMALE2, ///< Female button in the advanced view.
SCMFW_WIDGET_SEL_LOADSAVE, ///< Selection to display the load/save/number buttons in the advanced view.
SCMFW_WIDGET_SEL_MALEFEMALE, ///< Selection to display the male/female buttons in the simple view.
SCMFW_WIDGET_SEL_PARTS, ///< Selection to display the buttons for setting each part of the face in the advanced view.
@ -936,7 +938,7 @@ enum SelectCompanyManagerFaceWidgets {
SCMFW_WIDGET_GLASSES_R,
};
/** Nested widget description for the normal/simple company manager face selection dialog */
/** Nested widget description for the company manager face selection dialog */
static const NWidgetPart _nested_select_company_manager_face_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
@ -954,6 +956,15 @@ static const NWidgetPart _nested_select_company_manager_face_widgets[] = {
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_RANDOM_NEW_FACE), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON, STR_FACE_NEW_FACE_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, SCMFW_WIDGET_SEL_LOADSAVE), // Load/number/save buttons under the portrait in the advanced view.
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 5), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_LOAD), SetFill(1, 0), SetDataTip(STR_FACE_LOAD, STR_FACE_LOAD_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_FACECODE), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE, STR_FACE_FACECODE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_SAVE), SetFill(1, 0), SetDataTip(STR_FACE_SAVE, STR_FACE_SAVE_TOOLTIP),
NWidget(NWID_SPACER), SetMinimalSize(0, 5), SetFill(0, 1),
EndContainer(),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP),
@ -966,52 +977,12 @@ static const NWidgetPart _nested_select_company_manager_face_widgets[] = {
NWidget(NWID_SPACER), SetFill(0, 1),
EndContainer(),
EndContainer(),
EndContainer(),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_FACE_CANCEL_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_ACCEPT), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_FACE_OK_TOOLTIP),
EndContainer(),
};
/** Nested widget description for the advanced company manager face selection dialog */
static const NWidgetPart _nested_select_company_manager_face_adv_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, SCMFW_WIDGET_CAPTION), SetDataTip(STR_FACE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_IMGBTN, COLOUR_GREY, SCMFW_WIDGET_TOGGLE_LARGE_SMALL), SetDataTip(SPR_LARGE_SMALL_WINDOW, STR_FACE_SIMPLE_TOOLTIP),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, SCMFW_WIDGET_SELECT_FACE),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(NWID_HORIZONTAL), SetPIP(2, 2, 2),
NWidget(NWID_VERTICAL),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(WWT_EMPTY, COLOUR_GREY, SCMFM_WIDGET_FACE), SetMinimalSize(92, 119),
NWidget(NWID_SPACER), SetFill(1, 0),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_RANDOM_NEW_FACE), SetFill(1, 0), SetDataTip(STR_MAPGEN_RANDOM, STR_FACE_NEW_FACE_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, SCMFW_WIDGET_SEL_LOADSAVE), // Load/number/save buttons under the portrait in the advanced view.
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 5), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_LOAD), SetFill(1, 0), SetDataTip(STR_FACE_LOAD, STR_FACE_LOAD_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_FACECODE), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE, STR_FACE_FACECODE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_SAVE), SetFill(1, 0), SetDataTip(STR_FACE_SAVE, STR_FACE_SAVE_TOOLTIP),
NWidget(NWID_SPACER), SetMinimalSize(0, 5), SetFill(0, 1),
EndContainer(),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON), SetFill(1, 0), SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP),
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidget(NWID_SELECTION, INVALID_COLOUR, SCMFW_WIDGET_SEL_PARTS), // Advanced face parts setting.
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_TEXTBTN, COLOUR_GREY, SCMFW_WIDGET_MALE), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, SCMFW_WIDGET_FEMALE), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, SCMFW_WIDGET_MALE2), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON, STR_FACE_MALE_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, SCMFW_WIDGET_FEMALE2), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON, STR_FACE_FEMALE_TOOLTIP),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
@ -1149,9 +1120,9 @@ class SelectCompanyManagerFaceWindow : public Window
}
public:
SelectCompanyManagerFaceWindow(const WindowDesc *desc, Window *parent, bool advanced, int top, int left) : Window()
SelectCompanyManagerFaceWindow(const WindowDesc *desc, Window *parent) : Window()
{
this->advanced = advanced;
this->advanced = false;
this->CreateNestedTree(desc);
this->SelectDisplayPlanes(this->advanced);
this->FinishInitNested(desc, parent->window_number);
@ -1160,12 +1131,6 @@ public:
this->face = Company::Get((CompanyID)this->window_number)->face;
this->UpdateData();
/* Check if repositioning from default is required */
if (top != FIRST_GUI_CALL && left != FIRST_GUI_CALL) {
this->top = top;
this->left = left;
}
}
/** Select planes to display to the user with the #NWID_SELECTION widgets #SCMFW_WIDGET_SEL_LOADSAVE, #SCMFW_WIDGET_SEL_MALEFEMALE, and #SCMFW_WIDGET_SEL_PARTS.
@ -1173,11 +1138,16 @@ public:
*/
void SelectDisplayPlanes(bool advanced)
{
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : STACKED_SELECTION_ZERO_SIZE);
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : STACKED_SELECTION_ZERO_SIZE);
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? STACKED_SELECTION_ZERO_SIZE : 0);
this->GetWidget<NWidgetCore>(SCMFW_WIDGET_RANDOM_NEW_FACE)->widget_data = advanced ? STR_MAPGEN_RANDOM : STR_FACE_NEW_FACE_BUTTON;
NWidgetCore *wi = this->GetWidget<NWidgetCore>(SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON);
if (advanced) {
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_LOADSAVE)->SetDisplayedPlane(0);
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_PARTS)->SetDisplayedPlane(0);
wi->SetDataTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
} else {
this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_MALEFEMALE)->SetDisplayedPlane(0);
wi->SetDataTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
}
}
@ -1255,61 +1225,60 @@ public:
virtual void OnPaint()
{
/* lower the non-selected gender button */
this->SetWidgetLoweredState(SCMFW_WIDGET_MALE, !this->is_female);
this->SetWidgetLoweredState(SCMFW_WIDGET_FEMALE, this->is_female);
this->SetWidgetsLoweredState(!this->is_female, SCMFW_WIDGET_MALE, SCMFW_WIDGET_MALE2, WIDGET_LIST_END);
this->SetWidgetsLoweredState( this->is_female, SCMFW_WIDGET_FEMALE, SCMFW_WIDGET_FEMALE2, WIDGET_LIST_END);
/* advanced company manager face selection window */
if (this->advanced) {
/* lower the non-selected ethnicity button */
this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_AFR, HasBit(this->ge, ETHNICITY_BLACK));
/* lower the non-selected ethnicity button */
this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_EUR, !HasBit(this->ge, ETHNICITY_BLACK));
this->SetWidgetLoweredState(SCMFW_WIDGET_ETHNICITY_AFR, HasBit(this->ge, ETHNICITY_BLACK));
/* Disable dynamically the widgets which CompanyManagerFaceVariable 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 */
this->SetWidgetsDisabledState(_cmf_info[CMFV_EYE_COLOUR].valid_values[this->ge] < 2,
/* Disable dynamically the widgets which CompanyManagerFaceVariable 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 */
this->SetWidgetsDisabledState(_cmf_info[CMFV_EYE_COLOUR].valid_values[this->ge] < 2,
SCMFW_WIDGET_EYECOLOUR, SCMFW_WIDGET_EYECOLOUR_L, SCMFW_WIDGET_EYECOLOUR_R, WIDGET_LIST_END);
/* Chin buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_CHIN].valid_values[this->ge] < 2,
/* Chin buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_CHIN].valid_values[this->ge] < 2,
SCMFW_WIDGET_CHIN, SCMFW_WIDGET_CHIN_L, SCMFW_WIDGET_CHIN_R, WIDGET_LIST_END);
/* Eyebrows buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_EYEBROWS].valid_values[this->ge] < 2,
/* Eyebrows buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_EYEBROWS].valid_values[this->ge] < 2,
SCMFW_WIDGET_EYEBROWS, SCMFW_WIDGET_EYEBROWS_L, SCMFW_WIDGET_EYEBROWS_R, WIDGET_LIST_END);
/* Lips or (if it a male face with a moustache) moustache buttons */
this->SetWidgetsDisabledState(_cmf_info[this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS].valid_values[this->ge] < 2,
/* Lips or (if it a male face with a moustache) moustache buttons */
this->SetWidgetsDisabledState(_cmf_info[this->is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS].valid_values[this->ge] < 2,
SCMFW_WIDGET_LIPS_MOUSTACHE, SCMFW_WIDGET_LIPS_MOUSTACHE_L, SCMFW_WIDGET_LIPS_MOUSTACHE_R, WIDGET_LIST_END);
/* Nose buttons | male faces with moustache haven't any nose options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
/* Nose buttons | male faces with moustache haven't any nose options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_NOSE].valid_values[this->ge] < 2 || this->is_moust_male,
SCMFW_WIDGET_NOSE, SCMFW_WIDGET_NOSE_L, SCMFW_WIDGET_NOSE_R, WIDGET_LIST_END);
/* Hair buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_HAIR].valid_values[this->ge] < 2,
/* Hair buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_HAIR].valid_values[this->ge] < 2,
SCMFW_WIDGET_HAIR, SCMFW_WIDGET_HAIR_L, SCMFW_WIDGET_HAIR_R, WIDGET_LIST_END);
/* Jacket buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_JACKET].valid_values[this->ge] < 2,
/* Jacket buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_JACKET].valid_values[this->ge] < 2,
SCMFW_WIDGET_JACKET, SCMFW_WIDGET_JACKET_L, SCMFW_WIDGET_JACKET_R, WIDGET_LIST_END);
/* Collar buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_COLLAR].valid_values[this->ge] < 2,
/* Collar buttons */
this->SetWidgetsDisabledState(_cmf_info[CMFV_COLLAR].valid_values[this->ge] < 2,
SCMFW_WIDGET_COLLAR, SCMFW_WIDGET_COLLAR_L, SCMFW_WIDGET_COLLAR_R, WIDGET_LIST_END);
/* Tie/earring buttons | female faces without earring haven't any earring options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_TIE_EARRING].valid_values[this->ge] < 2 ||
/* Tie/earring buttons | female faces without earring haven't any earring options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_TIE_EARRING].valid_values[this->ge] < 2 ||
(this->is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_TIE_EARRING, this->ge) == 0),
SCMFW_WIDGET_TIE_EARRING, SCMFW_WIDGET_TIE_EARRING_L, SCMFW_WIDGET_TIE_EARRING_R, WIDGET_LIST_END);
/* Glasses buttons | faces without glasses haven't any glasses options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_GLASSES].valid_values[this->ge] < 2 || GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge) == 0,
/* Glasses buttons | faces without glasses haven't any glasses options */
this->SetWidgetsDisabledState(_cmf_info[CMFV_GLASSES].valid_values[this->ge] < 2 || GetCompanyManagerFaceBits(this->face, CMFV_HAS_GLASSES, this->ge) == 0,
SCMFW_WIDGET_GLASSES, SCMFW_WIDGET_GLASSES_L, SCMFW_WIDGET_GLASSES_R, WIDGET_LIST_END);
}
this->DrawWidgets();
}
@ -1412,21 +1381,11 @@ public:
switch (widget) {
/* Toggle size, advanced/simple face selection */
case SCMFW_WIDGET_TOGGLE_LARGE_SMALL:
case SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: {
DoCommandP(0, 0, this->face, CMD_SET_COMPANY_MANAGER_FACE);
/* Backup some data before deletion */
int oldtop = this->top; ///< current top position of the window before closing it
int oldleft = this->left; ///< current top position of the window before closing it
bool adv = !this->advanced;
Window *parent = this->parent;
delete this;
/* Open up the (toggled size) Face selection window at the same position as the previous */
DoSelectCompanyManagerFace(parent, adv, oldtop, oldleft);
} break;
case SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON:
this->advanced = !this->advanced;
this->SelectDisplayPlanes(this->advanced);
this->ReInit();
break;
/* OK button */
case SCMFW_WIDGET_ACCEPT:
@ -1462,7 +1421,9 @@ public:
/* Toggle gender (male/female) button */
case SCMFW_WIDGET_MALE:
case SCMFW_WIDGET_FEMALE:
SetCompanyManagerFaceBits(this->face, CMFV_GENDER, this->ge, widget - SCMFW_WIDGET_MALE);
case SCMFW_WIDGET_MALE2:
case SCMFW_WIDGET_FEMALE2:
SetCompanyManagerFaceBits(this->face, CMFV_GENDER, this->ge, (widget == SCMFW_WIDGET_FEMALE || widget == SCMFW_WIDGET_FEMALE2));
ScaleAllCompanyManagerFaceBits(this->face);
this->UpdateData();
this->SetDirty();
@ -1489,7 +1450,7 @@ public:
* First it checks which CompanyManagerFaceVariable is being changed, and then either
* a: invert the value for boolean variables, or
* b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
if (this->advanced && widget >= SCMFW_WIDGET_HAS_MOUSTACHE_EARRING && widget <= SCMFW_WIDGET_GLASSES_R) {
if (widget >= SCMFW_WIDGET_HAS_MOUSTACHE_EARRING && widget <= SCMFW_WIDGET_GLASSES_R) {
CompanyManagerFaceVariable cmfv; // which CompanyManagerFaceVariable shall be edited
if (widget < SCMFW_WIDGET_EYECOLOUR_L) { // Bool buttons
@ -1559,7 +1520,7 @@ const StringID SelectCompanyManagerFaceWindow::PART_TEXTS[] = {
STR_FACE_COLLAR, // SCMFW_WIDGET_COLLAR_TEXT
};
/** normal/simple company manager face selection window description */
/** Company manager face selection window description */
static const WindowDesc _select_company_manager_face_desc(
WDP_AUTO, WDP_AUTO, 190, 163,
WC_COMPANY_MANAGER_FACE, WC_NONE,
@ -1567,14 +1528,6 @@ static const WindowDesc _select_company_manager_face_desc(
_nested_select_company_manager_face_widgets, lengthof(_nested_select_company_manager_face_widgets)
);
/** advanced company manager face selection window description */
static const WindowDesc _select_company_manager_face_adv_desc(
WDP_AUTO, WDP_AUTO, 220, 220,
WC_COMPANY_MANAGER_FACE, WC_NONE,
WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
_nested_select_company_manager_face_adv_widgets, lengthof(_nested_select_company_manager_face_adv_widgets)
);
/**
* Open the simple/advanced company manager face selection window
*
@ -1583,12 +1536,12 @@ static const WindowDesc _select_company_manager_face_adv_desc(
* @param top previous top position of the window
* @param left previous left position of the window
*/
static void DoSelectCompanyManagerFace(Window *parent, bool adv, int top, int left)
static void DoSelectCompanyManagerFace(Window *parent)
{
if (!Company::IsValidID((CompanyID)parent->window_number)) return;
if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
new SelectCompanyManagerFaceWindow(adv ? &_select_company_manager_face_adv_desc : &_select_company_manager_face_desc, parent, adv, top, left); // simple or advanced window
new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc, parent);
}
@ -1935,7 +1888,7 @@ struct CompanyWindow : Window
virtual void OnClick(Point pt, int widget)
{
switch (widget) {
case CW_WIDGET_NEW_FACE: DoSelectCompanyManagerFace(this, false); break;
case CW_WIDGET_NEW_FACE: DoSelectCompanyManagerFace(this); break;
case CW_WIDGET_COLOUR_SCHEME:
if (BringWindowToFrontById(WC_COMPANY_COLOUR, this->window_number)) break;

Loading…
Cancel
Save