1
0
Fork 0

(svn r7066) -Codechange: Factorise common code

release/0.5
tron 2006-11-05 11:17:33 +00:00
parent 2a53bcf2b0
commit 24cce7bfa1
1 changed files with 59 additions and 69 deletions

View File

@ -814,11 +814,23 @@ static void ViewportAddTownNames(DrawPixelInfo *dpi)
} }
} }
static void AddStation(const Station *st, StringID str, uint16 width)
{
StringSpriteToDraw *sstd;
sstd = AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities, 0);
if (sstd != NULL) {
sstd->color = (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner];
sstd->width = width;
}
}
static void ViewportAddStationNames(DrawPixelInfo *dpi) static void ViewportAddStationNames(DrawPixelInfo *dpi)
{ {
int left, top, right, bottom; int left, top, right, bottom;
Station *st; const Station *st;
StringSpriteToDraw *sstd;
if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU) if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU)
return; return;
@ -834,12 +846,7 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
top < st->sign.top + 12 && top < st->sign.top + 12 &&
right > st->sign.left && right > st->sign.left &&
left < st->sign.left + st->sign.width_1) { left < st->sign.left + st->sign.width_1) {
AddStation(st, STR_305C_0, st->sign.width_1);
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0);
if (sstd != NULL) {
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner];
sstd->width = st->sign.width_1;
}
} }
} }
} else if (dpi->zoom == 1) { } else if (dpi->zoom == 1) {
@ -851,12 +858,7 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
top < st->sign.top + 24 && top < st->sign.top + 24 &&
right > st->sign.left && right > st->sign.left &&
left < st->sign.left + st->sign.width_1*2) { left < st->sign.left + st->sign.width_1*2) {
AddStation(st, STR_305C_0, st->sign.width_1);
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0);
if (sstd != NULL) {
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner];
sstd->width = st->sign.width_1;
}
} }
} }
@ -871,22 +873,29 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
top < st->sign.top + 24 && top < st->sign.top + 24 &&
right > st->sign.left && right > st->sign.left &&
left < st->sign.left + st->sign.width_2*4) { left < st->sign.left + st->sign.width_2*4) {
AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
}
}
}
}
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_STATION_SIGN_TINY, st->index, st->facilities, 0);
static void AddSign(const Sign *si, StringID str, uint16 width)
{
StringSpriteToDraw *sstd;
sstd = AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->str, 0, 0);
if (sstd != NULL) { if (sstd != NULL) {
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner]; sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
sstd->width = st->sign.width_2 | 0x8000; sstd->width = width;
}
}
}
} }
} }
static void ViewportAddSigns(DrawPixelInfo *dpi) static void ViewportAddSigns(DrawPixelInfo *dpi)
{ {
Sign *si; const Sign *si;
int left, top, right, bottom; int left, top, right, bottom;
StringSpriteToDraw *sstd;
if (!(_display_opt & DO_SHOW_SIGNS)) if (!(_display_opt & DO_SHOW_SIGNS))
return; return;
@ -902,12 +911,7 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
top < si->sign.top + 12 && top < si->sign.top + 12 &&
right > si->sign.left && right > si->sign.left &&
left < si->sign.left + si->sign.width_1) { left < si->sign.left + si->sign.width_1) {
AddSign(si, STR_2806, si->sign.width_1);
sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0);
if (sstd != NULL) {
sstd->width = si->sign.width_1;
sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
}
} }
} }
} else if (dpi->zoom == 1) { } else if (dpi->zoom == 1) {
@ -918,12 +922,7 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
top < si->sign.top + 24 && top < si->sign.top + 24 &&
right > si->sign.left && right > si->sign.left &&
left < si->sign.left + si->sign.width_1 * 2) { left < si->sign.left + si->sign.width_1 * 2) {
AddSign(si, STR_2806, si->sign.width_1);
sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0);
if (sstd != NULL) {
sstd->width = si->sign.width_1;
sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
}
} }
} }
} else { } else {
@ -935,23 +934,29 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
top < si->sign.top + 24 && top < si->sign.top + 24 &&
right > si->sign.left && right > si->sign.left &&
left < si->sign.left + si->sign.width_2 * 4) { left < si->sign.left + si->sign.width_2 * 4) {
AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
}
}
}
}
sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2002, si->str, 0, 0);
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
{
StringSpriteToDraw *sstd;
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, 0);
if (sstd != NULL) { if (sstd != NULL) {
sstd->width = si->sign.width_2 | 0x8000; sstd->color = (wp->deleted ? 0xE : 11);
sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; sstd->width = width;
}
}
}
} }
} }
static void ViewportAddWaypoints(DrawPixelInfo *dpi) static void ViewportAddWaypoints(DrawPixelInfo *dpi)
{ {
Waypoint *wp; const Waypoint *wp;
int left, top, right, bottom; int left, top, right, bottom;
StringSpriteToDraw *sstd;
if (!(_display_opt & DO_WAYPOINTS)) if (!(_display_opt & DO_WAYPOINTS))
return; return;
@ -967,12 +972,7 @@ static void ViewportAddWaypoints(DrawPixelInfo *dpi)
top < wp->sign.top + 12 && top < wp->sign.top + 12 &&
right > wp->sign.left && right > wp->sign.left &&
left < wp->sign.left + wp->sign.width_1) { left < wp->sign.left + wp->sign.width_1) {
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
if (sstd != NULL) {
sstd->width = wp->sign.width_1;
sstd->color = (wp->deleted ? 0xE : 11);
}
} }
} }
} else if (dpi->zoom == 1) { } else if (dpi->zoom == 1) {
@ -983,12 +983,7 @@ static void ViewportAddWaypoints(DrawPixelInfo *dpi)
top < wp->sign.top + 24 && top < wp->sign.top + 24 &&
right > wp->sign.left && right > wp->sign.left &&
left < wp->sign.left + wp->sign.width_1*2) { left < wp->sign.left + wp->sign.width_1*2) {
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
if (sstd != NULL) {
sstd->width = wp->sign.width_1;
sstd->color = (wp->deleted ? 0xE : 11);
}
} }
} }
} else { } else {
@ -1000,12 +995,7 @@ static void ViewportAddWaypoints(DrawPixelInfo *dpi)
top < wp->sign.top + 24 && top < wp->sign.top + 24 &&
right > wp->sign.left && right > wp->sign.left &&
left < wp->sign.left + wp->sign.width_2*4) { left < wp->sign.left + wp->sign.width_2*4) {
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT_TINY, wp->index, 0, 0);
if (sstd != NULL) {
sstd->width = wp->sign.width_2 | 0x8000;
sstd->color = (wp->deleted ? 0xE : 11);
}
} }
} }
} }
@ -1132,6 +1122,8 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss
dp.height >>= zoom; dp.height >>= zoom;
do { do {
uint16 colour;
if (ss->width != 0) { if (ss->width != 0) {
int x = (ss->x >> zoom) - 1; int x = (ss->x >> zoom) - 1;
int y = (ss->y >> zoom) - 1; int y = (ss->y >> zoom) - 1;
@ -1165,16 +1157,14 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss
) && ss->width != 0) { ) && ss->width != 0) {
/* Real colors need the IS_PALETTE_COLOR flag /* Real colors need the IS_PALETTE_COLOR flag
* otherwise colors from _string_colormap are assumed. */ * otherwise colors from _string_colormap are assumed. */
DrawString( colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR;
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
ss->string, _colour_gradient[ss->color][6] | IS_PALETTE_COLOR
);
} else { } else {
colour = 16;
}
DrawString( DrawString(
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
ss->string, 16 ss->string, colour
); );
}
ss = ss->next; ss = ss->next;
} while (ss != NULL); } while (ss != NULL);