![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cGuiACIfProp.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/cGuiACIfProp.h" 00026 00027 #include "gui/cGuiSEFactory.h" 00028 00029 /******************************************************************************/ 00030 namespace n2l 00031 { 00032 /**************************************************************************/ 00033 cGuiACIfProp::cGuiACIfProp() 00034 { 00035 init(); 00036 } 00037 00038 /**************************************************************************/ 00039 cGuiACIfProp::cGuiACIfProp( const cDynVar &iDef ) 00040 { 00041 init(); 00042 load( iDef ); 00043 } 00044 00045 /**************************************************************************/ 00046 cGuiACIfProp::~cGuiACIfProp() 00047 { 00048 } 00049 00050 /**************************************************************************/ 00051 void cGuiACIfProp::load( const cDynVar &iDef ) 00052 { 00053 cGuiACInt::load( iDef ); 00054 00055 { 00056 const tString Op = strToLower(iDef["op"]); 00057 if (Op == "<") mOp = Op_LessThan; 00058 else if (Op == ">") mOp = Op_GreaterThan; 00059 else if (Op == "==") mOp = Op_Equals; 00060 else if (Op == "!=") mOp = Op_Not; 00061 else mOp = Op_Equals; 00062 } 00063 00064 mElement = iDef.keyValueOr( "element", mElement ); 00065 00066 mKey = iDef.keyValueOr( "prop", mKey ); 00067 mInnerKey = iDef.keyValueOr( "innerProp", mInnerKey ); 00068 00069 mValue = iDef.keyValueOr( "value", mValue ); 00070 00071 mAction = cGuiACFactory::current().load( iDef["action"] ); 00072 00073 if (iDef.keyExists("elseAction")) 00074 mElseAction = cGuiACFactory::current().load( iDef["elseAction"] ); 00075 } 00076 00077 /**************************************************************************/ 00078 const tBool cGuiACIfProp::preserveAction() const 00079 { 00080 return mAction.isSet() || mElseAction.isSet(); 00081 } 00082 00083 /**************************************************************************/ 00084 void cGuiACIfProp::execute( cGuiElement *const ioElement, 00085 const tGuiActionType iType, const cDynVar &iData ) 00086 { 00087 const cGuiElement *target; 00088 if (!mElement.empty()) { 00089 cGuiElement *tmpLast = ioElement; 00090 cGuiElement *tmp = ioElement; 00091 while (tmp->canvas()) { 00092 tmp = tmp->canvas(); 00093 if (tmp==tmpLast) 00094 throw cBadDataUseException( "cGuiACIfProp::execute", 00095 "Canvas loop." ); 00096 tmpLast = tmp; 00097 } 00098 cGuiCanvas *canvas = dynamic_cast<cGuiCanvas*>(tmp); 00099 if (!canvas) 00100 throw cBadDataUseException("cGuiACIfProp::execute", 00101 "Wanted to check a property on \"" + mElement + 00102 "\" but our element has access to no canvas to search" ); 00103 00104 try { 00105 target = (canvas->mustGet(mElement)).dumbPtr(); 00106 } 00107 catch ( const cException &iE ) { 00108 throw cBadDataUseException( "cGuiACIfProp::execute", 00109 "Wanted to check a property on \"" + mElement + 00110 "\" but no such element existed to check. Got " 00111 "exception while searching: " + tString(iE) ); 00112 } 00113 } else 00114 target = ioElement; 00115 00116 tBool ok = true; 00117 const cDynVar Val = target->prop( mKey, mInnerKey ); 00118 00119 switch (mOp) { 00120 case Op_Equals: 00121 if (Val != mValue) ok = false; 00122 break; 00123 00124 case Op_GreaterThan: 00125 if (Val <= mValue) ok = false; 00126 break; 00127 00128 case Op_LessThan: 00129 if (Val >= mValue) ok = false; 00130 break; 00131 00132 case Op_Not: 00133 if (Val == mValue) ok = false; 00134 break; 00135 00136 default: 00137 throw cOutOfBoundsException( "cGuiACIfProp::execute", 00138 "No such operation exists." ); 00139 } 00140 00141 if (ok) { 00142 if (!mAction.isSet()) return; 00143 mAction->execute( ioElement, iType, iData ); 00144 if (!mAction->preserveAction()) mAction = 0; 00145 } else { 00146 if (!mElseAction.isSet()) return; 00147 mElseAction->execute( ioElement, iType, iData ); 00148 if (!mElseAction->preserveAction()) mElseAction = 0; 00149 } 00150 } 00151 00152 /**************************************************************************/ 00153 const cAutoPtr<cGuiACInt> cGuiACIfProp::clone() const 00154 { 00155 cAutoPtr<cGuiACIfProp> newElement( new cGuiACIfProp ); 00156 cloneInto( newElement ); 00157 return newElement; 00158 } 00159 00160 /**************************************************************************/ 00161 void cGuiACIfProp::cloneInto( const cAutoPtr<cGuiACIfProp> &ioElement ) const 00162 { 00163 cGuiACInt::cloneInto( ioElement ); 00164 ioElement->mElement = mElement; 00165 ioElement->mOp = mOp; 00166 ioElement->mKey = mKey; 00167 ioElement->mInnerKey = mInnerKey; 00168 ioElement->mValue = mValue; 00169 00170 if (mAction.isSet()) 00171 ioElement->mAction = mAction->clone(); 00172 else 00173 ioElement->mAction = 0; 00174 00175 if (mElseAction.isSet()) 00176 ioElement->mElseAction = mElseAction->clone(); 00177 else 00178 ioElement->mElseAction = 0; 00179 } 00180 00181 /**************************************************************************/ 00182 void cGuiACIfProp::init() 00183 { 00184 mOp = Op_Equals; 00185 mKey.clear(); 00186 mInnerKey.clear(); 00187 mValue = true; 00188 lockPreserveAction( true ); 00189 } 00190 00191 } |