Feature: Add a button to the vehicle advisory news window to open the group window.

pull/128/head
stormcone 5 years ago committed by Charles Pigott
parent cc1d72c3a3
commit 798e9ee93e

@ -870,6 +870,8 @@ STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE :{BIG_FONT}{BLAC
STR_NEWS_NEW_VEHICLE_TYPE :{BIG_FONT}{BLACK}{ENGINE}
STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE :{BLACK}New {STRING} now available! - {ENGINE}
STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP :{BLACK}Open the group window focused on the vehicle's group
STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO :{WHITE}{STATION} no longer accepts {STRING}
STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_OR_CARGO :{WHITE}{STATION} no longer accepts {STRING} or {STRING}
STR_NEWS_STATION_NOW_ACCEPTS_CARGO :{WHITE}{STATION} now accepts {STRING}

@ -16,6 +16,7 @@
#include "vehicle_base.h"
#include "vehicle_func.h"
#include "vehicle_gui.h"
#include "roadveh.h"
#include "station_base.h"
#include "industry.h"
#include "town.h"
@ -32,6 +33,7 @@
#include "company_base.h"
#include "settings_internal.h"
#include "guitimer_func.h"
#include "group_gui.h"
#include "widgets/news_widget.h"
@ -181,6 +183,8 @@ static const NWidgetPart _nested_small_news_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetMinimalSize(14, 11), SetResize(1, 0),
SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
EndContainer(),
/* Main part */
@ -279,6 +283,27 @@ struct NewsWindow : Window {
/* For company news with a face we have a separate headline in param[0] */
if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
const Vehicle *v = Vehicle::Get(ni->ref1);
switch (v->type) {
case VEH_TRAIN:
nwid->widget_data = STR_TRAIN;
break;
case VEH_ROAD:
nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
break;
case VEH_SHIP:
nwid->widget_data = STR_SHIP;
break;
case VEH_AIRCRAFT:
nwid->widget_data = STR_PLANE;
break;
default:
break; // Do nothing
}
}
this->FinishInitNested(0);
/* Initialize viewport if it exists. */
@ -354,6 +379,24 @@ struct NewsWindow : Window {
str = GetEngineInfoString(engine);
break;
}
case WID_N_SHOW_GROUP:
if (this->ni->reftype1 == NR_VEHICLE) {
Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
d2.width += WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT;
*size = d2;
} else {
/* Hide 'Show group window' button if this news is not about a vehicle. */
size->width = 0;
size->height = 0;
resize->width = 0;
resize->height = 0;
fill->width = 0;
fill->height = 0;
}
return;
default:
return; // Do nothing
}
@ -449,6 +492,12 @@ struct NewsWindow : Window {
case WID_N_VIEWPORT:
break; // Ignore clicks
case WID_N_SHOW_GROUP:
if (this->ni->reftype1 == NR_VEHICLE) {
const Vehicle *v = Vehicle::Get(this->ni->ref1);
ShowCompanyGroupForVehicle(v);
}
break;
default:
if (this->ni->reftype1 == NR_VEHICLE) {
const Vehicle *v = Vehicle::Get(this->ni->ref1);

@ -870,6 +870,7 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_N_VEH_NAME, "WID_N_VEH_NAME");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_N_VEH_SPR, "WID_N_VEH_SPR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_N_VEH_INFO, "WID_N_VEH_INFO");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_N_SHOW_GROUP, "WID_N_SHOW_GROUP");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MH_STICKYBOX, "WID_MH_STICKYBOX");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MH_BACKGROUND, "WID_MH_BACKGROUND");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_MH_SCROLLBAR, "WID_MH_SCROLLBAR");

@ -1940,6 +1940,7 @@ public:
WID_N_VEH_NAME = ::WID_N_VEH_NAME, ///< Name of the new vehicle.
WID_N_VEH_SPR = ::WID_N_VEH_SPR, ///< Graphical display of the new vehicle.
WID_N_VEH_INFO = ::WID_N_VEH_INFO, ///< Some technical data of the new vehicle.
WID_N_SHOW_GROUP = ::WID_N_SHOW_GROUP, ///< Show vehicle's group
};
/** Widgets of the #MessageHistoryWindow class. */

@ -31,6 +31,7 @@ enum NewsWidgets {
WID_N_VEH_NAME, ///< Name of the new vehicle.
WID_N_VEH_SPR, ///< Graphical display of the new vehicle.
WID_N_VEH_INFO, ///< Some technical data of the new vehicle.
WID_N_SHOW_GROUP, ///< Show vehicle's group
};
/** Widgets of the #MessageHistoryWindow class. */

Loading…
Cancel
Save