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

Version history

Revision # Author Created at
p8iovjkgp Anonymous 09 Mar 2017, 19:17:41 UTC Diff
p3ylqawqb Anonymous 08 Mar 2017, 16:41:38 UTC Diff
pvzyrl5w2 Anonymous 08 Mar 2017, 12:54:04 UTC Diff

Comments