Subversion Repositories Games.Chess Giants

Rev

Rev 140 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // dialog_pawnpromotion.cpp
  2.  
  3. #include "../common.h"
  4.  
  5.  
  6. // dialog template
  7. #define THIS_DIALOG DIALOG_PAWNPROMOTION
  8.  
  9.  
  10. // global variables used in this module only
  11. static int promotion_type = PART_NONE;
  12.  
  13.  
  14. // prototypes of local functions
  15. static void StartThread_ThisDialog (void *thread_parms);
  16. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
  17.  
  18.  
  19. void DialogBox_PawnPromotion (void)
  20. {
  21.    // helper function to fire up the modeless dialog box
  22.  
  23.    _beginthread (StartThread_ThisDialog, 0, NULL); // so fire up a new one
  24.  
  25.    return; // return as soon as the thread is fired up
  26. }
  27.  
  28.  
  29. void DialogBox_PawnPromotion_Validated (void)
  30. {
  31.    // callback function called by the main game thread when the dialog box is validated
  32.  
  33.    boardmove_t *currentmove;
  34.  
  35.    // remember this callback is no longer to be called
  36.    is_dialogbox_pawnpromotion_validated = false;
  37.  
  38.    currentmove = &the_board.moves[the_board.move_count - 1]; // quick access to previous move
  39.  
  40.    // save promotion type and promote the part to the desired type
  41.    currentmove->promotion_type = promotion_type;
  42.    Move_SetSlot (currentmove, currentmove->target[0], currentmove->target[1], currentmove->color, currentmove->promotion_type);
  43.  
  44.    // evaluate new check and stalemate status
  45.    currentmove->is_check = Move_IsCheck (currentmove, 1 - currentmove->color); // save whether opponent is in check or not
  46.    currentmove->is_stalemate = Move_IsStaleMate (currentmove, 1 - currentmove->color); // save whether opponent is stalemate
  47.  
  48.    // re-describe our move in Standard Abbreviated Notation and describe the resulting table in Forsyth-Edwards Notation
  49.    Move_DescribeInSAN (currentmove);
  50.    Move_DescribeInFEN (currentmove);
  51.  
  52.    // forget the hovered and selected positions
  53.    Board_SetSelectedAndHovered (&the_board, -1, -1, -1, -1);
  54.  
  55.    the_board.has_playerchanged = true; // pawn promotion is complete, we can switch players now
  56.    the_board.reevaluate = true; // evaluate the new board
  57.    the_scene.update = true; // and redraw the scene
  58.  
  59.    return; // finished, pawn has been promoted to the desired part type
  60. }
  61.  
  62.  
  63. static void StartThread_ThisDialog (void *thread_parms)
  64. {
  65.    // this function runs in a separate thread, for that's the only way (seemingly)
  66.    // to implement a non-modal message box using the Common Controls library.
  67.  
  68.    // display the dialog box
  69.    promotion_type = DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog);
  70.    if (promotion_type > 0)
  71.       is_dialogbox_pawnpromotion_validated = true;
  72.  
  73.    return; // _endthread() implied
  74. }
  75.  
  76.  
  77. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  78. {
  79.    // message handler for the dialog box
  80.  
  81.    unsigned short wParam_hiword;
  82.    unsigned short wParam_loword;
  83.  
  84.    // filter out the commonly used message values
  85.    wParam_hiword = HIWORD (wParam);
  86.    wParam_loword = LOWORD (wParam);
  87.  
  88.    // have we just fired up this window ?
  89.    if (message == WM_INITDIALOG)
  90.    {
  91.       // center the window
  92.       CenterWindow (hWnd, hMainWnd);
  93.  
  94.       // set dialog icons (small one for title bar & big one for task manager)
  95.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  96.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  97.  
  98.       // set window title and control texts
  99.       SetWindowText (hWnd, LOCALIZE (L"PawnPromotion_Title"));
  100.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_QUESTION), LOCALIZE (L"PawnPromotion_Question"));
  101.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR), LOCALIZE (L"PawnPromotion_StatusBar"));
  102.  
  103.       // convert the bitmaps to clickable things
  104.       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_ROOK));
  105.       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_KNIGHT));
  106.       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_BISHOP));
  107.       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_QUEEN));
  108.  
  109.       // convert the status bar message to a hyperlink
  110.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR));
  111.    }
  112.  
  113.    // else did we take action on one of the controls ?
  114.    else if (message == WM_COMMAND)
  115.    {
  116.       // was it the "rook" button ?
  117.       if (wParam_loword == BUTTON_ROOK)
  118.          EndDialog (hWnd, PART_ROOK); // close the dialog box and return a "promote to rook" value
  119.  
  120.       // else was it the "knight" button ?
  121.       else if (wParam_loword == BUTTON_KNIGHT)
  122.          EndDialog (hWnd, PART_KNIGHT); // close the dialog box and return a "promote to knight" value
  123.  
  124.       // else was it the "bishop" button ?
  125.       else if (wParam_loword == BUTTON_BISHOP)
  126.          EndDialog (hWnd, PART_BISHOP); // close the dialog box and return a "promote to bishop" value
  127.  
  128.       // else was it the "queen" button ?
  129.       else if (wParam_loword == BUTTON_QUEEN)
  130.          EndDialog (hWnd, PART_QUEEN); // close the dialog box and return a "promote to queen" value
  131.  
  132.       // else was it the status bar hyperlink ?
  133.       else if (wParam_loword == STATICTEXT_PAWNPROMOTION_STATUSBAR)
  134.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  135.    }
  136.  
  137.    // call the default dialog message processing function to keep things going
  138.    return (false);
  139. }
  140.