Based on the previous announcement, the main task today is to add the initial interface and the Setup interface
Initial interface
Click the Start button, if you have successfully connected to the server in the settings, it will enter the account login interface, or pop-up window error
void Start () { // start Game button if0) { MessageBox (NULL, " is not connected to the server, please enter the IP in the settings "," error " , MB_OK); } Else { 1; // Account Login Page }}
Start button
The connected variable in the code when the IP connection in the Settings page is successful 1,FORM1 represents the account login interface (FORM0 as the initial interface, form for the game interface, FORM3 for the Settings page)
Settings page
The IP input box and the Connect button still take advantage of the previous function, but the coordinates change when the two controls are initialized because of the position change.
All of the buttons and input boxes are defined using the previously written button and InputBox.
Button Back_button (Changex (0), Changey (768-666), Changex (124-0) + 1, Changey (707-666) + 1, back);
Button Connect_button (Changex (806), Changey (768-366), Changex (921-806) + 1, Changey (420-366) + 1, Conne Cttoserver);
Button Musicon_button (Changex (428), Changey (768-463), Changex (664-428) + 1, Changey (517-463) + 1, Musico n);
Button Musicoff_button (Changex (658), Changey (768-463), Changex (921-658) + 1, Changey (517-463) + 1, Musi COFF);
Button Fullscreen_button (Changex (428), Changey (768-556), Changex (664-428) + 1, Changey (610-556) + 1, Fu Llscreen);
Button Window_button (Changex (685), Changey (768-556), Changex (921-685) + 1, Changey (610-556) + 1, Wind ow);
InputBox ip_inputbox (Changex (428), Changey (768-366), Changex (795-428) + 1, Changey (420-366) + 1);
The last parameter of the button object is the corresponding function that is bound by the mouse click response
classButton { Public: Doublex; Doubley; DoubleW; Doubleh; Clickevent clickevent; //button FunctionButton (DoubleX1,DoubleY1,DoubleW1,Doubleh1,clickevent CK) {x=X1; Y=Y1; W=W1; H=H1; Clickevent=ck; } voidDraw () {//Draw ButtonGLCOLOR3F (0,0,0); Glbegin (gl_quads); GLVERTEX2F (x+W, y); glvertex2f (x, y); glvertex2f (x, y-h); GLVERTEX2F (x+w, Yh); Glend (); } voidClickDoubleX1,DoubleY1) {//Click Response function if(x1 >= x&&x1 <= x + w&&y1 >= y-h&&y1 <=y) {clickevent (); } }};
Button
The click Response function for each button is implemented as follows:
voidConnecttoserver () {StringStream ss (IP_INPUTBOX.S); intA, B, C, D; CharC1, C2, C3; SS>> a >> c1 >> b >> C2 >> C >> C3 >>D; if(C1 = ='.'&&C2 = ='.'&&C3 = ='.'&&a <=255&& a >=0&& b <=255&& b >=0&& C <=255&& C >=0&& D <=255&& D >=0) {SERVIP=Ip_inputbox.s.c_str (); intStatus =client (); if(Status = =0) {MessageBox (NULL,"Connection Successful","Success", MB_OK);//*Connected =1;//* } Else if(Status = =1) {MessageBox (NULL,"connection failed, please try again","Error", MB_OK); } //form = 1; } Else{ip_inputbox.s.clear (); MessageBox (NULL,"IP address format input error, please re-enter","Error", MB_OK); }}
Connect
When the IP input does not conform to the specification, it will prompt the following error
When the connection is successful
When the connection fails
void Musicon () { // Open Music button * PlaySound ("res/abc.wav" , NULL, Snd_filename | snd_async);}
Music on
void Musicoff () { // Close Music button * PlaySound (null, NULL, NULL);}
Music off
void fullscreen () { // Full Screen button * glutfullscreen ();}
fullscreen
void window () { // windowing button * glutreshapewindow (1366768); // Change window size int cx = glutget (glut_screen_width); // Get screen size int cy = glutget (glut_screen_height); 1366 2 768 2); // Window Center }
window
void back () { // return button * 0; // return to initial interface }
Back
Through the above work, I learned how to maximize the window and restore the window, referring to the http://www.xuebuyuan.com/1559974.html
And the OpenGL Setup window centering method, refer to the http://www.linuxidc.com/Linux/2012-04/58982.htm
And the use of the MessageBox, referring to the Baidu encyclopedia
Slimer Soft Engineering Daily-June 30, 2016