Subversion Repositories Games.Chess Giants

Rev

Rev 1 | Rev 140 | Go to most recent revision | 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];
  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.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new message box thread
  33.  
  34.    return; // return as soon as the thread is fired up
  35. }
  36.  
  37.  
  38. void DialogBox_PlayerInfoName_Validated (void)
  39. {
  40.    // callback function called by the main game thread when the dialog box is validated
  41.  
  42.    // remember this callback is no longer to be called
  43.    is_dialogbox_playerinfoname_validated = false;
  44.  
  45.    return; // finished
  46. }
  47.  
  48.  
  49. static void StartThread_ThisDialog (void *thread_parms)
  50. {
  51.    // this function runs in a separate thread, for that's the only way (seemingly)
  52.    // to implement a non-modal message box using the Common Controls library.
  53.  
  54.    // display the dialog box
  55.    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
  56.       is_dialogbox_playerinfoname_validated = true;
  57.  
  58.    the_board.reevaluate = true; // refresh the GUI buttons if needed
  59.    return; // _endthread() implied
  60. }
  61.  
  62.  
  63. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  64. {
  65.    unsigned short wParam_hiword;
  66.    unsigned short wParam_loword;
  67.  
  68.    // filter out the commonly used message values
  69.    wParam_hiword = HIWORD (wParam);
  70.    wParam_loword = LOWORD (wParam);
  71.  
  72.    // have we just fired up this window ?
  73.    if (message == WM_INITDIALOG)
  74.    {
  75.       // center the window
  76.       CenterWindow (hWnd, hMainWnd);
  77.  
  78.       // set dialog icons (small one for title bar & big one for task manager)
  79.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  80.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  81.  
  82.       // set window title and control texts
  83.       SetWindowText (hWnd, LOCALIZE (L"PlayerInfoName_Title"));
  84.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_QUESTION, LOCALIZE (L"PlayerInfoName_Question"));
  85.       SetDlgItemText (hWnd, BUTTON_DISPLAY, LOCALIZE (L"PlayerInfoName_Display"));
  86.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR, LOCALIZE (L"PlayerInfoName_StatusBar"));
  87.  
  88.       // convert the status bar message to a hyperlink
  89.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR));
  90.    }
  91.  
  92.    // else did we take action on one of the controls ?
  93.    else if (message == WM_COMMAND)
  94.    {
  95.       // was it the display button ?
  96.       if (wParam_loword == BUTTON_DISPLAY)
  97.       {
  98.          GetDlgItemText (hWnd, EDITBOX_PLAYERINFONAME_NAME, player_name, WCHAR_SIZEOF (player_name)); // get player name
  99.          PlayerCard_FindOrCreate (player_name); // and fire up the relevant player card
  100.  
  101.          EndDialog (hWnd, 1); // close the dialog box and return OK
  102.       }
  103.  
  104.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  105.       else if (wParam_loword == IDCANCEL)
  106.          EndDialog (hWnd, 0); // close the dialog box
  107.  
  108.       // else was it the status bar hyperlink ?
  109.       else if (wParam_loword == STATICTEXT_PLAYERINFONAME_STATUSBAR)
  110.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  111.    }
  112.  
  113.    // call the default dialog message processing function to keep things going
  114.    return (false);
  115. }
  116.