summaryrefslogtreecommitdiff
path: root/apps/plugins/frotz/hotkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/frotz/hotkey.c')
-rw-r--r--apps/plugins/frotz/hotkey.c221
1 files changed, 221 insertions, 0 deletions
diff --git a/apps/plugins/frotz/hotkey.c b/apps/plugins/frotz/hotkey.c
new file mode 100644
index 0000000000..d214f1f322
--- /dev/null
+++ b/apps/plugins/frotz/hotkey.c
@@ -0,0 +1,221 @@
1/* hotkey.c - Hot key functions
2 * Copyright (c) 1995-1997 Stefan Jokisch
3 *
4 * Changes for Rockbox copyright 2009 Torne Wuff
5 *
6 * This file is part of Frotz.
7 *
8 * Frotz is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Frotz is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 */
22
23#include "frotz.h"
24#include "lib/pluginlib_exit.h"
25
26extern int restore_undo (void);
27
28extern int read_number (void);
29
30extern bool read_yes_or_no (const char *);
31
32extern void replay_open (void);
33extern void replay_close (void);
34extern void record_open (void);
35extern void record_close (void);
36
37extern void seed_random (int);
38
39/*
40 * hot_key_debugging
41 *
42 * ...allows user to toggle cheating options on/off.
43 *
44 */
45
46static bool hot_key_debugging (void)
47{
48
49 f_setup.attribute_assignment = read_yes_or_no ("Watch attribute assignment");
50 f_setup.attribute_testing = read_yes_or_no ("Watch attribute testing");
51
52 f_setup.object_movement = read_yes_or_no ("Watch object movement");
53 f_setup.object_locating = read_yes_or_no ("Watch object locating");
54
55 return FALSE;
56
57}/* hot_key_debugging */
58
59/*
60 * hot_key_playback
61 *
62 * ...allows user to turn playback on.
63 *
64 */
65
66static bool hot_key_playback (void)
67{
68
69 rb->splash(HZ, "Playback on");
70
71 if (!istream_replay)
72 replay_open ();
73
74 return FALSE;
75
76}/* hot_key_playback */
77
78/*
79 * hot_key_recording
80 *
81 * ...allows user to turn recording on/off.
82 *
83 */
84
85static bool hot_key_recording (void)
86{
87
88 if (istream_replay) {
89 rb->splash(HZ, "Playback off");
90 replay_close ();
91 } else if (ostream_record) {
92 rb->splash(HZ, "Recording off");
93 record_close ();
94 } else {
95 rb->splash(HZ, "Recording on");
96 record_open ();
97 }
98
99 return FALSE;
100
101}/* hot_key_recording */
102
103/*
104 * hot_key_seed
105 *
106 * ...allows user to seed the random number seed.
107 *
108 */
109
110static bool hot_key_seed (void)
111{
112
113 print_string ("Enter seed value (or return to randomize): ");
114 seed_random (read_number ());
115
116 return FALSE;
117
118}/* hot_key_seed */
119
120/*
121 * hot_key_undo
122 *
123 * ...allows user to undo the previous turn.
124 *
125 */
126
127static bool hot_key_undo (void)
128{
129
130 if (restore_undo ()) {
131
132 print_string ("undo\n");
133
134 if (h_version >= V5) { /* for V5+ games we must */
135 store (2); /* store 2 (for success) */
136 return TRUE; /* and abort the input */
137 }
138
139 if (h_version <= V3) { /* for V3- games we must */
140 z_show_status (); /* draw the status line */
141 return FALSE; /* and continue input */
142 }
143
144 } else rb->splash(HZ, "No undo information available.");
145
146 return FALSE;
147
148}/* hot_key_undo */
149
150/*
151 * hot_key_restart
152 *
153 * ...allows user to start a new game.
154 *
155 */
156
157static bool hot_key_restart (void)
158{
159
160 if (read_yes_or_no ("Do you wish to restart")) {
161
162 z_restart ();
163 return TRUE;
164
165 } else return FALSE;
166
167}/* hot_key_restart */
168
169/*
170 * hot_key_quit
171 *
172 * ...allows user to exit the game.
173 *
174 */
175
176bool hot_key_quit (void)
177{
178
179 if (read_yes_or_no ("Do you wish to quit")) {
180
181 exit(0);
182
183 } else return FALSE;
184
185}/* hot_key_quit */
186
187/*
188 * handle_hot_key
189 *
190 * Perform the action associated with a so-called hot key. Return
191 * true to abort the current input action.
192 *
193 */
194
195bool handle_hot_key (zchar key)
196{
197
198 if (cwin == 0) {
199
200 bool aborting;
201
202 aborting = FALSE;
203
204 switch (key) {
205 case ZC_HKEY_RECORD: aborting = hot_key_recording (); break;
206 case ZC_HKEY_PLAYBACK: aborting = hot_key_playback (); break;
207 case ZC_HKEY_SEED: aborting = hot_key_seed (); break;
208 case ZC_HKEY_UNDO: aborting = hot_key_undo (); break;
209 case ZC_HKEY_RESTART: aborting = hot_key_restart (); break;
210 case ZC_HKEY_QUIT: aborting = hot_key_quit (); break;
211 case ZC_HKEY_DEBUG: aborting = hot_key_debugging (); break;
212 }
213
214 if (aborting)
215 return TRUE;
216
217 }
218
219 return FALSE;
220
221}/* handle_hot_key */