From 3c19422ee9cc38e710bd2f262b2b91a3d6e04ab6 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 6 Dec 2009 00:36:19 +0000 Subject: [PATCH] Created open game functionality in the player. Fix #37. Made some new menus in the player. git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@203 ddfedd41-794f-dd11-ae45-00112f111e67 --- libchimara/chimara-glk.c | 4 ++ libchimara/chimara-glk.h | 7 ++- player/callbacks.c | 125 ++++++++++++++++++++++++++++++++++++--- player/chimara.menus | 24 ++++++-- player/chimara.ui | 84 ++++++++++++++++++++++++-- player/main.c | 44 +++++++------- 6 files changed, 249 insertions(+), 39 deletions(-) diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index 93f95c7..a00ae65 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -1161,6 +1161,10 @@ chimara_glk_run(ChimaraGlk *glk, const gchar *plugin, int argc, char *argv[], GE { g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE); g_return_val_if_fail(plugin, FALSE); + if(chimara_glk_get_running(glk)) { + g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_ALREADY_RUNNING, _("There was already a plugin running.")); + return FALSE; + } ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk); struct StartupData *startup = g_slice_new0(struct StartupData); diff --git a/libchimara/chimara-glk.h b/libchimara/chimara-glk.h index dfa669e..45b3b6a 100644 --- a/libchimara/chimara-glk.h +++ b/libchimara/chimara-glk.h @@ -60,12 +60,17 @@ typedef struct _ChimaraGlkClass { * An appropriate interpreter plugin for the autodetected * game file type could not be found. * + * + * CHIMARA_PLUGIN_ALREADY_RUNNING + * A plugin was opened while there was already another plugin + * running in the widget. * */ typedef enum _ChimaraError { CHIMARA_LOAD_MODULE_ERROR, CHIMARA_NO_GLK_MAIN, - CHIMARA_PLUGIN_NOT_FOUND + CHIMARA_PLUGIN_NOT_FOUND, + CHIMARA_PLUGIN_ALREADY_RUNNING } ChimaraError; /** diff --git a/player/callbacks.c b/player/callbacks.c index 479a5ce..a4c81a1 100644 --- a/player/callbacks.c +++ b/player/callbacks.c @@ -30,23 +30,134 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include #include +#include #include "error.h" -void on_save(GtkAction *action, ChimaraGlk *glk) { +void +on_open_activate(GtkAction *action, ChimaraGlk *glk) +{ + GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk))); + + if(chimara_glk_get_running(glk)) { + GtkWidget *dialog = gtk_message_dialog_new(window, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CANCEL, + _("Are you sure you want to open a new game?")); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), + _("If you open a new game, you will quit the one you are currently playing.")); + gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK); + gint response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + if(response != GTK_RESPONSE_OK) + return; + + chimara_glk_stop(glk); + chimara_glk_wait(glk); + } + + GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"), + window, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + GError *error = NULL; + gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) + error_dialog(window, error, _("Could not open game file.")); + g_free(filename); + } + gtk_widget_destroy(dialog); +} + +void +on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk) +{ + +} + +void +on_stop_activate(GtkAction *action, ChimaraGlk *glk) +{ + chimara_glk_stop(glk); +} + +void +on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk) +{ + gtk_main_quit(); +} + +void +on_cut_activate(GtkAction *action, ChimaraGlk *glk) +{ + +} + +void +on_copy_activate(GtkAction *action, ChimaraGlk *glk) +{ + +} + +void +on_paste_activate(GtkAction *action, ChimaraGlk *glk) +{ + +} + +void +on_preferences_activate(GtkAction *action, ChimaraGlk *glk) +{ + +} + +void +on_undo_activate(GtkAction *action, ChimaraGlk *glk) +{ + chimara_glk_feed_line_input(glk, "undo"); +} + +void +on_save_activate(GtkAction *action, ChimaraGlk *glk) +{ chimara_glk_feed_line_input(glk, "save"); } -void on_restore(GtkAction *action, ChimaraGlk *glk) { +void +on_restore_activate(GtkAction *action, ChimaraGlk *glk) +{ chimara_glk_feed_line_input(glk, "restore"); } -gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk) { - gtk_main_quit(); - return TRUE; +void +on_restart_activate(GtkAction *action, ChimaraGlk *glk) +{ + chimara_glk_feed_line_input(glk, "restart"); +} + +void +on_quit_activate(GtkAction *action, ChimaraGlk *glk) +{ + chimara_glk_feed_line_input(glk, "quit"); } -void on_quit(GtkAction *action, ChimaraGlk *glk) { +void +on_about_activate(GtkAction *action, ChimaraGlk *glk) +{ + +} + +gboolean +on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk) +{ gtk_main_quit(); + return TRUE; } diff --git a/player/chimara.menus b/player/chimara.menus index e7ead1e..3127088 100644 --- a/player/chimara.menus +++ b/player/chimara.menus @@ -3,17 +3,33 @@ - - + + + + + + + + + + + + + + + + + + + + - - diff --git a/player/chimara.ui b/player/chimara.ui index 2519722..ce47531 100644 --- a/player/chimara.ui +++ b/player/chimara.ui @@ -4,7 +4,7 @@ Chimara - 800 + 600 800 @@ -26,24 +26,96 @@ _Open Quit the current game and load a new one gtk-media-play + _Restore... _Restore Restore a previously saved game gtk-open - + _Save Save the game gtk-save - + + + + _Quit Chimara + Leave the program + gtk-quit + + + + _Command + + + _Edit + + + _Stop Game + _Stop + Immediately stop the running game + gtk-stop + + + + Open _Recent + 10 + mru + + + + _Undo + Attempt to undo the last move (the game may not allow this) + gtk-undo + + + + Res_tart + Tell the game to restart + gtk-media-rewind + _Quit - Exit Chimara - gtk-quit - + Try to quit the game + gtk-media-stop + + + + Cu_t + Cut the selection + gtk-cut + + + + _Copy + Copy the selection + gtk-copy + + + + _Paste + Paste the clipboard + gtk-paste + + + + P_references + Configure the application + gtk-preferences + + + + _Help + + + _About... + _About + About this application + gtk-about + diff --git a/player/main.c b/player/main.c index 089fc24..9827d31 100644 --- a/player/main.c +++ b/player/main.c @@ -80,10 +80,23 @@ create_window(void) action group. */ const gchar *actions[] = { "game", "", - "open", "F7", - "restore", "O", - "save", NULL, /* NULL means use stock accelerator */ - "quit", NULL, + "open", "O", + "recent", "", + "stop", "", + "quit_chimara", NULL, /* NULL means use stock accelerator */ + "command", "", + "undo", "Z", + "save", NULL, + "restore", "R", + "restart", "", + "quit", "", + "edit", "", + "cut", NULL, + "copy", NULL, + "paste", NULL, + "preferences", "", + "help", "", + "about", "", NULL }; const gchar **ptr; @@ -97,15 +110,7 @@ create_window(void) } glk = chimara_if_new(); - //chimara_if_set_preferred_interpreter( CHIMARA_IF(glk), CHIMARA_IF_FORMAT_Z8, CHIMARA_IF_INTERPRETER_NITFOL); - - g_object_set(glk, - "border-width", 6, - "spacing", 6, - "ignore-errors", TRUE, - NULL); - chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12"); - chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12"); + g_object_set(glk, "ignore-errors", TRUE, NULL); GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") ); if(vbox == NULL) @@ -147,14 +152,11 @@ main(int argc, char *argv[]) g_object_unref( G_OBJECT(builder) ); g_object_unref( G_OBJECT(uimanager) ); - if(argc < 2) { - error_dialog(GTK_WINDOW(window), NULL, "Must provide a game file"); - return 1; - } - - if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) { - error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: "); - return 1; + if(argc >= 2) { + if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) { + error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: "); + return 1; + } } gdk_threads_enter(); -- 2.30.2