summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <Colomar.6.4.3@GMail.com>2018-09-23 03:50:41 +0200
committerGitHub <noreply@github.com>2018-09-23 03:50:41 +0200
commit00fbed24f98e19d4c65977649f02c5062f86927c (patch)
treed28adc7cb0454ec27c48902c57b607a5b1811d2c
parent8ef916c58d08c9d2088b796ce6b8e34b1a20fd13 (diff)
parent380395d7f5cb48b803c4aeda6fec84f12d0bf9c5 (diff)
Merge pull request #65 from AlejandroColomar/4-a4
V 4~a4
-rw-r--r--Makefile14
-rw-r--r--bin/Makefile8
-rw-r--r--libalx/inc/alx_input.h (renamed from libalx/inc/alx_getnum.h)24
-rw-r--r--libalx/obj/Makefile48
-rw-r--r--libalx/src/alx_input.c (renamed from libalx/src/alx_getnum.c)124
-rw-r--r--libalx/src/alx_ncur.c81
-rw-r--r--modules/menu/obj/Makefile4
-rw-r--r--modules/menu/src/menu_clui.c2
-rw-r--r--modules/menu/src/menu_gui.c305
-rw-r--r--modules/player/obj/Makefile3
-rw-r--r--modules/player/src/player_gui.c276
-rw-r--r--modules/player/src/player_iface.c31
12 files changed, 615 insertions, 305 deletions
diff --git a/Makefile b/Makefile
index 0de5249..947b08b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
#!/usr/bin/make -f
-VERSION = 4
-PATCHLEVEL = ~a3
-SUBLEVEL =
-EXTRAVERSION =
-NAME = graphic
+VERSION = 4
+PATCHLEVEL = ~a4
+SUBLEVEL =
+EXTRAVERSION =
+NAME = graphic
export VERSION
export PATCHLEVEL
@@ -269,7 +269,3 @@ help:
################################################################################
######## End of file ###########################################################
################################################################################
-######## End of file ###########################################################
-################################################################################
-######## End of file ###########################################################
-################################################################################
diff --git a/bin/Makefile b/bin/Makefile
index 3a6448c..6211f13 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -32,7 +32,7 @@ _ALL = mine-sweeper mine-sweeper.exe
ALL = $(BIN_NAME)
-MAIN_OBJ_LIBALX = alx_file.o alx_getnum.o alx_ncur.o alx_seed.o
+MAIN_OBJ_LIBALX = alx_lib.o
MAIN_OBJ_ABOUT = about_mod.o
MAIN_OBJ_CTRL = ctrl_mod.o
MAIN_OBJ_GAME = game_mod.o
@@ -60,7 +60,7 @@ all: $(ALL)
$(BIN_NAME): $(MAIN_OBJS)
$(Q)$(CC) $^ -o $@ $(LIBS)
- @echo "\tLD $@"
+ @echo "\tBIN $@"
@echo ""
@@ -71,7 +71,3 @@ clean:
################################################################################
######## End of file ###########################################################
################################################################################
-######## End of file ###########################################################
-################################################################################
-######## End of file ###########################################################
-################################################################################
diff --git a/libalx/inc/alx_getnum.h b/libalx/inc/alx_input.h
index 17404e0..0fef5d0 100644
--- a/libalx/inc/alx_getnum.h
+++ b/libalx/inc/alx_input.h
@@ -6,8 +6,8 @@
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# ifndef ALX_GETNUM_H
- # define ALX_GETNUM_H
+# ifndef ALX_INPUT_H
+ # define ALX_INPUT_H
/******************************************************************************
@@ -15,12 +15,30 @@
******************************************************************************/
#include <math.h>
#include <stdarg.h>
+ #include <stdbool.h>
#include <stdint.h>
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
+ int alx_sscan_dbl (double *dest,
+ double m,
+ double def,
+ double M,
+ const char *str);
+
+ int alx_sscan_int (int64_t *dest,
+ double m,
+ int64_t def,
+ double M,
+ const char *str);
+
+ int alx_sscan_fname (const char *fpath,
+ char *fname,
+ bool exist,
+ const char *str);
+
double alx_getdbl (double m,
double def,
double M,
@@ -39,7 +57,7 @@
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# endif /* alx_getnum.h */
+# endif /* alx_input.h */
/******************************************************************************
diff --git a/libalx/obj/Makefile b/libalx/obj/Makefile
index 717c7af..84eae78 100644
--- a/libalx/obj/Makefile
+++ b/libalx/obj/Makefile
@@ -10,36 +10,36 @@ SRC_DIR = $(LIBALX_DIR)/src/
# dependencies
-_ALL = alx_cmp.o alx_file.o alx_getnum.o alx_mask.o alx_math.o alx_ncur.o alx_seed.o
+_ALL = alx_cmp.o alx_file.o alx_input.o alx_mask.o alx_math.o alx_ncur.o alx_seed.o
ALL = $(_ALL) alx_lib.o
-CMP_INC = alx_cmp.h
-CMP_DEPS = $(SRC_DIR)/alx_cmp.c $(patsubst %,$(INC_DIR)/%,$(CMP_INC))
-CMP_INC_DIRS = -I $(INC_DIR)
+CMP_INC = alx_cmp.h
+CMP_DEPS = $(SRC_DIR)/alx_cmp.c $(patsubst %,$(INC_DIR)/%,$(CMP_INC))
+CMP_INC_DIRS = -I $(INC_DIR)
-FILE_INC = alx_file.h
-FILE_DEPS = $(SRC_DIR)/alx_file.c $(patsubst %,$(INC_DIR)/%,$(FILE_INC))
-FILE_INC_DIRS = -I $(INC_DIR)
+FILE_INC = alx_file.h
+FILE_DEPS = $(SRC_DIR)/alx_file.c $(patsubst %,$(INC_DIR)/%,$(FILE_INC))
+FILE_INC_DIRS = -I $(INC_DIR)
-GETN_INC = alx_getnum.h
-GETN_DEPS = $(SRC_DIR)/alx_getnum.c $(patsubst %,$(INC_DIR)/%,$(GETN_INC))
-GETN_INC_DIRS = -I $(INC_DIR)
+INPUT_INC = alx_input.h
+INPUT_DEPS = $(SRC_DIR)/alx_input.c $(patsubst %,$(INC_DIR)/%,$(INPUT_INC))
+INPUT_INC_DIRS = -I $(INC_DIR)
-MASK_INC = alx_mask.h
-MASK_DEPS = $(SRC_DIR)/alx_mask.c $(patsubst %,$(INC_DIR)/%,$(MASK_INC))
-MASK_INC_DIRS = -I $(INC_DIR)
+MASK_INC = alx_mask.h
+MASK_DEPS = $(SRC_DIR)/alx_mask.c $(patsubst %,$(INC_DIR)/%,$(MASK_INC))
+MASK_INC_DIRS = -I $(INC_DIR)
-MATH_INC = alx_math.h
-MATH_DEPS = $(SRC_DIR)/alx_math.c $(patsubst %,$(INC_DIR)/%,$(MATH_INC))
-MATH_INC_DIRS = -I $(INC_DIR)
+MATH_INC = alx_math.h
+MATH_DEPS = $(SRC_DIR)/alx_math.c $(patsubst %,$(INC_DIR)/%,$(MATH_INC))
+MATH_INC_DIRS = -I $(INC_DIR)
-NCUR_INC = alx_ncur.h
-NCUR_DEPS = $(SRC_DIR)/alx_ncur.c $(patsubst %,$(INC_DIR)/%,$(NCUR_INC))
-NCUR_INC_DIRS = -I $(INC_DIR)
+NCUR_INC = alx_ncur.h alx_input.h
+NCUR_DEPS = $(SRC_DIR)/alx_ncur.c $(patsubst %,$(INC_DIR)/%,$(NCUR_INC))
+NCUR_INC_DIRS = -I $(INC_DIR)
-SEED_INC = alx_seed.h
-SEED_DEPS = $(SRC_DIR)/alx_seed.c $(patsubst %,$(INC_DIR)/%,$(SEED_INC))
-SEED_INC_DIRS = -I $(INC_DIR)
+SEED_INC = alx_seed.h
+SEED_DEPS = $(SRC_DIR)/alx_seed.c $(patsubst %,$(INC_DIR)/%,$(SEED_INC))
+SEED_INC_DIRS = -I $(INC_DIR)
# target: dependencies
# action
@@ -61,8 +61,8 @@ alx_file.o: $(FILE_DEPS)
$(Q)$(CC) $(CFLAGS) $(FILE_INC_DIRS) -c $< -o $@
@echo "\tCC $@"
-alx_getnum.o: $(GETN_DEPS)
- $(Q)$(CC) $(CFLAGS) $(GETN_INC_DIRS) -c $< -o $@
+alx_input.o: $(INPUT_DEPS)
+ $(Q)$(CC) $(CFLAGS) $(INPUT_INC_DIRS) -c $< -o $@
@echo "\tCC $@"
alx_mask.o: $(MASK_DEPS)
diff --git a/libalx/src/alx_getnum.c b/libalx/src/alx_input.c
index 3bfa22f..0c52cb9 100644
--- a/libalx/src/alx_getnum.c
+++ b/libalx/src/alx_input.c
@@ -11,12 +11,13 @@
* * * * * * * * * */
#include <inttypes.h>
#include <stdarg.h>
+ #include <stdbool.h>
#include <stdio.h>
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
- #include "alx_getnum.h"
+ #include "alx_input.h"
/******************************************************************************
@@ -26,9 +27,11 @@
# define MAX_TRIES (2)
+ # define ERR_OK (0)
# define ERR_RANGE (1)
# define ERR_SSCANF (2)
- # define ERR_FGETS (3)
+ # define ERR_FPTR (3)
+ # define ERR_FGETS (4)
# define ERR_RANGE_MSG "¡ Number is out of range !"
# define ERR_SSCANF_MSG "¡ sscanf() error !"
@@ -47,6 +50,97 @@ static void manage_error (int err);
******* main *****************************************************************
******************************************************************************/
/*
+ * Scan a double in the range [m, M].
+ * return: 0 if correct
+ * non 0 if there is an error
+ */
+int alx_sscan_dbl (double *dest, double m, double def, double M, const char *str)
+{
+ int err;
+
+ if (sscanf(str, " %lf", dest) != 1) {
+ err = ERR_SSCANF;
+ } else if ((*dest < m) || (*dest > M)) {
+ err = ERR_RANGE;
+ } else {
+ err = ERR_OK;
+ }
+
+ if (err) {
+ *dest = def;
+ }
+
+ return err;
+}
+
+ /*
+ * Scan an int64_t in the range [m, M].
+ * return: 0 if correct
+ * non 0 if there is an error
+ */
+int alx_sscan_int (int64_t *dest, double m, int64_t def, double M, const char *str)
+{
+ int err;
+
+ if (sscanf(str, " %"SCNi64"", dest) != 1) {
+ err = ERR_SSCANF;
+ } else if ((*dest < m) || (*dest > M)) {
+ err = ERR_RANGE;
+ } else {
+ err = ERR_OK;
+ }
+
+ if (err) {
+ *dest = def;
+ }
+
+ return err;
+}
+
+ /*
+ * Scan a file name in fpath.
+ * return: 0 if correct
+ * non 0 if there is an error
+ */
+int alx_sscan_fname (const char *fpath, char *fname, bool exist, const char *str)
+{
+ char buff [FILENAME_MAX];
+ char file_path [FILENAME_MAX];
+ int err;
+ FILE *fp;
+
+ if (sscanf(str, " %s ", buff) != 1) {
+ err = ERR_SSCANF;
+ } else {
+ snprintf(file_path, FILENAME_MAX, "%s%s", fpath, buff);
+
+ fp = fopen(file_path, "r");
+
+ if (exist) {
+ if (fp == NULL) {
+ err = ERR_FPTR;
+ } else {
+ err = ERR_OK;
+ fclose(fp);
+ }
+ } else {
+ if (fp == NULL) {
+ err = ERR_OK;
+ } else {
+ err = ERR_FPTR;
+ fclose(fp);
+ }
+ }
+ }
+
+ if (!err) {
+ snprintf(fname, FILENAME_MAX, buff);
+ }
+
+ return err;
+}
+
+ /*
* Ask for a double in the range [m, M].
*
* If the user enters a non valid number, it repeats to ask for
@@ -123,16 +217,15 @@ static double loop_getdbl (double m, double def, double M)
if (x == NULL) {
err = ERR_FGETS;
- } else if (sscanf(buff, " %lf", &R) != 1) {
- err = ERR_SSCANF;
- } else if (R < m || R > M) {
- err = ERR_RANGE;
} else {
- break;
+ err = alx_sscan_dbl(&R, m, def, M, buff);
}
- manage_error(err);
- R = def;
+ if (err) {
+ manage_error(err);
+ } else {
+ break;
+ }
}
return R;
@@ -151,16 +244,15 @@ static int64_t loop_getint (double m, int64_t def, double M)
if (x == NULL) {
err = ERR_FGETS;
- } else if (sscanf(buff, " %"SCNi64, &Z) != 1) {
- err = ERR_SSCANF;
- } else if (Z < m || Z > M) {
- err = ERR_RANGE;
} else {
- break;
+ err = alx_sscan_int(&Z, m, def, M, buff);
}
- manage_error(err);
- Z = def;
+ if (err) {
+ manage_error(err);
+ } else {
+ break;
+ }
}
return Z;
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c
index 78de144..c059488 100644
--- a/libalx/src/alx_ncur.c
+++ b/libalx/src/alx_ncur.c
@@ -22,6 +22,8 @@
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
+ #include "alx_input.h"
+
#include "alx_ncur.h"
@@ -35,8 +37,9 @@
# define ERR_OK (0)
# define ERR_RANGE (1)
# define ERR_SSCANF (2)
- # define ERR_GETSTR (3)
- # define ERR_FPTR (4)
+ # define ERR_FPTR (3)
+ # define ERR_FGETS (4)
+ # define ERR_GETSTR (5)
# define ERR_RANGE_MSG "¡ Number is out of range !"
# define ERR_SSCANF_MSG "¡ sscanf() error !"
@@ -561,19 +564,17 @@ static double loop_w_getdbl (WINDOW *win,
wclear(win);
wrefresh(win);
- err = ERR_OK;
if (x == ERR) {
- err = ERR_GETSTR;
- } else if (sscanf(buff, "%lf", &R) != 1) {
- err = ERR_SSCANF;
- } else if (R < m || R > M) {
- err = ERR_RANGE;
+ err = ERR_GETSTR;
} else {
- break;
+ err = alx_sscan_dbl(&R, m, def, M, buff);
}
- manage_w_error(win, err);
- R = def;
+ if (err) {
+ manage_w_error(win, err);
+ } else {
+ break;
+ }
}
return R;
@@ -595,19 +596,17 @@ static int64_t loop_w_getint (WINDOW *win,
wclear(win);
wrefresh(win);
- err = ERR_OK;
if (x == ERR) {
err = ERR_GETSTR;
- } else if (sscanf(buff, "%"SCNi64, &Z) != 1) {
- err = ERR_SSCANF;
- } else if (Z < m || Z > M) {
- err = ERR_RANGE;
} else {
- break;
+ err = alx_sscan_int(&Z, m, def, M, buff);
}
- manage_w_error(win, err);
- Z = def;
+ if (err) {
+ manage_w_error(win, err);
+ } else {
+ break;
+ }
}
return Z;
@@ -634,7 +633,11 @@ static void loop_w_getstr (char *dest, int destsize, WINDOW *win)
break;
}
- manage_w_error(win, err);
+ if (err) {
+ manage_w_error(win, err);
+ } else {
+ break;
+ }
}
if (!err) {
@@ -647,11 +650,8 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist,
{
int i;
char buff [FILENAME_MAX];
- char buff2 [FILENAME_MAX];
- char file_path [FILENAME_MAX];
int x;
int err;
- FILE *fp;
for (i = 0; i < MAX_TRIES; i++) {
echo();
@@ -660,38 +660,17 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist,
wclear(win);
wrefresh(win);
- err = ERR_OK;
if (x == ERR) {
- err = ERR_GETSTR;
- } else if (sscanf(buff, " %s ", buff2) != 1) {
- err = ERR_SSCANF;
+ err = ERR_GETSTR;
} else {
- snprintf(file_path, FILENAME_MAX, "%s%s", fpath, buff2);
-
- fp = fopen(file_path, "r");
-
- if (exist) {
- if (fp == NULL) {
- err = ERR_FPTR;
- } else {
- fclose(fp);
- break;
- }
- } else {
- if (fp != NULL) {
- err = ERR_FPTR;
- fclose(fp);
- } else {
- break;
- }
- }
+ err = alx_sscan_fname(fpath, fname, exist, buff);
}
- manage_w_error(win, err);
- }
-
- if (!err) {
- snprintf(fname, FILENAME_MAX, buff2);
+ if (err) {
+ manage_w_error(win, err);
+ } else {
+ break;
+ }
}
}
diff --git a/modules/menu/obj/Makefile b/modules/menu/obj/Makefile
index 5b72d54..be8ede5 100644
--- a/modules/menu/obj/Makefile
+++ b/modules/menu/obj/Makefile
@@ -54,7 +54,7 @@ MENUI_INC_DIRS = -I $(INC_DIR) \
-I $(CTRL_INC_DIR) \
-I $(GAME_INC_DIR)
-MENUCLUI_INC_LIBALX = alx_getnum.h
+MENUCLUI_INC_LIBALX = alx_input.h
MENUCLUI_INC_ABOUT = about.h
MENUCLUI_INC_CTRL = start.h
MENUCLUI_INC_GAME = game_iface.h
@@ -94,7 +94,7 @@ MENUTUI_INC_DIRS = -I $(INC_DIR) \
-I $(GAME_INC_DIR) \
-I $(SAVE_INC_DIR)
-MENUGUI_INC_LIBALX = alx_ncur.h
+MENUGUI_INC_LIBALX = alx_input.h
MENUGUI_INC_ABOUT = about.h
MENUGUI_INC_CTRL = start.h
MENUGUI_INC_GAME = game_iface.h
diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c
index 6fccbe0..dacd569 100644
--- a/modules/menu/src/menu_clui.c
+++ b/modules/menu/src/menu_clui.c
@@ -17,7 +17,7 @@
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
- #include "alx_getnum.h"
+ #include "alx_input.h"
#include "about.h"
#include "game_iface.h"
diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c
index 427534a..806ab87 100644
--- a/modules/menu/src/menu_gui.c
+++ b/modules/menu/src/menu_gui.c
@@ -22,6 +22,8 @@
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
+ #include "alx_input.h"
+
#include "about.h"
#include "game_iface.h"
#include "save.h"
@@ -55,6 +57,31 @@ struct Label_Data {
char text [LINE_SIZE];
};
+struct Entry_dbl_Data {
+ GtkWidget *ptr;
+ struct Label_Data lbl;
+ double *num;
+ double min;
+ double def;
+ double max;
+};
+
+struct Entry_int_Data {
+ GtkWidget *ptr;
+ struct Label_Data lbl;
+ int *num;
+ double min;
+ int64_t def;
+ double max;
+};
+
+struct Entry_fname_Data {
+ GtkWidget *ptr;
+ struct Label_Data lbl;
+ const char *fpath;
+ char *fname;
+};
+
/******************************************************************************
******* variables ************************************************************
@@ -82,6 +109,11 @@ static void destroy_window (GtkWidget *widget,
/* Selection */
static void callback_button (GtkWidget *widget,
void *data);
+ /* Entries */
+static void callback_entry_dbl (GtkWidget *widget,
+ void *data);
+static void callback_entry_int (GtkWidget *widget,
+ void *data);
/* Text */
static void menu_gui_disclaim (void);
static void menu_gui_license (void);
@@ -189,7 +221,7 @@ void menu_gui (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Clear window */
@@ -224,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 */
@@ -235,16 +265,14 @@ static gboolean delete_window (GtkWidget *widget,
static void destroy_window (GtkWidget *widget,
void *data)
{
- g_print ("destroy event occurred\n");
-
exit(EXIT_SUCCESS);
}
/* * * * * * * * * *
* * Selection * * * * * *
* * * * * * * * * */
-static void callback_button (GtkWidget *widget,
- void *data)
+static void callback_button (GtkWidget *widget,
+ void *data)
{
struct Button_Data *button;
@@ -256,6 +284,81 @@ static void callback_button (GtkWidget *widget,
}
/* * * * * * * * * *
+ * * Entries * * * * * * *
+ * * * * * * * * * */
+static void callback_entry_dbl (GtkWidget *widget,
+ void *data)
+{
+ struct Entry_dbl_Data *entry;
+ const char *str;
+ int err;
+ char buff [LINE_SIZE];
+
+ entry = ((struct Entry_dbl_Data *)data);
+
+ str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
+ err = alx_sscan_dbl(entry->num, entry->min, entry->def, entry->max, 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_int (GtkWidget *widget,
+ void *data)
+{
+ struct Entry_int_Data *entry;
+ const char *str;
+ int err;
+ int64_t Z;
+ char buff [LINE_SIZE];
+
+ entry = ((struct Entry_int_Data *)data);
+
+ str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
+ err = alx_sscan_int(&Z, entry->min, entry->def, entry->max, 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);
+ } else {
+ *(entry->num) = Z;
+ }
+
+ gtk_main_quit();
+}
+
+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, true, 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();
+}
+
+/* * * * * * * * * *
* * Text * * * * * * *
* * * * * * * * * */
static void menu_gui_disclaim (void)
@@ -417,53 +520,55 @@ static void menu_gui_continue (void)
int sw;
GtkWidget *separator[4];
struct Label_Data label;
- struct Button_Data button [7];
+ struct Button_Data button [6];
+ struct Entry_fname_Data entry_fname[1];
/* Text */
snprintf(label.text, LINE_SIZE, "Game menu");
snprintf(button[1].text, LINE_SIZE, "[_1] Start");
snprintf(button[2].text, LINE_SIZE, "[_2] Select map");
snprintf(button[3].text, LINE_SIZE, "[_3] Change difficulty");
- snprintf(button[5].text, LINE_SIZE, "[_5] Hi scores");
- snprintf(button[6].text, LINE_SIZE, "[_6] DEVEL");
+ snprintf(button[4].text, LINE_SIZE, "[_4] Hi scores");
+ snprintf(button[5].text, LINE_SIZE, "[_5] DEVEL");
snprintf(button[0].text, LINE_SIZE, "[_0] Back");
/* Data */
- button[1].num = 1;
- button[2].num = 2;
- button[3].num = 3;
- button[4].num = 4;
- button[5].num = 5;
- button[6].num = 6;
- button[0].num = 0;
- button[1].sw = &sw;
- button[2].sw = &sw;
- button[3].sw = &sw;
- button[4].sw = &sw;
- button[5].sw = &sw;
- button[6].sw = &sw;
- button[0].sw = &sw;
+ button[1].num = 1;
+ button[2].num = 2;
+ button[3].num = 3;
+ button[4].num = 4;
+ button[5].num = 5;
+ button[0].num = 0;
+ button[1].sw = &sw;
+ button[2].sw = &sw;
+ button[3].sw = &sw;
+ entry_fname[0].fpath = saved_path;
+ entry_fname[0].fname = saved_name;
+ button[4].sw = &sw;
+ button[5].sw = &sw;
+ button[0].sw = &sw;
/* Menu loop */
wh = true;
while (wh) {
/* Text */
- snprintf(button[4].text, LINE_SIZE, "[_4] Change file name (File: \"%s\")", saved_name);
+ snprintf(entry_fname[0].lbl.text, LINE_SIZE, "Change file name (File: \"%s\")", saved_name);
/* Generate widgets */
- box = gtk_vbox_new(false, 0);
- label.ptr = gtk_label_new(label.text);
- separator[0] = gtk_hseparator_new();
- button[1].ptr = gtk_button_new_with_mnemonic(button[1].text);
- separator[1] = gtk_hseparator_new();
- button[2].ptr = gtk_button_new_with_mnemonic(button[2].text);
- button[3].ptr = gtk_button_new_with_mnemonic(button[3].text);
- button[4].ptr = gtk_button_new_with_mnemonic(button[4].text);
- button[5].ptr = gtk_button_new_with_mnemonic(button[5].text);
- separator[2] = gtk_hseparator_new();
- button[6].ptr = gtk_button_new_with_mnemonic(button[6].text);
- separator[3] = gtk_hseparator_new();
- button[0].ptr = gtk_button_new_with_mnemonic(button[0].text);
+ box = gtk_vbox_new(false, 0);
+ label.ptr = gtk_label_new(label.text);
+ separator[0] = gtk_hseparator_new();
+ button[1].ptr = gtk_button_new_with_mnemonic(button[1].text);
+ separator[1] = gtk_hseparator_new();
+ button[2].ptr = gtk_button_new_with_mnemonic(button[2].text);
+ 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[4].text);
+ separator[2] = gtk_hseparator_new();
+ 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);
/* Events */
g_signal_connect(button[1].ptr, "clicked",
@@ -472,12 +577,12 @@ static void menu_gui_continue (void)
G_CALLBACK(callback_button), (void *)&button[2]);
g_signal_connect(button[3].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[3]);
+ g_signal_connect(entry_fname[0].ptr, "activate",
+ G_CALLBACK(callback_entry_fname), (void *)&entry_fname[0]);
g_signal_connect(button[4].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[4]);
g_signal_connect(button[5].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[5]);
- g_signal_connect(button[6].ptr, "clicked",
- G_CALLBACK(callback_button), (void *)&button[6]);
g_signal_connect(button[0].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[0]);
@@ -491,10 +596,11 @@ static void menu_gui_continue (void)
gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5);
gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_fname[0].lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_fname[0].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), button[4].ptr, true, true, 0);
- gtk_box_pack_start(GTK_BOX(box), button[5].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5);
- gtk_box_pack_start(GTK_BOX(box), button[6].ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), button[5].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), separator[3], false, false, 5);
gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0);
@@ -502,39 +608,30 @@ static void menu_gui_continue (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
+ /* Clear window */
+ gtk_widget_destroy(box);
+
/* Selection */
switch (sw) {
case 0:
- gtk_widget_destroy(box);
wh = false;
break;
case 1:
- gtk_widget_destroy(box);
start_switch();
break;
case 2:
- gtk_widget_destroy(box);
menu_gui_select();
break;
case 3:
- gtk_widget_destroy(box);
menu_gui_level();
break;
case 4:
- save_clr();
-// alx_w_getfname(saved_path, saved_name, true, w2, r2,
-// txt[0], NULL);
- gtk_widget_destroy(box);
- break;
- case 5:
- gtk_widget_destroy(box);
menu_gui_hiscores();
break;
- case 6:
- gtk_widget_destroy(box);
+ case 5:
menu_gui_devel();
break;
}
@@ -596,7 +693,7 @@ static void menu_gui_select (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Clear window */
@@ -684,7 +781,7 @@ static void menu_gui_level (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Clear window */
@@ -714,48 +811,60 @@ static void menu_gui_custom (void)
int sw;
GtkWidget *separator[3];
struct Label_Data label;
- struct Button_Data button [4];
+ struct Button_Data button [1];
+ struct Entry_int_Data entry_int[2];
+ struct Entry_dbl_Data entry_dbl[1];
/* Text */
snprintf(label.text, LINE_SIZE, "Custom");
snprintf(button[0].text, LINE_SIZE, "[_0] Back");
/* Data */
- button[1].num = 1;
- button[2].num = 2;
- button[3].num = 3;
- button[0].num = 0;
- button[1].sw = &sw;
- button[2].sw = &sw;
- button[3].sw = &sw;
- button[0].sw = &sw;
+ entry_int[0].num = &menu_iface_variables.rows;
+ entry_int[0].min = 2;
+ entry_int[0].def = menu_iface_variables.rows;
+ entry_int[0].max = ROWS_GUI_MAX;
+ entry_int[1].num = &menu_iface_variables.cols;
+ entry_int[1].min = 2;
+ entry_int[1].def = menu_iface_variables.cols;
+ entry_int[1].max = COLS_GUI_MAX;
+ entry_dbl[0].num = &menu_iface_variables.p;
+ entry_dbl[0].min = 0;
+ entry_dbl[0].def = menu_iface_variables.p;
+ entry_dbl[0].max = 1;
+ button[0].num = 0;
+ button[0].sw = &sw;
/* Menu loop */
wh = true;
while (wh) {
+
/* Text */
- snprintf(button[1].text, LINE_SIZE, "[_1] Change rows: rows\t\t(%i)", menu_iface_variables.rows);
- snprintf(button[2].text, LINE_SIZE, "[_2] Change columns: cols\t(%i)", menu_iface_variables.cols);
- snprintf(button[3].text, LINE_SIZE, "[_3] Change proportion of mines: p\t(%lf)", menu_iface_variables.p);
+ snprintf(entry_int[0].lbl.text, LINE_SIZE, "Change rows: rows\t\t(%i)", menu_iface_variables.rows);
+ snprintf(entry_int[1].lbl.text, LINE_SIZE, "Change columns: cols\t(%i)", menu_iface_variables.cols);
+ snprintf(entry_dbl[0].lbl.text, LINE_SIZE, "Change proportion of mines: p\t(%lf)", menu_iface_variables.p);
/* Generate widgets */
- box = gtk_vbox_new(false, 0);
- label.ptr = gtk_label_new(label.text);
- separator[0] = gtk_hseparator_new();
- button[1].ptr = gtk_button_new_with_mnemonic(button[1].text);
- button[2].ptr = gtk_button_new_with_mnemonic(button[2].text);
- separator[1] = gtk_hseparator_new();
- button[3].ptr = gtk_button_new_with_mnemonic(button[3].text);
- separator[2] = gtk_hseparator_new();
- button[0].ptr = gtk_button_new_with_mnemonic(button[0].text);
+ box = gtk_vbox_new(false, 0);
+ label.ptr = gtk_label_new(label.text);
+ separator[0] = gtk_hseparator_new();
+ entry_int[0].lbl.ptr = gtk_label_new(entry_int[0].lbl.text);
+ entry_int[0].ptr = gtk_entry_new();
+ entry_int[1].lbl.ptr = gtk_label_new(entry_int[1].lbl.text);
+ entry_int[1].ptr = gtk_entry_new();
+ separator[1] = gtk_hseparator_new();
+ entry_dbl[0].lbl.ptr = gtk_label_new(entry_dbl[0].lbl.text);
+ entry_dbl[0].ptr = gtk_entry_new();
+ separator[2] = gtk_hseparator_new();
+ button[0].ptr = gtk_button_new_with_mnemonic(button[0].text);
/* Events */
- g_signal_connect(button[1].ptr, "clicked",
- G_CALLBACK(callback_button), (void *)&button[1]);
- g_signal_connect(button[2].ptr, "clicked",
- G_CALLBACK(callback_button), (void *)&button[2]);
- g_signal_connect(button[3].ptr, "clicked",
- G_CALLBACK(callback_button), (void *)&button[3]);
+ g_signal_connect(entry_int[0].ptr, "activate",
+ G_CALLBACK(callback_entry_int), (void *)&entry_int[0]);
+ g_signal_connect(entry_int[1].ptr, "activate",
+ G_CALLBACK(callback_entry_int), (void *)&entry_int[1]);
+ g_signal_connect(entry_dbl[0].ptr, "activate",
+ G_CALLBACK(callback_entry_dbl), (void *)&entry_dbl[0]);
g_signal_connect(button[0].ptr, "clicked",
G_CALLBACK(callback_button), (void *)&button[0]);
@@ -765,10 +874,13 @@ static void menu_gui_custom (void)
/* Box */
gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0);
gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5);
- gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0);
- gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_int[0].lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_int[0].ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_int[1].lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_int[1].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5);
- gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_dbl[0].lbl.ptr, true, true, 0);
+ gtk_box_pack_start(GTK_BOX(box), entry_dbl[0].ptr, true, true, 0);
gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5);
gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0);
@@ -776,7 +888,7 @@ static void menu_gui_custom (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Selection */
@@ -784,17 +896,8 @@ static void menu_gui_custom (void)
case 0:
wh = false;
break;
- case 1:
-// menu_iface_variables.rows = alx_w_getint(w2, r2,
-// txt[sw - 1], 2, menu_iface_variables.rows, ROWS_TUI_MAX, NULL);
- break;
- case 2:
-// menu_iface_variables.cols = alx_w_getint(w2, r2,
-// txt[sw - 1], 2, menu_iface_variables.cols, COLS_TUI_MAX, NULL);
- break;
- case 3:
-// menu_iface_variables.p = alx_w_getdbl(w2, r2,
-// txt[sw - 1], 0, menu_iface_variables.p, 1, NULL);
+
+ default:
break;
}
@@ -854,7 +957,7 @@ static void menu_gui_devel (void)
gtk_widget_show_all(window_gui);
/* GTK loop */
- sw = 0;
+ sw = -1;
gtk_main();
/* Selection */
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);
diff --git a/modules/player/src/player_iface.c b/modules/player/src/player_iface.c
index 357594c..f736f2e 100644
--- a/modules/player/src/player_iface.c
+++ b/modules/player/src/player_iface.c
@@ -53,16 +53,12 @@ static int player_action;
******* static functions *****************************************************
******************************************************************************/
/* Actions */
-static void player_iface_act (struct Game_Iface_In *game_iface_in,
- int action);
+static void player_iface_act (struct Game_Iface_In *game_iface_in);
/* Actions: game iface */
-static void player_iface_act_start (int action);
-
-static void player_iface_act_play (struct Game_Iface_In *game_iface_in,
- int action);
-static void player_iface_act_game (struct Game_Iface_In *game_iface_in,
- int action);
+static void player_iface_act_start (void);
+static void player_iface_act_play (struct Game_Iface_In *game_iface_in);
+static void player_iface_act_game (struct Game_Iface_In *game_iface_in);
/* Actions: player iface */
static void player_iface_move_up (void);
@@ -127,7 +123,7 @@ int player_iface_start (int *pos_row, int *pos_col)
break;
}
- player_iface_act_start(player_action);
+ player_iface_act_start();
} while (player_action != PLAYER_IFACE_ACT_STEP &&
player_action != PLAYER_IFACE_ACT_QUIT);
@@ -206,7 +202,7 @@ void player_iface (const struct Game_Iface_Out *game_iface_out,
break;
}
- player_iface_act(game_iface_in, player_action);
+ player_iface_act(game_iface_in);
}
void player_iface_save_name (const char *filepath, char *filename, int destsize)
@@ -267,15 +263,14 @@ void player_iface_cleanup (void)
/* * * * * * * * * *
* * * Actions * * * * * *
* * * * * * * * * */
-static void player_iface_act (struct Game_Iface_In *game_iface_in,
- int player_action)
+static void player_iface_act (struct Game_Iface_In *game_iface_in)
{
switch (player_action) {
case PLAYER_IFACE_ACT_STEP:
case PLAYER_IFACE_ACT_FLAG:
case PLAYER_IFACE_ACT_FLAG_POSSIBLE:
case PLAYER_IFACE_ACT_RM_FLAG:
- player_iface_act_play(game_iface_in, player_action);
+ player_iface_act_play(game_iface_in);
break;
case PLAYER_IFACE_ACT_PAUSE:
@@ -286,7 +281,7 @@ static void player_iface_act (struct Game_Iface_In *game_iface_in,
case PLAYER_IFACE_ACT_XYZZY_P:
case PLAYER_IFACE_ACT_XYZZY_NP:
case PLAYER_IFACE_ACT_QUIT:
- player_iface_act_game(game_iface_in, player_action);
+ player_iface_act_game(game_iface_in);
break;
case PLAYER_IFACE_ACT_MOVE_UP:
@@ -311,7 +306,7 @@ static void player_iface_act (struct Game_Iface_In *game_iface_in,
}
}
-static void player_iface_act_start (int player_action)
+static void player_iface_act_start (void)
{
switch (player_action) {
case PLAYER_IFACE_ACT_STEP:
@@ -343,8 +338,7 @@ static void player_iface_act_start (int player_action)
/* * * * * * * * * *
* * * Actions: game iface * * * * *
* * * * * * * * * */
-static void player_iface_act_play (struct Game_Iface_In *game_iface_in,
- int player_action)
+static void player_iface_act_play (struct Game_Iface_In *game_iface_in)
{
switch (player_action) {
case PLAYER_IFACE_ACT_STEP:
@@ -371,8 +365,7 @@ static void player_iface_act_play (struct Game_Iface_In *game_iface_in,
game_iface_in->action = GAME_IFACE_ACT_PLAY;
}
-static void player_iface_act_game (struct Game_Iface_In *game_iface_in,
- int player_action)
+static void player_iface_act_game (struct Game_Iface_In *game_iface_in)
{
switch (player_action) {
case PLAYER_IFACE_ACT_PAUSE: