Selaa lähdekoodia

Commencement du choix de l'UI (Simple ou avancée

François Gautrais 8 vuotta sitten
vanhempi
commit
8073d56237
7 muutettua tiedostoa jossa 526 lisäystä ja 444 poistoa
  1. 1 34
      final/sainterblon.json
  2. 3 1
      src/Makefile.am
  3. 6 2
      src/Makefile.in
  4. 5 384
      src/g-window.cc
  5. 22 23
      src/g-window.h
  6. 427 0
      src/window-advanced.cc
  7. 62 0
      src/window-advanced.h

+ 1 - 34
final/sainterblon.json

@@ -111,39 +111,6 @@
 				}
 			],
 			"resource" : "plana"
-		},
-		{
-			"coordinates" : 
-			[
-				[
-					-1.6598367691040039,
-					48.021968841552734
-				],
-				[
-					-1.6580986976623535,
-					48.021793365478516
-				],
-				[
-					-1.6595578193664551,
-					48.0208740234375
-				]
-			],
-			"name" : "intro",
-			"points" : 
-			[
-				{
-					"angle" : 180.0,
-					"coordinates" : 
-					[
-						-1.6593432426452637,
-						48.021648406982422
-					],
-					"field" : 120.0,
-					"radius" : 10.0,
-					"useAngle" : false
-				}
-			],
-			"resource" : "intro"
 		}
 	],
 	"dir" : "/home/ptitcois/Programmation/TestMin3D2/app/src/main",
@@ -173,7 +140,7 @@
 				1.0,
 				1.0
 			],
-			"stage" : 4,
+			"stage" : 0,
 			"title" : "Un message mysterieux",
 			"type" : "Image"
 		},

+ 3 - 1
src/Makefile.am

@@ -112,7 +112,9 @@ libui_a_SOURCES =  \
 	zone-tab.cc \
 	zone-tab.h \
 	tab.cc \
-	tab.h
+	tab.h \
+	window-advanced.cc \
+	window-advanced.h
 
 libdata_a_SOURCES =  \
 	area.cc \

+ 6 - 2
src/Makefile.in

@@ -148,7 +148,8 @@ libui_a_AR = $(AR) $(ARFLAGS)
 libui_a_LIBADD =
 am_libui_a_OBJECTS = general-tab.$(OBJEXT) g-window.$(OBJEXT) \
 	map-viewer.$(OBJEXT) resource-tab.$(OBJEXT) \
-	stage-tab.$(OBJEXT) zone-tab.$(OBJEXT) tab.$(OBJEXT)
+	stage-tab.$(OBJEXT) zone-tab.$(OBJEXT) tab.$(OBJEXT) \
+	window-advanced.$(OBJEXT)
 libui_a_OBJECTS = $(am_libui_a_OBJECTS)
 libutils_a_AR = $(AR) $(ARFLAGS)
 libutils_a_LIBADD =
@@ -465,7 +466,9 @@ libui_a_SOURCES = \
 	zone-tab.cc \
 	zone-tab.h \
 	tab.cc \
-	tab.h
+	tab.h \
+	window-advanced.cc \
+	window-advanced.h
 
 libdata_a_SOURCES = \
 	area.cc \
@@ -649,6 +652,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stage.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tab.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/window-advanced.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zone-tab.Po@am__quote@
 
 .cc.o:

+ 5 - 384
src/g-window.cc

@@ -41,69 +41,23 @@ struct _Private
 	/* ANJUTA: Widgets declaration for histodexc.ui - DO NOT REMOVE */
 };
 
-static void on_new (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_new ();
-}
-
-static void on_open (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_open ();
-}
-
-static void on_save (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_save ();
-}
 
-static void on_import (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_import ();
-}
-
-static void on_saveas (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_saveas ();
-}
-
-static void on_exit_win (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_exit ();
-}
 
-static void on_generate (GtkMenuItem* app, gpointer user_data)
-{
-	CallbackArg* r = (CallbackArg*) user_data;
-	((GWindow*)r->tab)->on_generate ();
-}
-
-void
-on_window_destroy (GtkWidget *widget, gpointer data)
-{
-	gtk_main_quit ();
-}
-
-GWindow::GWindow()
+GWindow::GWindow(const std::string& file)
 {
 	setlocale(LC_NUMERIC, "C");
 	m_magic=1234;
 	#if !defined(TEST) && defined(G_OS_WIN32)
 	gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
 	gchar *datadir = g_build_filename (prefix, "share", PACKAGE, NULL);
-	gchar *ui_file = g_build_filename (datadir, "ui", "histodexc.ui", NULL);
+	gchar *ui_file = g_build_filename (datadir, "ui", file.c_str(), NULL);
 	#endif
 
 	GError* error = NULL;
 
 	/* Load UI from file */
 	m_builder = gtk_builder_new ();
-	if (!gtk_builder_add_from_file (m_builder, UI_FILE, &error))
+	if (!gtk_builder_add_from_file (m_builder, file.c_str (), &error))
 	{
 		g_critical ("Couldn't load builder file: %s", error->message);
 		g_error_free (error);
@@ -119,12 +73,12 @@ GWindow::GWindow()
         {
                 g_critical ("Widget \"%s\" is missing in file %s.",
 				TOP_WINDOW,
-				UI_FILE);
+				file.c_str());
         }
 
 	m_priv = (Private*) g_malloc (sizeof (struct _Private));
 	/* ANJUTA: Widgets initialization for histodexc.ui - DO NOT REMOVE */
-	init_menu();
+	
 
 	/*#if !defined(TEST) && defined(G_OS_WIN32)
 		g_free (prefix);
@@ -140,337 +94,4 @@ GWindow::~GWindow()
 	g_free (m_priv);
 }
 
-void GWindow::show()
-{
-	gtk_widget_show (m_window);
-}
-
-
-bool GWindow::checkSaved()
-{
-	if(isModidified())
-	{
-		gint result;
-		GtkDialogFlags flags = GTK_DIALOG_MODAL;
-		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(m_window),
-				                         flags,
-										 GTK_MESSAGE_QUESTION,
-										 GTK_BUTTONS_YES_NO,
-				                         "Voulez-vous sauvegarder le fichier ?");
-		gtk_window_set_title(GTK_WINDOW(dialog), "Sauvegarder");
-		result=gtk_dialog_run (GTK_DIALOG (dialog));
-
-		if (result==GTK_RESPONSE_YES)
-		{
-		    on_save();
-			return true;
-		}
-		else if (result==GTK_RESPONSE_NO)
-		{
-			return true;
-		}else
-		{
-			return false;
-		}
-		gtk_widget_destroy (dialog);
-	}
-}
-
-void window_start(int argc, char** argv)
-{
-	GWindow* g = new GWindow ();
-	g->show();
-	if(argc>1)
-		g->open(argv[1]);
-	else 
-		g->on_new();
-}
-
-
-void GWindow::init_menu()
-{
-	static CallbackArg* sm_args = new CallbackArg (this);
-	m_resource = new ResourceTab (m_window, m_builder);
-	m_zone = new ZoneTab (m_window, m_builder, m_resource);
-	m_stage = new StageTab (m_window, m_builder, m_resource);
-	m_general = new GeneralTab (m_window, m_builder, m_stage);
-	
-	m_generate=GTK_BUTTON(gtk_builder_get_object(m_builder,"gen_generate"));
-	CONNECT(m_generate, "clicked", ::on_generate, new CallbackArg (this));
-
-
-	m_new=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_new"));
-	m_open=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_open"));
-	m_import=GTK_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_import"));
-	m_save=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_save"));
-	m_saveas=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_saveas"));
-	m_exit=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_exit"));
-	m_log=GTK_TEXT_VIEW(gtk_builder_get_object(m_builder,"tv_log"));
-
-	CONNECT(m_new, "activate", ::on_new, sm_args);
-	CONNECT(m_open, "activate", ::on_open , sm_args);
-	CONNECT(m_save, "activate", ::on_save, sm_args);
-	CONNECT(m_saveas, "activate", ::on_saveas, sm_args);
-	CONNECT(m_exit, "activate", ::on_exit_win, sm_args);
-	CONNECT(m_import, "activate", ::on_import, sm_args);
-	CONNECT(m_window, "destroy", on_exit_win,sm_args);
-}
-
-void GWindow::on_generate()
-{
-	int w=0;
-	int e=0;
-	int ce=0;
-	std::string sa ="Succès de la génération";
-	std::string sb = "Rien à déclarer";
-	General g = m_general->getGeneral();
-	std::vector<Resource>&  r= m_resource->getResources();
-	std::vector<Area>&  a= m_zone->getAreas();
-	std::vector<Stage>&  s= m_stage->getStages();
-	Generator gen(g, a, r,s, this);
-	std::string log;
-	gen.generate();
-	ce=gen.getCriticalErrorsCount ();
-	e=gen.getErrorsCount ();
-	w=gen.getWarningCount ();
-	log=gen.getLog ();
-	gtk_text_view_set_text (m_log, log.c_str());
-
-	std::cout << "W=" << w << " E =" << e << std::endl; 
-	if(w && !e && !ce)
-	{
-		sa="Avertissement(s) lors de la génération";
-		sb=tstr(w)+" avertisssments lors de la génération. Des problèmes peuvent apparaitre à l'éxecution";
-	}
-	if(e && ! ce)
-	{
-		sa="Erreur(s) lors de la génération";
-		sb=tstr(e)+" erreurs et "+tstr(w)+" avertisssments lors de la génération. Des problèmes devraient apparaitre à l'éxecution";
-	}
-	if(ce)
-	{
-		sa="Erreur(s) critique(s) lors de la génération";
-		sb=tstr(ce)+ " erreurs critiques " +tstr(e)+" erreurs et "+tstr(w)+" avertisssments lors de la génération. La génération a échouée";
-	}
-
-
-	
-
-
-	GtkWidget* dialog = NULL;
-	GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
-	dialog = gtk_message_dialog_new (GTK_WINDOW(m_window),
-                                 flags,
-                                 GTK_MESSAGE_INFO,
-                                 GTK_BUTTONS_OK,
-                                 sb.c_str());
-	gtk_dialog_run (GTK_DIALOG (dialog));
-	gtk_widget_destroy (dialog);
-	
-}
-
-void GWindow::write(const std::string& file)
-{
-	std::ofstream out(file);
-	Json::Value j = m_general->getJson();
-	//std::cout << j << std::endl;
-	j["areas"] = m_zone->getJson();
-	j["stages_list"] = m_stage->getJson();
-	j["resources"] = m_resource->getJson();
-	out << j;
-}
-
-
-Json::Value GWindow::getJson(bool genFinal)
-{
-	Json::Value j = m_general->getJson(genFinal);
-	std::cout << j << std::endl;
-	j["areas"] = m_zone->getJson();
-	j["stages_list"] = m_stage->getJson();
-	if(!genFinal) 
-		j["resources"] = m_resource->getJson();
-	else 
-		j["others"] = m_resource->getJsonOrphelin ();
-	return j;
-}
-
-
-void GWindow::on_new()
-{
-	Json::Value v(Json::arrayValue);
-	m_currentFile="";
-	m_resource->open(v);
-	m_zone->open(v);
-	m_general->open(v);
-	m_stage->open(v);
-	setModidified ();
-	m_general->on_stage_changed();
-	changeFile ("");
-}
-
-void GWindow::setModidified()
-{
-	m_resource->setModified ();
-	m_zone->setModified ();
-	m_general->setModified ();
-	m_stage->setModified ();
-}
-
-
-void GWindow::clearModidified()
-{
-	m_resource->clearModified ();
-	m_zone->clearModified ();
-	m_general->clearModified ();
-	m_stage->clearModified ();
-}
 
-
-bool GWindow::isModidified()
-{
-	bool b= false;
-	b|=m_resource->getModified ();
-	b|=m_zone->getModified ();
-	b|=m_general->getModified ();
-	b|=m_stage->getModified ();
-	return b;
-}
-
-void GWindow::on_open()
-{
-	GtkWidget *dialog;
-	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
-	gint res;
-	printf("2 M_WINDOWS: %d\n",  m_window);
-	dialog = gtk_file_chooser_dialog_new ("Ouvrir le fichier de jeu",
-		                                  GTK_WINDOW(m_window),
-		                                  action,
-		                                  _("_Annuler"),
-		                                  GTK_RESPONSE_CANCEL,
-		                                  _("_Ouvrir"),
-		                                  GTK_RESPONSE_ACCEPT,
-		                                  NULL);
-
-	res = gtk_dialog_run (GTK_DIALOG (dialog));
-	if (res == GTK_RESPONSE_ACCEPT)
-	{
-		try{
-			std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
-			open(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
-			changeFile(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
-			clearModidified();
-		}catch(std::exception& e)
-		{
-			
-			std::cout << "Error:" << e.what() << std::endl;
-		}
-	}
-
-	gtk_widget_destroy (dialog);
-}
-
-void GWindow::on_import()
-{
-	GtkWidget *dialog;
-	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
-	gint res;
-	dialog = gtk_file_chooser_dialog_new ("Importer le fichier Merkaartor",
-		                                  GTK_WINDOW(m_window),
-		                                  action,
-		                                  _("_Annuler"),
-		                                  GTK_RESPONSE_CANCEL,
-		                                  _("_Ouvrir"),
-		                                  GTK_RESPONSE_ACCEPT,
-		                                  NULL);
-
-	res = gtk_dialog_run (GTK_DIALOG (dialog));
-	if (res == GTK_RESPONSE_ACCEPT)
-	{
-		try{
-			std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
-			Merkaartot m(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
-			Json::Value v = m.getJson ();
-			m_zone->open(v);
-		}catch(std::exception& e)
-		{
-			
-			std::cout << "Error:" << e.what() << std::endl;
-		}
-	}
-
-	gtk_widget_destroy (dialog);
-}
-
-
-void GWindow::on_save()
-{
-	if(m_currentFile=="")
-	{
-		on_saveas();
-	}else
-	{
-		write(m_currentFile);
-		clearModidified();
-	}
-}
-
-void GWindow::on_saveas()
-{
-	GtkWidget *dialog;
-	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
-	gint res;
-
-	dialog = gtk_file_chooser_dialog_new ("Enregister le fichier de jeu",
-		                                  GTK_WINDOW(m_window),
-		                                  action,
-		                                  _("_Annuler"),
-		                                  GTK_RESPONSE_CANCEL,
-		                                  _("_Enregistrer"),
-		                                  GTK_RESPONSE_ACCEPT,
-		                                  NULL);
-	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
-	res = gtk_dialog_run (GTK_DIALOG (dialog));
-	if (res == GTK_RESPONSE_ACCEPT)
-	{
-		std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
-		write(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
-		changeFile(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
-		clearModidified();
-	}
-	gtk_widget_destroy (dialog);
-}
-
-void GWindow::changeFile(const std::string& file)
-{
-	std::string s = "File: "+file;
-	m_currentFile=file; 
-	if(file=="")
-		gtk_window_set_title (GTK_WINDOW(m_window),"*New File");
-	else 
-		gtk_window_set_title (GTK_WINDOW(m_window),s.c_str());
-}
-
-
-void GWindow::open(const std::string& f)
-{
-	if(checkSaved ())
-	{
-		Json::Value v;
-		std::ifstream in(f);
-		in >> v;
-		m_resource->open(v["resources"]);
-		m_zone->open(v["areas"]);
-		m_stage->open(v["stages_list"]);
-		m_general->open(v);
-		changeFile (f);
-	}
-}
-
-
-void GWindow::on_exit()
-{
-	if(checkSaved ())
-	{
-		gtk_main_quit ();
-	}
-}

+ 22 - 23
src/g-window.h

@@ -19,6 +19,9 @@
 
 #ifndef _G_WINDOW_H_
 #define _G_WINDOW_H_
+#include <iostream>
+#include <json/json.h>
+#include <gtk/gtk.h>
 
 
 class GeneralTab;
@@ -29,21 +32,21 @@ struct _Private;
 class GWindow
 {
 	public:
-		GWindow();
+		GWindow(const std::string& file);
 		virtual ~GWindow();
 
-		virtual void show();
-		void write(const std::string& file);
-		Json::Value getJson(bool genFinal=false);
-		void on_generate();
-		void on_new();
-		void on_import();
-		void on_open();
-		void on_save();
-		void on_saveas();
-		void on_exit();
-		void open(const std::string& f);
-		void changeFile(const std::string& file);
+		virtual void show()=0;
+		virtual void write(const std::string& file)=0;
+		virtual Json::Value getJson(bool genFinal=false)=0;
+		virtual void on_generate()=0;
+		virtual void on_new()=0;
+		virtual void on_import()=0;
+		virtual void on_open()=0;
+		virtual void on_save()=0;
+		virtual void on_saveas()=0;
+		virtual void on_exit()=0;
+		virtual void open(const std::string& f)=0;
+		virtual void changeFile(const std::string& file)=0;
 		 
 		
 	protected:
@@ -62,18 +65,14 @@ class GWindow
 		GtkTextView*		m_log;
 		
 
-		GeneralTab		*m_general;
-		ResourceTab		*m_resource;
-		ZoneTab			*m_zone;
-		StageTab		*m_stage;
-		std::string     m_currentFile;
+		
 	protected:
-		void init_menu();
-		void setModidified();
+		virtual void init_menu()=0;
+		virtual void setModidified()=0;
 
-		void clearModidified();
-		bool isModidified();
-		bool checkSaved();
+		virtual void clearModidified()=0;
+		virtual bool isModidified()=0;
+		virtual bool checkSaved()=0;
 		 
 	private:
 

+ 427 - 0
src/window-advanced.cc

@@ -0,0 +1,427 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * window-advanced.cc
+ * Copyright (C) 2017 Unknown <francois@gautrais.eu>
+ *
+ * histodexc is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * histodexc is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "window-advanced.h"
+#include "main.h"
+#include <config.h>
+#include <gtk/gtk.h>
+
+
+#include <glib/gi18n.h>
+#include "g-window.h"
+
+#include "general-tab.h"
+#include "resource-tab.h"
+#include "stage-tab.h"
+#include "zone-tab.h"
+#include "merkator.h"
+#include <fstream>
+#include "generator.h"
+#include "utils.h"
+static void on_new (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_new ();
+}
+
+static void on_open (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_open ();
+}
+
+static void on_save (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_save ();
+}
+
+static void on_import (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_import ();
+}
+
+static void on_saveas (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_saveas ();
+}
+
+static void on_exit_win (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_exit ();
+}
+
+static void on_generate (GtkMenuItem* app, gpointer user_data)
+{
+	CallbackArg* r = (CallbackArg*) user_data;
+	((GWindow*)r->tab)->on_generate ();
+}
+
+void
+on_window_destroy (GtkWidget *widget, gpointer data)
+{
+	gtk_main_quit ();
+}
+
+
+WindowAdvanced::WindowAdvanced(const std::string& file) : GWindow (file)
+{
+	init_menu();
+}
+WindowAdvanced::~WindowAdvanced()
+{
+}
+
+void WindowAdvanced::show()
+{
+	gtk_widget_show (m_window);
+}
+
+
+bool WindowAdvanced::checkSaved()
+{
+	if(isModidified())
+	{
+		gint result;
+		GtkDialogFlags flags = GTK_DIALOG_MODAL;
+		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(m_window),
+				                         flags,
+										 GTK_MESSAGE_QUESTION,
+										 GTK_BUTTONS_YES_NO,
+				                         "Voulez-vous sauvegarder le fichier ?");
+		gtk_window_set_title(GTK_WINDOW(dialog), "Sauvegarder");
+		result=gtk_dialog_run (GTK_DIALOG (dialog));
+
+		if (result==GTK_RESPONSE_YES)
+		{
+		    on_save();
+			return true;
+		}
+		else if (result==GTK_RESPONSE_NO)
+		{
+			return true;
+		}else
+		{
+			return false;
+		}
+		gtk_widget_destroy (dialog);
+	}
+}
+
+void window_start(int argc, char** argv)
+{
+	WindowAdvanced* g = new WindowAdvanced (UI_FILE);
+	g->show();
+	if(argc>1)
+		g->open(argv[1]);
+	else 
+		g->on_new();
+}
+
+
+void WindowAdvanced::init_menu()
+{
+	static CallbackArg* sm_args = new CallbackArg (this);
+	m_resource = new ResourceTab (m_window, m_builder);
+	m_zone = new ZoneTab (m_window, m_builder, m_resource);
+	m_stage = new StageTab (m_window, m_builder, m_resource);
+	m_general = new GeneralTab (m_window, m_builder, m_stage);
+	
+	m_generate=GTK_BUTTON(gtk_builder_get_object(m_builder,"gen_generate"));
+	CONNECT(m_generate, "clicked", ::on_generate, new CallbackArg (this));
+
+
+	m_new=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_new"));
+	m_open=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_open"));
+	m_import=GTK_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_import"));
+	m_save=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_save"));
+	m_saveas=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_saveas"));
+	m_exit=GTK_IMAGE_MENU_ITEM(gtk_builder_get_object(m_builder,"menu_exit"));
+	m_log=GTK_TEXT_VIEW(gtk_builder_get_object(m_builder,"tv_log"));
+
+	CONNECT(m_new, "activate", ::on_new, sm_args);
+	CONNECT(m_open, "activate", ::on_open , sm_args);
+	CONNECT(m_save, "activate", ::on_save, sm_args);
+	CONNECT(m_saveas, "activate", ::on_saveas, sm_args);
+	CONNECT(m_exit, "activate", ::on_exit_win, sm_args);
+	CONNECT(m_import, "activate", ::on_import, sm_args);
+	CONNECT(m_window, "destroy", on_exit_win,sm_args);
+}
+
+void WindowAdvanced::on_generate()
+{
+	int w=0;
+	int e=0;
+	int ce=0;
+	std::string sa ="Succès de la génération";
+	std::string sb = "Rien à déclarer";
+	General g = m_general->getGeneral();
+	std::vector<Resource>&  r= m_resource->getResources();
+	std::vector<Area>&  a= m_zone->getAreas();
+	std::vector<Stage>&  s= m_stage->getStages();
+	Generator gen(g, a, r,s, this);
+	std::string log;
+	gen.generate();
+	ce=gen.getCriticalErrorsCount ();
+	e=gen.getErrorsCount ();
+	w=gen.getWarningCount ();
+	log=gen.getLog ();
+	gtk_text_view_set_text (m_log, log.c_str());
+
+	std::cout << "W=" << w << " E =" << e << std::endl; 
+	if(w && !e && !ce)
+	{
+		sa="Avertissement(s) lors de la génération";
+		sb=tstr(w)+" avertisssments lors de la génération. Des problèmes peuvent apparaitre à l'éxecution";
+	}
+	if(e && ! ce)
+	{
+		sa="Erreur(s) lors de la génération";
+		sb=tstr(e)+" erreurs et "+tstr(w)+" avertisssments lors de la génération. Des problèmes devraient apparaitre à l'éxecution";
+	}
+	if(ce)
+	{
+		sa="Erreur(s) critique(s) lors de la génération";
+		sb=tstr(ce)+ " erreurs critiques " +tstr(e)+" erreurs et "+tstr(w)+" avertisssments lors de la génération. La génération a échouée";
+	}
+
+
+	
+
+
+	GtkWidget* dialog = NULL;
+	GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
+	dialog = gtk_message_dialog_new (GTK_WINDOW(m_window),
+                                 flags,
+                                 GTK_MESSAGE_INFO,
+                                 GTK_BUTTONS_OK,
+                                 sb.c_str());
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+	
+}
+
+void WindowAdvanced::write(const std::string& file)
+{
+	std::ofstream out(file);
+	Json::Value j = m_general->getJson();
+	//std::cout << j << std::endl;
+	j["areas"] = m_zone->getJson();
+	j["stages_list"] = m_stage->getJson();
+	j["resources"] = m_resource->getJson();
+	out << j;
+}
+
+
+Json::Value WindowAdvanced::getJson(bool genFinal)
+{
+	Json::Value j = m_general->getJson(genFinal);
+	std::cout << j << std::endl;
+	j["areas"] = m_zone->getJson();
+	j["stages_list"] = m_stage->getJson();
+	if(!genFinal) 
+		j["resources"] = m_resource->getJson();
+	else 
+		j["others"] = m_resource->getJsonOrphelin ();
+	return j;
+}
+
+
+void WindowAdvanced::on_new()
+{
+	Json::Value v(Json::arrayValue);
+	m_currentFile="";
+	m_resource->open(v);
+	m_zone->open(v);
+	m_general->open(v);
+	m_stage->open(v);
+	setModidified ();
+	m_general->on_stage_changed();
+	changeFile ("");
+}
+
+void WindowAdvanced::setModidified()
+{
+	m_resource->setModified ();
+	m_zone->setModified ();
+	m_general->setModified ();
+	m_stage->setModified ();
+}
+
+
+void WindowAdvanced::clearModidified()
+{
+	m_resource->clearModified ();
+	m_zone->clearModified ();
+	m_general->clearModified ();
+	m_stage->clearModified ();
+}
+
+
+bool WindowAdvanced::isModidified()
+{
+	bool b= false;
+	b|=m_resource->getModified ();
+	b|=m_zone->getModified ();
+	b|=m_general->getModified ();
+	b|=m_stage->getModified ();
+	return b;
+}
+
+void WindowAdvanced::on_open()
+{
+	GtkWidget *dialog;
+	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
+	gint res;
+	printf("2 M_WINDOWS: %d\n",  m_window);
+	dialog = gtk_file_chooser_dialog_new ("Ouvrir le fichier de jeu",
+		                                  GTK_WINDOW(m_window),
+		                                  action,
+		                                  _("_Annuler"),
+		                                  GTK_RESPONSE_CANCEL,
+		                                  _("_Ouvrir"),
+		                                  GTK_RESPONSE_ACCEPT,
+		                                  NULL);
+
+	res = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (res == GTK_RESPONSE_ACCEPT)
+	{
+		try{
+			std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
+			open(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
+			changeFile(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
+			clearModidified();
+		}catch(std::exception& e)
+		{
+			
+			std::cout << "Error:" << e.what() << std::endl;
+		}
+	}
+
+	gtk_widget_destroy (dialog);
+}
+
+void WindowAdvanced::on_import()
+{
+	GtkWidget *dialog;
+	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
+	gint res;
+	dialog = gtk_file_chooser_dialog_new ("Importer le fichier Merkaartor",
+		                                  GTK_WINDOW(m_window),
+		                                  action,
+		                                  _("_Annuler"),
+		                                  GTK_RESPONSE_CANCEL,
+		                                  _("_Ouvrir"),
+		                                  GTK_RESPONSE_ACCEPT,
+		                                  NULL);
+
+	res = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (res == GTK_RESPONSE_ACCEPT)
+	{
+		try{
+			std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
+			Merkaartot m(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
+			Json::Value v = m.getJson ();
+			m_zone->open(v);
+		}catch(std::exception& e)
+		{
+			
+			std::cout << "Error:" << e.what() << std::endl;
+		}
+	}
+
+	gtk_widget_destroy (dialog);
+}
+
+
+void WindowAdvanced::on_save()
+{
+	if(m_currentFile=="")
+	{
+		on_saveas();
+	}else
+	{
+		write(m_currentFile);
+		clearModidified();
+	}
+}
+
+void WindowAdvanced::on_saveas()
+{
+	GtkWidget *dialog;
+	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
+	gint res;
+
+	dialog = gtk_file_chooser_dialog_new ("Enregister le fichier de jeu",
+		                                  GTK_WINDOW(m_window),
+		                                  action,
+		                                  _("_Annuler"),
+		                                  GTK_RESPONSE_CANCEL,
+		                                  _("_Enregistrer"),
+		                                  GTK_RESPONSE_ACCEPT,
+		                                  NULL);
+	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+	res = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (res == GTK_RESPONSE_ACCEPT)
+	{
+		std::cout << gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)) << std::endl;
+		write(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
+		changeFile(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)));
+		clearModidified();
+	}
+	gtk_widget_destroy (dialog);
+}
+
+void WindowAdvanced::changeFile(const std::string& file)
+{
+	std::string s = "File: "+file;
+	m_currentFile=file; 
+	if(file=="")
+		gtk_window_set_title (GTK_WINDOW(m_window),"*New File");
+	else 
+		gtk_window_set_title (GTK_WINDOW(m_window),s.c_str());
+}
+
+
+void WindowAdvanced::open(const std::string& f)
+{
+	if(checkSaved ())
+	{
+		Json::Value v;
+		std::ifstream in(f);
+		in >> v;
+		m_resource->open(v["resources"]);
+		m_zone->open(v["areas"]);
+		m_stage->open(v["stages_list"]);
+		m_general->open(v);
+		changeFile (f);
+	}
+}
+
+
+void WindowAdvanced::on_exit()
+{
+	if(checkSaved ())
+	{
+		gtk_main_quit ();
+	}
+}

+ 62 - 0
src/window-advanced.h

@@ -0,0 +1,62 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * window-advanced.h
+ * Copyright (C) 2017 Unknown <francois@gautrais.eu>
+ *
+ * histodexc is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * histodexc is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _WINDOW_ADVANCED_H_
+#define _WINDOW_ADVANCED_H_
+#include "g-window.h"
+class GeneralTab;
+class ResourceTab;
+class ZoneTab;
+class StageTab;
+class WindowAdvanced: public GWindow 
+{
+public:
+	WindowAdvanced(const std::string& file);
+	virtual ~WindowAdvanced();
+	 
+	virtual void show();
+	virtual void write(const std::string& file);
+	virtual Json::Value getJson(bool genFinal=false);
+	virtual void on_generate();
+	virtual void on_new();
+	virtual void on_import();
+	virtual void on_open();
+	virtual void on_save();
+	virtual void on_saveas();
+	virtual void on_exit();
+	virtual void open(const std::string& f);
+	virtual void changeFile(const std::string& file);
+protected:
+	GeneralTab		*m_general;
+	ResourceTab		*m_resource;
+	ZoneTab			*m_zone;
+	StageTab		*m_stage;
+	std::string     m_currentFile;
+private:
+	virtual void init_menu();
+	virtual void setModidified();
+
+	virtual void clearModidified();
+	virtual bool isModidified();
+	virtual bool checkSaved();
+
+};
+
+#endif // _WINDOW_ADVANCED_H_
+