summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authorstormcone <48624099+stormcone@users.noreply.github.com>2019-07-22 22:16:41 +0200
committerCharles Pigott <charlespigott@googlemail.com>2019-12-23 18:04:10 +0000
commit798e9ee93e1189586d72201abab7caccc3fb6bdc (patch)
treeb45c303244fed4aee881494127bd3bc16ff0cc63 /src/news_gui.cpp
parentcc1d72c3a370f3c9a13e8722f8d69f5735b95285 (diff)
downloadopenttd-798e9ee93e1189586d72201abab7caccc3fb6bdc.tar.xz
Feature: Add a button to the vehicle advisory news window to open the group window.
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 6fd6ca38a..f963a876a 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -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);