00001
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 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
00055 this->SetWidgetDisabledState(WAYPVW_RENAME, this->wp->owner != _local_company);
00056 SetDParam(0, this->wp->index);
00057 this->DrawWidgets();
00058
00059 this->DrawViewport();
00060 }
00061
00062 virtual void OnClick(Point pt, int widget)
00063 {
00064 switch (widget) {
00065 case WAYPVW_CENTERVIEW:
00066 if (_ctrl_pressed) {
00067 ShowExtraViewPortWindow(this->wp->xy);
00068 } else {
00069 ScrollMainWindowToTile(this->wp->xy);
00070 }
00071 break;
00072
00073 case WAYPVW_RENAME:
00074 SetDParam(0, this->wp->index);
00075 ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
00076 break;
00077
00078 case WAYPVW_SHOW_TRAINS:
00079 ShowVehicleListWindow(this->wp);
00080 break;
00081 }
00082 }
00083
00084 virtual void OnInvalidateData(int data)
00085 {
00086 int x = TileX(this->wp->xy) * TILE_SIZE;
00087 int y = TileY(this->wp->xy) * TILE_SIZE;
00088 ScrollWindowTo(x,y, this);
00089 }
00090
00091 virtual void OnQueryTextFinished(char *str)
00092 {
00093 if (str == NULL) return;
00094
00095 DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME), NULL, str);
00096 }
00097
00098 };
00099
00100 static const Widget _waypoint_view_widgets[] = {
00101 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
00102 { WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 247, 0, 13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS},
00103 { WWT_STICKYBOX, RESIZE_NONE, COLOUR_GREY, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
00104 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 259, 14, 105, 0x0, STR_NULL},
00105 { WWT_INSET, RESIZE_NONE, COLOUR_GREY, 2, 257, 16, 103, 0x0, STR_NULL},
00106 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 121, 106, 117, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION},
00107 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 122, 244, 106, 117, STR_0130_RENAME, STR_CHANGE_WAYPOINT_NAME},
00108 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 245, 259, 106, 117, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP },
00109 { WIDGETS_END},
00110 };
00111
00112 static const WindowDesc _waypoint_view_desc = {
00113 WDP_AUTO, WDP_AUTO, 260, 118, 260, 118,
00114 WC_WAYPOINT_VIEW, WC_NONE,
00115 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
00116 _waypoint_view_widgets,
00117 };
00118
00119 void ShowWaypointWindow(const Waypoint *wp)
00120 {
00121 if (!wp->IsValid()) return;
00122 AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
00123 }