waypoint_gui.cpp

Go to the documentation of this file.
00001 /* $Id: waypoint_gui.cpp 15589 2009-02-26 14:10:57Z smatz $ */
00002 
00005 #include "stdafx.h"
00006 #include "window_gui.h"
00007 #include "gui.h"
00008 #include "textbuf_gui.h"
00009 #include "vehicle_gui.h"
00010 #include "viewport_func.h"
00011 #include "strings_func.h"
00012 #include "gfx_func.h"
00013 #include "command_func.h"
00014 #include "company_func.h"
00015 #include "functions.h"
00016 #include "window_func.h"
00017 
00018 #include "table/strings.h"
00019 
00020 struct WaypointWindow : Window {
00021 private:
00022   Waypoint *wp;
00023 
00024   enum WaypointViewWidget {
00025     WAYPVW_CLOSEBOX = 0,
00026     WAYPVW_CAPTION,
00027     WAYPVW_STICKY,
00028     WAYPVW_VIEWPORTPANEL,
00029     WAYPVW_SPACER,
00030     WAYPVW_CENTERVIEW,
00031     WAYPVW_RENAME,
00032     WAYPVW_SHOW_TRAINS,
00033   };
00034 
00035 public:
00036   WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
00037   {
00038     this->wp = GetWaypoint(this->window_number);
00039     if (this->wp->owner != OWNER_NONE) this->owner = this->wp->owner;
00040 
00041     this->flags4 |= WF_DISABLE_VP_SCROLL;
00042     InitializeWindowViewport(this, 3, 17, 254, 86, this->wp->xy, ZOOM_LVL_MIN);
00043 
00044     this->FindWindowPlacementAndResize(desc);
00045   }
00046 
00047   ~WaypointWindow()
00048   {
00049     DeleteWindowById(WC_TRAINS_LIST, (this->window_number << 16) | (VEH_TRAIN << 11) | VLW_WAYPOINT_LIST | this->wp->owner);
00050   }
00051 
00052   virtual void OnPaint()
00053   {
00054     /* You can only change your own waypoints */
00055     this->SetWidgetDisabledState(WAYPVW_RENAME, this->wp->owner != _local_company);
00056     /* Disable the widget for waypoints with no owner (after company bankrupt) */
00057     this->SetWidgetDisabledState(WAYPVW_SHOW_TRAINS, this->wp->owner == OWNER_NONE);
00058 
00059     SetDParam(0, this->wp->index);
00060     this->DrawWidgets();
00061 
00062     this->DrawViewport();
00063   }
00064 
00065   virtual void OnClick(Point pt, int widget)
00066   {
00067     switch (widget) {
00068       case WAYPVW_CENTERVIEW: /* scroll to location */
00069         if (_ctrl_pressed) {
00070           ShowExtraViewPortWindow(this->wp->xy);
00071         } else {
00072           ScrollMainWindowToTile(this->wp->xy);
00073         }
00074         break;
00075 
00076       case WAYPVW_RENAME: /* rename */
00077         SetDParam(0, this->wp->index);
00078         ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
00079         break;
00080 
00081       case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/
00082         ShowVehicleListWindow(this->wp);
00083         break;
00084     }
00085   }
00086 
00087   virtual void OnInvalidateData(int data)
00088   {
00089     int x = TileX(this->wp->xy) * TILE_SIZE;
00090     int y = TileY(this->wp->xy) * TILE_SIZE;
00091     ScrollWindowTo(x,y, this);
00092   }
00093 
00094   virtual void OnQueryTextFinished(char *str)
00095   {
00096     if (str == NULL) return;
00097 
00098     DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME), NULL, str);
00099   }
00100 
00101 };
00102 
00103 static const Widget _waypoint_view_widgets[] = {
00104 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},                 // WAYPVW_CLOSEBOX
00105 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   247,     0,    13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS},       // WAYPVW_CAPTION
00106 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   248,   259,     0,    13, 0x0,                   STR_STICKY_BUTTON},                     // WAYPVW_STICKY
00107 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   259,    14,   105, 0x0,                   STR_NULL},                              // WAYPVW_VIEWPORTPANEL
00108 {      WWT_INSET,   RESIZE_NONE,  COLOUR_GREY,     2,   257,    16,   103, 0x0,                   STR_NULL},                              // WAYPVW_SPACER
00109 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   121,   106,   117, STR_00E4_LOCATION,     STR_3053_CENTER_MAIN_VIEW_ON_STATION},  // WAYPVW_CENTERVIEW
00110 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   122,   244,   106,   117, STR_0130_RENAME,       STR_CHANGE_WAYPOINT_NAME},              // WAYPVW_RENAME
00111 { WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   245,   259,   106,   117, STR_TRAIN,             STR_SCHEDULED_TRAINS_TIP },             // WAYPVW_SHOW_TRAINS
00112 {   WIDGETS_END},
00113 };
00114 
00115 static const WindowDesc _waypoint_view_desc = {
00116   WDP_AUTO, WDP_AUTO, 260, 118, 260, 118,
00117   WC_WAYPOINT_VIEW, WC_NONE,
00118   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
00119   _waypoint_view_widgets,
00120 };
00121 
00122 void ShowWaypointWindow(const Waypoint *wp)
00123 {
00124   if (!wp->IsValid()) return;  // little safety
00125   AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
00126 }

Generated on Mon Mar 9 23:33:53 2009 for openttd by  doxygen 1.5.6