Files
GDevelop/IDE/CreateTemplate.cpp
T
Florian 156a0bc3f9 Making code refactoring/cleaning/documentation.
git-svn-id: svn://localhost@388 8062f311-0dae-4547-b526-b8ab9ac864a5
2011-02-12 15:06:26 +00:00

353 lines
21 KiB
C++

#include "CreateTemplate.h"
//(*InternalHeaders(CreateTemplate)
#include <wx/bitmap.h>
#include <wx/settings.h>
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)
#include <wx/log.h>
#include <wx/filedlg.h>
#include "GDL/HelpFileAccess.h"
#include "tinyxml.h"
#include <string>
#include <vector>
#include "GDL/Game.h"
#include "GDL/OpenSaveGame.h"
#include "GDL/CommonTools.h"
using namespace std;
//(*IdInit(CreateTemplate)
const long CreateTemplate::ID_STATICBITMAP3 = wxNewId();
const long CreateTemplate::ID_STATICTEXT1 = wxNewId();
const long CreateTemplate::ID_PANEL1 = wxNewId();
const long CreateTemplate::ID_STATICLINE1 = wxNewId();
const long CreateTemplate::ID_STATICTEXT5 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL18 = wxNewId();
const long CreateTemplate::ID_STATICTEXT4 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL17 = wxNewId();
const long CreateTemplate::ID_BUTTON4 = wxNewId();
const long CreateTemplate::ID_PANEL2 = wxNewId();
const long CreateTemplate::ID_STATICTEXT2 = wxNewId();
const long CreateTemplate::ID_STATICTEXT3 = wxNewId();
const long CreateTemplate::ID_STATICTEXT6 = wxNewId();
const long CreateTemplate::ID_STATICTEXT7 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL1 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL16 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL15 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL14 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL13 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL12 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL11 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL10 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL9 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL8 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL7 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL6 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL5 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL4 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL3 = wxNewId();
const long CreateTemplate::ID_TEXTCTRL2 = wxNewId();
const long CreateTemplate::ID_PANEL3 = wxNewId();
const long CreateTemplate::ID_NOTEBOOK1 = wxNewId();
const long CreateTemplate::ID_STATICLINE2 = wxNewId();
const long CreateTemplate::ID_BUTTON2 = wxNewId();
const long CreateTemplate::ID_BUTTON1 = wxNewId();
const long CreateTemplate::ID_BUTTON3 = wxNewId();
//*)
BEGIN_EVENT_TABLE( CreateTemplate, wxDialog )
//(*EventTable(CreateTemplate)
//*)
END_EVENT_TABLE()
CreateTemplate::CreateTemplate( wxWindow* parent, vector < BaseEventSPtr > & events_ ) :
events( events_ )
{
//(*Initialize(CreateTemplate)
wxFlexGridSizer* FlexGridSizer4;
wxFlexGridSizer* FlexGridSizer3;
wxFlexGridSizer* FlexGridSizer2;
wxFlexGridSizer* FlexGridSizer6;
wxFlexGridSizer* FlexGridSizer1;
wxFlexGridSizer* FlexGridSizer17;
Create(parent, wxID_ANY, _("Créer un modèle d\'évènements"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer17 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer17->AddGrowableCol(0);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(420,54), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
Panel1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
FlexGridSizer6 = new wxFlexGridSizer(0, 3, 0, 0);
StaticBitmap3 = new wxStaticBitmap(Panel1, ID_STATICBITMAP3, wxBitmap(wxImage(_T("res/addtemplate.png"))), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP3"));
FlexGridSizer6->Add(StaticBitmap3, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Vous pouvez créer un modèle d\'évènements à partir des \névènements de la scène actuelle. Un modèle d\'évènement\npermet de créer automatiquement et rapidement des évènements,\nen remplissant juste quelques paramètres."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT1"));
FlexGridSizer6->Add(StaticText1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(FlexGridSizer6);
FlexGridSizer6->SetSizeHints(Panel1);
FlexGridSizer17->Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
FlexGridSizer17->Add(StaticLine1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
FlexGridSizer1->Add(FlexGridSizer17, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
Panel2 = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));
FlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
FlexGridSizer4->AddGrowableCol(1);
FlexGridSizer4->AddGrowableRow(1);
StaticText5 = new wxStaticText(Panel2, ID_STATICTEXT5, _("Nom du modèle :"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
FlexGridSizer4->Add(StaticText5, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
nomEdit = new wxTextCtrl(Panel2, ID_TEXTCTRL18, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL18"));
FlexGridSizer4->Add(nomEdit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText4 = new wxStaticText(Panel2, ID_STATICTEXT4, _("Description du modèle :"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
FlexGridSizer4->Add(StaticText4, 1, wxALL|wxALIGN_RIGHT|wxALIGN_TOP, 5);
descEdit = new wxTextCtrl(Panel2, ID_TEXTCTRL17, wxEmptyString, wxDefaultPosition, wxSize(201,64), wxTE_MULTILINE, wxDefaultValidator, _T("ID_TEXTCTRL17"));
FlexGridSizer4->Add(descEdit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer4->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button1 = new wxButton(Panel2, ID_BUTTON4, _("Suivant"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
FlexGridSizer4->Add(Button1, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Panel2->SetSizer(FlexGridSizer4);
FlexGridSizer4->Fit(Panel2);
FlexGridSizer4->SetSizeHints(Panel2);
Panel3 = new wxPanel(Notebook1, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL3"));
FlexGridSizer2 = new wxFlexGridSizer(0, 2, 0, 0);
FlexGridSizer2->AddGrowableCol(1);
StaticText2 = new wxStaticText(Panel3, ID_STATICTEXT2, _("Rechercher ceci\ndans les paramètres\ndes actions et conditions"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT2"));
wxFont StaticText2Font(wxDEFAULT,wxDEFAULT,wxFONTSTYLE_NORMAL,wxBOLD,false,wxEmptyString,wxFONTENCODING_DEFAULT);
StaticText2->SetFont(StaticText2Font);
FlexGridSizer2->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText3 = new wxStaticText(Panel3, ID_STATICTEXT3, _("Description qui sera donnée à l\'insertion"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
wxFont StaticText3Font(wxDEFAULT,wxDEFAULT,wxFONTSTYLE_NORMAL,wxBOLD,false,wxEmptyString,wxFONTENCODING_DEFAULT);
StaticText3->SetFont(StaticText3Font);
FlexGridSizer2->Add(StaticText3, 1, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
StaticText6 = new wxStaticText(Panel3, ID_STATICTEXT6, _("Exemple : MonObjet"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
wxFont StaticText6Font(wxDEFAULT,wxDEFAULT,wxFONTSTYLE_ITALIC,wxNORMAL,false,wxEmptyString,wxFONTENCODING_DEFAULT);
StaticText6->SetFont(StaticText6Font);
FlexGridSizer2->Add(StaticText6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText7 = new wxStaticText(Panel3, ID_STATICTEXT7, _("Exemple : Entrez l\'objet servant de héros."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
wxFont StaticText7Font(wxDEFAULT,wxDEFAULT,wxFONTSTYLE_ITALIC,wxNORMAL,false,wxEmptyString,wxFONTENCODING_DEFAULT);
StaticText7->SetFont(StaticText7Font);
FlexGridSizer2->Add(StaticText7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj1Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
FlexGridSizer2->Add(NomObj1Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc1Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL16, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL16"));
FlexGridSizer2->Add(Desc1Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj2Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL15, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL15"));
FlexGridSizer2->Add(NomObj2Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc2Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL14, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL14"));
FlexGridSizer2->Add(Desc2Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj3Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL13, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL13"));
FlexGridSizer2->Add(NomObj3Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc3Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL12, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL12"));
FlexGridSizer2->Add(Desc3Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj4Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL11, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL11"));
FlexGridSizer2->Add(NomObj4Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc4Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL10, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL10"));
FlexGridSizer2->Add(Desc4Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj5Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL9, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL9"));
FlexGridSizer2->Add(NomObj5Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc5Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL8, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL8"));
FlexGridSizer2->Add(Desc5Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj6Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL7, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL7"));
FlexGridSizer2->Add(NomObj6Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc6Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
FlexGridSizer2->Add(Desc6Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj7Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL5, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
FlexGridSizer2->Add(NomObj7Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc7Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
FlexGridSizer2->Add(Desc7Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
NomObj8Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxSize(118,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
FlexGridSizer2->Add(NomObj8Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Desc8Edit = new wxTextCtrl(Panel3, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
FlexGridSizer2->Add(Desc8Edit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel3->SetSizer(FlexGridSizer2);
FlexGridSizer2->Fit(Panel3);
FlexGridSizer2->SetSizeHints(Panel3);
Notebook1->AddPage(Panel2, _("Informations sur le modèle"), false);
Notebook1->AddPage(Panel3, _("Paramètres"), false);
FlexGridSizer1->Add(Notebook1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticLine2 = new wxStaticLine(this, ID_STATICLINE2, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE2"));
FlexGridSizer1->Add(StaticLine2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
FlexGridSizer3 = new wxFlexGridSizer(0, 3, 0, 0);
FlexGridSizer3->AddGrowableCol(0);
CreateBt = new wxButton(this, ID_BUTTON2, _("Créer"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
FlexGridSizer3->Add(CreateBt, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
AnnulerBt = new wxButton(this, ID_BUTTON1, _("Fermer"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
FlexGridSizer3->Add(AnnulerBt, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
AideBt = new wxButton(this, ID_BUTTON3, _("Aide"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
FlexGridSizer3->Add(AideBt, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(FlexGridSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
SetSizer(FlexGridSizer1);
FlexGridSizer1->Fit(this);
FlexGridSizer1->SetSizeHints(this);
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CreateTemplate::OnButton1Click);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CreateTemplate::OnCreateBtClick);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CreateTemplate::OnAnnulerBtClick);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CreateTemplate::OnAideBtClick);
//*)
}
CreateTemplate::~CreateTemplate()
{
//(*Destroy(CreateTemplate)
//*)
}
struct sizestring
{
bool operator()( const std::pair<string, int> & left, const std::pair<string, int> & right )
{
return left.first.size() > right.first.size();
}
};
void CreateTemplate::OnCreateBtClick( wxCommandEvent& event )
{
vector < std::pair<string, int> > parameters;
//On rajoute tous les paramètres et leur numéro
if ( NomObj1Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj1Edit->GetValue() ), 1 ) );
if ( NomObj2Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj2Edit->GetValue() ), 2 ) );
if ( NomObj3Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj3Edit->GetValue() ), 3 ) );
if ( NomObj4Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj4Edit->GetValue() ), 4 ) );
if ( NomObj5Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj5Edit->GetValue() ), 5 ) );
if ( NomObj6Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj6Edit->GetValue() ), 6 ) );
if ( NomObj7Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj7Edit->GetValue() ), 7 ) );
if ( NomObj8Edit->GetValue() != "" )
parameters.push_back( std::pair<string, int>( static_cast<string>( NomObj8Edit->GetValue() ), 8 ) );
//On classe de la plus petite chaine à la plus grande
std::sort( parameters.begin(), parameters.end(), sizestring() );
ProcessEvents(events, parameters);
TiXmlDocument doc;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "ISO-8859-1", "" );
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "Template" );
doc.LinkEndChild( root );
root->SetAttribute( "nom", nomEdit->GetValue().c_str() );
root->SetAttribute( "desc", descEdit->GetValue().c_str() );
root->SetAttribute( "param1", Desc1Edit->GetValue().c_str() );
root->SetAttribute( "param2", Desc2Edit->GetValue().c_str() );
root->SetAttribute( "param3", Desc3Edit->GetValue().c_str() );
root->SetAttribute( "param4", Desc4Edit->GetValue().c_str() );
root->SetAttribute( "param5", Desc5Edit->GetValue().c_str() );
root->SetAttribute( "param6", Desc6Edit->GetValue().c_str() );
root->SetAttribute( "param7", Desc7Edit->GetValue().c_str() );
root->SetAttribute( "param8", Desc8Edit->GetValue().c_str() );
TiXmlElement * elemEvents = new TiXmlElement( "Events" );
root->LinkEndChild( elemEvents );
OpenSaveGame::SaveEvents(events, elemEvents);
wxFileDialog dialog( this, _( "Choisissez où enregistrer le modèle" ), "", "", "Modèle (*.mgd)|*.mgd", wxFD_SAVE );
dialog.ShowModal();
if ( dialog.GetPath() != "" )
{
string path = static_cast<string>( dialog.GetPath() );
if ( !doc.SaveFile( path.c_str() ) )
{
wxLogError( _( "Impossible d'enregistrer le fichier. Vérifiez que le disque comporte assez d'espace disque, qu'il n'est pas protégé en écriture, et que vous possèdez les autorisations nécessaires." ) );
return;
}
}
wxLogMessage(_("Le modèle a été correctement créé."));
}
////////////////////////////////////////////////////////////
/// Remplace les paramètres par des _PARAMx_
////////////////////////////////////////////////////////////
void CreateTemplate::ProcessEvents(vector < BaseEventSPtr > & eventsToProcess, vector < std::pair<string, int> > parameters)
{
//On remplace dans chaque paramètre des actions et des conditions
for ( unsigned int i = 0;i < eventsToProcess.size() ;i++ )
{
vector < vector<Instruction>* > allConditionsVectors = eventsToProcess[i]->GetAllConditionsVectors();
for (unsigned int c = 0;c<allConditionsVectors.size();++c)
{
for ( unsigned int nb = 0;nb < allConditionsVectors[c]->size() ;nb++ )
{
vector < GDExpression > parametres = allConditionsVectors[c]->at( nb ).GetParameters();
for ( unsigned int j = 0;j < parametres.size() ;j++ )
{
//On respecte bien l'ordre, du plus grand au plus petit
for ( unsigned int k = 0; k < parameters.size() ;k++ )
{
string ReplaceBy = "_PARAM" +ToString( parameters.at( k ).second ) + "_";
parametres.at( j ) = GDExpression( ConvertParam( parametres.at( j ).GetPlainString(), parameters.at( k ).first, ReplaceBy ) );
}
}
allConditionsVectors[c]->at( nb ).SetParameters(parametres);
}
}
vector < vector<Instruction>* > allActionsVectors = eventsToProcess[i]->GetAllActionsVectors();
for (unsigned int a = 0;a<allActionsVectors.size();++a)
{
for ( unsigned int nb = 0;nb < allActionsVectors[a]->size() ;nb++ )
{
vector < GDExpression > parametres = allActionsVectors[a]->at( nb ).GetParameters();
for ( unsigned int j = 0;j < parametres.size() ;j++ )
{
//On respecte bien l'ordre, du plus grand au plus petit
for ( unsigned int k = 0; k < parameters.size() ;k++ )
{
string ReplaceBy = "_PARAM" +ToString( parameters.at( k ).second ) + "_";
parametres.at( j ) = GDExpression( ConvertParam( parametres.at( j ).GetPlainString(), parameters.at( k ).first, ReplaceBy ) );
}
}
allActionsVectors[a]->at( nb ).SetParameters(parametres);
}
}
//Les sous évènements aussi
if ( eventsToProcess[i]->CanHaveSubEvents() )
ProcessEvents(eventsToProcess[i]->GetSubEvents(), parameters);
}
}
void CreateTemplate::OnAnnulerBtClick( wxCommandEvent& event )
{
EndModal( 0 );
}
string CreateTemplate::ConvertParam( string Parametre, string ToReplace, string ReplaceBy )
{
if ( ToReplace == "" ) return Parametre;
if ( Parametre.find( ToReplace ) != string::npos )
Parametre.replace( Parametre.find( ToReplace ), ToReplace.length(), ReplaceBy );
return Parametre;
}
void CreateTemplate::OnAideBtClick( wxCommandEvent& event )
{
HelpFileAccess * helpFileAccess = HelpFileAccess::GetInstance();
helpFileAccess->DisplaySection(151);
}
void CreateTemplate::OnButton1Click(wxCommandEvent& event)
{
Notebook1->SetSelection(1);
}