dock_gui.cpp

Go to the documentation of this file.
00001 /* $Id: dock_gui.cpp 20494 2010-08-14 18:01:55Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "openttd.h"
00014 #include "tile_map.h"
00015 #include "terraform_gui.h"
00016 #include "window_gui.h"
00017 #include "station_gui.h"
00018 #include "command_func.h"
00019 #include "water.h"
00020 #include "window_func.h"
00021 #include "vehicle_func.h"
00022 #include "sound_func.h"
00023 #include "viewport_func.h"
00024 #include "gfx_func.h"
00025 #include "company_func.h"
00026 #include "slope_func.h"
00027 #include "tilehighlight_func.h"
00028 #include "company_base.h"
00029 #include "station_type.h"
00030 
00031 #include "table/sprites.h"
00032 #include "table/strings.h"
00033 
00034 static void ShowBuildDockStationPicker(Window *parent);
00035 static void ShowBuildDocksDepotPicker(Window *parent);
00036 
00037 static Axis _ship_depot_direction;
00038 
00039 void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00040 {
00041   if (result.Failed()) return;
00042 
00043   SndPlayTileFx(SND_02_SPLAT, tile);
00044   if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
00045 }
00046 
00047 void CcBuildCanal(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00048 {
00049   if (result.Succeeded()) SndPlayTileFx(SND_02_SPLAT, tile);
00050 }
00051 
00052 
00053 static void PlaceDocks_Dock(TileIndex tile)
00054 {
00055   uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
00056 
00057   /* tile is always the land tile, so need to evaluate _thd.pos */
00058   CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
00059 
00060   /* Determine the watery part of the dock. */
00061   DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
00062   TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
00063 
00064   ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
00065 }
00066 
00067 static void PlaceDocks_Depot(TileIndex tile)
00068 {
00069   DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
00070 }
00071 
00072 static void PlaceDocks_Buoy(TileIndex tile)
00073 {
00074   DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
00075 }
00076 
00077 static void PlaceDocks_BuildCanal(TileIndex tile)
00078 {
00079   VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
00080 }
00081 
00082 static void PlaceDocks_BuildLock(TileIndex tile)
00083 {
00084   DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
00085 }
00086 
00087 static void PlaceDocks_BuildRiver(TileIndex tile)
00088 {
00089   VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
00090 }
00091 
00092 static void PlaceDocks_Aqueduct(TileIndex tile)
00093 {
00094   VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
00095 }
00096 
00097 
00099 enum DockToolbarWidgets {
00100   DTW_BUTTONS_BEGIN,             
00101   DTW_CANAL = DTW_BUTTONS_BEGIN, 
00102   DTW_LOCK,                      
00103   DTW_DEMOLISH,                  
00104   DTW_DEPOT,                     
00105   DTW_STATION,                   
00106   DTW_BUOY,                      
00107   DTW_RIVER,                     
00108   DTW_BUILD_AQUEDUCT,            
00109   DTW_END,                       
00110 };
00111 
00112 
00113 static void BuildDocksClick_Canal(Window *w)
00114 {
00115 
00116   HandlePlacePushButton(w, DTW_CANAL, SPR_CURSOR_CANAL, HT_RECT, PlaceDocks_BuildCanal);
00117 }
00118 
00119 static void BuildDocksClick_Lock(Window *w)
00120 {
00121   HandlePlacePushButton(w, DTW_LOCK, SPR_CURSOR_LOCK, HT_RECT, PlaceDocks_BuildLock);
00122 }
00123 
00124 static void BuildDocksClick_Demolish(Window *w)
00125 {
00126   HandlePlacePushButton(w, DTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
00127 }
00128 
00129 static void BuildDocksClick_Depot(Window *w)
00130 {
00131   if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
00132   if (HandlePlacePushButton(w, DTW_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT, PlaceDocks_Depot)) ShowBuildDocksDepotPicker(w);
00133 }
00134 
00135 static void BuildDocksClick_Dock(Window *w)
00136 {
00137   if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
00138   if (HandlePlacePushButton(w, DTW_STATION, SPR_CURSOR_DOCK, HT_SPECIAL, PlaceDocks_Dock)) ShowBuildDockStationPicker(w);
00139 }
00140 
00141 static void BuildDocksClick_Buoy(Window *w)
00142 {
00143   if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
00144   HandlePlacePushButton(w, DTW_BUOY, SPR_CURSOR_BOUY, HT_RECT, PlaceDocks_Buoy);
00145 }
00146 
00147 static void BuildDocksClick_River(Window *w)
00148 {
00149   if (_game_mode != GM_EDITOR) return;
00150   HandlePlacePushButton(w, DTW_RIVER, SPR_CURSOR_RIVER, HT_RECT, PlaceDocks_BuildRiver);
00151 }
00152 
00153 static void BuildDocksClick_Aqueduct(Window *w)
00154 {
00155   HandlePlacePushButton(w, DTW_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_RECT, PlaceDocks_Aqueduct);
00156 }
00157 
00158 
00159 typedef void OnButtonClick(Window *w);
00160 static OnButtonClick * const _build_docks_button_proc[] = {
00161   BuildDocksClick_Canal,
00162   BuildDocksClick_Lock,
00163   BuildDocksClick_Demolish,
00164   BuildDocksClick_Depot,
00165   BuildDocksClick_Dock,
00166   BuildDocksClick_Buoy,
00167   BuildDocksClick_River,
00168   BuildDocksClick_Aqueduct
00169 };
00170 
00171 struct BuildDocksToolbarWindow : Window {
00172   BuildDocksToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
00173   {
00174     this->InitNested(desc, window_number);
00175     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
00176   }
00177 
00178   ~BuildDocksToolbarWindow()
00179   {
00180     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
00181   }
00182 
00183   virtual void OnPaint()
00184   {
00185     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP), DTW_DEPOT, DTW_STATION, DTW_BUOY, WIDGET_LIST_END);
00186     this->DrawWidgets();
00187   }
00188 
00189   virtual void OnClick(Point pt, int widget, int click_count)
00190   {
00191     if (widget >= DTW_BUTTONS_BEGIN) _build_docks_button_proc[widget - DTW_BUTTONS_BEGIN](this);
00192   }
00193 
00194   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00195   {
00196     switch (keycode) {
00197       case '1': BuildDocksClick_Canal(this); break;
00198       case '2': BuildDocksClick_Lock(this); break;
00199       case '3': BuildDocksClick_Demolish(this); break;
00200       case '4': BuildDocksClick_Depot(this); break;
00201       case '5': BuildDocksClick_Dock(this); break;
00202       case '6': BuildDocksClick_Buoy(this); break;
00203       case '7': BuildDocksClick_River(this); break;
00204       case 'B':
00205       case '8': BuildDocksClick_Aqueduct(this); break;
00206       default:  return ES_NOT_HANDLED;
00207     }
00208     return ES_HANDLED;
00209   }
00210 
00211   virtual void OnPlaceObject(Point pt, TileIndex tile)
00212   {
00213     _place_proc(tile);
00214   }
00215 
00216   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
00217   {
00218     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
00219   }
00220 
00221   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
00222   {
00223     if (pt.x != -1) {
00224       switch (select_proc) {
00225         case DDSP_BUILD_BRIDGE:
00226           if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
00227           DoCommandP(end_tile, start_tile, TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
00228 
00229         case DDSP_DEMOLISH_AREA:
00230           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
00231           break;
00232         case DDSP_CREATE_WATER:
00233           DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR ? _ctrl_pressed : 0), CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcBuildCanal);
00234           break;
00235         case DDSP_CREATE_RIVER:
00236           DoCommandP(end_tile, start_tile, 2, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
00237           break;
00238 
00239         default: break;
00240       }
00241     }
00242   }
00243 
00244   virtual void OnPlaceObjectAbort()
00245   {
00246     this->RaiseButtons();
00247 
00248     DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
00249     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
00250     DeleteWindowById(WC_SELECT_STATION, 0);
00251     DeleteWindowByClass(WC_BUILD_BRIDGE);
00252   }
00253 
00254   virtual void OnPlacePresize(Point pt, TileIndex tile_from)
00255   {
00256     DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, NULL));
00257     TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile_from, ReverseDiagDir(dir)) : tile_from);
00258 
00259     VpSetPresizeRange(tile_from, tile_to);
00260   }
00261 };
00262 
00263 
00268 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
00269   NWidget(NWID_HORIZONTAL),
00270     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00271     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00272     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
00273   EndContainer(),
00274   NWidget(NWID_HORIZONTAL_LTR),
00275     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_BUILD_CANALS_TOOLTIP),
00276     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
00277     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
00278     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
00279     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_DEPOT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DEPOT, STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP),
00280     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_STATION), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DOCK, STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP),
00281     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BOUY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
00282     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_BUILD_AQUEDUCT), SetMinimalSize(23, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
00283   EndContainer(),
00284 };
00285 
00286 static const WindowDesc _build_docks_toolbar_desc(
00287   WDP_ALIGN_TOOLBAR, 0, 0,
00288   WC_BUILD_TOOLBAR, WC_NONE,
00289   WDF_CONSTRUCTION,
00290   _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets)
00291 );
00292 
00293 void ShowBuildDocksToolbar()
00294 {
00295   if (!Company::IsValidID(_local_company)) return;
00296 
00297   DeleteWindowByClass(WC_BUILD_TOOLBAR);
00298   AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
00299 }
00300 
00305 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
00306   NWidget(NWID_HORIZONTAL),
00307     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00308     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00309     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
00310   EndContainer(),
00311   NWidget(NWID_HORIZONTAL),
00312     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_CREATE_LAKE_TOOLTIP),
00313     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
00314     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
00315     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
00316     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_RIVER), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_RIVER, STR_WATERWAYS_TOOLBAR_CREATE_RIVER_TOOLTIP),
00317     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_BUILD_AQUEDUCT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
00318   EndContainer(),
00319 };
00320 
00322 static const WindowDesc _build_docks_scen_toolbar_desc(
00323   WDP_AUTO, 0, 0,
00324   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
00325   WDF_CONSTRUCTION,
00326   _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
00327 );
00328 
00329 void ShowBuildDocksScenToolbar()
00330 {
00331   AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
00332 }
00333 
00335 enum BuildDockStationWidgets {
00336   BDSW_BACKGROUND, 
00337   BDSW_LT_OFF,     
00338   BDSW_LT_ON,      
00339   BDSW_INFO,       
00340 };
00341 
00342 struct BuildDocksStationWindow : public PickerWindowBase {
00343 public:
00344   BuildDocksStationWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
00345   {
00346     this->InitNested(desc, TRANSPORT_WATER);
00347     this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
00348   }
00349 
00350   virtual ~BuildDocksStationWindow()
00351   {
00352     DeleteWindowById(WC_SELECT_STATION, 0);
00353   }
00354 
00355   virtual void OnPaint()
00356   {
00357     int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
00358 
00359     this->DrawWidgets();
00360 
00361     if (_settings_client.gui.station_show_coverage) {
00362       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
00363     } else {
00364       SetTileSelectSize(1, 1);
00365     }
00366 
00367     /* strings such as 'Size' and 'Coverage Area' */
00368     int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
00369     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
00370     int right  = back_nwi->pos_x + back_nwi->current_x;
00371     int bottom = back_nwi->pos_y + back_nwi->current_y;
00372     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
00373     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
00374     /* Resize background if the text is not equally long as the window. */
00375     if (top > bottom || (top < bottom && back_nwi->current_y > back_nwi->smallest_y)) {
00376       ResizeWindow(this, 0, top - bottom);
00377     }
00378   }
00379 
00380   virtual void OnClick(Point pt, int widget, int click_count)
00381   {
00382     switch (widget) {
00383       case BDSW_LT_OFF:
00384       case BDSW_LT_ON:
00385         this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
00386         _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
00387         this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
00388         SndPlayFx(SND_15_BEEP);
00389         this->SetDirty();
00390         break;
00391     }
00392   }
00393 
00394   virtual void OnTick()
00395   {
00396     CheckRedrawStationCoverage(this);
00397   }
00398 };
00399 
00401 static const NWidgetPart _nested_build_dock_station_widgets[] = {
00402   NWidget(NWID_HORIZONTAL),
00403     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00404     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00405   EndContainer(),
00406   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
00407     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
00408     NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
00409     NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
00410       NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_OFF), SetMinimalSize(40, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
00411       NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_ON), SetMinimalSize(40, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
00412     EndContainer(),
00413     NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
00414   EndContainer(),
00415 };
00416 
00417 static const WindowDesc _build_dock_station_desc(
00418   WDP_AUTO, 0, 0,
00419   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
00420   WDF_CONSTRUCTION,
00421   _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
00422 );
00423 
00424 static void ShowBuildDockStationPicker(Window *parent)
00425 {
00426   new BuildDocksStationWindow(&_build_dock_station_desc, parent);
00427 }
00428 
00430 enum BuildDockDepotWidgets {
00431   BDDW_BACKGROUND,
00432   BDDW_X,
00433   BDDW_Y,
00434 };
00435 
00436 struct BuildDocksDepotWindow : public PickerWindowBase {
00437 private:
00438   static void UpdateDocksDirection()
00439   {
00440     if (_ship_depot_direction != AXIS_X) {
00441       SetTileSelectSize(1, 2);
00442     } else {
00443       SetTileSelectSize(2, 1);
00444     }
00445   }
00446 
00447 public:
00448   BuildDocksDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
00449   {
00450     this->InitNested(desc, TRANSPORT_WATER);
00451     this->LowerWidget(_ship_depot_direction + BDDW_X);
00452     UpdateDocksDirection();
00453   }
00454 
00455   virtual void OnPaint()
00456   {
00457     this->DrawWidgets();
00458 
00459     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_X)->pos_x + 64, this->GetWidget<NWidgetBase>(BDDW_X)->pos_y + 18, 0);
00460     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_X)->pos_x + 32, this->GetWidget<NWidgetBase>(BDDW_X)->pos_y + 34, 1);
00461     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_Y)->pos_x + 32, this->GetWidget<NWidgetBase>(BDDW_Y)->pos_y + 18, 2);
00462     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_Y)->pos_x + 64, this->GetWidget<NWidgetBase>(BDDW_Y)->pos_y + 34, 3);
00463   }
00464 
00465   virtual void OnClick(Point pt, int widget, int click_count)
00466   {
00467     switch (widget) {
00468       case BDDW_X:
00469       case BDDW_Y:
00470         this->RaiseWidget(_ship_depot_direction + BDDW_X);
00471         _ship_depot_direction = (widget == BDDW_X ? AXIS_X : AXIS_Y);
00472         this->LowerWidget(_ship_depot_direction + BDDW_X);
00473         SndPlayFx(SND_15_BEEP);
00474         UpdateDocksDirection();
00475         this->SetDirty();
00476         break;
00477     }
00478   }
00479 };
00480 
00481 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
00482   NWidget(NWID_HORIZONTAL),
00483     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00484     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00485   EndContainer(),
00486   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDDW_BACKGROUND),
00487     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
00488     NWidget(NWID_HORIZONTAL_LTR),
00489       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
00490       NWidget(WWT_PANEL, COLOUR_GREY, BDDW_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
00491       EndContainer(),
00492       NWidget(NWID_SPACER), SetMinimalSize(2, 0),
00493       NWidget(WWT_PANEL, COLOUR_GREY, BDDW_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
00494       EndContainer(),
00495       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
00496     EndContainer(),
00497     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
00498   EndContainer(),
00499 };
00500 
00501 static const WindowDesc _build_docks_depot_desc(
00502   WDP_AUTO, 0, 0,
00503   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
00504   WDF_CONSTRUCTION,
00505   _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
00506 );
00507 
00508 
00509 static void ShowBuildDocksDepotPicker(Window *parent)
00510 {
00511   new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
00512 }
00513 
00514 
00515 void InitializeDockGui()
00516 {
00517   _ship_depot_direction = AXIS_X;
00518 }

Generated on Tue Sep 14 17:06:48 2010 for OpenTTD by  doxygen 1.6.1