mirror of https://github.com/OpenTTD/OpenTTD
(svn r13131) -Codechange: make a class of the ErrmsgWindow.
parent
cc0dae2271
commit
5b54c9e373
129
src/misc_gui.cpp
129
src/misc_gui.cpp
|
@ -328,11 +328,6 @@ void ShowAboutWindow()
|
||||||
new AboutWindow();
|
new AboutWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64 _errmsg_decode_params[20];
|
|
||||||
static StringID _errmsg_message_1, _errmsg_message_2;
|
|
||||||
static uint _errmsg_duration;
|
|
||||||
|
|
||||||
|
|
||||||
static const Widget _errmsg_widgets[] = {
|
static const Widget _errmsg_widgets[] = {
|
||||||
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||||
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 239, 0, 13, STR_00B2_MESSAGE, STR_NULL},
|
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 239, 0, 13, STR_00B2_MESSAGE, STR_NULL},
|
||||||
|
@ -347,13 +342,34 @@ static const Widget _errmsg_face_widgets[] = {
|
||||||
{ WIDGETS_END},
|
{ WIDGETS_END},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ErrmsgWndProc(Window *w, WindowEvent *e)
|
struct ErrmsgWindow : public Window {
|
||||||
{
|
private:
|
||||||
switch (e->event) {
|
uint duration;
|
||||||
case WE_PAINT:
|
uint64 decode_params[20];
|
||||||
CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
|
StringID message_1;
|
||||||
DrawWindowWidgets(w);
|
StringID message_2;
|
||||||
CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
|
|
||||||
|
public:
|
||||||
|
ErrmsgWindow(Point pt, int width, int height, StringID msg1, StringID msg2, const Widget *widget) : Window(pt.x, pt.y, width, height, NULL, WC_ERRMSG, widget)
|
||||||
|
{
|
||||||
|
this->duration = _patches.errmsg_duration;
|
||||||
|
CopyOutDParam(this->decode_params, 0, lengthof(this->decode_params));
|
||||||
|
this->message_1 = msg1;
|
||||||
|
this->message_2 = msg2;
|
||||||
|
this->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
|
||||||
|
this->FindWindowPlacementAndResize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnPaint()
|
||||||
|
{
|
||||||
|
static int y[][3] = {
|
||||||
|
{15, 25, 30}, // _errmsg_widgets
|
||||||
|
{45, 65, 90}, // _errmsg_face_widgets
|
||||||
|
};
|
||||||
|
|
||||||
|
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
|
||||||
|
DrawWindowWidgets(this);
|
||||||
|
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
|
||||||
|
|
||||||
/* If the error message comes from a NewGRF, we must use the text ref. stack reserved for error messages.
|
/* If the error message comes from a NewGRF, we must use the text ref. stack reserved for error messages.
|
||||||
* If the message doesn't come from a NewGRF, it won't use the TTDP-style text ref. stack, so we won't hurt anything
|
* If the message doesn't come from a NewGRF, it won't use the TTDP-style text ref. stack, so we won't hurt anything
|
||||||
|
@ -361,82 +377,60 @@ static void ErrmsgWndProc(Window *w, WindowEvent *e)
|
||||||
SwitchToErrorRefStack();
|
SwitchToErrorRefStack();
|
||||||
RewindTextRefStack();
|
RewindTextRefStack();
|
||||||
|
|
||||||
if (!IsWindowOfPrototype(w, _errmsg_face_widgets)) {
|
byte i = 0;
|
||||||
DrawStringMultiCenter(
|
if (IsWindowOfPrototype(this, _errmsg_face_widgets)) {
|
||||||
120,
|
const Player *p = GetPlayer((PlayerID)GetDParamX(this->decode_params, 2));
|
||||||
(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15),
|
|
||||||
_errmsg_message_2,
|
|
||||||
w->width - 2);
|
|
||||||
if (_errmsg_message_1 != INVALID_STRING_ID) {
|
|
||||||
DrawStringMultiCenter(
|
|
||||||
120,
|
|
||||||
30,
|
|
||||||
_errmsg_message_1,
|
|
||||||
w->width - 2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const Player *p = GetPlayer((PlayerID)GetDParamX(_errmsg_decode_params,2));
|
|
||||||
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
||||||
|
i = 1;
|
||||||
DrawStringMultiCenter(
|
|
||||||
214,
|
|
||||||
(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
|
|
||||||
_errmsg_message_2,
|
|
||||||
w->width - 2);
|
|
||||||
if (_errmsg_message_1 != INVALID_STRING_ID) {
|
|
||||||
DrawStringMultiCenter(
|
|
||||||
214,
|
|
||||||
90,
|
|
||||||
_errmsg_message_1,
|
|
||||||
w->width - 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte j = (this->message_1 == INVALID_STRING_ID) ? 1 : 0;
|
||||||
|
DrawStringMultiCenter(this->width - 120, y[i][j], this->message_2, this->width - 2);
|
||||||
|
if (j == 0) {
|
||||||
|
DrawStringMultiCenter(this->width - 120, y[i][2], this->message_1, this->width - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch back to the normal text ref. stack for NewGRF texts */
|
/* Switch back to the normal text ref. stack for NewGRF texts */
|
||||||
SwitchToNormalRefStack();
|
SwitchToNormalRefStack();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case WE_MOUSELOOP:
|
virtual void OnMouseLoop()
|
||||||
if (_right_button_down) delete w;
|
{
|
||||||
break;
|
if (_right_button_down) delete this;
|
||||||
|
}
|
||||||
|
|
||||||
case WE_100_TICKS:
|
virtual void OnHundredthTick()
|
||||||
if (--_errmsg_duration == 0) delete w;
|
{
|
||||||
break;
|
if (--this->duration == 0) delete this;
|
||||||
|
}
|
||||||
|
|
||||||
case WE_DESTROY:
|
~ErrmsgWindow()
|
||||||
|
{
|
||||||
SetRedErrorSquare(0);
|
SetRedErrorSquare(0);
|
||||||
extern StringID _switch_mode_errorstr;
|
extern StringID _switch_mode_errorstr;
|
||||||
_switch_mode_errorstr = INVALID_STRING_ID;
|
_switch_mode_errorstr = INVALID_STRING_ID;
|
||||||
break;
|
}
|
||||||
|
|
||||||
case WE_KEYPRESS:
|
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||||
if (e->we.keypress.keycode == WKC_SPACE) {
|
{
|
||||||
/* Don't continue. */
|
if (keycode != WKC_SPACE) return true;
|
||||||
e->we.keypress.cont = false;
|
delete this;
|
||||||
delete w;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
|
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
|
||||||
{
|
{
|
||||||
DeleteWindowById(WC_ERRMSG, 0);
|
DeleteWindowById(WC_ERRMSG, 0);
|
||||||
|
|
||||||
if (msg_2 == STR_NULL) msg_2 = STR_EMPTY;
|
if (!_patches.errmsg_duration) return;
|
||||||
|
|
||||||
_errmsg_message_1 = msg_1;
|
if (msg_2 == STR_NULL) msg_2 = STR_EMPTY;
|
||||||
_errmsg_message_2 = msg_2;
|
|
||||||
CopyOutDParam(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params));
|
|
||||||
_errmsg_duration = _patches.errmsg_duration;
|
|
||||||
if (!_errmsg_duration) return;
|
|
||||||
|
|
||||||
Point pt;
|
Point pt;
|
||||||
const ViewPort *vp;
|
const ViewPort *vp;
|
||||||
Window *w;
|
|
||||||
|
|
||||||
if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
|
if (msg_1 != STR_013B_OWNED_BY || GetDParam(2) >= 8) {
|
||||||
if ((x | y) != 0) {
|
if ((x | y) != 0) {
|
||||||
pt = RemapCoords2(x, y);
|
pt = RemapCoords2(x, y);
|
||||||
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
||||||
|
@ -453,7 +447,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
|
||||||
pt.x = (_screen.width - 240) >> 1;
|
pt.x = (_screen.width - 240) >> 1;
|
||||||
pt.y = (_screen.height - 46) >> 1;
|
pt.y = (_screen.height - 46) >> 1;
|
||||||
}
|
}
|
||||||
w = new Window(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
|
new ErrmsgWindow(pt, 240, 46, msg_1, msg_2, _errmsg_widgets);
|
||||||
} else {
|
} else {
|
||||||
if ((x | y) != 0) {
|
if ((x | y) != 0) {
|
||||||
pt = RemapCoords2(x, y);
|
pt = RemapCoords2(x, y);
|
||||||
|
@ -464,13 +458,10 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
|
||||||
pt.x = (_screen.width - 334) >> 1;
|
pt.x = (_screen.width - 334) >> 1;
|
||||||
pt.y = (_screen.height - 137) >> 1;
|
pt.y = (_screen.height - 137) >> 1;
|
||||||
}
|
}
|
||||||
w = new Window(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
|
new ErrmsgWindow(pt, 334, 137, msg_1, msg_2, _errmsg_face_widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
|
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
|
||||||
{
|
{
|
||||||
StringID msg = STR_0805_ESTIMATED_COST;
|
StringID msg = STR_0805_ESTIMATED_COST;
|
||||||
|
|
Loading…
Reference in New Issue