Index: src/dock_gui.cpp
===================================================================
--- src/dock_gui.cpp (revision 27772)
+++ src/dock_gui.cpp (working copy)
@@ -27,6 +27,7 @@
#include "hotkeys.h"
#include "gui.h"
#include "zoom_func.h"
+#include "transparency.h"
#include "widgets/dock_widget.h"
@@ -106,6 +107,7 @@
~BuildDocksToolbarWindow()
{
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
+ StopTempTransparency();
}
/**
@@ -126,6 +128,7 @@
if (!can_build) {
DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
+ StopTempTransparency();
}
}
@@ -133,39 +136,45 @@
{
switch (widget) {
case WID_DT_CANAL: // Build canal button
- HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
+ if (HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT)) StartTempTransparency();
break;
case WID_DT_LOCK: // Build lock button
- HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
+ if (HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL)) StartTempTransparency();
break;
case WID_DT_DEMOLISH: // Demolish aka dynamite button
- HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
+ if (HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL)) StartTempTransparency();
break;
case WID_DT_DEPOT: // Build depot button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
- if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
+ if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) {
+ ShowBuildDocksDepotPicker(this);
+ StartTempTransparency();
+ }
break;
case WID_DT_STATION: // Build station button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
- if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
+ if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) {
+ ShowBuildDockStationPicker(this);
+ StartTempTransparency();
+ }
break;
case WID_DT_BUOY: // Build buoy button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
- HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
+ if (HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT)) StartTempTransparency();
break;
case WID_DT_RIVER: // Build river button (in scenario editor)
if (_game_mode != GM_EDITOR) return;
- HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
+ if (HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT)) StartTempTransparency();
break;
case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
- HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
+ if (HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL)) StartTempTransparency();
break;
default: return;
@@ -254,6 +263,7 @@
DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
DeleteWindowById(WC_SELECT_STATION, 0);
DeleteWindowByClass(WC_BUILD_BRIDGE);
+ StopTempTransparency();
}
virtual void OnPlacePresize(Point pt, TileIndex tile_from)
@@ -348,6 +358,7 @@
if (!Company::IsValidID(_local_company)) return NULL;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
+ StopTempTransparency();
return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
}
@@ -407,7 +418,9 @@
virtual ~BuildDocksStationWindow()
{
+
DeleteWindowById(WC_SELECT_STATION, 0);
+ StopTempTransparency();
}
virtual void OnPaint()
@@ -502,9 +515,17 @@
{
this->InitNested(TRANSPORT_WATER);
this->LowerWidget(_ship_depot_direction + WID_BDD_X);
+ StartTempTransparency();
UpdateDocksDirection();
}
+ virtual ~BuildDocksDepotWindow()
+ {
+
+ DeleteWindowById(WC_SELECT_STATION, 0);
+ StopTempTransparency();
+ }
+
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
switch (widget) {
Index: src/transparency.h
===================================================================
--- src/transparency.h (revision 27772)
+++ src/transparency.h (working copy)
@@ -37,7 +37,9 @@
typedef uint TransparencyOptionBits; ///< transparency option bits
extern TransparencyOptionBits _transparency_opt;
+extern TransparencyOptionBits _transparency_opt_tmp;
extern TransparencyOptionBits _transparency_lock;
+extern TransparencyOptionBits _transparency_lock_tmp;
extern TransparencyOptionBits _invisibility_opt;
extern byte _display_opt;
@@ -71,6 +73,7 @@
static inline void ToggleTransparency(TransparencyOption to)
{
ToggleBit(_transparency_opt, to);
+ if (_transparency_opt_tmp != NULL) ToggleBit(_transparency_opt_tmp, to);
}
/**
@@ -109,6 +112,7 @@
static inline void ToggleTransparencyLock(TransparencyOption to)
{
ToggleBit(_transparency_lock, to);
+ if (_transparency_lock_tmp != NULL) ToggleBit(_transparency_lock_tmp, to);
}
/** Set or clear all non-locked transparency options */
@@ -126,4 +130,30 @@
MarkWholeScreenDirty();
}
+/**
+ * Temporarily store transparency options and locks for later
+ * restoration and set all non-locked transparency options.
+ */
+static inline void StartTempTransparency()
+{
+ _transparency_opt_tmp = _transparency_opt;
+ _transparency_lock_tmp = _transparency_opt_tmp | _transparency_lock;
+ _transparency_opt |= GB(~_transparency_lock_tmp, 0, TO_END);
+
+ MarkWholeScreenDirty();
+}
+
+/**
+ * Restore transparency options and clear temporary
+ * transparency options and locks.
+ */
+static inline void StopTempTransparency()
+{
+ _transparency_opt &= _transparency_lock_tmp;
+ _transparency_opt_tmp = NULL;
+ _transparency_lock_tmp = NULL;
+
+ MarkWholeScreenDirty();
+}
+
#endif /* TRANSPARENCY_H */
Index: src/transparency_gui.cpp
===================================================================
--- src/transparency_gui.cpp (revision 27772)
+++ src/transparency_gui.cpp (working copy)
@@ -22,9 +22,11 @@
#include "safeguards.h"
-TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
-TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
-TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
+TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
+TransparencyOptionBits _transparency_opt_tmp = NULL; ///< Temporary bits that should be transparent while building.
+TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
+TransparencyOptionBits _transparency_lock_tmp = NULL; ///< Prevent temporary bits from flipping while building.
+TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
byte _display_opt; ///< What do we want to draw/do?
class TransparenciesWindow : public Window