Mercurial > hg > openttd
comparison src/ship_gui.cpp @ 7530:614aeff92fd3 draft
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 05 Sep 2007 23:26:45 +0000 |
parents | 307a03e3f031 |
children | e6f32e659811 |
comparison
equal
deleted
inserted
replaced
7529:d334553f6db4 | 7530:614aeff92fd3 |
---|---|
25 if (v->index == selection) { | 25 if (v->index == selection) { |
26 DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY); | 26 DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 static void ShipDetailsWndProc(Window *w, WindowEvent *e) | |
31 { | |
32 switch (e->event) { | |
33 case WE_PAINT: { | |
34 const Vehicle *v = GetVehicle(w->window_number); | |
35 StringID str; | |
36 | |
37 SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); | |
38 /* disable service-scroller when interval is set to disabled */ | |
39 SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships); | |
40 SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships); | |
41 | |
42 SetDParam(0, v->index); | |
43 DrawWindowWidgets(w); | |
44 | |
45 /* Draw running cost */ | |
46 { | |
47 int year = v->age / 366; | |
48 | |
49 SetDParam(1, year); | |
50 | |
51 SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED); | |
52 SetDParam(2, v->max_age / 366); | |
53 SetDParam(3, v->GetDisplayRunningCost()); | |
54 DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0); | |
55 } | |
56 | |
57 /* Draw max speed */ | |
58 { | |
59 SetDParam(0, v->GetDisplayMaxSpeed()); | |
60 DrawString(2, 25, STR_9813_MAX_SPEED, 0); | |
61 } | |
62 | |
63 /* Draw profit */ | |
64 { | |
65 SetDParam(0, v->profit_this_year); | |
66 SetDParam(1, v->profit_last_year); | |
67 DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0); | |
68 } | |
69 | |
70 /* Draw breakdown & reliability */ | |
71 { | |
72 SetDParam(0, v->reliability * 100 >> 16); | |
73 SetDParam(1, v->breakdowns_since_last_service); | |
74 DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0); | |
75 } | |
76 | |
77 /* Draw service interval text */ | |
78 { | |
79 SetDParam(0, v->service_interval); | |
80 SetDParam(1, v->date_of_last_service); | |
81 DrawString(13, 102, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0); | |
82 } | |
83 | |
84 DrawShipImage(v, 3, 57, INVALID_VEHICLE); | |
85 | |
86 SetDParam(0, v->engine_type); | |
87 SetDParam(1, v->build_year); | |
88 SetDParam(2, v->value); | |
89 DrawString(74, 57, STR_9816_BUILT_VALUE, 0); | |
90 | |
91 SetDParam(0, v->cargo_type); | |
92 SetDParam(1, v->cargo_cap); | |
93 DrawString(74, 67, STR_9817_CAPACITY, 0); | |
94 | |
95 str = STR_8812_EMPTY; | |
96 if (!v->cargo.Empty()) { | |
97 SetDParam(0, v->cargo_type); | |
98 SetDParam(1, v->cargo.Count()); | |
99 SetDParam(2, v->cargo.Source()); | |
100 str = STR_8813_FROM; | |
101 } | |
102 DrawString(74, 78, str, 0); | |
103 | |
104 /* Draw Transfer credits text */ | |
105 SetDParam(0, v->cargo.FeederShare()); | |
106 DrawString(74, 89, STR_FEEDER_CARGO_VALUE, 0); | |
107 | |
108 } break; | |
109 | |
110 case WE_CLICK: { | |
111 int mod; | |
112 const Vehicle *v; | |
113 switch (e->we.click.widget) { | |
114 case 2: /* rename */ | |
115 v = GetVehicle(w->window_number); | |
116 SetDParam(0, v->index); | |
117 ShowQueryString(STR_VEHICLE_NAME, STR_9831_NAME_SHIP, 31, 150, w, CS_ALPHANUMERAL); | |
118 break; | |
119 case 5: /* increase int */ | |
120 mod = _ctrl_pressed? 5 : 10; | |
121 goto do_change_service_int; | |
122 case 6: /* decrease int */ | |
123 mod = _ctrl_pressed ? - 5 : -10; | |
124 do_change_service_int: | |
125 v = GetVehicle(w->window_number); | |
126 | |
127 mod = GetServiceIntervalClamped(mod + v->service_interval); | |
128 if (mod == v->service_interval) return; | |
129 | |
130 DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); | |
131 break; | |
132 } | |
133 } break; | |
134 | |
135 case WE_ON_EDIT_TEXT: | |
136 if (e->we.edittext.str[0] != '\0') { | |
137 _cmd_text = e->we.edittext.str; | |
138 DoCommandP(0, w->window_number, 0, NULL, | |
139 CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP)); | |
140 } | |
141 break; | |
142 } | |
143 } | |
144 | |
145 | |
146 static const Widget _ship_details_widgets[] = { | |
147 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, | |
148 { WWT_CAPTION, RESIZE_NONE, 14, 11, 364, 0, 13, STR_9811_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, | |
149 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_982F_NAME_SHIP}, | |
150 { WWT_PANEL, RESIZE_NONE, 14, 0, 404, 14, 55, 0x0, STR_NULL}, | |
151 { WWT_PANEL, RESIZE_NONE, 14, 0, 404, 56, 100, 0x0, STR_NULL}, | |
152 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, | |
153 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, | |
154 { WWT_PANEL, RESIZE_NONE, 14, 11, 404, 101, 112, 0x0, STR_NULL}, | |
155 { WIDGETS_END}, | |
156 }; | |
157 | |
158 static const WindowDesc _ship_details_desc = { | |
159 WDP_AUTO, WDP_AUTO, 405, 113, 405, 113, | |
160 WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, | |
161 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, | |
162 _ship_details_widgets, | |
163 ShipDetailsWndProc | |
164 }; | |
165 | |
166 void ShowShipDetailsWindow(const Vehicle *v) | |
167 { | |
168 Window *w; | |
169 VehicleID veh = v->index; | |
170 | |
171 DeleteWindowById(WC_VEHICLE_ORDERS, veh); | |
172 DeleteWindowById(WC_VEHICLE_DETAILS, veh); | |
173 w = AllocateWindowDescFront(&_ship_details_desc, veh); | |
174 w->caption_color = v->owner; | |
175 } | |
176 | |
177 void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) | 30 void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) |
178 { | 31 { |
179 const Vehicle *v; | 32 const Vehicle *v; |
180 if (!success) return; | 33 if (!success) return; |
181 | 34 |
184 _backup_orders_tile = 0; | 37 _backup_orders_tile = 0; |
185 RestoreVehicleOrders(v, _backup_orders_data); | 38 RestoreVehicleOrders(v, _backup_orders_data); |
186 } | 39 } |
187 ShowVehicleViewWindow(v); | 40 ShowVehicleViewWindow(v); |
188 } | 41 } |
42 | |
43 /** | |
44 * Draw the details for the given vehicle at the position (x,y) | |
45 * | |
46 * @param v current vehicle | |
47 * @param x The x coordinate | |
48 * @param y The y coordinate | |
49 */ | |
50 void DrawShipDetails(const Vehicle *v, int x, int y) | |
51 { | |
52 SetDParam(0, v->engine_type); | |
53 SetDParam(1, v->build_year); | |
54 SetDParam(2, v->value); | |
55 DrawString(x, y, STR_9816_BUILT_VALUE, 0); | |
56 | |
57 SetDParam(0, v->cargo_type); | |
58 SetDParam(1, v->cargo_cap); | |
59 DrawString(x, y + 10, STR_9817_CAPACITY, 0); | |
60 | |
61 StringID str = STR_8812_EMPTY; | |
62 if (!v->cargo.Empty()) { | |
63 SetDParam(0, v->cargo_type); | |
64 SetDParam(1, v->cargo.Count()); | |
65 SetDParam(2, v->cargo.Source()); | |
66 str = STR_8813_FROM; | |
67 } | |
68 DrawString(x, y + 21, str, 0); | |
69 | |
70 /* Draw Transfer credits text */ | |
71 SetDParam(0, v->cargo.FeederShare()); | |
72 DrawString(x, y + 33, STR_FEEDER_CARGO_VALUE, 0); | |
73 } |