menu_events.hpp

Go to the documentation of this file.
00001 /* $Id: menu_events.hpp 26242 2008-04-30 03:52:10Z alink $ */
00002 /*
00003    Copyright (C) 2006 - 2008 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
00004    wesnoth playturn Copyright (C) 2003 by David White <dave@whitevine.net>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License version 2
00009    or at your option any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef MENU_EVENTS_H_INCLUDED
00017 #define MENU_EVENTS_H_INCLUDED
00018 
00019 #include "global.hpp"
00020 
00021 #include "show_dialog.hpp"
00022 #include "display.hpp"
00023 #include "floating_textbox.hpp"
00024 #include "mouse_events.hpp"
00025 #include "statistics.hpp"
00026 #include "widgets/textbox.hpp"
00027 
00028 class game_state;
00029 class gamestatus;
00030 
00031 enum LEVEL_RESULT { VICTORY, DEFEAT, QUIT, LEVEL_CONTINUE, LEVEL_CONTINUE_NO_SAVE, OBSERVER_END, SKIP_TO_LINGER };
00032 
00033 #define DELAY_END_LEVEL(end_ptr, code) try { \
00034     code; \
00035     } catch ( end_level_exception &e) { \
00036         if (end_ptr == 0) { \
00037             end_ptr = new end_level_exception(e); \
00038         } \
00039     }
00040 
00041 #define THROW_END_LEVEL_DELETE(end_ptr) if (end_ptr) {\
00042     end_level_exception temp_exception(*end_ptr);\
00043     delete end_ptr; \
00044     throw temp_exception; \
00045     }
00046 
00047 #define THROW_END_LEVEL(end_ptr) if (end_ptr) {\
00048     throw end_level_exception(*end_ptr); \
00049     }
00050 
00051 struct end_level_exception {
00052     end_level_exception(LEVEL_RESULT res, const int percentage = -1,
00053             const bool add = false, const bool bonus=true) :
00054         result(res),
00055         gold_bonus(bonus),
00056         carryover_percentage(percentage),
00057         carryover_add(add)
00058     {}
00059 
00060     LEVEL_RESULT result;
00061     bool gold_bonus;
00062     int carryover_percentage;
00063     bool carryover_add;
00064 };
00065 
00066 struct end_turn_exception {
00067     end_turn_exception(unsigned int r = 0): redo(r) {}
00068     unsigned int redo;
00069 };
00070 
00071 namespace events{
00072 
00073 class chat_handler {
00074 public:
00075     chat_handler();
00076     virtual ~chat_handler();
00077 
00078 protected:
00079     void do_speak(const std::string& message, bool allies_only=false);
00080 
00081     //called from do_speak
00082     virtual void add_chat_message(const time_t& time,
00083             const std::string& speaker, int side, const std::string& message,
00084             game_display::MESSAGE_TYPE type=game_display::MESSAGE_PRIVATE)=0;
00085     virtual void send_chat_message(const std::string& message, bool allies_only=false)=0;
00086     void send_command(const std::string& cmd, const std::string& args="");
00087     void change_logging(const std::string& data);
00088     friend class chat_command_handler;
00089 };
00090 
00091 class menu_handler : private chat_handler {
00092 public:
00093     menu_handler(game_display* gui, unit_map& units, std::vector<team>& teams,
00094         const config& level, const gamemap& map,
00095         const config& game_config, const gamestatus& status, game_state& gamestate,
00096         undo_list& undo_stack, undo_list& redo_stack);
00097     virtual ~menu_handler();
00098 
00099     const undo_list& get_undo_list() const;
00100     gui::floating_textbox& get_textbox();
00101     void set_gui(game_display* gui) { gui_ = gui; }
00102 
00103     std::string get_title_suffix(int team_num);
00104     void objectives(const unsigned int team_num);
00105     void show_statistics(const unsigned int team_num);
00106     void unit_list();
00107     void status_table(int selected=0);
00108     void save_game(const std::string& message, gui::DIALOG_TYPE dialog_type, const bool has_exit_button=false, const bool replay=false);
00109     void save_map();
00110     void load_game();
00111     void preferences();
00112     void show_chat_log();
00113     void show_help();
00114     void speak();
00115     void whisper();
00116     void shout();
00117     void recruit(const bool browse, const unsigned int team_num, const gamemap::location& last_hex);
00118     void repeat_recruit(const unsigned int team_num, const gamemap::location& last_hex);
00119     void recall(const unsigned int team_num, const gamemap::location& last_hex);
00120     void undo(const unsigned int team_num);
00121     void redo(const unsigned int team_num);
00122     void show_enemy_moves(bool ignore_units, const unsigned int team_num);
00123     void toggle_shroud_updates(const unsigned int team_num);
00124     void update_shroud_now(const unsigned int team_num);
00125     bool end_turn(const unsigned int team_num);
00126     void goto_leader(const unsigned int team_num);
00127     void unit_description(mouse_handler& mousehandler);
00128     void rename_unit(mouse_handler& mousehandler);
00129     void create_unit(mouse_handler& mousehandler);
00130     void change_unit_side(mouse_handler& mousehandler);
00131     void label_terrain(mouse_handler& mousehandler, bool team_only);
00132     void clear_labels();
00133     void continue_move(mouse_handler& mousehandler, const unsigned int team_num);
00134     void toggle_grid();
00135     void unit_hold_position(mouse_handler& mousehandler, const unsigned int team_num);
00136     void end_unit_turn(mouse_handler& mousehandler, const unsigned int team_num);
00137     void search();
00138     void user_command();
00139     void custom_command(mouse_handler& mousehandler, const unsigned int team_num);
00140     void ai_formula();
00141     void clear_messages();
00142 #ifdef USRCMD2
00143     void user_command_2();
00144     void user_command_3();
00145 #endif
00146 
00147     unit_map::iterator current_unit(mouse_handler& mousehandler);
00148     unit_map::const_iterator current_unit(const mouse_handler& mousehandler) const;
00149     void move_unit_to_loc(const unit_map::const_iterator& ui, const gamemap::location& target,
00150         bool continue_move, const unsigned int team_num, mouse_handler& mousehandler);
00151     void do_speak();
00152     void do_search(const std::string& new_search);
00153     void do_command(const std::string& str, const unsigned int team_num, mouse_handler& mousehandler);
00154     void do_ai_formula(const std::string& str, const unsigned int team_num, mouse_handler& mousehandler);
00155     void clear_undo_stack(const unsigned int team_num);
00156     void autosave(const std::string &label, unsigned turn, const config &starting_pos) const;
00157     bool has_team() const;
00158 protected:
00159     void add_chat_message(const time_t& time, const std::string& speaker,
00160             int side, const std::string& message,
00161             game_display::MESSAGE_TYPE type=game_display::MESSAGE_PRIVATE);
00162     void send_chat_message(const std::string& message, bool allies_only=false);
00163 private:
00164     //console_handler is basically a sliced out part of menu_handler
00165     //and as such needs access to menu_handler's privates
00166     friend class console_handler;
00167                 
00168     //void do_speak(const std::string& message, bool allies_only);
00169     void do_recruit(const std::string& name, const unsigned int team_num, const gamemap::location& last_hex);
00170 //  std::vector<std::string> create_unit_table(const statistics::stats::str_int_map& m,unsigned int team);
00171     void write_game_snapshot(config& start) const;
00172     bool has_friends() const;
00173     bool clear_shroud(const unsigned int team_num);
00174     static void change_side_controller(const std::string& side, const std::string& player, bool own_side=false);
00175     void scenario_settings_table(int selected=0);
00176 
00177     game_display* gui_;
00178     unit_map& units_;
00179     std::vector<team>& teams_;
00180     const config& level_;
00181     const gamemap& map_;
00182     const config& game_config_;
00183     const gamestatus& status_;
00184     game_state& gamestate_;
00185 
00186     undo_list& undo_stack_;
00187     undo_list& redo_stack_;
00188     gui::floating_textbox textbox_info_;
00189     std::string last_search_;
00190     gamemap::location last_search_hit_;
00191 
00192     std::string last_recruit_;
00193 };
00194 
00195 }
00196 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs