make "reports" not a singleton object
This is necessary to make game_events not a singleton.
This commit is contained in:
parent
2f783c78a8
commit
0459f8a574
17 changed files with 108 additions and 98 deletions
|
@ -148,7 +148,7 @@ void display::remove_single_overlay(const map_location& loc, const std::string&
|
|||
|
||||
|
||||
|
||||
display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb, const config& theme_cfg, const config& level) :
|
||||
display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb, reports & reports_object, const config& theme_cfg, const config& level) :
|
||||
dc_(dc),
|
||||
halo_man_(new halo::manager(*this)),
|
||||
wb_(wb),
|
||||
|
@ -176,6 +176,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
|
|||
turbo_(false),
|
||||
invalidateGameStatus_(true),
|
||||
map_labels_(new map_labels(*this, 0)),
|
||||
reports_object_(reports_object),
|
||||
scroll_event_("scrolled"),
|
||||
complete_redraw_event_("completely_redrawn"),
|
||||
nextDraw_(0),
|
||||
|
@ -3083,7 +3084,7 @@ void display::refresh_report(std::string const &report_name, const config * new_
|
|||
|
||||
reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
|
||||
|
||||
const config generated_cfg = new_cfg ? config() : reports::generate_report(report_name, temp_context);
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_.generate_report(report_name, temp_context);
|
||||
if ( new_cfg == NULL )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
|
@ -3294,7 +3295,7 @@ void display::refresh_report(std::string const &report_name, const config * new_
|
|||
|
||||
reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
|
||||
|
||||
const config generated_cfg = new_cfg ? config() : reports::generate_report(report_name, temp_context);
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_.generate_report(report_name, temp_context);
|
||||
if ( new_cfg == NULL )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class fake_unit_manager;
|
|||
class terrain_builder;
|
||||
class map_labels;
|
||||
class arrow;
|
||||
class reports;
|
||||
|
||||
namespace halo {
|
||||
class manager;
|
||||
|
@ -77,6 +78,7 @@ class display : public filter_context
|
|||
{
|
||||
public:
|
||||
display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb,
|
||||
reports & reports_object,
|
||||
const config& theme_cfg, const config& level);
|
||||
virtual ~display();
|
||||
static display* get_singleton() { return singleton_ ;}
|
||||
|
@ -777,7 +779,7 @@ protected:
|
|||
bool turbo_;
|
||||
bool invalidateGameStatus_;
|
||||
boost::scoped_ptr<map_labels> map_labels_;
|
||||
|
||||
reports & reports_object_;
|
||||
|
||||
/** Event raised when the map is being scrolled */
|
||||
mutable events::generic_event scroll_event_;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include "dialogs.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "reports.hpp"
|
||||
|
||||
#include "desktop/clipboard.hpp"
|
||||
#include "../../game_preferences.hpp"
|
||||
|
@ -63,7 +64,8 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
: controller_base(SDL_GetTicks(), game_config, video)
|
||||
, mouse_handler_base()
|
||||
, active_menu_(editor::MAP)
|
||||
, gui_(new editor_display(editor::get_dummy_display_context(), video, get_theme(game_config, "editor"), config()))
|
||||
, reports_(new reports())
|
||||
, gui_(new editor_display(editor::get_dummy_display_context(), video, *reports_, get_theme(game_config, "editor"), config()))
|
||||
, tods_()
|
||||
, context_manager_(new context_manager(*gui_.get(), game_config_))
|
||||
, toolkit_(NULL)
|
||||
|
|
|
@ -215,6 +215,8 @@ class editor_controller : public controller_base,
|
|||
|
||||
editor::menu_type active_menu_;
|
||||
|
||||
/** Reports object. Must be initialized before the gui_ */
|
||||
boost::scoped_ptr<reports> reports_;
|
||||
|
||||
/** The display object used and owned by the editor. */
|
||||
boost::scoped_ptr<editor_display> gui_;
|
||||
|
|
|
@ -53,8 +53,9 @@ const display_context * get_dummy_display_context() {
|
|||
// End dummy display context
|
||||
|
||||
editor_display::editor_display(const display_context * dc, CVideo& video,
|
||||
reports & reports_object,
|
||||
const config& theme_cfg, const config& level)
|
||||
: display(dc, video, boost::shared_ptr<wb::manager>(), theme_cfg, level)
|
||||
: display(dc, video, boost::shared_ptr<wb::manager>(), reports_object, theme_cfg, level)
|
||||
, brush_locations_()
|
||||
, palette_report_()
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ class editor_display : public display
|
|||
{
|
||||
public:
|
||||
editor_display(const display_context * dc, CVideo& video,
|
||||
reports & reports_object,
|
||||
const config& theme_cfg, const config& level);
|
||||
|
||||
bool in_editor() const { return true; }
|
||||
|
|
|
@ -68,9 +68,10 @@ std::vector<surface> footsteps_images(const map_location& loc, const pathfind::m
|
|||
#endif
|
||||
|
||||
game_display::game_display(game_board& board, CVideo& video, boost::weak_ptr<wb::manager> wb,
|
||||
reports & reports_object,
|
||||
const tod_manager& tod,
|
||||
const config& theme_cfg, const config& level) :
|
||||
display(&board, video, wb, theme_cfg, level),
|
||||
display(&board, video, wb, reports_object, theme_cfg, level),
|
||||
overlay_map_(),
|
||||
attack_indicator_src_(),
|
||||
attack_indicator_dst_(),
|
||||
|
@ -93,7 +94,8 @@ game_display* game_display::create_dummy_display(CVideo& video)
|
|||
static config dummy_cfg2;
|
||||
static game_board dummy_board(boost::make_shared<terrain_type_data>(dummy_cfg), dummy_cfg2);
|
||||
static tod_manager dummy_tod(dummy_cfg);
|
||||
return new game_display(dummy_board, video, boost::shared_ptr<wb::manager>(), dummy_tod,
|
||||
static reports rep_;
|
||||
return new game_display(dummy_board, video, boost::shared_ptr<wb::manager>(), rep_, dummy_tod,
|
||||
dummy_cfg, dummy_cfg);
|
||||
}
|
||||
|
||||
|
@ -470,7 +472,7 @@ void game_display::draw_sidebar()
|
|||
|
||||
// We display the unit the mouse is over if it is over a unit,
|
||||
// otherwise we display the unit that is selected.
|
||||
BOOST_FOREACH(const std::string &name, reports::report_list()) {
|
||||
BOOST_FOREACH(const std::string &name, reports_object_.report_list()) {
|
||||
refresh_report(name);
|
||||
}
|
||||
invalidateGameStatus_ = false;
|
||||
|
|
|
@ -40,6 +40,7 @@ class game_display : public display
|
|||
public:
|
||||
game_display(game_board& board, CVideo& video,
|
||||
boost::weak_ptr<wb::manager> wb,
|
||||
reports & reports_object,
|
||||
const tod_manager& tod_manager,
|
||||
const config& theme_cfg,
|
||||
const config& level);
|
||||
|
|
|
@ -318,7 +318,6 @@ manager::~manager() {
|
|||
clear_events();
|
||||
event_handlers.clear();
|
||||
hotkey::delete_all_wml_hotkeys();
|
||||
reports::reset_generators();
|
||||
unit_wml_ids.clear();
|
||||
used_items.clear();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "pathfind/teleport.hpp"
|
||||
#include "preferences_display.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "savegame.hpp"
|
||||
#include "saved_game.hpp"
|
||||
|
@ -112,6 +113,7 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
|
|||
saved_game_(state_of_game),
|
||||
prefs_disp_manager_(),
|
||||
tooltips_manager_(),
|
||||
reports_(new reports()),
|
||||
events_manager_(),
|
||||
labels_manager_(),
|
||||
help_manager_(&game_config),
|
||||
|
@ -213,7 +215,7 @@ void play_controller::init(CVideo& video){
|
|||
|
||||
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
loadscreen::start_stage("build terrain");
|
||||
gui_.reset(new game_display(gamestate_.board_, video, whiteboard_manager_, gamestate_.tod_manager_, theme_cfg, level_));
|
||||
gui_.reset(new game_display(gamestate_.board_, video, whiteboard_manager_, *reports_, gamestate_.tod_manager_, theme_cfg, level_));
|
||||
if (!gui_->video().faked()) {
|
||||
if (saved_game_.mp_settings().mp_countdown)
|
||||
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
|
||||
|
@ -233,7 +235,7 @@ void play_controller::init(CVideo& video){
|
|||
// This *needs* to be created before the show_intro and show_map_scene
|
||||
// as that functions use the manager state_of_game
|
||||
// Has to be done before registering any events!
|
||||
lua_kernel_.reset(new game_lua_kernel(level_, *gui_, gamestate_, *this));
|
||||
lua_kernel_.reset(new game_lua_kernel(level_, *gui_, gamestate_, *this, *reports_));
|
||||
resources::lua_kernel=lua_kernel_.get();
|
||||
events_manager_.reset(new game_events::manager(level_));
|
||||
|
||||
|
|
|
@ -237,6 +237,7 @@ protected:
|
|||
boost::scoped_ptr<preferences::display_manager> prefs_disp_manager_;
|
||||
boost::scoped_ptr<tooltips::manager> tooltips_manager_;
|
||||
boost::scoped_ptr<game_lua_kernel> lua_kernel_;
|
||||
boost::scoped_ptr<reports> reports_;
|
||||
boost::scoped_ptr<game_events::manager> events_manager_;
|
||||
font::floating_label_context labels_manager_;
|
||||
help::help_manager help_manager_;
|
||||
|
|
|
@ -339,7 +339,7 @@ void replay_controller::reset_replay()
|
|||
events_manager_.reset();
|
||||
lua_kernel_.reset();
|
||||
resources::lua_kernel=NULL;
|
||||
lua_kernel_.reset(new game_lua_kernel(level_, *gui_, gamestate_, *this));
|
||||
lua_kernel_.reset(new game_lua_kernel(level_, *gui_, gamestate_, *this, *reports_));
|
||||
resources::lua_kernel=lua_kernel_.get();
|
||||
events_manager_.reset(new game_events::manager(level_));
|
||||
|
||||
|
|
126
src/reports.cpp
126
src/reports.cpp
|
@ -91,16 +91,12 @@ static std::string flush(std::ostringstream &s)
|
|||
return r;
|
||||
}
|
||||
|
||||
typedef config (*generator_function)(reports::context & );
|
||||
|
||||
typedef std::map<std::string, generator_function> static_report_generators;
|
||||
typedef std::map<std::string, reports::generator *> dynamic_report_generators;
|
||||
typedef std::map<std::string, reports::generator_function> static_report_generators;
|
||||
static static_report_generators static_generators;
|
||||
static dynamic_report_generators dynamic_generators;
|
||||
|
||||
struct report_generator_helper
|
||||
{
|
||||
report_generator_helper(const char *name, generator_function g)
|
||||
report_generator_helper(const char *name, reports::generator_function g)
|
||||
{
|
||||
static_generators.insert(static_report_generators::value_type(name, g));
|
||||
}
|
||||
|
@ -113,8 +109,6 @@ struct report_generator_helper
|
|||
|
||||
static char const *naps = "</span>";
|
||||
|
||||
namespace reports {
|
||||
|
||||
static const unit *get_visible_unit(reports::context & rc)
|
||||
{
|
||||
return rc.dc().get_visible_unit(rc.screen().displayed_unit_hex(),
|
||||
|
@ -129,8 +123,6 @@ static const unit *get_selected_unit(reports::context & rc)
|
|||
rc.screen().show_everything());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static config gray_inactive(reports::context & rc, const std::string &str)
|
||||
{
|
||||
if ( rc.screen().viewing_side() == rc.screen().playing_side() )
|
||||
|
@ -158,12 +150,12 @@ static config unit_name(const unit *u)
|
|||
|
||||
REPORT_GENERATOR(unit_name, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_name(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_name, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_name(u);
|
||||
}
|
||||
|
||||
|
@ -179,12 +171,12 @@ static config unit_type(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_type, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_type(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_type, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_type(u);
|
||||
}
|
||||
|
||||
|
@ -198,12 +190,12 @@ static config unit_race(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_race, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_race(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_race, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_race(u);
|
||||
}
|
||||
|
||||
|
@ -229,12 +221,12 @@ static config unit_side(reports::context & rc, const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_side, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_side(rc,u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_side, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_side(rc, u);
|
||||
}
|
||||
|
||||
|
@ -254,18 +246,18 @@ static config unit_level(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_level, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_level(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_level, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_level(u);
|
||||
}
|
||||
|
||||
REPORT_GENERATOR(unit_amla, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
if (!u) return config();
|
||||
config res;
|
||||
typedef std::pair<std::string, std::string> pair_string;
|
||||
|
@ -296,12 +288,12 @@ static config unit_traits(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_traits, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_traits(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_traits, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_traits(u);
|
||||
}
|
||||
|
||||
|
@ -330,12 +322,12 @@ static config unit_status(reports::context & rc, const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_status,rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_status(rc,u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_status, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_status(rc, u);
|
||||
}
|
||||
|
||||
|
@ -362,12 +354,12 @@ static config unit_alignment(reports::context & rc, const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_alignment, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_alignment(rc, u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_alignment, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_alignment(rc, u);
|
||||
}
|
||||
|
||||
|
@ -407,12 +399,12 @@ static config unit_abilities(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_abilities, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_abilities(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_abilities, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_abilities(u);
|
||||
}
|
||||
|
||||
|
@ -461,12 +453,12 @@ static config unit_hp(reports::context& rc, const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_hp, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_hp(rc, u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_hp, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_hp(rc, u);
|
||||
}
|
||||
|
||||
|
@ -483,12 +475,12 @@ static config unit_xp(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_xp, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_xp(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_xp, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_xp(u);
|
||||
}
|
||||
|
||||
|
@ -504,12 +496,12 @@ static config unit_advancement_options(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_advancement_options, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_advancement_options(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_advancement_options, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_advancement_options(u);
|
||||
}
|
||||
|
||||
|
@ -556,13 +548,13 @@ static config unit_defense(reports::context & rc, const unit* u, const map_locat
|
|||
}
|
||||
REPORT_GENERATOR(unit_defense,rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
|
||||
return unit_defense(rc, u, displayed_unit_hex);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_defense, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
const map_location& selected_hex = rc.screen().selected_hex();
|
||||
return unit_defense(rc, u, selected_hex);
|
||||
}
|
||||
|
@ -579,12 +571,12 @@ static config unit_vision(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_vision, rc)
|
||||
{
|
||||
const unit* u = reports::get_visible_unit(rc);
|
||||
const unit* u = get_visible_unit(rc);
|
||||
return unit_vision(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_vision, rc)
|
||||
{
|
||||
const unit* u = reports::get_selected_unit(rc);
|
||||
const unit* u = get_selected_unit(rc);
|
||||
return unit_vision(u);
|
||||
}
|
||||
|
||||
|
@ -646,12 +638,12 @@ static config unit_moves(reports::context & rc, const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_moves, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_moves(rc, u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_moves, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_moves(rc, u);
|
||||
}
|
||||
|
||||
|
@ -1007,15 +999,15 @@ static config unit_weapons(reports::context & rc, const unit *u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_weapons, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
if (!u) return config();
|
||||
|
||||
return unit_weapons(rc, u);
|
||||
}
|
||||
REPORT_GENERATOR(highlighted_unit_weapons, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *sec_u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
const unit *sec_u = get_visible_unit(rc);
|
||||
|
||||
if (!u) return config();
|
||||
if (!sec_u || u == sec_u) return unit_weapons(rc, sec_u);
|
||||
|
@ -1032,8 +1024,8 @@ REPORT_GENERATOR(highlighted_unit_weapons, rc)
|
|||
}
|
||||
REPORT_GENERATOR(selected_unit_weapons, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *sec_u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
const unit *sec_u = get_visible_unit(rc);
|
||||
|
||||
if (!u) return config();
|
||||
if (!sec_u || u == sec_u) return unit_weapons(rc, u);
|
||||
|
@ -1051,26 +1043,26 @@ REPORT_GENERATOR(selected_unit_weapons, rc)
|
|||
|
||||
REPORT_GENERATOR(unit_image,rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
if (!u) return config();
|
||||
return image_report(u->absolute_image() + u->image_mods());
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_image, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
if (!u) return config();
|
||||
return image_report(u->absolute_image() + u->image_mods());
|
||||
}
|
||||
|
||||
REPORT_GENERATOR(selected_unit_profile, rc)
|
||||
{
|
||||
const unit *u = reports::get_selected_unit(rc);
|
||||
const unit *u = get_selected_unit(rc);
|
||||
if (!u) return config();
|
||||
return image_report(u->small_profile());
|
||||
}
|
||||
REPORT_GENERATOR(unit_profile, rc)
|
||||
{
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
if (!u) return config();
|
||||
return image_report(u->small_profile());
|
||||
}
|
||||
|
@ -1217,7 +1209,7 @@ static config unit_box_at(reports::context & rc, const map_location& mouseover_h
|
|||
|
||||
bg_terrain_image = bg_terrain_image + "~CS(" + color.str() + ")";
|
||||
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
std::string unit_image;
|
||||
if (u)
|
||||
unit_image = "~BLIT(" + u->absolute_image() + u->image_mods() + ",35,22)";
|
||||
|
@ -1464,7 +1456,7 @@ REPORT_GENERATOR(position, rc)
|
|||
std::ostringstream str;
|
||||
str << mouseover_hex;
|
||||
|
||||
const unit *u = reports::get_visible_unit(rc);
|
||||
const unit *u = get_visible_unit(rc);
|
||||
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
|
||||
if (!u ||
|
||||
(displayed_unit_hex != mouseover_hex &&
|
||||
|
@ -1571,32 +1563,20 @@ REPORT_GENERATOR(report_countdown, rc)
|
|||
return text_report(str.str());
|
||||
}
|
||||
|
||||
static std::set<std::string> all_reports;
|
||||
|
||||
void reports::reset_generators()
|
||||
{
|
||||
BOOST_FOREACH(dynamic_report_generators::value_type &rg, dynamic_generators) {
|
||||
delete rg.second;
|
||||
}
|
||||
dynamic_generators.clear();
|
||||
all_reports.clear();
|
||||
}
|
||||
|
||||
void reports::register_generator(const std::string &name, reports::generator *g)
|
||||
{
|
||||
std::pair<dynamic_report_generators::iterator, bool> ib =
|
||||
dynamic_generators.insert(std::make_pair(name, g));
|
||||
dynamic_generators_.insert(std::make_pair(name, g));
|
||||
if (!ib.second) {
|
||||
delete ib.first->second;
|
||||
ib.first->second = g;
|
||||
ib.first->second.reset(g);
|
||||
}
|
||||
}
|
||||
|
||||
config reports::generate_report(const std::string &name, reports::context & rc, bool only_static)
|
||||
{
|
||||
if (!only_static) {
|
||||
dynamic_report_generators::const_iterator i = dynamic_generators.find(name);
|
||||
if (i != dynamic_generators.end())
|
||||
dynamic_report_generators::const_iterator i = dynamic_generators_.find(name);
|
||||
if (i != dynamic_generators_.end())
|
||||
return i->second->generate(rc);
|
||||
}
|
||||
static_report_generators::const_iterator j = static_generators.find(name);
|
||||
|
@ -1607,12 +1587,12 @@ config reports::generate_report(const std::string &name, reports::context & rc,
|
|||
|
||||
const std::set<std::string> &reports::report_list()
|
||||
{
|
||||
if (!all_reports.empty()) return all_reports;
|
||||
if (!all_reports_.empty()) return all_reports_;
|
||||
BOOST_FOREACH(const static_report_generators::value_type &v, static_generators) {
|
||||
all_reports.insert(v.first);
|
||||
all_reports_.insert(v.first);
|
||||
}
|
||||
BOOST_FOREACH(const dynamic_report_generators::value_type &v, dynamic_generators) {
|
||||
all_reports.insert(v.first);
|
||||
BOOST_FOREACH(const dynamic_report_generators::value_type &v, dynamic_generators_) {
|
||||
all_reports_.insert(v.first);
|
||||
}
|
||||
return all_reports;
|
||||
return all_reports_;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ namespace events {
|
|||
class mouse_handler;
|
||||
}
|
||||
|
||||
namespace reports {
|
||||
class reports {
|
||||
public:
|
||||
|
||||
class context
|
||||
{
|
||||
|
@ -71,12 +72,22 @@ struct generator
|
|||
virtual ~generator() {}
|
||||
};
|
||||
|
||||
void reset_generators();
|
||||
void register_generator(const std::string &name, generator *);
|
||||
|
||||
config generate_report(const std::string &name, context & ct, bool only_static = false);
|
||||
|
||||
const std::set<std::string> &report_list();
|
||||
}
|
||||
|
||||
|
||||
typedef config (*generator_function)(reports::context & );
|
||||
typedef std::map<std::string, boost::shared_ptr<reports::generator> > dynamic_report_generators;
|
||||
|
||||
private:
|
||||
|
||||
std::set<std::string> all_reports_;
|
||||
|
||||
dynamic_report_generators dynamic_generators_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2846,7 +2846,7 @@ namespace {
|
|||
int game_lua_kernel::impl_theme_item(lua_State *L, std::string m)
|
||||
{
|
||||
reports::context temp_context = reports::context(board(), game_display_, tod_man(), play_controller_.get_whiteboard(), play_controller_.get_mouse_handler_base());
|
||||
luaW_pushconfig(L, reports::generate_report(m.c_str(), temp_context , true));
|
||||
luaW_pushconfig(L, reports_.generate_report(m.c_str(), temp_context , true));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -2860,20 +2860,20 @@ int game_lua_kernel::impl_theme_items_get(lua_State *L)
|
|||
lua_pushvalue(L, 2);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_rawset(L, 1);
|
||||
reports::register_generator(m, new lua_report_generator(L, m));
|
||||
reports_.register_generator(m, new lua_report_generator(L, m));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a field of the theme_items table (__newindex metamethod).
|
||||
*/
|
||||
static int impl_theme_items_set(lua_State *L)
|
||||
int game_lua_kernel::impl_theme_items_set(lua_State *L)
|
||||
{
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
lua_pushvalue(L, 2);
|
||||
lua_pushvalue(L, 3);
|
||||
lua_rawset(L, 1);
|
||||
reports::register_generator(m, new lua_report_generator(L, m));
|
||||
reports_.register_generator(m, new lua_report_generator(L, m));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2910,8 +2910,8 @@ tod_manager & game_lua_kernel::tod_man() {
|
|||
return game_state_.tod_manager_;
|
||||
}
|
||||
|
||||
game_lua_kernel::game_lua_kernel(const config &cfg, game_display & gd, game_state & gs, play_controller & pc)
|
||||
: lua_kernel_base(&gd.video()), game_display_(gd), game_state_(gs), play_controller_(pc), level_(cfg)
|
||||
game_lua_kernel::game_lua_kernel(const config &cfg, game_display & gd, game_state & gs, play_controller & pc, reports & reports_object)
|
||||
: lua_kernel_base(&gd.video()), game_display_(gd), game_state_(gs), play_controller_(pc), reports_(reports_object), level_(cfg)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
|
||||
|
@ -3155,7 +3155,7 @@ game_lua_kernel::game_lua_kernel(const config &cfg, game_display & gd, game_stat
|
|||
lua_createtable(L, 0, 2);
|
||||
lua_cpp::push_closure(L, boost::bind(&game_lua_kernel::impl_theme_items_get, this, _1), 0);
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_pushcfunction(L, impl_theme_items_set);
|
||||
lua_cpp::push_closure(L, boost::bind(&game_lua_kernel::impl_theme_items_set, this, _1), 0);
|
||||
lua_setfield(L, -2, "__newindex");
|
||||
lua_setmetatable(L, -2);
|
||||
lua_setfield(L, -2, "theme_items");
|
||||
|
|
|
@ -39,6 +39,7 @@ class team;
|
|||
class game_data;
|
||||
class tod_manager;
|
||||
class play_controller;
|
||||
class reports;
|
||||
|
||||
typedef int (*lua_CFunction) (lua_State *L);
|
||||
|
||||
|
@ -47,6 +48,7 @@ class game_lua_kernel : public lua_kernel_base
|
|||
game_display & game_display_;
|
||||
game_state & game_state_;
|
||||
play_controller & play_controller_;
|
||||
reports & reports_;
|
||||
|
||||
// Private functions to ease access to parts of game_state
|
||||
game_board & board();
|
||||
|
@ -115,13 +117,14 @@ class game_lua_kernel : public lua_kernel_base
|
|||
int intf_get_all_vars(lua_State *L);
|
||||
int impl_theme_item(lua_State *L, std::string name);
|
||||
int impl_theme_items_get(lua_State *L);
|
||||
int impl_theme_items_set(lua_State *L);
|
||||
|
||||
//private helpers
|
||||
std::string synced_state();
|
||||
void lua_chat(std::string const &caption, std::string const &msg);
|
||||
|
||||
public:
|
||||
game_lua_kernel(const config &, game_display &, game_state &, play_controller &);
|
||||
game_lua_kernel(const config &, game_display &, game_state &, play_controller &, reports &);
|
||||
|
||||
virtual std::string my_name() { return "Game Lua Kernel"; }
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "game_display.hpp"
|
||||
#include "terrain_type_data.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "reports.hpp"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
|
@ -37,6 +38,7 @@ namespace test_utils {
|
|||
config dummy_cfg2_;
|
||||
game_board dummy_board_;
|
||||
tod_manager dummy_tod_;
|
||||
reports dummy_reports;
|
||||
const events::event_context main_event_context_;
|
||||
|
||||
|
||||
|
@ -68,7 +70,7 @@ namespace test_utils {
|
|||
dummy_board_(boost::make_shared<terrain_type_data>(dummy_cfg_), dummy_cfg2_),
|
||||
dummy_tod_(dummy_cfg_),
|
||||
main_event_context_(),
|
||||
disp_(dummy_board_, video_, boost::shared_ptr<wb::manager> (), dummy_tod_,
|
||||
disp_(dummy_board_, video_, boost::shared_ptr<wb::manager> (), dummy_reports, dummy_tod_,
|
||||
dummy_cfg_, dummy_cfg_)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue