src/news_gui.cpp
branchnoai
changeset 9724 b39bc69bb2f2
parent 9723 eee46cb39750
child 9826 9707ad4c9b60
equal deleted inserted replaced
9723:eee46cb39750 9724:b39bc69bb2f2
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 
     3 
     4 #include "stdafx.h"
     4 #include "stdafx.h"
     5 #include "openttd.h"
     5 #include "openttd.h"
     6 #include "table/sprites.h"
       
     7 #include "table/strings.h"
       
     8 #include "gui.h"
     6 #include "gui.h"
     9 #include "window_gui.h"
     7 #include "window_gui.h"
    10 #include "viewport_func.h"
     8 #include "viewport_func.h"
    11 #include "news.h"
     9 #include "news.h"
    12 #include "variables.h"
    10 #include "settings_type.h"
    13 #include "transparency.h"
    11 #include "transparency.h"
    14 #include "strings_func.h"
    12 #include "strings_func.h"
    15 #include "window_func.h"
    13 #include "window_func.h"
    16 #include "date_func.h"
    14 #include "date_func.h"
    17 #include "vehicle_base.h"
    15 #include "vehicle_base.h"
    18 #include "sound_func.h"
    16 #include "sound_func.h"
    19 #include "string_func.h"
    17 #include "string_func.h"
       
    18 #include "widgets/dropdown_func.h"
       
    19 
       
    20 #include "table/sprites.h"
       
    21 #include "table/strings.h"
    20 
    22 
    21 /** @file news_gui.cpp
    23 /** @file news_gui.cpp
    22  *
    24  *
    23  * News system is realized as a FIFO queue (in an array)
    25  * News system is realized as a FIFO queue (in an array)
    24  * The positions in the queue can't be rearranged, we only access
    26  * The positions in the queue can't be rearranged, we only access
    48 #define NB_WIDG_PER_SETTING 4
    50 #define NB_WIDG_PER_SETTING 4
    49 
    51 
    50 typedef byte NewsID;
    52 typedef byte NewsID;
    51 #define INVALID_NEWS 255
    53 #define INVALID_NEWS 255
    52 
    54 
       
    55 NewsItem _statusbar_news_item;
       
    56 uint32 _news_display_opt;
       
    57 bool _news_ticker_sound;
    53 static NewsItem _news_items[MAX_NEWS];      ///< The news FIFO queue
    58 static NewsItem _news_items[MAX_NEWS];      ///< The news FIFO queue
    54 static NewsID _current_news = INVALID_NEWS; ///< points to news item that should be shown next
    59 static NewsID _current_news = INVALID_NEWS; ///< points to news item that should be shown next
    55 static NewsID _oldest_news = 0;             ///< points to first item in fifo queue
    60 static NewsID _oldest_news = 0;             ///< points to first item in fifo queue
    56 static NewsID _latest_news = INVALID_NEWS;  ///< points to last item in fifo queue
    61 static NewsID _latest_news = INVALID_NEWS;  ///< points to last item in fifo queue
    57 
    62 
   779 }
   784 }
   780 
   785 
   781 
   786 
   782 /** News settings window widget offset constants */
   787 /** News settings window widget offset constants */
   783 enum {
   788 enum {
   784 	WIDGET_NEWSOPT_BTN_SUMMARY  = 4,  ///< Button that adjusts at once the level for all settings
   789 	WIDGET_NEWSOPT_DROP_SUMMARY = 4,  ///< Dropdown that adjusts at once the level for all settings
   785 	WIDGET_NEWSOPT_DROP_SUMMARY,      ///< Drop down button for same upper button
   790 	WIDGET_NEWSOPT_SOUNDTICKER  = 6,  ///< Button activating sound on events
   786 	WIDGET_NEWSOPT_SOUNDTICKER  = 7,  ///< Button activating sound on events
   791 	WIDGET_NEWSOPT_START_OPTION = 8,  ///< First widget that is part of a group [<] .. [.]
   787 	WIDGET_NEWSOPT_START_OPTION = 9,  ///< First widget that is part of a group [<] .. [.]
       
   788 };
   792 };
   789 
   793 
   790 /**
   794 /**
   791  * Setup the disabled/enabled buttons in the message window
   795  * Setup the disabled/enabled buttons in the message window
   792  * If the value is 'off' disable the [<] widget, and enable the [>] one
   796  * If the value is 'off' disable the [<] widget, and enable the [>] one
   834 		case WE_PAINT: {
   838 		case WE_PAINT: {
   835 			uint32 val = _news_display_opt;
   839 			uint32 val = _news_display_opt;
   836 			int i, y;
   840 			int i, y;
   837 
   841 
   838 			if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
   842 			if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
       
   843 
       
   844 			w->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = message_opt[WP(w, def_d).data_1];
   839 			DrawWindowWidgets(w);
   845 			DrawWindowWidgets(w);
   840 
   846 
   841 			/* Draw the string of each setting on each button. */
   847 			/* Draw the string of each setting on each button. */
   842 			for (i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
   848 			for (i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
   843 				/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
   849 				/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
   844 				 * which will give centered position */
   850 				 * which will give centered position */
   845 				DrawStringCentered(51, y + 1, message_opt[val & 0x3], TC_BLACK);
   851 				DrawStringCentered(51, y + 1, message_opt[val & 0x3], TC_BLACK);
   846 			}
   852 			}
   847 
       
   848 			/* Draw the general bottom button string as well */
       
   849 			DrawStringCentered(51, y + 10, message_opt[WP(w, def_d).data_1], TC_BLACK);
       
   850 		} break;
   853 		} break;
   851 
   854 
   852 		case WE_CLICK:
   855 		case WE_CLICK:
   853 			switch (e->we.click.widget) {
   856 			switch (e->we.click.widget) {
   854 				case WIDGET_NEWSOPT_BTN_SUMMARY:
       
   855 				case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
   857 				case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
   856 					ShowDropDownMenu(w, message_opt, WP(w, def_d).data_1, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
   858 					ShowDropDownMenu(w, message_opt, WP(w, def_d).data_1, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
   857 					break;
   859 					break;
   858 
   860 
   859 				case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
   861 				case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
   942 {    WWT_LABEL, RESIZE_NONE, COLOUR_BROWN,
   944 {    WWT_LABEL, RESIZE_NONE, COLOUR_BROWN,
   943 	  0, 409, 13, 26,
   945 	  0, 409, 13, 26,
   944 	STR_0205_MESSAGE_TYPES,   STR_NULL},
   946 	STR_0205_MESSAGE_TYPES,   STR_NULL},
   945 
   947 
   946 /* General drop down and sound button, widgets WIDGET_NEWSOPT_BTN_SUMMARY and WIDGET_NEWSOPT_DROP_SUMMARY */
   948 /* General drop down and sound button, widgets WIDGET_NEWSOPT_BTN_SUMMARY and WIDGET_NEWSOPT_DROP_SUMMARY */
   947 {     WWT_PANEL, RESIZE_NONE, COLOUR_YELLOW,
   949 {  WWT_DROPDOWN, RESIZE_NONE, COLOUR_YELLOW,
   948 	  4,  86,  34 + NT_END * NEWS_SETTING_BASELINE_SKIP,  45 + NT_END * NEWS_SETTING_BASELINE_SKIP,
   950 	  4,  98,  34 + NT_END * NEWS_SETTING_BASELINE_SKIP,  45 + NT_END * NEWS_SETTING_BASELINE_SKIP,
   949 	0x0, STR_NULL},
   951 	0x0, STR_NULL},
   950 
       
   951 {   WWT_TEXTBTN, RESIZE_NONE, COLOUR_YELLOW,
       
   952 	 87,  98,  34 + NT_END * NEWS_SETTING_BASELINE_SKIP,  45 + NT_END * NEWS_SETTING_BASELINE_SKIP,
       
   953 	STR_0225, STR_NULL},
       
   954 
   952 
   955 {      WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
   953 {      WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
   956 	103, 409,  35 + NT_END * NEWS_SETTING_BASELINE_SKIP,  47 + NT_END * NEWS_SETTING_BASELINE_SKIP,
   954 	103, 409,  35 + NT_END * NEWS_SETTING_BASELINE_SKIP,  47 + NT_END * NEWS_SETTING_BASELINE_SKIP,
   957 	STR_MESSAGES_ALL, STR_NULL},
   955 	STR_MESSAGES_ALL, STR_NULL},
   958 
   956