Subversion Repositories Games.Chess Giants

Rev

Rev 124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 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
 
140 pmbaty 32
   is_dialogbox_displayed = true;
1 pmbaty 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;
140 pmbaty 58
   is_dialogbox_displayed = false;
1 pmbaty 59
 
124 pmbaty 60
   the_board.reevaluate = true; // refresh the GUI buttons if needed
1 pmbaty 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
      // convert the status bar message to a hyperlink
91
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PLAYERINFONAME_STATUSBAR));
92
   }
93
 
94
   // else did we take action on one of the controls ?
95
   else if (message == WM_COMMAND)
96
   {
97
      // was it the display button ?
98
      if (wParam_loword == BUTTON_DISPLAY)
99
      {
100
         GetDlgItemText (hWnd, EDITBOX_PLAYERINFONAME_NAME, player_name, WCHAR_SIZEOF (player_name)); // get player name
101
         PlayerCard_FindOrCreate (player_name); // and fire up the relevant player card
102
 
103
         EndDialog (hWnd, 1); // close the dialog box and return OK
104
      }
105
 
106
      // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
107
      else if (wParam_loword == IDCANCEL)
108
         EndDialog (hWnd, 0); // close the dialog box
109
 
110
      // else was it the status bar hyperlink ?
111
      else if (wParam_loword == STATICTEXT_PLAYERINFONAME_STATUSBAR)
112
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
113
   }
114
 
115
   // call the default dialog message processing function to keep things going
116
   return (false);
117
}