109 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, int mode, PlaceProc *placeproc) |
109 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, int mode, PlaceProc *placeproc) |
110 { |
110 { |
111 if (IsWindowWidgetDisabled(w, widget)) return false; |
111 if (IsWindowWidgetDisabled(w, widget)) return false; |
112 |
112 |
113 SndPlayFx(SND_15_BEEP); |
113 SndPlayFx(SND_15_BEEP); |
114 SetWindowDirty(w); |
114 w->SetDirty(); |
115 |
115 |
116 if (IsWindowWidgetLowered(w, widget)) { |
116 if (IsWindowWidgetLowered(w, widget)) { |
117 ResetObjectToPlace(); |
117 ResetObjectToPlace(); |
118 return false; |
118 return false; |
119 } |
119 } |
454 dis >>= 1; |
454 dis >>= 1; |
455 } |
455 } |
456 } break; |
456 } break; |
457 |
457 |
458 case WE_DESTROY: { |
458 case WE_DESTROY: { |
459 Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
459 Window *v = Window::FindById(WC_MAIN_TOOLBAR, 0); |
460 RaiseWindowWidget(v, WP(w,menu_d).main_button); |
460 RaiseWindowWidget(v, WP(w,menu_d).main_button); |
461 SetWindowDirty(v); |
461 v->SetDirty(); |
462 return; |
462 return; |
463 } |
463 } |
464 |
464 |
465 case WE_POPUPMENU_SELECT: { |
465 case WE_POPUPMENU_SELECT: { |
466 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
466 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
467 int action_id; |
467 int action_id; |
468 |
468 |
469 |
469 |
470 if (index < 0) { |
470 if (index < 0) { |
471 Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); |
471 Window *w2 = Window::FindById(WC_MAIN_TOOLBAR,0); |
472 if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) |
472 if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) |
473 index = WP(w,menu_d).sel_index; |
473 index = WP(w,menu_d).sel_index; |
474 } |
474 } |
475 |
475 |
476 action_id = WP(w,menu_d).action_id; |
476 action_id = WP(w,menu_d).action_id; |
477 DeleteWindow(w); |
477 w->Close(); |
478 |
478 |
479 if (index >= 0) { |
479 if (index >= 0) { |
480 assert((uint)index <= lengthof(_menu_clicked_procs)); |
480 assert((uint)index <= lengthof(_menu_clicked_procs)); |
481 _menu_clicked_procs[action_id](index); |
481 _menu_clicked_procs[action_id](index); |
482 } |
482 } |
488 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
488 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
489 |
489 |
490 if (index == -1 || index == WP(w,menu_d).sel_index) return; |
490 if (index == -1 || index == WP(w,menu_d).sel_index) return; |
491 |
491 |
492 WP(w,menu_d).sel_index = index; |
492 WP(w,menu_d).sel_index = index; |
493 SetWindowDirty(w); |
493 w->SetDirty(); |
494 return; |
494 return; |
495 } |
495 } |
496 } |
496 } |
497 } |
497 } |
498 |
498 |
529 // Increase one to fit in PlayerList in the menu when in network |
529 // Increase one to fit in PlayerList in the menu when in network |
530 if (_networking && WP(w,menu_d).main_button == 9) num++; |
530 if (_networking && WP(w,menu_d).main_button == 9) num++; |
531 |
531 |
532 if (WP(w,menu_d).item_count != num) { |
532 if (WP(w,menu_d).item_count != num) { |
533 WP(w,menu_d).item_count = num; |
533 WP(w,menu_d).item_count = num; |
534 SetWindowDirty(w); |
534 w->SetDirty(); |
535 num = num * 10 + 2; |
535 num = num * 10 + 2; |
536 w->height = num; |
536 w->height = num; |
537 w->widget[0].bottom = w->widget[0].top + num - 1; |
537 w->widget[0].bottom = w->widget[0].top + num - 1; |
538 SetWindowDirty(w); |
538 w->SetDirty(); |
539 } |
539 } |
540 } |
540 } |
541 |
541 |
542 static void PlayerMenuWndProc(Window *w, WindowEvent *e) |
542 static void PlayerMenuWndProc(Window *w, WindowEvent *e) |
543 { |
543 { |
589 |
589 |
590 break; |
590 break; |
591 } |
591 } |
592 |
592 |
593 case WE_DESTROY: { |
593 case WE_DESTROY: { |
594 Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
594 Window *v = Window::FindById(WC_MAIN_TOOLBAR, 0); |
595 RaiseWindowWidget(v, WP(w,menu_d).main_button); |
595 RaiseWindowWidget(v, WP(w,menu_d).main_button); |
596 SetWindowDirty(v); |
596 v->SetDirty(); |
597 return; |
597 return; |
598 } |
598 } |
599 |
599 |
600 case WE_POPUPMENU_SELECT: { |
600 case WE_POPUPMENU_SELECT: { |
601 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
601 int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); |
608 } else { |
608 } else { |
609 index = GetPlayerIndexFromMenu(index); |
609 index = GetPlayerIndexFromMenu(index); |
610 } |
610 } |
611 |
611 |
612 if (index < 0) { |
612 if (index < 0) { |
613 Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); |
613 Window *w2 = Window::FindById(WC_MAIN_TOOLBAR,0); |
614 if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) |
614 if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) |
615 index = WP(w,menu_d).sel_index; |
615 index = WP(w,menu_d).sel_index; |
616 } |
616 } |
617 |
617 |
618 DeleteWindow(w); |
618 w->Close(); |
619 |
619 |
620 if (index >= 0) { |
620 if (index >= 0) { |
621 assert(index >= 0 && index < 30); |
621 assert(index >= 0 && index < 30); |
622 _menu_clicked_procs[action_id](index); |
622 _menu_clicked_procs[action_id](index); |
623 } |
623 } |
705 * we clicked on and w->left the toolbar window itself. So meaning that |
705 * we clicked on and w->left the toolbar window itself. So meaning that |
706 * the default position is aligned with the left side of the clicked button */ |
706 * the default position is aligned with the left side of the clicked button */ |
707 width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140); |
707 width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140); |
708 x = w->left + clamp(x, 0, w->width - width); // or alternatively '_screen.width - width' |
708 x = w->left + clamp(x, 0, w->width - width); // or alternatively '_screen.width - width' |
709 |
709 |
710 w = AllocateWindow(x, 22, width, item_count * 10 + 2, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets); |
710 w = Window::Allocate(x, 22, width, item_count * 10 + 2, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets); |
711 w->widget[0].bottom = item_count * 10 + 1; |
711 w->widget[0].bottom = item_count * 10 + 1; |
712 w->flags4 &= ~WF_WHITE_BORDER_MASK; |
712 w->flags4 &= ~WF_WHITE_BORDER_MASK; |
713 |
713 |
714 WP(w,menu_d).item_count = item_count; |
714 WP(w,menu_d).item_count = item_count; |
715 WP(w,menu_d).sel_index = 0; |
715 WP(w,menu_d).sel_index = 0; |
731 |
731 |
732 LowerWindowWidget(w, main_button); |
732 LowerWindowWidget(w, main_button); |
733 InvalidateWidget(w, main_button); |
733 InvalidateWidget(w, main_button); |
734 |
734 |
735 DeleteWindowById(WC_TOOLBAR_MENU, 0); |
735 DeleteWindowById(WC_TOOLBAR_MENU, 0); |
736 w = AllocateWindow(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); |
736 w = Window::Allocate(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); |
737 w->flags4 &= ~WF_WHITE_BORDER_MASK; |
737 w->flags4 &= ~WF_WHITE_BORDER_MASK; |
738 WP(w,menu_d).item_count = 0; |
738 WP(w,menu_d).item_count = 0; |
739 WP(w,menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); |
739 WP(w,menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); |
740 if (_networking && main_button == 9) { |
740 if (_networking && main_button == 9) { |
741 if (_local_player != PLAYER_SPECTATOR) { |
741 if (_local_player != PLAYER_SPECTATOR) { |
881 } |
881 } |
882 if (vp != NULL) { // the vp can be null when how == ZOOM_NONE |
882 if (vp != NULL) { // the vp can be null when how == ZOOM_NONE |
883 vp->virtual_left = WP(w, vp_d).scrollpos_x; |
883 vp->virtual_left = WP(w, vp_d).scrollpos_x; |
884 vp->virtual_top = WP(w, vp_d).scrollpos_y; |
884 vp->virtual_top = WP(w, vp_d).scrollpos_y; |
885 } |
885 } |
886 SetWindowDirty(w); |
886 w->SetDirty(); |
887 /* Update the windows that have zoom-buttons to perhaps disable their buttons */ |
887 /* Update the windows that have zoom-buttons to perhaps disable their buttons */ |
888 SendWindowMessageClass(w->window_class, how, w->window_number, 0); |
888 SendWindowMessageClass(w->window_class, how, w->window_number, 0); |
889 return true; |
889 return true; |
890 } |
890 } |
891 |
891 |
892 static void ToolbarZoomInClick(Window *w) |
892 static void ToolbarZoomInClick(Window *w) |
893 { |
893 { |
894 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
894 if (DoZoomInOutWindow(ZOOM_IN, Window::FindById(WC_MAIN_WINDOW, 0))) { |
895 HandleButtonClick(w, 17); |
895 w->HandleButtonClick(17); |
896 SndPlayFx(SND_15_BEEP); |
896 SndPlayFx(SND_15_BEEP); |
897 } |
897 } |
898 } |
898 } |
899 |
899 |
900 static void ToolbarZoomOutClick(Window *w) |
900 static void ToolbarZoomOutClick(Window *w) |
901 { |
901 { |
902 if (DoZoomInOutWindow(ZOOM_OUT,FindWindowById(WC_MAIN_WINDOW, 0))) { |
902 if (DoZoomInOutWindow(ZOOM_OUT,Window::FindById(WC_MAIN_WINDOW, 0))) { |
903 HandleButtonClick(w, 18); |
903 w->HandleButtonClick(18); |
904 SndPlayFx(SND_15_BEEP); |
904 SndPlayFx(SND_15_BEEP); |
905 } |
905 } |
906 } |
906 } |
907 |
907 |
908 static void ToolbarBuildRailClick(Window *w) |
908 static void ToolbarBuildRailClick(Window *w) |
973 |
973 |
974 static void ToolbarScenDateBackward(Window *w) |
974 static void ToolbarScenDateBackward(Window *w) |
975 { |
975 { |
976 // don't allow too fast scrolling |
976 // don't allow too fast scrolling |
977 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
977 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
978 HandleButtonClick(w, 6); |
978 w->HandleButtonClick(6); |
979 SetWindowDirty(w); |
979 w->SetDirty(); |
980 |
980 |
981 _patches_newgame.starting_year = clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR); |
981 _patches_newgame.starting_year = clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR); |
982 SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); |
982 SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); |
983 } |
983 } |
984 _left_button_clicked = false; |
984 _left_button_clicked = false; |
986 |
986 |
987 static void ToolbarScenDateForward(Window *w) |
987 static void ToolbarScenDateForward(Window *w) |
988 { |
988 { |
989 // don't allow too fast scrolling |
989 // don't allow too fast scrolling |
990 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
990 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
991 HandleButtonClick(w, 7); |
991 w->HandleButtonClick(7); |
992 SetWindowDirty(w); |
992 w->SetDirty(); |
993 |
993 |
994 _patches_newgame.starting_year = clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR); |
994 _patches_newgame.starting_year = clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR); |
995 SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); |
995 SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); |
996 } |
996 } |
997 _left_button_clicked = false; |
997 _left_button_clicked = false; |
1003 PopupMainToolbMenu(w, 8 | (17 << 8), STR_02DE_MAP_OF_WORLD, 4, 0); |
1003 PopupMainToolbMenu(w, 8 | (17 << 8), STR_02DE_MAP_OF_WORLD, 4, 0); |
1004 } |
1004 } |
1005 |
1005 |
1006 static void ToolbarScenZoomIn(Window *w) |
1006 static void ToolbarScenZoomIn(Window *w) |
1007 { |
1007 { |
1008 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
1008 if (DoZoomInOutWindow(ZOOM_IN, Window::FindById(WC_MAIN_WINDOW, 0))) { |
1009 HandleButtonClick(w, 9); |
1009 w->HandleButtonClick(9); |
1010 SndPlayFx(SND_15_BEEP); |
1010 SndPlayFx(SND_15_BEEP); |
1011 } |
1011 } |
1012 } |
1012 } |
1013 |
1013 |
1014 static void ToolbarScenZoomOut(Window *w) |
1014 static void ToolbarScenZoomOut(Window *w) |
1015 { |
1015 { |
1016 if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { |
1016 if (DoZoomInOutWindow(ZOOM_OUT, Window::FindById(WC_MAIN_WINDOW, 0))) { |
1017 HandleButtonClick(w, 10); |
1017 w->HandleButtonClick(10); |
1018 SndPlayFx(SND_15_BEEP); |
1018 SndPlayFx(SND_15_BEEP); |
1019 } |
1019 } |
1020 } |
1020 } |
1021 |
1021 |
1022 void ZoomInOrOutToCursorWindow(bool in, Window *w) |
1022 void ZoomInOrOutToCursorWindow(bool in, Window *w) |
1311 case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
1311 case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
1312 _editor_terraform_button_proc[e->we.click.widget - 4](w); |
1312 _editor_terraform_button_proc[e->we.click.widget - 4](w); |
1313 break; |
1313 break; |
1314 case 12: case 13: { /* Increase/Decrease terraform size */ |
1314 case 12: case 13: { /* Increase/Decrease terraform size */ |
1315 int size = (e->we.click.widget == 12) ? 1 : -1; |
1315 int size = (e->we.click.widget == 12) ? 1 : -1; |
1316 HandleButtonClick(w, e->we.click.widget); |
1316 w->HandleButtonClick(e->we.click.widget); |
1317 size += _terraform_size; |
1317 size += _terraform_size; |
1318 |
1318 |
1319 if (!IS_INT_INSIDE(size, 1, 8 + 1)) return; |
1319 if (!IS_INT_INSIDE(size, 1, 8 + 1)) return; |
1320 _terraform_size = size; |
1320 _terraform_size = size; |
1321 |
1321 |
1322 SndPlayFx(SND_15_BEEP); |
1322 SndPlayFx(SND_15_BEEP); |
1323 SetWindowDirty(w); |
1323 w->SetDirty(); |
1324 } break; |
1324 } break; |
1325 case 14: /* gen random land */ |
1325 case 14: /* gen random land */ |
1326 HandleButtonClick(w, 14); |
1326 w->HandleButtonClick(14); |
1327 ShowCreateScenario(); |
1327 ShowCreateScenario(); |
1328 break; |
1328 break; |
1329 case 15: /* Reset landscape */ |
1329 case 15: /* Reset landscape */ |
1330 ShowQuery( |
1330 ShowQuery( |
1331 STR_022C_RESET_LANDSCAPE, |
1331 STR_022C_RESET_LANDSCAPE, |
1381 AllocateWindowDescFront(&_scen_edit_land_gen_desc, 0); |
1381 AllocateWindowDescFront(&_scen_edit_land_gen_desc, 0); |
1382 } |
1382 } |
1383 |
1383 |
1384 static void ToolbarScenGenLand(Window *w) |
1384 static void ToolbarScenGenLand(Window *w) |
1385 { |
1385 { |
1386 HandleButtonClick(w, 11); |
1386 w->HandleButtonClick(11); |
1387 SndPlayFx(SND_15_BEEP); |
1387 SndPlayFx(SND_15_BEEP); |
1388 |
1388 |
1389 ShowEditorTerraformToolBar(); |
1389 ShowEditorTerraformToolBar(); |
1390 } |
1390 } |
1391 |
1391 |
1435 HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, 1, PlaceProc_Town); |
1435 HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, 1, PlaceProc_Town); |
1436 break; |
1436 break; |
1437 case 5: {/* random town */ |
1437 case 5: {/* random town */ |
1438 Town *t; |
1438 Town *t; |
1439 |
1439 |
1440 HandleButtonClick(w, 5); |
1440 w->HandleButtonClick(5); |
1441 _generating_world = true; |
1441 _generating_world = true; |
1442 t = CreateRandomTown(20, _scengen_town_size); |
1442 t = CreateRandomTown(20, _scengen_town_size); |
1443 _generating_world = false; |
1443 _generating_world = false; |
1444 |
1444 |
1445 if (t == NULL) { |
1445 if (t == NULL) { |
1449 } |
1449 } |
1450 |
1450 |
1451 break; |
1451 break; |
1452 } |
1452 } |
1453 case 6: {/* many random towns */ |
1453 case 6: {/* many random towns */ |
1454 HandleButtonClick(w, 6); |
1454 w->HandleButtonClick(6); |
1455 |
1455 |
1456 _generating_world = true; |
1456 _generating_world = true; |
1457 if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
1457 if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); |
1458 _generating_world = false; |
1458 _generating_world = false; |
1459 break; |
1459 break; |
1461 |
1461 |
1462 case 7: case 8: case 9: |
1462 case 7: case 8: case 9: |
1463 RaiseWindowWidget(w, (_scengen_town_size - 1) + 7); |
1463 RaiseWindowWidget(w, (_scengen_town_size - 1) + 7); |
1464 _scengen_town_size = (e->we.click.widget - 7) + 1; |
1464 _scengen_town_size = (e->we.click.widget - 7) + 1; |
1465 LowerWindowWidget(w, (_scengen_town_size - 1) + 7); |
1465 LowerWindowWidget(w, (_scengen_town_size - 1) + 7); |
1466 SetWindowDirty(w); |
1466 w->SetDirty(); |
1467 break; |
1467 break; |
1468 } |
1468 } |
1469 break; |
1469 break; |
1470 |
1470 |
1471 case WE_TIMEOUT: |
1471 case WE_TIMEOUT: |
1472 RaiseWindowWidget(w, 5); |
1472 RaiseWindowWidget(w, 5); |
1473 RaiseWindowWidget(w, 6); |
1473 RaiseWindowWidget(w, 6); |
1474 SetWindowDirty(w); |
1474 w->SetDirty(); |
1475 break; |
1475 break; |
1476 case WE_PLACE_OBJ: |
1476 case WE_PLACE_OBJ: |
1477 _place_proc(e->we.place.tile); |
1477 _place_proc(e->we.place.tile); |
1478 break; |
1478 break; |
1479 case WE_ABORT_PLACE_OBJ: |
1479 case WE_ABORT_PLACE_OBJ: |
1480 RaiseWindowButtons(w); |
1480 w->RaiseButtons(); |
1481 LowerWindowWidget(w, (_scengen_town_size - 1) + 7); |
1481 LowerWindowWidget(w, (_scengen_town_size - 1) + 7); |
1482 SetWindowDirty(w); |
1482 w->SetDirty(); |
1483 break; |
1483 break; |
1484 } |
1484 } |
1485 } |
1485 } |
1486 |
1486 |
1487 static const WindowDesc _scen_edit_town_gen_desc = { |
1487 static const WindowDesc _scen_edit_town_gen_desc = { |
1492 ScenEditTownGenWndProc, |
1492 ScenEditTownGenWndProc, |
1493 }; |
1493 }; |
1494 |
1494 |
1495 static void ToolbarScenGenTown(Window *w) |
1495 static void ToolbarScenGenTown(Window *w) |
1496 { |
1496 { |
1497 HandleButtonClick(w, 12); |
1497 w->HandleButtonClick(12); |
1498 SndPlayFx(SND_15_BEEP); |
1498 SndPlayFx(SND_15_BEEP); |
1499 |
1499 |
1500 AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0); |
1500 AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0); |
1501 } |
1501 } |
1502 |
1502 |
1643 DrawWindowWidgets(w); |
1643 DrawWindowWidgets(w); |
1644 break; |
1644 break; |
1645 |
1645 |
1646 case WE_CLICK: |
1646 case WE_CLICK: |
1647 if (e->we.click.widget == 3) { |
1647 if (e->we.click.widget == 3) { |
1648 HandleButtonClick(w, 3); |
1648 w->HandleButtonClick(3); |
1649 |
1649 |
1650 if (!AnyTownExists()) { |
1650 if (!AnyTownExists()) { |
1651 ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); |
1651 ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); |
1652 return; |
1652 return; |
1653 } |
1653 } |
1683 _ignore_restrictions = false; |
1683 _ignore_restrictions = false; |
1684 _generating_world = false; |
1684 _generating_world = false; |
1685 break; |
1685 break; |
1686 } |
1686 } |
1687 case WE_ABORT_PLACE_OBJ: |
1687 case WE_ABORT_PLACE_OBJ: |
1688 RaiseWindowButtons(w); |
1688 w->RaiseButtons(); |
1689 SetWindowDirty(w); |
1689 w->SetDirty(); |
1690 break; |
1690 break; |
1691 case WE_TIMEOUT: |
1691 case WE_TIMEOUT: |
1692 RaiseWindowWidget(w, 3); |
1692 RaiseWindowWidget(w, 3); |
1693 InvalidateWidget(w, 3); |
1693 InvalidateWidget(w, 3); |
1694 break; |
1694 break; |
1735 }; |
1735 }; |
1736 |
1736 |
1737 |
1737 |
1738 static void ToolbarScenGenIndustry(Window *w) |
1738 static void ToolbarScenGenIndustry(Window *w) |
1739 { |
1739 { |
1740 HandleButtonClick(w, 13); |
1740 w->HandleButtonClick(13); |
1741 SndPlayFx(SND_15_BEEP); |
1741 SndPlayFx(SND_15_BEEP); |
1742 AllocateWindowDescFront(_scenedit_industry_descs[_opt.landscape],0); |
1742 AllocateWindowDescFront(_scenedit_industry_descs[_opt.landscape],0); |
1743 } |
1743 } |
1744 |
1744 |
1745 static void ToolbarScenBuildRoad(Window *w) |
1745 static void ToolbarScenBuildRoad(Window *w) |
1746 { |
1746 { |
1747 HandleButtonClick(w, 14); |
1747 w->HandleButtonClick(14); |
1748 SndPlayFx(SND_15_BEEP); |
1748 SndPlayFx(SND_15_BEEP); |
1749 ShowBuildRoadScenToolbar(); |
1749 ShowBuildRoadScenToolbar(); |
1750 } |
1750 } |
1751 |
1751 |
1752 static void ToolbarScenPlantTrees(Window *w) |
1752 static void ToolbarScenPlantTrees(Window *w) |
1753 { |
1753 { |
1754 HandleButtonClick(w, 15); |
1754 w->HandleButtonClick(15); |
1755 SndPlayFx(SND_15_BEEP); |
1755 SndPlayFx(SND_15_BEEP); |
1756 ShowBuildTreesScenToolbar(); |
1756 ShowBuildTreesScenToolbar(); |
1757 } |
1757 } |
1758 |
1758 |
1759 static void ToolbarScenPlaceSign(Window *w) |
1759 static void ToolbarScenPlaceSign(Window *w) |
1760 { |
1760 { |
1761 HandleButtonClick(w, 16); |
1761 w->HandleButtonClick(16); |
1762 SndPlayFx(SND_15_BEEP); |
1762 SndPlayFx(SND_15_BEEP); |
1763 SelectSignTool(); |
1763 SelectSignTool(); |
1764 } |
1764 } |
1765 |
1765 |
1766 static void ToolbarBtn_NULL(Window *w) |
1766 static void ToolbarBtn_NULL(Window *w) |
1809 GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
1809 GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
1810 |
1810 |
1811 /* If spectator, disable all construction buttons |
1811 /* If spectator, disable all construction buttons |
1812 * ie : Build road, rail, ships, airports and landscaping |
1812 * ie : Build road, rail, ships, airports and landscaping |
1813 * Since enabled state is the default, just disable when needed */ |
1813 * Since enabled state is the default, just disable when needed */ |
1814 SetWindowWidgetsDisabledState(w, _current_player == PLAYER_SPECTATOR, 19, 20, 21, 22, 23, WIDGET_LIST_END); |
1814 w->SetWidgetsDisabledState(_current_player == PLAYER_SPECTATOR, 19, 20, 21, 22, 23, WIDGET_LIST_END); |
1815 /* disable company list drop downs, if there are no companies */ |
1815 /* disable company list drop downs, if there are no companies */ |
1816 SetWindowWidgetsDisabledState(w, ActivePlayerCount() == 0, 7, 8, 13, 14, 15, 16, WIDGET_LIST_END); |
1816 w->SetWidgetsDisabledState(ActivePlayerCount() == 0, 7, 8, 13, 14, 15, 16, WIDGET_LIST_END); |
1817 |
1817 |
1818 DrawWindowWidgets(w); |
1818 DrawWindowWidgets(w); |
1819 break; |
1819 break; |
1820 |
1820 |
1821 case WE_CLICK: { |
1821 case WE_CLICK: { |
1863 _place_proc(e->we.place.tile); |
1863 _place_proc(e->we.place.tile); |
1864 } break; |
1864 } break; |
1865 |
1865 |
1866 case WE_ABORT_PLACE_OBJ: { |
1866 case WE_ABORT_PLACE_OBJ: { |
1867 RaiseWindowWidget(w, 25); |
1867 RaiseWindowWidget(w, 25); |
1868 SetWindowDirty(w); |
1868 w->SetDirty(); |
1869 } break; |
1869 } break; |
1870 |
1870 |
1871 case WE_MOUSELOOP: |
1871 case WE_MOUSELOOP: |
1872 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
1872 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
1873 ToggleWidgetLoweredState(w, 0); |
1873 ToggleWidgetLoweredState(w, 0); |
2062 _place_proc(e->we.place.tile); |
2062 _place_proc(e->we.place.tile); |
2063 } break; |
2063 } break; |
2064 |
2064 |
2065 case WE_ABORT_PLACE_OBJ: { |
2065 case WE_ABORT_PLACE_OBJ: { |
2066 RaiseWindowWidget(w, 25); |
2066 RaiseWindowWidget(w, 25); |
2067 SetWindowDirty(w); |
2067 w->SetDirty(); |
2068 } break; |
2068 } break; |
2069 |
2069 |
2070 case WE_MOUSELOOP: |
2070 case WE_MOUSELOOP: |
2071 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
2071 if (IsWindowWidgetLowered(w, 0) != !!_pause) { |
2072 ToggleWidgetLoweredState(w, 0); |
2072 ToggleWidgetLoweredState(w, 0); |
2073 SetWindowDirty(w); |
2073 w->SetDirty(); |
2074 } |
2074 } |
2075 |
2075 |
2076 if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) { |
2076 if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) { |
2077 ToggleWidgetLoweredState(w, 1); |
2077 ToggleWidgetLoweredState(w, 1); |
2078 SetWindowDirty(w); |
2078 w->SetDirty(); |
2079 } |
2079 } |
2080 break; |
2080 break; |
2081 |
2081 |
2082 case WE_MESSAGE: |
2082 case WE_MESSAGE: |
2083 HandleZoomMessage(w, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 9, 10); |
2083 HandleZoomMessage(w, Window::FindById(WC_MAIN_WINDOW, 0)->viewport, 9, 10); |
2084 break; |
2084 break; |
2085 } |
2085 } |
2086 } |
2086 } |
2087 |
2087 |
2088 static const WindowDesc _toolb_scen_desc = { |
2088 static const WindowDesc _toolb_scen_desc = { |
2165 DrawStringCentered(320, 1, STR_SAVING_GAME, 0); |
2165 DrawStringCentered(320, 1, STR_SAVING_GAME, 0); |
2166 } else if (_do_autosave) { |
2166 } else if (_do_autosave) { |
2167 DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0); |
2167 DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0); |
2168 } else if (_pause) { |
2168 } else if (_pause) { |
2169 DrawStringCentered(320, 1, STR_0319_PAUSED, 0); |
2169 DrawStringCentered(320, 1, STR_0319_PAUSED, 0); |
2170 } else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) { |
2170 } else if (WP(w,def_d).data_1 > -1280 && Window::FindById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) { |
2171 // Draw the scrolling news text |
2171 // Draw the scrolling news text |
2172 if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1)) |
2172 if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1)) |
2173 WP(w,def_d).data_1 = -1280; |
2173 WP(w,def_d).data_1 = -1280; |
2174 } else { |
2174 } else { |
2175 if (p != NULL) { |
2175 if (p != NULL) { |
2183 if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, 489, 2); |
2183 if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, 489, 2); |
2184 } break; |
2184 } break; |
2185 |
2185 |
2186 case WE_MESSAGE: |
2186 case WE_MESSAGE: |
2187 w->message.msg = e->we.message.msg; |
2187 w->message.msg = e->we.message.msg; |
2188 SetWindowDirty(w); |
2188 w->SetDirty(); |
2189 break; |
2189 break; |
2190 |
2190 |
2191 case WE_CLICK: |
2191 case WE_CLICK: |
2192 switch (e->we.click.widget) { |
2192 switch (e->we.click.widget) { |
2193 case 1: ShowLastNewsMessage(); break; |
2193 case 1: ShowLastNewsMessage(); break; |
2413 } |
2413 } |
2414 |
2414 |
2415 width = _screen.width; |
2415 width = _screen.width; |
2416 height = _screen.height; |
2416 height = _screen.height; |
2417 |
2417 |
2418 w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
2418 w = Window::Allocate(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); |
2419 AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); |
2419 AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); |
2420 |
2420 |
2421 // XXX: these are not done |
2421 // XXX: these are not done |
2422 switch (_game_mode) { |
2422 switch (_game_mode) { |
2423 default: NOT_REACHED(); |
2423 default: NOT_REACHED(); |