mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r17397) -Codechange: Add new vehicle news window.
This commit is contained in:
parent
c0b9a6a9bc
commit
0f9da2d636
|
@ -263,25 +263,6 @@ void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal)
|
|||
}
|
||||
}
|
||||
|
||||
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
||||
{
|
||||
assert(ni->reftype1 == NR_ENGINE);
|
||||
EngineID engine = ni->ref1;
|
||||
|
||||
SetDParam(0, GetEngineCategoryName(engine));
|
||||
DrawStringMultiLine(1, w->width - 2, 0, 56, STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE, TC_FROMSTRING, SA_CENTER);
|
||||
|
||||
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
||||
|
||||
SetDParam(0, engine);
|
||||
DrawStringMultiLine(1, w->width - 2, 56, 88, STR_NEWS_NEW_VEHICLE_TYPE, TC_FROMSTRING, SA_CENTER);
|
||||
|
||||
DrawVehicleEngine(w->width >> 1, 88, engine, GetEnginePalette(engine, _local_company));
|
||||
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
|
||||
DrawStringMultiLine(26, w->width - 26, 100, 170, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
||||
}
|
||||
|
||||
|
||||
/** Sort all items using qsort() and given 'CompareItems' function
|
||||
* @param el list to be sorted
|
||||
* @param compare function for evaluation of the quicksort
|
||||
|
|
134
src/news_gui.cpp
134
src/news_gui.cpp
|
@ -21,6 +21,7 @@
|
|||
#include "window_func.h"
|
||||
#include "date_func.h"
|
||||
#include "vehicle_base.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "station_base.h"
|
||||
#include "industry.h"
|
||||
#include "town.h"
|
||||
|
@ -29,7 +30,9 @@
|
|||
#include "widgets/dropdown_func.h"
|
||||
#include "statusbar_gui.h"
|
||||
#include "company_manager_face.h"
|
||||
#include "company_func.h"
|
||||
#include "map_func.h"
|
||||
#include "engine_gui.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -51,9 +54,6 @@ static NewsItem *_forced_news = NULL; ///< item the user has asked for
|
|||
static NewsItem *_current_news = NULL;
|
||||
|
||||
|
||||
typedef void DrawNewsCallbackProc(struct Window *w, const NewsItem *ni);
|
||||
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni);
|
||||
|
||||
/**
|
||||
* Get the position a news-reference is referencing.
|
||||
* @param reftype The type of reference.
|
||||
|
@ -85,6 +85,11 @@ enum NewsTypeWidgets {
|
|||
NTW_MESSAGE, ///< Space for displaying the message. Only used in small news items.
|
||||
NTW_MGR_FACE, ///< Face of the manager.
|
||||
NTW_MGR_NAME, ///< Name of the manager.
|
||||
NTW_VEH_TITLE, ///< Vehicle new title.
|
||||
NTW_VEH_BKGND, ///< Dark background of new vehicle news.
|
||||
NTW_VEH_NAME, ///< Name of the new vehicle.
|
||||
NTW_VEH_SPR, ///< Graphical display of the new vehicle.
|
||||
NTW_VEH_INFO, ///< Some technical data of the new vehicle.
|
||||
};
|
||||
|
||||
/* Normal news items. */
|
||||
|
@ -105,6 +110,33 @@ static WindowDesc _normal_news_desc(
|
|||
NULL, _nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
|
||||
);
|
||||
|
||||
/* New vehicles news items. */
|
||||
static const NWidgetPart _nested_vehicle_news_widgets[] = {
|
||||
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
||||
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_TEXT, COLOUR_WHITE, NTW_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
|
||||
NWidget(NWID_SPACER), SetFill(false, true),
|
||||
EndContainer(),
|
||||
NWidget(WWT_LABEL, COLOUR_WHITE, NTW_VEH_TITLE), SetFill(true, true), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
|
||||
EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_VEH_BKGND), SetPadding(0, 25, 1, 25),
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_NAME), SetMinimalSize(369, 33), SetFill(true, false),
|
||||
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_SPR), SetMinimalSize(369, 32), SetFill(true, false),
|
||||
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_INFO), SetMinimalSize(369, 46), SetFill(true, false),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
static WindowDesc _vehicle_news_desc(
|
||||
WDP_CENTER, 476, 430, 170, 430, 170,
|
||||
WC_NEWS_WINDOW, WC_NONE,
|
||||
WDF_DEF_WIDGET,
|
||||
NULL, _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
|
||||
);
|
||||
|
||||
/* Company news items. */
|
||||
static const NWidgetPart _nested_company_news_widgets[] = {
|
||||
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
||||
|
@ -191,7 +223,6 @@ struct NewsSubtypeData {
|
|||
NewsMode display_mode; ///< Display mode value @see NewsMode
|
||||
NewsFlag flags; ///< Initial NewsFlags bits @see NewsFlag
|
||||
WindowDesc *desc; ///< Window description for displaying this news.
|
||||
DrawNewsCallbackProc *callback; ///< Call-back function
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -199,24 +230,24 @@ struct NewsSubtypeData {
|
|||
*/
|
||||
static const NewsSubtypeData _news_subtype_data[] = {
|
||||
/* type, display_mode, flags, window description, callback */
|
||||
{ NT_ARRIVAL_COMPANY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_ARRIVAL_COMPANY
|
||||
{ NT_ARRIVAL_OTHER, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_ARRIVAL_OTHER
|
||||
{ NT_ACCIDENT, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_ACCIDENT
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc, NULL }, ///< NS_COMPANY_TROUBLE
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc, NULL }, ///< NS_COMPANY_MERGER
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc, NULL }, ///< NS_COMPANY_BANKRUPT
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc, NULL }, ///< NS_COMPANY_NEW
|
||||
{ NT_INDUSTRY_OPEN, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_INDUSTRY_OPEN
|
||||
{ NT_INDUSTRY_CLOSE, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_INDUSTRY_CLOSE
|
||||
{ NT_ECONOMY, NM_NORMAL, NF_NONE, &_normal_news_desc, NULL }, ///< NS_ECONOMY
|
||||
{ NT_INDUSTRY_COMPANY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_INDUSTRY_COMPANY
|
||||
{ NT_INDUSTRY_OTHER, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_INDUSTRY_OTHER
|
||||
{ NT_INDUSTRY_NOBODY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc, NULL }, ///< NS_INDUSTRY_NOBODY
|
||||
{ NT_ADVICE, NM_SMALL, NF_INCOLOUR, &_small_news_desc, NULL }, ///< NS_ADVICE
|
||||
{ NT_NEW_VEHICLES, NM_NORMAL, NF_NONE, &_normal_news_desc, DrawNewsNewVehicleAvail }, ///< NS_NEW_VEHICLES
|
||||
{ NT_ACCEPTANCE, NM_SMALL, NF_INCOLOUR, &_small_news_desc, NULL }, ///< NS_ACCEPTANCE
|
||||
{ NT_SUBSIDIES, NM_NORMAL, NF_NONE, &_normal_news_desc, NULL }, ///< NS_SUBSIDIES
|
||||
{ NT_GENERAL, NM_NORMAL, NF_NONE, &_normal_news_desc, NULL }, ///< NS_GENERAL
|
||||
{ NT_ARRIVAL_COMPANY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_COMPANY
|
||||
{ NT_ARRIVAL_OTHER, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_OTHER
|
||||
{ NT_ACCIDENT, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ACCIDENT
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_TROUBLE
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_MERGER
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_BANKRUPT
|
||||
{ NT_COMPANY_INFO, NM_COMPANY, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_NEW
|
||||
{ NT_INDUSTRY_OPEN, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OPEN
|
||||
{ NT_INDUSTRY_CLOSE, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_CLOSE
|
||||
{ NT_ECONOMY, NM_NORMAL, NF_NONE, &_normal_news_desc }, ///< NS_ECONOMY
|
||||
{ NT_INDUSTRY_COMPANY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_COMPANY
|
||||
{ NT_INDUSTRY_OTHER, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OTHER
|
||||
{ NT_INDUSTRY_NOBODY, NM_THIN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_NOBODY
|
||||
{ NT_ADVICE, NM_SMALL, NF_INCOLOUR, &_small_news_desc }, ///< NS_ADVICE
|
||||
{ NT_NEW_VEHICLES, NM_NORMAL, NF_NONE, &_vehicle_news_desc }, ///< NS_NEW_VEHICLES
|
||||
{ NT_ACCEPTANCE, NM_SMALL, NF_INCOLOUR, &_small_news_desc }, ///< NS_ACCEPTANCE
|
||||
{ NT_SUBSIDIES, NM_NORMAL, NF_NONE, &_normal_news_desc }, ///< NS_SUBSIDIES
|
||||
{ NT_GENERAL, NM_NORMAL, NF_NONE, &_normal_news_desc }, ///< NS_GENERAL
|
||||
};
|
||||
|
||||
assert_compile(lengthof(_news_subtype_data) == NS_END);
|
||||
|
@ -313,11 +344,6 @@ struct NewsWindow : Window {
|
|||
case NM_NORMAL: {
|
||||
this->DrawWidgets();
|
||||
|
||||
if (_news_subtype_data[this->ni->subtype].callback != NULL) {
|
||||
(_news_subtype_data[this->ni->subtype].callback)(this, ni);
|
||||
break;
|
||||
}
|
||||
|
||||
DrawString(2, this->width - 1, 1, STR_SILVER_CROSS);
|
||||
|
||||
SetDParam(0, this->ni->date);
|
||||
|
@ -328,6 +354,7 @@ struct NewsWindow : Window {
|
|||
break;
|
||||
}
|
||||
|
||||
case NM_NEW_VEH:
|
||||
case NM_COMPANY:
|
||||
case NM_THIN:
|
||||
case NM_SMALL:
|
||||
|
@ -351,6 +378,17 @@ struct NewsWindow : Window {
|
|||
str = this->GetCompanyMessageString();
|
||||
break;
|
||||
|
||||
case NTW_VEH_NAME:
|
||||
case NTW_VEH_TITLE:
|
||||
str = this->GetNewVehicleMessageString(widget);
|
||||
break;
|
||||
|
||||
case NTW_VEH_INFO: {
|
||||
assert(this->ni->reftype1 == NR_ENGINE);
|
||||
EngineID engine = this->ni->ref1;
|
||||
str = GetEngineInfoString(engine);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return; // Do nothing
|
||||
}
|
||||
|
@ -397,6 +435,29 @@ struct NewsWindow : Window {
|
|||
case NTW_COMPANY_MSG:
|
||||
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
|
||||
break;
|
||||
|
||||
case NTW_VEH_BKGND:
|
||||
GfxFillRect(r.left, r.top, r.right, r.bottom, 10);
|
||||
break;
|
||||
|
||||
case NTW_VEH_NAME:
|
||||
case NTW_VEH_TITLE:
|
||||
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
|
||||
break;
|
||||
|
||||
case NTW_VEH_SPR: {
|
||||
assert(this->ni->reftype1 == NR_ENGINE);
|
||||
EngineID engine = this->ni->ref1;
|
||||
DrawVehicleEngine((r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company));
|
||||
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
|
||||
break;
|
||||
}
|
||||
case NTW_VEH_INFO: {
|
||||
assert(this->ni->reftype1 == NR_ENGINE);
|
||||
EngineID engine = this->ni->ref1;
|
||||
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,6 +551,25 @@ private:
|
|||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
StringID GetNewVehicleMessageString(int widget) const
|
||||
{
|
||||
assert(this->ni->reftype1 == NR_ENGINE);
|
||||
EngineID engine = this->ni->ref1;
|
||||
|
||||
switch (widget) {
|
||||
case NTW_VEH_TITLE:
|
||||
SetDParam(0, GetEngineCategoryName(engine));
|
||||
return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
|
||||
|
||||
case NTW_VEH_NAME:
|
||||
SetDParam(0, engine);
|
||||
return STR_NEWS_NEW_VEHICLE_TYPE;
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* static */ uint NewsWindow::duration = 0; // Instance creation.
|
||||
|
|
|
@ -72,6 +72,7 @@ enum NewsMode {
|
|||
NM_NORMAL = 1, ///< Show a simple news message without viewport (height 170 pixels).
|
||||
NM_THIN = 2, ///< Show a simple news message with a viewport (height 130 pixels).
|
||||
NM_COMPANY = 3, ///< Show news about companies.
|
||||
NM_NEW_VEH = 4, ///< Show news about new vehicles.
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue