Skip to content

Commit

Permalink
Merge remote-tracking branch 'zappaman/replay_single_move'
Browse files Browse the repository at this point in the history
Conflicts:
	RELEASE_NOTES
  • Loading branch information
cbeck88 committed Aug 29, 2014
2 parents ff2cc6b + 4302249 commit d4723a7
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 21 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES
Expand Up @@ -39,6 +39,10 @@ Version 1.11.7 (check this) from just before feature freeze introduced a "carryo
Another point raised in internal discussion is that it would probably be more useful if this feature applied before random map generation occurred, which when it was first implemented wasn't how it worked. Since there are many changes planned to this scenario generation code path, for instance the merging of mp and sp, and this feature adds a fair bit of complication, we decided to shelf it and perhaps rethink it later.
[/section]

[section="play single move button in replay mode"]
A button that allows playing one move at a time in replay mode has been added.
[/section]

[section="Example section 2"]
Example contents 2.
[/section]
Expand Down
2 changes: 2 additions & 0 deletions changelog
Expand Up @@ -76,6 +76,8 @@ Version 1.13.0-dev:
* Fixed bug #22045: Only blit neutral surfaces.
* [item] images are now subject to local ToD lighting effects instead of
just the current map-wide ToD lighting (bug #22215).
* Replays:
* Added a button that allows playing a single move in replay mode.
* Units:
* Increased the experience requirement for the Rami from 32 to 39
* Increased the experience requirement for the Saree from 56 to 64
Expand Down
33 changes: 31 additions & 2 deletions data/themes/macros.cfg
Expand Up @@ -465,10 +465,25 @@
yanchor=fixed
[/action]
[/add]
[add]
[action]
id=button-nextmove
ref=button-nextside
type=image
image=button_square/button_square_30
overlay=icons/action/play_move_30
title= _ "Next Move"
tooltip= _ "play single move"
items=replaynextmove
rect="+4,=,+23,="
xanchor=fixed
yanchor=fixed
[/action]
[/add]
[add]
[menu]
id=show-what
ref=button-nextside
ref=button-nextmove
image=button_normal/button_H22
title= _ "Point of view"
items=replayshowteam1,replayshoweach,replayshoweverything
Expand Down Expand Up @@ -591,10 +606,24 @@
yanchor=fixed
[/action]
[/add]
[add]
[action]
id=button-nextmove
ref=button-nextside
type=image
image=classic/play-move
title= _ "Next Move"
tooltip= _ "play single move"
items=replaynextmove
rect="+4,=,+23,="
xanchor=fixed
yanchor=fixed
[/action]
[/add]
[add]
[menu]
id=show-what
ref=button-nextside
ref=button-nextmove
image=classic/lite
title= _ "Point of view"
items=replayshowteam1,replayshoweach,replayshoweverything
Expand Down
Binary file added images/buttons/classic/play_move-active.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/buttons/classic/play_move-pressed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/buttons/classic/play_move.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/action/play_move_30-active.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/action/play_move_30-pressed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/action/play_move_30.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions players_changelog
Expand Up @@ -32,6 +32,9 @@ Version 1.13.0-dev:
* Updated translations: Czech, French, German, Greek, Hungarian, Italian,
Lithuanian, Scottish Gaelic, Slovak, Vietnamese.

* Replays:
* Added a button that allows playing a single move in replay mode.

* Units:
* Increased the experience requirement for the Rami from 32 to 39.
* Increased the experience requirement for the Saree from 56 to 64.
Expand Down
3 changes: 3 additions & 0 deletions src/hotkey/command_executor.cpp
Expand Up @@ -209,6 +209,9 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
case HOTKEY_REPLAY_NEXT_SIDE:
replay_next_side();
break;
case HOTKEY_REPLAY_NEXT_MOVE:
replay_next_move();
break;
case HOTKEY_REPLAY_SHOW_EVERYTHING:
replay_show_everything();
break;
Expand Down
1 change: 1 addition & 0 deletions src/hotkey/command_executor.hpp
Expand Up @@ -84,6 +84,7 @@ class command_executor
virtual void stop_replay() {}
virtual possible_end_play_signal replay_next_turn() { return boost::none; }
virtual possible_end_play_signal replay_next_side() { return boost::none; }
virtual possible_end_play_signal replay_next_move() { return boost::none; }
virtual void replay_show_everything() {}
virtual void replay_show_each() {}
virtual void replay_show_team1() {}
Expand Down
1 change: 1 addition & 0 deletions src/hotkey/hotkey_command.cpp
Expand Up @@ -100,6 +100,7 @@ hotkey::hotkey_command_temp hotkey_list_[] = {
{ hotkey::HOTKEY_REPLAY_STOP, "stopreplay", N_("Stop Replay"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_NEXT_TURN, "replaynextturn", N_("Next Turn"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_NEXT_SIDE, "replaynextside", N_("Next Side"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_NEXT_MOVE, "replaynextmove", N_("Next Move"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING, "replayshoweverything", N_("Full Map"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_SHOW_EACH, "replayshoweach", N_("Each Team"), false, scope_game, "" },
{ hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1", N_("Team 1"), false, scope_game, "" },
Expand Down
2 changes: 1 addition & 1 deletion src/hotkey/hotkey_command.hpp
Expand Up @@ -56,7 +56,7 @@ enum HOTKEY_COMMAND {

// Replay
HOTKEY_REPLAY_PLAY, HOTKEY_REPLAY_RESET, HOTKEY_REPLAY_STOP, HOTKEY_REPLAY_NEXT_TURN,
HOTKEY_REPLAY_NEXT_SIDE, HOTKEY_REPLAY_SHOW_EVERYTHING,
HOTKEY_REPLAY_NEXT_SIDE, HOTKEY_REPLAY_NEXT_MOVE, HOTKEY_REPLAY_SHOW_EVERYTHING,
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
HOTKEY_REPLAY_SKIP_ANIMATION,

Expand Down
9 changes: 6 additions & 3 deletions src/replay.cpp
Expand Up @@ -715,7 +715,7 @@ static void show_oos_error_error_function(const std::string& message, bool /*hea
replay::process_error(message);
}

REPLAY_RETURN do_replay()
REPLAY_RETURN do_replay(bool one_move)
{
log_scope("do replay");

Expand All @@ -724,10 +724,10 @@ REPLAY_RETURN do_replay()
}

update_locker lock_update(resources::screen->video(),get_replay_source().is_skipping());
return do_replay_handle();
return do_replay_handle(one_move);
}

REPLAY_RETURN do_replay_handle()
REPLAY_RETURN do_replay_handle(bool one_move)
{

//team &current_team = (*resources::teams)[side_num - 1];
Expand Down Expand Up @@ -909,6 +909,9 @@ REPLAY_RETURN do_replay_handle()
we need to use the undo stack during replays in order to make delayed shroud updated work.
*/
synced_context::run_in_synced_context(commandname, data, true, !get_replay_source().is_skipping(), false,show_oos_error_error_function);
if (one_move) {
return REPLAY_FOUND_END_MOVE;
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/replay.hpp
Expand Up @@ -165,13 +165,14 @@ enum REPLAY_RETURN
{
REPLAY_RETURN_AT_END,
REPLAY_FOUND_DEPENDENT,
REPLAY_FOUND_END_TURN
REPLAY_FOUND_END_TURN,
REPLAY_FOUND_END_MOVE
};
//replays up to one turn from the recorder object
//returns true if it got to the end of the turn without data running out
REPLAY_RETURN do_replay();
REPLAY_RETURN do_replay(bool one_move = false);

REPLAY_RETURN do_replay_handle();
REPLAY_RETURN do_replay_handle(bool one_move = false);

class replay_network_sender
{
Expand Down
61 changes: 49 additions & 12 deletions src/replay_controller.cpp
Expand Up @@ -140,7 +140,8 @@ replay_controller::~replay_controller()

void replay_controller::init(){
DBG_REPLAY << "in replay_controller::init()...\n";


last_replay_action = REPLAY_FOUND_END_MOVE;
//guarantee the cursor goes back to 'normal' at the end of the level
const cursor::setter cursor_setter(cursor::NORMAL);
init_replay_display();
Expand Down Expand Up @@ -211,14 +212,19 @@ gui::button* replay_controller::play_side_button()
return gui_->find_action_button("button-nextside");
}

gui::button* replay_controller::play_move_button()
{
return gui_->find_action_button("button-nextmove");
}

void replay_controller::update_replay_ui()
{
//check if we have all buttons - if someone messed with theme then some buttons may be missing
//if any of the buttons is missing, we just disable every one
if(!replay_ui_has_all_buttons()) {
gui::button *play_b = play_button(), *stop_b = stop_button(),
*reset_b = reset_button(), *play_turn_b = play_turn_button(),
*play_side_b = play_side_button();
*play_side_b = play_side_button(), *play_move_b = play_move_button();

if(play_b) {
play_b->enable(false);
Expand All @@ -239,6 +245,10 @@ void replay_controller::update_replay_ui()
if(play_side_b) {
play_side_b->enable(false);
}

if (play_move_b) {
play_move_b->enable(false);
}
}
}

Expand All @@ -251,6 +261,7 @@ void replay_controller::replay_ui_playback_should_start()
reset_button()->enable(false);
play_turn_button()->enable(false);
play_side_button()->enable(false);
play_move_button()->enable(false);
}

void replay_controller::replay_ui_playback_should_stop()
Expand All @@ -263,10 +274,12 @@ void replay_controller::replay_ui_playback_should_stop()
reset_button()->enable(true);
play_turn_button()->enable(true);
play_side_button()->enable(true);
play_move_button()->enable(true);

play_button()->release();
play_turn_button()->release();
play_side_button()->release();
play_move_button()->release();
} else {
reset_button()->enable(true);
stop_button()->enable(false);
Expand Down Expand Up @@ -377,23 +390,32 @@ possible_end_play_signal replay_controller::replay_next_turn(){
return boost::none;
}

possible_end_play_signal replay_controller::replay_next_side(){
possible_end_play_signal replay_controller::replay_next_move_or_side(bool one_move){
is_playing_ = true;
replay_ui_playback_should_start();

HANDLE_END_PLAY_SIGNAL( play_side() );
HANDLE_END_PLAY_SIGNAL( play_move_or_side(one_move) );
while (current_team().is_empty()) {
HANDLE_END_PLAY_SIGNAL( play_side() );
HANDLE_END_PLAY_SIGNAL( play_move_or_side(one_move) );
}

if (!skip_replay_ || !is_playing_) {
if ( (!skip_replay_ || !is_playing_) && (last_replay_action == REPLAY_FOUND_END_TURN) ){
gui_->scroll_to_leader(player_number_,game_display::ONSCREEN,false);
}

replay_ui_playback_should_stop();
return boost::none;
}

possible_end_play_signal replay_controller::replay_next_side(){
return replay_next_move_or_side(false);
}

possible_end_play_signal replay_controller::replay_next_move(){
return replay_next_move_or_side(true);
}


void replay_controller::process_oos(const std::string& msg) const
{
if (game_config::ignore_replay_errors) {
Expand Down Expand Up @@ -499,9 +521,18 @@ possible_end_play_signal replay_controller::play_turn(){
return boost::none;
}

//make only one side move

possible_end_play_signal replay_controller::play_side() {
return play_move_or_side(false);
}

possible_end_play_signal replay_controller::play_move() {
return play_move_or_side(true);
}

//make only one side move
possible_end_play_signal replay_controller::play_move_or_side(bool one_move) {

DBG_REPLAY << "Status turn number: " << turn() << "\n";
DBG_REPLAY << "Replay_Controller turn number: " << current_turn_ << "\n";
DBG_REPLAY << "Player number: " << player_number_ << "\n";
Expand All @@ -510,7 +541,10 @@ possible_end_play_signal replay_controller::play_side() {
if (!current_team().is_empty()) {
statistics::reset_turn_stats(current_team().save_id());

possible_end_play_signal signal = play_controller::init_side(true);
possible_end_play_signal signal = NULL;
if (last_replay_action == REPLAY_FOUND_END_TURN) {
signal = play_controller::init_side(true);
}

if (signal) {
switch (boost::apply_visitor(get_signal_type(), *signal) ) {
Expand All @@ -526,10 +560,12 @@ possible_end_play_signal replay_controller::play_side() {
DBG_REPLAY << "doing replay " << player_number_ << "\n";
// if have reached the end we don't want to execute finish_side_turn and finish_turn
// becasue we might not have enough data to execute them (like advancements during turn_end for example)

try {
if(do_replay() != REPLAY_FOUND_END_TURN) {
// We reached the end of teh replay without finding and end turn tag.
last_replay_action = do_replay(one_move);
if(last_replay_action != REPLAY_FOUND_END_TURN) {
//We reached the end of the replay without finding an end turn tag.
//REPLAY_FOUND_DEPENDENT here might indicate an OOS error
return boost::none;
}
} catch(end_level_exception& e){
Expand Down Expand Up @@ -640,6 +676,7 @@ bool replay_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
case hotkey::HOTKEY_REPLAY_PLAY:
case hotkey::HOTKEY_REPLAY_NEXT_TURN:
case hotkey::HOTKEY_REPLAY_NEXT_SIDE:
case hotkey::HOTKEY_REPLAY_NEXT_MOVE:
//we have one events_disabler when starting the replay_controller and a second when entering the synced context.
return (events::commands_disabled <= 1 ) && !recorder.at_end();
default:
Expand Down
6 changes: 6 additions & 0 deletions src/replay_controller.hpp
Expand Up @@ -39,8 +39,10 @@ class replay_controller : public play_controller
possible_end_play_signal play_replay();
void reset_replay();
void stop_replay();
possible_end_play_signal replay_next_move_or_side(bool one_move);
possible_end_play_signal replay_next_turn();
possible_end_play_signal replay_next_side();
possible_end_play_signal replay_next_move();
void process_oos(const std::string& msg) const;
void replay_show_everything();
void replay_show_each();
Expand All @@ -60,7 +62,9 @@ class replay_controller : public play_controller
private:
void init();
possible_end_play_signal play_turn();
possible_end_play_signal play_move_or_side(bool one_move = false);
possible_end_play_signal play_side();
possible_end_play_signal play_move();
void update_teams();
void update_gui();
void init_replay_display();
Expand All @@ -80,6 +84,7 @@ class replay_controller : public play_controller
gui::button* reset_button();
gui::button* play_turn_button();
gui::button* play_side_button();
gui::button* play_move_button();

bool replay_ui_has_all_buttons() {
return play_button() && stop_button() && reset_button() &&
Expand All @@ -89,6 +94,7 @@ class replay_controller : public play_controller
saved_game saved_game_start_;
game_board gameboard_start_;
tod_manager tod_manager_start_;
unsigned int last_replay_action;

unsigned int current_turn_;
bool is_playing_;
Expand Down

0 comments on commit d4723a7

Please sign in to comment.