Clean ":layers" and add layer order and back/foreground flag

This commit is contained in:
Ali El Gariani 2010-07-18 01:47:07 +00:00
parent b451146c9d
commit 6c19fbef3f
3 changed files with 36 additions and 59 deletions

View file

@ -33,18 +33,6 @@ static lg::log_domain log_engine("engine");
#define ERR_NG LOG_STREAM(err, log_engine)
#define WRN_NG LOG_STREAM(warn, log_engine)
/** The tile width used when using basex and basey. This is not,
* necessarily, the tile width in pixels, this is totally
* arbitrary. However, it will be set to 72 for convenience.
*/
static const int TILEWIDTH = 72;
/** The position of unit graphics in a tile. Graphics whose y
* position is below this value are considered background for
* this tile; graphics whose y position is above this value are
* considered foreground.
*/
static const int UNITPOS = 36 + 18;
terrain_builder::building_ruleset terrain_builder::building_rules_;
const config* terrain_builder::rules_cfg_ = NULL;
@ -80,7 +68,7 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
}
foreach(const rule_image_rand& ri, images){
bool is_background = ri->layer < 0 || (ri->layer == 0 && ri->basey < UNITPOS);
bool is_background = ri->is_background();
imagelist& img_list = is_background ? images_background : images_foreground;
@ -112,37 +100,6 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
}
}
std::vector<std::string> terrain_builder::tile::get_info() const
{
std::vector<std::string> res;
//TODO sort images if needed
foreach(const rule_image_rand& ri, images){
//TODO: read all variants
const rule_image_variant& variant = ri->variants.back();
std::ostringstream info;
const image::locator& img = variant.image.get_first_frame();
const std::string& name = img.get_filename();
//const std::string& modif = img.get_modifications();
std::string img_sep(char(1), 1);
const map_location& loc = img.get_loc();
info << "&" << name << "~LOC("
<<loc.x << "," << loc.y << ","
<< img.get_center_x() << "," << img.get_center_y()
<< ")"
<< img_sep << name
<< "=" << img.get_loc()
<< "=" << ri->layer
<< "=" << ri->basex
<< "=" << ri->basey;
res.push_back(info.str());
}
return res;
}
void terrain_builder::tile::clear()
{
flags.clear();

View file

@ -57,6 +57,19 @@ public:
*/
};
/** The tile width used when using basex and basey. This is not,
* necessarily, the tile width in pixels, this is totally
* arbitrary. However, it will be set to 72 for convenience.
*/
static const int TILEWIDTH = 72;
/** The position of unit graphics in a tile. Graphics whose y
* position is below this value are considered background for
* this tile; graphics whose y position is above this value are
* considered foreground.
*/
static const int UNITPOS = 36 + 18;
/** A shorthand typedef for a list of animated image locators,
* the base data type returned by the get_terrain_at method.
*/
@ -195,6 +208,10 @@ public:
struct rule_image {
rule_image(int layer, int x, int y, bool global_image=false, int center_x=-1, int center_y=-1);
bool is_background() const {
return layer < 0 || (layer == 0 && basey < UNITPOS);
}
/** The layer of the image for horizontal layering */
int layer;
/** The position of the image base (that is, the point where
@ -274,8 +291,6 @@ public:
*/
void rebuild_cache(const std::string &tod, logs* log = NULL);
std::vector<std::string> get_info() const;
/** Clears all data in this tile, and resets the cache */
void clear();

View file

@ -3123,14 +3123,15 @@ void console_handler::do_layers() {
std::vector<std::string> layers;
//NOTE: columns reflect WML keys, don't translate them
std::string heading = std::string(1,HEADING_PREFIX) +
"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
"^#" + COLUMN_SEPARATOR + // 0
"Image" + COLUMN_SEPARATOR + // 1
"Name" + COLUMN_SEPARATOR + // 2
"Loc" + COLUMN_SEPARATOR + // 3
"Layer" + COLUMN_SEPARATOR + // 4
"Base.x" + COLUMN_SEPARATOR + // 5
"Base.y" + COLUMN_SEPARATOR + // 6
"Center" // 7
;
layers.push_back(heading);
@ -3142,6 +3143,7 @@ void console_handler::do_layers() {
terrain_builder::tile::logs tile_logs;
tile->rebuild_cache(tod_id, &tile_logs);
int order = 1;
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;
@ -3153,7 +3155,9 @@ void console_handler::do_layers() {
const map_location& loc_cut = img.get_loc();
std::ostringstream str;
str << IMAGE_PREFIX << "terrain/foreground.png"
str << (ri->is_background() ? "B ": "F ") << order
<< COLUMN_SEPARATOR
<< IMAGE_PREFIX << "terrain/foreground.png"
<< "~BLIT("
<< name << "~LOC("
<< loc_cut.x << "," << loc_cut.y << ","
@ -3166,9 +3170,10 @@ void console_handler::do_layers() {
<< COLUMN_SEPARATOR << ri->layer
<< COLUMN_SEPARATOR << ri->basex
<< COLUMN_SEPARATOR << ri->basey
<< COLUMN_SEPARATOR << ri->center_x
<< COLUMN_SEPARATOR << ri->center_y;
<< COLUMN_SEPARATOR
<< ri->center_x << ", " << ri->center_y;
layers.push_back(str.str());
++order;
}
std::vector<std::string> flags(tile->flags.begin(),tile->flags.end());
@ -3176,8 +3181,8 @@ void console_handler::do_layers() {
// NOTE using ", " also allows better word wrapping
info << "Flags :" << utils::join(flags, ", ");
int choice = 0;
{
gui::dialog menu(*menu_handler_.gui_, _("Layers"), info.str(), gui::OK_CANCEL);
{
gui::dialog menu(*menu_handler_.gui_, _("Layers"), info.str(), gui::OK_CANCEL);
menu.set_menu(layers);
choice = menu.show();
}