The Battle for Wesnoth  1.17.17+dev
replay_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2023
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "play_controller.hpp"
18 #include "replay.hpp"
19 #include "mouse_handler_base.hpp" //events::command_disabler
20 
21 #include <vector>
22 
24 {
25 public:
27  {
28  public:
29  virtual void move_done() {}
30  virtual void new_side_turn(int , int ) {}
31  virtual bool should_stop() { return true; }
33  };
34  static void nop() {}
35  replay_controller(play_controller& controller, bool control_view, const std::shared_ptr<config>& reset_state, const std::function<void()>& on_end_replay = nop);
37 
38  // void reset_replay();
39  void play_replay();
40  void stop_replay();
41  void replay_next_turn();
42  void replay_next_side();
43  void replay_next_move();
44  void play_side_impl();
45 
46  bool recorder_at_end() const;
47  bool should_stop() const { return stop_condition_->should_stop(); }
48  bool can_execute_command(const hotkey::ui_command& cmd) const;
49  bool is_controlling_view() const {
50  return vision_.has_value();
51  }
52  bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
53  const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
54  void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
56  void replay_show_each();
57  void replay_show_team1();
58  void update_teams();
59  void update_viewing_player();
60  bool see_all();
61 private:
62  void add_replay_theme();
63  void init();
64  void update_gui();
65  void handle_generic_event(const std::string& name) override;
66 
67  /**
68  * Refresh the states of the replay-control buttons, this will cause the
69  * hotkey framework to query can_execute_command() for each button and then
70  * set the enabled/disabled state based on that query.
71  *
72  * The ids for the associated buttons are: "button-playreplay",
73  * "button-stopreplay", "button-resetreplay", "button-nextturn",
74  * "button-nextside", and "button-nextmove".
75  */
77 
79  std::unique_ptr<replay_stop_condition> stop_condition_;
81 
83  {
87  };
88  std::optional<REPLAY_VISION> vision_;
89  /// When the "Reset" button is pressed reset the gamestate to this
90  /// serialized gamestaten, the initial gamestate.
91  std::shared_ptr<config> reset_state_;
92  /// Called when there are no more moves in the [replay] to process
93  std::function<void()> on_end_replay_;
94  /// Used by unit tests.
96 };
replay_controller(play_controller &controller, bool control_view, const std::shared_ptr< config > &reset_state, const std::function< void()> &on_end_replay=nop)
bool recorder_at_end() const
std::optional< REPLAY_VISION > vision_
play_controller & controller_
void handle_generic_event(const std::string &name) override
bool is_controlling_view() const
const std::shared_ptr< config > & get_reset_state() const
void return_to_play_side(bool r=true)
events::command_disabler disabler_
std::shared_ptr< config > reset_state_
When the "Reset" button is pressed reset the gamestate to this serialized gamestaten,...
std::function< void()> on_end_replay_
Called when there are no more moves in the [replay] to process.
std::unique_ptr< replay_stop_condition > stop_condition_
bool can_execute_command(const hotkey::ui_command &cmd) const
bool should_stop() const
bool allow_reset_replay() const
bool return_to_play_side_
Used by unit tests.
void update_enabled_buttons()
Refresh the states of the replay-control buttons, this will cause the hotkey framework to query can_e...
Replay control code.
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...