1
0
Fork 0

(svn r1598) Feature: Message history now is stickyable and resizeable

The news messages are now precisely cropped according to pixel width to fit optimal into the window.
Introduced a new date format: DATE_TINY, which is ISOish.
release/0.4.5
dominik 2005-01-22 23:13:20 +00:00
parent 8313879b3c
commit 6027e777c8
4 changed files with 44 additions and 11 deletions

View File

@ -2785,6 +2785,8 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Choose the railtype you want to replace en
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Displays which engine the left selected engine is being replaced with, if any STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Displays which engine the left selected engine is being replaced with, if any
STR_REPLACE_HELP :{BLACK}This allows you to replace one engine type with another type, when trains of the original type enter a depot STR_REPLACE_HELP :{BLACK}This allows you to replace one engine type with another type, when trains of the original type enter a depot
STR_SHORT_DATE :{WHITE}{DATE_TINY}
############ Lists rail types ############ Lists rail types
STR_RAIL_VEHICLES :Rail Vehicles STR_RAIL_VEHICLES :Rail Vehicles

View File

@ -501,10 +501,12 @@ static byte getNews(byte i)
return i; return i;
} }
static void GetNewsString(NewsItem *ni, byte *buffer) // cut string after len pixels
static void GetNewsString(NewsItem *ni, byte *buffer, uint max)
{ {
StringID str; StringID str;
byte *s, *d; byte *s, *d;
uint len = 0;
if (ni->display_mode == 3) { if (ni->display_mode == 3) {
str = _get_news_string_callback[ni->callback](ni); str = _get_news_string_callback[ni->callback](ni);
@ -521,7 +523,7 @@ static void GetNewsString(NewsItem *ni, byte *buffer)
for (;; s++) { for (;; s++) {
// cut strings that are too long // cut strings that are too long
if (s >= str_buffr + 55) { if (len >= max-24) { // add 3x "." at the end
d[0] = d[1] = d[2] = '.'; d[0] = d[1] = d[2] = '.';
d += 3; d += 3;
*d = '\0'; *d = '\0';
@ -535,6 +537,7 @@ static void GetNewsString(NewsItem *ni, byte *buffer)
d[0] = d[1] = d[2] = d[3] = ' '; d[0] = d[1] = d[2] = d[3] = ' ';
d += 4; d += 4;
} else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) {
len += _stringwidth_table[*s - 32];
*d++ = *s; *d++ = *s;
} }
} }
@ -553,17 +556,17 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
DrawWindowWidgets(w); DrawWindowWidgets(w);
if (_total_news == 0) break; if (_total_news == 0) break;
show = min(_total_news, 10); show = min(_total_news, w->vscroll.cap);
for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
// get news in correct order // get news in correct order
ni = &_news_items[getNews(p)]; ni = &_news_items[getNews(p)];
SetDParam(0, ni->date); SetDParam(0, ni->date);
DrawString(4, y, STR_00AF, 16); DrawString(4, y, STR_SHORT_DATE, 16);
GetNewsString(ni, buffer); GetNewsString(ni, buffer, w->width-90);
DoDrawString(buffer, 85, y, 16); DoDrawString(buffer, 82, y, 16);
y += 12; y += 12;
} }
@ -572,7 +575,7 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
case WE_CLICK: case WE_CLICK:
switch (e->click.widget) { switch (e->click.widget) {
case 2: { case 3: {
int y = (e->click.pt.y - 19) / 12; int y = (e->click.pt.y - 19) / 12;
byte p, q; byte p, q;
@ -601,21 +604,27 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
} }
} }
break; break;
case WE_RESIZE:
w->vscroll.cap += e->sizing.diff.y / 12;
break;
} }
} }
static const Widget _message_history_widgets[] = { static const Widget _message_history_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 399, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS}, { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 387, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP}, { WWT_STICKYBOX, RESIZE_LR, 13, 388, 399, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 388, 399, 14, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_IMGBTN, RESIZE_RB, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP},
{ WWT_SCROLLBAR, RESIZE_LRB, 13, 388, 399, 14, 127, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_RESIZEBOX, RESIZE_LRTB, 13, 388, 399, 128, 139, 0x0, STR_RESIZE_BUTTON},
{ WIDGETS_END}, { WIDGETS_END},
}; };
static const WindowDesc _message_history_desc = { static const WindowDesc _message_history_desc = {
240, 22, 400, 140, 240, 22, 400, 140,
WC_MESSAGE_HISTORY, 0, WC_MESSAGE_HISTORY, 0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_message_history_widgets, _message_history_widgets,
MessageHistoryWndProc MessageHistoryWndProc
}; };
@ -630,6 +639,10 @@ void ShowMessageHistory(void)
if (w != NULL) { if (w != NULL) {
w->vscroll.cap = 10; w->vscroll.cap = 10;
w->vscroll.count = _total_news; w->vscroll.count = _total_news;
w->resize.step_height = 12;
w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
w->resize.step_width = 1;
w->resize.width = 200; // can't make window any smaller than 200 pixel
SetWindowDirty(w); SetWindowDirty(w);
} }
} }

View File

@ -266,6 +266,7 @@ static const CmdStruct _cmd_structs[] = {
{"TOWN", EmitSingleByte, 0x9B}, {"TOWN", EmitSingleByte, 0x9B},
{"CURRENCY64", EmitSingleByte, 0x9C}, {"CURRENCY64", EmitSingleByte, 0x9C},
{"WAYPOINT", EmitSingleByte, 0x9D}, // waypoint name {"WAYPOINT", EmitSingleByte, 0x9D}, // waypoint name
{"DATE_TINY", EmitSingleByte, 0x9E},
// 0x9E=158 is the LAST special character we may use. // 0x9E=158 is the LAST special character we may use.
{"UPARROW", EmitSingleByte, 0xA0}, {"UPARROW", EmitSingleByte, 0xA0},

View File

@ -259,6 +259,17 @@ static byte *FormatMonthAndYear(byte *buff, uint16 number)
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
} }
static byte *FormatTinyDate(byte *buff, uint16 number)
{
const char *src;
YearMonthDay ymd;
ConvertDayToYMD(&ymd, number);
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL);
return buff;
}
uint GetCurrentCurrencyRate(void) uint GetCurrentCurrencyRate(void)
{ {
return (&_currency_specs[_opt.currency])->rate; return (&_currency_specs[_opt.currency])->rate;
@ -478,6 +489,12 @@ static byte *DecodeString(byte *buff, const byte *str)
buff = GetString(buff, str); buff = GetString(buff, str);
} break; } break;
case 0x9E: { // {DATE_TINY}
buff = FormatTinyDate(buff, GetParamUint16());
break;
}
// case 0x88..0x98: // {COLORS} // case 0x88..0x98: // {COLORS}
// case 0xE: // {TINYFONT} // case 0xE: // {TINYFONT}
// case 0xF: // {BIGFONT} // case 0xF: // {BIGFONT}