Prepare new maemo release
[maemo-rb.git] / apps / plugins / frotz / hotkey.c
blobd214f1f322e12ff129390677fb08f45828e10c69
1 /* hotkey.c - Hot key functions
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * Changes for Rockbox copyright 2009 Torne Wuff
6 * This file is part of Frotz.
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.
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.
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
23 #include "frotz.h"
24 #include "lib/pluginlib_exit.h"
26 extern int restore_undo (void);
28 extern int read_number (void);
30 extern bool read_yes_or_no (const char *);
32 extern void replay_open (void);
33 extern void replay_close (void);
34 extern void record_open (void);
35 extern void record_close (void);
37 extern void seed_random (int);
40 * hot_key_debugging
42 * ...allows user to toggle cheating options on/off.
46 static bool hot_key_debugging (void)
49 f_setup.attribute_assignment = read_yes_or_no ("Watch attribute assignment");
50 f_setup.attribute_testing = read_yes_or_no ("Watch attribute testing");
52 f_setup.object_movement = read_yes_or_no ("Watch object movement");
53 f_setup.object_locating = read_yes_or_no ("Watch object locating");
55 return FALSE;
57 }/* hot_key_debugging */
60 * hot_key_playback
62 * ...allows user to turn playback on.
66 static bool hot_key_playback (void)
69 rb->splash(HZ, "Playback on");
71 if (!istream_replay)
72 replay_open ();
74 return FALSE;
76 }/* hot_key_playback */
79 * hot_key_recording
81 * ...allows user to turn recording on/off.
85 static bool hot_key_recording (void)
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 ();
99 return FALSE;
101 }/* hot_key_recording */
104 * hot_key_seed
106 * ...allows user to seed the random number seed.
110 static bool hot_key_seed (void)
113 print_string ("Enter seed value (or return to randomize): ");
114 seed_random (read_number ());
116 return FALSE;
118 }/* hot_key_seed */
121 * hot_key_undo
123 * ...allows user to undo the previous turn.
127 static bool hot_key_undo (void)
130 if (restore_undo ()) {
132 print_string ("undo\n");
134 if (h_version >= V5) { /* for V5+ games we must */
135 store (2); /* store 2 (for success) */
136 return TRUE; /* and abort the input */
139 if (h_version <= V3) { /* for V3- games we must */
140 z_show_status (); /* draw the status line */
141 return FALSE; /* and continue input */
144 } else rb->splash(HZ, "No undo information available.");
146 return FALSE;
148 }/* hot_key_undo */
151 * hot_key_restart
153 * ...allows user to start a new game.
157 static bool hot_key_restart (void)
160 if (read_yes_or_no ("Do you wish to restart")) {
162 z_restart ();
163 return TRUE;
165 } else return FALSE;
167 }/* hot_key_restart */
170 * hot_key_quit
172 * ...allows user to exit the game.
176 bool hot_key_quit (void)
179 if (read_yes_or_no ("Do you wish to quit")) {
181 exit(0);
183 } else return FALSE;
185 }/* hot_key_quit */
188 * handle_hot_key
190 * Perform the action associated with a so-called hot key. Return
191 * true to abort the current input action.
195 bool handle_hot_key (zchar key)
198 if (cwin == 0) {
200 bool aborting;
202 aborting = FALSE;
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;
214 if (aborting)
215 return TRUE;
219 return FALSE;
221 }/* handle_hot_key */