summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-03-06 16:23:32 +0000
committerfrosch <frosch@openttd.org>2010-03-06 16:23:32 +0000
commitbcb01903cdca4232eb2dd5ace0c002fefd2e336b (patch)
tree396d7c64b478e6f80c6a3c9a5d3bc96a1db86629
parentdc79bf4c0190666f321962e106af705323348976 (diff)
downloadopenttd-bcb01903cdca4232eb2dd5ace0c002fefd2e336b.tar.xz
(svn r19357) -Codechange: Add 'face' member to ErrmsgWindow to simplify stuff.
-rw-r--r--src/misc_gui.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index d5d4d5490..42776ca5e 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -541,9 +541,10 @@ private:
uint height_summary; ///< Height of the #summary_msg string in pixels in the #EMW_MESSAGE widget.
uint height_detailed; ///< Height of the #detailed_msg string in pixels in the #EMW_MESSAGE widget.
Point position; ///< Position of the error message window.
+ CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
public:
- ErrmsgWindow(Point pt, const WindowDesc *desc, StringID summary_msg, StringID detailed_msg, bool no_timeout) : Window()
+ ErrmsgWindow(Point pt, StringID summary_msg, StringID detailed_msg, bool no_timeout) : Window()
{
this->position = pt;
this->duration = no_timeout ? 0 : _settings_client.gui.errmsg_duration;
@@ -551,6 +552,10 @@ public:
this->summary_msg = summary_msg;
this->detailed_msg = detailed_msg;
+ CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
+ this->face = (this->detailed_msg == STR_ERROR_OWNED_BY && company <= MAX_COMPANIES) ? company : INVALID_COMPANY;
+ const WindowDesc *desc = (face == INVALID_COMPANY) ? &_errmsg_desc : &_errmsg_face_desc;
+
assert(summary_msg != INVALID_STRING_ID);
this->InitNested(desc);
@@ -595,7 +600,7 @@ public:
Point pt = RemapCoords2(this->position.x, this->position.y);
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
- if (this->detailed_msg != STR_ERROR_OWNED_BY || GetDParamX(this->decode_params, 2) >= MAX_COMPANIES) {
+ if (this->face == INVALID_COMPANY) {
/* move x pos to opposite corner */
pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; // Stay 20 pixels away from the edge of the screen.
@@ -624,7 +629,7 @@ public:
{
switch (widget) {
case EMW_FACE: {
- const Company *c = Company::Get((CompanyID)GetDParamX(this->decode_params, 2));
+ const Company *c = Company::Get(this->face);
DrawCompanyManagerFace(c->face, c->colour, r.left, r.top);
break;
}
@@ -720,8 +725,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
DeleteWindowById(WC_ERRMSG, 0);
Point pt = {x, y};
- const WindowDesc *desc = (detailed_msg != STR_ERROR_OWNED_BY || GetDParam(2) >= MAX_COMPANIES) ? &_errmsg_desc : &_errmsg_face_desc;
- new ErrmsgWindow(pt, desc, summary_msg, detailed_msg, no_timeout);
+ new ErrmsgWindow(pt, summary_msg, detailed_msg, no_timeout);
}
void ShowEstimatedCostOrIncome(Money cost, int x, int y)