//**************************************************************************
//*                   MODE 3 Lobby Screen                                  *
//**************************************************************************
static void checkMouseMode3(SDL_Event *event, SDL_Point *currentMouseLocation, SDL_Rect buttonPlacement[], int *select, int *mode, int modeMaxButtons[], bool *match, int *keyboardMode){
    for(int i=0; i < modeMaxButtons[3]; i++){
        if(mouseOnButton(currentMouseLocation, buttonPlacement, &i)){ // Is the mouse on button 'i' ?
            if(event->type == SDL_MOUSEBUTTONDOWN){
                *keyboardMode = ENTERING_TEXT;

                if(i == 2){                 // Ready
                    //playerReady = !playerReady;
                    SDLNet_TCP_Send(client.TCPSock, "#", strlen("#"));

                }
                else if(i == 1){            // Leave
                    isConnected = false;
                    SDLNet_TCP_Send(client.TCPSock, "-", strlen("-"));
                    SDLNet_TCP_Close(client.TCPSock);
                    SDLNet_UDP_Close(client.UDPRecvSock);
                    SDLNet_UDP_Close(client.UDPSendSock);

                    for(int i=0; i < MAX_PLAYERS; i++)
                        playerReady[i] = 0;

                    clearTextStrings(6);
                    printf("LEFT; '-' sent to server, socket closed, ready statuses cleared, textstrings cleared, mode changed\n"); //*****************************************
                    *mode = 5;
                }                           // (ELSE: Enter Chat Message Window Pressed)
            }
        }
    }
}
Exemple #2
0
bool UIButton::mouseDown(unsigned touchID, float x, float y)
{	
	if (touchOnButton != UINT_MAX) return false;
	if (!mouseOnButton(x, y)) return false;
	touchOnButton = touchID;
	
	// Switch to active state
	if (currentState == Normal) setState(NormalActive);
	else if (currentState == Secondary) setState(SecondaryActive);
	
	return true;
}
Exemple #3
0
bool UIButton::mouseUp(unsigned touchID, float x, float y)
{
	if (touchID == touchOnButton)
		touchOnButton = UINT_MAX;
	else return false;
	if (!mouseOnButton(x, y)) return false;
	
	// Switch to inactive state
	if (currentState == NormalActive) setState(Normal);
	else if (currentState == SecondaryActive) setState(Secondary);
	
	// Call action
	target->action(this);
	
	return true;
}
Exemple #4
0
bool UIButton::mouseDragged(unsigned touchID, float x, float y)
{
	if (touchID != touchOnButton) return false;
	
	if (mouseOnButton(x, y))
	{
		if (currentState == Normal) setState(NormalActive);
		else if (currentState == Secondary) setState(SecondaryActive);
		return true;
	}
	else
	{
		if (currentState == NormalActive) setState(Normal);
		else if (currentState == SecondaryActive) setState(Secondary);
		return false;
	}
}
//**************************************************************************
//*                   MODE 0 (Startup Screen)                              *
//**************************************************************************
static void checkMouseMode0(SDL_Event *event, SDL_Point *currentMouseLocation, SDL_Rect buttonPlacement[], int *select, int *mode, int modeMaxButtons[], bool *match, bool *quit){
    for(int i=0; i < modeMaxButtons[0]; i++){
        if(mouseOnButton(currentMouseLocation, buttonPlacement, &i)){ // Is the mouse on button 'i' ?
            *select = i;
            *match = true;
            if(event->type == SDL_MOUSEBUTTONDOWN){
                if(i == 2){     // EXIT
                    *quit = true;
                }
                else if(i == 1) // OPTIONS
                    printf("OPTIONS\n");
                else{           // FIND SERVERS
                    *mode = FIND_SERVERS;
                }
            }
        }
    }
    return;
}
//**************************************************************************
//*                   MODE 1 (Find Servers Screen)                         *
//**************************************************************************
static void checkMouseMode1(SDL_Event *event, SDL_Point *currentMouseLocation, SDL_Rect buttonPlacement[], int *select, int *mode, int modeMaxButtons[], bool *match){
    for(int i=0; i < modeMaxButtons[1]; i++){
        if(mouseOnButton(currentMouseLocation, buttonPlacement, &i)){ // Is the mouse on button 'i' ?
            *select = i;
            *match = true;
            if(event->type == SDL_MOUSEBUTTONDOWN){
                if(i == 2){         // BACK
                    *mode = STARTUP;
                }
                else if(i == 1){     // JOIN CUSTOM SERVER
                    *mode = JOIN_CUSTOM;
                    *select = -1;
                }
                else{               // JOIN DEFAULT SERVER
                    printf("JOIN DEFAULT SERVER\n");
                }
            }
        }
    }
    return;
}
//**************************************************************************
//*                   MODE 5 (Join Custom Server Screen)                   *
//**************************************************************************
static void checkMouseMode5(SDL_Event *event, SDL_Point *currentMouseLocation, SDL_Rect buttonPlacement[], int *select, int *mode, int modeMaxButtons[], bool *match, int *keyboardMode){
    for(int i=0; i < modeMaxButtons[5]; i++){
        if(mouseOnButton(currentMouseLocation, buttonPlacement, &i)){ // Is the mouse on button 'i' ?
            if(event->type == SDL_MOUSEBUTTONDOWN){
                *keyboardMode = NONE;

                if(i == 4){         // GO!
                    joinLobby(mode);
                }
                else if(i == 3){    // Close
                    *mode = FIND_SERVERS;
                }
                else{    // Enter IP _OR_ Port _OR_ Name Field
                    *select = i;
                    *keyboardMode = ENTERING_TEXT;
                    *match = true;
                }
            }
        }
    }
    return;
}