summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2007-11-10 01:17:15 +0000
committerbelugas <belugas@openttd.org>2007-11-10 01:17:15 +0000
commitf55fdfb7c42b2e2e39b165fd17f7671e14516303 (patch)
tree07b6a8f97a15f768d33fc0b7a3405373f3745b3b
parent3a84801f5563ca73c47c56f9682582abe990abb7 (diff)
downloadopenttd-f55fdfb7c42b2e2e39b165fd17f7671e14516303.tar.xz
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
-Codechange: Wrap all transparency settings in accessors, hiding the implementation -Change: Clicking "transparent building" menu will toggle Houses And Trees only. The other options can be used in the transparency gui. Initial patch by Smatz (FS#1349), with some rework by BigBB and your humble servant.
-rw-r--r--projects/openttd.vcproj3
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/elrail.cpp17
-rw-r--r--src/industry_cmd.cpp5
-rw-r--r--src/main_gui.cpp33
-rw-r--r--src/newgrf_house.cpp7
-rw-r--r--src/newgrf_industrytiles.cpp5
-rw-r--r--src/news_gui.cpp7
-rw-r--r--src/openttd.cpp3
-rw-r--r--src/openttd.h11
-rw-r--r--src/rail_cmd.cpp5
-rw-r--r--src/road_cmd.cpp11
-rw-r--r--src/settings.cpp2
-rw-r--r--src/station_cmd.cpp7
-rw-r--r--src/texteff.cpp5
-rw-r--r--src/town_cmd.cpp5
-rw-r--r--src/transparency.h69
-rw-r--r--src/transparency_gui.cpp19
-rw-r--r--src/tree_cmd.cpp5
-rw-r--r--src/tunnelbridge_cmd.cpp25
-rw-r--r--src/unmovable_cmd.cpp7
-rw-r--r--src/variables.h1
-rw-r--r--src/viewport.cpp7
-rw-r--r--src/water_cmd.cpp3
25 files changed, 165 insertions, 102 deletions
diff --git a/projects/openttd.vcproj b/projects/openttd.vcproj
index a821044e0..7ee50b846 100644
--- a/projects/openttd.vcproj
+++ b/projects/openttd.vcproj
@@ -685,6 +685,9 @@
RelativePath=".\..\src\train.h">
</File>
<File
+ RelativePath=".\..\src\transparency.h">
+ </File>
+ <File
RelativePath=".\..\src\transparency_gui.h">
</File>
<File
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index e8559486b..f4e9bf89c 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -1144,6 +1144,10 @@
>
</File>
<File
+ RelativePath=".\..\src\transparency.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\transparency_gui.h"
>
</File>
diff --git a/source.list b/source.list
index 68d5433cd..a4cc2da0a 100644
--- a/source.list
+++ b/source.list
@@ -194,6 +194,7 @@ tile.h
timetable.h
town.h
train.h
+transparency.h
transparency_gui.h
variables.h
vehicle.h
diff --git a/src/elrail.cpp b/src/elrail.cpp
index 8a0e7854c..47f854ddf 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -65,6 +65,7 @@
#include "vehicle.h"
#include "train.h"
#include "gui.h"
+#include "transparency.h"
static inline TLG GetTLG(TileIndex t)
{
@@ -195,7 +196,7 @@ void DrawCatenaryOnTunnel(const TileInfo *ti)
sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset + 1,
GetTileZ(ti->tile) + sss->z_offset,
- HASBIT(_transparent_opt, TO_BUILDINGS),
+ IsTransparencySet(TO_BUILDINGS),
BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset
);
}
@@ -342,7 +343,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
AddSortableSpriteToDraw(pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE,
GetPCPElevation(ti->tile, i),
- HASBIT(_transparent_opt, TO_BUILDINGS), -1, -1);
+ IsTransparencySet(TO_BUILDINGS), -1, -1);
break; /* We already have drawn a pylon, bail out */
}
}
@@ -350,7 +351,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
}
/* Don't draw a wire under a low bridge */
- if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !HASBIT(_transparent_opt, TO_BUILDINGS)) {
+ if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BUILDINGS)) {
uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
@@ -377,7 +378,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
*/
AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset,
- HASBIT(_transparent_opt, TO_BUILDINGS));
+ IsTransparencySet(TO_BUILDINGS));
}
}
}
@@ -410,7 +411,7 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
- HASBIT(_transparent_opt, TO_BUILDINGS)
+ IsTransparencySet(TO_BUILDINGS)
);
/* Finished with wires, draw pylons */
@@ -421,7 +422,7 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
if (HASBIT(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
- AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, HASBIT(_transparent_opt, TO_BUILDINGS), -1, -1);
+ AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1);
}
/* need a pylon on the southern end of the bridge */
@@ -431,7 +432,7 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
if (HASBIT(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
- AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, HASBIT(_transparent_opt, TO_BUILDINGS), -1, -1);
+ AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1);
}
}
@@ -457,7 +458,7 @@ void DrawCatenary(const TileInfo *ti)
sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
sss->x_size, sss->y_size, sss->z_size,
GetTileMaxZ(ti->tile) + sss->z_offset,
- HASBIT(_transparent_opt, TO_BUILDINGS)
+ IsTransparencySet(TO_BUILDINGS)
);
return;
}
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 4e846cec5..621495b94 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -38,6 +38,7 @@
#include "newgrf_callbacks.h"
#include "misc/autoptr.hpp"
#include "autoslope.h"
+#include "transparency.h"
void ShowIndustryViewWindow(int industry);
void BuildOilRig(TileIndex tile);
@@ -310,9 +311,9 @@ static void DrawTile_Industry(TileInfo *ti)
dits->height,
dits->dz,
ti->z,
- HASBIT(_transparent_opt, TO_INDUSTRIES));
+ IsTransparencySet(TO_INDUSTRIES));
- if (HASBIT(_transparent_opt, TO_INDUSTRIES)) return;
+ if (IsTransparencySet(TO_INDUSTRIES)) return;
}
{
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 9d25e6354..d84c6c2d1 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -47,6 +47,7 @@
#include "network/network_server.h"
#include "network/network_gui.h"
#include "industry.h"
+#include "transparency.h"
static int _rename_id = 1;
static int _rename_what = -1;
@@ -156,22 +157,6 @@ static void ToolbarFastForwardClick(Window *w)
}
-/** Toggle all transparency options, except for signs */
-static void ToggleTransparency()
-{
- static byte trans_opt = ~0;
-
- if (GB(_transparent_opt, 1, 7) == 0) {
- SB(_transparent_opt, 1, 7, GB(trans_opt, 1, 7));
- } else {
- trans_opt = _transparent_opt;
- SB(_transparent_opt, 1, 7, 0);
- }
-
- MarkWholeScreenDirty();
-}
-
-
static void MenuClickSettings(int index)
{
switch (index) {
@@ -187,8 +172,11 @@ static void MenuClickSettings(int index)
case 9: TOGGLEBIT(_display_opt, DO_WAYPOINTS); break;
case 10: TOGGLEBIT(_display_opt, DO_FULL_ANIMATION); break;
case 11: TOGGLEBIT(_display_opt, DO_FULL_DETAIL); break;
- case 12: ToggleTransparency(); break;
- case 13: TOGGLEBIT(_transparent_opt, TO_SIGNS); break;
+ case 12:
+ ToggleTransparency(TO_TREES);
+ ToggleTransparency(TO_HOUSES);
+ break;
+ case 13: ToggleTransparency(TO_SIGNS); break;
}
MarkWholeScreenDirty();
}
@@ -988,8 +976,8 @@ static void ToolbarOptionsClick(Window *w)
if (HASBIT(_display_opt, DO_WAYPOINTS)) SETBIT(x, 9);
if (HASBIT(_display_opt, DO_FULL_ANIMATION)) SETBIT(x, 10);
if (HASBIT(_display_opt, DO_FULL_DETAIL)) SETBIT(x, 11);
- if (GB(_transparent_opt, 1, 7) != 0) SETBIT(x, 12);
- if (HASBIT(_transparent_opt, TO_SIGNS)) SETBIT(x, 13);
+ if (IsTransparencySet(TO_HOUSES) && IsTransparencySet(TO_TREES)) SETBIT(x, 12);
+ if (IsTransparencySet(TO_SIGNS)) SETBIT(x, 13);
WP(w,menu_d).checked_items = x;
}
@@ -2259,8 +2247,9 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
case '5' | WKC_CTRL:
case '6' | WKC_CTRL:
case '7' | WKC_CTRL:
+ case '8' | WKC_CTRL:
/* Transparency toggle hot keys */
- TOGGLEBIT(_transparent_opt, e->we.keypress.keycode - ('1' | WKC_CTRL));
+ ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL)));
MarkWholeScreenDirty();
break;
@@ -2269,7 +2258,7 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
break;
case 'X':
- ToggleTransparency();
+ ResetRestoreAllTransparency();
break;
#ifdef ENABLE_NETWORK
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 568225667..a284abb67 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -25,6 +25,7 @@
#include "newgrf_town.h"
#include "newgrf_sound.h"
#include "newgrf_commons.h"
+#include "transparency.h"
static BuildingCounts _building_counts;
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
@@ -320,7 +321,7 @@ void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, Ho
if (IS_CUSTOM_SPRITE(image)) image += stage;
- if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !HASBIT(_transparent_opt, TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+ if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !IsTransparencySet(TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
if (pal == 0) {
const HouseSpec *hs = GetHouseSpecs(house_id);
if (HASBIT(hs->callback_mask, CBM_HOUSE_COLOUR)) {
@@ -343,10 +344,10 @@ void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, Ho
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z + dtss->delta_z,
- HASBIT(_transparent_opt, TO_HOUSES)
+ IsTransparencySet(TO_HOUSES)
);
} else {
- AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, HASBIT(_transparent_opt, TO_HOUSES));
+ AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_HOUSES));
}
}
}
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 6a28d350e..70420915b 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -22,6 +22,7 @@
#include "table/sprites.h"
#include "table/strings.h"
#include "sprite.h"
+#include "transparency.h"
/**
* Based on newhouses equivalent, but adapted for newindustries
@@ -195,10 +196,10 @@ void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte r
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z + dtss->delta_z,
- !HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES)
+ !HASBIT(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_INDUSTRIES)
);
} else {
- AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, HASBIT(_transparent_opt, TO_INDUSTRIES));
+ AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_INDUSTRIES));
}
}
}
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index a8d8b0e36..724ec1e78 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -17,6 +17,7 @@
#include "variables.h"
#include "date.h"
#include "string.h"
+#include "transparency.h"
/** @file news_gui.cpp
*
@@ -137,10 +138,10 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
ni->string_id, w->width - 4);
} else {
/* Back up transparency options to draw news view */
- byte to_backup = _transparent_opt;
- _transparent_opt = 0;
+ TransparencyOptionBits to_backup = _transparency_opt;
+ _transparency_opt = 0;
DrawWindowViewport(w);
- _transparent_opt = to_backup;
+ _transparency_opt = to_backup;
/* Shade the viewport into gray, or color*/
vp = w->viewport;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index d2285a318..0ab4dc4c0 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -321,9 +321,6 @@ static void LoadIntroGame()
{
_game_mode = GM_MENU;
- /* Clear transparency options */
- _transparent_opt = 0;
-
_opt_ptr = &_opt_newgame;
ResetGRFConfig(false);
diff --git a/src/openttd.h b/src/openttd.h
index 2fdf8e0a9..79cfb5783 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -187,17 +187,6 @@ enum {
DO_WAYPOINTS = 6,
};
-enum {
- TO_SIGNS,
- TO_TREES,
- TO_HOUSES,
- TO_INDUSTRIES,
- TO_BUILDINGS,
- TO_BRIDGES,
- TO_STRUCTURES,
- TO_LOADING,
-};
-
/* Landscape types */
enum {
LT_TEMPERATE = 0,
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index f0e16edf5..957c37b07 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -40,6 +40,7 @@
#include "train.h"
#include "misc/autoptr.hpp"
#include "autoslope.h"
+#include "transparency.h"
const byte _track_sloped_sprites[14] = {
14, 15, 22, 13,
@@ -1755,7 +1756,7 @@ default_waypoint:
image += relocation;
}
- if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+ if (!IsTransparencySet(TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
pal = _drawtile_track_palette;
} else {
pal = dtss->pal;
@@ -1767,7 +1768,7 @@ default_waypoint:
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z + dtss->delta_z,
- HASBIT(_transparent_opt, TO_BUILDINGS)
+ IsTransparencySet(TO_BUILDINGS)
);
} else {
AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 886593b33..68ec7d957 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -33,6 +33,7 @@
#include "tunnel_map.h"
#include "misc/autoptr.hpp"
#include "autoslope.h"
+#include "transparency.h"
#define M(x) (1 << (x))
/* Level crossings may only be built on these slopes */
@@ -946,7 +947,7 @@ static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
void DrawTramCatenary(TileInfo *ti, RoadBits tram)
{
/* Don't draw the catenary under a low bridge */
- if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !HASBIT(_transparent_opt, TO_BUILDINGS)) {
+ if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BUILDINGS)) {
uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
@@ -963,8 +964,8 @@ void DrawTramCatenary(TileInfo *ti, RoadBits tram)
front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
}
- AddSortableSpriteToDraw(back, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
- AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
+ AddSortableSpriteToDraw(back, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS));
+ AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS));
}
/**
@@ -1120,7 +1121,7 @@ static void DrawTile_Road(TileInfo *ti)
SpriteID image = dtss->image;
SpriteID pal;
- if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+ if (!IsTransparencySet(TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
pal = palette;
} else {
pal = PAL_NONE;
@@ -1131,7 +1132,7 @@ static void DrawTile_Road(TileInfo *ti)
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z,
- HASBIT(_transparent_opt, TO_BUILDINGS)
+ IsTransparencySet(TO_BUILDINGS)
);
}
break;
diff --git a/src/settings.cpp b/src/settings.cpp
index 4e35b1954..d268ff1df 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -49,6 +49,7 @@
#include "fontcache.h"
#endif
#include "spritecache.h"
+#include "transparency.h"
/** The patch values that are used for new games and/or modified in config file */
Patches _patches_newgame;
@@ -1275,6 +1276,7 @@ static const SettingDescGlobVarList _misc_settings[] = {
#endif
SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size, 4, 1, 64, 0, STR_NULL, NULL),
SDTG_VAR("player_face", SLE_UINT32, S, 0, _player_face, 0,0,0xFFFFFFFF,0, STR_NULL, NULL),
+ SDTG_VAR("transparency_options", SLE_UINT8, S, 0, _transparency_opt, 0, 0,0xFF,0, STR_NULL, NULL),
SDTG_END()
};
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 9bc18c759..dcf3f1f53 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -43,6 +43,7 @@
#include "cargotype.h"
#include "strings.h"
#include "autoslope.h"
+#include "transparency.h"
DEFINE_OLD_POOL_GENERIC(Station, Station)
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop)
@@ -2138,7 +2139,7 @@ static void DrawTile_Station(TileInfo *ti)
}
SpriteID pal;
- if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+ if (!IsTransparencySet(TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
pal = palette;
} else {
pal = dtss->pal;
@@ -2150,10 +2151,10 @@ static void DrawTile_Station(TileInfo *ti)
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z + dtss->delta_z,
- HASBIT(_transparent_opt, TO_BUILDINGS)
+ IsTransparencySet(TO_BUILDINGS)
);
} else {
- AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, HASBIT(_transparent_opt, TO_BUILDINGS));
+ AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, IsTransparencySet(TO_BUILDINGS));
}
}
}
diff --git a/src/texteff.cpp b/src/texteff.cpp
index f42a650e4..eae4e0aed 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -20,6 +20,7 @@
#include "date.h"
#include "texteff.hpp"
#include "video/video_driver.hpp"
+#include "transparency.h"
enum {
MAX_TEXTMESSAGE_LENGTH = 200,
@@ -390,7 +391,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
dpi->top <= te->bottom &&
dpi->left + dpi->width > te->x &&
dpi->top + dpi->height > te->y) {
- if (te->mode == TE_RISING || (_patches.loading_indicators && !HASBIT(_transparent_opt, TO_LOADING))) {
+ if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2);
}
}
@@ -405,7 +406,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
dpi->top <= te->bottom * 2 - te->y &&
dpi->left + dpi->width > te->x &&
dpi->top + dpi->height > te->y) {
- if (te->mode == TE_RISING || (_patches.loading_indicators && !HASBIT(_transparent_opt, TO_LOADING))) {
+ if (te->mode == TE_RISING || (_patches.loading_indicators && !IsTransparencySet(TO_LOADING))) {
AddStringToDraw(te->x, te->y, (StringID)(te->string_id - 1), te->params_1, te->params_2);
}
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 8a9e00dd5..e6891accd 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -43,6 +43,7 @@
#include "misc/autoptr.hpp"
#include "autoslope.h"
#include "waypoint.h"
+#include "transparency.h"
/* Initialize the town-pool */
DEFINE_OLD_POOL_GENERIC(Town, Town)
@@ -183,10 +184,10 @@ static void DrawTile_Town(TileInfo *ti)
dcts->height,
dcts->dz,
ti->z,
- HASBIT(_transparent_opt, TO_HOUSES)
+ IsTransparencySet(TO_HOUSES)
);
- if (HASBIT(_transparent_opt, TO_HOUSES)) return;
+ if (IsTransparencySet(TO_HOUSES)) return;
}
{
diff --git a/src/transparency.h b/src/transparency.h
new file mode 100644
index 000000000..3dae9cecc
--- /dev/null
+++ b/src/transparency.h
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/** @file transparency.h */
+
+#ifndef TRANSPARENCY_H
+#define TRANSPARENCY_H
+
+/**
+ * Transparency option bits: which position in _transparency_opt stands for which transparency.
+ * If you change the order, change the order of the ShowTransparencyToolbar() stuff in transparency_gui.cpp too.
+ * If you add or remove an option don't forget to change the transparency 'hot keys' in main_gui.cpp.
+ * If you add an option and have more then 8, change the typedef TransparencyOptionBits and
+ * the save stuff (e.g. SLE_UINT8 to SLE_UINT16) in settings.cpp .
+ */
+enum TransparencyOption {
+ TO_SIGNS = 0, ///< signs
+ TO_TREES, ///< trees
+ TO_HOUSES, ///< town buildings
+ TO_INDUSTRIES, ///< industries
+ TO_BUILDINGS, ///< player buildings - depots, stations, HQ, ...
+ TO_BRIDGES, ///< bridges
+ TO_STRUCTURES, ///< unmovable structures
+ TO_LOADING, ///< loading indicators
+ TO_END,
+};
+
+typedef byte TransparencyOptionBits; ///< transparency option bits
+extern TransparencyOptionBits _transparency_opt;
+
+/**
+ * Check if the transparency option bit is set
+ * and if we aren't in the game menu (there's never transparency)
+ *
+ * @param to the structure which transparency option is ask for
+ */
+static inline bool IsTransparencySet(TransparencyOption to)
+{
+ return (HASBIT(_transparency_opt, to) && _game_mode != GM_MENU);
+}
+
+/**
+ * Toggle the transparency option bit
+ *
+ * @param to the structure which transparency option is toggle
+ */
+static inline void ToggleTransparency(TransparencyOption to)
+{
+ TOGGLEBIT(_transparency_opt, to);
+}
+
+/** Toggle all transparency options (except signs) or restore the stored transparencies */
+static inline void ResetRestoreAllTransparency()
+{
+ /* backup of the original transparencies or if all transparencies false toggle them to true */
+ static TransparencyOptionBits trans_opt = ~0;
+
+ if (_transparency_opt == 0) {
+ /* no structure is transparent, so restore the old transparency if present otherwise set all true */
+ _transparency_opt = trans_opt;
+ } else {
+ /* any structure is transparent, so store current transparency settings and reset it */
+ trans_opt = _transparency_opt;
+ _transparency_opt = 0;
+ }
+
+ MarkWholeScreenDirty();
+}
+
+#endif /* TRANSPARENCY_H */
diff --git a/src/transparency_gui.cpp b/src/transparency_gui.cpp
index bebb18fa1..d66f494b9 100644
--- a/src/transparency_gui.cpp
+++ b/src/transparency_gui.cpp
@@ -11,6 +11,9 @@
#include "gfx.h"
#include "sound.h"
#include "variables.h"
+#include "transparency.h"
+
+TransparencyOptionBits _transparency_opt;
enum TransparencyToolbarWidgets{
/* Widgets not toggled when pressing the X key */
@@ -27,16 +30,6 @@ enum TransparencyToolbarWidgets{
TTW_WIDGET_END, ///< End of toggle buttons
};
-/** Toggle the bits of the transparencies variable
- * when clicking on a widget, and play a sound
- * @param widget been clicked.
- */
-static void Transparent_Click(byte widget)
-{
- TOGGLEBIT(_transparent_opt, widget);
- SndPlayFx(SND_15_BEEP);
-}
-
static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -44,14 +37,16 @@ static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
/* must be sure that the widgets show the transparency variable changes
* also when we use shortcuts */
for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
- SetWindowWidgetLoweredState(w, i, HASBIT(_transparent_opt, i - TTW_WIDGET_SIGNS));
+ SetWindowWidgetLoweredState(w, i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
}
DrawWindowWidgets(w);
break;
case WE_CLICK:
if (e->we.click.widget >= TTW_WIDGET_SIGNS) {
- Transparent_Click(e->we.click.widget - TTW_WIDGET_SIGNS);
+ /* toggle the bit of the transparencies variable when clicking on a widget, and play a sound */
+ ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
+ SndPlayFx(SND_15_BEEP);
MarkWholeScreenDirty();
}
break;
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index a901143a3..3e53fbee7 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -20,6 +20,7 @@
#include "sound.h"
#include "variables.h"
#include "genworld.h"
+#include "transparency.h"
/**
* List of tree placer algorithm.
@@ -427,7 +428,7 @@ static void DrawTile_Trees(TileInfo *ti)
StartSpriteCombine();
- if (!HASBIT(_transparent_opt, TO_TREES) || !_patches.invisible_trees) {
+ if (!IsTransparencySet(TO_TREES) || !_patches.invisible_trees) {
TreeListEnt te[4];
uint i;
@@ -460,7 +461,7 @@ static void DrawTile_Trees(TileInfo *ti)
if (tep == NULL) break;
- AddSortableSpriteToDraw(tep->image, tep->pal, ti->x + tep->x, ti->y + tep->y, 16 - tep->x, 16 - tep->y, 0x30, z, HASBIT(_transparent_opt, TO_TREES), -tep->x, -tep->y);
+ AddSortableSpriteToDraw(tep->image, tep->pal, ti->x + tep->x, ti->y + tep->y, 16 - tep->x, 16 - tep->y, 0x30, z, IsTransparencySet(TO_TREES), -tep->x, -tep->y);
tep->image = 0;
}
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 1145913e2..d5ff51d95 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -33,6 +33,7 @@
#include "date.h"
#include "newgrf_sound.h"
#include "autoslope.h"
+#include "transparency.h"
#include "table/bridge_land.h"
@@ -858,12 +859,12 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis
for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) {
/* Draw front facing pillar */
if (cur_z >= front_height) {
- AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5);
+ AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
}
/* Draw back facing pillar, but not the highest part directly under the bridge-floor */
if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) {
- AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5);
+ AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
}
}
}
@@ -897,16 +898,16 @@ static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay)
/* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called
* The bounding boxes here are the same as for bridge front/roof */
- AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
+ AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, IsTransparencySet(TO_BRIDGES));
- AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BUILDINGS));
+ AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, IsTransparencySet(TO_BUILDINGS));
/* Start a new SpriteCombine for the front part */
EndSpriteCombine();
StartSpriteCombine();
/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
- AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BUILDINGS), front_bb_offset_x[offset], front_bb_offset_y[offset]);
+ AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, IsTransparencySet(TO_BUILDINGS), front_bb_offset_x[offset], front_bb_offset_y[offset]);
}
/**
@@ -969,7 +970,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
catenary = true;
StartSpriteCombine();
- AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + dir, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
+ AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + dir, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_BUILDINGS), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
}
} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
DrawCatenary(ti);
@@ -1028,7 +1029,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
* it doesn't disappear behind it
*/
AddSortableSpriteToDraw(
- psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, HASBIT(_transparent_opt, TO_BRIDGES)
+ psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, IsTransparencySet(TO_BRIDGES)
);
if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
@@ -1156,9 +1157,9 @@ void DrawBridgeMiddle(const TileInfo* ti)
/* Draw floor and far part of bridge*/
if (axis == AXIS_X) {
- AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, BRIDGE_Z_START);
+ AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
} else {
- AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, BRIDGE_Z_START);
+ AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
}
psid++;
@@ -1180,10 +1181,10 @@ void DrawBridgeMiddle(const TileInfo* ti)
/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
if (axis == AXIS_X) {
y += 12;
- if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 3, BRIDGE_Z_START);
+ if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 3, BRIDGE_Z_START);
} else {
x += 12;
- if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 3, 0, BRIDGE_Z_START);
+ if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START);
}
/* Draw TramFront as SpriteCombine */
@@ -1195,7 +1196,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
if (psid->sprite != 0) {
SpriteID image = psid->sprite;
SpriteID pal = psid->pal;
- if (HASBIT(_transparent_opt, TO_BRIDGES)) {
+ if (IsTransparencySet(TO_BRIDGES)) {
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
pal = PALETTE_TO_TRANSPARENT;
}
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index b5b9fe4c6..f711e8aab 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -25,6 +25,7 @@
#include "genworld.h"
#include "bridge.h"
#include "autoslope.h"
+#include "transparency.h"
/** Destroy a HQ.
* During normal gameplay you can only implicitely destroy a HQ when you are
@@ -129,7 +130,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
AddSortableSpriteToDraw(
dtus->image, PAL_NONE, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
dtus->width, dtus->height, dtus->z_size, ti->z,
- HASBIT(_transparent_opt, TO_STRUCTURES)
+ IsTransparencySet(TO_STRUCTURES)
);
break;
}
@@ -140,7 +141,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE);
- AddSortableSpriteToDraw(SPR_STATUE_COMPANY, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), ti->x, ti->y, 16, 16, 25, ti->z, HASBIT(_transparent_opt, TO_STRUCTURES));
+ AddSortableSpriteToDraw(SPR_STATUE_COMPANY, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), ti->x, ti->y, 16, 16, 25, ti->z, IsTransparencySet(TO_STRUCTURES));
break;
case UNMOVABLE_OWNED_LAND:
@@ -172,7 +173,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
dtss->size_x, dtss->size_y,
dtss->size_z, ti->z + dtss->delta_z,
- HASBIT(_transparent_opt, TO_STRUCTURES)
+ IsTransparencySet(TO_STRUCTURES)
);
}
break;
diff --git a/src/variables.h b/src/variables.h
index 02e18885f..da7b46f8d 100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -290,7 +290,6 @@ VARDEF bool _do_autosave;
VARDEF int _autosave_ctr;
VARDEF byte _display_opt;
-VARDEF byte _transparent_opt;
VARDEF int _caret_timer;
VARDEF uint32 _news_display_opt;
VARDEF bool _news_ticker_sound;
diff --git a/src/viewport.cpp b/src/viewport.cpp
index e03a3b948..fa816b6fb 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -26,6 +26,7 @@
#include "roadveh.h"
#include "vehicle_gui.h"
#include "blitter/factory.hpp"
+#include "transparency.h"
#define VIEWPORT_DRAW_MEM (65536 * 2)
@@ -1483,10 +1484,10 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss
/* Draw the rectangle if 'tranparent station signs' is off,
* or if we are drawing a general text sign (STR_2806) */
- if (!HASBIT(_transparent_opt, TO_SIGNS) || ss->string == STR_2806) {
+ if (!IsTransparencySet(TO_SIGNS) || ss->string == STR_2806) {
DrawFrameRect(
x, y, x + w, bottom, ss->color,
- HASBIT(_transparent_opt, TO_SIGNS) ? FR_TRANSPARENT : FR_NONE
+ IsTransparencySet(TO_SIGNS) ? FR_TRANSPARENT : FR_NONE
);
}
}
@@ -1495,7 +1496,7 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss
SetDParam(1, ss->params[1]);
/* if we didn't draw a rectangle, or if transparant building is on,
* draw the text in the color the rectangle would have */
- if (HASBIT(_transparent_opt, TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) {
+ if (IsTransparencySet(TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) {
/* Real colors need the IS_PALETTE_COLOR flag
* otherwise colors from _string_colormap are assumed. */
colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 87eaa675f..14b570dd7 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -30,6 +30,7 @@
#include "newgrf.h"
#include "newgrf_canal.h"
#include "misc/autoptr.hpp"
+#include "transparency.h"
/** Array for the shore sprites */
static const SpriteID _water_shore_sprites[] = {
@@ -449,7 +450,7 @@ static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
ti->x + wdts->delta_x, ti->y + wdts->delta_y,
wdts->width, wdts->height,
wdts->unk, ti->z + wdts->delta_z,
- HASBIT(_transparent_opt, TO_BUILDINGS));
+ IsTransparencySet(TO_BUILDINGS));
}
}