Subversion Repositories Games.Chess Giants

Rev

Rev 140 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // dialog_playerinfoname.cpp
  2.  
  3. #include "../common.h"
  4.  
  5.  
  6. // dialog template
  7. #define THIS_DIALOG DIALOG_PLAYERINFONAME
  8.  
  9.  
  10. // global variables
  11. static wchar_t player_name[64] = L"";
  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_PlayerInfoName (void)
  20. {
  21.    // helper function to fire up the modeless dialog box
  22.  
  23.    player_t *network_player;
  24.  
  25.    network_player = Player_FindByType (PLAYER_INTERNET); // quick access to network player
  26.    if (network_player == NULL)
  27.       return; // consistency check
  28.  
  29.    if (lastonlineplayers_time + 5.0f < current_time)
  30.       Player_SendBuffer_Add (network_player, 1000, L"who\n"); // request a players list update
  31.  
  32.    is_dialogbox_displayed = true;
  33.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new message box thread
  34.  
  35.    return; // return as soon as the thread is fired up
  36. }
  37.  
  38.  
  39. void DialogBox_PlayerInfoName_Validated (void)
  40. {
  41.    // callback function called by the main game thread when the dialog box is validated
  42.  
  43.    // remember this callback is no longer to be called
  44.    is_dialogbox_playerinfoname_validated = false;
  45.  
  46.    return; // finished
  47. }
  48.  
  49.  
  50. static void StartThread_ThisDialog (void *thread_parms)
  51. {
  52.    // this function runs in a separate thread, for that's the only way (seemingly)
  53.    // to implement a non-modal message box using the Common Controls library.
  54.  
  55.    // display the dialog box
  56.    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
  57.       is_dialogbox_playerinfoname_validated = true;
  58.    is_dialogbox_displayed = false;
  59.  
  60.    the_board.reevaluate = true; // refresh the GUI buttons if needed
  61.    return; // _endthread() implied
  62. }
  63.  
  64.  
  65. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  66. {
  67.    unsigned short wParam_hiword;
  68.    unsigned short wParam_loword;
  69.  
  70.    // filter out the commonly used message values
  71.    wParam_hiword = HIWORD (wParam);
  72.    wParam_loword = LOWORD (wParam);
  73.  
  74.    // have we just fired up this window ?
  75.    if (message == WM_INITDIALOG)
  76.    {
  77.       // center the window
  78.       CenterWindow (hWnd, hMainWnd);
  79.  
  80.       // set dialog icons (small one for title bar & big one for task manager)
  81.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  82.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  83.  
  84.       // set window title and control texts
  85.       SetWindowText (hWnd, LOCALIZE (L"PlayerInfoName_Title"));
  86.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_QUESTION, LOCALIZE (L"PlayerInfoName_Question"));
  87.       SetDlgItemText (hWnd, BUTTON_DISPLAY, LOCALIZE (L"PlayerInfoName_Display"));
  88.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR, LOCALIZE (L"PlayerInfoName_StatusBar"));
  89.  
  90.       // set the edit box value, select it and send focus to it
  91.       SetDlgItemText (hWnd, EDITBOX_PLAYERINFONAME_NAME, player_name); // reuse last player name asked for
  92.       SendMessage (GetDlgItem (hWnd, EDITBOX_PLAYERINFONAME_NAME), EM_SETSEL, 0, -1);
  93.       SetFocus (GetDlgItem (hWnd, EDITBOX_PLAYERINFONAME_NAME));
  94.  
  95.       // convert the status bar message to a hyperlink
  96.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR));
  97.    }
  98.  
  99.    // else did we take action on one of the controls ?
  100.    else if (message == WM_COMMAND)
  101.    {
  102.       // was it the display button ?
  103.       if (wParam_loword == BUTTON_DISPLAY)
  104.       {
  105.          GetDlgItemText (hWnd, EDITBOX_PLAYERINFONAME_NAME, player_name, WCHAR_SIZEOF (player_name)); // get player name
  106.          PlayerCard_FindOrCreate (player_name); // and fire up the relevant player card
  107.  
  108.          EndDialog (hWnd, 1); // close the dialog box and return OK
  109.       }
  110.  
  111.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  112.       else if (wParam_loword == IDCANCEL)
  113.          EndDialog (hWnd, 0); // close the dialog box
  114.  
  115.       // else was it the status bar hyperlink ?
  116.       else if (wParam_loword == STATICTEXT_PLAYERINFONAME_STATUSBAR)
  117.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  118.    }
  119.  
  120.    // call the default dialog message processing function to keep things going
  121.    return (false);
  122. }
  123.