news_gui.cpp File Reference

News system is realized as a FIFO queue (in an array) The positions in the queue can't be rearranged, we only access the array elements through pointers to the elements. More...

#include "stdafx.h"
#include "openttd.h"
#include "gui.h"
#include "window_gui.h"
#include "viewport_func.h"
#include "news.h"
#include "settings_type.h"
#include "transparency.h"
#include "strings_func.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_base.h"
#include "sound_func.h"
#include "string_func.h"
#include "widgets/dropdown_func.h"
#include "table/sprites.h"
#include "table/strings.h"

Go to the source code of this file.

Defines

#define MAX_NEWS   30
 Number of news items in the FIFO queue.
#define NB_WIDG_PER_SETTING   4
#define INVALID_NEWS   255
#define NEWS_SETTINGS_LINE(basey, linenum, text)
 Macro to construct one news-setting line in the news-settings window.

Typedefs

typedef byte NewsID

Enumerations

enum  { WIDGET_NEWSOPT_DROP_SUMMARY = 4, WIDGET_NEWSOPT_SOUNDTICKER = 6, WIDGET_NEWSOPT_START_OPTION = 8 }
 News settings window widget offset constants. More...

Functions

void DrawNewsNewVehicleAvail (Window *w)
void DrawNewsBankrupcy (Window *w)
static void MoveToNextItem ()
 Move to the next news item.
StringID GetNewsStringNewVehicleAvail (const NewsItem *ni)
StringID GetNewsStringBankrupcy (const NewsItem *ni)
void InitNewsItemStructs ()
 Initialize the news-items data structures.
void DrawNewsBorder (const Window *w)
static void NewsWindowProc (Window *w, WindowEvent *e)
static NewsID increaseIndex (NewsID i)
 Return the correct index in the pseudo-fifo queue and deals with overflows when increasing the index.
static NewsID decreaseIndex (NewsID i)
 Return the correct index in the pseudo-fifo queue and deals with overflows when decreasing the index.
void AddNewsItem (StringID string, uint32 flags, uint data_a, uint data_b)
 Add a new newsitem to be shown.
static byte GetNewsDisplayValue (byte item)
 Get the value of an item of the news-display settings.
static void SetNewsDisplayValue (byte item, byte val)
 Set the value of an item in the news-display settings.
static void ShowNewspaper (NewsItem *ni)
 Open up an own newspaper window for the news item.
static void ShowTicker (const NewsItem *ni)
 Show news item in the ticker.
static bool ReadyForNextItem ()
 Are we ready to show another news item? Only if nothing is in the newsticker and no newspaper is displayed.
void NewsLoop ()
static void ShowNewsMessage (NewsID i)
 Do a forced show of a specific message.
void ShowLastNewsMessage ()
 Show previous news item.
static NewsID getNews (NewsID i)
static void DrawNewsString (int x, int y, uint16 color, const NewsItem *ni, uint maxw)
 Draw an unformatted news message truncated to a maximum length.
static void MessageHistoryWndProc (Window *w, WindowEvent *e)
void ShowMessageHistory ()
 Display window with news messages history.
static void SetMessageButtonStates (Window *w, byte value, int element)
 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.
static void MessageOptionsWndProc (Window *w, WindowEvent *e)
 Event handler of the Message Options window.
void ShowMessageOptions ()
void DeleteVehicleNews (VehicleID vid, StringID news)
 Delete a news item type about a vehicle if the news item type is INVALID_STRING_ID all news about the vehicle get deleted.

Variables

NewsItem _statusbar_news_item
uint32 _news_display_opt
bool _news_ticker_sound
static NewsItem _news_items [MAX_NEWS]
 The news FIFO queue.
static NewsID _current_news = INVALID_NEWS
 points to news item that should be shown next
static NewsID _oldest_news = 0
 points to first item in fifo queue
static NewsID _latest_news = INVALID_NEWS
 points to last item in fifo queue
static NewsID _forced_news = INVALID_NEWS
 Forced news item.
static byte _total_news = 0
 Number of news items in FIFO queue.
static DrawNewsCallbackProc *const _draw_news_callback []
GetNewsStringCallbackProc *const _get_news_string_callback []
static const byte _news_items_age [NT_END]
 Maximum age of news items.
static const Widget _news_type13_widgets []
static WindowDesc _news_type13_desc
static const Widget _news_type2_widgets []
static WindowDesc _news_type2_desc
static const Widget _news_type0_widgets []
static WindowDesc _news_type0_desc
static const SoundFx _news_sounds [NT_END]
const char * _news_display_name [NT_END]
static const Widget _message_history_widgets []
static const WindowDesc _message_history_desc
static const int NEWS_SETTING_BASELINE_SKIP = 12
 Distance between two news-setting lines, should be at least 12.
static const Widget _message_options_widgets []
static const WindowDesc _message_options_desc


Detailed Description

News system is realized as a FIFO queue (in an array) The positions in the queue can't be rearranged, we only access the array elements through pointers to the elements.

Once the array is full, the oldest entry (_oldest_news) is being overwritten by the newest (_latest_news).

 * oldest                   current   lastest
 *  |                          |         |
 * [O------------F-------------C---------L           ]
 *               |
 *            forced
 * 

Of course by using an array we can have situations like

 * [----L          O-----F---------C-----------------]
 * This is where we have wrapped around the array and have
 * (MAX_NEWS - O) + L news items
 * 

Definition in file news_gui.cpp.


Define Documentation

#define NEWS_SETTINGS_LINE ( basey,
linenum,
text   ) 

Value:

{ WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
      4,  12,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
    SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
  { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, \
     13,  89,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
    STR_EMPTY, STR_NULL}, \
  { WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
     90,  98,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
    SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
        { WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW, \
    103, 409,  basey + 1 + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 13 + linenum * NEWS_SETTING_BASELINE_SKIP, \
    text, STR_NULL}
Macro to construct one news-setting line in the news-settings window.

One line consists of four widgets, namely

  • A [<] button
  • A [...] label
  • A [>] button
  • A text label describing the news category Horizontal positions of the widgets are hard-coded, vertical start position is (basey + linenum * NEWS_SETTING_BASELINE_SKIP). Height of one line is 12, with the text label shifted 1 pixel down.

First line should be widget number WIDGET_NEWSOPT_START_OPTION

Parameters:
basey,: Base Y coordinate
linenum,: Count, news-setting is the linenum-th line
text,: StringID for the text label to display

Definition at line 918 of file news_gui.cpp.


Enumeration Type Documentation

anonymous enum

News settings window widget offset constants.

Enumerator:
WIDGET_NEWSOPT_DROP_SUMMARY  Dropdown that adjusts at once the level for all settings.
WIDGET_NEWSOPT_SOUNDTICKER  Button activating sound on events.
WIDGET_NEWSOPT_START_OPTION  First widget that is part of a group [<] .. [.].

Definition at line 788 of file news_gui.cpp.


Function Documentation

void AddNewsItem ( StringID  string,
uint32  flags,
uint  data_a,
uint  data_b 
)

Add a new newsitem to be shown.

Parameters:
string String to display, can have special values based on parameter flags
flags various control bits that will show various news-types. See macro NEWS_FLAGS()
data_a news-specific value based on news type
data_b news-specific value based on news type
Note:
flags exists of 4 byte-sized extra parameters.
  1. Bits 0 - 7 display_mode, any of the NewsMode enums (NM_)
  2. Bits 8 - 15 news flags, any of the NewsFlags enums (NF_)
  3. Bits 16 - 23 news category, any of the NewsType enums (NT_)
  4. Bits 24 - 31 news callback function, any of the NewsCallback enums (DNC_)
If the display mode is NM_CALLBACK, special news is shown and parameter string has a special meaning.
  • For DNC_TRAINAVAIL, DNC_ROADAVAIL, DNC_SHIPAVAIL, DNC_AIRCRAFTAVAIL messages: StringID is the index of the engine that is shown

Definition at line 281 of file news_gui.cpp.

References _current_news, _forced_news, _latest_news, _news_items, _oldest_news, _total_news, increaseIndex(), MAX_NEWS, MoveToNextItem(), NF_INCOLOR, and SetWindowDirty().

Referenced by AircraftEntersTerminal(), ChangeIndustryProduction(), CheckOrders(), CheckSwitchToEuro(), CheckTrainCollision(), CmdBuildIndustry(), CmdPlayerCtrl(), Disaster_CoalMine_Init(), DisasterTick_Airplane(), DisasterTick_Big_Ufo(), DisasterTick_Helicopter(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), MaybeNewIndustry(), ReportNewsProductionChangeIndustry(), and ShowRejectOrAcceptNews().

static void DrawNewsString ( int  x,
int  y,
uint16  color,
const NewsItem *  ni,
uint  maxw 
) [static]

Draw an unformatted news message truncated to a maximum length.

If length exceeds maximum length it will be postfixed by '...'

Parameters:
x,y position of the string
color the color the string will be shown in
*ni NewsItem being printed
maxw maximum width of string in pixels

Definition at line 661 of file news_gui.cpp.

References NM_CALLBACK.

static byte GetNewsDisplayValue ( byte  item  )  [inline, static]

Get the value of an item of the news-display settings.

This is a little tricky since on/off/summary must use 2 bits to store the value

Parameters:
item the item whose value is requested
Returns:
return the found value which is between 0-2

Definition at line 443 of file news_gui.cpp.

References GB(), and NT_END.

Referenced by MessageOptionsWndProc(), and MoveToNextItem().

static void MessageOptionsWndProc ( Window *  w,
WindowEvent *  e 
) [static]

Event handler of the Message Options window.

Parameters:
w window pointer
e event been triggered

Definition at line 816 of file news_gui.cpp.

References GetNewsDisplayValue(), NT_END, SetMessageButtonStates(), SetNewsDisplayValue(), SetWindowDirty(), WIDGET_NEWSOPT_DROP_SUMMARY, WIDGET_NEWSOPT_SOUNDTICKER, and WIDGET_NEWSOPT_START_OPTION.

static void SetMessageButtonStates ( Window *  w,
byte  value,
int  element 
) [static]

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.

Parameters:
w Window been used
value to set in the widget
element index of the group of widget to set

Definition at line 803 of file news_gui.cpp.

References WIDGET_NEWSOPT_START_OPTION.

Referenced by MessageOptionsWndProc().

static void SetNewsDisplayValue ( byte  item,
byte  val 
) [inline, static]

Set the value of an item in the news-display settings.

This is a little tricky since on/off/summary must use 2 bits to store the value

Parameters:
item the item whose value is being set
val new value

Definition at line 455 of file news_gui.cpp.

References NT_END, and SB().

Referenced by MessageOptionsWndProc().


Variable Documentation

DrawNewsCallbackProc* const _draw_news_callback[] [static]

Initial value:

 {
  DrawNewsNewVehicleAvail,  
  DrawNewsBankrupcy,        
}

Definition at line 78 of file news_gui.cpp.

NewsID _forced_news = INVALID_NEWS [static]

Forced news item.

Users can force an item by accessing the history or "last message". If the message being shown was forced by the user, its index is stored in _forced_news. Otherwise, _forced_news variable is INVALID_NEWS.

Definition at line 67 of file news_gui.cpp.

Referenced by AddNewsItem(), DeleteVehicleNews(), InitNewsItemStructs(), MoveToNextItem(), ReadyForNextItem(), ShowLastNewsMessage(), ShowNewsMessage(), and ShowNewspaper().

GetNewsStringCallbackProc* const _get_news_string_callback[]

Initial value:

 {
  GetNewsStringNewVehicleAvail,  
  GetNewsStringBankrupcy,        
}

Definition at line 84 of file news_gui.cpp.

const WindowDesc _message_history_desc [static]

Initial value:

 {
  240, 22, 400, 140, 400, 140,
  WC_MESSAGE_HISTORY, WC_NONE,
  WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  _message_history_widgets,
  MessageHistoryWndProc
}

Definition at line 759 of file news_gui.cpp.

const Widget _message_history_widgets[] [static]

Initial value:

 {
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},
{    WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   387,     0,    13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{  WWT_STICKYBOX,     RESIZE_LR,    13,   388,   399,     0,    13, 0x0,                 STR_STICKY_BUTTON},
{      WWT_PANEL,     RESIZE_RB,    13,     0,   387,    14,   139, 0x0,                 STR_MESSAGE_HISTORY_TIP},
{  WWT_SCROLLBAR,    RESIZE_LRB,    13,   388,   399,    14,   127, 0x0,                 STR_0190_SCROLL_BAR_SCROLLS_LIST},
{  WWT_RESIZEBOX,   RESIZE_LRTB,    13,   388,   399,   128,   139, 0x0,                 STR_RESIZE_BUTTON},
{   WIDGETS_END},
}

Definition at line 749 of file news_gui.cpp.

const WindowDesc _message_options_desc [static]

Initial value:

 {
  270,  22,  410,  65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
             410,  65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
  WC_GAME_OPTIONS, WC_NONE,
  WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
  _message_options_widgets,
  MessageOptionsWndProc
}

Definition at line 987 of file news_gui.cpp.

const char* _news_display_name[NT_END]

Initial value:

 {
  "arrival_player",
  "arrival_other",
  "accident",
  "company_info",
  "openclose",
  "economy",
  "production_player",
  "production_other",
  "production_nobody",
  "advice",
  "new_vehicles",
  "acceptance",
  "subsidies",
  "general",
}

Definition at line 420 of file news_gui.cpp.

const byte _news_items_age[NT_END] [static]

Initial value:

 {
  60,  
  60,  
  90,  
  60,  
  90,  
  30,  
  30,  
  30,  
  30,  
  150, 
  30,  
  90,  
  180, 
  60   
}
Maximum age of news items.

Don't show item if it's older than x days, corresponds with NewsType in news.h

See also:
NewsType

Definition at line 341 of file news_gui.cpp.

const SoundFx _news_sounds[NT_END] [static]

Initial value:

 {
  SND_1D_APPLAUSE,  
  SND_1D_APPLAUSE,  
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
  SND_1E_OOOOH,   
  SND_BEGIN,    
  SND_BEGIN,    
  SND_BEGIN,    
}

Definition at line 403 of file news_gui.cpp.

WindowDesc _news_type0_desc [static]

Initial value:

 {
  WDP_CENTER, 476, 280, 87, 280, 87,
  WC_NEWS_WINDOW, WC_NONE,
  WDF_DEF_WIDGET,
  _news_type0_widgets,
  NewsWindowProc
}

Definition at line 395 of file news_gui.cpp.

const Widget _news_type0_widgets[] [static]

Initial value:

 {
{      WWT_PANEL,   RESIZE_NONE,     5,     0,   279,    14,    86, 0x0,              STR_NULL},
{   WWT_CLOSEBOX,   RESIZE_NONE,     5,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
{    WWT_CAPTION,   RESIZE_NONE,     5,    11,   279,     0,    13, STR_012C_MESSAGE, STR_NULL},
{      WWT_INSET,   RESIZE_NONE,     5,     2,   277,    16,    64, 0x0,              STR_NULL},
{   WIDGETS_END},
}

Definition at line 387 of file news_gui.cpp.

WindowDesc _news_type13_desc [static]

Initial value:

 {
  WDP_CENTER, 476, 430, 170, 430, 170,
  WC_NEWS_WINDOW, WC_NONE,
  WDF_DEF_WIDGET,
  _news_type13_widgets,
  NewsWindowProc
}

Definition at line 365 of file news_gui.cpp.

const Widget _news_type13_widgets[] [static]

Initial value:

 {
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
{      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
{   WIDGETS_END},
}

Definition at line 359 of file news_gui.cpp.

WindowDesc _news_type2_desc [static]

Initial value:

 {
  WDP_CENTER, 476, 430, 130, 430, 130,
  WC_NEWS_WINDOW, WC_NONE,
  WDF_DEF_WIDGET,
  _news_type2_widgets,
  NewsWindowProc
}

Definition at line 379 of file news_gui.cpp.

const Widget _news_type2_widgets[] [static]

Initial value:

 {
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   129, 0x0, STR_NULL},
{      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
{   WIDGETS_END},
}

Definition at line 373 of file news_gui.cpp.

byte _total_news = 0 [static]

Number of news items in FIFO queue.

See also:
_news_items

Definition at line 69 of file news_gui.cpp.

Referenced by AddNewsItem(), DeleteVehicleNews(), InitNewsItemStructs(), ShowMessageHistory(), and ShowNewsMessage().


Generated on Wed Oct 1 17:03:29 2008 for openttd by  doxygen 1.5.6