summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDušan Ďurech <dusan.d@centrum.cz>2009-12-27 20:49:44 +0100
committerDušan Ďurech <dusan.d@centrum.cz>2009-12-27 20:49:44 +0100
commitcdc100ff4a0ceecae2ee2cecaf9df6b82b8636e4 (patch)
treec28235253651978153fc97657cf73a2b376197c5
parentfda7d7a9443a05d7ec0870be482b735a7b4f7ef9 (diff)
implements yes/no dialog if to quit the game or not
-rw-r--r--src/client/yes_no_dialog.c137
-rw-r--r--src/client/yes_no_dialog.h20
-rw-r--r--src/screen/world.c27
3 files changed, 182 insertions, 2 deletions
diff --git a/src/client/yes_no_dialog.c b/src/client/yes_no_dialog.c
new file mode 100644
index 0000000..0b7f9b3
--- /dev/null
+++ b/src/client/yes_no_dialog.c
@@ -0,0 +1,137 @@
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+
+#include "interface.h"
+#include "hotKey.h"
+#include "yes_no_dialog.h"
+#include "image.h"
+#include "font.h"
+
+#include "widget.h"
+#include "widget_label.h"
+#include "widget_button.h"
+
+static image_t *g_background;
+
+static widget_t *widgetLabelMsg;
+
+static widget_t *widgetButtonYes;
+static widget_t *widgetButtonNo;
+
+static void (*handle_yes)(void *param);
+static void (*handle_no)(void *param);
+static void *param;
+static bool_t active_dialog;
+
+static void eventWidget(void *p)
+{
+ widget_t *button;
+
+ button = (widget_t *) p;
+
+ yes_no_dialog_set_active(FALSE);
+
+ if (button == widgetButtonYes) {
+ handle_yes(param);
+ }
+
+ if (button == widgetButtonNo) {
+ handle_no(param);
+ }
+}
+
+void yes_no_dialog_init()
+{
+ active_dialog = FALSE;
+
+ g_background = image_get(IMAGE_GROUP_BASE, "screen_main");
+
+ widgetLabelMsg = label_new("empty label", WINDOW_SIZE_X / 2,
+ YES_NO_DIALOG_LOCATIN_Y + 20,
+ WIDGET_LABEL_CENTER);
+
+ widgetButtonYes = button_new(_("Yes"), YES_NO_DIALOG_LOCATIN_X + 20,
+ YES_NO_DIALOG_LOCATIN_Y + 60,
+ eventWidget);
+
+ widgetButtonNo = button_new(_("No"), YES_NO_DIALOG_LOCATIN_X + 20 +
+ WIDGET_BUTTON_WIDTH + 20,
+ YES_NO_DIALOG_LOCATIN_Y + 60,
+ eventWidget);
+}
+
+static void hotkey_escape()
+{
+ yes_no_dialog_set_active(FALSE);
+ handle_no(param);
+}
+
+void yes_no_dialog_set_active(bool_t active)
+{
+ active_dialog = active;
+
+ if (active_dialog == TRUE)
+ {
+ hot_key_register(SDLK_ESCAPE, hotkey_escape);
+ }
+ else
+ {
+ hot_key_unregister(SDLK_ESCAPE);
+ }
+}
+
+bool_t yes_no_dialog_is_active()
+{
+ return active_dialog;
+}
+
+void yes_no_dialog_set(char *label, void *function_yes, void *function_no, void *p_param)
+{
+ label_destroy(widgetLabelMsg);
+
+ widgetLabelMsg = label_new(label, WINDOW_SIZE_X / 2,
+ YES_NO_DIALOG_LOCATIN_Y + 20,
+ WIDGET_LABEL_CENTER);
+
+ handle_yes = function_yes;
+ handle_no = function_no;
+ param = p_param;
+}
+
+void yes_no_dialog_draw()
+{
+ if (active_dialog == FALSE) {
+ return;
+ }
+
+ image_draw(g_background, YES_NO_DIALOG_LOCATIN_X,
+ YES_NO_DIALOG_LOCATIN_Y,
+ YES_NO_DIALOG_LOCATIN_X,
+ YES_NO_DIALOG_LOCATIN_Y,
+ YES_NO_DIALOG_SIZE_X,
+ YES_NO_DIALOG_SIZE_Y);
+
+ label_draw(widgetLabelMsg);
+ button_draw(widgetButtonYes);
+ button_draw(widgetButtonNo);
+}
+
+void yes_no_dialog_event()
+{
+ if (active_dialog == FALSE) {
+ return;
+ }
+
+ button_event(widgetButtonYes);
+ button_event(widgetButtonNo);
+}
+
+void yes_no_dialog_quit()
+{
+ label_destroy(widgetLabelMsg);
+ button_destroy(widgetButtonYes);
+ button_destroy(widgetButtonNo);
+}
diff --git a/src/client/yes_no_dialog.h b/src/client/yes_no_dialog.h
new file mode 100644
index 0000000..3cef74c
--- /dev/null
+++ b/src/client/yes_no_dialog.h
@@ -0,0 +1,20 @@
+#ifndef YES_NO_DIALOG_H
+#define YES_NO_DIALOG_H
+
+#define YES_NO_ACTIVE_TIME_INTERVAL 500
+
+#define YES_NO_DIALOG_SIZE_X 320
+#define YES_NO_DIALOG_SIZE_Y 120
+
+#define YES_NO_DIALOG_LOCATIN_X (WINDOW_SIZE_X / 2 - YES_NO_DIALOG_SIZE_X / 2)
+#define YES_NO_DIALOG_LOCATIN_Y (WINDOW_SIZE_Y / 2 - YES_NO_DIALOG_SIZE_Y / 2)
+
+extern void yes_no_dialog_init();
+extern void yes_no_dialog_set_active(bool_t active);
+extern bool_t yes_no_dialog_is_active();
+extern void yes_no_dialog_set(char *label, void *function_yes, void *function_no, void *p_param);
+extern void yes_no_dialog_draw();
+extern void yes_no_dialog_event();
+extern void yes_no_dialog_quit();
+
+#endif /* YES_NO_DIALOG_H */
diff --git a/src/screen/world.c b/src/screen/world.c
index 1aaa2cc..c2615c8 100644
--- a/src/screen/world.c
+++ b/src/screen/world.c
@@ -28,6 +28,7 @@
#include "pauza.h"
#include "term.h"
#include "saveDialog.h"
+#include "yes_no_dialog.h"
#include "saveLoad.h"
#ifndef NO_SOUND
@@ -205,6 +206,7 @@ void world_draw()
pauza_draw();
term_draw();
save_dialog_draw();
+ yes_no_dialog_draw();
}
static void netAction(tux_t *tux, int action)
@@ -346,7 +348,9 @@ void world_event()
net_multiplayer_event();
- if (pauza_is_active() == FALSE && save_dialog_is_active() == FALSE) {
+ if (pauza_is_active() == FALSE &&
+ save_dialog_is_active() == FALSE &&
+ yes_no_dialog_is_active() == FALSE) {
arena_event(arena);
/*module_event();*/
}
@@ -366,13 +370,28 @@ void world_event()
pauza_event();
term_event();
save_dialog_event();
+ yes_no_dialog_event();
}
-static void hotkey_escape()
+void dialog_yes(void *p)
{
+ UNUSED(p);
+
world_do_end();
}
+void dialog_no(void *p)
+{
+ UNUSED(p);
+}
+
+static void hotkey_escape()
+{
+ yes_no_dialog_set("Naozaj chete ukoncit hru ?", dialog_yes, dialog_no, NULL);
+ yes_no_dialog_set_active(TRUE);
+ //world_do_end();
+}
+
void startWorld()
{
arena = NULL;
@@ -387,6 +406,8 @@ void startWorld()
setGameType();
+ yes_no_dialog_init();
+
if (net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE) {
save_dialog_init();
}
@@ -448,6 +469,8 @@ void stoptWorld()
pauza_quit();
term_quit();
+ yes_no_dialog_quit();
+
if (net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE) {
save_dialog_quit();
}