mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
This commit is contained in:
parent
b139756e2b
commit
fccfcd093b
|
@ -14,10 +14,9 @@ void DrawNewsBorder(const Window *w);
|
||||||
void InitNewsItemStructs();
|
void InitNewsItemStructs();
|
||||||
|
|
||||||
extern NewsItem _statusbar_news_item;
|
extern NewsItem _statusbar_news_item;
|
||||||
extern uint32 _news_display_opt;
|
|
||||||
extern bool _news_ticker_sound;
|
extern bool _news_ticker_sound;
|
||||||
|
|
||||||
extern const NewsTypeData _news_type_data[NT_END];
|
extern NewsTypeData _news_type_data[NT_END];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a news item type about a vehicle
|
* Delete a news item type about a vehicle
|
||||||
|
|
|
@ -53,7 +53,6 @@ typedef byte NewsID;
|
||||||
#define INVALID_NEWS 255
|
#define INVALID_NEWS 255
|
||||||
|
|
||||||
NewsItem _statusbar_news_item;
|
NewsItem _statusbar_news_item;
|
||||||
uint32 _news_display_opt;
|
|
||||||
bool _news_ticker_sound;
|
bool _news_ticker_sound;
|
||||||
static NewsItem _news_items[MAX_NEWS]; ///< The news FIFO queue
|
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 _current_news = INVALID_NEWS; ///< points to news item that should be shown next
|
||||||
|
@ -337,22 +336,22 @@ void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsTyp
|
||||||
/**
|
/**
|
||||||
* Per-NewsType data
|
* Per-NewsType data
|
||||||
*/
|
*/
|
||||||
const NewsTypeData _news_type_data[NT_END] = {
|
NewsTypeData _news_type_data[NT_END] = {
|
||||||
/* name, age, sound */
|
/* name, age, sound, display */
|
||||||
{ "arrival_player", 60, SND_1D_APPLAUSE }, ///< NT_ARRIVAL_PLAYER
|
{ "arrival_player", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_PLAYER
|
||||||
{ "arrival_other", 60, SND_1D_APPLAUSE }, ///< NT_ARRIVAL_OTHER
|
{ "arrival_other", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_OTHER
|
||||||
{ "accident", 90, SND_BEGIN }, ///< NT_ACCIDENT
|
{ "accident", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCIDENT
|
||||||
{ "company_info", 60, SND_BEGIN }, ///< NT_COMPANY_INFO
|
{ "company_info", 60, SND_BEGIN, ND_FULL }, ///< NT_COMPANY_INFO
|
||||||
{ "openclose", 90, SND_BEGIN }, ///< NT_OPENCLOSE
|
{ "openclose", 90, SND_BEGIN, ND_FULL }, ///< NT_OPENCLOSE
|
||||||
{ "economy", 30, SND_BEGIN }, ///< NT_ECONOMY
|
{ "economy", 30, SND_BEGIN, ND_FULL }, ///< NT_ECONOMY
|
||||||
{ "production_player", 30, SND_BEGIN }, ///< NT_INDUSTRY_PLAYER
|
{ "production_player", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_PLAYER
|
||||||
{ "production_other", 30, SND_BEGIN }, ///< NT_INDUSTRY_OTHER
|
{ "production_other", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_OTHER
|
||||||
{ "production_nobody", 30, SND_BEGIN }, ///< NT_INDUSTRY_NOBODY
|
{ "production_nobody", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_NOBODY
|
||||||
{ "advice", 150, SND_BEGIN }, ///< NT_ADVICE
|
{ "advice", 150, SND_BEGIN, ND_FULL }, ///< NT_ADVICE
|
||||||
{ "new_vehicles", 30, SND_1E_OOOOH }, ///< NT_NEW_VEHICLES
|
{ "new_vehicles", 30, SND_1E_OOOOH, ND_FULL }, ///< NT_NEW_VEHICLES
|
||||||
{ "acceptance", 90, SND_BEGIN }, ///< NT_ACCEPTANCE
|
{ "acceptance", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCEPTANCE
|
||||||
{ "subsidies", 180, SND_BEGIN }, ///< NT_SUBSIDIES
|
{ "subsidies", 180, SND_BEGIN, ND_FULL }, ///< NT_SUBSIDIES
|
||||||
{ "general", 60, SND_BEGIN }, ///< NT_GENERAL
|
{ "general", 60, SND_BEGIN, ND_FULL }, ///< NT_GENERAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -401,30 +400,6 @@ static WindowDesc _news_type0_desc = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* @param item the item whose value is requested
|
|
||||||
* @return return the found value which is between 0-2
|
|
||||||
*/
|
|
||||||
static inline byte GetNewsDisplayValue(byte item)
|
|
||||||
{
|
|
||||||
assert(item < NT_END && GB(_news_display_opt, item * 2, 2) <= 2);
|
|
||||||
return GB(_news_display_opt, item * 2, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* @param item the item whose value is being set
|
|
||||||
* @param val new value
|
|
||||||
*/
|
|
||||||
static inline void SetNewsDisplayValue(byte item, byte val)
|
|
||||||
{
|
|
||||||
assert(item < NT_END && val <= 2);
|
|
||||||
SB(_news_display_opt, item * 2, 2, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Open up an own newspaper window for the news item */
|
/** Open up an own newspaper window for the news item */
|
||||||
static void ShowNewspaper(NewsItem *ni)
|
static void ShowNewspaper(NewsItem *ni)
|
||||||
{
|
{
|
||||||
|
@ -521,9 +496,9 @@ static void MoveToNextItem()
|
||||||
/* check the date, don't show too old items */
|
/* check the date, don't show too old items */
|
||||||
if (_date - _news_type_data[ni->type].age > ni->date) return;
|
if (_date - _news_type_data[ni->type].age > ni->date) return;
|
||||||
|
|
||||||
switch (GetNewsDisplayValue(ni->type)) {
|
switch (_news_type_data[ni->type].display) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
case 0: { // Off - show nothing only a small reminder in the status bar
|
case ND_OFF: { // Off - show nothing only a small reminder in the status bar
|
||||||
Window *w = FindWindowById(WC_STATUS_BAR, 0);
|
Window *w = FindWindowById(WC_STATUS_BAR, 0);
|
||||||
|
|
||||||
if (w != NULL) {
|
if (w != NULL) {
|
||||||
|
@ -533,14 +508,14 @@ static void MoveToNextItem()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1: // Summary - show ticker, but if forced big, cascade to full
|
case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full
|
||||||
if (!(ni->flags & NF_FORCE_BIG)) {
|
if (!(ni->flags & NF_FORCE_BIG)) {
|
||||||
ShowTicker(ni);
|
ShowTicker(ni);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Fallthrough */
|
/* Fallthrough */
|
||||||
|
|
||||||
case 2: // Full - show newspaper
|
case ND_FULL: // Full - show newspaper
|
||||||
ShowNewspaper(ni);
|
ShowNewspaper(ni);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -769,33 +744,30 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
/* WP(w, def_d).data_1 stores state of the ALL on/off/summary button */
|
/* WP(w, def_d).data_1 stores state of the ALL on/off/summary button */
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_CREATE: {
|
case WE_CREATE: {
|
||||||
uint32 val = _news_display_opt;
|
NewsDisplay all_val;
|
||||||
uint32 all_val;
|
|
||||||
|
|
||||||
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
|
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
|
||||||
all_val = val & 0x3;
|
all_val = _news_type_data[0].display;
|
||||||
for (int i = 0; i < NT_END; i++, val >>= 2) {
|
for (int i = 0; i < NT_END; i++) {
|
||||||
SetMessageButtonStates(w, val & 0x3, i);
|
SetMessageButtonStates(w, _news_type_data[i].display, i);
|
||||||
/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
|
/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
|
||||||
if ((val & 0x3) != all_val) all_val = 0;
|
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 */
|
/* If all values are the same value, the ALL-button will take over this value */
|
||||||
WP(w, def_d).data_1 = all_val;
|
WP(w, def_d).data_1 = all_val;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
uint32 val = _news_display_opt;
|
|
||||||
|
|
||||||
if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
|
if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
|
||||||
|
|
||||||
w->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = message_opt[WP(w, def_d).data_1];
|
w->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = message_opt[WP(w, def_d).data_1];
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
/* Draw the string of each setting on each button. */
|
/* Draw the string of each setting on each button. */
|
||||||
for (int i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
|
for (int i = 0, y = 26; i < NT_END; i++, y += 12) {
|
||||||
/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
|
/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
|
||||||
* which will give centered position */
|
* which will give centered position */
|
||||||
DrawStringCentered(51, y + 1, message_opt[val & 0x3], TC_BLACK);
|
DrawStringCentered(51, y + 1, message_opt[_news_type_data[i].display], TC_BLACK);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -815,10 +787,10 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
int wid = e->we.click.widget - WIDGET_NEWSOPT_START_OPTION;
|
int wid = e->we.click.widget - WIDGET_NEWSOPT_START_OPTION;
|
||||||
if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
|
if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
|
||||||
int element = wid / NB_WIDG_PER_SETTING;
|
int element = wid / NB_WIDG_PER_SETTING;
|
||||||
byte val = (GetNewsDisplayValue(element) + ((wid % NB_WIDG_PER_SETTING) ? 1 : -1)) % 3;
|
byte val = (_news_type_data[element].display + ((wid % NB_WIDG_PER_SETTING) ? 1 : -1)) % 3;
|
||||||
|
|
||||||
SetMessageButtonStates(w, val, element);
|
SetMessageButtonStates(w, val, element);
|
||||||
SetNewsDisplayValue(element, val);
|
_news_type_data[element].display = (NewsDisplay)val;
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -830,7 +802,7 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
for (int i = 0; i < NT_END; i++) {
|
for (int i = 0; i < NT_END; i++) {
|
||||||
SetMessageButtonStates(w, e->we.dropdown.index, i);
|
SetMessageButtonStates(w, e->we.dropdown.index, i);
|
||||||
SetNewsDisplayValue(i, e->we.dropdown.index);
|
_news_type_data[i].display = (NewsDisplay)e->we.dropdown.index;
|
||||||
}
|
}
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -76,6 +76,15 @@ enum NewsBankrupcy {
|
||||||
NB_BNEWCOMPANY = (4 << 4), ///< A new company has been started
|
NB_BNEWCOMPANY = (4 << 4), ///< A new company has been started
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* News display options
|
||||||
|
*/
|
||||||
|
enum NewsDisplay {
|
||||||
|
ND_OFF, ///< Only show a reminder in the status bar
|
||||||
|
ND_SUMMARY, ///< Show ticker
|
||||||
|
ND_FULL, ///< Show newspaper
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Per-NewsType data
|
* Per-NewsType data
|
||||||
*/
|
*/
|
||||||
|
@ -83,6 +92,7 @@ struct NewsTypeData {
|
||||||
const char *const name; ///< Name
|
const char *const name; ///< Name
|
||||||
const byte age; ///< Maximum age of news items (in days)
|
const byte age; ///< Maximum age of news items (in days)
|
||||||
const SoundFx sound; ///< Sound
|
const SoundFx sound; ///< Sound
|
||||||
|
NewsDisplay display; ///< Display mode (off, summary, full)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NewsItem {
|
struct NewsItem {
|
||||||
|
|
|
@ -1654,15 +1654,13 @@ static const SettingDesc _currency_settings[] = {
|
||||||
#undef NO
|
#undef NO
|
||||||
#undef CR
|
#undef CR
|
||||||
|
|
||||||
static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
|
static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
|
||||||
{
|
{
|
||||||
IniGroup *group = ini_getgroup(ini, grpname, -1);
|
IniGroup *group = ini_getgroup(ini, grpname, -1);
|
||||||
IniItem *item;
|
IniItem *item;
|
||||||
/* By default, set everything to full (0xAAAAAAAA = 1010101010101010) */
|
|
||||||
uint res = 0xAAAAAAAA;
|
|
||||||
|
|
||||||
/* If no group exists, return everything full */
|
/* If no group exists, return */
|
||||||
if (group == NULL) return res;
|
if (group == NULL) return;
|
||||||
|
|
||||||
for (item = group->item; item != NULL; item = item->next) {
|
for (item = group->item; item != NULL; item = item->next) {
|
||||||
int news_item = -1;
|
int news_item = -1;
|
||||||
|
@ -1678,18 +1676,16 @@ static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(item->value, "full") == 0) {
|
if (strcasecmp(item->value, "full") == 0) {
|
||||||
SB(res, news_item * 2, 2, 2);
|
_news_type_data[news_item].display = ND_FULL;
|
||||||
} else if (strcasecmp(item->value, "off") == 0) {
|
} else if (strcasecmp(item->value, "off") == 0) {
|
||||||
SB(res, news_item * 2, 2, 0);
|
_news_type_data[news_item].display = ND_OFF;
|
||||||
} else if (strcasecmp(item->value, "summarized") == 0) {
|
} else if (strcasecmp(item->value, "summarized") == 0) {
|
||||||
SB(res, news_item * 2, 2, 1);
|
_news_type_data[news_item].display = ND_SUMMARY;
|
||||||
} else {
|
} else {
|
||||||
DEBUG(misc, 0, "Invalid display value: %s", item->value);
|
DEBUG(misc, 0, "Invalid display value: %s", item->value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load a GRF configuration from the given group name */
|
/* Load a GRF configuration from the given group name */
|
||||||
|
@ -1745,7 +1741,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_display)
|
static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname)
|
||||||
{
|
{
|
||||||
IniGroup *group = ini_getgroup(ini, grpname, -1);
|
IniGroup *group = ini_getgroup(ini, grpname, -1);
|
||||||
IniItem **item;
|
IniItem **item;
|
||||||
|
@ -1756,9 +1752,9 @@ static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_d
|
||||||
|
|
||||||
for (int i = 0; i < NT_END; i++) {
|
for (int i = 0; i < NT_END; i++) {
|
||||||
const char *value;
|
const char *value;
|
||||||
int v = GB(news_display, i * 2, 2);
|
int v = _news_type_data[i].display;
|
||||||
|
|
||||||
value = (v == 0 ? "off" : (v == 1 ? "summarized" : "full"));
|
value = (v == ND_OFF ? "off" : (v == ND_SUMMARY ? "summarized" : "full"));
|
||||||
|
|
||||||
*item = ini_item_alloc(group, _news_type_data[i].name, strlen(_news_type_data[i].name));
|
*item = ini_item_alloc(group, _news_type_data[i].name, strlen(_news_type_data[i].name));
|
||||||
(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
|
(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
|
||||||
|
@ -1847,7 +1843,7 @@ void LoadFromConfig()
|
||||||
HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
|
HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
|
||||||
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
|
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
|
||||||
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
|
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
|
||||||
_news_display_opt = NewsDisplayLoadConfig(ini, "news_display");
|
NewsDisplayLoadConfig(ini, "news_display");
|
||||||
CheckDifficultyLevels();
|
CheckDifficultyLevels();
|
||||||
ini_free(ini);
|
ini_free(ini);
|
||||||
}
|
}
|
||||||
|
@ -1859,7 +1855,7 @@ void SaveToConfig()
|
||||||
HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
|
HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
|
||||||
GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
|
GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
|
||||||
GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
|
GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
|
||||||
NewsDisplaySaveConfig(ini, "news_display", _news_display_opt);
|
NewsDisplaySaveConfig(ini, "news_display");
|
||||||
SaveVersionInConfig(ini);
|
SaveVersionInConfig(ini);
|
||||||
ini_save(_config_file, ini);
|
ini_save(_config_file, ini);
|
||||||
ini_free(ini);
|
ini_free(ini);
|
||||||
|
|
Loading…
Reference in New Issue