The Battle for Wesnoth  1.15.2+dev
replay_controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2018 by the Battle for Wesnoth Project
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include "play_controller.hpp"
17 #include "replay.hpp"
18 #include "mouse_handler_base.hpp" //events::command_disabler
19 
20 #include <vector>
21 
22 class video;
23 
25 {
26 public:
28  {
29  public:
30  virtual void move_done() {}
31  virtual void new_side_turn(int , int ) {}
32  virtual bool should_stop() { return true; }
34  };
35  static void nop() {}
36  replay_controller(play_controller& controller, bool control_view, const std::shared_ptr<config>& reset_state, const std::function<void()>& on_end_replay = nop);
38 
39  // void reset_replay();
40  void play_replay();
41  void stop_replay();
42  void replay_next_turn();
43  void replay_next_side();
44  void replay_next_move();
46 
47  bool recorder_at_end() const;
48  bool should_stop() const { return stop_condition_->should_stop(); }
49  bool can_execute_command(const hotkey::hotkey_command& cmd, int index) const;
50  bool is_controlling_view() const { return vision_.is_initialized(); }
51  bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
52  const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
53  void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
55  void replay_show_each();
56  void replay_show_team1();
57  void update_teams();
58  void update_viewing_player();
59  bool see_all();
60 private:
61  void add_replay_theme();
62  void init();
63  void update_gui();
64  void handle_generic_event(const std::string& name) override;
65 
66  /**
67  * Refresh the states of the replay-control buttons, this will cause the
68  * hotkey framework to query can_execute_command() for each button and then
69  * set the enabled/disabled state based on that query.
70  *
71  * The ids for the associated buttons are: "button-playreplay",
72  * "button-stopreplay", "button-resetreplay", "button-nextturn",
73  * "button-nextside", and "button-nextmove".
74  */
76 
78  std::unique_ptr<replay_stop_condition> stop_condition_;
80 
82  {
86  };
87  boost::optional<REPLAY_VISION> vision_;
88  std::shared_ptr<config> reset_state_;
89  std::function<void()> on_end_replay_;
91 };
std::function< void()> on_end_replay_
boost::optional< REPLAY_VISION > vision_
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:153
std::unique_ptr< replay_stop_condition > stop_condition_
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:71
play_controller & controller_
bool is_controlling_view() const
std::shared_ptr< config > reset_state_
bool should_stop() const