Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9671
Modified Files:
Trade.cpp contextmenu.cpp contextmenu.h factory.h npc.cpp
npc.h
Log Message:
Reimplemented context menus
Index: Trade.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/Trade.cpp,v
retrieving revision 1.91
retrieving revision 1.92
diff -C2 -d -r1.91 -r1.92
*** Trade.cpp 8 Jan 2004 08:33:38 -0000 1.91
--- Trade.cpp 28 Jan 2004 02:18:13 -0000 1.92
***************
*** 188,192 ****
if ( pChar->CountGold() < totalValue )
{
! pVendor->talk( 500192, 0xFFFF, pChar->socket() ); //Begging thy pardon, but thou casnt afford that.
return;
}
--- 188,192 ----
if ( pChar->CountGold() < totalValue )
{
! pVendor->talk( 500192, 0, 0xFFFF, pChar->socket() ); //Begging thy pardon, but thou casnt afford that.
return;
}
***************
*** 196,200 ****
if ( pChar->CountBankGold() < totalValue )
{
! pVendor->talk( 500191, 0xFFFF, pChar->socket() ); //Begging thy pardon, but thy bank account lacks these funds.
return;
}
--- 196,200 ----
if ( pChar->CountBankGold() < totalValue )
{
! pVendor->talk( 500191, 0, 0xFFFF, pChar->socket() ); //Begging thy pardon, but thy bank account lacks these funds.
return;
}
***************
*** 205,209 ****
{
socket->send( &clearBuy );
! pVendor->talk( 500190, 0xFFFF, pChar->socket() ); // Thou hast bought nothing!
return;
}
--- 205,209 ----
{
socket->send( &clearBuy );
! pVendor->talk( 500190, 0, 0xFFFF, pChar->socket() ); // Thou hast bought nothing!
return;
}
Index: contextmenu.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/contextmenu.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** contextmenu.cpp 23 Sep 2003 12:40:18 -0000 1.16
--- contextmenu.cpp 28 Jan 2004 02:18:13 -0000 1.17
***************
*** 4,8 ****
// UO Server Emulation Program
//
! // Copyright 2001-2003 by holders identified in authors.txt
// 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
--- 4,8 ----
// UO Server Emulation Program
//
! // Copyright 2001-2004 by holders identified in authors.txt
// 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
***************
*** 38,96 ****
#include "player.h"
! cConMenu::cConMenu( const cElement *Tag )
! {
! applyDefinition( Tag );
! recreateEvents();
! }
!
! void cConSingleOption::setOption( const cElement *Tag )
{
! this->tag_ = Tag->getAttribute( "tag" ).toUShort();
! this->intlocid_ = Tag->getAttribute( "intlocid" ).toUShort();
! this->msgid_ = Tag->getAttribute( "msgid" ).toUShort();
}
! void cConMenuOptions::addOption( const cElement *Tag )
{
! cConSingleOption SingleOption;
! SingleOption.setOption( Tag );
! this->options_.push_back( SingleOption );
}
! void cConMenuOptions::processNode( const cElement *Tag )
{
! QString TagName = Tag->name();
! if( TagName == "option" )
! addOption ( Tag );
}
! void cConMenu::processNode( const cElement *Tag )
{
! QString TagName = Tag->name();
! cConMenuOptions tOptions;
!
! tOptions.applyDefinition( Tag );
!
! if( TagName == "access" && Tag->hasAttribute( "acl" ) )
{
! tOptions.processNode( Tag );
! options_.insert( Tag->getAttribute( "acl" ), tOptions );
! tOptions.deleteAll();
}
! else if( TagName == "events" )
{
! eventList_ = QStringList::split( ",", Tag->getValue() );
! recreateEvents();
! }
}
! void cConMenu::recreateEvents( void )
{
! scriptChain.clear();
// Walk the eventList and recreate
! QStringList::const_iterator myIter( eventList_.begin() );
! for( ; myIter != eventList_.end(); ++myIter )
{
cPythonScript *myScript = ScriptManager::instance()->find( (*myIter).latin1() );
--- 38,156 ----
#include "player.h"
! /*!
! Builds a context menu out of the definition scripts
! */
! void cContextMenu::processNode( const cElement *Tag )
{
! QString TagName = Tag->name();
!
! if( TagName == "events" )
! {
! scripts_ = Tag->getValue();
! }
! else if ( TagName == "option" )
! {
! bool ok;
! ushort msgid = Tag->getAttribute("msgid").toUShort();
! ushort tag = Tag->getAttribute("tag").toUShort();
! ushort color = Tag->getAttribute("color").toUShort(&ok);
! if ( !ok )
! color = 0x7FE0; // Default
! bool checkenabled = Tag->getAttribute("checkenabled", "false").lower() == "true";
! bool checkvisible = Tag->getAttribute("checkvisible", "false").lower() == "true";
! entries_.push_back( new cContextMenuEntry( msgid, tag, color, checkvisible, checkenabled ) );
! }
}
! /*!
! Deletes all menu entries, should only be called from the Context Menu manager
! */
! void cContextMenu::disposeEntries()
{
! const_iterator it ( entries_.begin() );
! for ( ; it != entries_.end(); ++it )
! delete *it;
}
! /*!
! Handles response from client invoking all the scripts binded to this menu's
! given \a entry.
! */
! void cContextMenu::onContextEntry( cPlayer* from, cUObject* target, ushort entry )
{
! if ( scriptChain_.isEmpty() || entries_.size() <= entry )
! return;
! PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, from, PyGetObjectObject, target, entries_[entry]->scriptTag() );
! for ( cPythonScript* script = scriptChain_.first(); script; script = scriptChain_.next() )
! {
! script->callEventHandler( EVENT_CONTEXTENTRY, args );
! }
}
! /*!
! Calls script handler to check whether the given entry of the menu
! should be sent or not to the client
! */
! bool cContextMenu::onCheckVisible( cPlayer* from, cUObject* target, ushort entry )
{
! if ( scriptChain_.isEmpty() || entries_.size() <= entry )
! return true;
!
! bool returnValue = true;
! PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, from, PyGetObjectObject, target, entries_[entry]->scriptTag() );
! for ( cPythonScript* script = scriptChain_.first(); script; script = scriptChain_.next() )
{
! PyObject* obj = script->callEvent( "onContextMenuCheckVisible", args );
! if ( obj )
! {
! if ( !PyObject_IsTrue( obj ) )
! returnValue = false;
! Py_XDECREF( obj );
! }
!
! if ( !returnValue )
! return false;
}
! return true;
! }
!
! /*!
! Calls script handler to check whether the given entry of the menu
! should be flagged as enabled or not to the client
! */
! bool cContextMenu::onCheckEnabled( cPlayer* from, cUObject* target, ushort entry )
! {
! if ( scriptChain_.isEmpty() || entries_.size() <= entry )
! return true;
!
! bool returnValue = true;
! PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, from, PyGetObjectObject, target, entries_[entry]->scriptTag() );
! for ( cPythonScript* script = scriptChain_.first(); script; script = scriptChain_.next() )
{
! PyObject* obj = script->callEvent( "onContextMenuCheckEnabled", args );
! if ( obj )
! {
! if ( !PyObject_IsTrue( obj ) )
! returnValue = false;
! Py_XDECREF( obj );
! }
+ if ( !returnValue )
+ return false;
+ }
+ return true;
}
! /*!
! Reloads associated Python scripts
! */
! void cContextMenu::recreateEvents()
{
! scriptChain_.clear();
// Walk the eventList and recreate
! QStringList eventList = QStringList::split(",", scripts_);
! QStringList::const_iterator myIter( eventList.begin() );
! for( ; myIter != eventList.end(); ++myIter )
{
cPythonScript *myScript = ScriptManager::instance()->find( (*myIter).latin1() );
***************
*** 100,139 ****
continue;
! scriptChain.push_back( myScript );
! }
! }
!
! bool cConMenu::onContextEntry( cPlayer *Caller, cUObject *Target, Q_UINT16 Tag ) const
! {
! // If we dont have any events assigned just skip processing
! if( scriptChain.empty() )
! return false;
!
! PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, Caller, PyGetObjectObject, Target, Tag );
!
! // If we got ANY events process them in order
! for( UI08 i = 0; i < scriptChain.size(); i++ )
! {
! if ( scriptChain[ i ]->callEventHandler( EVENT_CONTEXTENTRY, args ) )
! return true;
}
-
- return false;
}
! const cConMenuOptions* cConMenu::getOptionsByAcl( const QString& acl ) const
! {
! QMap< QString, cConMenuOptions >::const_iterator it = options_.find( acl );
! if( it != options_.end() )
! return &it.data();
!
! return 0;
! }
!
! void cAllConMenus::load( void )
{
QStringList sections = DefManager->getSections( WPDT_CONTEXTMENU );
QStringList::const_iterator it = sections.begin();
! while( it != sections.end() )
{
const cElement* section = DefManager->getDefinition( WPDT_CONTEXTMENU, (*it) );
--- 160,175 ----
continue;
! scriptChain_.append( myScript );
}
}
! /*!
! Loads and pre-builds all context menus
! */
! void cAllContextMenus::load( void )
{
QStringList sections = DefManager->getSections( WPDT_CONTEXTMENU );
QStringList::const_iterator it = sections.begin();
! for ( ; it != sections.end(); ++it )
{
const cElement* section = DefManager->getDefinition( WPDT_CONTEXTMENU, (*it) );
***************
*** 141,178 ****
if( section )
{
! menus_.insert( (*it), cConMenu( section ) );
}
- ++it;
}
}
! bool cAllConMenus::menuExists( const QString& bindmenu ) const
{
! QMap< QString, cConMenu >::const_iterator it( menus_.find( bindmenu ) );
return it != menus_.end();
}
! const cConMenuOptions* cAllConMenus::getMenuOptions( const QString& bindmenu, const QString& acl ) const
{
! QMap< QString, cConMenu >::const_iterator it = menus_.find( bindmenu );
! if ( it != menus_.end() )
! return it.data().getOptionsByAcl( acl );
return 0;
}
! const cConMenu* cAllConMenus::getMenu( const QString& bindmenu, const QString& acl ) const
{
! Q_UNUSED(acl);
! QMap< QString, cConMenu >::const_iterator it( menus_.find( bindmenu ) );
! if ( it != menus_.end() )
! return &it.data();
!
! return 0;
}
! void cAllConMenus::reload( void )
{
! menus_.clear();
load();
}
--- 177,224 ----
if( section )
{
! cContextMenu* menu = new cContextMenu;
! menu->applyDefinition( section );
! menu->recreateEvents();
! menus_.insert( (*it), menu );
}
}
}
! /*!
! Checks if a given menu exists or not, indexed by name
! */
! bool cAllContextMenus::menuExists( const QString& bindmenu ) const
{
! const_iterator it( menus_.find( bindmenu ) );
return it != menus_.end();
}
! /*!
! Retrieves the menu
! */
! cContextMenu* cAllContextMenus::getMenu( const QString& bindmenu ) const
{
! const_iterator it( menus_.find( bindmenu ) );
! if ( it != menus_.end() )
! {
! return it.data(); // returns a copy of the menu
! }
return 0;
}
! void cAllContextMenus::unload()
{
! const_iterator it( menus_.begin() );
! for ( ; it != menus_.end(); ++it )
! {
! it.data()->disposeEntries();
! delete it.data();
! }
}
! void cAllContextMenus::reload( void )
{
! unload();
load();
}
Index: contextmenu.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/contextmenu.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** contextmenu.h 20 Jul 2003 00:04:51 -0000 1.13
--- contextmenu.h 28 Jan 2004 02:18:13 -0000 1.14
***************
*** 4,9 ****
// UO Server Emulation Program
//
! // Copyright 1997, 98 by Marcus Rating (Cironian)
! // Copyright 2001-2003 by holders identified in authors.txt
// 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
--- 4,8 ----
// UO Server Emulation Program
//
! // Copyright 2001-2004 by holders identified in authors.txt
// 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
***************
*** 47,113 ****
class cElement;
! class cConSingleOption
{
! public:
!
! void setOption( const cElement *Tag );
! Q_UINT16 getTag( void ) { return tag_; }
! Q_UINT16 getIntlocID(void) { return intlocid_; }
! Q_UINT16 getMsgID(void) { return msgid_; }
!
! private:
! Q_UINT16 tag_;
! Q_UINT16 intlocid_;
! Q_UINT16 msgid_;
! };
- class cConMenuOptions : public cDefinable
- {
public:
- typedef QValueVector< cConSingleOption > vSingleOption;
- void processNode( const cElement *Tag );
- vSingleOption getOptions( void ) const { return options_; }
- void addOption( const cElement *Tag );
- void deleteAll( void ) { options_.clear(); }
! private:
! vSingleOption options_;
};
! class cConMenu : public cDefinable
{
public:
! cConMenu() {};
! cConMenu( const cElement *Tag );
! void processNode( const cElement *Tag );
! const cConMenuOptions* getOptionsByAcl( const QString& acl ) const;
! void recreateEvents( void );
!
! bool onContextEntry( cPlayer *Caller, cUObject *Target, Q_UINT16 Tag ) const;
private:
! QMap< QString, cConMenuOptions > options_;
! QStringList eventList_;
! std::vector<cPythonScript*> scriptChain;
};
! class cAllConMenus
{
public:
- ~cAllConMenus() { menus_.clear(); }
! bool menuExists( const QString& bindmenu ) const;
! void load( void );
! void reload( void );
! const cConMenuOptions* getMenuOptions( const QString& bindmenu, const QString& acl ) const;
! const cConMenu* getMenu( const QString& bindmenu, const QString& acl ) const;
!
private:
! QMap< QString, cConMenu > menus_;
};
! typedef SingletonHolder<cAllConMenus> ContextMenus;
#endif // __CONTEXTMENU_H__
--- 46,122 ----
class cElement;
! class cContextMenuEntry
{
! ushort cliloc_;
! ushort flags_;
! ushort color_;
! ushort scriptTag_;
! bool checkvisible_;
! bool checkenabled_;
public:
! cContextMenuEntry( ushort cliloc, ushort scriptTag, ushort color = 0, bool checkvisible = false, bool checkenabled = false ) :
! cliloc_( cliloc ), scriptTag_(scriptTag), flags_ ( 0 ), color_(0), checkvisible_(checkvisible_), checkenabled_(checkenabled)
! {
! flags_ |= ( color_ & 0xFFFF ) ? 32 : 0;
! }
+ bool isEnabled() const { return !(flags_ & 0x0001); }
+ bool setEnabled( bool enable )
+ {
+ flags_ = enable ? flags_ & ~0x0001 : flags_ | 0x0001;
+ }
+
+ ushort color() const { return color_; }
+ ushort flags() const { return flags_; }
+ ushort scriptTag() const { return scriptTag_; }
+ ushort cliloc() const { return cliloc_; }
+ bool checkVisible() const { return checkvisible_; }
+ bool checkEnabled() const { return checkenabled_; }
};
! class cContextMenu : public cDefinable
{
public:
! typedef QValueVector< cContextMenuEntry* > Entries;
! typedef Entries::const_iterator const_iterator;
! typedef Entries::iterator iterator;
!
! const_iterator begin() const { return entries_.begin(); }
! const_iterator end() const { return entries_.end(); }
!
! uint count() const { return entries_.count(); }
! void processNode( const cElement *Tag );
! void onContextEntry( cPlayer* from, cUObject* target, ushort entry );
! bool onCheckVisible( cPlayer* from, cUObject* target, ushort entry );
! bool onCheckEnabled( cPlayer* from, cUObject* target, ushort entry );
! void recreateEvents();
! void disposeEntries();
private:
! Entries entries_;
! QPtrList<cPythonScript> scriptChain_;
! QString scripts_;
};
! class cAllContextMenus
{
public:
! bool menuExists( const QString& bindmenu ) const;
! void load();
! void unload();
! void reload();
!
! cContextMenu* getMenu( const QString& ) const;
private:
! typedef QMap< QString, cContextMenu* > Menus;
! typedef Menus::const_iterator const_iterator;
! Menus menus_;
};
! typedef SingletonHolder<cAllContextMenus> ContextMenus;
#endif // __CONTEXTMENU_H__
Index: factory.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/factory.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** factory.h 12 Jan 2003 18:11:31 -0000 1.2
--- factory.h 28 Jan 2004 02:18:13 -0000 1.3
***************
*** 4,9 ****
// UO Server Emulation Program
//
! // Copyright 1997, 98 by Marcus Rating (Cironian)
! // Copyright 2001-2003 by holders identified in authors.txt
// 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
--- 4,8 ----
// UO Server Emulation Program
//
! // Copyright 2001-2004 by holders identified in authors.txt
// 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
Index: npc.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** npc.cpp 22 Jan 2004 04:48:12 -0000 1.54
--- npc.cpp 28 Jan 2004 02:18:13 -0000 1.55
***************
*** 353,361 ****
}
! void cNPC::talk( const UINT32 MsgID, UI16 color /*= 0xFFFF*/, cUOSocket* socket /*= 0*/ )
{
if ( socket )
{
! socket->clilocMessage( MsgID, 0, color, 3, this );
}
else
--- 353,361 ----
}
! void cNPC::talk( const UINT32 MsgID, const QString& params /*= 0*/, UI16 color /*= 0xFFFF*/, cUOSocket* socket /*= 0*/ )
{
if ( socket )
{
! socket->clilocMessage( MsgID, params, color, 3, this );
}
else
Index: npc.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** npc.h 8 Jan 2004 08:33:38 -0000 1.28
--- npc.h 28 Jan 2004 02:18:13 -0000 1.29
***************
*** 93,97 ****
virtual void resend( bool clean = true, bool excludeself = false );
virtual void talk( const QString &message, UI16 color = 0xFFFF, UINT8 type = 0, bool autospam = false, cUOSocket* socket = NULL );
! void talk( const UINT32 MsgID, UI16 color = 0xFFFF, cUOSocket* socket = 0 );
virtual UINT8 notority( P_CHAR pChar = NULL );
virtual void kill();
--- 93,97 ----
virtual void resend( bool clean = true, bool excludeself = false );
virtual void talk( const QString &message, UI16 color = 0xFFFF, UINT8 type = 0, bool autospam = false, cUOSocket* socket = NULL );
! void talk( const UINT32 MsgID, const QString& params = 0, UI16 color = 0xFFFF, cUOSocket* socket = 0 );
virtual UINT8 notority( P_CHAR pChar = NULL );
virtual void kill();
|