From 82029b56ff0f1ad51db73af5bd37c4ee1e5d2bdc Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 9 Jan 2014 21:00:02 -0800 Subject: [PATCH] pfGameGUIMsg => plString --- .../pfConsole/pfGameConsoleCommands.cpp | 14 ++++---- .../FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp | 6 ++-- .../FeatureLib/pfMessage/pfGameGUIMsg.h | 34 +++++++++++-------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfGameConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfGameConsoleCommands.cpp index 6cbfbcdf..6faca0e4 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfGameConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfGameConsoleCommands.cpp @@ -136,7 +136,7 @@ PF_CONSOLE_CMD( Game, LoadDialog, "string dlgName", "Loads the given GUI dialog if( mgrKey ) { pfGameGUIMsg *msg = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kLoadDialog ); - msg->SetString( params[ 0 ] ); + msg->SetString( (const char *)params[ 0 ] ); plgDispatch::MsgSend( msg ); } } @@ -148,8 +148,8 @@ PF_CONSOLE_CMD( Game, LoadLocalDialog, "string ageName, string dlgName", "Loads if( mgrKey ) { pfGameGUIMsg *msg = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kLoadDialog ); - msg->SetString( params[ 1 ] ); - msg->SetAge( params[ 0 ] ); + msg->SetString( (const char *)params[ 1 ] ); + msg->SetAge( (const char *)params[ 0 ] ); plgDispatch::MsgSend( msg ); } } @@ -161,7 +161,7 @@ PF_CONSOLE_CMD( Game, ShowDialog, "string dlgName", "Shows the given GUI dialog" if( mgrKey ) { pfGameGUIMsg *msg = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kShowDialog ); - msg->SetString( params[ 0 ] ); + msg->SetString( (const char *)params[ 0 ] ); plgDispatch::MsgSend( msg ); } } @@ -173,7 +173,7 @@ PF_CONSOLE_CMD( Game, HideDialog, "string dlgName", "Hides the given GUI dialog" if( mgrKey ) { pfGameGUIMsg *msg = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kHideDialog ); - msg->SetString( params[ 0 ] ); + msg->SetString( (const char *)params[ 0 ] ); plgDispatch::MsgSend( msg ); } } @@ -187,11 +187,11 @@ PF_CONSOLE_CMD( Game, SwitchDialog, "string olddlgName, string newdlgName", "Hid if( mgrKey ) { pfGameGUIMsg *msg = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kHideDialog ); - msg->SetString( params[ 0 ] ); + msg->SetString( (const char *)params[ 0 ] ); plgDispatch::MsgSend( msg ); pfGameGUIMsg *msg2 = new pfGameGUIMsg( mgrKey, pfGameGUIMsg::kShowDialog ); - msg2->SetString( params[ 1 ] ); + msg2->SetString( (const char *)params[ 1 ] ); plgDispatch::MsgSend( msg2 ); } } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp index 482d670d..e9816654 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp @@ -181,11 +181,11 @@ bool pfGameGUIMgr::MsgReceive( plMessage* pMsg ) if( guiMsg != nil ) { if( guiMsg->GetCommand() == pfGameGUIMsg::kLoadDialog ) - LoadDialog( guiMsg->GetString(), nil, guiMsg->GetAge() ); + LoadDialog(guiMsg->GetString().c_str(), nil, guiMsg->GetAge().c_str()); else if( guiMsg->GetCommand() == pfGameGUIMsg::kShowDialog ) - IShowDialog( guiMsg->GetString() ); + IShowDialog(guiMsg->GetString().c_str()); else if( guiMsg->GetCommand() == pfGameGUIMsg::kHideDialog ) - IHideDialog( guiMsg->GetString() ); + IHideDialog(guiMsg->GetString().c_str()); return true; } diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h b/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h index cac66bd8..217456ce 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h +++ b/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h @@ -52,13 +52,15 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "pnMessage/plMessage.h" +#define GAME_GUI_MSG_STRING_SIZE (128) + class pfGameGUIMsg : public plMessage { protected: - uint8_t fCommand; - char fString[ 128 ]; - char *fAge; + uint8_t fCommand; + plString fString; + plString fAge; public: enum @@ -68,9 +70,8 @@ class pfGameGUIMsg : public plMessage kLoadDialog }; - pfGameGUIMsg() : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fAge = nil; } - pfGameGUIMsg( plKey &receiver, uint8_t command ) : plMessage( nil, nil, nil ) { AddReceiver( receiver ); fCommand = command; fAge = nil; } - ~pfGameGUIMsg() { delete [] fAge; } + pfGameGUIMsg() : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); } + pfGameGUIMsg(plKey &receiver, uint8_t command) : plMessage(nil, nil, nil) { AddReceiver(receiver); fCommand = command; } CLASSNAME_REGISTER( pfGameGUIMsg ); GETINTERFACE_ANY( pfGameGUIMsg, plMessage ); @@ -79,25 +80,30 @@ class pfGameGUIMsg : public plMessage { plMessage::IMsgRead( s, mgr ); s->ReadLE( &fCommand ); - s->Read( sizeof( fString ), fString ); - fAge = s->ReadSafeString(); + char buffer[GAME_GUI_MSG_STRING_SIZE]; + s->Read(sizeof(buffer), buffer); + buffer[GAME_GUI_MSG_STRING_SIZE - 1] = 0; + fString = buffer; + fAge = s->ReadSafeString_TEMP(); } virtual void Write(hsStream* s, hsResMgr* mgr) { plMessage::IMsgWrite( s, mgr ); s->WriteLE( fCommand ); - s->Write( sizeof( fString ), fString ); + char buffer[GAME_GUI_MSG_STRING_SIZE]; + strncpy(buffer, fString.c_str(), GAME_GUI_MSG_STRING_SIZE); + s->Write(sizeof(buffer), buffer); s->WriteSafeString( fAge ); } - uint8_t GetCommand( void ) { return fCommand; } + uint8_t GetCommand() const { return fCommand; } - void SetString( const char *str ) { hsStrncpy( fString, str, sizeof( fString ) - 1 ); } - const char *GetString( void ) { return fString; } + void SetString(const plString &str) { fString = str; } + plString GetString() const { return fString; } - void SetAge( const char *str ) { delete [] fAge; if( str == nil ) fAge = nil; else fAge = hsStrcpy( str ); } - const char *GetAge( void ) { return fAge; } + void SetAge(const plString &age) { fAge = age; } + plString GetAge() const { return fAge; } }; #endif // _pfGameGUIMsg_h