28 #include "date_func.h" |
28 #include "date_func.h" |
29 #include "string_func.h" |
29 #include "string_func.h" |
30 #include "settings_type.h" |
30 #include "settings_type.h" |
31 #include "widgets/dropdown_func.h" |
31 #include "widgets/dropdown_func.h" |
32 #include "widgets/dropdown_type.h" |
32 #include "widgets/dropdown_type.h" |
|
33 #include "tilehighlight_func.h" |
33 |
34 |
34 #include "table/sprites.h" |
35 #include "table/sprites.h" |
35 #include "table/strings.h" |
36 #include "table/strings.h" |
36 |
37 |
37 /* player face selection window */ |
38 /* player face selection window */ |
164 |
165 |
165 /* Recheck the size of the window as it might need to be resized due to the local player changing */ |
166 /* Recheck the size of the window as it might need to be resized due to the local player changing */ |
166 int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 74 + 10 * EXPENSES_END); |
167 int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 74 + 10 * EXPENSES_END); |
167 if (w->height != new_height) { |
168 if (w->height != new_height) { |
168 /* Make window dirty before and after resizing */ |
169 /* Make window dirty before and after resizing */ |
169 SetWindowDirty(w); |
170 w->SetDirty(); |
170 w->height = new_height; |
171 w->height = new_height; |
171 SetWindowDirty(w); |
172 w->SetDirty(); |
172 |
173 |
173 w->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player); |
174 w->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player); |
174 w->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player); |
175 w->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player); |
175 } |
176 } |
176 |
177 |
195 bool stickied = !!(w->flags4 & WF_STICKY); |
196 bool stickied = !!(w->flags4 & WF_STICKY); |
196 int oldtop = w->top; ///< current top position of the window before closing it |
197 int oldtop = w->top; ///< current top position of the window before closing it |
197 int oldleft = w->left; ///< current left position of the window before closing it |
198 int oldleft = w->left; ///< current left position of the window before closing it |
198 PlayerID player = (PlayerID)w->window_number; |
199 PlayerID player = (PlayerID)w->window_number; |
199 |
200 |
200 DeleteWindow(w); |
201 delete w; |
201 /* Open up the (toggled size) Finance window at the same position as the previous */ |
202 /* Open up the (toggled size) Finance window at the same position as the previous */ |
202 DoShowPlayerFinances(player, !HasBit(mode, 0), stickied, oldtop, oldleft); |
203 DoShowPlayerFinances(player, !HasBit(mode, 0), stickied, oldtop, oldleft); |
203 } |
204 } |
204 break; |
205 break; |
205 |
206 |
869 case PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: { |
870 case PFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: { |
870 int oldtop = w->top; ///< current top position of the window before closing it |
871 int oldtop = w->top; ///< current top position of the window before closing it |
871 int oldleft = w->left; ///< current top position of the window before closing it |
872 int oldleft = w->left; ///< current top position of the window before closing it |
872 |
873 |
873 DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE); |
874 DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE); |
874 DeleteWindow(w); |
875 delete w; |
875 /* Open up the (toggled size) Face selection window at the same position as the previous */ |
876 /* Open up the (toggled size) Face selection window at the same position as the previous */ |
876 DoSelectPlayerFace((PlayerID)w->window_number, !WP(w, facesel_d).advanced, oldtop, oldleft); |
877 DoSelectPlayerFace((PlayerID)w->window_number, !WP(w, facesel_d).advanced, oldtop, oldleft); |
877 } break; |
878 } break; |
878 |
879 |
879 /* Cancel button */ |
880 /* Cancel button */ |
880 case PFW_WIDGET_CANCEL: |
881 case PFW_WIDGET_CANCEL: |
881 DeleteWindow(w); |
882 delete w; |
882 break; |
883 break; |
883 |
884 |
884 /* OK button */ |
885 /* OK button */ |
885 case PFW_WIDGET_ACCEPT: |
886 case PFW_WIDGET_ACCEPT: |
886 DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE); |
887 DoCommandP(0, 0, *pf, NULL, CMD_SET_PLAYER_FACE); |
887 DeleteWindow(w); |
888 delete w; |
888 break; |
889 break; |
889 |
890 |
890 /* Load button */ |
891 /* Load button */ |
891 case PFW_WIDGET_LOAD: |
892 case PFW_WIDGET_LOAD: |
892 *pf = _player_face; |
893 *pf = _player_face; |
893 ScaleAllPlayerFaceBits(*pf); |
894 ScaleAllPlayerFaceBits(*pf); |
894 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_LOAD_DONE, 0, 0); |
895 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_LOAD_DONE, 0, 0); |
895 SetWindowDirty(w); |
896 w->SetDirty(); |
896 break; |
897 break; |
897 |
898 |
898 /* 'Player face number' button, view and/or set player face number */ |
899 /* 'Player face number' button, view and/or set player face number */ |
899 case PFW_WIDGET_FACECODE: |
900 case PFW_WIDGET_FACECODE: |
900 SetDParam(0, *pf); |
901 SetDParam(0, *pf); |
910 /* Toggle gender (male/female) button */ |
911 /* Toggle gender (male/female) button */ |
911 case PFW_WIDGET_MALE: |
912 case PFW_WIDGET_MALE: |
912 case PFW_WIDGET_FEMALE: |
913 case PFW_WIDGET_FEMALE: |
913 SetPlayerFaceBits(*pf, PFV_GENDER, ge, e->we.click.widget - PFW_WIDGET_MALE); |
914 SetPlayerFaceBits(*pf, PFV_GENDER, ge, e->we.click.widget - PFW_WIDGET_MALE); |
914 ScaleAllPlayerFaceBits(*pf); |
915 ScaleAllPlayerFaceBits(*pf); |
915 SetWindowDirty(w); |
916 w->SetDirty(); |
916 break; |
917 break; |
917 |
918 |
918 /* Randomize face button */ |
919 /* Randomize face button */ |
919 case PFW_WIDGET_RANDOM_NEW_FACE: |
920 case PFW_WIDGET_RANDOM_NEW_FACE: |
920 RandomPlayerFaceBits(*pf, ge, WP(w, facesel_d).advanced); |
921 RandomPlayerFaceBits(*pf, ge, WP(w, facesel_d).advanced); |
921 SetWindowDirty(w); |
922 w->SetDirty(); |
922 break; |
923 break; |
923 |
924 |
924 /* Toggle ethnicity (european/african) button */ |
925 /* Toggle ethnicity (european/african) button */ |
925 case PFW_WIDGET_ETHNICITY_EUR: |
926 case PFW_WIDGET_ETHNICITY_EUR: |
926 case PFW_WIDGET_ETHNICITY_AFR: |
927 case PFW_WIDGET_ETHNICITY_AFR: |
927 SetPlayerFaceBits(*pf, PFV_ETHNICITY, ge, e->we.click.widget - PFW_WIDGET_ETHNICITY_EUR); |
928 SetPlayerFaceBits(*pf, PFV_ETHNICITY, ge, e->we.click.widget - PFW_WIDGET_ETHNICITY_EUR); |
928 ScaleAllPlayerFaceBits(*pf); |
929 ScaleAllPlayerFaceBits(*pf); |
929 SetWindowDirty(w); |
930 w->SetDirty(); |
930 break; |
931 break; |
931 |
932 |
932 default: |
933 default: |
933 /* For all buttons from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R is the same function. |
934 /* For all buttons from PFW_WIDGET_HAS_MOUSTACHE_EARRING to PFW_WIDGET_GLASSES_R is the same function. |
934 * Therefor is this combined function. |
935 * Therefor is this combined function. |
975 /* Set a new player face number */ |
976 /* Set a new player face number */ |
976 if (!StrEmpty(e->we.edittext.str)) { |
977 if (!StrEmpty(e->we.edittext.str)) { |
977 *pf = strtoul(e->we.edittext.str, NULL, 10); |
978 *pf = strtoul(e->we.edittext.str, NULL, 10); |
978 ScaleAllPlayerFaceBits(*pf); |
979 ScaleAllPlayerFaceBits(*pf); |
979 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0); |
980 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_SET, 0, 0); |
980 SetWindowDirty(w); |
981 w->SetDirty(); |
981 } else { |
982 } else { |
982 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_ERR, 0, 0); |
983 ShowErrorMessage(INVALID_STRING_ID, STR_FACE_FACECODE_ERR, 0, 0); |
983 } |
984 } |
984 break; |
985 break; |
985 } |
986 } |
1268 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w); |
1269 SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w); |
1269 SetTileSelectSize(2, 2); |
1270 SetTileSelectSize(2, 2); |
1270 w->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ); |
1271 w->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ); |
1271 w->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ); |
1272 w->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ); |
1272 } else { |
1273 } else { |
1273 ScrollMainWindowToTile(tile); |
1274 if (_ctrl_pressed) { |
|
1275 ShowExtraViewPortWindow(tile); |
|
1276 } else { |
|
1277 ScrollMainWindowToTile(tile); |
|
1278 } |
1274 } |
1279 } |
1275 break; |
1280 break; |
1276 } |
1281 } |
1277 |
1282 |
1278 case PCW_WIDGET_RELOCATE_HQ: |
1283 case PCW_WIDGET_RELOCATE_HQ: |
1298 } |
1303 } |
1299 break; |
1304 break; |
1300 |
1305 |
1301 case WE_MOUSELOOP: |
1306 case WE_MOUSELOOP: |
1302 /* redraw the window every now and then */ |
1307 /* redraw the window every now and then */ |
1303 if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); |
1308 if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty(); |
1304 break; |
1309 break; |
1305 |
1310 |
1306 case WE_PLACE_OBJ: |
1311 case WE_PLACE_OBJ: |
1307 if (DoCommandP(e->we.place.tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS))) |
1312 if (DoCommandP(e->we.place.tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS))) |
1308 ResetObjectToPlace(); |
1313 ResetObjectToPlace(); |
1458 DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640); |
1463 DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640); |
1459 } |
1464 } |
1460 } break; |
1465 } break; |
1461 |
1466 |
1462 case WE_CLICK: /* Close the window (and show the highscore window) */ |
1467 case WE_CLICK: /* Close the window (and show the highscore window) */ |
1463 DeleteWindow(w); |
1468 delete w; |
1464 break; |
1469 break; |
1465 |
1470 |
1466 case WE_DESTROY: /* Show the highscore window when this one is closed */ |
1471 case WE_DESTROY: /* Show the highscore window when this one is closed */ |
1467 if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause |
1472 if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause |
1468 ShowHighscoreTable(w->window_number, WP(w, highscore_d).rank); |
1473 ShowHighscoreTable(w->window_number, WP(w, highscore_d).rank); |