summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-20 11:40:33 +0000
committerrubidium <rubidium@openttd.org>2008-04-20 11:40:33 +0000
commit650651064b5f585a876170f0ba9e4b613f0d5fd6 (patch)
tree27579cb47236c22150f5e4f424fdeef6366666b1 /src
parent8186344628fb4d1c76c7e6d9994d1f18277a2412 (diff)
downloadopenttd-650651064b5f585a876170f0ba9e4b613f0d5fd6.tar.xz
(svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
Diffstat (limited to 'src')
-rw-r--r--src/news_func.h3
-rw-r--r--src/news_gui.cpp88
-rw-r--r--src/news_type.h10
-rw-r--r--src/settings.cpp26
4 files changed, 52 insertions, 75 deletions
diff --git a/src/news_func.h b/src/news_func.h
index bb4ea6e72..5ccbbef4d 100644
--- a/src/news_func.h
+++ b/src/news_func.h
@@ -14,10 +14,9 @@ void DrawNewsBorder(const Window *w);
void InitNewsItemStructs();
extern NewsItem _statusbar_news_item;
-extern uint32 _news_display_opt;
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
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 88495f4eb..0fe316ec0 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -53,7 +53,6 @@ typedef byte NewsID;
#define INVALID_NEWS 255
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
@@ -337,22 +336,22 @@ void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsTyp
/**
* Per-NewsType data
*/
-const NewsTypeData _news_type_data[NT_END] = {
- /* name, age, sound */
- { "arrival_player", 60, SND_1D_APPLAUSE }, ///< NT_ARRIVAL_PLAYER
- { "arrival_other", 60, SND_1D_APPLAUSE }, ///< NT_ARRIVAL_OTHER
- { "accident", 90, SND_BEGIN }, ///< NT_ACCIDENT
- { "company_info", 60, SND_BEGIN }, ///< NT_COMPANY_INFO
- { "openclose", 90, SND_BEGIN }, ///< NT_OPENCLOSE
- { "economy", 30, SND_BEGIN }, ///< NT_ECONOMY
- { "production_player", 30, SND_BEGIN }, ///< NT_INDUSTRY_PLAYER
- { "production_other", 30, SND_BEGIN }, ///< NT_INDUSTRY_OTHER
- { "production_nobody", 30, SND_BEGIN }, ///< NT_INDUSTRY_NOBODY
- { "advice", 150, SND_BEGIN }, ///< NT_ADVICE
- { "new_vehicles", 30, SND_1E_OOOOH }, ///< NT_NEW_VEHICLES
- { "acceptance", 90, SND_BEGIN }, ///< NT_ACCEPTANCE
- { "subsidies", 180, SND_BEGIN }, ///< NT_SUBSIDIES
- { "general", 60, SND_BEGIN }, ///< NT_GENERAL
+NewsTypeData _news_type_data[NT_END] = {
+ /* name, age, sound, display */
+ { "arrival_player", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_PLAYER
+ { "arrival_other", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_OTHER
+ { "accident", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCIDENT
+ { "company_info", 60, SND_BEGIN, ND_FULL }, ///< NT_COMPANY_INFO
+ { "openclose", 90, SND_BEGIN, ND_FULL }, ///< NT_OPENCLOSE
+ { "economy", 30, SND_BEGIN, ND_FULL }, ///< NT_ECONOMY
+ { "production_player", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_PLAYER
+ { "production_other", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_OTHER
+ { "production_nobody", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_NOBODY
+ { "advice", 150, SND_BEGIN, ND_FULL }, ///< NT_ADVICE
+ { "new_vehicles", 30, SND_1E_OOOOH, ND_FULL }, ///< NT_NEW_VEHICLES
+ { "acceptance", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCEPTANCE
+ { "subsidies", 180, SND_BEGIN, ND_FULL }, ///< NT_SUBSIDIES
+ { "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 */
static void ShowNewspaper(NewsItem *ni)
{
@@ -521,9 +496,9 @@ static void MoveToNextItem()
/* check the date, don't show too old items */
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();
- 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);
if (w != NULL) {
@@ -533,14 +508,14 @@ static void MoveToNextItem()
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)) {
ShowTicker(ni);
break;
}
/* Fallthrough */
- case 2: // Full - show newspaper
+ case ND_FULL: // Full - show newspaper
ShowNewspaper(ni);
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 */
switch (e->event) {
case WE_CREATE: {
- uint32 val = _news_display_opt;
- uint32 all_val;
+ NewsDisplay all_val;
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
- all_val = val & 0x3;
- for (int i = 0; i < NT_END; i++, val >>= 2) {
- SetMessageButtonStates(w, val & 0x3, i);
+ all_val = _news_type_data[0].display;
+ for (int i = 0; i < NT_END; 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 ((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 */
WP(w, def_d).data_1 = all_val;
} break;
case WE_PAINT: {
- uint32 val = _news_display_opt;
-
if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
w->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = message_opt[WP(w, def_d).data_1];
DrawWindowWidgets(w);
/* 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,
* 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;
@@ -815,10 +787,10 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
int wid = e->we.click.widget - WIDGET_NEWSOPT_START_OPTION;
if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
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);
- SetNewsDisplayValue(element, val);
+ _news_type_data[element].display = (NewsDisplay)val;
SetWindowDirty(w);
}
} break;
@@ -830,7 +802,7 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
for (int i = 0; i < NT_END; 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);
break;
diff --git a/src/news_type.h b/src/news_type.h
index d96e2171a..8ed7f8335 100644
--- a/src/news_type.h
+++ b/src/news_type.h
@@ -77,12 +77,22 @@ enum NewsBankrupcy {
};
/**
+ * 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
*/
struct NewsTypeData {
const char *const name; ///< Name
const byte age; ///< Maximum age of news items (in days)
const SoundFx sound; ///< Sound
+ NewsDisplay display; ///< Display mode (off, summary, full)
};
struct NewsItem {
diff --git a/src/settings.cpp b/src/settings.cpp
index 322b4014b..bd75029af 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1654,15 +1654,13 @@ static const SettingDesc _currency_settings[] = {
#undef NO
#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);
IniItem *item;
- /* By default, set everything to full (0xAAAAAAAA = 1010101010101010) */
- uint res = 0xAAAAAAAA;
- /* If no group exists, return everything full */
- if (group == NULL) return res;
+ /* If no group exists, return */
+ if (group == NULL) return;
for (item = group->item; item != NULL; item = item->next) {
int news_item = -1;
@@ -1678,18 +1676,16 @@ static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
}
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) {
- SB(res, news_item * 2, 2, 0);
+ _news_type_data[news_item].display = ND_OFF;
} else if (strcasecmp(item->value, "summarized") == 0) {
- SB(res, news_item * 2, 2, 1);
+ _news_type_data[news_item].display = ND_SUMMARY;
} else {
DEBUG(misc, 0, "Invalid display value: %s", item->value);
continue;
}
}
-
- return res;
}
/* 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;
}
-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);
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++) {
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)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
@@ -1847,7 +1843,7 @@ void LoadFromConfig()
HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
- _news_display_opt = NewsDisplayLoadConfig(ini, "news_display");
+ NewsDisplayLoadConfig(ini, "news_display");
CheckDifficultyLevels();
ini_free(ini);
}
@@ -1859,7 +1855,7 @@ void SaveToConfig()
HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
- NewsDisplaySaveConfig(ini, "news_display", _news_display_opt);
+ NewsDisplaySaveConfig(ini, "news_display");
SaveVersionInConfig(ini);
ini_save(_config_file, ini);
ini_free(ini);