Skip to content

Instantly share code, notes, and snippets.

@Ram-Z
Last active September 30, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-Z/f275fc29d35aa4c17360 to your computer and use it in GitHub Desktop.
Save Ram-Z/f275fc29d35aa4c17360 to your computer and use it in GitHub Desktop.
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 84288a0..9389897 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -61,6 +61,7 @@ static const KeycodeNames _keycode_to_name[] = {
{"NUM_MINUS", WKC_NUM_MINUS},
{"=", WKC_EQUALS},
{"-", WKC_MINUS},
+ {"SPACE", WKC_SPACE},
};
/**
@@ -173,6 +174,11 @@ static const char *KeycodeToString(uint16 keycode)
strecat(buf, "META", lastof(buf));
first = false;
}
+ if (keycode & WKC_SPACE) {
+ if (!first) strecat(buf, "+", lastof(buf));
+ strecat(buf, "SPACE", lastof(buf));
+ first = false;
+ }
if (!first) strecat(buf, "+", lastof(buf));
keycode = keycode & ~WKC_SPECIAL_KEYS;
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 3800af8..72e9226 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -27,6 +27,7 @@
#include "statusbar_gui.h"
#include "company_manager_face.h"
#include "company_func.h"
+#include "hotkeys.h"
#include "engine_base.h"
#include "engine_gui.h"
#include "core/geometry_func.hpp"
@@ -76,185 +77,12 @@ static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
}
}
-/* Normal news items. */
-static const NWidgetPart _nested_normal_news_widgets[] = {
- NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
- NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
- NWidget(NWID_SPACER), SetFill(1, 0),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
- NWidget(NWID_SPACER), SetFill(0, 1),
- EndContainer(),
- EndContainer(),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
- EndContainer(),
-};
-
-static WindowDesc _normal_news_desc(
- WDP_MANUAL, NULL, 0, 0,
- WC_NEWS_WINDOW, WC_NONE,
- 0,
- _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, WID_N_PANEL),
- NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
- NWidget(NWID_SPACER), SetFill(0, 1),
- EndContainer(),
- NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
- EndContainer(),
- NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
- NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
- NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
- EndContainer(),
- EndContainer(),
- EndContainer(),
-};
-
-static WindowDesc _vehicle_news_desc(
- WDP_MANUAL, NULL, 0, 0,
- WC_NEWS_WINDOW, WC_NONE,
- 0,
- _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
-);
-
-/* Company news items. */
-static const NWidgetPart _nested_company_news_widgets[] = {
- NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
- NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
- NWidget(NWID_SPACER), SetFill(0, 1),
- EndContainer(),
- NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
- EndContainer(),
- NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
- NWidget(NWID_SPACER), SetFill(0, 1),
- EndContainer(),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
- EndContainer(),
- EndContainer(),
-};
+WindowDesc* GetNewsWindowLayout(NewsFlag flags);
-static WindowDesc _company_news_desc(
- WDP_MANUAL, NULL, 0, 0,
- WC_NEWS_WINDOW, WC_NONE,
- 0,
- _nested_company_news_widgets, lengthof(_nested_company_news_widgets)
-);
-
-/* Thin news items. */
-static const NWidgetPart _nested_thin_news_widgets[] = {
- NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
- NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
- NWidget(NWID_SPACER), SetFill(1, 0),
- NWidget(NWID_VERTICAL),
- NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
- NWidget(NWID_SPACER), SetFill(0, 1),
- EndContainer(),
- EndContainer(),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
- EndContainer(),
+enum NewsHotkeys {
+ NHK_QUIT,
};
-static WindowDesc _thin_news_desc(
- WDP_MANUAL, NULL, 0, 0,
- WC_NEWS_WINDOW, WC_NONE,
- 0,
- _nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
-);
-
-/* Small news items. */
-static const NWidgetPart _nested_small_news_widgets[] = {
- /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
- NWidget(NWID_HORIZONTAL),
- NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
- NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
- EndContainer(),
-
- /* Main part */
- NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
- NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
- EndContainer(),
- NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
- EndContainer(),
-};
-
-static WindowDesc _small_news_desc(
- WDP_MANUAL, NULL, 0, 0,
- WC_NEWS_WINDOW, WC_NONE,
- 0,
- _nested_small_news_widgets, lengthof(_nested_small_news_widgets)
-);
-
-/**
- * Window layouts for news items.
- */
-static WindowDesc* _news_window_layout[] = {
- &_thin_news_desc, ///< NF_THIN
- &_small_news_desc, ///< NF_SMALL
- &_normal_news_desc, ///< NF_NORMAL
- &_vehicle_news_desc, ///< NF_VEHICLE
- &_company_news_desc, ///< NF_COMPANY
-};
-
-WindowDesc* GetNewsWindowLayout(NewsFlag flags)
-{
- uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
- assert(layout < lengthof(_news_window_layout));
- return _news_window_layout[layout];
-}
-
-/**
- * Per-NewsType data
- */
-static NewsTypeData _news_type_data[] = {
- /* name, age, sound, */
- NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
- NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
- NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
- NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
- NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
- NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
- NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
- NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
- NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
- NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
- NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
- NewsTypeData("news_display.new_vehicles", 30, SND_1E_OOOOH ), ///< NT_NEW_VEHICLES
- NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
- NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
- NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
-};
-
-assert_compile(lengthof(_news_type_data) == NT_END);
-
-/**
- * Return the news display option.
- * @return display options
- */
-NewsDisplay NewsTypeData::GetDisplay() const
-{
- uint index;
- const SettingDesc *sd = GetSettingFromName(this->name, &index);
- assert(sd != NULL);
- void *ptr = GetVariableAddress(NULL, &sd->save);
- return (NewsDisplay)ReadValue(ptr, sd->save.conv);
-}
-
/** Window class displaying a news item. */
struct NewsWindow : Window {
uint16 chat_height; ///< Height of the chat window.
@@ -262,36 +90,7 @@ struct NewsWindow : Window {
const NewsItem *ni; ///< News item to display.
static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
- NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
- {
- NewsWindow::duration = 555;
- const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
- this->chat_height = (w != NULL) ? w->height : 0;
- this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
-
- this->flags |= WF_DISABLE_VP_SCROLL;
-
- this->CreateNestedTree();
-
- /* 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];
-
- this->FinishInitNested(0);
-
- /* Initialize viewport if it exists. */
- NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
- if (nvp != NULL) {
- nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
- if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
- if ((this->ni->flags & NF_INCOLOUR) == 0) {
- nvp->disp_flags |= ND_SHADE_GREY;
- } else if (this->ni->flags & NF_SHADE) {
- nvp->disp_flags |= ND_SHADE_DIMMED;
- }
- }
-
- PositionNewsMessage(this);
- }
+ NewsWindow(WindowDesc *desc, const NewsItem *ni);
void DrawNewsBorder(const Rect &r) const
{
@@ -452,13 +251,22 @@ struct NewsWindow : Window {
}
}
- virtual EventState OnKeyPress(WChar key, uint16 keycode)
+ virtual EventState OnHotkey(int hotkey)
{
- if (keycode == WKC_SPACE) {
- /* Don't continue. */
- delete this;
- return ES_HANDLED;
+ switch (hotkey) {
+ case NHK_QUIT: delete this; break;
+ default: return ES_NOT_HANDLED;
}
+ return ES_HANDLED;
+ }
+
+ virtual EventState OnKeyPress(WChar key, uint16 keycode)
+ {
+ // if (keycode == WKC_SPACE) {
+ // #<{(| Don't continue. |)}>#
+ // delete this;
+ // return ES_HANDLED;
+ // }
return ES_NOT_HANDLED;
}
@@ -483,6 +291,8 @@ struct NewsWindow : Window {
this->SetWindowTop(newtop);
}
+ static HotkeyList hotkeys;
+
private:
/**
* Moves the window so #newtop is new 'top' coordinate. Makes screen dirty where needed.
@@ -529,6 +339,226 @@ private:
/* static */ uint NewsWindow::duration = 0; // Instance creation.
+static Hotkey news_hotkeys[] = {
+ Hotkey(WKC_SPACE, "quit", NHK_QUIT),
+};
+
+HotkeyList NewsWindow::hotkeys("news", news_hotkeys);
+
+/* Normal news items. */
+static const NWidgetPart _nested_normal_news_widgets[] = {
+ NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
+ NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
+ NWidget(NWID_SPACER), SetFill(1, 0),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
+ NWidget(NWID_SPACER), SetFill(0, 1),
+ EndContainer(),
+ EndContainer(),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
+ EndContainer(),
+};
+
+static WindowDesc _normal_news_desc(
+ WDP_MANUAL, NULL, 0, 0,
+ WC_NEWS_WINDOW, WC_NONE,
+ 0,
+ _nested_normal_news_widgets, lengthof(_nested_normal_news_widgets),
+ &NewsWindow::hotkeys
+);
+
+/* New vehicles news items. */
+static const NWidgetPart _nested_vehicle_news_widgets[] = {
+ NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
+ NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
+ NWidget(NWID_SPACER), SetFill(0, 1),
+ EndContainer(),
+ NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
+ EndContainer(),
+ NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
+ NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
+ NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
+ EndContainer(),
+ EndContainer(),
+ EndContainer(),
+};
+
+static WindowDesc _vehicle_news_desc(
+ WDP_MANUAL, NULL, 0, 0,
+ WC_NEWS_WINDOW, WC_NONE,
+ 0,
+ _nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets),
+ &NewsWindow::hotkeys
+);
+
+/* Company news items. */
+static const NWidgetPart _nested_company_news_widgets[] = {
+ NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
+ NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
+ NWidget(NWID_SPACER), SetFill(0, 1),
+ EndContainer(),
+ NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
+ EndContainer(),
+ NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
+ NWidget(NWID_SPACER), SetFill(0, 1),
+ EndContainer(),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
+ EndContainer(),
+ EndContainer(),
+};
+
+static WindowDesc _company_news_desc(
+ WDP_MANUAL, NULL, 0, 0,
+ WC_NEWS_WINDOW, WC_NONE,
+ 0,
+ _nested_company_news_widgets, lengthof(_nested_company_news_widgets),
+ &NewsWindow::hotkeys
+);
+
+/* Thin news items. */
+static const NWidgetPart _nested_thin_news_widgets[] = {
+ NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
+ NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
+ NWidget(NWID_SPACER), SetFill(1, 0),
+ NWidget(NWID_VERTICAL),
+ NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
+ NWidget(NWID_SPACER), SetFill(0, 1),
+ EndContainer(),
+ EndContainer(),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
+ EndContainer(),
+};
+
+static WindowDesc _thin_news_desc(
+ WDP_MANUAL, NULL, 0, 0,
+ WC_NEWS_WINDOW, WC_NONE,
+ 0,
+ _nested_thin_news_widgets, lengthof(_nested_thin_news_widgets),
+ &NewsWindow::hotkeys
+);
+
+/* Small news items. */
+static const NWidgetPart _nested_small_news_widgets[] = {
+ /* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
+ NWidget(NWID_HORIZONTAL),
+ NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
+ NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
+ EndContainer(),
+
+ /* Main part */
+ NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
+ NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
+ EndContainer(),
+ NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
+ EndContainer(),
+};
+
+static WindowDesc _small_news_desc(
+ WDP_MANUAL, NULL, 0, 0,
+ WC_NEWS_WINDOW, WC_NONE,
+ 0,
+ _nested_small_news_widgets, lengthof(_nested_small_news_widgets),
+ &NewsWindow::hotkeys
+);
+
+/**
+ * Window layouts for news items.
+ */
+static WindowDesc* _news_window_layout[] = {
+ &_thin_news_desc, ///< NF_THIN
+ &_small_news_desc, ///< NF_SMALL
+ &_normal_news_desc, ///< NF_NORMAL
+ &_vehicle_news_desc, ///< NF_VEHICLE
+ &_company_news_desc, ///< NF_COMPANY
+};
+
+NewsWindow::NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
+{
+ NewsWindow::duration = 555;
+ const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
+ this->chat_height = (w != NULL) ? w->height : 0;
+ this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
+
+ this->flags |= WF_DISABLE_VP_SCROLL;
+
+ this->CreateNestedTree();
+
+ /* 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];
+
+ this->FinishInitNested(0);
+
+ /* Initialize viewport if it exists. */
+ NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
+ if (nvp != NULL) {
+ nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
+ if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
+ if ((this->ni->flags & NF_INCOLOUR) == 0) {
+ nvp->disp_flags |= ND_SHADE_GREY;
+ } else if (this->ni->flags & NF_SHADE) {
+ nvp->disp_flags |= ND_SHADE_DIMMED;
+ }
+ }
+
+ PositionNewsMessage(this);
+}
+
+WindowDesc* GetNewsWindowLayout(NewsFlag flags)
+{
+ uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
+ assert(layout < lengthof(_news_window_layout));
+ return _news_window_layout[layout];
+}
+
+/**
+ * Per-NewsType data
+ */
+static NewsTypeData _news_type_data[] = {
+ /* name, age, sound, */
+ NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
+ NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
+ NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
+ NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
+ NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
+ NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
+ NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
+ NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
+ NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
+ NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
+ NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
+ NewsTypeData("news_display.new_vehicles", 30, SND_1E_OOOOH ), ///< NT_NEW_VEHICLES
+ NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
+ NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
+ NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
+};
+
+assert_compile(lengthof(_news_type_data) == NT_END);
+
+/**
+ * Return the news display option.
+ * @return display options
+ */
+NewsDisplay NewsTypeData::GetDisplay() const
+{
+ uint index;
+ const SettingDesc *sd = GetSettingFromName(this->name, &index);
+ assert(sd != NULL);
+ void *ptr = GetVariableAddress(NULL, &sd->save);
+ return (NewsDisplay)ReadValue(ptr, sd->save.conv);
+}
/** Open up an own newspaper window for the news item */
static void ShowNewspaper(const NewsItem *ni)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment