Skip to content

Commit

Permalink
Preview maps when hovering over them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed Dec 4, 2011
1 parent 5718af7 commit 48eda8d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
25 changes: 20 additions & 5 deletions src/multiint.cpp
Expand Up @@ -3479,7 +3479,8 @@ void runMultiOptions(void)
{
static UDWORD lastrefresh = 0;
UDWORD id, value, i;
char sTemp[128];
char sTemp[128], oldGameMap[128];
int oldMaxPlayers;
PLAYERSTATS playerStats;
W_CONTEXT context;

Expand Down Expand Up @@ -3551,7 +3552,8 @@ void runMultiOptions(void)
if(multiRequestUp)
{
id = widgRunScreen(psRScreen); // a requester box is up.
if( runMultiRequester(id,&id,(char*)&sTemp,&value))
bool isHoverPreview;
if (runMultiRequester(id, &id, (char *)&sTemp, &value, &isHoverPreview))
{
switch(id)
{
Expand All @@ -3570,17 +3572,30 @@ void runMultiOptions(void)
netPlayersUpdated = true;
break;
case MULTIOP_MAP:
sstrcpy(oldGameMap, game.map);
oldMaxPlayers = game.maxPlayers;

sstrcpy(game.map, sTemp);
game.maxPlayers =(UBYTE) value;
loadMapPreview(true);
game.maxPlayers = value;
loadMapPreview(!isHoverPreview);

if (isHoverPreview)
{
sstrcpy(game.map, oldGameMap);
game.maxPlayers = oldMaxPlayers;
}

widgSetString(psWScreen,MULTIOP_MAP,sTemp);
addGameOptions();
break;
default:
loadMapPreview(false); // Restore the preview of the old map.
break;
}
addPlayerBox( !ingame.bHostSetup );
if (!isHoverPreview)
{
addPlayerBox( !ingame.bHostSetup );
}
}
}
else
Expand Down
28 changes: 25 additions & 3 deletions src/multimenu.cpp
Expand Up @@ -158,6 +158,7 @@ static char const * M_REQUEST_NP_TIPS[] = { N_("2 players"), N_("3 players"),
#define R_BUT_H 30

bool multiRequestUp = false; //multimenu is up.
static unsigned hoverPreviewId;
static bool giftsUp[MAX_PLAYERS] = {true}; //gift buttons for player are up.

char debugMenuEntry[DEBUGMENU_MAX_ENTRIES][MAX_STR_LENGTH];
Expand Down Expand Up @@ -604,6 +605,7 @@ void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD mo
}
}
multiRequestUp = true;
hoverPreviewId = 0;


// if it's map select then add the cam style buttons.
Expand Down Expand Up @@ -663,24 +665,44 @@ static void closeMultiRequester(void)
return;
}

bool runMultiRequester(UDWORD id,UDWORD *mode, char *chosen,UDWORD *chosenValue)
bool runMultiRequester(UDWORD id, UDWORD *mode, char *chosen, UDWORD *chosenValue, bool *isHoverPreview)
{
if( (id == M_REQUEST_CLOSE) || CancelPressed() ) // user hit close box || hit the cancel key
{
closeMultiRequester();
*mode = 0;
return true;
}

if( id>=M_REQUEST_BUT && id<=M_REQUEST_BUTM) // chose a file.
bool hoverPreview = false;
if (id == 0 && context == MULTIOP_MAP)
{
id = widgGetMouseOver(psRScreen);
if (id == hoverPreviewId)
{
id = 0; // Don't re-render preview.
}
hoverPreview = true;
}
if (id >= M_REQUEST_BUT && id <= M_REQUEST_BUTM) // chose a file.
{
strcpy(chosen,((W_BUTTON *)widgGetFromID(psRScreen,id))->pText );

*chosenValue = ((W_BUTTON *)widgGetFromID(psRScreen,id))->UserData ;
closeMultiRequester();
*mode = context;
*isHoverPreview = hoverPreview;
hoverPreviewId = id;
if (!hoverPreview)
{
closeMultiRequester();
}

return true;
}
if (hoverPreview)
{
id = 0;
}

switch (id)
{
Expand Down
2 changes: 1 addition & 1 deletion src/multimenu.h
Expand Up @@ -31,7 +31,7 @@
extern void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD id,UBYTE mapCam, UBYTE numPlayers);
extern bool multiRequestUp;
extern W_SCREEN *psRScreen; // requester stuff.
extern bool runMultiRequester(UDWORD id,UDWORD *contextmode, char *chosen,UDWORD *chosenValue);
bool runMultiRequester(UDWORD id, UDWORD *mode, char *chosen, UDWORD *chosenValue, bool *isHoverPreview);
extern void displayRequestOption(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);

// multimenu
Expand Down

0 comments on commit 48eda8d

Please sign in to comment.