Skip to content

Commit caad960

Browse files
committed
Added usermessage_c.create_message function to access IServerPluginHelpers->CreateMessage functionality. A fix for KeyValues instantiation and implementation of the Color class are needed in order to use the functionality.
1 parent 414eb91 commit caad960

File tree

4 files changed

+74
-13
lines changed

4 files changed

+74
-13
lines changed

src/core/core/sp_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern PLUGIN_RESULT DispatchClientCommand(edict_t *pEntity, const CCommand &com
100100
//---------------------------------------------------------------------------------
101101
CSourcePython g_SourcePythonPlugin;
102102
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CSourcePython, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_SourcePythonPlugin );
103+
IServerPluginCallbacks *pPlugin;
103104

104105
//---------------------------------------------------------------------------------
105106
// Helper console variable to tell scripters what engine version we are running
@@ -196,6 +197,8 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn
196197
ConnectTier2Libraries( &interfaceFactory, 2 );
197198
#endif
198199

200+
pPlugin = this;
201+
199202
// Get all engine interfaces.
200203
if( !GetInterfaces(gEngineInterfaces, interfaceFactory) ) {
201204
return false;

src/core/modules/usermessage/usermessage.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,22 @@
2424
* Development Team grants this exception to all derivative works.
2525
*/
2626

27+
//-----------------------------------------------------------------------------
28+
// Includes.
29+
//-----------------------------------------------------------------------------
2730
#include "usermessage.h"
28-
31+
#include "public/engine/iserverplugin.h"
32+
#include "core/sp_main.h"
33+
34+
//-----------------------------------------------------------------------------
35+
// Externals.
36+
//-----------------------------------------------------------------------------
37+
extern IServerPluginHelpers *helpers;
38+
extern IServerPluginCallbacks *pPlugin;
39+
40+
//-----------------------------------------------------------------------------
41+
// CUserMessage implementation.
42+
//-----------------------------------------------------------------------------
2943
CUserMessage::CUserMessage(const MRecipientFilter &recipient_filter, const char *message_name ) :
3044
CUserMessageImplementation(recipient_filter, message_name),
3145
m_sent(false)
@@ -105,3 +119,11 @@ void CUserMessage::set_string( const char *field_name, const char *field_value,
105119
{
106120
CUserMessageImplementation::set_string(field_name, field_value, index);
107121
}
122+
123+
//-----------------------------------------------------------------------------
124+
// Functions.
125+
//-----------------------------------------------------------------------------
126+
void CreateMessage( edict_t *pEdict, DIALOG_TYPE type, KeyValues *data )
127+
{
128+
helpers->CreateMessage(pEdict, type, data, pPlugin);
129+
}

src/core/modules/usermessage/usermessage.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
#ifndef _USERMESSAGE_H_
2828
#define _USERMESSAGE_H_
2929

30+
//-----------------------------------------------------------------------------
31+
// Includes.
32+
//-----------------------------------------------------------------------------
3033
#include "irecipientfilter.h"
31-
3234
#include "utility/wrap_macros.h"
33-
3435
#include GAME_INCLUDE_PATH(usermessage_implementation.h)
36+
#include "public/engine/iserverplugin.h"
3537

38+
//-----------------------------------------------------------------------------
39+
// CUserMessage.
40+
//-----------------------------------------------------------------------------
3641
class CUserMessage : public CUserMessageImplementation
3742
{
3843
public:
@@ -64,4 +69,9 @@ class CUserMessage : public CUserMessageImplementation
6469
bool m_sent;
6570
};
6671

67-
#endif
72+
//-----------------------------------------------------------------------------
73+
// Functions.
74+
//-----------------------------------------------------------------------------
75+
void CreateMessage( edict_t *pEdict, DIALOG_TYPE type, KeyValues *data );
76+
77+
#endif // _USERMESSAGE_H_

src/core/modules/usermessage/usermessage_wrap_python.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@
2424
* Development Team grants this exception to all derivative works.
2525
*/
2626

27+
//-----------------------------------------------------------------------------
28+
// Includes.
29+
//-----------------------------------------------------------------------------
2730
#include "modules/export_main.h"
2831
#include "usermessage.h"
2932

30-
//---------------------------------------------------------------------------------
33+
//-----------------------------------------------------------------------------
3134
// Namespaces to use
32-
//---------------------------------------------------------------------------------
35+
//-----------------------------------------------------------------------------
3336
using namespace boost::python;
3437

35-
//---------------------------------------------------------------------------------
38+
//-----------------------------------------------------------------------------
3639
// Exposer functions.
37-
//---------------------------------------------------------------------------------
40+
//-----------------------------------------------------------------------------
3841
void export_usermessage_interface();
42+
void export_message_functions();
43+
void export_dialog_enum();
3944

40-
//---------------------------------------------------------------------------------
45+
//-----------------------------------------------------------------------------
4146
// Method overloads
42-
//---------------------------------------------------------------------------------
47+
//-----------------------------------------------------------------------------
4348
DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_char, 2, 3);
4449
DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_byte, 2, 3);
4550
DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_short, 2, 3);
@@ -49,12 +54,14 @@ DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_bool, 2, 3);
4954
DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_string, 2, 3);
5055
DECLARE_CLASS_METHOD_OVERLOAD(CUserMessage, set_buffer, 3, 4);
5156

52-
//---------------------------------------------------------------------------------
57+
//-----------------------------------------------------------------------------
5358
// Exposes the engine module.
54-
//---------------------------------------------------------------------------------
59+
//-----------------------------------------------------------------------------
5560
DECLARE_SP_MODULE(usermessage_c)
5661
{
5762
export_usermessage_interface();
63+
export_message_functions();
64+
export_dialog_enum();
5865
}
5966

6067
void export_usermessage_interface()
@@ -139,4 +146,23 @@ void export_usermessage_interface()
139146
)
140147

141148
BOOST_END_CLASS()
142-
}
149+
}
150+
151+
void export_message_functions()
152+
{
153+
def("create_message",
154+
CreateMessage,
155+
"Creates an onscreen menu with various option buttons"
156+
);
157+
}
158+
159+
void export_dialog_enum()
160+
{
161+
enum_<DIALOG_TYPE>("DialogType")
162+
ENUM_VALUE("MSG", DIALOG_MSG)
163+
ENUM_VALUE("MENU", DIALOG_MENU)
164+
ENUM_VALUE("TEXT", DIALOG_TEXT)
165+
ENUM_VALUE("ENTRY", DIALOG_ENTRY)
166+
ENUM_VALUE("ASKCONNECT", DIALOG_ASKCONNECT)
167+
BOOST_END_CLASS()
168+
}

0 commit comments

Comments
 (0)