Clean the implentation of ':layers'
- also display (scaled) image from the source for easier identification - show center.x/y - support [variant] - directly log from the engine function to avoid code duplication
This commit is contained in:
parent
6755770b22
commit
14ba29f0f6
5 changed files with 65 additions and 29 deletions
|
@ -67,7 +67,7 @@ terrain_builder::tile::tile() :
|
|||
sorted_images(false)
|
||||
{}
|
||||
|
||||
void terrain_builder::tile::rebuild_cache(const std::string& tod)
|
||||
void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
|
||||
{
|
||||
images_background.clear();
|
||||
images_foreground.clear();
|
||||
|
@ -103,6 +103,10 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod)
|
|||
img_list.push_back(variant.image);
|
||||
img_list.back().set_animation_time(ri.rand % img_list.back().get_animation_duration());
|
||||
|
||||
if(log) {
|
||||
log->push_back(std::make_pair(&ri, &variant));
|
||||
}
|
||||
|
||||
break; // found a matching variant
|
||||
}
|
||||
}
|
||||
|
@ -276,14 +280,6 @@ const terrain_builder::imagelist *terrain_builder::get_terrain_at(const map_loca
|
|||
return NULL;
|
||||
}
|
||||
|
||||
std::vector<std::string> terrain_builder::get_tile_info(const map_location &loc) const
|
||||
{
|
||||
if(tile_map_.on_map(loc))
|
||||
return tile_map_[loc].get_info();
|
||||
else
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
bool terrain_builder::update_animation(const map_location &loc)
|
||||
{
|
||||
if(!tile_map_.on_map(loc))
|
||||
|
@ -1107,3 +1103,10 @@ void terrain_builder::build_terrains()
|
|||
++rule_index;
|
||||
}
|
||||
}
|
||||
|
||||
terrain_builder::tile* terrain_builder::get_tile(const map_location &loc)
|
||||
{
|
||||
if(tile_map_.on_map(loc))
|
||||
return &(tile_map_[loc]);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -112,8 +112,6 @@ public:
|
|||
const imagelist *get_terrain_at(const map_location &loc,
|
||||
const std::string &tod, TERRAIN_TYPE const terrain_type);
|
||||
|
||||
std::vector<std::string> get_tile_info(const map_location &loc) const;
|
||||
|
||||
/** Updates the animation at a given tile.
|
||||
* Returns true if something has changed, and must be redrawn.
|
||||
*
|
||||
|
@ -265,13 +263,16 @@ public:
|
|||
/** Contructor for the tile() structure */
|
||||
tile();
|
||||
|
||||
struct rule_image_rand;
|
||||
typedef std::pair<const rule_image_rand*, const rule_image_variant*> log_details;
|
||||
typedef std::vector<log_details> logs;
|
||||
/** Rebuilds the whole image cache, for a given time-of-day.
|
||||
* Must be called when the time-of-day has changed,
|
||||
* to select the correct images.
|
||||
*
|
||||
* @param tod The current time-of-day
|
||||
*/
|
||||
void rebuild_cache(const std::string &tod);
|
||||
void rebuild_cache(const std::string &tod, logs* log = NULL);
|
||||
|
||||
std::vector<std::string> get_info() const;
|
||||
|
||||
|
@ -318,6 +319,8 @@ public:
|
|||
bool sorted_images;
|
||||
};
|
||||
|
||||
tile* get_tile(const map_location &loc);
|
||||
|
||||
private:
|
||||
/**
|
||||
* The list of constraints attached to a terrain_graphics WML rule.
|
||||
|
|
|
@ -809,11 +809,6 @@ void display::toggle_debug_foreground()
|
|||
debug_foreground = !debug_foreground;
|
||||
}
|
||||
|
||||
std::vector<std::string> display::get_tile_info(const map_location &loc)
|
||||
{
|
||||
return builder_->get_tile_info(loc);
|
||||
}
|
||||
|
||||
void display::flip()
|
||||
{
|
||||
if(video().faked()) {
|
||||
|
|
|
@ -344,7 +344,7 @@ public:
|
|||
*/
|
||||
static void toggle_debug_foreground();
|
||||
|
||||
std::vector<std::string> get_tile_info(const map_location &loc);
|
||||
terrain_builder& get_builder() {return *builder_;};
|
||||
|
||||
void flip();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "builder.hpp"
|
||||
#include "ai/manager.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "formatter.hpp"
|
||||
|
@ -3119,21 +3120,55 @@ void console_handler::do_layers() {
|
|||
const mouse_handler& mousehandler = resources::controller->get_mouse_handler_base();
|
||||
const map_location &loc = mousehandler.get_last_hex();
|
||||
|
||||
|
||||
std::vector<std::string> layers;
|
||||
//FIXME: translate columns
|
||||
//NOTE: columns reflect WML keys, don't translate them
|
||||
std::string heading = std::string(1,HEADING_PREFIX) +
|
||||
"Image" + COLUMN_SEPARATOR + // 0
|
||||
"Loc" + COLUMN_SEPARATOR + // 1
|
||||
"Layer" + COLUMN_SEPARATOR + // 2
|
||||
"Base.x" + COLUMN_SEPARATOR + // 3
|
||||
"Base.y" // 4
|
||||
;
|
||||
"Image" + COLUMN_SEPARATOR + // 0
|
||||
"Name" + COLUMN_SEPARATOR + // 1
|
||||
"Loc" + COLUMN_SEPARATOR + // 2
|
||||
"Layer" + COLUMN_SEPARATOR + // 3
|
||||
"Base.x" + COLUMN_SEPARATOR + // 4
|
||||
"Base.y" + COLUMN_SEPARATOR + // 5
|
||||
"Center.x"+ COLUMN_SEPARATOR + // 6
|
||||
"Center.y" // 7
|
||||
;
|
||||
layers.push_back(heading);
|
||||
|
||||
std::vector<std::string> info =
|
||||
menu_handler_.gui_->get_tile_info(loc);
|
||||
layers.insert(layers.end(), info.begin(), info.end());
|
||||
display& disp = *(menu_handler_.gui_);
|
||||
terrain_builder& builder = disp.get_builder();
|
||||
terrain_builder::tile* tile = builder.get_tile(loc);
|
||||
|
||||
const std::string& tod_id = disp.get_time_of_day(loc).id;
|
||||
terrain_builder::tile::logs tile_logs;
|
||||
tile->rebuild_cache(tod_id, &tile_logs);
|
||||
|
||||
foreach(const terrain_builder::tile::log_details det, tile_logs) {
|
||||
const terrain_builder::tile::rule_image_rand& ri = *det.first;
|
||||
const terrain_builder::rule_image_variant& variant = *det.second;
|
||||
|
||||
const image::locator& img = variant.image.get_first_frame();
|
||||
const std::string& name = img.get_filename();
|
||||
//TODO deal with (rarely used) ~modifications
|
||||
//const std::string& modif = img.get_modifications();
|
||||
const map_location& loc = img.get_loc();
|
||||
|
||||
std::ostringstream info;
|
||||
info << IMAGE_PREFIX << name
|
||||
<< "~LOC("
|
||||
<< loc.x << "," << loc.y << ","
|
||||
<< img.get_center_x() << "," << img.get_center_y()
|
||||
<< ")"
|
||||
<< COLUMN_SEPARATOR
|
||||
<< IMAGE_PREFIX << name << "~SCALE(72,72)"
|
||||
<< IMG_TEXT_SEPARATOR << name
|
||||
<< COLUMN_SEPARATOR << img.get_loc()
|
||||
<< COLUMN_SEPARATOR << ri->layer
|
||||
<< COLUMN_SEPARATOR << ri->basex
|
||||
<< COLUMN_SEPARATOR << ri->basey
|
||||
<< COLUMN_SEPARATOR << ri->center_x
|
||||
<< COLUMN_SEPARATOR << ri->center_y;
|
||||
layers.push_back(info.str());
|
||||
}
|
||||
|
||||
int choice = 0;
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue