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 "vehiclelist.h"
00017 #include "vehicle_gui.h"
00018 #include "viewport_func.h"
00019 #include "strings_func.h"
00020 #include "command_func.h"
00021 #include "company_func.h"
00022 #include "company_base.h"
00023 #include "window_func.h"
00024 #include "waypoint_base.h"
00025
00026 #include "widgets/waypoint_widget.h"
00027
00028 #include "table/strings.h"
00029
00031 struct WaypointWindow : Window {
00032 private:
00033 VehicleType vt;
00034 Waypoint *wp;
00035
00040 TileIndex GetCenterTile() const
00041 {
00042 if (!this->wp->IsInUse()) return this->wp->xy;
00043
00044 TileArea ta;
00045 this->wp->GetTileArea(&ta, this->vt == VEH_TRAIN ? STATION_WAYPOINT : STATION_BUOY);
00046 return ta.GetCenterTile();
00047 }
00048
00049 public:
00055 WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
00056 {
00057 this->wp = Waypoint::Get(window_number);
00058 this->vt = (wp->string_id == STR_SV_STNAME_WAYPOINT) ? VEH_TRAIN : VEH_SHIP;
00059
00060 this->CreateNestedTree(desc);
00061 if (this->vt == VEH_TRAIN) {
00062 this->GetWidget<NWidgetCore>(WID_W_SHOW_VEHICLES)->SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP);
00063 this->GetWidget<NWidgetCore>(WID_W_CENTER_VIEW)->tool_tip = STR_WAYPOINT_VIEW_CENTER_TOOLTIP;
00064 this->GetWidget<NWidgetCore>(WID_W_RENAME)->tool_tip = STR_WAYPOINT_VIEW_CHANGE_WAYPOINT_NAME;
00065 }
00066 this->FinishInitNested(desc, window_number);
00067
00068 if (this->wp->owner != OWNER_NONE) this->owner = this->wp->owner;
00069 this->flags |= WF_DISABLE_VP_SCROLL;
00070
00071 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_W_VIEWPORT);
00072 nvp->InitializeViewport(this, this->GetCenterTile(), ZOOM_LVL_VIEWPORT);
00073
00074 this->OnInvalidateData(0);
00075 }
00076
00077 ~WaypointWindow()
00078 {
00079 Owner owner = this->owner;
00080
00081
00082 if (!Company::IsValidID(owner)) owner = _local_company;
00083
00084
00085 if (Company::IsValidID(owner)) DeleteWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, owner, this->window_number).Pack(), false);
00086 }
00087
00088 virtual void SetStringParameters(int widget) const
00089 {
00090 if (widget == WID_W_CAPTION) SetDParam(0, this->wp->index);
00091 }
00092
00093 virtual void OnClick(Point pt, int widget, int click_count)
00094 {
00095 switch (widget) {
00096 case WID_W_CENTER_VIEW:
00097 if (_ctrl_pressed) {
00098 ShowExtraViewPortWindow(this->GetCenterTile());
00099 } else {
00100 ScrollMainWindowToTile(this->GetCenterTile());
00101 }
00102 break;
00103
00104 case WID_W_RENAME:
00105 SetDParam(0, this->wp->index);
00106 ShowQueryString(STR_WAYPOINT_NAME, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_STATION_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
00107 break;
00108
00109 case WID_W_SHOW_VEHICLES:
00110 ShowVehicleListWindow(this->wp->owner, this->vt, this->wp->index);
00111 break;
00112 }
00113 }
00114
00120 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00121 {
00122 if (!gui_scope) return;
00123
00124 this->SetWidgetDisabledState(WID_W_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE));
00125
00126 this->SetWidgetDisabledState(WID_W_SHOW_VEHICLES, !this->wp->IsInUse());
00127
00128 ScrollWindowToTile(this->GetCenterTile(), this, true);
00129 }
00130
00131 virtual void OnResize()
00132 {
00133 if (this->viewport != NULL) {
00134 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_W_VIEWPORT);
00135 nvp->UpdateViewportCoordinates(this);
00136 this->wp->UpdateVirtCoord();
00137
00138 ScrollWindowToTile(this->GetCenterTile(), this, true);
00139 }
00140 }
00141
00142 virtual void OnQueryTextFinished(char *str)
00143 {
00144 if (str == NULL) return;
00145
00146 DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME), NULL, str);
00147 }
00148
00149 };
00150
00152 static const NWidgetPart _nested_waypoint_view_widgets[] = {
00153 NWidget(NWID_HORIZONTAL),
00154 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00155 NWidget(WWT_CAPTION, COLOUR_GREY, WID_W_CAPTION), SetDataTip(STR_WAYPOINT_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00156 NWidget(WWT_SHADEBOX, COLOUR_GREY),
00157 NWidget(WWT_STICKYBOX, COLOUR_GREY),
00158 EndContainer(),
00159 NWidget(WWT_PANEL, COLOUR_GREY),
00160 NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
00161 NWidget(NWID_VIEWPORT, COLOUR_GREY, WID_W_VIEWPORT), SetMinimalSize(256, 88), SetPadding(1, 1, 1, 1), SetResize(1, 1),
00162 EndContainer(),
00163 EndContainer(),
00164 NWidget(NWID_HORIZONTAL),
00165 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_CENTER_VIEW), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_LOCATION, STR_BUOY_VIEW_CENTER_TOOLTIP),
00166 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_RENAME), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_BUOY_VIEW_CHANGE_BUOY_NAME),
00167 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_SHOW_VEHICLES), SetMinimalSize(15, 12), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
00168 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00169 EndContainer(),
00170 };
00171
00173 static const WindowDesc _waypoint_view_desc(
00174 WDP_AUTO, 260, 118,
00175 WC_WAYPOINT_VIEW, WC_NONE,
00176 0,
00177 _nested_waypoint_view_widgets, lengthof(_nested_waypoint_view_widgets)
00178 );
00179
00184 void ShowWaypointWindow(const Waypoint *wp)
00185 {
00186 AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
00187 }