The Battle for Wesnoth  1.17.0-dev
replay_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2021
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 
23 class video;
24 
26 {
27 public:
29  {
30  public:
31  virtual void move_done() {}
32  virtual void new_side_turn(int , int ) {}
33  virtual bool should_stop() { return true; }
35  };
36  static void nop() {}
37  replay_controller(play_controller& controller, bool control_view, const std::shared_ptr<config>& reset_state, const std::function<void()>& on_end_replay = nop);
39 
40  // void reset_replay();
41  void play_replay();
42  void stop_replay();
43  void replay_next_turn();
44  void replay_next_side();
45  void replay_next_move();
47 
48  bool recorder_at_end() const;
49  bool should_stop() const { return stop_condition_->should_stop(); }
50  bool can_execute_command(const hotkey::hotkey_command& cmd, int index) const;
51  bool is_controlling_view() const {
52  return vision_.has_value();
53  }
54  bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
55  const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
56  void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
58  void replay_show_each();
59  void replay_show_team1();
60  void update_teams();
61  void update_viewing_player();
62  bool see_all();
63 private:
64  void add_replay_theme();
65  void init();
66  void update_gui();
67  void handle_generic_event(const std::string& name) override;
68 
69  /**
70  * Refresh the states of the replay-control buttons, this will cause the
71  * hotkey framework to query can_execute_command() for each button and then
72  * set the enabled/disabled state based on that query.
73  *
74  * The ids for the associated buttons are: "button-playreplay",
75  * "button-stopreplay", "button-resetreplay", "button-nextturn",
76  * "button-nextside", and "button-nextmove".
77  */
79 
81  std::unique_ptr<replay_stop_condition> stop_condition_;
83 
85  {
89  };
90  std::optional<REPLAY_VISION> vision_;
91  std::shared_ptr<config> reset_state_;
92  std::function<void()> on_end_replay_;
94 };
std::function< void()> on_end_replay_
void return_to_play_side(bool r=true)
replay_controller(play_controller &controller, bool control_view, const std::shared_ptr< config > &reset_state, const std::function< void()> &on_end_replay=nop)
Stores all information related to functions that can be bound to hotkeys.
Replay control code.
events::command_disabler disabler_
bool recorder_at_end() const
void handle_generic_event(const std::string &name) override
REPLAY_RETURN
Definition: replay.hpp:156
std::unique_ptr< replay_stop_condition > stop_condition_
std::optional< REPLAY_VISION > vision_
void update_enabled_buttons()
Refresh the states of the replay-control buttons, this will cause the hotkey framework to query can_e...
REPLAY_RETURN play_side_impl()
bool allow_reset_replay() const
bool can_execute_command(const hotkey::hotkey_command &cmd, int index) const
const std::shared_ptr< config > & get_reset_state() const
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:72
play_controller & controller_
bool is_controlling_view() const
std::shared_ptr< config > reset_state_
bool should_stop() const