mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r18346) -Codechange: Compute size of face part display buttons only once in face window.
This commit is contained in:
parent
5187a5980b
commit
bb19a2e757
@ -1081,8 +1081,11 @@ class SelectCompanyManagerFaceWindow : public Window
|
|||||||
bool is_female; ///< Female face.
|
bool is_female; ///< Female face.
|
||||||
bool is_moust_male; ///< Male face with a moustache.
|
bool is_moust_male; ///< Male face with a moustache.
|
||||||
|
|
||||||
static const StringID PART_TEXTS_IS_FEMALE[];
|
Dimension yesno_dim; ///< Dimension of a yes/no button of a part in the advanced face window.
|
||||||
static const StringID PART_TEXTS[];
|
Dimension number_dim; ///< Dimension of a number widget of a part in the advanced face window.
|
||||||
|
|
||||||
|
static const StringID PART_TEXTS_IS_FEMALE[]; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
|
||||||
|
static const StringID PART_TEXTS[]; ///< Fixed strings to describe parts of the face.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw dynamic a label to the left of the button and a value in the button
|
* Draw dynamic a label to the left of the button and a value in the button
|
||||||
@ -1150,6 +1153,29 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void OnInit()
|
||||||
|
{
|
||||||
|
/* Size of the boolean yes/no button. */
|
||||||
|
Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
|
||||||
|
yesno_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
||||||
|
yesno_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||||
|
/* Size of the number button + arrows. */
|
||||||
|
Dimension number_dim = {0, 0};
|
||||||
|
for (int val = 1; val <= 12; val++) {
|
||||||
|
SetDParam(0, val);
|
||||||
|
number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
|
||||||
|
}
|
||||||
|
uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
|
||||||
|
number_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + arrows_width;
|
||||||
|
number_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||||
|
/* Compute width of both buttons. */
|
||||||
|
yesno_dim.width = max(yesno_dim.width, number_dim.width);
|
||||||
|
number_dim.width = yesno_dim.width - arrows_width;
|
||||||
|
|
||||||
|
this->yesno_dim = yesno_dim;
|
||||||
|
this->number_dim = number_dim;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
@ -1184,6 +1210,9 @@ public:
|
|||||||
|
|
||||||
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING:
|
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING:
|
||||||
case SCMFW_WIDGET_HAS_GLASSES:
|
case SCMFW_WIDGET_HAS_GLASSES:
|
||||||
|
*size = this->yesno_dim;
|
||||||
|
break;
|
||||||
|
|
||||||
case SCMFW_WIDGET_EYECOLOUR:
|
case SCMFW_WIDGET_EYECOLOUR:
|
||||||
case SCMFW_WIDGET_CHIN:
|
case SCMFW_WIDGET_CHIN:
|
||||||
case SCMFW_WIDGET_EYEBROWS:
|
case SCMFW_WIDGET_EYEBROWS:
|
||||||
@ -1193,31 +1222,9 @@ public:
|
|||||||
case SCMFW_WIDGET_JACKET:
|
case SCMFW_WIDGET_JACKET:
|
||||||
case SCMFW_WIDGET_COLLAR:
|
case SCMFW_WIDGET_COLLAR:
|
||||||
case SCMFW_WIDGET_TIE_EARRING:
|
case SCMFW_WIDGET_TIE_EARRING:
|
||||||
case SCMFW_WIDGET_GLASSES: {
|
case SCMFW_WIDGET_GLASSES:
|
||||||
/* Size of the boolean yes/no button. */
|
*size = this->number_dim;
|
||||||
Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
|
|
||||||
yesno_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
||||||
yesno_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
||||||
/* Size of the number button + arrows. */
|
|
||||||
Dimension number_dim = {0, 0};
|
|
||||||
for (int val = 1; val <= 12; val++) {
|
|
||||||
SetDParam(0, val);
|
|
||||||
number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
|
|
||||||
}
|
|
||||||
uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
|
|
||||||
number_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + arrows_width;
|
|
||||||
number_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
||||||
/* Compute width of yes/no button. */
|
|
||||||
yesno_dim.width = max(yesno_dim.width, number_dim.width);
|
|
||||||
number_dim.width = yesno_dim.width - arrows_width;
|
|
||||||
|
|
||||||
if (widget == SCMFW_WIDGET_HAS_MOUSTACHE_EARRING || widget == SCMFW_WIDGET_HAS_GLASSES) {
|
|
||||||
*size = yesno_dim;
|
|
||||||
} else {
|
|
||||||
*size = number_dim;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user