add z_order attribute to wesnoth.add_tile_overlay fixes #3156

this probably won't work for halos yet.
This commit is contained in:
gfgtdf 2018-10-20 22:46:32 +02:00
parent 262549433f
commit 082aa2afe2
4 changed files with 42 additions and 11 deletions

View File

@ -106,7 +106,7 @@ void display::parse_team_overlays()
}
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo, const std::string& team_name, const std::string& item_id, bool visible_under_fog)
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo, const std::string& team_name, const std::string& item_id, bool visible_under_fog, float z_order)
{
if (halo_man_) {
halo::handle halo_handle;
@ -115,7 +115,21 @@ void display::add_overlay(const map_location& loc, const std::string& img, const
get_location_y(loc) + hex_size() / 2, halo, loc);
}
get_overlays().emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog));
auto it1 = get_overlays().emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog, z_order));
auto itor_pair = get_overlays().equal_range(loc);
//get_overlays().emplace adds at the end.
assert(itor_pair.second != itor_pair.first && std::next(it1, 1) == itor_pair.second);
UNUSED(it1); //it is only used in the assert above.
if(std::next(itor_pair.first, 1) != itor_pair.second) {
//the range itor_pair is already sorted, except for the last element we just inserted,
for (auto it = itor_pair.second; it != std::next(itor_pair.first, 1);--it) {
overlay& one = std::next(it, - 1)->second;
overlay& two = (it)->second;
if(one.z_order > two.z_order) {
std::swap(one, two);
}
}
}
}
}

View File

@ -148,7 +148,7 @@ public:
*/
void add_overlay(const map_location& loc, const std::string& image,
const std::string& halo="", const std::string& team_name="",const std::string& item_id="",
bool visible_under_fog = true);
bool visible_under_fog = true, float z_order = 0);
/** remove_overlay will remove all overlays on a tile. */
void remove_overlay(const map_location& loc);

View File

@ -19,16 +19,32 @@
struct overlay
{
overlay(const std::string& img, const std::string& halo_img,
halo::handle handle, const std::string& overlay_team_name, const std::string& item_id, const bool fogged) : image(img), halo(halo_img),
team_name(overlay_team_name), id(item_id), halo_handle(handle) , visible_in_fog(fogged)
overlay(const std::string& img,
const std::string& halo_img,
halo::handle handle,
const std::string& overlay_team_name,
const std::string& item_id,
const bool fogged,
float item_z_order = 0)
: image(img)
, halo(halo_img)
, team_name(overlay_team_name)
, id(item_id)
, halo_handle(handle)
, visible_in_fog(fogged)
, z_order(item_z_order)
{}
overlay(const config& cfg) :
image(cfg["image"]), halo(cfg["halo"]), team_name(cfg["team_name"]),
name(cfg["name"].t_str()), id(cfg["id"]),
halo_handle(), visible_in_fog(cfg["visible_in_fog"].to_bool())
overlay(const config& cfg)
: image(cfg["image"])
, halo(cfg["halo"])
, team_name(cfg["team_name"])
, name(cfg["name"].t_str())
, id(cfg["id"])
, halo_handle()
, visible_in_fog(cfg["visible_in_fog"].to_bool())
, z_order(cfg["z_order"].to_double(0))
{
}
@ -40,5 +56,6 @@ struct overlay
halo::handle halo_handle;
bool visible_in_fog;
float z_order;
};

View File

@ -3345,7 +3345,7 @@ int game_lua_kernel::intf_add_tile_overlay(lua_State *L)
if (game_display_) {
game_display_->add_overlay(loc, cfg["image"], cfg["halo"],
team_name, cfg["name"], cfg["visible_in_fog"].to_bool(true));
team_name, cfg["name"], cfg["visible_in_fog"].to_bool(true), cfg["z_order"].to_double(0));
}
return 0;
}