summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-09-23 03:47:08 +0200
committeralex <alex@ASUS>2018-09-23 03:47:08 +0200
commit380395d7f5cb48b803c4aeda6fec84f12d0bf9c5 (patch)
treed28adc7cb0454ec27c48902c57b607a5b1811d2c
parent214e9089c55184585b748ec292c7ef973136a8bf (diff)
Add save option in GUI
-rw-r--r--modules/menu/src/menu_gui.c14
-rw-r--r--modules/player/obj/Makefile3
-rw-r--r--modules/player/src/player_gui.c276
3 files changed, 211 insertions, 82 deletions
diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c
index 4d08711..806ab87 100644
--- a/modules/menu/src/menu_gui.c
+++ b/modules/menu/src/menu_gui.c
@@ -221,7 +221,7 @@ void menu_gui (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Clear window */
@@ -256,8 +256,6 @@ static gboolean delete_window (GtkWidget *widget,
GdkEvent *event,
void *data)
{
- g_print ("delete event occurred\n");
-
gtk_main_quit();
/* false: send destroy signal */
@@ -267,8 +265,6 @@ static gboolean delete_window (GtkWidget *widget,
static void destroy_window (GtkWidget *widget,
void *data)
{
- g_print ("destroy event occurred\n");
-
exit(EXIT_SUCCESS);
}
@@ -540,8 +536,8 @@ static void menu_gui_continue (void)
button[1].num = 1;
button[2].num = 2;
button[3].num = 3;
- button[4].num = 5;
- button[5].num = 6;
+ button[4].num = 4;
+ button[5].num = 5;
button[0].num = 0;
button[1].sw = &sw;
button[2].sw = &sw;
@@ -568,9 +564,9 @@ static void menu_gui_continue (void)
button[3].ptr = gtk_button_new_with_mnemonic(button[3].text);
entry_fname[0].lbl.ptr = gtk_label_new(entry_fname[0].lbl.text);
entry_fname[0].ptr = gtk_entry_new();
- button[4].ptr = gtk_button_new_with_mnemonic(button[5].text);
+ button[4].ptr = gtk_button_new_with_mnemonic(button[4].text);
separator[2] = gtk_hseparator_new();
- button[5].ptr = gtk_button_new_with_mnemonic(button[6].text);
+ button[5].ptr = gtk_button_new_with_mnemonic(button[5].text);
separator[3] = gtk_hseparator_new();
button[0].ptr = gtk_button_new_with_mnemonic(button[0].text);
diff --git a/modules/player/obj/Makefile b/modules/player/obj/Makefile
index 70bce1f..a6f5fc0 100644
--- a/modules/player/obj/Makefile
+++ b/modules/player/obj/Makefile
@@ -44,14 +44,17 @@ PLAYTUI_INC_DIRS = -I $(INC_DIR) \
-I $(LIBALX_INC_DIR) \
-I $(GAME_INC_DIR)
+PLAYGUI_INC_LIBALX = alx_input.h
PLAYGUI_INC_GAME = game_iface.h
PLAYGUI_INC_MENU = menu_gui.h
PLAYGUI_INC = player_gui.h player_iface.h
PLAYGUI_DEPS = $(SRC_DIR)/player_gui.c \
$(patsubst %,$(INC_DIR)/%,$(PLAYGUI_INC)) \
+ $(patsubst %,$(LIBALX_INC_DIR)/%,$(PLAYGUI_INC_LIBALX)) \
$(patsubst %,$(GAME_INC_DIR)/%,$(PLAYGUI_INC_GAME)) \
$(patsubst %,$(MENU_INC_DIR)/%,$(PLAYGUI_INC_MENU))
PLAYGUI_INC_DIRS = -I $(INC_DIR) \
+ -I $(LIBALX_INC_DIR) \
-I $(GAME_INC_DIR) \
-I $(MENU_INC_DIR)
diff --git a/modules/player/src/player_gui.c b/modules/player/src/player_gui.c
index 6521823..d7a8446 100644
--- a/modules/player/src/player_gui.c
+++ b/modules/player/src/player_gui.c
@@ -20,6 +20,9 @@
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
+ /* alx_sscan_fname() */
+ #include "alx_input.h"
+
/* struct Game_Iface_Out */
#include "game_iface.h"
/* window_gui */
@@ -59,53 +62,67 @@ enum TButtons {
/******************************************************************************
******* structs **************************************************************
******************************************************************************/
+struct Label_Data {
+ GtkWidget *ptr;
+ char text [LINE_SIZE];
+};
+
struct Field_Data {
- GtkWidget *ptr;
- char ch;
- int r;
- int c;
- int *row;
- int *col;
- int *act;
+ GtkWidget *ptr;
+ char ch;
+ int r;
+ int c;
+ int *row;
+ int *col;
+ int *act;
};
struct Button_Data {
- GtkWidget *ptr;
- char text [LINE_SIZE];
- int val;
- int *act;
+ GtkWidget *ptr;
+ char text [LINE_SIZE];
+ int val;
+ int *act;
};
struct TButton_Data {
- GtkWidget *ptr;
- char text [LINE_SIZE];
- char text2 [LINE_SIZE];
- int val;
- int val2;
- int *act;
+ GtkWidget *ptr;
+ char text [LINE_SIZE];
+ char text2 [LINE_SIZE];
+ int val;
+ int val2;
+ int *act;
};
-struct PBar_Data {
- GtkWidget *ptr;
- double frac;
- char text [LINE_SIZE];
+struct Entry_fname_Data {
+ GtkWidget *ptr;
+ struct Label_Data lbl;
+ const char *fpath;
+ char *fname;
};
-struct EBox_Data {
- GtkWidget *ptr;
- int val;
- int *act;
+struct Entry_str_Data {
+ GtkWidget *ptr;
+ struct Label_Data lbl;
+ char *str;
+ int strsize;
};
-struct Label_Data {
- GtkWidget *ptr;
- char text [LINE_SIZE];
+struct PBar_Data {
+ GtkWidget *ptr;
+ double frac;
+ char text [LINE_SIZE];
+};
+
+struct EBox_Data {
+ GtkWidget *ptr;
+ int val;
+ int *act;
};
struct Timeout_Data {
- int id;
- int val;
- int *act;
+ int id;
+ int val;
+ int *act;
};
@@ -117,6 +134,8 @@ static GtkWidget *box_help;
static GtkWidget *box_help_in;
static struct Button_Data button [BTN_QTTY];
static struct TButton_Data tbutton [TBTN_QTTY];
+static struct Entry_str_Data entry_name;
+static struct Entry_fname_Data entry_fname;
static GtkWidget *box_board;
static GtkWidget *box_board_in;
static struct PBar_Data pbar_board_tit;
@@ -167,17 +186,21 @@ static void show_help_cheat (void);
static void show_help_safe (void);
static void show_help_gameover (void);
/* Input */
-static gboolean callback_field (GtkWidget *widget,
- GdkEventButton *event,
- void *data);
-static gboolean callback_ebox (GtkWidget *widget,
- GdkEventButton *event,
- void *data);
-static void callback_button (GtkWidget *widget,
- void *data);
-static gboolean callback_tbutton (GtkWidget *widget,
- void *data);
-static gboolean callback_timeout (void *data);
+static gboolean callback_field (GtkWidget *widget,
+ GdkEventButton *event,
+ void *data);
+static gboolean callback_ebox (GtkWidget *widget,
+ GdkEventButton *event,
+ void *data);
+static void callback_button (GtkWidget *widget,
+ void *data);
+static gboolean callback_tbutton (GtkWidget *widget,
+ void *data);
+static void callback_entry_fname (GtkWidget *widget,
+ void *data);
+static void callback_entry_str (GtkWidget *widget,
+ void *data);
+static gboolean callback_timeout (void *data);
/******************************************************************************
@@ -261,30 +284,56 @@ int player_gui (const struct Game_Iface_Out *board,
void player_gui_save_name (const char *filepath, char *filename, int destsize)
{
-#if 0
- /* Input box */
- int w;
- int r;
- w = 60;
- r = 10;
-
- /* Request name */
- alx_w_getfname(filepath, filename, false, w, r, "File name:", NULL);
-#endif
+ entry_fname.fpath = filepath;
+ entry_fname.fname = filename;
+
+ gtk_widget_hide(button[BTN_CH_OFF].ptr);
+ gtk_widget_hide(button[BTN_CH_1].ptr);
+ gtk_widget_hide(button[BTN_CH_2].ptr);
+ gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
+ gtk_widget_hide(button[BTN_SAVE].ptr);
+ gtk_widget_show(entry_fname.lbl.ptr);
+ gtk_widget_show(entry_fname.ptr);
+ gtk_widget_hide(button[BTN_QUIT].ptr);
+
+ gtk_widget_hide(box_board);
+
+ gtk_main();
+
+ gtk_widget_show(box_board);
+
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+
+ /* Update last_help */
+ last_help = GAME_IFACE_STATE_FOO;
}
void player_gui_score_name (char *player_name, int destsize)
{
-#if 0
- /* Input box */
- int w;
- int r;
- w = 60;
- r = 10;
-
- /* Request name */
- alx_w_getstr(player_name, w, r, "Your name:", NULL);
-#endif
+ entry_name.str = player_name;
+ entry_name.strsize = destsize;
+
+ gtk_widget_hide(button[BTN_CH_OFF].ptr);
+ gtk_widget_hide(button[BTN_CH_1].ptr);
+ gtk_widget_hide(button[BTN_CH_2].ptr);
+ gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
+ gtk_widget_hide(button[BTN_SAVE].ptr);
+ gtk_widget_show(entry_name.lbl.ptr);
+ gtk_widget_show(entry_name.ptr);
+ gtk_widget_hide(button[BTN_QUIT].ptr);
+
+ gtk_widget_hide(box_board);
+
+ gtk_main();
+
+ gtk_widget_show(box_board);
+
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
+
+ /* Update last_help */
+ last_help = GAME_IFACE_STATE_FOO;
}
void player_gui_cleanup (void)
@@ -554,6 +603,8 @@ static void help_init (int *action)
snprintf(tbutton[TBTN_PAUSE].text, LINE_SIZE, "_Pause");
snprintf(tbutton[TBTN_PAUSE].text2, LINE_SIZE, "[_P] Continue");
snprintf(button[BTN_SAVE].text, LINE_SIZE, "_Save");
+ snprintf(entry_fname.lbl.text, LINE_SIZE, "File name:");
+ snprintf(entry_name.lbl.text, LINE_SIZE, "Your name:");
snprintf(button[BTN_QUIT].text, LINE_SIZE, "_Quit");
/* Data */
@@ -581,6 +632,10 @@ static void help_init (int *action)
button[BTN_CH_2].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_2].text);
tbutton[TBTN_PAUSE].ptr = gtk_toggle_button_new_with_mnemonic(tbutton[TBTN_PAUSE].text);
button[BTN_SAVE].ptr = gtk_button_new_with_mnemonic(button[BTN_SAVE].text);
+ entry_fname.lbl.ptr = gtk_label_new(entry_fname.lbl.text);
+ entry_fname.ptr = gtk_entry_new();
+ entry_name.lbl.ptr = gtk_label_new(entry_name.lbl.text);
+ entry_name.ptr = gtk_entry_new();
button[BTN_QUIT].ptr = gtk_button_new_with_mnemonic(button[BTN_QUIT].text);
/* Toggle buttons */
@@ -597,6 +652,10 @@ static void help_init (int *action)
G_CALLBACK(callback_tbutton), (void *)&tbutton[TBTN_PAUSE]);
g_signal_connect(button[BTN_SAVE].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[BTN_SAVE]);
+ g_signal_connect(entry_fname.ptr, "activate",
+ G_CALLBACK(callback_entry_fname), (void *)&entry_fname);
+ g_signal_connect(entry_name.ptr, "activate",
+ G_CALLBACK(callback_entry_str), (void *)&entry_name);
g_signal_connect(button[BTN_QUIT].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[BTN_QUIT]);
@@ -606,6 +665,10 @@ static void help_init (int *action)
gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_CH_2].ptr, false, false, 0);
gtk_box_pack_start(GTK_BOX(box_help_in), tbutton[TBTN_PAUSE].ptr, false, false, 0);
gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_SAVE].ptr, false, false, 0);
+ gtk_box_pack_start(GTK_BOX(box_help_in), entry_fname.lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box_help_in), entry_fname.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box_help_in), entry_name.lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box_help_in), entry_name.ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_QUIT].ptr, false, false, 0);
}
@@ -655,6 +718,10 @@ static void show_help_start (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
gtk_widget_hide(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
/* Update last_help */
@@ -673,6 +740,10 @@ static void show_help_play (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_show(tbutton[TBTN_PAUSE].ptr);
gtk_widget_show(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
@@ -684,6 +755,10 @@ static void show_help_pause (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_show(tbutton[TBTN_PAUSE].ptr);
gtk_widget_show(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
@@ -695,6 +770,10 @@ static void show_help_xyzzy (void)
gtk_widget_show(button[BTN_CH_2].ptr);
gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
gtk_widget_show(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
@@ -706,6 +785,10 @@ static void show_help_cheat (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
gtk_widget_show(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
@@ -717,6 +800,10 @@ static void show_help_safe (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
gtk_widget_show(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
@@ -728,15 +815,19 @@ static void show_help_gameover (void)
gtk_widget_hide(button[BTN_CH_2].ptr);
gtk_widget_hide(tbutton[TBTN_PAUSE].ptr);
gtk_widget_hide(button[BTN_SAVE].ptr);
+ gtk_widget_hide(entry_fname.lbl.ptr);
+ gtk_widget_hide(entry_fname.ptr);
+ gtk_widget_hide(entry_name.lbl.ptr);
+ gtk_widget_hide(entry_name.ptr);
gtk_widget_show(button[BTN_QUIT].ptr);
}
/* * * * * * * * * *
* * * Input * * * * * * *
* * * * * * * * * */
-static gboolean callback_field (GtkWidget *widget,
- GdkEventButton *event,
- void *data)
+static gboolean callback_field (GtkWidget *widget,
+ GdkEventButton *event,
+ void *data)
{
if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
g_source_remove(timeout.id);
@@ -769,9 +860,9 @@ static gboolean callback_field (GtkWidget *widget,
return false;
}
-static gboolean callback_ebox (GtkWidget *widget,
- GdkEventButton *event,
- void *data)
+static gboolean callback_ebox (GtkWidget *widget,
+ GdkEventButton *event,
+ void *data)
{
if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
g_source_remove(timeout.id);
@@ -798,8 +889,8 @@ static gboolean callback_ebox (GtkWidget *widget,
}
-static void callback_button (GtkWidget *widget,
- void *data)
+static void callback_button (GtkWidget *widget,
+ void *data)
{
if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
g_source_remove(timeout.id);
@@ -814,8 +905,8 @@ static void callback_button (GtkWidget *widget,
}
-static gboolean callback_tbutton (GtkWidget *widget,
- void *data)
+static gboolean callback_tbutton (GtkWidget *widget,
+ void *data)
{
if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
g_source_remove(timeout.id);
@@ -837,7 +928,46 @@ static gboolean callback_tbutton (GtkWidget *widget,
gtk_main_quit();
}
-static gboolean callback_timeout (void *data)
+static void callback_entry_fname (GtkWidget *widget,
+ void *data)
+{
+ struct Entry_fname_Data *entry;
+ const char *str;
+ int err;
+ char buff [LINE_SIZE];
+
+ entry = ((struct Entry_fname_Data *)data);
+
+ str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
+ err = alx_sscan_fname(entry->fpath, entry->fname, false, str);
+
+ if (err) {
+ snprintf(buff, LINE_SIZE, "Error %i", err);
+ gtk_entry_set_text(GTK_ENTRY(entry->ptr), buff);
+ gtk_editable_select_region(GTK_EDITABLE(entry->ptr),
+ 0, GTK_ENTRY(entry->ptr)->text_length);
+ }
+
+ gtk_main_quit();
+}
+
+static void callback_entry_str (GtkWidget *widget,
+ void *data)
+{
+ struct Entry_str_Data *entry;
+ const char *str;
+ int err;
+ char buff [LINE_SIZE];
+
+ entry = ((struct Entry_str_Data *)data);
+
+ str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
+ snprintf(entry->str, entry->strsize, "%s", str);
+
+ gtk_main_quit();
+}
+
+static gboolean callback_timeout (void *data)
{
struct Timeout_Data *tout;
tout = ((struct Timeout_Data *)data);