Skip to content

Commit

Permalink
minor refactor of help -- launch dialogs from help:: not dialogs::
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jul 24, 2014
1 parent 47fe0aa commit ae58f71
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
38 changes: 2 additions & 36 deletions src/dialogs.cpp
Expand Up @@ -1450,7 +1450,7 @@ const unit_preview_pane::details units_list_preview_pane::get_details() const
void units_list_preview_pane::process_event()
{
if (details_button_.pressed() && index_ >= 0 && index_ < int(size())) {
show_unit_description(*units_[index_]);
help::show_unit_description(*units_[index_]);
}
}

Expand Down Expand Up @@ -1538,44 +1538,10 @@ void unit_types_preview_pane::process_event()
if (details_button_.pressed() && index_ >= 0 && index_ < int(size())) {
const unit_type* type = (*unit_types_)[index_];
if (type != NULL)
show_unit_description(*type);
help::show_unit_description(*type);
}
}


void show_unit_description(const unit &u)
{
show_unit_description(u.type());
}

void show_terrain_description(const terrain_type &t)
{
help::show_terrain_help(*display::get_singleton(), t.id(), t.hide_in_editor() || t.is_combined());
}

void show_unit_description(const unit_type &t)
{
std::string var_id = t.get_cfg()["variation_id"].str();
if (var_id.empty())
var_id = t.get_cfg()["variation_name"].str();
bool hide_help = t.hide_help();
bool use_variation = false;
if (!var_id.empty()) {
const unit_type *parent = unit_types.find(t.id());
assert(parent);
if (hide_help) {
hide_help = parent->hide_help();
} else {
use_variation = true;
}
}

if (use_variation)
help::show_variation_help(*display::get_singleton(), t.id(), var_id, hide_help);
else
help::show_unit_help(*display::get_singleton(), t.id(), !t.variations().empty(), hide_help);
}

static network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
{
const size_t width = 300;
Expand Down
5 changes: 0 additions & 5 deletions src/dialogs.hpp
Expand Up @@ -148,11 +148,6 @@ class unit_types_preview_pane : public dialogs::unit_preview_pane
int side_;
};


void show_unit_description(const unit_type &t);
void show_unit_description(const unit &u);
void show_terrain_description(const terrain_type& t);

network::connection network_send_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num=0);
network::connection network_receive_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num=0);
network::connection network_connect_dialog(display& disp, const std::string& msg, const std::string& hostname, int port);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/editor_controller.cpp
Expand Up @@ -1327,7 +1327,7 @@ void editor_controller::terrain_description()
return;

const terrain_type& type = context_manager_->get_map().get_terrain_info(loc);
dialogs::show_terrain_description(type);
help::show_terrain_description(type);
}

void editor_controller::process_keyup_event(const SDL_Event& event)
Expand Down
33 changes: 33 additions & 0 deletions src/help.cpp
Expand Up @@ -514,6 +514,39 @@ class help_browser : public gui::widget
topic const *shown_topic_;
};

void show_unit_description(const unit &u)
{
help::show_unit_description(u.type());
}

void show_terrain_description(const terrain_type &t)
{
help::show_terrain_help(*display::get_singleton(), t.id(), t.hide_in_editor() || t.is_combined());
}

void show_unit_description(const unit_type &t)
{
std::string var_id = t.get_cfg()["variation_id"].str();
if (var_id.empty())
var_id = t.get_cfg()["variation_name"].str();
bool hide_help = t.hide_help();
bool use_variation = false;
if (!var_id.empty()) {
const unit_type *parent = unit_types.find(t.id());
assert(parent);
if (hide_help) {
hide_help = parent->hide_help();
} else {
use_variation = true;
}
}

if (use_variation)
help::show_variation_help(*display::get_singleton(), t.id(), var_id, hide_help);
else
help::show_unit_help(*display::get_singleton(), t.id(), !t.variations().empty(), hide_help);
}

// Generator stuff below. Maybe move to a separate file? This one is
// getting crowded. Dunno if much more is needed though so I'll wait and
// see.
Expand Down
5 changes: 5 additions & 0 deletions src/help.hpp
Expand Up @@ -17,6 +17,8 @@
class config;
class display;
class gamemap;
class terrain_type;
class unit_type;

#include "hotkey/command_executor.hpp"
#include "construct_dialog.hpp"
Expand Down Expand Up @@ -69,6 +71,9 @@ class help_button : public gui::dialog_button, public hotkey::command_executor {
hotkey::basic_handler *help_hand_;
};

void show_unit_description(const unit_type &t);
void show_unit_description(const unit &u);
void show_terrain_description(const terrain_type& t);

} // End namespace help.

Expand Down
4 changes: 2 additions & 2 deletions src/menu_events.cpp
Expand Up @@ -894,7 +894,7 @@ void menu_handler::unit_description()
{
const unit_map::const_iterator un = current_unit();
if(un != units_.end()) {
dialogs::show_unit_description(*un);
help::show_unit_description(*un);
}
}

Expand All @@ -907,7 +907,7 @@ void menu_handler::terrain_description(mouse_handler& mousehandler)

const terrain_type& type = map_.get_terrain_info(loc);
//const terrain_type& info = resources::gameboard->map().get_terrain_info(terrain);
dialogs::show_terrain_description(type);
help::show_terrain_description(type);
}

void menu_handler::rename_unit()
Expand Down

0 comments on commit ae58f71

Please sign in to comment.