bool CEditorAction::Valid(CApplication* pApp) { // if the user removes an object sometimes the conditions / actions can still refer to the removed object // and this causes a headache // uberhack: set global filter removed if (oid == -1 && actID == 7) return false; CObjType* objecttype = pApp->FindObjTypeFromNumber(oid); if(objecttype ) { if(mid < -1) { //check that the effect still exists if(!objecttype->GetEffect(mid * -1)) return false; } if(mid > -1) { if(!objecttype->GetBehaviorByUniqueID(mid)) return false; } // loop each param; for(int p = 0; p < params.size(); p++) { CEditorParam* param = params.at(p); if(param->m_type == 14) //variable { // lookup the variable if(!objecttype->GetPrivateVariable(atoi(param->CreateParamString(pApp)))) return false; } if(param->m_type == 13) //global { if(!pApp->GetGlobalVariable(atoi(param->CreateParamString(pApp)))) return false; } if(param->m_type == EDITORPARAM_OBJECT) { CString stparam = param->CreateParamString(pApp); int o = atoi(stparam); if(o == 0 && stparam != "0") return true; //attribute if(!pApp->FindObjTypeFromNumber( o)) return false; } if(pApp) param->CreateParamString(pApp); //Calling this function updates valid...terrible design but meh if(param->valid == false) return false; } return true; } return false; }
bool CEditorCondition::IsLoop(CApplication* app) { if(m_Text != "") { return (m_Text.Find("<img>3</img>") != -1); } else { if(!app) return false; CObjType* objectType = app->FindObjTypeFromNumber(oid); if(!objectType) return false; ACESEntry2* acesEntry; if(mid == -1) // ace or custom ace acesEntry = objectType->GetACESEntry(CONDITION, cndID); else // movement { //MovementIterator mi = objectType->m_Movements.begin(); //advance(mi, mid); CBehavior* pMov = objectType->GetBehaviorByUniqueID(mid); if (pMov == NULL) throw; acesEntry = GetOINFO(pMov->BehaviorDLLIndex)->GetACEEntry(CONDITION, cndID); } // effects never have triggers if(!acesEntry) return false; if (acesEntry->aceDisplayText.Find("<img>3</img>") != -1) return true; return false; } }
CString CEditorParam::CreateParamString(CApplication* pApp) { CObjTypeMap& typemap = pApp->object_types; CString ret; valid = true; vector<Token>::iterator i = ttokens.begin(); vector<Token>::iterator ttokens_end = ttokens.end(); ttokens_end = ttokens.end(); for ( ; i != ttokens_end; i++) { switch (i->t) { case T_IDENTIFIER: switch (i->tsub) { case TT_OBJECTNAME: { if(CObjType* pType = pApp->FindObjTypeFromNumber(i->oidOwner)) ret += pType->GetName(); else valid = false; break; } case TT_FAMILYNAME: ret += i->str; break; case TT_MOVEMENTNAME: { CObjType* pType; CBehavior* pMov; if(pType = pApp->FindObjTypeFromNumber(i->oidOwner)) ret += pType->GetName(); else { valid = false; break; } ret += "["; if (pMov = pType->GetBehaviorByUniqueID(i->id)) ret += pMov->Text + "]"; else valid = false; break; } case TT_NORMAL: ret += i->str; break; } break; case T_VARIABLENAME: ret += "'"; if(i->oidOwner == -1) { CApplication::GlobalVariable* pGlobal = pApp->GetGlobalVariable(i->id); if(pGlobal) ret += pGlobal->name; else valid = false; } else if(CObjType* pType = pApp->FindObjTypeFromNumber(i->oidOwner)) { PrivateValue* pValue = pType->GetPrivateVariable(i->id); if(pValue) ret += pValue->name; else valid = false; } ret += "'"; break; case T_STRINGLITERAL: ret += "\""; ret += i->str; ret += "\""; break; default: ret += i->str; break; } } return ret; // Davos code //CString ret; //for( int a = 0; a < tokens.size(); a ++) //{ // CEditorParamToken tokenitem = tokens[a]; // if(tokenitem.trans) // { // if(tokenitem.type == 0) // normal // ret += tokenitem.tok; // else if(tokenitem.type == 1) // object name // { // // long number = atol(tokenitem.tok); // CObjType* pType; // // if(typemap.Lookup(number,pType)) // ret += pType->m_name; // //else - we need some sort of tempory name if we cant find one or the user could lose information! // } // // // // // else if(tokenitem.type == 2) // family // { // ret += tokenitem.tok; // /* // long number = atol(tokenitem.tok); // //list<CFamily>::iterator i = pApp->m_Families.begin(); // //advance(i, number); // CFamily* i = pApp->FindFamilyFromNumber(number); // // TODO error checking...what if a family is removed? // ret += i->m_Name; // */ // } // else // ret += tokenitem.tok; // } // // else // { // ret += tokenitem.tok; // } //} //// TODO: Reform objectID tokens into object name //return ret; }
// OnRClick(NMHDR* pNMHDR, LRESULT* pResult) // Handle right clicking an object and inserting an expression. void CParametersDlg::OnDblClick(NMHDR* pNMHDR, LRESULT* pResult) { POSITION listpos = m_Expand.GetFirstSelectedItemPosition(); int item = m_Expand.GetNextSelectedItem(listpos); //if(item == -1) return; CObjType* pObjType = (CObjType*)m_Expand.GetItemData(item); CEventWizardDlg EventWizard; EventWizard.m_aceType = EXPRESSION; EventWizard.layout = layout; EventWizard.application = application; if(pObjType){ EventWizard.m_pSelectedObject = pObjType->ObjectIdentifier; EventWizard.m_iStep = 2; } else EventWizard.m_iStep = 1; EventWizard.SetMap(&application->object_types); if(EventWizard.DoModal() != IDOK) return; // The user can click Back and get a different object's expression, so make sure we're using the current one. pObjType = application->FindObjTypeFromNumber(EventWizard.m_pSelectedObject); int aceIndex = EventWizard.m_aceIndex; int mID = EventWizard.m_childid; CObjType tmp; CObjType *pInfoType = NULL; if(mID == -1) pInfoType = pObjType; CBehavior* pMov = NULL; CEffect* pEffect = NULL; // there are no effect expressions but perhaps in the future... if(mID < -1) { pInfoType = &tmp; pEffect = pObjType->GetEffect(-mID); tmp.CreateFromEffect(pEffect); } if(mID > -1) { pInfoType = &tmp; pMov = pObjType->GetBehaviorByUniqueID(mID); tmp.CreateFromBehavior(pMov); } if(!pInfoType) return; ACESEntry2* pACE = pInfoType->GetACESEntry(EXPRESSION, aceIndex); if (pWndFocusParam == NULL) return; CString Func; if(pObjType->ObjectIdentifier == -1) { Func.Format("%s", pACE->aceDisplayText); if (pACE->auxStr != "") { Func += "("; Func += pACE->auxStr; Func += ")"; } } else { if(pMov) { Func.Format("%s[%s].%s", pObjType->GetName(), pMov->Text, pACE->aceDisplayText); if (pACE->params.size() != 0) { Func += "("; for (int i = 0; i < pACE->params.size(); i++) { Func += pACE->params[i].name; if (i != (pACE->params.size() - 1)) Func += ", "; } Func += ")"; } } else { // Starts with <: interpret as shortcut for other expression eg. <MouseX> if (pACE->aceDisplayText.Left(1) == "<") { Func = pACE->aceDisplayText.Mid(1, pACE->aceDisplayText.GetLength() - 2); } else { Func = pObjType->GetName(); // Allow expressions to specify object name like 'Counter' if (pACE->aceDisplayText != "") { // Allow expressions to specify an ACE name like "(x,y,z)" eg. Array(x,y,z) if (pACE->aceDisplayText.Left(1) != "(") Func += "."; Func += pACE->aceDisplayText; } if (pACE->params.size() != 0) { Func += "("; // okay loop params, add name and , for (int i = 0; i < pACE->params.size(); i++) { Func += pACE->params[i].name; //only add if liek not last 0ne if (i != (pACE->params.size() - 1)) Func += ", "; } Func += ")"; } } } } pWndFocusParam->SendMessage(SCI_REPLACESEL, 0, (LPARAM)(const char*)Func); *pResult = 0; }