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

Version history

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

Comments