diff options
author | rubidium <rubidium@openttd.org> | 2008-05-16 07:08:04 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-05-16 07:08:04 +0000 |
commit | 083d7e8726c27e4cc5ad7c875deaf37c894b0eb0 (patch) | |
tree | 71b42c2570a5e13678d6722deaf7787da0a7ade9 /src | |
parent | 5b712cf81e48c7e38bd6da6e127ad8965abf30c6 (diff) | |
download | openttd-083d7e8726c27e4cc5ad7c875deaf37c894b0eb0.tar.xz |
(svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
Diffstat (limited to 'src')
-rw-r--r-- | src/main_gui.cpp | 3 | ||||
-rw-r--r-- | src/news_gui.cpp | 17 | ||||
-rw-r--r-- | src/saveload.cpp | 5 | ||||
-rw-r--r-- | src/statusbar_gui.cpp | 18 | ||||
-rw-r--r-- | src/statusbar_gui.h | 20 |
5 files changed, 46 insertions, 17 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp index afd874643..56bac55db 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -29,6 +29,7 @@ #include "player_gui.h" #include "settings_type.h" #include "toolbar_gui.h" +#include "statusbar_gui.h" #include "variables.h" #include "tilehighlight_func.h" @@ -431,8 +432,6 @@ void SetupColorsAndInitialWindow() } } -extern void ShowStatusBar(); - void ShowVitalWindows() { AllocateToolbar(); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 5fd782cfe..0c6928e37 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -18,6 +18,7 @@ #include "string_func.h" #include "widgets/dropdown_func.h" #include "map_func.h" +#include "statusbar_gui.h" #include "table/sprites.h" #include "table/strings.h" @@ -472,8 +473,7 @@ static void ShowTicker(const NewsItem *ni) if (_news_ticker_sound) SndPlayFx(SND_16_MORSE); _statusbar_news_item = *ni; - Window *w = FindWindowById(WC_STATUS_BAR, 0); - if (w != NULL) WP(w, def_d).data_1 = 360; + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER); } @@ -490,8 +490,7 @@ static bool ReadyForNextItem() /* Ticker message * Check if the status bar message is still being displayed? */ - const Window *w = FindWindowById(WC_STATUS_BAR, 0); - if (w != NULL && WP(w, const def_d).data_1 > -1280) return false; + if (IsNewsTickerShown()) return false; /* Newspaper message, decrement duration counter */ if (ni->duration != 0) ni->duration--; @@ -517,15 +516,9 @@ static void MoveToNextItem() switch (_news_type_data[type].display) { default: NOT_REACHED(); - case ND_OFF: { // Off - show nothing only a small reminder in the status bar - Window *w = FindWindowById(WC_STATUS_BAR, 0); - - if (w != NULL) { - WP(w, def_d).data_2 = 91; - w->SetDirty(); - } + case ND_OFF: // Off - show nothing only a small reminder in the status bar + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER); break; - } case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full if (!(ni->flags & NF_FORCE_BIG)) { diff --git a/src/saveload.cpp b/src/saveload.cpp index 3178efdcf..b69fdbfe2 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -30,6 +30,7 @@ #include "core/endian_func.hpp" #include "vehicle_base.h" #include "autoreplace_base.h" +#include "statusbar_gui.h" #include <list> #include "table/strings.h" @@ -1493,7 +1494,7 @@ static void SaveFileStart() _fast_forward = 0; if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE); - InvalidateWindowData(WC_STATUS_BAR, 0, true); + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START); _ts.saveinprogress = true; } @@ -1504,7 +1505,7 @@ static void SaveFileDone() _fast_forward = _ts.ff_state; if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); - InvalidateWindowData(WC_STATUS_BAR, 0, false); + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH); _ts.saveinprogress = false; } diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 535636e4c..18d103918 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -18,6 +18,7 @@ #include "window_gui.h" #include "variables.h" #include "window_func.h" +#include "statusbar_gui.h" #include "table/strings.h" #include "table/sprites.h" @@ -107,7 +108,13 @@ static void StatusBarWndProc(Window *w, WindowEvent *e) } break; case WE_INVALIDATE_DATA: - WP(w, def_d).data_3 = e->we.invalidate.data; + switch (e->we.invalidate.data) { + default: NOT_REACHED(); + case SBI_SAVELOAD_START: WP(w, def_d).data_3 = true; break; + case SBI_SAVELOAD_FINISH: WP(w, def_d).data_3 = false; break; + case SBI_SHOW_TICKER: WP(w, def_d).data_1 = 360; break; + case SBI_SHOW_REMINDER: WP(w, def_d).data_2 = 91; break; + } break; case WE_CLICK: @@ -152,6 +159,15 @@ static WindowDesc _main_status_desc = { StatusBarWndProc }; +/** + * Checks whether the news ticker is currently being used. + */ +bool IsNewsTickerShown() +{ + const Window *w = FindWindowById(WC_STATUS_BAR, 0); + return w != NULL && WP(w, const def_d).data_1 > -1280; +} + void ShowStatusBar() { _main_status_desc.top = _screen.height - 12; diff --git a/src/statusbar_gui.h b/src/statusbar_gui.h new file mode 100644 index 000000000..8003bf6ea --- /dev/null +++ b/src/statusbar_gui.h @@ -0,0 +1,20 @@ +/* $Id$ */ + +/** @file statusbar_gui.h Functions, definitions and such used only by the GUI. */ + +#ifndef STATUSBAR_GUI_H +#define STATUSBAR_GUI_H + +enum StatusBarInvalidate +{ + SBI_SAVELOAD_START, + SBI_SAVELOAD_FINISH, + SBI_SHOW_TICKER, + SBI_SHOW_REMINDER, + SBI_END +}; + +bool IsNewsTickerShown(); +void ShowStatusBar(); + +#endif /* STATUSBAR_GUI_H */ |