00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef MOUSE_EVENTS_H_INCLUDED
00017 #define MOUSE_EVENTS_H_INCLUDED
00018
00019 #include "global.hpp"
00020
00021 #include "actions.hpp"
00022 #include "game_display.hpp"
00023 #include "pathfind.hpp"
00024 #include "unit_map.hpp"
00025
00026 class gamestatus;
00027
00028 #include "SDL.h"
00029
00030 namespace events{
00031
00032 struct command_disabler
00033 {
00034 command_disabler();
00035 ~command_disabler();
00036 };
00037
00038 class mouse_handler{
00039 public:
00040 mouse_handler(game_display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
00041 gamestatus& status, undo_list& undo_stack, undo_list& redo_stack);
00042 ~mouse_handler();
00043 static mouse_handler* get_singleton() { return singleton_ ;}
00044 void set_team(const int team_number);
00045 void mouse_motion(const SDL_MouseMotionEvent& event, const bool browse);
00046
00047 void mouse_update(const bool browse);
00048 void mouse_press(const SDL_MouseButtonEvent& event, const bool browse);
00049 void cycle_units(const bool browse, const bool reverse = false);
00050 void cycle_back_units(const bool browse) { cycle_units(browse, true); }
00051
00052 int get_path_turns() const { return path_turns_; }
00053 paths get_current_paths() { return current_paths_; }
00054 const gamemap::location& get_last_hex() const { return last_hex_; }
00055 gamemap::location get_selected_hex() const { return selected_hex_; }
00056 bool get_undo() const { return undo_; }
00057 bool get_show_menu() const { return show_menu_; }
00058 void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
00059 void set_current_paths(paths new_paths);
00060 void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }
00061 void deselect_hex();
00062 void invalidate_reachmap() { reachmap_invalid_ = true; }
00063
00064 void set_gui(game_display* gui) { gui_ = gui; }
00065 void set_undo(const bool undo) { undo_ = undo; }
00066
00067 unit_map::iterator selected_unit();
00068 paths::route get_route(unit_map::const_iterator un, gamemap::location go_to, team &team);
00069 private:
00070 team& viewing_team() { return teams_[(*gui_).viewing_team()]; }
00071 const team& viewing_team() const { return teams_[(*gui_).viewing_team()]; }
00072 team& current_team() { return teams_[team_num_-1]; }
00073
00074
00075 void mouse_motion(int x, int y, const bool browse, bool update=false);
00076 bool is_left_click(const SDL_MouseButtonEvent& event);
00077 bool is_middle_click(const SDL_MouseButtonEvent& event);
00078 bool is_right_click(const SDL_MouseButtonEvent& event);
00079 void left_click(const SDL_MouseButtonEvent& event, const bool browse);
00080 void select_hex(const gamemap::location& hex, const bool browse);
00081 void clear_undo_stack();
00082 bool move_unit_along_current_route(bool check_shroud, bool attackmove=false);
00083
00084 bool attack_enemy(unit_map::iterator attacker, unit_map::iterator defender);
00085
00086 bool attack_enemy_(unit_map::iterator attacker, unit_map::iterator defender);
00087 void show_attack_options(unit_map::const_iterator u);
00088 gamemap::location current_unit_attacks_from(const gamemap::location& loc);
00089 unit_map::const_iterator find_unit(const gamemap::location& hex) const;
00090 unit_map::iterator find_unit(const gamemap::location& hex);
00091 bool unit_in_cycle(unit_map::const_iterator it);
00092
00093 game_display* gui_;
00094 std::vector<team>& teams_;
00095 unit_map& units_;
00096 gamemap& map_;
00097 gamestatus& status_;
00098 undo_list& undo_stack_;
00099 undo_list& redo_stack_;
00100
00101 bool minimap_scrolling_;
00102 bool dragging_;
00103 bool dragging_started_;
00104 int drag_from_x_;
00105 int drag_from_y_;
00106
00107
00108 gamemap::location last_hex_;
00109
00110
00111 gamemap::location previous_hex_;
00112 gamemap::location previous_free_hex_;
00113 gamemap::location selected_hex_;
00114 gamemap::location next_unit_;
00115 paths::route current_route_;
00116 paths current_paths_;
00117 bool enemy_paths_;
00118 int path_turns_;
00119 unsigned int team_num_;
00120
00121
00122
00123 bool enemies_visible_;
00124 bool undo_;
00125 bool show_menu_;
00126 bool over_route_;
00127 bool attackmove_;
00128 bool reachmap_invalid_;
00129 bool show_partial_move_;
00130
00131 static mouse_handler * singleton_;
00132 };
00133
00134 extern int commands_disabled;
00135 }
00136
00137 #endif