![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cGuiACAddEffect.cppGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 #include "gui/cGuiACAddEffect.h" 00026 00027 #include "gui/cGuiSEFactory.h" 00028 00029 /******************************************************************************/ 00030 namespace n2l 00031 { 00032 /**************************************************************************/ 00033 cGuiACAddEffect::cGuiACAddEffect() 00034 { 00035 init(); 00036 } 00037 00038 /**************************************************************************/ 00039 cGuiACAddEffect::cGuiACAddEffect( 00040 const cAutoPtr<const cGuiSEInt> &ioEffect, 00041 const tString &iElementName ) 00042 { 00043 if (!ioEffect.isSet()) throw cBadDataUseException( 00044 "cGuiACAddEffect::cGuiACAddEffect", "Null Effect Given" ); 00045 00046 init(); 00047 00048 mEffect = ioEffect; 00049 mElementName = iElementName; 00050 } 00051 00052 /**************************************************************************/ 00053 cGuiACAddEffect::cGuiACAddEffect( const cDynVar &iDef ) 00054 { 00055 init(); 00056 load( iDef ); 00057 } 00058 00059 /**************************************************************************/ 00060 cGuiACAddEffect::~cGuiACAddEffect() 00061 { 00062 } 00063 00064 /**************************************************************************/ 00065 void cGuiACAddEffect::load( const cDynVar &iDef ) 00066 { 00067 cGuiACInt::load( iDef ); 00068 if (!iDef.keyExists("effect")) 00069 throw cBadDataUseException( "cGuiACAddEffect::load", 00070 "Null Effect Given" ); 00071 00072 mEffect = cGuiSEFactory::current().load( iDef["effect"] ); 00073 mElementName = iDef.keyValueOr("elementName",mElementName); 00074 mElementName = iDef.keyValueOr("element",mElementName); 00075 } 00076 00077 /**************************************************************************/ 00078 void cGuiACAddEffect::execute( cGuiElement *const ioElement, 00079 const tGuiActionType iType, const cDynVar &iData ) 00080 { 00081 cGuiElement *target; 00082 if (!mElementName.empty()) { 00083 cGuiElement *tmp = ioElement; 00084 while (tmp->canvas()) tmp = tmp->canvas(); 00085 cGuiCanvas *canvas = dynamic_cast<cGuiCanvas*>(tmp); 00086 if (!canvas) 00087 throw cBadDataUseException("cGuiACAddEffect::execute", 00088 "Wanted to add effect to \"" + mElementName + 00089 "\" but our element has access to no canvas to search" ); 00090 00091 target = (canvas->mustGet(mElementName)).dumbPtr(); 00092 } else 00093 target = ioElement; 00094 00095 // Lets do it. 00096 target->addEffect( mEffect->clone() ); 00097 } 00098 00099 /**************************************************************************/ 00100 const cAutoPtr<cGuiACInt> cGuiACAddEffect::clone() const 00101 { 00102 cAutoPtr<cGuiACAddEffect> newElement( new cGuiACAddEffect ); 00103 cloneInto( newElement ); 00104 return newElement; 00105 } 00106 00107 /**************************************************************************/ 00108 void cGuiACAddEffect::cloneInto( 00109 const cAutoPtr<cGuiACAddEffect> &ioElement ) const 00110 { 00111 cGuiACInt::cloneInto( ioElement ); 00112 ioElement->mEffect = mEffect->clone(); 00113 ioElement->mElementName = mElementName; 00114 } 00115 00116 /**************************************************************************/ 00117 void cGuiACAddEffect::init() 00118 { 00119 } 00120 00121 } |