|
|
|
@ -1103,270 +1103,3 @@ void ShowMessageHistory()
|
|
|
|
|
DeleteWindowById(WC_MESSAGE_HISTORY, 0);
|
|
|
|
|
new MessageHistoryWindow(&_message_history_desc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct MessageOptionsWindow : Window {
|
|
|
|
|
static const StringID message_opt[]; ///< Message report options, 'off', 'summary', or 'full'.
|
|
|
|
|
int state; ///< Option value for setting all categories at once.
|
|
|
|
|
Dimension dim_message_opt; ///< Amount of space needed for a label such that all labels will fit.
|
|
|
|
|
|
|
|
|
|
MessageOptionsWindow(const WindowDesc *desc) : Window()
|
|
|
|
|
{
|
|
|
|
|
this->InitNested(desc, WN_GAME_OPTIONS_MESSAGE_OPTION);
|
|
|
|
|
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
|
|
|
|
|
NewsDisplay all_val = _news_type_data[0].display;
|
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
|
this->SetMessageButtonStates(_news_type_data[i].display, i);
|
|
|
|
|
/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
|
|
|
|
|
if (_news_type_data[i].display != all_val) all_val = ND_OFF;
|
|
|
|
|
}
|
|
|
|
|
/* If all values are the same value, the ALL-button will take over this value */
|
|
|
|
|
this->state = all_val;
|
|
|
|
|
this->OnInvalidateData(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup the disabled/enabled buttons in the message window
|
|
|
|
|
* If the value is 'off' disable the [<] widget, and enable the [>] one
|
|
|
|
|
* Same-wise for all the others. Starting value of 4 is the first widget
|
|
|
|
|
* group. These are grouped as [<][>] .. [<][>], etc.
|
|
|
|
|
* @param value to set in the widget
|
|
|
|
|
* @param element index of the group of widget to set
|
|
|
|
|
*/
|
|
|
|
|
void SetMessageButtonStates(byte value, int element)
|
|
|
|
|
{
|
|
|
|
|
element *= MOS_WIDG_PER_SETTING;
|
|
|
|
|
|
|
|
|
|
this->SetWidgetDisabledState(element + WID_MO_START_OPTION, value == 0);
|
|
|
|
|
this->SetWidgetDisabledState(element + WID_MO_START_OPTION + 2, value == 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
|
{
|
|
|
|
|
if (widget >= WID_MO_START_OPTION && widget < WID_MO_END_OPTION && (widget - WID_MO_START_OPTION) % MOS_WIDG_PER_SETTING == 1) {
|
|
|
|
|
/* Draw the string of each setting on each button. */
|
|
|
|
|
int i = (widget - WID_MO_START_OPTION) / MOS_WIDG_PER_SETTING;
|
|
|
|
|
DrawString(r.left, r.right, r.top + 2, this->message_opt[_news_type_data[i].display], TC_BLACK, SA_HOR_CENTER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void OnInit()
|
|
|
|
|
{
|
|
|
|
|
this->dim_message_opt.width = 0;
|
|
|
|
|
this->dim_message_opt.height = 0;
|
|
|
|
|
for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) this->dim_message_opt = maxdim(this->dim_message_opt, GetStringBoundingBox(*str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
|
|
{
|
|
|
|
|
if (widget >= WID_MO_START_OPTION && widget < WID_MO_END_OPTION) {
|
|
|
|
|
/* Height is the biggest widget height in a row. */
|
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
|
|
|
|
|
|
|
|
|
|
/* Compute width for the label widget only. */
|
|
|
|
|
if ((widget - WID_MO_START_OPTION) % MOS_WIDG_PER_SETTING == 1) {
|
|
|
|
|
size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Size computations for global message options. */
|
|
|
|
|
if (widget == WID_MO_DROP_SUMMARY || widget == WID_MO_LABEL_SUMMARY || widget == WID_MO_SOUNDTICKER || widget == WID_MO_SOUNDTICKER_LABEL) {
|
|
|
|
|
/* Height is the biggest widget height in a row. */
|
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM);
|
|
|
|
|
|
|
|
|
|
if (widget == WID_MO_DROP_SUMMARY) {
|
|
|
|
|
size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
|
|
|
|
|
} else if (widget == WID_MO_SOUNDTICKER) {
|
|
|
|
|
size->width += MOS_BUTTON_SPACE; // A bit extra for better looks.
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
|
*/
|
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
|
|
|
|
{
|
|
|
|
|
if (!gui_scope) return;
|
|
|
|
|
/* Update the dropdown value for 'set all categories'. */
|
|
|
|
|
this->GetWidget<NWidgetCore>(WID_MO_DROP_SUMMARY)->widget_data = this->message_opt[this->state];
|
|
|
|
|
|
|
|
|
|
/* Update widget to reflect the value of the #_news_ticker_sound variable. */
|
|
|
|
|
this->SetWidgetLoweredState(WID_MO_SOUNDTICKER, _news_ticker_sound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
|
|
{
|
|
|
|
|
switch (widget) {
|
|
|
|
|
case WID_MO_DROP_SUMMARY: // Dropdown menu for all settings
|
|
|
|
|
ShowDropDownMenu(this, this->message_opt, this->state, WID_MO_DROP_SUMMARY, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WID_MO_SOUNDTICKER: // Change ticker sound on/off
|
|
|
|
|
_news_ticker_sound ^= 1;
|
|
|
|
|
this->InvalidateData();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: { // Clicked on the [<] .. [>] widgets
|
|
|
|
|
if (widget >= WID_MO_START_OPTION && widget < WID_MO_END_OPTION) {
|
|
|
|
|
int wid = widget - WID_MO_START_OPTION;
|
|
|
|
|
int element = wid / MOS_WIDG_PER_SETTING;
|
|
|
|
|
byte val = (_news_type_data[element].display + ((wid % MOS_WIDG_PER_SETTING) ? 1 : -1)) % 3;
|
|
|
|
|
|
|
|
|
|
this->SetMessageButtonStates(val, element);
|
|
|
|
|
_news_type_data[element].display = (NewsDisplay)val;
|
|
|
|
|
this->SetDirty();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
|
{
|
|
|
|
|
this->state = index;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
|
this->SetMessageButtonStates(index, i);
|
|
|
|
|
_news_type_data[i].display = (NewsDisplay)index;
|
|
|
|
|
}
|
|
|
|
|
this->InvalidateData();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const StringID MessageOptionsWindow::message_opt[] = {STR_NEWS_MESSAGES_OFF, STR_NEWS_MESSAGES_SUMMARY, STR_NEWS_MESSAGES_FULL, INVALID_STRING_ID};
|
|
|
|
|
|
|
|
|
|
/** Make a column with the buttons for changing each news category setting, and the global settings. */
|
|
|
|
|
static NWidgetBase *MakeButtonsColumn(int *biggest_index)
|
|
|
|
|
{
|
|
|
|
|
NWidgetVertical *vert_buttons = new NWidgetVertical;
|
|
|
|
|
|
|
|
|
|
/* Top-part of the column, one row for each new category. */
|
|
|
|
|
int widnum = WID_MO_START_OPTION;
|
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
|
/* [<] button. */
|
|
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum, AWV_DECREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
|
|
|
|
leaf->SetFill(1, 1);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
/* Label. */
|
|
|
|
|
leaf = new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_YELLOW, widnum + 1, STR_EMPTY, STR_NULL);
|
|
|
|
|
leaf->SetFill(1, 1);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
/* [>] button. */
|
|
|
|
|
leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum + 2, AWV_INCREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
|
|
|
|
leaf->SetFill(1, 1);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
vert_buttons->Add(hor);
|
|
|
|
|
|
|
|
|
|
widnum += MOS_WIDG_PER_SETTING;
|
|
|
|
|
}
|
|
|
|
|
*biggest_index = widnum - MOS_WIDG_PER_SETTING + 2;
|
|
|
|
|
|
|
|
|
|
/* Space between the category buttons and the global settings buttons. */
|
|
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, MOS_ABOVE_GLOBAL_SETTINGS);
|
|
|
|
|
vert_buttons->Add(spacer);
|
|
|
|
|
|
|
|
|
|
/* Bottom part of the column with buttons for global changes. */
|
|
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_DROPDOWN, COLOUR_YELLOW, WID_MO_DROP_SUMMARY, STR_EMPTY, STR_NULL);
|
|
|
|
|
leaf->SetFill(1, 1);
|
|
|
|
|
vert_buttons->Add(leaf);
|
|
|
|
|
|
|
|
|
|
leaf = new NWidgetLeaf(WWT_TEXTBTN_2, COLOUR_YELLOW, WID_MO_SOUNDTICKER, STR_STATION_BUILD_COVERAGE_OFF, STR_NULL);
|
|
|
|
|
leaf->SetFill(1, 1);
|
|
|
|
|
vert_buttons->Add(leaf);
|
|
|
|
|
|
|
|
|
|
*biggest_index = max(*biggest_index, max<int>(WID_MO_DROP_SUMMARY, WID_MO_SOUNDTICKER));
|
|
|
|
|
return vert_buttons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Make a column with descriptions for each news category and the global settings. */
|
|
|
|
|
static NWidgetBase *MakeDescriptionColumn(int *biggest_index)
|
|
|
|
|
{
|
|
|
|
|
NWidgetVertical *vert_desc = new NWidgetVertical;
|
|
|
|
|
|
|
|
|
|
/* Top-part of the column, one row for each new category. */
|
|
|
|
|
int widnum = WID_MO_START_OPTION;
|
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
|
|
|
|
|
|
/* Descriptive text. */
|
|
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, widnum + 3, _news_type_data[i].description, STR_NULL);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, 0);
|
|
|
|
|
spacer->SetFill(1, 0);
|
|
|
|
|
hor->Add(spacer);
|
|
|
|
|
vert_desc->Add(hor);
|
|
|
|
|
|
|
|
|
|
widnum += MOS_WIDG_PER_SETTING;
|
|
|
|
|
}
|
|
|
|
|
*biggest_index = widnum - MOS_WIDG_PER_SETTING + 3;
|
|
|
|
|
|
|
|
|
|
/* Space between the category descriptions and the global settings descriptions. */
|
|
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, MOS_ABOVE_GLOBAL_SETTINGS);
|
|
|
|
|
vert_desc->Add(spacer);
|
|
|
|
|
|
|
|
|
|
/* Bottom part of the column with descriptions of global changes. */
|
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, WID_MO_LABEL_SUMMARY, STR_NEWS_MESSAGES_ALL, STR_NULL);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
|
spacer = new NWidgetSpacer(0, 0);
|
|
|
|
|
spacer->SetFill(1, 0);
|
|
|
|
|
hor->Add(spacer);
|
|
|
|
|
vert_desc->Add(hor);
|
|
|
|
|
|
|
|
|
|
hor = new NWidgetHorizontal;
|
|
|
|
|
leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, WID_MO_SOUNDTICKER_LABEL, STR_NEWS_MESSAGES_SOUND, STR_NULL);
|
|
|
|
|
hor->Add(leaf);
|
|
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
|
spacer = new NWidgetSpacer(0, 0);
|
|
|
|
|
leaf->SetFill(1, 0);
|
|
|
|
|
hor->Add(spacer);
|
|
|
|
|
vert_desc->Add(hor);
|
|
|
|
|
|
|
|
|
|
*biggest_index = max(*biggest_index, max<int>(WID_MO_LABEL_SUMMARY, WID_MO_SOUNDTICKER_LABEL));
|
|
|
|
|
return vert_desc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_message_options_widgets[] = {
|
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_NEWS_MESSAGE_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
|
EndContainer(),
|
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, WID_MO_BACKGROUND),
|
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
|
NWidget(WWT_LABEL, COLOUR_BROWN, WID_MO_LABEL), SetMinimalSize(0, 14), SetDataTip(STR_NEWS_MESSAGE_TYPES, STR_NULL),
|
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
|
EndContainer(),
|
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_LEFT_EDGE, 0),
|
|
|
|
|
NWidgetFunction(MakeButtonsColumn),
|
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_COLUMN_SPACING, 0),
|
|
|
|
|
NWidgetFunction(MakeDescriptionColumn),
|
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_RIGHT_EDGE, 0),
|
|
|
|
|
EndContainer(),
|
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, MOS_BOTTOM_EDGE),
|
|
|
|
|
EndContainer(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _message_options_desc(
|
|
|
|
|
WDP_AUTO, 0, 0,
|
|
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
|
|
|
|
0,
|
|
|
|
|
_nested_message_options_widgets, lengthof(_nested_message_options_widgets)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the settings window for news messages.
|
|
|
|
|
*/
|
|
|
|
|
void ShowMessageOptions()
|
|
|
|
|
{
|
|
|
|
|
DeleteWindowByClass(WC_GAME_OPTIONS);
|
|
|
|
|
new MessageOptionsWindow(&_message_options_desc);
|
|
|
|
|
}
|
|
|
|
|