void Layout::UpdateBehaviorsSharedData(gd::Project & project) { std::vector < gd::String > allBehaviorsTypes; std::vector < gd::String > allBehaviorsNames; //Search in objects for the type and the name of every behaviors. for (std::size_t i = 0;i<initialObjects.size();++i) { std::vector < gd::String > objectBehaviors = initialObjects[i]->GetAllBehaviorNames(); for (unsigned int j = 0;j<objectBehaviors.size();++j) { gd::Behavior & behavior = initialObjects[i]->GetBehavior(objectBehaviors[j]); allBehaviorsTypes.push_back(behavior.GetTypeName()); allBehaviorsNames.push_back(behavior.GetName()); } } for (std::size_t i = 0;i<project.GetObjectsCount();++i) { std::vector < gd::String > objectBehaviors = project.GetObject(i).GetAllBehaviorNames(); for (std::size_t j = 0;j<objectBehaviors.size();++j) { gd::Behavior & behavior = project.GetObject(i).GetBehavior(objectBehaviors[j]); allBehaviorsTypes.push_back(behavior.GetTypeName()); allBehaviorsNames.push_back(behavior.GetName()); } } //Create non existing shared data for (std::size_t i = 0;i<allBehaviorsTypes.size() && i < allBehaviorsNames.size();++i) { if ( behaviorsInitialSharedDatas.find(allBehaviorsNames[i]) == behaviorsInitialSharedDatas.end() ) { std::shared_ptr<gd::BehaviorsSharedData> behaviorsSharedDatas = project.CreateBehaviorSharedDatas(allBehaviorsTypes[i]); if ( behaviorsSharedDatas ) { behaviorsSharedDatas->SetName(allBehaviorsNames[i]); behaviorsInitialSharedDatas[behaviorsSharedDatas->GetName()] = behaviorsSharedDatas; } } } //Remove useless shared data: //First construct the list of existing shared data. std::vector < gd::String > allSharedData; for (std::map < gd::String, std::shared_ptr<gd::BehaviorsSharedData> >::const_iterator it = behaviorsInitialSharedDatas.begin(); it != behaviorsInitialSharedDatas.end();++it) { allSharedData.push_back(it->first); } //Then delete shared data not linked to a behavior for (std::size_t i = 0;i<allSharedData.size();++i) { if ( std::find(allBehaviorsNames.begin(), allBehaviorsNames.end(), allSharedData[i]) == allBehaviorsNames.end() ) behaviorsInitialSharedDatas.erase(allSharedData[i]); } }
gd::String GD_CORE_API GetTypeOfBehavior(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups) { for (std::size_t i = 0;i<layout.GetObjectsCount();++i) { vector < gd::String > behaviors = layout.GetObject(i).GetAllBehaviorNames(); for (std::size_t j = 0;j<behaviors.size();++j) { if ( layout.GetObject(i).GetBehavior(behaviors[j]).GetName() == name ) return layout.GetObject(i).GetBehavior(behaviors[j]).GetTypeName(); } } for (std::size_t i = 0;i<project.GetObjectsCount();++i) { vector < gd::String > behaviors = project.GetObject(i).GetAllBehaviorNames(); for (std::size_t j = 0;j<behaviors.size();++j) { if ( project.GetObject(i).GetBehavior(behaviors[j]).GetName() == name ) return project.GetObject(i).GetBehavior(behaviors[j]).GetTypeName(); } } return ""; }
void ParameterEditorLauncher::LaunchEditor(wxWindow * parent, gd::Project & project, gd::Layout & layout, const gd::ParameterMetadata & metadata, std::vector<wxTextCtrl * > & paramEdits, std::size_t paramIndex) { if (paramIndex >= paramEdits.size()) return; wxTextCtrl * editCtrl = paramEdits.at(paramIndex); if (!editCtrl) return; if ( gd::ParameterMetadata::IsObject(metadata.GetType()) ) { gd::ChooseObjectDialog dialog(parent, project, layout, true, metadata.GetExtraInfo()); if ( dialog.ShowModal() == 1 ) { editCtrl->ChangeValue(dialog.GetChosenObject()); } return; } else if ( metadata.GetType() == "behavior" ) { gd::String object = paramEdits.empty() ? "" : paramEdits[0]->GetValue(); gd::ChooseBehaviorDialog dialog(parent, project, layout, object, metadata.GetExtraInfo()); if (dialog.DeduceBehavior() || dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.GetChosenBehavior()); return; } else if ( metadata.GetType() == "expression" ) { gd::EditExpressionDialog dialog(parent, editCtrl->GetValue(), project, layout); if ( dialog.ShowModal() == 1 ) { editCtrl->ChangeValue(dialog.GetExpression()); } return; } else if ( metadata.GetType() == "mouse" ) { ChoixBouton dialog(parent, editCtrl->GetValue()); if ( dialog.ShowModal() == 1 ) { editCtrl->ChangeValue(dialog.bouton); } return; } else if ( metadata.GetType() == "key" ) { ChoixClavier dialog(parent, editCtrl->GetValue()); if ( dialog.ShowModal() == 1 ) { editCtrl->ChangeValue(dialog.selectedKey); } return; } else if ( metadata.GetType() == "string" ) { gd::EditStrExpressionDialog dialog(parent, editCtrl->GetValue(), project, layout); if ( dialog.ShowModal() == 1 ) { editCtrl->ChangeValue(dialog.GetExpression()); } return; } else if ( metadata.GetType() == "relationalOperator" ) { SigneTest dialog(parent); int chosenOperator = dialog.ShowModal(); if ( chosenOperator == 1 ) editCtrl->ChangeValue("="); if ( chosenOperator == 2 ) editCtrl->ChangeValue(">"); if ( chosenOperator == 3 ) editCtrl->ChangeValue("<"); if ( chosenOperator == 4 ) editCtrl->ChangeValue(">="); if ( chosenOperator == 5 ) editCtrl->ChangeValue("<="); if ( chosenOperator == 6 ) editCtrl->ChangeValue("!="); return; } else if ( metadata.GetType() == "color" ) { wxColour color = wxGetColourFromUser(parent, wxColour(0,0,0)); if ( color.IsOk() ) { wxString r; r << static_cast<int>(color.Red()); wxString v; v << static_cast<int>(color.Green()); wxString b; b << static_cast<int>(color.Blue()); wxString colorStr = "\""+r+";"+v+";"+b+"\""; editCtrl->ChangeValue(colorStr); } return; } else if ( metadata.GetType() == "police" ) { wxString projectDirectory = wxFileName::FileName(project.GetProjectFile()).GetPath(); wxFileDialog dialog(parent, _("Choose a font ( ttf/ttc files )"), projectDirectory, "", "Polices (*.ttf, *.ttc)|*.ttf;*.ttc"); dialog.ShowModal(); if ( dialog.GetPath() != "" ) //Note that path is relative to the project file: { wxFileName filename(dialog.GetPath()); filename.MakeRelativeTo(projectDirectory); editCtrl->ChangeValue(filename.GetFullPath()); } return; } else if ( metadata.GetType() == "musicfile" ) { wxString projectDirectory = wxFileName::FileName(project.GetProjectFile()).GetPath(); wxFileDialog dialog(parent, _("Choose a music ( ogg files )"), projectDirectory, "", _("Audio files (*.ogg)|*.ogg")); dialog.ShowModal(); if ( dialog.GetPath() != "" ) //Note that path is relative to the project file: { wxFileName filename(dialog.GetPath()); filename.MakeRelativeTo(projectDirectory); editCtrl->ChangeValue(filename.GetFullPath()); } return; } else if ( metadata.GetType() == "soundfile" ) { wxString projectDirectory = wxFileName::FileName(project.GetProjectFile()).GetPath(); wxFileDialog dialog(parent, _("Choose a sound"), projectDirectory, "", _("Audio files (*.wav, *.ogg)|*.wav;*.ogg")); dialog.ShowModal(); if ( dialog.GetPath() != "" ) //Note that path is relative to the project file: { wxFileName filename(dialog.GetPath()); filename.MakeRelativeTo(projectDirectory); editCtrl->ChangeValue(filename.GetFullPath()); } return; } else if ( metadata.GetType() == "operator" ) { SigneModification dialog(parent); int retour = dialog.ShowModal(); if ( retour == 1 ) editCtrl->ChangeValue("="); if ( retour == 2 ) editCtrl->ChangeValue("+"); if ( retour == 3 ) editCtrl->ChangeValue("-"); if ( retour == 4 ) editCtrl->ChangeValue("*"); if ( retour == 5 ) editCtrl->ChangeValue("/"); return; } else if ( metadata.GetType() == "password" ) { GeneratePassword dialog(parent); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.mdp); return; } else if ( metadata.GetType() == "trueorfalse" ) { TrueOrFalse dialog(parent, _("Choose True or False to fill the parameter"), _("True or False")); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(_("True")); else editCtrl->ChangeValue(_("False")); } else if ( metadata.GetType() == "yesorno" ) { if (wxMessageBox(_("Choose yes or no to fullfil parent parameter:"), _("Yes or no") ,wxYES_NO ) == wxYES) editCtrl->ChangeValue(_("yes")); else editCtrl->ChangeValue(_("no")); return; } else if ( metadata.GetType() == "layer" ) { gd::ChooseLayerDialog dialog(parent, layout); if( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.GetChosenLayer()); return; } else if ( metadata.GetType() == "joyaxis" ) { ChoiceJoyAxis dialog(parent, editCtrl->GetValue(), project, layout); if( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.joyaxis); return; } else if ( metadata.GetType() == "file" ) { ChoiceFile dialog(parent, editCtrl->GetValue(), project, layout); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.file); return; } else if ( metadata.GetType() == "objectvar" ) { if ( paramEdits.empty() ) return; gd::String objectWanted = paramEdits[0]->GetValue(); gd::Object * object = NULL; if ( layout.HasObjectNamed(objectWanted) ) object = &layout.GetObject(objectWanted); else if ( project.HasObjectNamed(objectWanted) ) object = &project.GetObject(objectWanted); else return; gd::ChooseVariableDialog dialog(parent, object->GetVariables()); dialog.SetAssociatedObject(&project, &layout, object); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.GetSelectedVariable()); return; } else if ( metadata.GetType() == "scenevar" ) { gd::ChooseVariableDialog dialog(parent, layout.GetVariables()); dialog.SetAssociatedLayout(&project, &layout); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.GetSelectedVariable()); return; } else if ( metadata.GetType() == "globalvar" ) { gd::ChooseVariableDialog dialog(parent, project.GetVariables()); dialog.SetAssociatedProject(&project); if ( dialog.ShowModal() == 1 ) editCtrl->ChangeValue(dialog.GetSelectedVariable()); return; } }
vector < gd::String > GD_CORE_API GetBehaviorsOfObject(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups) { bool behaviorsAlreadyInserted = false; vector < gd::String > behaviors; //Search in objects if ( layout.HasObjectNamed(name) ) //We check first layout's objects' list. { std::vector < gd::String > objectBehaviors = layout.GetObject(name).GetAllBehaviorNames(); std::copy(objectBehaviors.begin(), objectBehaviors.end(), back_inserter(behaviors)); behaviorsAlreadyInserted = true; } else if ( project.HasObjectNamed(name) ) //Then the global object list { vector < gd::String > objectBehaviors = project.GetObject(name).GetAllBehaviorNames(); std::copy(objectBehaviors.begin(), objectBehaviors.end(), back_inserter(behaviors)); behaviorsAlreadyInserted = true; } //Search in groups if ( searchInGroups ) { for (std::size_t i = 0;i<layout.GetObjectGroups().size();++i) { if ( layout.GetObjectGroups()[i].GetName() == name ) { //A group has the name searched //Verifying now that all objects have common behaviors. vector < gd::String > groupsObjects = layout.GetObjectGroups()[i].GetAllObjectsNames(); for (std::size_t j = 0;j<groupsObjects.size();++j) { //Get behaviors of the object of the group and delete behavior which are not in commons. vector < gd::String > objectBehaviors = GetBehaviorsOfObject(project, layout, groupsObjects[j], false); if (!behaviorsAlreadyInserted) { behaviorsAlreadyInserted = true; behaviors = objectBehaviors; } else { for (std::size_t a = 0 ;a<behaviors.size();++a) { if ( find(objectBehaviors.begin(), objectBehaviors.end(), behaviors[a]) == objectBehaviors.end() ) { behaviors.erase(behaviors.begin() + a); --a; } } } } } } for (std::size_t i = 0;i<project.GetObjectGroups().size();++i) { if ( project.GetObjectGroups()[i].GetName() == name ) { //A group has the name searched //Verifying now that all objects have common behaviors. vector < gd::String > groupsObjects = project.GetObjectGroups()[i].GetAllObjectsNames(); for (std::size_t j = 0;j<groupsObjects.size();++j) { //Get behaviors of the object of the group and delete behavior which are not in commons. vector < gd::String > objectBehaviors = GetBehaviorsOfObject(project, layout, groupsObjects[j], false); if (!behaviorsAlreadyInserted) { behaviorsAlreadyInserted = true; behaviors = objectBehaviors; } else { for (std::size_t a = 0 ;a<behaviors.size();++a) { if ( find(objectBehaviors.begin(), objectBehaviors.end(), behaviors[a]) == objectBehaviors.end() ) { behaviors.erase(behaviors.begin() + a); --a; } } } } } } } return behaviors; }
gd::String GD_CORE_API GetTypeOfObject(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups) { gd::String type; //Search in objects if ( layout.HasObjectNamed(name) ) type = layout.GetObject(name).GetType(); else if ( project.HasObjectNamed(name) ) type = project.GetObject(name).GetType(); //Search in groups if ( searchInGroups ) { for (std::size_t i = 0;i<layout.GetObjectGroups().size();++i) { if ( layout.GetObjectGroups()[i].GetName() == name ) { //A group has the name searched //Verifying now that all objects have the same type. vector < gd::String > groupsObjects = layout.GetObjectGroups()[i].GetAllObjectsNames(); gd::String previousType = groupsObjects.empty() ? "" : GetTypeOfObject(project, layout, groupsObjects[0], false); for (std::size_t j = 0;j<groupsObjects.size();++j) { if ( GetTypeOfObject(project, layout, groupsObjects[j], false) != previousType ) return ""; //The group has more than one type. } if ( !type.empty() && previousType != type ) return ""; //The group has objects of different type, so the group has not any type. type = previousType; } } for (std::size_t i = 0;i<project.GetObjectGroups().size();++i) { if ( project.GetObjectGroups()[i].GetName() == name ) { //A group has the name searched //Verifying now that all objects have the same type. vector < gd::String > groupsObjects = project.GetObjectGroups()[i].GetAllObjectsNames(); gd::String previousType = groupsObjects.empty() ? "" : GetTypeOfObject(project, layout, groupsObjects[0], false); for (std::size_t j = 0;j<groupsObjects.size();++j) { if ( GetTypeOfObject(project, layout, groupsObjects[j], false) != previousType ) return ""; //The group has more than one type. } if ( !type.empty() && previousType != type ) return ""; //The group has objects of different type, so the group has not any type. type = previousType; } } } return type; }