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_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.    return; // _endthread() implied
  59. }
  60.  
  61.  
  62. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  63. {
  64.    unsigned short wParam_hiword;
  65.    unsigned short wParam_loword;
  66.  
  67.    // filter out the commonly used message values
  68.    wParam_hiword = HIWORD (wParam);
  69.    wParam_loword = LOWORD (wParam);
  70.  
  71.    // have we just fired up this window ?
  72.    if (message == WM_INITDIALOG)
  73.    {
  74.       // center the window
  75.       CenterWindow (hWnd, hMainWnd);
  76.  
  77.       // set dialog icons (small one for title bar & big one for task manager)
  78.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  79.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  80.  
  81.       // set window title and control texts
  82.       SetWindowText (hWnd, LOCALIZE (L"PlayerInfoName_Title"));
  83.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_QUESTION, LOCALIZE (L"PlayerInfoName_Question"));
  84.       SetDlgItemText (hWnd, BUTTON_DISPLAY, LOCALIZE (L"PlayerInfoName_Display"));
  85.       SetDlgItemText (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR, LOCALIZE (L"PlayerInfoName_StatusBar"));
  86.  
  87.       // convert the status bar message to a hyperlink
  88.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR));
  89.    }
  90.  
  91.    // else did we take action on one of the controls ?
  92.    else if (message == WM_COMMAND)
  93.    {
  94.       // was it the display button ?
  95.       if (wParam_loword == BUTTON_DISPLAY)
  96.       {
  97.          GetDlgItemText (hWnd, EDITBOX_PLAYERINFONAME_NAME, player_name, WCHAR_SIZEOF (player_name)); // get player name
  98.          PlayerCard_FindOrCreate (player_name); // and fire up the relevant player card
  99.  
  100.          EndDialog (hWnd, 1); // close the dialog box and return OK
  101.       }
  102.  
  103.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  104.       else if (wParam_loword == IDCANCEL)
  105.          EndDialog (hWnd, 0); // close the dialog box
  106.  
  107.       // else was it the status bar hyperlink ?
  108.       else if (wParam_loword == STATICTEXT_PLAYERINFONAME_STATUSBAR)
  109.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  110.    }
  111.  
  112.    // call the default dialog message processing function to keep things going
  113.    return (false);
  114. }
  115.