From 804808de30377b5d77db82a3a6828ce6004ff464 Mon Sep 17 00:00:00 2001 From: ksterker Date: Mon, 5 Oct 2009 18:58:02 +0200 Subject: [PATCH] ADDED basic questedit application template; only GUI no logic yet --- src/questedit/Makefile.am | 24 +++++++ src/questedit/gui_questedit.cc | 95 +++++++++++++++++++++++++++ src/questedit/gui_questedit.h | 55 ++++++++++++++++ src/questedit/main.cc | 71 +++++++++++++++++++++ src/questedit/qed_cmdline.cc | 113 +++++++++++++++++++++++++++++++++ src/questedit/qed_cmdline.h | 73 +++++++++++++++++++++ src/questedit/questedit.glade | 4 +- 7 files changed, 433 insertions(+), 2 deletions(-) create mode 100644 src/questedit/gui_questedit.cc create mode 100644 src/questedit/gui_questedit.h create mode 100644 src/questedit/main.cc create mode 100644 src/questedit/qed_cmdline.cc create mode 100644 src/questedit/qed_cmdline.h diff --git a/src/questedit/Makefile.am b/src/questedit/Makefile.am index 8b13789..141ea00 100644 --- a/src/questedit/Makefile.am +++ b/src/questedit/Makefile.am @@ -1 +1,25 @@ +## Process this file with automake to produce Makefile.in +EXTRA_DIST = questedit.glade + +noinst_PROGRAMS = questedit + +noinst_HEADERS = \ + gui_questedit.h \ + qed_cmdline.h + +questedit_SOURCES = \ + gui_questedit.cc \ + main.cc \ + qed_cmdline.cc + +# just for the dependency +gui_questedit.cc : questedit.glade.h + +# generate a string out of the glade XML +$(srcdir)/questedit.glade.h : questedit.glade + sed -e 's/"/\\"/g' -e 's/>$$/>"/' -e 's/^\( *\) $@ + +INCLUDES = -I@top_srcdir@/src/common -I@top_srcdir@/src +questedit_CXXFLAGS = -D_VERSION_=\"0.1\" $(GTK_CFLAGS) $(PY_CFLAGS) $(ADONTHELL_CFLAGS) ${IGE_MAC_CFLAGS} +questedit_LDADD = ../common/libcommon.a $(GTK_LIBS) $(ADONTHELL_LIBS) ${IGE_MAC_LIBS} diff --git a/src/questedit/gui_questedit.cc b/src/questedit/gui_questedit.cc new file mode 100644 index 0000000..e4b6008 --- /dev/null +++ b/src/questedit/gui_questedit.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2009 Kai Sterker + Part of the Adonthell Project http://adonthell.linuxgames.com + + Adonthell 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 2 of the License, or + (at your option) any later version. + + Adonthell 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 Adonthell; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file questedit/gui_questedit.cc + * + * @author Kai Sterker + * @brief The quest editor main window. + */ + +#include + +#ifdef MAC_INTEGRATION +#include +#endif + +#include "gui_questedit.h" + +// Ui definition +static char questedit_ui[] = +#include "questedit.glade.h" +; + +// Main Window: on_widget_destroy App +static void on_widget_destroy (GtkWidget * widget, gpointer data) +{ + gtk_main_quit (); + gtk_widget_destroy (widget); +} + +// ctor +GuiQuestedit::GuiQuestedit () +{ + GError *err = NULL; + GObject *widget; + + Ui = gtk_builder_new(); + if (!gtk_builder_add_from_string(Ui, questedit_ui, -1, &err)) + { + g_message ("building questedit main window failed: %s", err->message); + g_error_free (err); + return; + } + + // get reference to dialog window + Window = GTK_WIDGET (gtk_builder_get_object (Ui, "main_window")); + g_signal_connect (Window, "delete-event", G_CALLBACK (on_widget_destroy), (gpointer) NULL); + gtk_widget_show_all (Window); + +#ifdef MAC_INTEGRATION + GtkWidget* menu = GTK_WIDGET (gtk_builder_get_object (Ui, "menu_bar")); + GtkWidget* separator = GTK_WIDGET (gtk_builder_get_object (Ui, "item_quit_separator")); + GtkWidget* quit_item = GTK_WIDGET (gtk_builder_get_object (Ui, "item_quit")); + + // Mac OSX-Style menu + gtk_widget_hide (separator); + gtk_widget_hide (menu); + + ige_mac_menu_set_menu_bar (GTK_MENU_SHELL (menu)); + ige_mac_menu_set_quit_menu_item (GTK_MENU_ITEM (quit_item)); + + // IgeMacMenuGroup *group = ige_mac_menu_add_app_menu_group (); + // ige_mac_menu_add_app_menu_item (group, GTK_MENU_ITEM (quit_item), NULL); +#endif + + /* + // connect menu signals + widget = gtk_builder_get_object (Ui, "item_new"); + g_signal_connect (widget, "activate", G_CALLBACK (on_file_new), (gpointer) this); + widget = gtk_builder_get_object (Ui, "item_load"); + g_signal_connect (widget, "activate", G_CALLBACK (on_file_load), (gpointer) this); + widget = gtk_builder_get_object (Ui, "item_save"); + g_signal_connect (widget, "activate", G_CALLBACK (on_file_save_activate), (gpointer) this); + widget = gtk_builder_get_object (Ui, "item_save_as"); + g_signal_connect (widget, "activate", G_CALLBACK (on_file_save_as_activate), (gpointer) this); + widget = gtk_builder_get_object (Ui, "item_quit"); + g_signal_connect (widget, "activate", G_CALLBACK (on_widget_destroy), (gpointer) NULL); + */ +} diff --git a/src/questedit/gui_questedit.h b/src/questedit/gui_questedit.h new file mode 100644 index 0000000..e39d765 --- /dev/null +++ b/src/questedit/gui_questedit.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2009 Kai Sterker + Part of the Adonthell Project http://adonthell.linuxgames.com + + Adonthell 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 2 of the License, or + (at your option) any later version. + + Adonthell 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 Adonthell; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file questedit/gui_questedit.h + * + * @author Kai Sterker + * @brief The modeller main window. + */ + + +#ifndef GUI_QUESTEDIT_H +#define GUI_QUESTEDIT_H + +/** + * The application main window. + */ +class GuiQuestedit +{ +public: + /** + * Create new instance of the GUI + */ + GuiQuestedit(); + + /** + * Get the application main window. + * @return the main window. + */ + GtkWidget *getWindow () const { return Window; } + +private: + /// the main window + GtkWidget *Window; + /// the user interface + GtkBuilder *Ui; +}; + +#endif diff --git a/src/questedit/main.cc b/src/questedit/main.cc new file mode 100644 index 0000000..7506226 --- /dev/null +++ b/src/questedit/main.cc @@ -0,0 +1,71 @@ +/* + Copyright (C) 2009 Kai Sterker + Part of the Adonthell Project http://adonthell.linuxgames.com + + Adonthell 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 2 of the License, or + (at your option) any later version. + + Adonthell 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 Adonthell; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file questedit/main.cc + * + * @author Kai Sterker + * @brief The main function of modeller. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "qed_cmdline.h" +#include "gui_questedit.h" + +#define main main + +int main (int argc, char *argv[]) +{ + // Init GTK+ + gtk_init (&argc, &argv); + + // parse command line + if (!QedCmdline::parse (argc, argv)) + return 1; + + // init game directory + base::init (QedCmdline::project, QedCmdline::datadir); + + // create the User Interface + GuiQuestedit questedit; + + // are there any sources given? + if (QedCmdline::sources >= argc) + { + // Nope -> a new quest tree is created + } + else + { + // Yep -> load quest data + // questedit.loadData (argv[QedCmdline::sources]); + } + + // start the main loop + gtk_main (); + + // good bye + return 0; +} diff --git a/src/questedit/qed_cmdline.cc b/src/questedit/qed_cmdline.cc new file mode 100644 index 0000000..8669213 --- /dev/null +++ b/src/questedit/qed_cmdline.cc @@ -0,0 +1,113 @@ +/* + Copyright (C) 2009 Kai Sterker + Part of the Adonthell Project http://adonthell.linuxgames.com + + Adonthell 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 2 of the License, or + (at your option) any later version. + + Adonthell 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 Adonthell; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file questedit/qed_cmdline.cc + * + * @author Kai Sterker + * @brief Methods to parse the questedit command line. + */ + +#include +#include +#include +#include "qed_cmdline.h" + +// the directory to look for project files +std::string QedCmdline::datadir = DATA_DIR"/games"; + +// the default project +std::string QedCmdline::project = ""; + +// index of the first dialgoue source in argv[] +int QedCmdline::sources; + +// examine the parameters passed to dlgedit +bool QedCmdline::parse (int argc, char* argv[]) +{ + int c; + + // Check for options + while ((c = getopt (argc, argv, "dhvg:p:")) != -1) + { + switch (c) + { + case 'd': + { + std::cout << datadir << std::endl; + return false; + } + + case 'v': + { + std::cout << _VERSION_ << std::endl; + return false; + } + + case 'p': + { + project = optarg; + break; + } + + case 'g': + { + datadir = optarg; + + if (datadir[datadir.size () - 1] == '/') + datadir.erase (datadir.size () - 1); + + // Check whether the requested game directory exists + DIR * mydir = opendir (datadir.c_str ()); + + if (!mydir) + { + std::cerr << "No such directory " << datadir << "!" << std::endl; + return false; + } + closedir (mydir); + + break; + } + + case '?': + case 'h': + { + help (argv[0]); + return false; + } + } + } + + sources = optind; + return true; +} + +// prints the help message +void QedCmdline::help (const std::string &program) +{ + std::cout << "Usage: " << program << " [OPTIONS] [QUEST DATA]" << std::endl; + std::cout << std::endl; + std::cout << "Where [OPTIONS] can be:\n"; + std::cout << "-h print this help message and exit" << std::endl; + std::cout << "-d print the project directory and exit" << std::endl; + std::cout << "-v print version and exit" << std::endl; + std::cout << "-g dir specify a custom project directory" << std::endl; + std::cout << "-p project specify a default project" << std::endl; +} diff --git a/src/questedit/qed_cmdline.h b/src/questedit/qed_cmdline.h new file mode 100644 index 0000000..944830c --- /dev/null +++ b/src/questedit/qed_cmdline.h @@ -0,0 +1,73 @@ +/* + Copyright (C) 2009 Kai Sterker + Part of the Adonthell Project http://adonthell.linuxgames.com + + Adonthell 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 2 of the License, or + (at your option) any later version. + + Adonthell 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 Adonthell; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file questedit/qed_cmdline.h + * + * @author Kai Sterker + * @brief Methods to parse the questedit commandline. + */ + +#ifndef QED_CMDLINE_H +#define QED_CMDLINE_H + +#include + +/** + * Apart from the above, QedCmdline stores the various options + * that can be specified on the command line + */ +class QedCmdline +{ +public: + /** + * The method doing all the work. To be called right after + * questedit is launched. + * @param argc argument count + * @param argv argument vector + * @return false indicates that the program shall quit + */ + static bool parse (int argc, char* argv[]); + + /** + * The directory where questedit searches for projects. + */ + static std::string datadir; + + /** + * The project. This is the directory that contains the mapobjects + * that can be placed on the map. + */ + static std::string project; + + /** + * The index in the argument vector pointing to the first non-option. + * With a bit of luck, this is a map file to load on startup. + */ + static int sources; + +private: + /** + * Print help message. + * @param program the program name. + */ + static void help (const std::string &program); +}; + +#endif // QED_CMDLINE_H diff --git a/src/questedit/questedit.glade b/src/questedit/questedit.glade index 19efba8..32a0c4e 100644 --- a/src/questedit/questedit.glade +++ b/src/questedit/questedit.glade @@ -13,7 +13,7 @@ - Adonthell Modeller + Adonthell Questedit 800 600 @@ -26,7 +26,7 @@ True - _Datei + _File True