summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--news_gui.c239
1 files changed, 126 insertions, 113 deletions
diff --git a/news_gui.c b/news_gui.c
index dd51fc6e9..eac0b4c6d 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -63,6 +63,11 @@ GetNewsStringCallbackProc * const _get_news_string_callback[] = {
void InitNewsItemStructs()
{
memset(_news_items, 0, sizeof(NewsItem)*MAX_NEWS);
+ _current_news = 255;
+ _oldest_news = 0;
+ _latest_news = 255;
+ _forced_news = 255;
+ _total_news = 0;
}
void DrawNewsBorder(Window *w)
@@ -381,8 +386,7 @@ static void MoveToNexItem()
void NewsLoop()
{
// no news item yet
- if(_total_news==0)
- return;
+ if(_total_news==0) return;
if( ReadyForNextItem() )
MoveToNexItem();
@@ -391,6 +395,8 @@ void NewsLoop()
/* Do a forced show of a specific message */
void ShowNewsMessage(byte i)
{
+ if(_total_news==0) return;
+
// Delete the news window
DeleteWindowById(WC_NEWS_WINDOW, 0);
@@ -422,121 +428,19 @@ void ShowLastNewsMessage()
}
-
-static void MessageOptionsWndProc(Window *w, WindowEvent *e)
-{
- switch(e->event) {
- case WE_PAINT: {
- uint16 x = _news_display_opt;
- uint32 cs = 0;
- int i, y;
-
- for(i=3; i!=23; i+=2) {
- cs |= 1 << (i + (x&1));
- x >>= 1;
- }
- cs |= (w->click_state >> 23) << 23;
-
- w->click_state = cs;
- DrawWindowWidgets(w);
-
- DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0);
-
- y = 27;
- for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) {
- DrawString(124, y, i, 0);
- y += 12;
- }
-
- break;
- }
-
- case WE_CLICK: {
- int wid;
- if ( (uint)(wid=e->click.widget - 3) < 20) {
- if (!(wid & 1)) {
- _news_display_opt &= ~(1 << (wid>>1));
- } else {
- _news_display_opt |= (1 << (wid>>1));
- }
- SetWindowDirty(w);
- // XXX: write settings
- }
- if( e->click.widget == 23) {
- _news_display_opt = 0;
- HandleButtonClick(w, 23);
- SetWindowDirty(w);
- }
- if( e->click.widget == 24) {
- _news_display_opt = ~0;
- HandleButtonClick(w, 24);
- SetWindowDirty(w);
- }
- } break;
- }
-}
-
-static const Widget _message_options_widgets[] = {
-{ WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, 13, 11, 369, 0, 13, STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 13, 0, 369, 14, 172, 0x0},
-{ WWT_CLOSEBOX, 3, 2, 61, 26, 37, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 26, 37, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 38, 49, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 38, 49, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 50, 61, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 50, 61, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 62, 73, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 62, 73, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 74, 85, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 74, 85, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 86, 97, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 86, 97, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 98, 109, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 98, 109, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 110, 121, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 110, 121, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 122, 133, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 122, 133, STR_02B9_FULL},
-{ WWT_CLOSEBOX, 3, 2, 61, 134, 145, STR_02B8_SUMMARY},
-{ WWT_CLOSEBOX, 3, 62, 121, 134, 145, STR_02B9_FULL},
-
-{ WWT_PUSHTXTBTN, 3, 15, 170, 154, 165, STR_MESSAGES_DISABLE_ALL, STR_NULL },
-{ WWT_PUSHTXTBTN, 3, 200, 355, 154, 165, STR_MESSAGES_ENABLE_ALL, STR_NULL },
-
-{ WWT_LAST},
-};
-
-static const WindowDesc _message_options_desc = {
- 270, 22, 370, 173,
- WC_GAME_OPTIONS,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _message_options_widgets,
- MessageOptionsWndProc
-};
-
-void ShowMessageOptions()
-{
- DeleteWindowById(WC_GAME_OPTIONS, 0);
- AllocateWindowDesc(&_message_options_desc);
-}
-
-
-
/* return news by number, with 0 being the most
-recent news. Returns false if end of queue reached. */
+recent news. Returns 255 if end of queue reached. */
static byte getNews(byte i)
{
- if(i>=MAX_NEWS)
- {
- return -1;
- }
+ if(i>=_total_news)
+ return 255;
- i = _latest_news - i;
- i = i % MAX_NEWS;
-
- if(_news_items[i].string_id == 0) return -1;
+ if(_latest_news < i)
+ i = _latest_news + MAX_NEWS - i;
+ else
+ i = _latest_news - i;
+ i = i % MAX_NEWS;
return i;
}
@@ -616,12 +520,23 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
int y = (e->click.pt.y - 19) / 12;
byte p, q;
+ /* // === DEBUG code only
+ for(p=0; p<_total_news; p++)
+ {
+ NewsItem *ni;
+ byte buffer[256];
+ ni=&_news_items[p];
+ GetNewsString(ni, buffer);
+ printf("%i\t%i\t%s\n", p, ni->date, buffer);
+ }
+ printf("=========================\n");
+ // === END OF DEBUG CODE */
+
p = y + w->vscroll.pos;
if( p > _total_news-1 ) break;
if(_latest_news >= p) q=_latest_news - p;
else q=_latest_news + MAX_NEWS - p;
-
ShowNewsMessage(q);
break;
@@ -661,3 +576,101 @@ void ShowMessageHistory()
}
}
+
+static void MessageOptionsWndProc(Window *w, WindowEvent *e)
+{
+ switch(e->event) {
+ case WE_PAINT: {
+ uint16 x = _news_display_opt;
+ uint32 cs = 0;
+ int i, y;
+
+ for(i=3; i!=23; i+=2) {
+ cs |= 1 << (i + (x&1));
+ x >>= 1;
+ }
+ cs |= (w->click_state >> 23) << 23;
+
+ w->click_state = cs;
+ DrawWindowWidgets(w);
+
+ DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0);
+
+ y = 27;
+ for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) {
+ DrawString(124, y, i, 0);
+ y += 12;
+ }
+
+ break;
+ }
+
+ case WE_CLICK: {
+ int wid;
+ if ( (uint)(wid=e->click.widget - 3) < 20) {
+ if (!(wid & 1)) {
+ _news_display_opt &= ~(1 << (wid>>1));
+ } else {
+ _news_display_opt |= (1 << (wid>>1));
+ }
+ SetWindowDirty(w);
+ // XXX: write settings
+ }
+ if( e->click.widget == 23) {
+ _news_display_opt = 0;
+ HandleButtonClick(w, 23);
+ SetWindowDirty(w);
+ }
+ if( e->click.widget == 24) {
+ _news_display_opt = ~0;
+ HandleButtonClick(w, 24);
+ SetWindowDirty(w);
+ }
+ } break;
+ }
+}
+
+static const Widget _message_options_widgets[] = {
+{ WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, 13, 11, 369, 0, 13, STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_PANEL, 13, 0, 369, 14, 172, 0x0},
+{ WWT_CLOSEBOX, 3, 2, 61, 26, 37, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 26, 37, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 38, 49, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 38, 49, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 50, 61, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 50, 61, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 62, 73, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 62, 73, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 74, 85, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 74, 85, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 86, 97, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 86, 97, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 98, 109, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 98, 109, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 110, 121, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 110, 121, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 122, 133, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 122, 133, STR_02B9_FULL},
+{ WWT_CLOSEBOX, 3, 2, 61, 134, 145, STR_02B8_SUMMARY},
+{ WWT_CLOSEBOX, 3, 62, 121, 134, 145, STR_02B9_FULL},
+
+{ WWT_PUSHTXTBTN, 3, 15, 170, 154, 165, STR_MESSAGES_DISABLE_ALL, STR_NULL },
+{ WWT_PUSHTXTBTN, 3, 200, 355, 154, 165, STR_MESSAGES_ENABLE_ALL, STR_NULL },
+
+{ WWT_LAST},
+};
+
+static const WindowDesc _message_options_desc = {
+ 270, 22, 370, 173,
+ WC_GAME_OPTIONS,0,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+ _message_options_widgets,
+ MessageOptionsWndProc
+};
+
+void ShowMessageOptions()
+{
+ DeleteWindowById(WC_GAME_OPTIONS, 0);
+ AllocateWindowDesc(&_message_options_desc);
+}