The Battle for Wesnoth  1.19.0-dev
replay_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2024
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 "mouse_handler_base.hpp" //events::command_disabler
19 
20 
22 {
23 public:
25  {
26  public:
27  virtual void move_done() {}
28  virtual void new_side_turn(int , int ) {}
29  virtual bool should_stop() { return true; }
31  };
32  static void nop() {}
33  replay_controller(play_controller& controller, bool control_view, const std::shared_ptr<config>& reset_state, const std::function<void()>& on_end_replay = nop);
35 
36  // void reset_replay();
37  void play_replay();
38  void stop_replay();
39  void replay_next_turn();
40  void replay_next_side();
41  void replay_next_move();
42  void play_side_impl();
43 
44  bool recorder_at_end() const;
45  bool should_stop() const { return stop_condition_->should_stop(); }
46  bool can_execute_command(const hotkey::ui_command& cmd) const;
47  bool is_controlling_view() const {
48  return vision_.has_value();
49  }
50  bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
51  const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
52  void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
54  void replay_show_each();
55  void replay_show_team1();
56  void update_teams();
57  void update_viewing_player();
58  bool see_all();
59 private:
60  void add_replay_theme();
61  void init();
62  void update_gui();
63  void handle_generic_event(const std::string& name) override;
64 
65  /**
66  * Refresh the states of the replay-control buttons, this will cause the
67  * hotkey framework to query can_execute_command() for each button and then
68  * set the enabled/disabled state based on that query.
69  *
70  * The ids for the associated buttons are: "button-playreplay",
71  * "button-stopreplay", "button-resetreplay", "button-nextturn",
72  * "button-nextside", and "button-nextmove".
73  */
75 
77  std::unique_ptr<replay_stop_condition> stop_condition_;
79 
81  {
85  };
86  std::optional<REPLAY_VISION> vision_;
87  /// When the "Reset" button is pressed reset the gamestate to this
88  /// serialized gamestaten, the initial gamestate.
89  std::shared_ptr<config> reset_state_;
90  /// Called when there are no more moves in the [replay] to process
91  std::function<void()> on_end_replay_;
92  /// Used by unit tests.
94 };
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...
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...