253 RTW_REMOVE, |
253 RTW_REMOVE, |
254 }; |
254 }; |
255 |
255 |
256 typedef void OnButtonClick(Window *w); |
256 typedef void OnButtonClick(Window *w); |
257 |
257 |
|
258 |
|
259 /** Toogles state of the Remove button of Build road toolbar |
|
260 * @param w window the button belongs to |
|
261 */ |
|
262 static void ToggleRoadButton_Remove(Window *w) |
|
263 { |
|
264 w->ToggleWidgetLoweredState(RTW_REMOVE); |
|
265 w->InvalidateWidget(RTW_REMOVE); |
|
266 _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); |
|
267 SetSelectionRed(_remove_button_clicked); |
|
268 } |
|
269 |
|
270 /** Updates the Remove button because of Ctrl state change |
|
271 * @param w window the button belongs to |
|
272 * @return true iff the remove buton was changed |
|
273 */ |
|
274 static bool RoadToolbar_CtrlChanged(Window *w) |
|
275 { |
|
276 if (w->IsWidgetDisabled(RTW_REMOVE)) return false; |
|
277 |
|
278 /* allow ctrl to switch remove mode only for these widgets */ |
|
279 for (uint i = RTW_ROAD_X; i <= RTW_AUTOROAD; i++) { |
|
280 if (w->IsWidgetLowered(i)) { |
|
281 ToggleRoadButton_Remove(w); |
|
282 return true; |
|
283 } |
|
284 } |
|
285 |
|
286 return false; |
|
287 } |
|
288 |
|
289 |
258 /** |
290 /** |
259 * Function that handles the click on the |
291 * Function that handles the click on the |
260 * X road placement button. |
292 * X road placement button. |
261 * |
293 * |
262 * @param w The current window |
294 * @param w The current window |
336 } |
368 } |
337 |
369 |
338 static void BuildRoadClick_Remove(Window *w) |
370 static void BuildRoadClick_Remove(Window *w) |
339 { |
371 { |
340 if (w->IsWidgetDisabled(RTW_REMOVE)) return; |
372 if (w->IsWidgetDisabled(RTW_REMOVE)) return; |
341 SetWindowDirty(w); |
373 ToggleRoadButton_Remove(w); |
342 SndPlayFx(SND_15_BEEP); |
374 SndPlayFx(SND_15_BEEP); |
343 w->ToggleWidgetLoweredState(RTW_REMOVE); |
|
344 SetSelectionRed(w->IsWidgetLowered(RTW_REMOVE)); |
|
345 } |
375 } |
346 |
376 |
347 /** Array with the handlers of the button-clicks for the road-toolbar */ |
377 /** Array with the handlers of the button-clicks for the road-toolbar */ |
348 static OnButtonClick* const _build_road_button_proc[] = { |
378 static OnButtonClick* const _build_road_button_proc[] = { |
349 BuildRoadClick_X_Dir, |
379 BuildRoadClick_X_Dir, |
444 _remove_button_clicked = false; |
474 _remove_button_clicked = false; |
445 _one_way_button_clicked = false; |
475 _one_way_button_clicked = false; |
446 _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w); |
476 _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w); |
447 } |
477 } |
448 UpdateOptionWidgetStatus(w, e->we.click.widget); |
478 UpdateOptionWidgetStatus(w, e->we.click.widget); |
|
479 if (_ctrl_pressed) RoadToolbar_CtrlChanged(w); |
449 break; |
480 break; |
450 |
481 |
451 case WE_KEYPRESS: |
482 case WE_KEYPRESS: |
452 for (uint8 i = 0; i != lengthof(_road_keycodes); i++) { |
483 for (uint8 i = 0; i != lengthof(_road_keycodes); i++) { |
453 if (e->we.keypress.keycode == _road_keycodes[i]) { |
484 if (e->we.keypress.keycode == _road_keycodes[i]) { |
454 e->we.keypress.cont = false; |
485 e->we.keypress.cont = false; |
455 _remove_button_clicked = false; |
486 _remove_button_clicked = false; |
456 _one_way_button_clicked = false; |
487 _one_way_button_clicked = false; |
457 _build_road_button_proc[i](w); |
488 _build_road_button_proc[i](w); |
458 UpdateOptionWidgetStatus(w, i + RTW_ROAD_X); |
489 UpdateOptionWidgetStatus(w, i + RTW_ROAD_X); |
|
490 if (_ctrl_pressed) RoadToolbar_CtrlChanged(w); |
459 break; |
491 break; |
460 } |
492 } |
461 } |
493 } |
462 MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection |
494 MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection |
463 break; |
495 break; |