00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "window_gui.h"
00014 #include "gui.h"
00015 #include "textbuf_gui.h"
00016 #include "vehicle_gui.h"
00017 #include "viewport_func.h"
00018 #include "strings_func.h"
00019 #include "command_func.h"
00020 #include "company_func.h"
00021 #include "window_func.h"
00022 #include "waypoint_base.h"
00023
00024 #include "table/strings.h"
00025
00027 enum WaypointWindowWidgets {
00028 WAYPVW_CAPTION,
00029 WAYPVW_VIEWPORT,
00030 WAYPVW_CENTERVIEW,
00031 WAYPVW_RENAME,
00032 WAYPVW_SHOW_VEHICLES,
00033 };
00034
00035 struct WaypointWindow : Window {
00036 private:
00037 VehicleType vt;
00038 Waypoint *wp;
00039
00040 public:
00041 WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
00042 {
00043 this->wp = Waypoint::Get(window_number);
00044 this->vt = (wp->string_id == STR_SV_STNAME_WAYPOINT) ? VEH_TRAIN : VEH_SHIP;
00045
00046 if (this->wp->owner != OWNER_NONE) this->owner = this->wp->owner;
00047
00048 this->CreateNestedTree(desc);
00049 if (this->vt == VEH_TRAIN) {
00050 this->GetWidget<NWidgetCore>(WAYPVW_SHOW_VEHICLES)->SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP);
00051 this->GetWidget<NWidgetCore>(WAYPVW_CENTERVIEW)->tool_tip = STR_WAYPOINT_VIEW_CENTER_TOOLTIP;
00052 this->GetWidget<NWidgetCore>(WAYPVW_RENAME)->tool_tip = STR_WAYPOINT_VIEW_CHANGE_WAYPOINT_NAME;
00053 }
00054 this->FinishInitNested(desc, window_number);
00055
00056 this->flags4 |= WF_DISABLE_VP_SCROLL;
00057 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WAYPVW_VIEWPORT);
00058 nvp->InitializeViewport(this, this->wp->xy, ZOOM_LVL_MIN);
00059
00060 this->OnInvalidateData(0);
00061 }
00062
00063 ~WaypointWindow()
00064 {
00065 DeleteWindowById(GetWindowClassForVehicleType(this->vt), (this->window_number << 16) | (this->vt << 11) | VLW_WAYPOINT_LIST | this->wp->owner);
00066 }
00067
00068 virtual void SetStringParameters(int widget) const
00069 {
00070 if (widget == WAYPVW_CAPTION) SetDParam(0, this->wp->index);
00071 }
00072
00073 virtual void OnPaint()
00074 {
00075 this->DrawWidgets();
00076 }
00077
00078 virtual void OnClick(Point pt, int widget, int click_count)
00079 {
00080 switch (widget) {
00081 case WAYPVW_CENTERVIEW:
00082 if (_ctrl_pressed) {
00083 ShowExtraViewPortWindow(this->wp->xy);
00084 } else {
00085 ScrollMainWindowToTile(this->wp->xy);
00086 }
00087 break;
00088
00089 case WAYPVW_RENAME:
00090 SetDParam(0, this->wp->index);
00091 ShowQueryString(STR_WAYPOINT_NAME, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
00092 break;
00093
00094 case WAYPVW_SHOW_VEHICLES:
00095 ShowVehicleListWindow((this->wp->owner == OWNER_NONE) ? _local_company : this->wp->owner, this->vt, this->wp);
00096 break;
00097 }
00098 }
00099
00100 virtual void OnInvalidateData(int data)
00101 {
00102
00103 this->SetWidgetDisabledState(WAYPVW_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE));
00104
00105 this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, !this->wp->IsInUse());
00106
00107 int x = TileX(this->wp->xy) * TILE_SIZE;
00108 int y = TileY(this->wp->xy) * TILE_SIZE;
00109 ScrollWindowTo(x, y, -1, this);
00110 }
00111
00112 virtual void OnResize()
00113 {
00114 if (this->viewport != NULL) {
00115 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WAYPVW_VIEWPORT);
00116 nvp->UpdateViewportCoordinates(this);
00117 }
00118 }
00119
00120 virtual void OnQueryTextFinished(char *str)
00121 {
00122 if (str == NULL) return;
00123
00124 DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME), NULL, str);
00125 }
00126
00127 };
00128
00129 static const NWidgetPart _nested_waypoint_view_widgets[] = {
00130 NWidget(NWID_HORIZONTAL),
00131 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00132 NWidget(WWT_CAPTION, COLOUR_GREY, WAYPVW_CAPTION), SetDataTip(STR_WAYPOINT_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00133 NWidget(WWT_SHADEBOX, COLOUR_GREY),
00134 NWidget(WWT_STICKYBOX, COLOUR_GREY),
00135 EndContainer(),
00136 NWidget(WWT_PANEL, COLOUR_GREY),
00137 NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
00138 NWidget(NWID_VIEWPORT, COLOUR_GREY, WAYPVW_VIEWPORT), SetMinimalSize(256, 88), SetPadding(1, 1, 1, 1), SetResize(1, 1),
00139 EndContainer(),
00140 EndContainer(),
00141 NWidget(NWID_HORIZONTAL),
00142 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WAYPVW_CENTERVIEW), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_LOCATION, STR_BUOY_VIEW_CENTER_TOOLTIP),
00143 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WAYPVW_RENAME), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_BUOY_VIEW_CHANGE_BUOY_NAME),
00144 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WAYPVW_SHOW_VEHICLES), SetMinimalSize(15, 12), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
00145 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00146 EndContainer(),
00147 };
00148
00149 static const WindowDesc _waypoint_view_desc(
00150 WDP_AUTO, 260, 118,
00151 WC_WAYPOINT_VIEW, WC_NONE,
00152 WDF_UNCLICK_BUTTONS,
00153 _nested_waypoint_view_widgets, lengthof(_nested_waypoint_view_widgets)
00154 );
00155
00156 void ShowWaypointWindow(const Waypoint *wp)
00157 {
00158 AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
00159 }