Loading

temporary transparency

  1. Index: src/dock_gui.cpp
  2. ===================================================================
  3. --- src/dock_gui.cpp    (revision 27772)
  4. +++ src/dock_gui.cpp    (working copy)
  5. @@ -27,6 +27,7 @@
  6.  #include "hotkeys.h"
  7.  #include "gui.h"
  8.  #include "zoom_func.h"
  9. +#include "transparency.h"
  10.  
  11.  #include "widgets/dock_widget.h"
  12.  
  13. @@ -106,6 +107,7 @@
  14.     ~BuildDocksToolbarWindow()
  15.     {
  16.         if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
  17. +       StopTempTransparency();
  18.     }
  19.  
  20.     /**
  21. @@ -126,6 +128,7 @@
  22.         if (!can_build) {
  23.             DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
  24.             DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
  25. +           StopTempTransparency();
  26.         }
  27.     }
  28.  
  29. @@ -133,39 +136,45 @@
  30.     {
  31.         switch (widget) {
  32.             case WID_DT_CANAL: // Build canal button
  33. -               HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
  34. +               if (HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT)) StartTempTransparency();
  35.                 break;
  36.  
  37.             case WID_DT_LOCK: // Build lock button
  38. -               HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
  39. +               if (HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL)) StartTempTransparency();
  40.                 break;
  41.  
  42.             case WID_DT_DEMOLISH: // Demolish aka dynamite button
  43. -               HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
  44. +               if (HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL)) StartTempTransparency();
  45.                 break;
  46.  
  47.             case WID_DT_DEPOT: // Build depot button
  48.                 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  49. -               if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
  50. +               if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) {
  51. +                   ShowBuildDocksDepotPicker(this);
  52. +                   StartTempTransparency();
  53. +               }
  54.                 break;
  55.  
  56.             case WID_DT_STATION: // Build station button
  57.                 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  58. -               if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
  59. +               if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) {
  60. +                   ShowBuildDockStationPicker(this);
  61. +                   StartTempTransparency();
  62. +               }
  63.                 break;
  64.  
  65.             case WID_DT_BUOY: // Build buoy button
  66.                 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  67. -               HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
  68. +               if (HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT)) StartTempTransparency();
  69.                 break;
  70.  
  71.             case WID_DT_RIVER: // Build river button (in scenario editor)
  72.                 if (_game_mode != GM_EDITOR) return;
  73. -               HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
  74. +               if (HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT)) StartTempTransparency();
  75.                 break;
  76.  
  77.             case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
  78. -               HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
  79. +               if (HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL)) StartTempTransparency();
  80.                 break;
  81.  
  82.             default: return;
  83. @@ -254,6 +263,7 @@
  84.         DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
  85.         DeleteWindowById(WC_SELECT_STATION, 0);
  86.         DeleteWindowByClass(WC_BUILD_BRIDGE);
  87. +       StopTempTransparency();
  88.     }
  89.  
  90.     virtual void OnPlacePresize(Point pt, TileIndex tile_from)
  91. @@ -348,6 +358,7 @@
  92.     if (!Company::IsValidID(_local_company)) return NULL;
  93.  
  94.     DeleteWindowByClass(WC_BUILD_TOOLBAR);
  95. +   StopTempTransparency();
  96.     return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
  97.  }
  98.  
  99. @@ -407,7 +418,9 @@
  100.  
  101.     virtual ~BuildDocksStationWindow()
  102.     {
  103. +      
  104.         DeleteWindowById(WC_SELECT_STATION, 0);
  105. +       StopTempTransparency();
  106.     }
  107.  
  108.     virtual void OnPaint()
  109. @@ -502,9 +515,17 @@
  110.     {
  111.         this->InitNested(TRANSPORT_WATER);
  112.         this->LowerWidget(_ship_depot_direction + WID_BDD_X);
  113. +       StartTempTransparency();
  114.         UpdateDocksDirection();
  115.     }
  116.  
  117. +   virtual ~BuildDocksDepotWindow()
  118. +   {
  119. +
  120. +       DeleteWindowById(WC_SELECT_STATION, 0);
  121. +       StopTempTransparency();
  122. +   }
  123. +
  124.     virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
  125.     {
  126.         switch (widget) {
  127. Index: src/transparency.h
  128. ===================================================================
  129. --- src/transparency.h  (revision 27772)
  130. +++ src/transparency.h  (working copy)
  131. @@ -37,7 +37,9 @@
  132.  
  133.  typedef uint TransparencyOptionBits; ///< transparency option bits
  134.  extern TransparencyOptionBits _transparency_opt;
  135. +extern TransparencyOptionBits _transparency_opt_tmp;
  136.  extern TransparencyOptionBits _transparency_lock;
  137. +extern TransparencyOptionBits _transparency_lock_tmp;
  138.  extern TransparencyOptionBits _invisibility_opt;
  139.  extern byte _display_opt;
  140.  
  141. @@ -71,6 +73,7 @@
  142.  static inline void ToggleTransparency(TransparencyOption to)
  143.  {
  144.     ToggleBit(_transparency_opt, to);
  145. +   if (_transparency_opt_tmp != NULL) ToggleBit(_transparency_opt_tmp, to);
  146.  }
  147.  
  148.  /**
  149. @@ -109,6 +112,7 @@
  150.  static inline void ToggleTransparencyLock(TransparencyOption to)
  151.  {
  152.     ToggleBit(_transparency_lock, to);
  153. +   if (_transparency_lock_tmp != NULL) ToggleBit(_transparency_lock_tmp, to);
  154.  }
  155.  
  156.  /** Set or clear all non-locked transparency options */
  157. @@ -126,4 +130,30 @@
  158.     MarkWholeScreenDirty();
  159.  }
  160.  
  161. +/**
  162. + * Temporarily store transparency options and locks for later
  163. + * restoration and set all non-locked transparency options.
  164. + */
  165. +static inline void StartTempTransparency()
  166. +{
  167. +   _transparency_opt_tmp = _transparency_opt;
  168. +   _transparency_lock_tmp = _transparency_opt_tmp | _transparency_lock;
  169. +   _transparency_opt |= GB(~_transparency_lock_tmp, 0, TO_END);
  170. +
  171. +   MarkWholeScreenDirty();
  172. +}
  173. +
  174. +/**
  175. + * Restore transparency options and clear temporary
  176. + * transparency options and locks.
  177. + */
  178. +static inline void StopTempTransparency()
  179. +{
  180. +   _transparency_opt &= _transparency_lock_tmp;
  181. +   _transparency_opt_tmp = NULL;
  182. +   _transparency_lock_tmp = NULL;
  183. +
  184. +   MarkWholeScreenDirty();
  185. +}
  186. +
  187.  #endif /* TRANSPARENCY_H */
  188. Index: src/transparency_gui.cpp
  189. ===================================================================
  190. --- src/transparency_gui.cpp    (revision 27772)
  191. +++ src/transparency_gui.cpp    (working copy)
  192. @@ -22,9 +22,11 @@
  193.  
  194.  #include "safeguards.h"
  195.  
  196. -TransparencyOptionBits _transparency_opt;  ///< The bits that should be transparent.
  197. -TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
  198. -TransparencyOptionBits _invisibility_opt;  ///< The bits that should be invisible.
  199. +TransparencyOptionBits _transparency_opt;             ///< The bits that should be transparent.
  200. +TransparencyOptionBits _transparency_opt_tmp = NULL;  ///< Temporary bits that should be transparent while building.
  201. +TransparencyOptionBits _transparency_lock;            ///< Prevent these bits from flipping with X.
  202. +TransparencyOptionBits _transparency_lock_tmp = NULL; ///< Prevent temporary bits from flipping while building.
  203. +TransparencyOptionBits _invisibility_opt;             ///< The bits that should be invisible.
  204.  byte _display_opt; ///< What do we want to draw/do?
  205.  
  206.  class TransparenciesWindow : public Window

Version history

Revision # Author Created at
pvzyrl5w2 Anonymous 08 Mar 2017, 12:54:04 UTC Diff

Comments