OSDN Git Service

Nazghul-0.7.1
[nazghul-jp/nazghul-jp.git] / src / escape.c
1 /*
2  * nazghul - an old-school RPG engine
3  * Copyright (C) 2008 Gordon McNutt
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17  * Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Gordon McNutt
20  * gmcnutt@users.sourceforge.net
21  */
22
23 #include "cmd.h"
24 #include "event.h"
25 #include "log.h"
26 #include "session.h"
27
28 #include <SDL.h>
29
30 static struct KeyHandler esc_key_hndlr;
31
32 static void esc_help(void)
33 {
34     log_begin("F)ollow mode\n");
35     log_continue("Q)uit\n");
36     log_continue("[1-9] Solo mode\n");
37     log_continue("CTRL-R)eload\n");
38     log_continue("CTRL-S)ave\n");
39     log_end("ESC to continue game\n");
40 }
41
42 static int esc_menu_key_fx(struct KeyHandler *kh, int key, int keymod)
43 {
44     switch (key) {
45     case 'f':
46         cmdToggleFollowMode();
47         return 1;
48     case 'q':
49         cmdQuit();
50         return 1;
51     case SDLK_1:
52     case SDLK_2:
53     case SDLK_3:
54     case SDLK_4:
55     case SDLK_5:
56     case SDLK_6:
57     case SDLK_7:
58     case SDLK_8:
59     case SDLK_9:                        
60         cmdSetSoloMode(key - SDLK_1);
61         return 1;
62     case KEY_CTRL_S:
63         cmdSave();
64         break;
65     case KEY_CTRL_R:
66         cmdReload();
67         return 1;
68     case SDLK_F10:
69         cmdSettings();
70         break;
71     case SDLK_ESCAPE:
72         log_msg("Continue");
73         return 1;
74     case '?':
75         esc_help();
76         break;
77     default:
78         //log_msg("Sorry, %d is not a valid command.");
79         break;
80     }
81     return 0;
82 }
83
84 static int esc_key_fx(struct KeyHandler *esckh, int key, int keymod)
85 {
86     struct KeyHandler kh;
87
88     if (SDLK_ESCAPE != key) {
89         return 0;
90     }
91
92     log_banner("ESC mode - press '?' for help");
93
94     kh.fx = esc_menu_key_fx;
95     eventPushKeyHandler(&kh);
96     eventHandle();
97     eventPopKeyHandler();
98     return 0;
99 }
100
101 void escape_start_handler(void)
102 {
103     esc_key_hndlr.fx = esc_key_fx;
104     eventPushKeyHandler(&esc_key_hndlr);
105 }
106
107 void escape_stop_handler(void)
108 {
109     eventPopKeyHandler();
110 }