The Battle for Wesnoth  1.15.12+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 {
51  return vision_.has_value();
52  }
53  bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
54  const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
55  void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
57  void replay_show_each();
58  void replay_show_team1();
59  void update_teams();
60  void update_viewing_player();
61  bool see_all();
62 private:
63  void add_replay_theme();
64  void init();
65  void update_gui();
66  void handle_generic_event(const std::string& name) override;
67 
68  /**
69  * Refresh the states of the replay-control buttons, this will cause the
70  * hotkey framework to query can_execute_command() for each button and then
71  * set the enabled/disabled state based on that query.
72  *
73  * The ids for the associated buttons are: "button-playreplay",
74  * "button-stopreplay", "button-resetreplay", "button-nextturn",
75  * "button-nextside", and "button-nextmove".
76  */
78 
80  std::unique_ptr<replay_stop_condition> stop_condition_;
82 
84  {
88  };
89  std::optional<REPLAY_VISION> vision_;
90  std::shared_ptr<config> reset_state_;
91  std::function<void()> on_end_replay_;
93 };
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:155
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:71
play_controller & controller_
bool is_controlling_view() const
std::shared_ptr< config > reset_state_
bool should_stop() const