2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <glib/gi18n.h>
22 #include "framework/commands.hpp"
23 #include "framework/gameactivity.hpp"
24 #include "framework/replaysaveractivity.hpp"
25 #include "framework/showtextactivity.hpp"
26 #include "gfx/screen.hpp"
27 #include "gfx/fontmanager.hpp"
28 #include "cave/gamecontrol.hpp"
29 #include "misc/printf.hpp"
30 #include "misc/util.hpp"
31 #include "cave/cavestored.hpp"
32 #include "cave/caveset.hpp"
33 #include "framework/replaymenuactivity.hpp"
35 ReplayMenuActivity::ReplayMenuActivity(App
*app
)
38 lines_per_page
= (app
->screen
->get_height() / app
->font_manager
->get_line_height()) - 5;
41 for (unsigned n
=0; n
<app
->caveset
->caves
.size(); ++n
) {
42 CaveStored
&cave
=app
->caveset
->cave(n
);
44 /* if cave has replays... */
45 if (!cave
.replays
.empty()) {
46 /* add an empty item as separator */
48 ReplayItem i
= { NULL
, NULL
};
52 ReplayItem i
= { &cave
, NULL
};
54 /* add replays, too */
55 for (std::list
<CaveReplay
>::iterator rit
=cave
.replays
.begin(); rit
!=cave
.replays
.end(); ++rit
) {
56 // .cave unchanged, .replay is the address of the replay
66 void ReplayMenuActivity::pushed_event() {
68 app
->enqueue_command(new PopActivityCommand(app
)); // pop myself
69 // TRANSLATORS: 40 chars max
70 app
->enqueue_command(new PushActivityCommand(app
, new ShowTextActivity(app
, _("Replays"), _("No replays for caveset."), SmartPtr
<Command
>())));
74 void ReplayMenuActivity::redraw_event() {
77 int page
=current
/lines_per_page
;
78 // TRANSLATORS: 40 chars max
79 app
->title_line(CPrintf(_("Replays, Page %d/%d")) % (page
+1) % (items
.size()/lines_per_page
+1));
80 // TRANSLATORS: 40 chars max
81 app
->status_line(_("Space: play F1: keys Esc: exit"));
83 for (unsigned n
=0; n
<lines_per_page
&& page
*lines_per_page
+n
<items
.size(); n
++) {
84 unsigned pos
=page
*lines_per_page
+n
;
86 int y
= (n
+2) * app
->font_manager
->get_line_height();
88 if (items
[pos
].cave
&& !items
[pos
].replay
) {
89 /* no replay pointer: this is a cave, so write its name. */
90 app
->set_color(GD_GDASH_WHITE
);
91 app
->blittext_n(0, y
, CPrintf(" %s") % items
[pos
].cave
->name
);
93 if (items
[pos
].replay
) {
94 /* level, successful/not, saved/not, player name */
95 app
->blittext_n(0, y
, CPrintf(" %c%c %c%c %cL%d, %s")
96 % GD_COLOR_INDEX_LIGHTBLUE
% (items
[pos
].replay
->saved
?GD_CHECKED_BOX_CHAR
:GD_UNCHECKED_BOX_CHAR
)
97 % (items
[pos
].replay
->success
?GD_COLOR_INDEX_GREEN
:GD_COLOR_INDEX_RED
) % GD_BALL_CHAR
98 % (current
==pos
? GD_COLOR_INDEX_YELLOW
: GD_COLOR_INDEX_GRAY3
)
99 % items
[pos
].replay
->level
% items
[pos
].replay
->player_name
);
107 /* the replay saver thing only works in the sdl version */
110 class SaveReplayCommand
: public Command1Param
<std::string
> {
112 SaveReplayCommand(App
*app
, CaveStored
*cave
, CaveReplay
*replay
)
114 Command1Param
<std::string
>(app
),
121 std::string
&filename_prefix
;
125 app
->enqueue_command(new PushActivityCommand(app
, new ReplaySaverActivity(app
, cave
, replay
, filename_prefix
)));
129 #endif /* IFDEF HAVE_SDL */
132 void ReplayMenuActivity::keypress_event(KeyCode keycode
, int gfxlib_keycode
) {
133 /* these keys are active also when there are replays and when there aren't any. */
138 _("Cursor keys"), _("Move"),
139 // TRANSLATORS: play here means playing the replay movie
140 _("Space, Enter"), _("Play"),
141 "I", _("Show replay info"),
143 // TRANSLATORS: this is for a checkbox which selects if the replays is to be saved with the cave or not.
144 "S", _("Toggle if saved with caves"),
145 /* the replay saver thing only works in the sdl version */
147 "W", _("Save movie"),
148 #endif /* IFDEF HAVE_SDL */
150 "ESC", _("Main menu"),
153 // TRANSLATORS: title of the cave replays window
154 app
->show_text_and_do_command(_("Replays Help"), help_strings_to_string(help
));
158 app
->enqueue_command(new PopActivityCommand(app
));
162 /* if no replays, the keys below should be inactive. so return. */
170 current
= gd_clamp(current
-1, 1, items
.size()-1);
171 } while (items
[current
].replay
==NULL
&& current
>=1);
176 current
= gd_clamp(current
+1, 1, items
.size()-1);
177 } while (items
[current
].replay
==NULL
&& current
<items
.size());
181 current
= gd_clamp(current
-lines_per_page
, 0, items
.size()-1);
185 current
= gd_clamp(current
+lines_per_page
, 0, items
.size()-1);
192 CaveReplay
*r
= items
[current
].replay
;
193 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Cave") % GD_COLOR_INDEX_YELLOW
% items
[current
].cave
->name
;
194 // TRANSLATORS: Cave level (1-5)
195 s
+= SPrintf("%c%s: %c%d\n") % GD_COLOR_INDEX_WHITE
% _("Level") % GD_COLOR_INDEX_YELLOW
% r
->level
;
196 // TRANSLATORS: "player" here means the name of the human player who played the replay
197 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Player") % GD_COLOR_INDEX_YELLOW
% r
->player_name
;
198 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Successful") % GD_COLOR_INDEX_LIGHTBLUE
% (r
->success
? _("yes") : _("no"));
199 s
+= SPrintf("%c%s: %c%d %s\n") % GD_COLOR_INDEX_WHITE
% _("Score") % GD_COLOR_INDEX_LIGHTBLUE
% r
->score
% _("points");
201 if (r
->comment
!= "")
202 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Comment") % GD_COLOR_INDEX_LIGHTBLUE
% r
->comment
;
203 if (r
->duration
> 0) {
204 // TRANSLATORS: duration of replay in seconds
205 s
+= SPrintf("%c%s: %c%ds\n") % GD_COLOR_INDEX_WHITE
% _("Duration") % GD_COLOR_INDEX_LIGHTBLUE
% r
->duration
;
208 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Date") % GD_COLOR_INDEX_LIGHTBLUE
% r
->date
;
209 if (r
->recorded_with
!= "")
210 // TRANSLATORS: ie. software by which the replay was recorded.
211 s
+= SPrintf("%c%s: %c%s\n") % GD_COLOR_INDEX_WHITE
% _("Recorded with") % GD_COLOR_INDEX_LIGHTBLUE
% r
->recorded_with
;
213 // TRANSLATORS: title of the window showing data about a particular replay
214 app
->show_message(_("Replay Info"), s
);
219 if (items
[current
].replay
) {
220 items
[current
].replay
->saved
=!items
[current
].replay
->saved
;
221 app
->caveset
->edited
= true;
225 /* the replay saver thing only works in the sdl version */
230 std::string prefix
= SPrintf("%s%sout") % gd_last_folder
% G_DIR_SEPARATOR
;
231 // TRANSLATE: the prefix of the name of the output files when saving the replay.
232 app
->input_text_and_do_command(_("Output filename prefix"), prefix
.c_str(), new SaveReplayCommand(app
, items
[current
].cave
, items
[current
].replay
));
235 #endif /* IFDEF HAVE_SDL */
238 if (items
[current
].replay
) {
239 GameControl
*game
= GameControl::new_replay(app
->caveset
, items
[current
].cave
, items
[current
].replay
);
240 app
->enqueue_command(new PushActivityCommand(app
, new GameActivity(app
, game
)));