/* * actionhandler.cpp * * Copyright (C) 2005 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) * * Credits : * Michael Cummings * * 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 (version 2 * of the License). * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Creation Date: 1/20/2005 * Description : client handler for clickable map object actions * */ #include #include #include "globals.h" #include "net/messages.h" #include "net/msghandler.h" #include "util/psxmlparser.h" #include "util/log.h" #include "actionhandler.h" #include "pscelclient.h" #include "paws/pawsmanager.h" #include "paws/pawscombo.h" #include "gui/pawsinfowindow.h" #include "gui/chatwindow.h" #include "gui/pawsgmgui.h" #include "gui/pawsgmaction.h" ActionHandler::ActionHandler( MsgHandler* mh, iObjectRegistry* obj_reg ) { msghandler = mh; object_reg = obj_reg; if ( msghandler ) { msghandler->Subscribe( this, MSGTYPE_MAPACTION ); } } ActionHandler::~ActionHandler() { if ( msghandler ) { msghandler->Unsubscribe( this, MSGTYPE_MAPACTION ); } } void ActionHandler::HandleMessage(MsgEntry* me) { psMapActionMessage msg( me ); if ( !msg.valid ) return; switch ( msg.command ) { case psMapActionMessage::NOT_HANDLED: { // Must Be GM9 if ( psengine->GetCelClient()->GetMainPlayer()->GetType() < 29 ) return; // Must have GM Window Open pawsGmGUIWindow * gm = (pawsGmGUIWindow *) PawsManager::GetSingleton().FindWidget( "GmGUI" ); if (gm != NULL) { if ( !gm->IsVisible() ) return; if ( gm->GetCurrentTab() != 2 ) return; } // Get Handle to Add/Edit window pawsGMActionWindow *edit = (pawsGMActionWindow *)PawsManager::GetSingleton().FindWidget( "AddEditActionWindow" ); if ( edit ) { edit->LoadAction( msg.actionXML ); (( pawsComboBox *)edit->FindWidget( "cboTriggerType" ))->Select( "" ); } break; } } } void ActionHandler::Query( const char* trigger, const char* sector, const char* mesh, int32_t poly, csVector3 pos ) { csString polyStr; polyStr.Format( "%d", poly ); csString posStr; posStr.Format( "%f%f%f", pos.x, pos.y, pos.z ); csString xml; xml.Append( "" ); xml.Append( "" ); xml.Append( sector ); xml.Append( "" ); xml.Append( "" ); xml.Append( mesh ); xml.Append( "" ); xml.Append( "" ); xml.Append( polyStr ); xml.Append( "" ); xml.Append( "" ); xml.Append( posStr ); xml.Append( "" ); xml.Append( "" ); xml.Append( trigger ); xml.Append( "" ); xml.Append( "" ); // Create Message psMapActionMessage queryMsg( 0, psMapActionMessage::QUERY, xml.GetData() ); // Send Message queryMsg.SendMessage(); } void ActionHandler::Save( const char* id, const char* masterid, const char* name, const char* sector, const char* mesh, const char* poly, const char* posx, const char* posy, const char* posz, const char* radius, const char* triggertype, const char* responsetype, const char* response ) { csString xml; csString escpxml_response = EscpXML(response); xml.Append( "" ); xml.Append( "" ); xml.Append( id ); xml.Append( "" ); xml.Append( "" ); xml.Append( masterid ); xml.Append( "" ); xml.Append( "" ); xml.Append( name ); xml.Append( "" ); xml.Append( "" ); xml.Append( sector ); xml.Append( "" ); xml.Append( "" ); xml.Append( mesh ); xml.Append( "" ); xml.Append( "" ); xml.Append( poly ); xml.Append( "" ); xml.Append( "" ); xml.Append( "" ); xml.Append( posx ); xml.Append( "" ); xml.Append( "" ); xml.Append( posy ); xml.Append( "" ); xml.Append( "" ); xml.Append( posz ); xml.Append( "" ); xml.Append( "" ); xml.Append( "" ); xml.Append( radius ); xml.Append( "" ); xml.Append( "" ); xml.Append( triggertype ); xml.Append( "" ); xml.Append( "" ); xml.Append( responsetype ); xml.Append( "" ); xml.Append( "" ); xml.Append( escpxml_response ); xml.Append( "" ); xml.Append( "" ); // Create Message psMapActionMessage queryMsg( 0, psMapActionMessage::SAVE, xml.GetData() ); // Send Message queryMsg.SendMessage(); } void ActionHandler::DeleteAction( const char* id ) { csString xml; xml.Append( "" ); xml.Append( "" ); xml.Append( id ); xml.Append( "" ); xml.Append( "" ); // Create Message psMapActionMessage queryMsg( 0, psMapActionMessage::DELETE_ACTION, xml.GetData() ); queryMsg.SendMessage(); } void ActionHandler::ReloadCache( ) { psMapActionMessage queryMsg( 0, psMapActionMessage::RELOAD_CACHE, "" ); queryMsg.SendMessage(); }