Skip to content

Commit

Permalink
libcommon: Added 'userValue' argument to Hu_MsgStart()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 21, 2012
1 parent 0a409f9 commit 57d8065
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 165 deletions.
90 changes: 50 additions & 40 deletions doomsday/plugins/common/include/hu_msg.h
@@ -1,46 +1,30 @@
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2005-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2012 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
/**
* @file hu_msg.h
* Important state change messages.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* @authors Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2012 Daniel Swanson <danij@dengine.net>
* @authors Copyright &copy; 1993-1996 by id Software, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

/**
* hu_msg.h: Important state change messages.
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef __HUD_MESSAGE_H__
#define __HUD_MESSAGE_H__
#ifndef LIBCOMMON_HUD_MESSAGE_H
#define LIBCOMMON_HUD_MESSAGE_H

#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#elif __JSTRIFE__
# include "jstrife.h"
#endif
#include "common.h"

typedef enum {
MSG_CANCEL = -1,
Expand All @@ -49,25 +33,51 @@ typedef enum {
NUM_MESSAGE_RESPONSES
} msgresponse_t;

typedef int (C_DECL *msgfunc_t) (msgresponse_t response, void* context);
typedef int (C_DECL *msgfunc_t) (msgresponse_t response, int userValue, void* userPointer);

typedef enum {
MSG_ANYKEY,
MSG_YESNO,
NUM_MESSAGE_TYPES
} msgtype_t;

/**
* Called during the PreInit of each game during start up.
* Register Cvars and CCmds for the important messages.
*/
void Hu_MsgRegister(void);

/**
* Called during init.
*/
void Hu_MsgInit(void);

/**
* Called during engine shutdown.
*/
void Hu_MsgShutdown(void);

/**
* Updates on Game Tick.
*/
void Hu_MsgTicker(void);

/**
* If an "any key" message is active, respond to the event.
*/
int Hu_MsgResponder(event_t* ev);

/**
* Draw any active message.
*/
void Hu_MsgDrawer(void);

boolean Hu_IsMessageActive(void);
boolean Hu_IsMessageActiveWithCallback(msgfunc_t callback);

void Hu_MsgStart(msgtype_t type, const char* msg, msgfunc_t callback, void* context);
/**
* Begin a new game state message/question.
*/
void Hu_MsgStart(msgtype_t type, const char* msg, msgfunc_t callback, int userValue, void* userPointer);

#endif
#endif /// LIBCOMMON_HUD_MESSAGE_H
6 changes: 6 additions & 0 deletions doomsday/plugins/common/include/p_savedef.h
Expand Up @@ -36,6 +36,8 @@
# define SAVEGAMEEXTENSION "dsg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define REBORN_SLOT 9

#elif __JDOOM64__
# define MY_SAVE_MAGIC 0x1D6420F4
# define MY_CLIENT_SAVE_MAGIC 0x2D6420F4
Expand All @@ -47,6 +49,8 @@
# define SAVEGAMEEXTENSION "6sg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define REBORN_SLOT 9

#elif __JHERETIC__
# define MY_SAVE_MAGIC 0x7D9A12C5
# define MY_CLIENT_SAVE_MAGIC 0x1062AF43
Expand All @@ -58,6 +62,8 @@
# define SAVEGAMEEXTENSION "hsg"
# define SAVEGAME_DEFAULT_DIR "savegame"

# define REBORN_SLOT 9

#elif __JHEXEN__
# define HXS_VERSION_TEXT "HXS Ver " // Do not change me!
# define HXS_VERSION_TEXT_LENGTH 16
Expand Down
44 changes: 18 additions & 26 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -1133,7 +1133,7 @@ void G_StartHelp(void)
Con_Message("Warning: InFine script 'help' not defined, ignoring.\n");
}

int G_EndGameResponse(msgresponse_t response, void* context)
int G_EndGameResponse(msgresponse_t response, int userValue, void* userPointer)
{
if(response == MSG_YES)
{
Expand All @@ -1155,19 +1155,19 @@ void G_EndGame(void)

if(!userGame)
{
Hu_MsgStart(MSG_ANYKEY, ENDNOGAME, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, ENDNOGAME, NULL, 0, NULL);
return;
}

/*
if(IS_NETGAME)
{
Hu_MsgStart(MSG_ANYKEY, NETEND, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, NETEND, NULL, 0, NULL);
return;
}
*/

Hu_MsgStart(MSG_YESNO, IS_CLIENT? GET_TXT(TXT_DISCONNECT) : ENDGAME, G_EndGameResponse, NULL);
Hu_MsgStart(MSG_YESNO, IS_CLIENT? GET_TXT(TXT_DISCONNECT) : ENDGAME, G_EndGameResponse, 0, NULL);
}

void G_DoLoadMap(void)
Expand Down Expand Up @@ -2688,7 +2688,7 @@ void G_InitNew(skillmode_t skill, uint episode, uint map)
G_DoLoadMap();
}

int G_QuitGameResponse(msgresponse_t response, void* context)
int G_QuitGameResponse(msgresponse_t response, int userValue, void* userPointer)
{
if(response == MSG_YES)
{
Expand Down Expand Up @@ -2725,7 +2725,7 @@ void G_QuitGame(void)
#endif

Con_Open(false);
Hu_MsgStart(MSG_YESNO, endString, G_QuitGameResponse, NULL);
Hu_MsgStart(MSG_YESNO, endString, G_QuitGameResponse, 0, NULL);
}

/**
Expand Down Expand Up @@ -3356,11 +3356,11 @@ D_CMD(OpenSaveMenu)
return true;
}

int loadGameConfirmResponse(msgresponse_t response, void* context)
int loadGameConfirmResponse(msgresponse_t response, int userValue, void* userPointer)
{
if(response == MSG_YES)
{
const int slot = *(int*)context;
const int slot = userValue;
G_LoadGame(slot);
}
return true;
Expand All @@ -3377,7 +3377,7 @@ D_CMD(LoadGame)
if(IS_NETGAME)
{
S_LocalSound(SFX_QUICKLOAD_PROMPT, NULL);
Hu_MsgStart(MSG_ANYKEY, QLOADNET, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, QLOADNET, NULL, 0, NULL);
return false;
}

Expand All @@ -3399,13 +3399,13 @@ D_CMD(LoadGame)
dd_snprintf(buf, 80, QLPROMPT, Str_Text(&info->name));

S_LocalSound(SFX_QUICKLOAD_PROMPT, NULL);
Hu_MsgStart(MSG_YESNO, buf, loadGameConfirmResponse, (void*)&slot);
Hu_MsgStart(MSG_YESNO, buf, loadGameConfirmResponse, slot, 0);
return true;
}
else if(!stricmp(argv[1], "quick") || !stricmp(argv[1], "<quick>"))
{
S_LocalSound(SFX_QUICKLOAD_PROMPT, NULL);
Hu_MsgStart(MSG_ANYKEY, QSAVESPOT, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, QSAVESPOT, NULL, 0, NULL);
return true;
}

Expand Down Expand Up @@ -3433,17 +3433,13 @@ D_CMD(QuickLoadGame)
return DD_Execute(true, "loadgame quick");
}

typedef struct {
int slot;
const char* name;
} savegameconfirmresponse_params_t;

int saveGameConfirmResponse(msgresponse_t response, void* context)
int saveGameConfirmResponse(msgresponse_t response, int userValue, void* userPointer)
{
if(response == MSG_YES)
{
savegameconfirmresponse_params_t* p = (savegameconfirmresponse_params_t*)context;
G_SaveGame2(p->slot, p->name);
const int slot = userValue;
const char* name = (const char*)userPointer;
G_SaveGame2(slot, name);
}
return true;
}
Expand All @@ -3465,14 +3461,14 @@ D_CMD(SaveGame)
if(player->playerState == PST_DEAD || Get(DD_PLAYBACK))
{
S_LocalSound(SFX_QUICKSAVE_PROMPT, NULL);
Hu_MsgStart(MSG_ANYKEY, SAVEDEAD, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, SAVEDEAD, NULL, 0, NULL);
return true;
}

if(G_GameState() != GS_MAP)
{
S_LocalSound(SFX_QUICKSAVE_PROMPT, NULL);
Hu_MsgStart(MSG_ANYKEY, SAVEOUTMAP, NULL, NULL);
Hu_MsgStart(MSG_ANYKEY, SAVEOUTMAP, NULL, 0, NULL);
return true;
}

Expand All @@ -3492,15 +3488,11 @@ D_CMD(SaveGame)
}

{
savegameconfirmresponse_params_t p;
const gamesaveinfo_t* info = SV_GameSaveInfoForSlot(slot);
dd_snprintf(buf, 80, QSPROMPT, Str_Text(&info->name));

p.slot = slot;
p.name = name;

S_LocalSound(SFX_QUICKSAVE_PROMPT, NULL);
Hu_MsgStart(MSG_YESNO, buf, saveGameConfirmResponse, (void*)&p);
Hu_MsgStart(MSG_YESNO, buf, saveGameConfirmResponse, slot, (void*)name);
}
return true;
}
Expand Down

0 comments on commit 57d8065

Please sign in to comment.