|
1 /* $Id$ */ |
|
2 |
|
3 /** @file waypoint_gui.cpp Handling of waypoints gui. */ |
|
4 |
|
5 #include "stdafx.h" |
|
6 #include "openttd.h" |
|
7 #include "window_gui.h" |
|
8 #include "gui.h" |
|
9 #include "textbuf_gui.h" |
|
10 #include "vehicle_gui.h" |
|
11 #include "waypoint.h" |
|
12 #include "viewport_func.h" |
|
13 #include "string_func.h" |
|
14 #include "strings_func.h" |
|
15 #include "gfx_func.h" |
|
16 #include "command_func.h" |
|
17 #include "functions.h" |
|
18 |
|
19 #include "table/strings.h" |
|
20 |
|
21 struct WaypointWindow : Window { |
|
22 private: |
|
23 Waypoint *wp; |
|
24 |
|
25 enum WaypointViewWidget { |
|
26 WAYPVW_CLOSEBOX = 0, |
|
27 WAYPVW_CAPTION, |
|
28 WAYPVW_STICKY, |
|
29 WAYPVW_VIEWPORTPANEL, |
|
30 WAYPVW_SPACER, |
|
31 WAYPVW_CENTERVIEW, |
|
32 WAYPVW_RENAME, |
|
33 WAYPVW_SHOW_TRAINS, |
|
34 }; |
|
35 |
|
36 public: |
|
37 WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
|
38 { |
|
39 this->wp = GetWaypoint(this->window_number); |
|
40 |
|
41 this->flags4 |= WF_DISABLE_VP_SCROLL; |
|
42 InitializeWindowViewport(this, 3, 17, 254, 86, this->wp->xy, ZOOM_LVL_MIN); |
|
43 |
|
44 this->FindWindowPlacementAndResize(desc); |
|
45 } |
|
46 |
|
47 virtual void OnPaint() |
|
48 { |
|
49 /* You can only change your own waypoints */ |
|
50 this->SetWidgetDisabledState(WAYPVW_RENAME, !CheckTileOwnership(this->wp->xy)); |
|
51 SetDParam(0, this->wp->index); |
|
52 this->DrawWidgets(); |
|
53 |
|
54 this->DrawViewport(); |
|
55 } |
|
56 |
|
57 virtual void OnClick(Point pt, int widget) |
|
58 { |
|
59 switch (widget) { |
|
60 case WAYPVW_CENTERVIEW: /* scroll to location */ |
|
61 if (_ctrl_pressed) { |
|
62 ShowExtraViewPortWindow(this->wp->xy); |
|
63 } else { |
|
64 ScrollMainWindowToTile(this->wp->xy); |
|
65 } |
|
66 break; |
|
67 |
|
68 case WAYPVW_RENAME: /* rename */ |
|
69 SetDParam(0, this->wp->index); |
|
70 ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL); |
|
71 break; |
|
72 |
|
73 case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/ |
|
74 ShowVehicleListWindow(this->wp); |
|
75 break; |
|
76 } |
|
77 } |
|
78 |
|
79 virtual void OnQueryTextFinished(char *str) |
|
80 { |
|
81 if (!StrEmpty(str)) { |
|
82 _cmd_text = str; |
|
83 DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); |
|
84 } |
|
85 } |
|
86 |
|
87 }; |
|
88 |
|
89 static const Widget _waypoint_view_widgets[] = { |
|
90 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // WAYPVW_CLOSEBOX |
|
91 { WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 247, 0, 13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS}, // WAYPVW_CAPTION |
|
92 { WWT_STICKYBOX, RESIZE_NONE, COLOUR_GREY, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, // WAYPVW_STICKY |
|
93 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 259, 14, 105, 0x0, STR_NULL}, // WAYPVW_VIEWPORTPANEL |
|
94 { WWT_INSET, RESIZE_NONE, COLOUR_GREY, 2, 257, 16, 103, 0x0, STR_NULL}, // WAYPVW_SPACER |
|
95 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 121, 106, 117, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // WAYPVW_CENTERVIEW |
|
96 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 122, 244, 106, 117, STR_0130_RENAME, STR_CHANGE_WAYPOINT_NAME}, // WAYPVW_RENAME |
|
97 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 245, 259, 106, 117, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // WAYPVW_SHOW_TRAINS |
|
98 { WIDGETS_END}, |
|
99 }; |
|
100 |
|
101 static const WindowDesc _waypoint_view_desc = { |
|
102 WDP_AUTO, WDP_AUTO, 260, 118, 260, 118, |
|
103 WC_WAYPOINT_VIEW, WC_NONE, |
|
104 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
|
105 _waypoint_view_widgets, |
|
106 }; |
|
107 |
|
108 void ShowWaypointWindow(const Waypoint *wp) |
|
109 { |
|
110 AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index); |
|
111 } |