# waypoint_gui.cpp

Go to the documentation of this file.

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